Skip to content

Commit

Permalink
Cleanup, formatting, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 3, 2024
1 parent 7de8bff commit 05316bd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
24 changes: 20 additions & 4 deletions examples/rpi_pico_w/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
//
// Copyright (c) 2024 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#include "FreeRTOS.h"
#include "pico/cyw43_arch.h"
#include "pico/stdlib.h"
#include "task.h"

#define TEST_TASK_PRIORITY (tskIDLE_PRIORITY + 2UL)
#define TASK_PRIORITY (tskIDLE_PRIORITY + 2UL)
#define WIFI_TIMEOUT 30000

int app_main();

Expand All @@ -18,15 +33,16 @@ void print_ip_address() {
}
}

void main_task(__unused void *params) {
void main_task(void *params) {
(void)params;
if (cyw43_arch_init()) {
printf("Failed to initialise\n");
return;
}

cyw43_arch_enable_sta_mode();
printf("Connecting to Wi-Fi...\n");
if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000) == 0) {
if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, WIFI_TIMEOUT) == 0) {
printf("Wi-Fi connected.\n");
print_ip_address();
app_main();
Expand All @@ -44,7 +60,7 @@ void main_task(__unused void *params) {
int main(void) {
stdio_init_all();

xTaskCreate(main_task, "TestMainThread", configMINIMAL_STACK_SIZE * 16, NULL, TEST_TASK_PRIORITY, NULL);
xTaskCreate(main_task, "MainThread", configMINIMAL_STACK_SIZE * 16, NULL, TASK_PRIORITY, NULL);

vTaskStartScheduler();

Expand Down
1 change: 1 addition & 0 deletions examples/rpi_pico_w/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
6 changes: 1 addition & 5 deletions include/zenoh-pico/system/platform/rpi_pico_w.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_SYSTEM_RPI_PICO_W_TYPES_H
#define ZENOH_PICO_SYSTEM_RPI_PICO_W_TYPES_H
Expand All @@ -28,11 +29,6 @@ typedef struct {
const char *name;
UBaseType_t priority;
size_t stack_depth;
#if (configSUPPORT_STATIC_ALLOCATION == 1)
bool static_allocation;
StackType_t *stack_buffer;
StaticTask_t *task_buffer;
#endif /* SUPPORT_STATIC_ALLOCATION */
} z_task_attr_t;

typedef struct {
Expand Down
4 changes: 2 additions & 2 deletions src/system/rpi_pico_w/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#include <stdlib.h>

Expand All @@ -33,7 +34,7 @@ z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_addre

struct addrinfo hints;
(void)memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC; // Allow IPv4 or IPv6
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0;
hints.ai_protocol = IPPROTO_TCP;
Expand All @@ -42,7 +43,6 @@ z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_addre
ret = _Z_ERR_GENERIC;
}

_Z_DEBUG("_z_create_endpoint_tcp: %s:%s -> %li", s_address, s_port, ep->_iptcp->ai_addrlen);
return ret;
}

Expand Down
22 changes: 2 additions & 20 deletions src/system/rpi_pico_w/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ static z_task_attr_t z_default_task_attr = {
.name = "",
.priority = configMAX_PRIORITIES / 2,
.stack_depth = 5120,
#if (configSUPPORT_STATIC_ALLOCATION == 1)
.static_allocation = false,
.stack_buffer = NULL,
.task_buffer = NULL,
#endif /* SUPPORT_STATIC_ALLOCATION */
};

/*------------------ Thread ------------------*/
Expand All @@ -92,22 +87,9 @@ z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void
attr = &z_default_task_attr;
}

#if (configSUPPORT_STATIC_ALLOCATION == 1)
if (attr->static_allocation) {
task->handle = xTaskCreateStatic(z_task_wrapper, attr->name, attr->stack_depth, z_arg, attr->priority,
attr->stack_buffer, attr->task_buffer);
if (task->handle == NULL) {
return -1;
}
} else {
#endif /* SUPPORT_STATIC_ALLOCATION */
if (xTaskCreate(z_task_wrapper, attr->name, attr->stack_depth, z_arg, attr->priority, &task->handle) !=
pdPASS) {
return -1;
}
#if (configSUPPORT_STATIC_ALLOCATION == 1)
if (xTaskCreate(z_task_wrapper, attr->name, attr->stack_depth, z_arg, attr->priority, &task->handle) != pdPASS) {
return -1;
}
#endif /* SUPPORT_STATIC_ALLOCATION */

return 0;
}
Expand Down

0 comments on commit 05316bd

Please sign in to comment.