diff --git a/firmware/app/tasks/beacon.c b/firmware/app/tasks/beacon.c
index a1917785..13c267d2 100644
--- a/firmware/app/tasks/beacon.c
+++ b/firmware/app/tasks/beacon.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2019/10/27
*
@@ -42,7 +42,7 @@
xTaskHandle xTaskBeaconHandle;
-void vTaskBeacon(void *pvParameters)
+void vTaskBeacon(void)
{
/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_BEACON_INIT_TIMEOUT_MS));
diff --git a/firmware/app/tasks/beacon.h b/firmware/app/tasks/beacon.h
index 0b74e728..62b87bf4 100644
--- a/firmware/app/tasks/beacon.h
+++ b/firmware/app/tasks/beacon.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2019/10/27
*
@@ -55,11 +55,9 @@ extern xTaskHandle xTaskBeaconHandle;
/**
* \brief Beacon task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskBeacon(void *pvParameters);
+void vTaskBeacon(void);
#endif /* BEACON_H_ */
diff --git a/firmware/app/tasks/csp_server.c b/firmware/app/tasks/csp_server.c
index 7b3c3e87..47ddd5a7 100644
--- a/firmware/app/tasks/csp_server.c
+++ b/firmware/app/tasks/csp_server.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/04/04
*
@@ -42,7 +42,7 @@
xTaskHandle xTaskCSPServerHandle;
-void vTaskCSPServer(void *pvParameters)
+void vTaskCSPServer(void)
{
/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_CSP_SERVER_INIT_TIMEOUT_MS));
@@ -63,18 +63,24 @@ void vTaskCSPServer(void *pvParameters)
while(1)
{
/* Wait for connection until reach timeout */
- if ((conn = csp_accept(sock, CONFIG_CSP_WAIT_CONN_TIMEOUT_MS)) == NULL)
+ conn = csp_accept(sock, CONFIG_CSP_WAIT_CONN_TIMEOUT_MS);
+ if (conn == NULL)
{
continue;
}
/* Read packets until reach timeout */
- while((packet = csp_read(conn, CONFIG_CSP_READ_PKT_TIMEOUT_MS)) != NULL)
+ packet = csp_read(conn, CONFIG_CSP_READ_PKT_TIMEOUT_MS);
+ while(packet != NULL)
{
switch(csp_conn_dport(conn))
{
- case CONFIG_CSP_PORT:
+ case CONFIG_CSP_PRIMARY_PORT:
/* TODO: Process packet here */
+ break;
+ case CONFIG_CSP_SECONDARY_PORT:
+ /* TODO: Process packet here */
+ break;
default:
/* Let the service handler reply pings, buffer use, etc. */
csp_service_handler(conn, packet);
diff --git a/firmware/app/tasks/csp_server.h b/firmware/app/tasks/csp_server.h
index c20a5d15..ba9808ea 100644
--- a/firmware/app/tasks/csp_server.h
+++ b/firmware/app/tasks/csp_server.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/04/04
*
@@ -54,11 +54,9 @@ extern xTaskHandle xTaskCSPServerHandle;
/**
* \brief CSP server task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskCSPServer(void *pvParameters);
+void vTaskCSPServer(void);
#endif /* CSP_SERVER_H_ */
diff --git a/firmware/app/tasks/heartbeat.c b/firmware/app/tasks/heartbeat.c
index 081dec2c..ec3a1397 100644
--- a/firmware/app/tasks/heartbeat.c
+++ b/firmware/app/tasks/heartbeat.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/20
*
@@ -40,7 +40,7 @@
xTaskHandle xTaskHeartbeatHandle;
-void vTaskHeartbeat(void *pvParameters)
+void vTaskHeartbeat(void)
{
/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_HEARTBEAT_INIT_TIMEOUT_MS));
diff --git a/firmware/app/tasks/heartbeat.h b/firmware/app/tasks/heartbeat.h
index 60a0645e..1b87ef9b 100644
--- a/firmware/app/tasks/heartbeat.h
+++ b/firmware/app/tasks/heartbeat.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/20
*
@@ -41,7 +41,7 @@
#include
#define TASK_HEARTBEAT_NAME "Heartbeat" /**< Task name. */
-#define TASK_HEARTBEAT_STACK_SIZE 128 /**< Memory stack size in bytes. */
+#define TASK_HEARTBEAT_STACK_SIZE 160 /**< Memory stack size in bytes. */
#define TASK_HEARTBEAT_PRIORITY 1 /**< Priority. */
#define TASK_HEARTBEAT_PERIOD_MS 500 /**< Period in milliseconds. */
#define TASK_HEARTBEAT_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */
@@ -54,11 +54,9 @@ extern xTaskHandle xTaskHeartbeatHandle;
/**
* \brief System heartbeat task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskHeartbeat(void *pvParameters);
+void vTaskHeartbeat(void);
#endif /* HEARTBEAT_H_ */
diff --git a/firmware/app/tasks/radio_reset.c b/firmware/app/tasks/radio_reset.c
index ba7c49da..8268869b 100644
--- a/firmware/app/tasks/radio_reset.c
+++ b/firmware/app/tasks/radio_reset.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/29
*
@@ -37,7 +37,7 @@
xTaskHandle xTaskRadioResetHandle;
-void vTaskRadioReset(void *pvParameters)
+void vTaskRadioReset(void)
{
/* Delay before the first cycle */
vTaskDelay(pdMS_TO_TICKS(TASK_RADIO_RESET_INITIAL_DELAY_MS));
diff --git a/firmware/app/tasks/radio_reset.h b/firmware/app/tasks/radio_reset.h
index 758b4e23..43cc84f9 100644
--- a/firmware/app/tasks/radio_reset.h
+++ b/firmware/app/tasks/radio_reset.h
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/29
*
@@ -54,11 +54,9 @@ extern xTaskHandle xTaskRadioResetHandle;
/**
* \brief Periodic radio reset task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskRadioReset(void *pvParameters);
+void vTaskRadioReset(void);
#endif /* RADIO_RESET_H_ */
diff --git a/firmware/app/tasks/read_sensors.c b/firmware/app/tasks/read_sensors.c
index 71366c3a..249cae87 100644
--- a/firmware/app/tasks/read_sensors.c
+++ b/firmware/app/tasks/read_sensors.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.25
+ * \version 0.1.10
*
* \date 2020/07/12
*
@@ -43,7 +43,7 @@
xTaskHandle xTaskReadSensorsHandle;
-void vTaskReadSensors(void *pvParameters)
+void vTaskReadSensors(void)
{
/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_READ_SENSORS_INIT_TIMEOUT_MS));
diff --git a/firmware/app/tasks/read_sensors.h b/firmware/app/tasks/read_sensors.h
index 07304e15..db43a2c9 100644
--- a/firmware/app/tasks/read_sensors.h
+++ b/firmware/app/tasks/read_sensors.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/07/12
*
@@ -54,11 +54,9 @@ extern xTaskHandle xTaskReadSensorsHandle;
/**
* \brief Read onboard sensors task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskReadSensors(void *pvParameters);
+void vTaskReadSensors(void);
#endif /* READ_SENSORS_H_ */
diff --git a/firmware/app/tasks/startup.c b/firmware/app/tasks/startup.c
index 87bdd20c..2a74cf2f 100644
--- a/firmware/app/tasks/startup.c
+++ b/firmware/app/tasks/startup.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2019/12/04
*
@@ -59,7 +59,7 @@ xTaskHandle xTaskStartupHandle;
EventGroupHandle_t task_startup_status;
-void vTaskStartup(void *pvParameters)
+void vTaskStartup(void)
{
unsigned int error_counter = 0;
@@ -144,7 +144,7 @@ void vTaskStartup(void *pvParameters)
error_counter++;
}
- if (error_counter > 0)
+ if (error_counter > 0U)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_STARTUP_NAME, "Boot completed with ");
sys_log_print_uint(error_counter);
@@ -167,38 +167,37 @@ void vTaskStartup(void *pvParameters)
vTaskSuspend(xTaskStartupHandle);
}
-int startup_init_csp()
+int startup_init_csp(void)
{
-#if CONFIG_CSP_ENABLED == 1
- /* CSP initialization */
- if (csp_init(CONFIG_CSP_MY_ADDRESS) != CSP_ERR_NONE)
- {
- return -1; /* Error during CSP initialization */
- }
+#if defined(CONFIG_CSP_ENABLED) && (CONFIG_CSP_ENABLED == 1)
+ int err = CSP_ERR_NONE;
- /* Buffer initialization */
- if (csp_buffer_init(CONFIG_CSP_BUFFER_MAX_PKTS, CONFIG_CSP_BUFFER_MAX_SIZE) != CSP_ERR_NONE)
- {
- return -1; /* Error during the CSP buffer initialization */
- }
-
- if (csp_route_set(CONFIG_CSP_TTC_ADDRESS, &csp_if_spi, CSP_NODE_MAC) != CSP_ERR_NONE)
- {
- return -1;
- }
-
- if (csp_route_set(CONFIG_CSP_EPS_ADDRESS, &csp_if_i2c, CSP_NODE_MAC) != CSP_ERR_NONE)
- {
- return -1;
- }
+ /* CSP initialization */
+ err = csp_init(CONFIG_CSP_MY_ADDRESS);
- /* CSP router task initialization */
- if (csp_route_start_task(CONFIG_CSP_ROUTER_WORD_STACK, CONFIG_CSP_ROUTER_TASK_PRIORITY) != CSP_ERR_NONE)
+ if (err == CSP_ERR_NONE)
{
- return -1; /* Error during CSP router task initialization! */
+ /* Buffer initialization */
+ err = csp_buffer_init(CONFIG_CSP_BUFFER_MAX_PKTS, CONFIG_CSP_BUFFER_MAX_SIZE);
+
+ if (err == CSP_ERR_NONE)
+ {
+ err = csp_route_set(CONFIG_CSP_TTC_ADDRESS, &csp_if_spi, CSP_NODE_MAC);
+
+ if (err == CSP_ERR_NONE)
+ {
+ err = csp_route_set(CONFIG_CSP_EPS_ADDRESS, &csp_if_i2c, CSP_NODE_MAC);
+
+ if (err == CSP_ERR_NONE)
+ {
+ /* CSP router task initialization */
+ err = csp_route_start_task(CONFIG_CSP_ROUTER_WORD_STACK, CONFIG_CSP_ROUTER_TASK_PRIORITY);
+ }
+ }
+ }
}
- return CSP_ERR_NONE;
+ return err;
#else
sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_STARTUP_NAME, "libcsp disabled!");
sys_log_new_line();
diff --git a/firmware/app/tasks/startup.h b/firmware/app/tasks/startup.h
index f11ac147..b7eff139 100644
--- a/firmware/app/tasks/startup.h
+++ b/firmware/app/tasks/startup.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2019/12/04
*
@@ -46,7 +46,7 @@
#define TASK_STARTUP_PRIORITY 5
/* Status done bit position */
-#define TASK_STARTUP_DONE (1 << 0)
+#define TASK_STARTUP_DONE (1U << 0)
/**
* \brief Startup task handle.
@@ -63,18 +63,16 @@ extern EventGroupHandle_t task_startup_status;
*
* This task runs in a single shot (non-periodic). After it's conclusion, it is deleted.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskStartup(void *pvParameters);
+void vTaskStartup(void);
/**
* \brief CSP initialization.
*
* \return The status/error code.
*/
-int startup_init_csp();
+int startup_init_csp(void);
#endif /* STARTUP_H_ */
diff --git a/firmware/app/tasks/system_reset.c b/firmware/app/tasks/system_reset.c
index 1a751602..c1e1c283 100644
--- a/firmware/app/tasks/system_reset.c
+++ b/firmware/app/tasks/system_reset.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/12
*
@@ -40,7 +40,7 @@
xTaskHandle xTaskSystemResetHandle;
-void vTaskSystemReset(void *pvParameters)
+void vTaskSystemReset(void)
{
while(1)
{
diff --git a/firmware/app/tasks/system_reset.h b/firmware/app/tasks/system_reset.h
index 54162163..e6f5668b 100644
--- a/firmware/app/tasks/system_reset.h
+++ b/firmware/app/tasks/system_reset.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/12
*
@@ -40,10 +40,10 @@
#include
#include
-#define TASK_SYSTEM_RESET_NAME "SystemReset" /**< Task name. */
-#define TASK_SYSTEM_RESET_STACK_SIZE 128 /**< Stack size in bytes. */
-#define TASK_SYSTEM_RESET_PRIORITY 2 /**< Task priority. */
-#define TASK_SYSTEM_RESET_PERIOD_MS (1000UL*60*60*10) /**< Task period in milliseconds. */
+#define TASK_SYSTEM_RESET_NAME "SystemReset" /**< Task name. */
+#define TASK_SYSTEM_RESET_STACK_SIZE 128 /**< Stack size in bytes. */
+#define TASK_SYSTEM_RESET_PRIORITY 2 /**< Task priority. */
+#define TASK_SYSTEM_RESET_PERIOD_MS (1000UL*60U*60U*10U) /**< Task period in milliseconds. */
/**
* \brief Periodic system reset handle.
@@ -55,11 +55,9 @@ extern xTaskHandle xTaskSystemResetHandle;
*
* This task resets the microcontroller.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskSystemReset(void *pvParameters);
+void vTaskSystemReset(void);
#endif /* SYSTEM_RESET_H_ */
diff --git a/firmware/app/tasks/tasks.c b/firmware/app/tasks/tasks.c
index 83f70ac8..7b9c79d2 100644
--- a/firmware/app/tasks/tasks.c
+++ b/firmware/app/tasks/tasks.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2019/11/02
*
@@ -53,7 +53,7 @@
void create_tasks(void)
{
/* Startup task */
-#if CONFIG_TASK_STARTUP_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskStartup, TASK_STARTUP_NAME, TASK_STARTUP_STACK_SIZE, NULL, TASK_STARTUP_PRIORITY, &xTaskStartupHandle);
if (xTaskStartupHandle == NULL)
@@ -63,7 +63,7 @@ void create_tasks(void)
#endif /* CONFIG_TASK_STARTUP_ENABLED */
/* Watchdog reset task */
-#if CONFIG_TASK_WATCHDOG_RESET_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskWatchdogReset, TASK_WATCHDOG_RESET_NAME, TASK_WATCHDOG_RESET_STACK_SIZE, NULL, TASK_WATCHDOG_RESET_PRIORITY, &xTaskWatchdogResetHandle);
if (xTaskWatchdogResetHandle == NULL)
@@ -73,7 +73,7 @@ void create_tasks(void)
#endif /* CONFIG_TASK_WATCHDOG_RESET_ENABLED */
/* Heartbeat task */
-#if CONFIG_TASK_HEARTBEAT_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskHeartbeat, TASK_HEARTBEAT_NAME, TASK_HEARTBEAT_STACK_SIZE, NULL, TASK_HEARTBEAT_PRIORITY, &xTaskHeartbeatHandle);
if (xTaskHeartbeatHandle == NULL)
@@ -82,7 +82,7 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_HEARTBEAT_ENABLED */
-#if CONFIG_TASK_SYSTEM_RESET_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskSystemReset, TASK_SYSTEM_RESET_NAME, TASK_SYSTEM_RESET_STACK_SIZE, NULL, TASK_SYSTEM_RESET_PRIORITY, &xTaskSystemResetHandle);
if (xTaskSystemResetHandle == NULL)
@@ -91,7 +91,7 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_SYSTEM_RESET_ENABLED */
-#if CONFIG_TASK_RADIO_RESET_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskRadioReset, TASK_RADIO_RESET_NAME, TASK_RADIO_RESET_STACK_SIZE, NULL, TASK_RADIO_RESET_PRIORITY, &xTaskRadioResetHandle);
if (xTaskRadioResetHandle == NULL)
@@ -100,7 +100,7 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_RADIO_RESET_ENABLED */
-#if CONFIG_TASK_READ_SENSORS_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskReadSensors, TASK_READ_SENSORS_NAME, TASK_READ_SENSORS_STACK_SIZE, NULL, TASK_READ_SENSORS_PRIORITY, &xTaskReadSensorsHandle);
if (xTaskReadSensorsHandle == NULL)
@@ -109,7 +109,7 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_READ_TEMP_ENABLED */
-#if CONFIG_TASK_BEACON_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskBeacon, TASK_BEACON_NAME, TASK_BEACON_STACK_SIZE, NULL, TASK_BEACON_PRIORITY, &xTaskBeaconHandle);
if (xTaskBeaconHandle == NULL)
@@ -118,7 +118,7 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_BEACON_ENABLED */
-#if CONFIG_TASK_UPLINK_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskUplink, TASK_UPLINK_NAME, TASK_UPLINK_STACK_SIZE, NULL, TASK_UPLINK_PRIORITY, &xTaskUplinkHandle);
if (xTaskUplinkHandle == NULL)
@@ -127,7 +127,7 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_UPLINK_ENABLED */
-#if CONFIG_TASK_TIME_CONTROL_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskTimeControl, TASK_TIME_CONTROL_NAME, TASK_TIME_CONTROL_STACK_SIZE, NULL, TASK_TIME_CONTROL_PRIORITY, &xTaskTimeControlHandle);
if (xTaskTimeControlHandle == NULL)
@@ -136,7 +136,7 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_BEACON_ENABLED */
-#if CONFIG_TASK_CSP_SERVER_ENABLED == 1
+#if defined(CONFIG_TASK_STARTUP_ENABLED) && (CONFIG_TASK_STARTUP_ENABLED == 1)
xTaskCreate(vTaskCSPServer, TASK_CSP_SERVER_NAME, TASK_CSP_SERVER_STACK_SIZE, NULL, TASK_CSP_SERVER_PRIORITY, &xTaskCSPServerHandle);
if (xTaskCSPServerHandle == NULL)
diff --git a/firmware/app/tasks/time_control.c b/firmware/app/tasks/time_control.c
index f3a4bc23..d45df57a 100644
--- a/firmware/app/tasks/time_control.c
+++ b/firmware/app/tasks/time_control.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/08/09
*
@@ -41,9 +41,44 @@
#include "time_control.h"
#include "startup.h"
+#define TIME_CONTROL_MEDIA MEDIA_INT_FLASH
+#define TIME_CONTROL_SAVE_PERIOD_SEC 60
+#define TIME_CONTROL_MEM_ID 0x12U
+#define TIME_CONTROL_CRC8_INITIAL_VAL 0x00U /* CRC8-CCITT initial value. */
+#define TIME_CONTROL_CRC8_POLYNOMIAL 0x07U /* CRC8-CCITT polynomial. */
+
xTaskHandle xTaskTimeControlHandle;
-void vTaskTimeControl(void *pvParameters)
+/**
+ * \brief Loads the last saved system time from the non-volatile memory.
+ *
+ * \param[in,out] tm is a pointer to load the read system time from the memory.
+ *
+ * \return The status/error code.
+ */
+static int time_control_load_sys_time(sys_time_t *tm);
+
+/**
+ * \brief Saves a given system time to the non-volatile memory.
+ *
+ * \param[in] tm is the system time value to save.
+ *
+ * \return The status/error code.
+ */
+static int time_control_save_sys_time(sys_time_t tm);
+
+/**
+ * \brief Computes the CRC-8 of a sequence of bytes.
+ *
+ * \param[in] data is an array of data to compute the CRC-8.
+ *
+ * \param[in] len is the number of bytes of the given array.
+ *
+ * \return The computed CRC-8 value of the given data.
+ */
+static uint8_t time_control_crc8(uint8_t *data, uint8_t len);
+
+void vTaskTimeControl(void)
{
/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_TIME_CONTROL_INIT_TIMEOUT_MS));
@@ -51,16 +86,16 @@ void vTaskTimeControl(void *pvParameters)
/* Load the last saved system time */
sys_time_t last_sys_time = 0;
- if (media_read(MEDIA_INT_FLASH, CONFIG_MEM_ADR_SYS_TIME, &last_sys_time, 1) != 0)
+ if (time_control_load_sys_time(&last_sys_time) == 0)
{
- sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "Error reading the system time from the internal flash memory!");
+ sys_log_print_event_from_module(SYS_LOG_INFO, TASK_TIME_CONTROL_NAME, "Last saved system time (epoch): ");
+ sys_log_print_uint(last_sys_time);
+ sys_log_print_msg(" sec");
sys_log_new_line();
}
else
{
- sys_log_print_event_from_module(SYS_LOG_INFO, TASK_TIME_CONTROL_NAME, "Last saved system time (epoch): ");
- sys_log_print_uint(last_sys_time);
- sys_log_print_msg(" sec");
+ sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "The last saved system time is not available!");
sys_log_new_line();
}
@@ -77,18 +112,95 @@ void vTaskTimeControl(void *pvParameters)
/* Read the current system time */
sys_time_t sys_tm = system_get_time();
- if (sys_tm % 60 == 0)
+ if ((sys_tm % TIME_CONTROL_SAVE_PERIOD_SEC) == 0)
{
/* Save the current system time */
- if (media_write(MEDIA_INT_FLASH, CONFIG_MEM_ADR_SYS_TIME, &sys_tm, 1))
- {
- sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "Error writing the system time to the internal flash memory!");
- sys_log_new_line();
- }
+// if (time_control_save_sys_time(sys_tm) != 0)
+// {
+// sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "Error saving the system time!");
+// sys_log_new_line();
+// }
}
vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_TIME_CONTROL_PERIOD_MS));
}
}
+static int time_control_load_sys_time(sys_time_t *tm)
+{
+ int err = -1;
+
+ uint8_t buf[6] = {0};
+
+ if (media_read(TIME_CONTROL_MEDIA, CONFIG_MEM_ADR_SYS_TIME, buf, 6U) == 0)
+ {
+ if ((buf[0] == TIME_CONTROL_MEM_ID) && (time_control_crc8(buf, 5U) == buf[5]))
+ {
+ *tm = ((sys_time_t)buf[1] << 24) |
+ ((sys_time_t)buf[2] << 16) |
+ ((sys_time_t)buf[3] << 8) |
+ (sys_time_t)buf[4];
+
+ err = 0;
+ }
+ else
+ {
+ sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "Error reading the system time from the non-volatile memory!");
+ sys_log_new_line();
+ }
+ }
+ else
+ {
+ sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "Error reading the system time from the non-volatile memory!");
+ sys_log_new_line();
+ }
+
+ return err;
+}
+
+static int time_control_save_sys_time(sys_time_t tm)
+{
+ int err = 0;
+
+ uint8_t buf[6] = {0};
+
+ buf[0] = TIME_CONTROL_MEM_ID;
+ buf[1] = ((uint32_t)tm >> 24) & 0xFFU;
+ buf[2] = ((uint32_t)tm >> 16) & 0xFFU;
+ buf[3] = ((uint32_t)tm >> 8) & 0xFFU;
+ buf[4] = (uint32_t)tm & 0xFFU;
+ buf[5] = time_control_crc8(buf, 5U);
+
+ if (media_write(TIME_CONTROL_MEDIA, CONFIG_MEM_ADR_SYS_TIME, buf, 6U) != 0)
+ {
+ sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "Error writing the system time to the non-volatile memory!");
+ sys_log_new_line();
+
+ err = -1;
+ }
+
+ return err;
+}
+
+static uint8_t time_control_crc8(uint8_t *data, uint8_t len)
+{
+ uint8_t crc = TIME_CONTROL_CRC8_INITIAL_VAL;
+
+ uint8_t i = 0U;
+ for(i = 0; i < len; i++)
+ {
+ crc ^= data[i];
+
+ uint8_t j = 0U;
+ for (j = 0U; j < 8U; j++)
+ {
+ crc = (crc << 1) ^ ((crc & 0x80U) ? TIME_CONTROL_CRC8_POLYNOMIAL : 0U);
+ }
+
+ crc &= 0xFFU;
+ }
+
+ return crc;
+}
+
/** \} End of time_control group */
diff --git a/firmware/app/tasks/time_control.h b/firmware/app/tasks/time_control.h
index 62003422..bde3227c 100644
--- a/firmware/app/tasks/time_control.h
+++ b/firmware/app/tasks/time_control.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/08/09
*
@@ -44,7 +44,7 @@
#define TASK_TIME_CONTROL_STACK_SIZE 128 /**< Stack size in bytes. */
#define TASK_TIME_CONTROL_PRIORITY 3 /**< Task priority. */
#define TASK_TIME_CONTROL_PERIOD_MS 1000 /**< Task period in milliseconds. */
-#define TASK_TIME_CONTROL_INIT_TIMEOUT_MS 0 /**< Wait time to initialize the task in milliseconds. */
+#define TASK_TIME_CONTROL_INIT_TIMEOUT_MS 1000 /**< Wait time to initialize the task in milliseconds. */
/**
* \brief Time control task handle.
@@ -54,11 +54,9 @@ extern xTaskHandle xTaskTimeControlHandle;
/**
* \brief Time control task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskTimeControl(void *pvParameters);
+void vTaskTimeControl(void);
#endif /* TIME_CONTROL_H_ */
diff --git a/firmware/app/tasks/uplink.c b/firmware/app/tasks/uplink.c
index 9dc17bbc..b495661e 100644
--- a/firmware/app/tasks/uplink.c
+++ b/firmware/app/tasks/uplink.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/04/18
*
@@ -41,7 +41,7 @@
xTaskHandle xTaskUplinkHandle;
-void vTaskUplink(void *pvParameters)
+void vTaskUplink(void)
{
/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_UPLINK_INIT_TIMEOUT_MS));
@@ -51,7 +51,7 @@ void vTaskUplink(void *pvParameters)
while(1)
{
- uint8_t data[129];
+ uint8_t data[129] = {0};
uint8_t len = 50;
if (radio_recv(data, len, TASK_UPLINK_PERIOD_MS) > 0)
diff --git a/firmware/app/tasks/uplink.h b/firmware/app/tasks/uplink.h
index b0da9043..d8b62263 100644
--- a/firmware/app/tasks/uplink.h
+++ b/firmware/app/tasks/uplink.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/04/18
*
@@ -55,11 +55,9 @@ extern xTaskHandle xTaskUplinkHandle;
/**
* \brief Uplink task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskUplink(void *pvParameters);
+void vTaskUplink(void);
#endif /* UPLINK_H_ */
diff --git a/firmware/app/tasks/watchdog_reset.c b/firmware/app/tasks/watchdog_reset.c
index 6213bc1c..78dd5081 100644
--- a/firmware/app/tasks/watchdog_reset.c
+++ b/firmware/app/tasks/watchdog_reset.c
@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TTC 2.0. If not, see .
+ * along with TTC 2.0. If not, see .
*
*/
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/11
*
@@ -39,7 +39,7 @@
xTaskHandle xTaskWatchdogResetHandle;
-void vTaskWatchdogReset(void *pvParameters)
+void vTaskWatchdogReset(void)
{
/* Delay before the first cycle */
vTaskDelay(pdMS_TO_TICKS(TASK_WATCHDOG_RESET_INITIAL_DELAY_MS));
diff --git a/firmware/app/tasks/watchdog_reset.h b/firmware/app/tasks/watchdog_reset.h
index 01293372..9b237227 100644
--- a/firmware/app/tasks/watchdog_reset.h
+++ b/firmware/app/tasks/watchdog_reset.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.0.9
+ * \version 0.1.10
*
* \date 2020/01/11
*
@@ -41,7 +41,7 @@
#include
#define TASK_WATCHDOG_RESET_NAME "WatchdogReset" /**< Task name. */
-#define TASK_WATCHDOG_RESET_STACK_SIZE 128 /**< Stack size in bytes. */
+#define TASK_WATCHDOG_RESET_STACK_SIZE 150 /**< Stack size in bytes. */
#define TASK_WATCHDOG_RESET_PRIORITY 1 /**< Task priority. */
#define TASK_WATCHDOG_RESET_PERIOD_MS 100 /**< Task period in milliseconds. */
#define TASK_WATCHDOG_RESET_INITIAL_DELAY_MS 0 /**< Delay, in milliseconds, before the first execution. */
@@ -54,11 +54,9 @@ extern xTaskHandle xTaskWatchdogResetHandle;
/**
* \brief Watchdog reset task.
*
- * \param[in] pvParameters is a value that will passed as the task's parameter.
- *
* \return None.
*/
-void vTaskWatchdogReset(void *pvParameters);
+void vTaskWatchdogReset(void);
#endif /* WATCHDOG_RESET_H_ */
diff --git a/firmware/version.h b/firmware/version.h
index 2bea1ae7..aea4bb8d 100644
--- a/firmware/version.h
+++ b/firmware/version.h
@@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino
*
- * \version 0.1.9
+ * \version 0.1.10
*
* \date 2021/04/04
*
@@ -36,7 +36,7 @@
#ifndef VERSION_H_
#define VERSION_H_
-#define FIRMWARE_VERSION "0.1.9"
+#define FIRMWARE_VERSION "0.1.10"
#define FIRMWARE_STATUS "Development"