From 2c45941c31ecb83b8884a5351035320a1cf1645f Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 27 Feb 2024 22:03:22 -0300 Subject: [PATCH 01/31] firmware: drivers: spi: Adding a mutex to protect the spi bus from concurrent acess issues #346 --- firmware/drivers/spi/spi_mutex.c | 92 ++++++++++++++++++++++++++++++++ firmware/drivers/spi/spi_mutex.h | 65 ++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 firmware/drivers/spi/spi_mutex.c create mode 100644 firmware/drivers/spi/spi_mutex.h diff --git a/firmware/drivers/spi/spi_mutex.c b/firmware/drivers/spi/spi_mutex.c new file mode 100644 index 00000000..c6433a4a --- /dev/null +++ b/firmware/drivers/spi/spi_mutex.c @@ -0,0 +1,92 @@ +/* + * spi_mutex.c + * + * Copyright The OBDH 2.0 Contributors. + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief SPI mutex implementation. + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.10 + * + * \date 2024/02/27 + * + * \addtogroup spi_mutex + * \{ + */ + +#include +#include +#include + +#include "spi_mutex.h" + +static xSemaphoreHandle spi_port0_mutex = NULL; + +int spi_mutex_create(void) +{ + static bool mutex_is_initialized = false; + int err = -1; + + if (!mutex_is_initialized) + { + spi_port0_mutex = xSemaphoreCreateMutex(); + + if (spi_port0_mutex != NULL) + { + mutex_is_initialized = true; + err = 0; + } + } + + return err; +} + +int spi_mutex_take(void) +{ + int err = -1; + + if (spi_port0_mutex != NULL) + { + if (xSemaphoreTake(spi_port0_mutex, pdMS_TO_TICKS(SPI_MUTEX_WAIT_TIME_MS)) == pdTRUE) + { + err = 0; + } + } + + return err; +} + +int spi_mutex_give(void) +{ + int err = -1; + + if (spi_port0_mutex != NULL) + { + xSemaphoreGive(spi_port0_mutex); + + err = 0; + } + + return err; +} + +/** \} End of spi_mutex group */ diff --git a/firmware/drivers/spi/spi_mutex.h b/firmware/drivers/spi/spi_mutex.h new file mode 100644 index 00000000..0e42d0a0 --- /dev/null +++ b/firmware/drivers/spi/spi_mutex.h @@ -0,0 +1,65 @@ +/* + * spi_mutex.h + * + * Copyright The OBDH 2.0 Contributors. + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief SPI mutex definition. + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.10 + * + * \date 2024/02/27 + * + * \defgroup spi_mutex SPI Mutex + * \ingroup spi + * \{ + */ + +#ifndef DRIVERS_SPI_SPI_MUTEX_H_ +#define DRIVERS_SPI_SPI_MUTEX_H_ + +#define SPI_MUTEX_WAIT_TIME_MS 50 + +/** + * \brief Creates the SPI mutex. + * + * \return The status/error code. + */ +int spi_mutex_create(void); + +/** + * \brief Attempts to take the SPI mutex. + * + * \return The status/error code. + */ +int spi_mutex_take(void); + +/** + * \brief Gives the SPI mutex. + * + * \return The status/error code. + */ +int spi_mutex_give(void); + +#endif /* DRIVERS_SPI_SPI_MUTEX_H_ */ + +/** \} End of spi_mutex group */ From 7241fc8dcf9853f2be779980a13b709222ae55bc Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 12 Mar 2024 23:01:13 -0300 Subject: [PATCH 02/31] firmware: drivers: spi: Updating mutex initialization. --- firmware/drivers/spi/spi.c | 12 ++++++ firmware/drivers/spi/spi.h | 23 +++++++++++ firmware/drivers/spi/spi_mutex.c | 12 ++++-- firmware/drivers/spi/spi_mutex.h | 65 -------------------------------- 4 files changed, 43 insertions(+), 69 deletions(-) delete mode 100644 firmware/drivers/spi/spi_mutex.h diff --git a/firmware/drivers/spi/spi.c b/firmware/drivers/spi/spi.c index 62a76bca..c5f846f4 100644 --- a/firmware/drivers/spi/spi.c +++ b/firmware/drivers/spi/spi.c @@ -309,6 +309,18 @@ int spi_init(spi_port_t port, spi_config_t config) } } + if (err == 0 && port == SPI_PORT_0) + { + if (spi_mutex_create() != 0) + { + #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) + sys_log_print_event_from_module(SYS_LOG_ERROR, SPI_MODULE_NAME, "Error creating the mutex for port 0"); + sys_log_new_line(); + #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ + err = -1; /* Error initializing the SPI port */ + } + } + switch(port) { case SPI_PORT_0: spi_port_0_is_open = true; break; diff --git a/firmware/drivers/spi/spi.h b/firmware/drivers/spi/spi.h index 02ced49c..9a5abc0c 100644 --- a/firmware/drivers/spi/spi.h +++ b/firmware/drivers/spi/spi.h @@ -42,6 +42,8 @@ #define SPI_MODULE_NAME "SPI" +#define SPI_MUTEX_WAIT_TIME_MS 10000U + /** * \brief SPI ports. */ @@ -250,6 +252,27 @@ int spi_read(spi_port_t port, spi_cs_t cs, uint8_t *data, uint16_t len); */ int spi_transfer(spi_port_t port, spi_cs_t cs, uint8_t *wd, uint8_t *rd, uint16_t len); +/** + * \brief Creates the SPI mutex. + * + * \return The status/error code. + */ +int spi_mutex_create(void); + +/** + * \brief Attempts to take the SPI mutex. + * + * \return The status/error code. + */ +int spi_mutex_take(void); + +/** + * \brief Gives the SPI mutex. + * + * \return The status/error code. + */ +int spi_mutex_give(void); + #endif /* SPI_H_ */ /** \} End of spi group */ diff --git a/firmware/drivers/spi/spi_mutex.c b/firmware/drivers/spi/spi_mutex.c index c6433a4a..f5da33f6 100644 --- a/firmware/drivers/spi/spi_mutex.c +++ b/firmware/drivers/spi/spi_mutex.c @@ -37,14 +37,15 @@ #include #include -#include "spi_mutex.h" +#include "spi.h" static xSemaphoreHandle spi_port0_mutex = NULL; +static bool mutex_is_initialized = false; + int spi_mutex_create(void) { - static bool mutex_is_initialized = false; - int err = -1; + int err = 0; if (!mutex_is_initialized) { @@ -53,7 +54,10 @@ int spi_mutex_create(void) if (spi_port0_mutex != NULL) { mutex_is_initialized = true; - err = 0; + } + else + { + err = -1; } } diff --git a/firmware/drivers/spi/spi_mutex.h b/firmware/drivers/spi/spi_mutex.h deleted file mode 100644 index 0e42d0a0..00000000 --- a/firmware/drivers/spi/spi_mutex.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * spi_mutex.h - * - * Copyright The OBDH 2.0 Contributors. - * - * This file is part of OBDH 2.0. - * - * OBDH 2.0 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * OBDH 2.0 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OBDH 2.0. If not, see . - * - */ - -/** - * \brief SPI mutex definition. - * - * \author Carlos Augusto Porto Freitas - * - * \version 0.10.10 - * - * \date 2024/02/27 - * - * \defgroup spi_mutex SPI Mutex - * \ingroup spi - * \{ - */ - -#ifndef DRIVERS_SPI_SPI_MUTEX_H_ -#define DRIVERS_SPI_SPI_MUTEX_H_ - -#define SPI_MUTEX_WAIT_TIME_MS 50 - -/** - * \brief Creates the SPI mutex. - * - * \return The status/error code. - */ -int spi_mutex_create(void); - -/** - * \brief Attempts to take the SPI mutex. - * - * \return The status/error code. - */ -int spi_mutex_take(void); - -/** - * \brief Gives the SPI mutex. - * - * \return The status/error code. - */ -int spi_mutex_give(void); - -#endif /* DRIVERS_SPI_SPI_MUTEX_H_ */ - -/** \} End of spi_mutex group */ From 78c230f9071f5497579a82d7833f410714ce2274 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 14 May 2024 22:09:00 -0300 Subject: [PATCH 03/31] firmware: drivers: spi: Fix MISRA-C rule #346 --- firmware/drivers/spi/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/drivers/spi/spi.c b/firmware/drivers/spi/spi.c index c5f846f4..1e2ab8f1 100644 --- a/firmware/drivers/spi/spi.c +++ b/firmware/drivers/spi/spi.c @@ -309,7 +309,7 @@ int spi_init(spi_port_t port, spi_config_t config) } } - if (err == 0 && port == SPI_PORT_0) + if ((err == 0) && (port == SPI_PORT_0)) { if (spi_mutex_create() != 0) { From 56b50dc574dac99434226bc9e143570d343b2422 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 14 May 2024 22:09:30 -0300 Subject: [PATCH 04/31] firmware: drivers: spi: Change spi mutex to be recursive #346 --- firmware/drivers/spi/spi_mutex.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/firmware/drivers/spi/spi_mutex.c b/firmware/drivers/spi/spi_mutex.c index f5da33f6..e2ceaeed 100644 --- a/firmware/drivers/spi/spi_mutex.c +++ b/firmware/drivers/spi/spi_mutex.c @@ -33,23 +33,25 @@ * \{ */ -#include -#include #include +#include -#include "spi.h" +#include +#include -static xSemaphoreHandle spi_port0_mutex = NULL; +#include "spi.h" -static bool mutex_is_initialized = false; +static SemaphoreHandle_t spi_port0_mutex = NULL; int spi_mutex_create(void) { + static bool mutex_is_initialized = false; + int err = 0; if (!mutex_is_initialized) { - spi_port0_mutex = xSemaphoreCreateMutex(); + spi_port0_mutex = xSemaphoreCreateRecursiveMutex(); if (spi_port0_mutex != NULL) { @@ -70,7 +72,7 @@ int spi_mutex_take(void) if (spi_port0_mutex != NULL) { - if (xSemaphoreTake(spi_port0_mutex, pdMS_TO_TICKS(SPI_MUTEX_WAIT_TIME_MS)) == pdTRUE) + if (xSemaphoreTakeRecursive(spi_port0_mutex, pdMS_TO_TICKS(SPI_MUTEX_WAIT_TIME_MS)) == pdTRUE) { err = 0; } @@ -85,7 +87,7 @@ int spi_mutex_give(void) if (spi_port0_mutex != NULL) { - xSemaphoreGive(spi_port0_mutex); + xSemaphoreGiveRecursive(spi_port0_mutex); err = 0; } From c197973e4190ed51da38ed719c327b685848a8e2 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 14 May 2024 22:13:04 -0300 Subject: [PATCH 05/31] firmware: tests: freertos_sim: Add recursive mutex simulation functions #346 --- firmware/tests/freertos_sim/semphr.c | 15 +++++++++++++++ firmware/tests/freertos_sim/semphr.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/firmware/tests/freertos_sim/semphr.c b/firmware/tests/freertos_sim/semphr.c index 5794f534..68d249b7 100644 --- a/firmware/tests/freertos_sim/semphr.c +++ b/firmware/tests/freertos_sim/semphr.c @@ -48,4 +48,19 @@ BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) return pdTRUE; } +SemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void) +{ + return (SemaphoreHandle_t) 0x01; +} + +BaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t xSemaphore, TickType_t xBlockTime) +{ + return pdTRUE; +} + +BaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t xSemaphore) +{ + return pdTRUE; +} + /** \} End of semphr_sim group */ diff --git a/firmware/tests/freertos_sim/semphr.h b/firmware/tests/freertos_sim/semphr.h index 3c072883..175351d4 100644 --- a/firmware/tests/freertos_sim/semphr.h +++ b/firmware/tests/freertos_sim/semphr.h @@ -55,6 +55,12 @@ BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xBlockTime); BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore); +SemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void); + +BaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t xSemaphore, TickType_t xBlockTime); + +BaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t xSemaphore); + #endif /* SEMPHR_SIM_H_ */ /** \} End of semphr_sim group */ From 0ed378a8c0cb33576069a650725158916d91b11b Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 14 May 2024 22:29:22 -0300 Subject: [PATCH 06/31] firmware: drivers: sl_ttc2: Update driver to use spi port mutex #346 --- firmware/drivers/sl_ttc2/sl_ttc2.c | 33 +++++-------------- firmware/drivers/sl_ttc2/sl_ttc2_mutex.c | 42 ++---------------------- 2 files changed, 12 insertions(+), 63 deletions(-) diff --git a/firmware/drivers/sl_ttc2/sl_ttc2.c b/firmware/drivers/sl_ttc2/sl_ttc2.c index 47df2694..1edfb8c4 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2.c +++ b/firmware/drivers/sl_ttc2/sl_ttc2.c @@ -70,38 +70,23 @@ int sl_ttc2_init(sl_ttc2_config_t config) { - static bool mutex_is_initialized = false; - int err = -1; - if (!mutex_is_initialized) + if (sl_ttc2_spi_init(config) == 0) { - err = sl_ttc2_mutex_create(); + sl_ttc2_delay_ms(10); - if (err == 0) + if (sl_ttc2_check_device(config) == 0) { - mutex_is_initialized = true; + err = 0; } } - - if (mutex_is_initialized) + else { - if (sl_ttc2_spi_init(config) == 0) - { - sl_ttc2_delay_ms(10); - - if (sl_ttc2_check_device(config) == 0) - { - err = 0; - } - } - else - { - #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) - sys_log_print_event_from_module(SYS_LOG_ERROR, SL_TTC2_MODULE_NAME, "Error initializing the SPI port!"); - sys_log_new_line(); - #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ - } + #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) + sys_log_print_event_from_module(SYS_LOG_ERROR, SL_TTC2_MODULE_NAME, "Error initializing the SPI port!"); + sys_log_new_line(); + #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ } return err; diff --git a/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c b/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c index ab6c5ccd..525b8848 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c +++ b/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c @@ -37,54 +37,18 @@ #include #include +#include #include "sl_ttc2.h" -static SemaphoreHandle_t sl_ttc2_mutex = NULL; - -int sl_ttc2_mutex_create(void) -{ - int err = 0; - - sl_ttc2_mutex = xSemaphoreCreateMutex(); - - if (sl_ttc2_mutex == NULL) - { - err = -1; - } - - return err; -} - int sl_ttc2_mutex_take(void) { - int err = -1; - - if (sl_ttc2_mutex != NULL) - { - /* See if we can obtain the semaphore. If the semaphore is not */ - /* available wait SL_TTC2_MUTEX_WAIT_TIME_MS ms to see if it becomes free */ - if (xSemaphoreTake(sl_ttc2_mutex, pdMS_TO_TICKS(SL_TTC2_MUTEX_WAIT_TIME_MS)) == pdTRUE) - { - err = 0; - } - } - - return err; + return spi_mutex_take(); } int sl_ttc2_mutex_give(void) { - int err = -1; - - if (sl_ttc2_mutex != NULL) - { - xSemaphoreGive(sl_ttc2_mutex); - - err = 0; - } - - return err; + return spi_mutex_give(); } /** \} End of sl_ttc2_mutex group */ From 07fbde5cc85de15c30e0564090e0d1fd536d676e Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 14 May 2024 22:44:01 -0300 Subject: [PATCH 07/31] firmware: tests: mockups: drivers: Add spi mutex mockup functions #346 --- firmware/tests/mockups/drivers/spi_wrap.c | 15 +++++++++++++++ firmware/tests/mockups/drivers/spi_wrap.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/firmware/tests/mockups/drivers/spi_wrap.c b/firmware/tests/mockups/drivers/spi_wrap.c index 85c5b91e..34fefc88 100644 --- a/firmware/tests/mockups/drivers/spi_wrap.c +++ b/firmware/tests/mockups/drivers/spi_wrap.c @@ -108,4 +108,19 @@ int __wrap_spi_transfer(spi_port_t port, spi_cs_t cs, uint8_t *wd, uint8_t *rd, return mock_type(int); } +int __wrap_spi_mutex_create(void) +{ + return mock_type(int); +} + +int __wrap_spi_mutex_take(void) +{ + return mock_type(int); +} + +int __wrap_spi_mutex_give(void) +{ + return mock_type(int); +} + /** \} End of spi_wrap group */ diff --git a/firmware/tests/mockups/drivers/spi_wrap.h b/firmware/tests/mockups/drivers/spi_wrap.h index 77e1529a..b58f5b23 100644 --- a/firmware/tests/mockups/drivers/spi_wrap.h +++ b/firmware/tests/mockups/drivers/spi_wrap.h @@ -51,6 +51,12 @@ int __wrap_spi_read(spi_port_t port, spi_cs_t cs, uint8_t *data, uint16_t len); int __wrap_spi_transfer(spi_port_t port, spi_cs_t cs, uint8_t *wd, uint8_t *rd, uint16_t len); +int __wrap_spi_mutex_create(void); + +int __wrap_spi_mutex_take(void); + +int __wrap_spi_mutex_give(void); + #endif /* SPI_WRAP_H_ */ /** \} End of spi_wrap group */ From 3f2234f80a3aaabf9f623bbf21a186b5c2f84855 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 14 May 2024 22:44:47 -0300 Subject: [PATCH 08/31] firmware: tests: mockups: drivers: Remove unnecessary mockup function --- firmware/tests/mockups/drivers/sl_ttc2_wrap.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/firmware/tests/mockups/drivers/sl_ttc2_wrap.c b/firmware/tests/mockups/drivers/sl_ttc2_wrap.c index 99f5db2e..4d0a33d6 100644 --- a/firmware/tests/mockups/drivers/sl_ttc2_wrap.c +++ b/firmware/tests/mockups/drivers/sl_ttc2_wrap.c @@ -491,11 +491,6 @@ int __wrap_sl_ttc2_read_packet(sl_ttc2_config_t config, uint8_t *data, uint16_t return mock_type(int); } -int __wrap_sl_ttc2_mutex_create(void) -{ - return mock_type(int); -} - int __wrap_sl_ttc2_mutex_take(void) { return mock_type(int); From 92050c31eaa9c4c4da67460a13cd4b85011faf22 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Tue, 14 May 2024 22:45:40 -0300 Subject: [PATCH 09/31] firmware: tests: drivers: Update sl_ttc2 driver test #346 --- firmware/tests/drivers/Makefile | 2 +- firmware/tests/drivers/sl_ttc2_test.c | 31 ++++++++++++--------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/firmware/tests/drivers/Makefile b/firmware/tests/drivers/Makefile index 7a0873a3..a75b03bb 100644 --- a/firmware/tests/drivers/Makefile +++ b/firmware/tests/drivers/Makefile @@ -29,7 +29,7 @@ SL_EPS2_TEST_FLAGS=$(FLAGS),--wrap=tca4311a_init,--wrap=tca4311a_enable,--wrap=t MT25Q_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle -SL_TTC2_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle,--wrap=sl_ttc2_mutex_create,--wrap=sl_ttc2_mutex_take,--wrap=sl_ttc2_mutex_give,--wrap=sl_ttc2_spi_read +SL_TTC2_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle,--wrap=spi_mutex_take,--wrap=spi_mutex_give,--wrap=sl_ttc2_spi_read .PHONY: all .PHONY: all diff --git a/firmware/tests/drivers/sl_ttc2_test.c b/firmware/tests/drivers/sl_ttc2_test.c index 3bc60951..b33936ca 100644 --- a/firmware/tests/drivers/sl_ttc2_test.c +++ b/firmware/tests/drivers/sl_ttc2_test.c @@ -60,9 +60,6 @@ static inline void read_adr(uint8_t adr, uint32_t val); static void sl_ttc2_init_test(void **state) { - /* Mutex creation */ - will_return(__wrap_sl_ttc2_mutex_create, 0); - /* SPI init */ expect_value(__wrap_spi_init, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_init, config.speed_hz, SL_TTC2_SPI_CLOCK_HZ); @@ -84,7 +81,7 @@ static void sl_ttc2_init_test(void **state) ans[3] = 0xCC; /* Radio 0 ID */ ans[4] = 0x2A; /* Radio 0 ID */ - will_return(__wrap_sl_ttc2_mutex_take, 0); + will_return(__wrap_spi_mutex_take, 0); expect_value(__wrap_spi_write, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_write, cs, SL_TTC2_SPI_CS); @@ -107,7 +104,7 @@ static void sl_ttc2_init_test(void **state) will_return(__wrap_sl_ttc2_spi_read, 0); - will_return(__wrap_sl_ttc2_mutex_give, 0); + will_return(__wrap_spi_mutex_give, 0); assert_return_code(sl_ttc2_init(conf), 0); } @@ -241,7 +238,7 @@ static void sl_ttc2_write_reg_test(void **state) break; } - will_return(__wrap_sl_ttc2_mutex_take, 0); + will_return(__wrap_spi_mutex_take, 0); expect_value(__wrap_spi_write, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_write, cs, SL_TTC2_SPI_CS); @@ -250,7 +247,7 @@ static void sl_ttc2_write_reg_test(void **state) will_return(__wrap_spi_write, 0); - will_return(__wrap_sl_ttc2_mutex_give, 0); + will_return(__wrap_spi_mutex_give, 0); assert_return_code(sl_ttc2_write_reg(conf, adr, val), 0); } @@ -375,7 +372,7 @@ static void sl_ttc2_read_reg_test(void **state) break; } - will_return(__wrap_sl_ttc2_mutex_take, 0); + will_return(__wrap_spi_mutex_take, 0); expect_value(__wrap_spi_write, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_write, cs, SL_TTC2_SPI_CS); @@ -398,7 +395,7 @@ static void sl_ttc2_read_reg_test(void **state) will_return(__wrap_sl_ttc2_spi_read, 0); - will_return(__wrap_sl_ttc2_mutex_give, 0); + will_return(__wrap_spi_mutex_give, 0); assert_return_code(sl_ttc2_read_reg(conf, adr, &res), 0); @@ -762,7 +759,7 @@ static void sl_ttc2_set_tx_enable_test(void **state) cmd[2] = adr; /* Address */ cmd[3] = val; - will_return(__wrap_sl_ttc2_mutex_take, 0); + will_return(__wrap_spi_mutex_take, 0); expect_value(__wrap_spi_write, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_write, cs, SL_TTC2_SPI_CS); @@ -771,7 +768,7 @@ static void sl_ttc2_set_tx_enable_test(void **state) will_return(__wrap_spi_write, 0); - will_return(__wrap_sl_ttc2_mutex_give, 0); + will_return(__wrap_spi_mutex_give, 0); assert_return_code(sl_ttc2_set_tx_enable(conf, (bool)val), 0); } @@ -873,7 +870,7 @@ static void sl_ttc2_transmit_packet_test(void **state) cmd[1] = SL_TTC2_CMD_TRANSMIT_PKT; /* Transmit packet command */ cmd[2] = data_len; /* Data lenght */ - will_return(__wrap_sl_ttc2_mutex_take, 0); + will_return(__wrap_spi_mutex_take, 0); expect_value(__wrap_spi_write, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_write, cs, SL_TTC2_SPI_CS); @@ -895,7 +892,7 @@ static void sl_ttc2_transmit_packet_test(void **state) will_return(__wrap_spi_write, 0); - will_return(__wrap_sl_ttc2_mutex_give, 0); + will_return(__wrap_spi_mutex_give, 0); assert_return_code(sl_ttc2_transmit_packet(conf, &cmd[3], data_len), 0); } @@ -924,7 +921,7 @@ static void sl_ttc2_read_packet_test(void **state) read_adr(adr, (uint32_t)pkt_len); - will_return(__wrap_sl_ttc2_mutex_take, 0); + will_return(__wrap_spi_mutex_take, 0); expect_value(__wrap_spi_write, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_write, cs, SL_TTC2_SPI_CS); @@ -951,7 +948,7 @@ static void sl_ttc2_read_packet_test(void **state) will_return(__wrap_sl_ttc2_spi_read, 0); - will_return(__wrap_sl_ttc2_mutex_give, 0); + will_return(__wrap_spi_mutex_give, 0); assert_return_code(sl_ttc2_read_packet(conf, res_pkt, &res_pkt_len), 0); @@ -1120,7 +1117,7 @@ static inline void read_adr(uint8_t adr, uint32_t val) break; } - will_return(__wrap_sl_ttc2_mutex_take, 0); + will_return(__wrap_spi_mutex_take, 0); expect_value(__wrap_spi_write, port, SL_TTC2_SPI_PORT); expect_value(__wrap_spi_write, cs, SL_TTC2_SPI_CS); @@ -1143,7 +1140,7 @@ static inline void read_adr(uint8_t adr, uint32_t val) will_return(__wrap_sl_ttc2_spi_read, 0); - will_return(__wrap_sl_ttc2_mutex_give, 0); + will_return(__wrap_spi_mutex_give, 0); } /** \} End of sl_ttc2_test group */ From e877c829b3bc4bab5b7824e3fe059a42b9c3dd29 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 15 May 2024 14:24:14 -0300 Subject: [PATCH 10/31] firmware: drivers: mt25q: Fix write enable/disable function #346 --- firmware/drivers/mt25q/mt25q.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/drivers/mt25q/mt25q.c b/firmware/drivers/mt25q/mt25q.c index aa588389..c767ac44 100644 --- a/firmware/drivers/mt25q/mt25q.c +++ b/firmware/drivers/mt25q/mt25q.c @@ -300,6 +300,7 @@ int mt25q_write_enable(void) if (status.write_enable_latch == MT25Q_WRITE_ENABLED) { err = 0; + break; } } } @@ -326,6 +327,7 @@ int mt25q_write_disable(void) if (status.write_enable_latch == MT25Q_WRITE_DISABLED) { err = 0; + break; } } } From 8cd4a77c67d66603fb391d16390ab61cdf089567 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 15 May 2024 22:25:15 -0300 Subject: [PATCH 11/31] firmware: drivers: sl_ttc2: Update sl_ttc2 mutex related definitions --- firmware/drivers/sl_ttc2/sl_ttc2.h | 7 ------- firmware/drivers/sl_ttc2/sl_ttc2_mutex.c | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/firmware/drivers/sl_ttc2/sl_ttc2.h b/firmware/drivers/sl_ttc2/sl_ttc2.h index c709dd60..ef927ffd 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2.h +++ b/firmware/drivers/sl_ttc2/sl_ttc2.h @@ -591,13 +591,6 @@ int sl_ttc2_spi_transfer(sl_ttc2_config_t config, uint8_t *wdata, uint8_t *rdata */ void sl_ttc2_delay_ms(uint32_t ms); -/** - * \brief Creates the sl_ttc2 create. - * - * \return The status/error code. - */ -int sl_ttc2_mutex_create(void); - /** * \brief Takes the sl_ttc2 mutex. * diff --git a/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c b/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c index 525b8848..30f64e61 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c +++ b/firmware/drivers/sl_ttc2/sl_ttc2_mutex.c @@ -21,7 +21,7 @@ */ /** - * \brief SpaceLab TTC 2.0 driver mutex definition. + * \brief SpaceLab TTC 2.0 driver mutex implementation. * * \author Carlos Augusto Porto Freitas * From 1acb2654b76b6375f96ef1167d114dd1625e69b3 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 15 May 2024 23:26:37 -0300 Subject: [PATCH 12/31] firmware: drivers: mt25q: Add mt25q mutex functions #346 --- firmware/drivers/mt25q/mt25q_mutex.c | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 firmware/drivers/mt25q/mt25q_mutex.c diff --git a/firmware/drivers/mt25q/mt25q_mutex.c b/firmware/drivers/mt25q/mt25q_mutex.c new file mode 100644 index 00000000..404a51b8 --- /dev/null +++ b/firmware/drivers/mt25q/mt25q_mutex.c @@ -0,0 +1,54 @@ +/* + * mt25q_mutex.c + * + * Copyright The OBDH 2.0 Contributors + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief Mt25q driver mutex implementation. + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.15 + * + * \date 2024/02/26 + * + * \addtogroup mt25q + * \{ + */ + +#include + +#include +#include +#include + +#include "mt25q.h" + +int mt25q_mutex_take(void) +{ + return spi_mutex_take(); +} + +int mt25q_mutex_give(void) +{ + return spi_mutex_give(); +} + +/** \} End of mt25q group */ From 93c842ff256bc0b90d4861655abdf6bf919db35a Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 15 May 2024 23:27:14 -0300 Subject: [PATCH 13/31] firmware: drivers: mt25q: Update mt25q driver to use the spi port mutex #346 --- firmware/drivers/mt25q/mt25q.c | 518 ++++++++++++++++++--------------- firmware/drivers/mt25q/mt25q.h | 14 + 2 files changed, 298 insertions(+), 234 deletions(-) diff --git a/firmware/drivers/mt25q/mt25q.c b/firmware/drivers/mt25q/mt25q.c index c767ac44..d21ed7f2 100644 --- a/firmware/drivers/mt25q/mt25q.c +++ b/firmware/drivers/mt25q/mt25q.c @@ -84,13 +84,18 @@ int mt25q_read_device_id(mt25q_dev_id_t *dev_id) uint8_t cmd[4] = {MT25Q_READ_ID_REG, MT25Q_DUMMY_BYTE, MT25Q_DUMMY_BYTE, MT25Q_DUMMY_BYTE}; uint8_t ans[4] = {0}; - if (mt25q_spi_transfer(cmd, ans, 4) == 0) + if (mt25q_mutex_take() == 0) { - dev_id->manufacturer_id = ans[1]; - dev_id->memory_type = ans[2]; - dev_id->memory_capacity = ans[3]; + if (mt25q_spi_transfer(cmd, ans, 4) == 0) + { + dev_id->manufacturer_id = ans[1]; + dev_id->memory_type = ans[2]; + dev_id->memory_capacity = ans[3]; - err = 0; + err = 0; + } + + (void)mt25q_mutex_give(); } return err; @@ -129,97 +134,112 @@ int mt25q_read_flash_description(flash_description_t *fdo) cmd[0] = MT25Q_READ_SERIAL_FLASH_DISCOVERY_PARAMETER_REG; - if (mt25q_spi_transfer(cmd, ans, 350) == 0) + if (mt25q_mutex_take() == 0) { - /* Remove the SPI command, address and dummy clocks */ - if (memmove(ans, &ans[5], 350) == ans) /* 5 = SPI command + address + dummy clocks */ + if (mt25q_spi_transfer(cmd, ans, 350) == 0) { - /* Check if the read data is valid */ - uint8_t sfdp[6] = {'S', 'F', 'D', 'P', 0, 164}; - if ((ans != NULL) && (memcmp(ans, sfdp, 4) == 0)) + (void)mt25q_mutex_give(); + + /* Remove the SPI command, address and dummy clocks */ + if (memmove(ans, &ans[5], 350) == ans) /* 5 = SPI command + address + dummy clocks */ { - /* The parameter table pointer is at MT25Q_DISCOVERY_TABLE_1 */ - uint32_t table_address = (uint32_t)ans[MT25Q_DISCOVERY_TABLE_1] | - ((uint32_t)ans[MT25Q_DISCOVERY_TABLE_1 + 1U] << 8) | - ((uint32_t)ans[MT25Q_DISCOVERY_TABLE_1 + 2U] << 16); - - /* Get the official device size in bytes */ - uint32_t size_buf = (uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE] | - ((uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE + 1U] << 8) | - ((uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE + 2U] << 16) | - ((uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE + 3U] << 24); - fdo->size = (size_buf + 1U) / 8U; - - /* Get the largest sector size and the sector count, and take one sub-sector size and sub-sector count. */ - /* The first two sector definitions have the definitions that we use - usually 4K and 64K. */ - uint32_t t_offset = table_address + MT25Q_DTABLE_1_SECTOR_DESCRIPTOR + 2U; - - if (ans[t_offset] != 0U) + /* Check if the read data is valid */ + uint8_t sfdp[6] = {'S', 'F', 'D', 'P', 0, 164}; + if ((ans != NULL) && (memcmp(ans, sfdp, 4) == 0)) { - fdo->sector_size_bit = ans[t_offset]; - /* fdo->sector_size = (1 << (ans[t_offset])); */ - fdo->sector_size = 1; - uint8_t i = 0; - for(i = 0; i < ans[t_offset]; i++) + /* The parameter table pointer is at MT25Q_DISCOVERY_TABLE_1 */ + uint32_t table_address = (uint32_t)ans[MT25Q_DISCOVERY_TABLE_1] | + ((uint32_t)ans[MT25Q_DISCOVERY_TABLE_1 + 1U] << 8) | + ((uint32_t)ans[MT25Q_DISCOVERY_TABLE_1 + 2U] << 16); + + /* Get the official device size in bytes */ + uint32_t size_buf = (uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE] | + ((uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE + 1U] << 8) | + ((uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE + 2U] << 16) | + ((uint32_t)ans[table_address + MT25Q_DTABLE_1_FLASH_SIZE + 3U] << 24); + fdo->size = (size_buf + 1U) / 8U; + + /* Get the largest sector size and the sector count, and take one sub-sector size and sub-sector count. */ + /* The first two sector definitions have the definitions that we use - usually 4K and 64K. */ + uint32_t t_offset = table_address + MT25Q_DTABLE_1_SECTOR_DESCRIPTOR + 2U; + + if (ans[t_offset] != 0U) { - fdo->sector_size = (fdo->sector_size << 1); - } - fdo->sector_count = fdo->size / fdo->sector_size; - fdo->sector_erase_cmd = ans[t_offset + 1U]; + fdo->sector_size_bit = ans[t_offset]; + /* fdo->sector_size = (1 << (ans[t_offset])); */ + fdo->sector_size = 1; + uint8_t i = 0; + for(i = 0; i < ans[t_offset]; i++) + { + fdo->sector_size = (fdo->sector_size << 1); + } + fdo->sector_count = fdo->size / fdo->sector_size; + fdo->sector_erase_cmd = ans[t_offset + 1U]; - fdo->sub_sector_size_bit = ans[t_offset - 2U]; - /* fdo->sub_sector_size = (1 << (ans[t_offset - 2])); */ - fdo->sub_sector_size = 1; - for(i = 0; i < ans[t_offset - 2U]; i++) - { - fdo->sub_sector_size = (fdo->sub_sector_size << 1); + fdo->sub_sector_size_bit = ans[t_offset - 2U]; + /* fdo->sub_sector_size = (1 << (ans[t_offset - 2])); */ + fdo->sub_sector_size = 1; + for(i = 0; i < ans[t_offset - 2U]; i++) + { + fdo->sub_sector_size = (fdo->sub_sector_size << 1); + } + fdo->sub_sector_count = fdo->size / fdo->sub_sector_size; + fdo->sub_sector_erase_cmd = ans[t_offset - 1U]; } - fdo->sub_sector_count = fdo->size / fdo->sub_sector_size; - fdo->sub_sector_erase_cmd = ans[t_offset - 1U]; - } - - /* Hard-coded flash parameters */ - fdo->page_size = 0x100U; - fdo->page_count = fdo->size / fdo->page_size; - fdo->address_mask = 0xFFU; - fdo->otp_size = 0x40U; + /* Hard-coded flash parameters */ + fdo->page_size = 0x100U; + fdo->page_count = fdo->size / fdo->page_size; + fdo->address_mask = 0xFFU; - /* Initial Die information */ - if (fdo->size > MT25Q_SIZE_64MB) - { - fdo->die_count = fdo->size / MT25Q_SIZE_64MB; - fdo->die_size = MT25Q_SIZE_64MB; - fdo->die_size_bit = 26; - } + fdo->otp_size = 0x40U; - /* Auto detect address mode */ - if (fdo->size > MT25Q_SIZE_16MB) - { - uint8_t flag = 0; + /* Initial Die information */ + if (fdo->size > MT25Q_SIZE_64MB) + { + fdo->die_count = fdo->size / MT25Q_SIZE_64MB; + fdo->die_size = MT25Q_SIZE_64MB; + fdo->die_size_bit = 26; + } - if (mt25q_enter_4_byte_address_mode() == 0) + /* Auto detect address mode */ + if (fdo->size > MT25Q_SIZE_16MB) { - /* Verify current address mode */ - if (mt25q_read_flag_status_register(&flag) == 0) + uint8_t flag = 0; + + if (mt25q_mutex_take() == 0) { - if ((flag & 1U) > 0U) /* Test addressing bit of flag status reg (bit 0) */ + if (mt25q_enter_4_byte_address_mode() == 0) { - fdo->num_adr_byte = MT25Q_ADDRESS_MODE_4_BYTE; + /* Verify current address mode */ + if (mt25q_read_flag_status_register(&flag) == 0) + { + if ((flag & 1U) > 0U) /* Test addressing bit of flag status reg (bit 0) */ + { + fdo->num_adr_byte = MT25Q_ADDRESS_MODE_4_BYTE; + } + + err = 0; + } } - err = 0; + (void)mt25q_mutex_give(); } } - } - else - { - fdo->num_adr_byte = MT25Q_ADDRESS_MODE_3_BYTE; + else + { + fdo->num_adr_byte = MT25Q_ADDRESS_MODE_3_BYTE; - err = 0; + err = 0; + } } } } + else + { + /* If the transfer fails the mutex has be to given here to prevent a deadlock */ + (void)mt25q_mutex_give(); + } } } } @@ -368,58 +388,61 @@ int mt25q_die_erase(mt25q_sector_t die) die_adr <<= 1; } - /* Check whether any previous Write, Program or Erase cycle is on-going */ - if (!mt25q_is_busy()) + if (mt25q_mutex_take() == 0) { - /* Disable Write protection */ - if (mt25q_write_enable() == 0) + /* Check whether any previous Write, Program or Erase cycle is on-going */ + if (!mt25q_is_busy()) { - uint8_t cmd = MT25Q_DIE_ERASE; - uint8_t adr_arr[4] = {0}; - - if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) - { - adr_arr[0] = (uint8_t)((die_adr >> 16) & 0xFFU); - adr_arr[1] = (uint8_t)((die_adr >> 8) & 0xFFU); - adr_arr[2] = (uint8_t)((die_adr >> 0) & 0xFFU); - } - else + /* Disable Write protection */ + if (mt25q_write_enable() == 0) { - adr_arr[0] = (uint8_t)((die_adr >> 24) & 0xFFU); - adr_arr[1] = (uint8_t)((die_adr >> 16) & 0xFFU); - adr_arr[2] = (uint8_t)((die_adr >> 8) & 0xFFU); - adr_arr[3] = (uint8_t)((die_adr >> 0) & 0xFFU); - } + uint8_t cmd = MT25Q_DIE_ERASE; + uint8_t adr_arr[4] = {0}; - if (mt25q_spi_select() == 0) - { - /* Write the erase command */ - if (mt25q_spi_write_only(&cmd, 1) == 0) + if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) + { + adr_arr[0] = (uint8_t)((die_adr >> 16) & 0xFFU); + adr_arr[1] = (uint8_t)((die_adr >> 8) & 0xFFU); + adr_arr[2] = (uint8_t)((die_adr >> 0) & 0xFFU); + } + else + { + adr_arr[0] = (uint8_t)((die_adr >> 24) & 0xFFU); + adr_arr[1] = (uint8_t)((die_adr >> 16) & 0xFFU); + adr_arr[2] = (uint8_t)((die_adr >> 8) & 0xFFU); + adr_arr[3] = (uint8_t)((die_adr >> 0) & 0xFFU); + } + + if (mt25q_spi_select() == 0) { - /* Write the address */ - if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) + /* Write the erase command */ + if (mt25q_spi_write_only(&cmd, 1) == 0) { - if (mt25q_spi_unselect() == 0) + /* Write the address */ + if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) { - /* Wait till complete */ - for(i = 0; i < MT25Q_SECTOR_ERASE_TIMEOUT_MS; i++) + if (mt25q_spi_unselect() == 0) { - if (!mt25q_is_busy()) + /* Wait till complete */ + for(i = 0; i < MT25Q_SECTOR_ERASE_TIMEOUT_MS; i++) { - break; - } + if (!mt25q_is_busy()) + { + break; + } - mt25q_delay_ms(1); - } + mt25q_delay_ms(1); + } - uint8_t flag = 0; - if (mt25q_read_flag_status_register(&flag) == 0) - { - if (mt25q_clear_flag_status_register() == 0) + uint8_t flag = 0; + if (mt25q_read_flag_status_register(&flag) == 0) { - if (i < MT25Q_SECTOR_ERASE_TIMEOUT_MS) + if (mt25q_clear_flag_status_register() == 0) { - err = 0; + if (i < MT25Q_SECTOR_ERASE_TIMEOUT_MS) + { + err = 0; + } } } } @@ -428,6 +451,8 @@ int mt25q_die_erase(mt25q_sector_t die) } } } + + (void)mt25q_mutex_give(); } } @@ -449,58 +474,61 @@ int mt25q_sector_erase(mt25q_sector_t sector) sector_adr <<= 1; } - /* Check whether any previous Write, Program or Erase cycle is on-going */ - if (!mt25q_is_busy()) + if (mt25q_mutex_take() == 0) { - /* Disable Write protection */ - if (mt25q_write_enable() == 0) + /* Check whether any previous Write, Program or Erase cycle is on-going */ + if (!mt25q_is_busy()) { - uint8_t cmd = mt25q_fdo.sector_erase_cmd; - uint8_t adr_arr[4] = {0}; - - if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) - { - adr_arr[0] = (uint8_t)((sector_adr >> 16) & 0xFFU); - adr_arr[1] = (uint8_t)((sector_adr >> 8) & 0xFFU); - adr_arr[2] = (uint8_t)((sector_adr >> 0) & 0xFFU); - } - else + /* Disable Write protection */ + if (mt25q_write_enable() == 0) { - adr_arr[0] = (uint8_t)((sector_adr >> 24) & 0xFFU); - adr_arr[1] = (uint8_t)((sector_adr >> 16) & 0xFFU); - adr_arr[2] = (uint8_t)((sector_adr >> 8) & 0xFFU); - adr_arr[3] = (uint8_t)((sector_adr >> 0) & 0xFFU); - } + uint8_t cmd = mt25q_fdo.sector_erase_cmd; + uint8_t adr_arr[4] = {0}; - if (mt25q_spi_select() == 0) - { - /* Write the erase command */ - if (mt25q_spi_write_only(&cmd, 1) == 0) + if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) + { + adr_arr[0] = (uint8_t)((sector_adr >> 16) & 0xFFU); + adr_arr[1] = (uint8_t)((sector_adr >> 8) & 0xFFU); + adr_arr[2] = (uint8_t)((sector_adr >> 0) & 0xFFU); + } + else + { + adr_arr[0] = (uint8_t)((sector_adr >> 24) & 0xFFU); + adr_arr[1] = (uint8_t)((sector_adr >> 16) & 0xFFU); + adr_arr[2] = (uint8_t)((sector_adr >> 8) & 0xFFU); + adr_arr[3] = (uint8_t)((sector_adr >> 0) & 0xFFU); + } + + if (mt25q_spi_select() == 0) { - /* Write the address */ - if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) + /* Write the erase command */ + if (mt25q_spi_write_only(&cmd, 1) == 0) { - if (mt25q_spi_unselect() == 0) + /* Write the address */ + if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) { - /* Wait till complete */ - for(i = 0; i < MT25Q_SECTOR_ERASE_TIMEOUT_MS; i++) + if (mt25q_spi_unselect() == 0) { - if (!mt25q_is_busy()) + /* Wait till complete */ + for(i = 0; i < MT25Q_SECTOR_ERASE_TIMEOUT_MS; i++) { - break; - } + if (!mt25q_is_busy()) + { + break; + } - mt25q_delay_ms(1); - } + mt25q_delay_ms(1); + } - uint8_t flag = 0; - if (mt25q_read_flag_status_register(&flag) == 0) - { - if (mt25q_clear_flag_status_register() == 0) + uint8_t flag = 0; + if (mt25q_read_flag_status_register(&flag) == 0) { - if (i < MT25Q_SECTOR_ERASE_TIMEOUT_MS) + if (mt25q_clear_flag_status_register() == 0) { - err = 0; + if (i < MT25Q_SECTOR_ERASE_TIMEOUT_MS) + { + err = 0; + } } } } @@ -509,6 +537,8 @@ int mt25q_sector_erase(mt25q_sector_t sector) } } } + + (void)mt25q_mutex_give(); } } @@ -530,58 +560,61 @@ int mt25q_sub_sector_erase(mt25q_sector_t sub) sub_sector_adr <<= 1; } - /* Check whether any previous Write, Program or Erase cycle is on-going */ - if (!mt25q_is_busy()) + if (mt25q_mutex_take() == 0) { - /* Disable Write protection */ - if (mt25q_write_enable() == 0) + /* Check whether any previous Write, Program or Erase cycle is on-going */ + if (!mt25q_is_busy()) { - uint8_t cmd = mt25q_fdo.sub_sector_erase_cmd; - uint8_t adr_arr[4] = {0}; - - if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) - { - adr_arr[0] = (uint8_t)((sub_sector_adr >> 16) & 0xFFU); - adr_arr[1] = (uint8_t)((sub_sector_adr >> 8) & 0xFFU); - adr_arr[2] = (uint8_t)((sub_sector_adr >> 0) & 0xFFU); - } - else + /* Disable Write protection */ + if (mt25q_write_enable() == 0) { - adr_arr[0] = (uint8_t)((sub_sector_adr >> 24) & 0xFFU); - adr_arr[1] = (uint8_t)((sub_sector_adr >> 16) & 0xFFU); - adr_arr[2] = (uint8_t)((sub_sector_adr >> 8) & 0xFFU); - adr_arr[3] = (uint8_t)((sub_sector_adr >> 0) & 0xFFU); - } + uint8_t cmd = mt25q_fdo.sub_sector_erase_cmd; + uint8_t adr_arr[4] = {0}; - if (mt25q_spi_select() == 0) - { - /* Write the erase command */ - if (mt25q_spi_write_only(&cmd, 1) == 0) + if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) { - /* Write the address */ - if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) + adr_arr[0] = (uint8_t)((sub_sector_adr >> 16) & 0xFFU); + adr_arr[1] = (uint8_t)((sub_sector_adr >> 8) & 0xFFU); + adr_arr[2] = (uint8_t)((sub_sector_adr >> 0) & 0xFFU); + } + else + { + adr_arr[0] = (uint8_t)((sub_sector_adr >> 24) & 0xFFU); + adr_arr[1] = (uint8_t)((sub_sector_adr >> 16) & 0xFFU); + adr_arr[2] = (uint8_t)((sub_sector_adr >> 8) & 0xFFU); + adr_arr[3] = (uint8_t)((sub_sector_adr >> 0) & 0xFFU); + } + + if (mt25q_spi_select() == 0) + { + /* Write the erase command */ + if (mt25q_spi_write_only(&cmd, 1) == 0) { - if (mt25q_spi_unselect() == 0) + /* Write the address */ + if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) { - /* Wait till complete */ - for(i = 0; i < MT25Q_SECTOR_ERASE_TIMEOUT_MS; i++) + if (mt25q_spi_unselect() == 0) { - if (!mt25q_is_busy()) + /* Wait till complete */ + for(i = 0; i < MT25Q_SECTOR_ERASE_TIMEOUT_MS; i++) { - break; - } + if (!mt25q_is_busy()) + { + break; + } - mt25q_delay_ms(1); - } + mt25q_delay_ms(1); + } - uint8_t flag = 0; - if (mt25q_read_flag_status_register(&flag) == 0) - { - if (mt25q_clear_flag_status_register() == 0) + uint8_t flag = 0; + if (mt25q_read_flag_status_register(&flag) == 0) { - if (i < MT25Q_SECTOR_ERASE_TIMEOUT_MS) + if (mt25q_clear_flag_status_register() == 0) { - err = 0; + if (i < MT25Q_SECTOR_ERASE_TIMEOUT_MS) + { + err = 0; + } } } } @@ -590,6 +623,8 @@ int mt25q_sub_sector_erase(mt25q_sector_t sub) } } } + + (void)mt25q_mutex_give(); } } @@ -600,56 +635,61 @@ int mt25q_write(uint32_t adr, uint8_t *data, uint16_t len) { int err = -1; - if (mt25q_write_enable() == 0) + if (mt25q_mutex_take() == 0) { - /* Computing the starting alignment, i.e. the distance from the page boundary */ - uint16_t data_offset = (mt25q_fdo.page_size - (adr & mt25q_fdo.address_mask)) & mt25q_fdo.address_mask; - - if (data_offset > len) + if (mt25q_write_enable() == 0) { - data_offset = len; - } + /* Computing the starting alignment, i.e. the distance from the page boundary */ + uint16_t data_offset = (mt25q_fdo.page_size - (adr & mt25q_fdo.address_mask)) & mt25q_fdo.address_mask; - uint8_t prog_instr = UINT8_MAX; - if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) - { - prog_instr = MT25Q_PAGE_PROGRAM; - } - else - { - prog_instr = MT25Q_4_BYTE_PAGE_PROGRAM; - } - - err = 0; + if (data_offset > len) + { + data_offset = len; + } - if (data_offset > 0U) - { - if (mt25q_gen_program(adr, data, data_offset, prog_instr) != 0) + uint8_t prog_instr = UINT8_MAX; + if (mt25q_fdo.num_adr_byte == MT25Q_ADDRESS_MODE_3_BYTE) { - err = -1; + prog_instr = MT25Q_PAGE_PROGRAM; + } + else + { + prog_instr = MT25Q_4_BYTE_PAGE_PROGRAM; } - } - if (err == 0) - { - for(; (data_offset + mt25q_fdo.page_size) < len; data_offset += mt25q_fdo.page_size) + err = 0; + + if (data_offset > 0U) { - if (mt25q_gen_program(adr + data_offset, &data[data_offset], mt25q_fdo.page_size, prog_instr) != 0) + if (mt25q_gen_program(adr, data, data_offset, prog_instr) != 0) { err = -1; - - break; } } if (err == 0) { - if (len > data_offset) + for(; (data_offset + mt25q_fdo.page_size) < len; data_offset += mt25q_fdo.page_size) + { + if (mt25q_gen_program(adr + data_offset, &data[data_offset], mt25q_fdo.page_size, prog_instr) != 0) + { + err = -1; + + break; + } + } + + if (err == 0) { - err = mt25q_gen_program(adr + data_offset, &data[data_offset], (len - data_offset), prog_instr); + if (len > data_offset) + { + err = mt25q_gen_program(adr + data_offset, &data[data_offset], (len - data_offset), prog_instr); + } } } } + + (void)mt25q_mutex_give(); } return err; @@ -679,24 +719,29 @@ int mt25q_read(uint32_t adr, uint8_t *data, uint16_t len) adr_arr[3] = (uint8_t)((adr >> 0) & 0xFFU); } - if (mt25q_spi_select() == 0) + if (mt25q_mutex_take() == 0) { - /* Write the READ command */ - if (mt25q_spi_write_only(&cmd, 1) == 0) + if (mt25q_spi_select() == 0) { - /* Write the address */ - if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) + /* Write the READ command */ + if (mt25q_spi_write_only(&cmd, 1) == 0) { - /* Read the data */ - if (mt25q_spi_read_only(data, len) == 0) + /* Write the address */ + if (mt25q_spi_write_only(adr_arr, mt25q_fdo.num_adr_byte) == 0) { - if (mt25q_spi_unselect() == 0) + /* Read the data */ + if (mt25q_spi_read_only(data, len) == 0) { - err = 0; + if (mt25q_spi_unselect() == 0) + { + err = 0; + } } } } } + + (void)mt25q_mutex_give(); } } @@ -744,11 +789,16 @@ int mt25q_read_flag_status_register(uint8_t *flag) uint8_t cmd[2] = {MT25Q_READ_FLAG_STATUS_REGISTER, MT25Q_DUMMY_BYTE}; uint8_t ans[2] = {0}; - if (mt25q_spi_transfer(cmd, ans, 2) == 0) + if (mt25q_mutex_take() == 0) { - *flag = ans[1]; + if (mt25q_spi_transfer(cmd, ans, 2) == 0) + { + *flag = ans[1]; - err = 0; + err = 0; + } + + (void)mt25q_mutex_give(); } return err; diff --git a/firmware/drivers/mt25q/mt25q.h b/firmware/drivers/mt25q/mt25q.h index 2f1af0c3..a12316aa 100644 --- a/firmware/drivers/mt25q/mt25q.h +++ b/firmware/drivers/mt25q/mt25q.h @@ -473,6 +473,20 @@ int mt25q_gpio_set_reset(bool state); */ void mt25q_delay_ms(uint32_t ms); +/** + * \brief Takes the mt25q mutex. + * + * \return The status/error code. + */ +int mt25q_mutex_take(void); + +/** + * \brief Gives the mt25q mutex. + * + * \return The status/error code. + */ +int mt25q_mutex_give(void); + #endif /* MT25Q_H_ */ /** \} End of mt25q group */ From d1917aa5499ee4b8ce4cd32a539e60ab0ad1d855 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 15 May 2024 23:37:47 -0300 Subject: [PATCH 14/31] firmware: drivers: cy15x102qn: Add cy15x102qn mutex functions #346 --- firmware/drivers/cy15x102qn/cy15x102qn.h | 14 +++++ .../drivers/cy15x102qn/cy15x102qn_mutex.c | 54 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 firmware/drivers/cy15x102qn/cy15x102qn_mutex.c diff --git a/firmware/drivers/cy15x102qn/cy15x102qn.h b/firmware/drivers/cy15x102qn/cy15x102qn.h index 3f919550..98f68dcd 100644 --- a/firmware/drivers/cy15x102qn/cy15x102qn.h +++ b/firmware/drivers/cy15x102qn/cy15x102qn.h @@ -621,6 +621,20 @@ int cy15x102qn_gpio_set_write_protect(cy15x102qn_config_t *conf); */ int cy15x102qn_gpio_clear_write_protect(cy15x102qn_config_t *conf); +/** + * \brief Takes the cy15x102qn mutex. + * + * \return The status/error code. + */ +int cy15x102qn_mutex_take(void); + +/** + * \brief Gives the cy15x102qn mutex. + * + * \return The status/error code. + */ +int cy15x102qn_mutex_give(void); + #endif /* CY15X102QN_H_ */ /** \} End of cy15x102qn group */ diff --git a/firmware/drivers/cy15x102qn/cy15x102qn_mutex.c b/firmware/drivers/cy15x102qn/cy15x102qn_mutex.c new file mode 100644 index 00000000..ca7bf0d3 --- /dev/null +++ b/firmware/drivers/cy15x102qn/cy15x102qn_mutex.c @@ -0,0 +1,54 @@ +/* + * cy15x102qn_mutex.c + * + * Copyright The OBDH 2.0 Contributors + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief Cy15x102qn driver mutex implementation. + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.15 + * + * \date 2024/02/26 + * + * \addtogroup cy15x102qn + * \{ + */ + +#include + +#include +#include +#include + +#include "cy15x102qn.h" + +int cy15x102qn_mutex_take(void) +{ + return spi_mutex_take(); +} + +int cy15x102qn_mutex_give(void) +{ + return spi_mutex_give(); +} + +/** \} End of cy15x102qn group */ From 0f29581aaf8a7036ad198fa7eebebf233b42625d Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Mon, 27 May 2024 20:50:15 -0300 Subject: [PATCH 15/31] firmware: drivers: cy15x102qn: Update cy15x102qn driver to use the spi port mutex #346 --- firmware/drivers/cy15x102qn/cy15x102qn.c | 101 +++++++++++++---------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/firmware/drivers/cy15x102qn/cy15x102qn.c b/firmware/drivers/cy15x102qn/cy15x102qn.c index 25015bd3..7b082ff9 100644 --- a/firmware/drivers/cy15x102qn/cy15x102qn.c +++ b/firmware/drivers/cy15x102qn/cy15x102qn.c @@ -24,8 +24,9 @@ * \brief CY15x102QN driver implementation. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.8.8 + * \version 0.10.15 * * \date 2021/06/04 * @@ -163,26 +164,40 @@ int cy15x102qn_write(cy15x102qn_config_t *conf, uint32_t adr, uint8_t *data, uin adr_arr[1] = (adr >> 8) & 0xFFU; adr_arr[2] = adr & 0xFFU; - if (cy15x102qn_spi_select(conf) == 0) + if (cy15x102qn_mutex_take() == 0) { - /* Write opcode */ - if (cy15x102qn_spi_write_only(conf, &cmd, 1) == 0) + if (cy15x102qn_spi_select(conf) == 0) { - /* Write address */ - if (cy15x102qn_spi_write_only(conf, adr_arr, 3) == 0) + /* Write opcode */ + if (cy15x102qn_spi_write_only(conf, &cmd, 1) == 0) { - /* Write data */ - if (cy15x102qn_spi_write_only(conf, data, len) == 0) + /* Write address */ + if (cy15x102qn_spi_write_only(conf, adr_arr, 3) == 0) { - if (cy15x102qn_spi_unselect(conf) == 0) + /* Write data */ + if (cy15x102qn_spi_write_only(conf, data, len) == 0) { - err = 0; + if (cy15x102qn_spi_unselect(conf) == 0) + { + err = 0; + } + } + else + { + #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) + sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the data during WRITE command!"); + sys_log_new_line(); + #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ + if (cy15x102qn_spi_unselect(conf) != 0) + { + err = -2; + } } } else { #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) - sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the data during WRITE command!"); + sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the address during WRITE command!"); sys_log_new_line(); #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ if (cy15x102qn_spi_unselect(conf) != 0) @@ -194,7 +209,7 @@ int cy15x102qn_write(cy15x102qn_config_t *conf, uint32_t adr, uint8_t *data, uin else { #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) - sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the address during WRITE command!"); + sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the opcode during WRITE command!"); sys_log_new_line(); #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ if (cy15x102qn_spi_unselect(conf) != 0) @@ -203,17 +218,8 @@ int cy15x102qn_write(cy15x102qn_config_t *conf, uint32_t adr, uint8_t *data, uin } } } - else - { - #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) - sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the opcode during WRITE command!"); - sys_log_new_line(); - #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ - if (cy15x102qn_spi_unselect(conf) != 0) - { - err = -2; - } - } + + (void)cy15x102qn_mutex_give(); } return err; @@ -230,26 +236,40 @@ int cy15x102qn_read(cy15x102qn_config_t *conf, uint32_t adr, uint8_t *data, uint adr_arr[1] = (adr >> 8) & 0xFFU; adr_arr[2] = adr & 0xFFU; - if (cy15x102qn_spi_select(conf) == 0) + if (cy15x102qn_mutex_take() == 0) { - /* Write opcode */ - if (cy15x102qn_spi_write_only(conf, &cmd, 1) == 0) + if (cy15x102qn_spi_select(conf) == 0) { - /* Write address */ - if (cy15x102qn_spi_write_only(conf, adr_arr, 3) == 0) + /* Write opcode */ + if (cy15x102qn_spi_write_only(conf, &cmd, 1) == 0) { - /* Read data */ - if (cy15x102qn_spi_read_only(conf, data, len) == 0) + /* Write address */ + if (cy15x102qn_spi_write_only(conf, adr_arr, 3) == 0) { - if (cy15x102qn_spi_unselect(conf) == 0) + /* Read data */ + if (cy15x102qn_spi_read_only(conf, data, len) == 0) { - err = 0; + if (cy15x102qn_spi_unselect(conf) == 0) + { + err = 0; + } + } + else + { + #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) + sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error reading the data during READ command!"); + sys_log_new_line(); + #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ + if (cy15x102qn_spi_unselect(conf) != 0) + { + err = -2; + } } } else { #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) - sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error reading the data during READ command!"); + sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the address during READ command!"); sys_log_new_line(); #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ if (cy15x102qn_spi_unselect(conf) != 0) @@ -261,7 +281,7 @@ int cy15x102qn_read(cy15x102qn_config_t *conf, uint32_t adr, uint8_t *data, uint else { #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) - sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the address during READ command!"); + sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the opcode during READ command!"); sys_log_new_line(); #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ if (cy15x102qn_spi_unselect(conf) != 0) @@ -270,17 +290,8 @@ int cy15x102qn_read(cy15x102qn_config_t *conf, uint32_t adr, uint8_t *data, uint } } } - else - { - #if defined(CONFIG_DRIVERS_DEBUG_ENABLED) && (CONFIG_DRIVERS_DEBUG_ENABLED == 1) - sys_log_print_event_from_module(SYS_LOG_ERROR, CY15X102QN_MODULE_NAME, "Error writing the opcode during READ command!"); - sys_log_new_line(); - #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ - if (cy15x102qn_spi_unselect(conf) != 0) - { - err = -2; - } - } + + (void)cy15x102qn_mutex_give(); } return err; From c5e39893b4cc1e0075851b1f7ee5109281afafdb Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Mon, 27 May 2024 21:00:49 -0300 Subject: [PATCH 16/31] firmware: Enable Housekeeping Task and increase its stack size --- firmware/app/tasks/housekeeping.h | 2 +- firmware/app/tasks/tasks.c | 10 ++++++++++ firmware/config/config.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/firmware/app/tasks/housekeeping.h b/firmware/app/tasks/housekeeping.h index a7899a74..d5a4b713 100644 --- a/firmware/app/tasks/housekeeping.h +++ b/firmware/app/tasks/housekeeping.h @@ -41,7 +41,7 @@ #include #define TASK_HOUSEKEEPING_NAME "Housekeeping" /**< Task name. */ -#define TASK_HOUSEKEEPING_STACK_SIZE 160 /**< Stack size in bytes. */ +#define TASK_HOUSEKEEPING_STACK_SIZE 225 /**< Stack size in bytes. */ #define TASK_HOUSEKEEPING_PRIORITY 3 /**< Task priority. */ #define TASK_HOUSEKEEPING_PERIOD_MS (10000) /**< Task period in milliseconds. */ #define TASK_HOUSEKEEPING_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */ diff --git a/firmware/app/tasks/tasks.c b/firmware/app/tasks/tasks.c index 0aa4ba80..5a5d45de 100644 --- a/firmware/app/tasks/tasks.c +++ b/firmware/app/tasks/tasks.c @@ -54,6 +54,7 @@ #include "process_tc.h" #include "pos_det.h" #include "read_px.h" +#include "housekeeping.h" void create_tasks(void) { @@ -204,6 +205,15 @@ void create_tasks(void) } #endif /* CONFIG_TASK_PAYLOAD_X_ENABLED */ +#if defined(CONFIG_TASK_HOUSEKEEPING_ENABLED) && (CONFIG_TASK_HOUSEKEEPING_ENABLED == 1) + xTaskCreate(vTaskHousekeeping, TASK_HOUSEKEEPING_NAME, TASK_HOUSEKEEPING_STACK_SIZE, NULL, TASK_HOUSEKEEPING_PRIORITY, &xTaskHousekeepingHandle); + + if (xTaskHousekeepingHandle == NULL) + { + /* Error creating the Housekeeping task */ + } +#endif /* CONFIG_TASK_HOUSEKEEPING_ENABLED */ + create_event_groups(); } diff --git a/firmware/config/config.h b/firmware/config/config.h index fddddbf9..d99bfb11 100644 --- a/firmware/config/config.h +++ b/firmware/config/config.h @@ -53,6 +53,7 @@ #define CONFIG_TASK_ANTENNA_DEPLOYMENT_ENABLED 0 #define CONFIG_TASK_POSITION_DETERMINATION_ENABLED 1 #define CONFIG_TASK_PAYLOAD_X_ENABLED 1 +#define CONFIG_TASK_HOUSEKEEPING_ENABLED 1 /* Devices */ #define CONFIG_DEV_MEDIA_INT_ENABLED 1 From 6ced576b1f8162a91991caa1c6d452922a570f4c Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 29 May 2024 17:46:37 -0300 Subject: [PATCH 17/31] firmware: app: structs: Fix define for TTC1 data default value --- firmware/app/structs/obdh_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/app/structs/obdh_data.h b/firmware/app/structs/obdh_data.h index b8da9523..162a7a55 100644 --- a/firmware/app/structs/obdh_data.h +++ b/firmware/app/structs/obdh_data.h @@ -105,7 +105,7 @@ #define OBDH_PARAM_MEDIA_LAST_OBDH_DATA_DEFAULT_VAL CONFIG_MEM_OBDH_DATA_START_PAGE #define OBDH_PARAM_MEDIA_LAST_EPS_DATA_DEFAULT_VAL CONFIG_MEM_EPS_DATA_START_PAGE #define OBDH_PARAM_MEDIA_LAST_TTC_0_DATA_DEFAULT_VAL CONFIG_MEM_TTC_0_DATA_START_PAGE -#define OBDH_PARAM_MEDIA_LAST_TTC_1_DATA_DEFAULT_VAL CONFIG_MEM_TTC_1_DATA_END_PAGE +#define OBDH_PARAM_MEDIA_LAST_TTC_1_DATA_DEFAULT_VAL CONFIG_MEM_TTC_1_DATA_START_PAGE #define OBDH_PARAM_MEDIA_LAST_ANT_DATA_DEFAULT_VAL CONFIG_MEM_ANT_DATA_START_PAGE #define OBDH_PARAM_MEDIA_LAST_EDC_DATA_DEFAULT_VAL CONFIG_MEM_EDC_DATA_START_PAGE #define OBDH_PARAM_MEDIA_LAST_PX_DATA_DEFAULT_VAL CONFIG_MEM_PX_DATA_START_PAGE From 59128b220e9bb2e46c837a7ab26991ba6d57b78c Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Mon, 3 Jun 2024 21:18:31 -0300 Subject: [PATCH 18/31] firmware: app: tasks: housekeeping: Fix OBDH data saving time period --- firmware/app/tasks/housekeeping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/app/tasks/housekeeping.c b/firmware/app/tasks/housekeeping.c index 6eff4a57..7198276a 100644 --- a/firmware/app/tasks/housekeeping.c +++ b/firmware/app/tasks/housekeeping.c @@ -66,7 +66,7 @@ void vTaskHousekeeping(void) } /* Save the last available OBDH data at every minute */ - if ((system_get_time() % (60U*1000U)) == 0U) + if ((system_get_time() % 60U) == 0U) { if (mem_mng_save_obdh_data_to_fram(sat_data_buf.obdh) != 0) { From 6f6179effaec508b24061a813b9d07bf46590711 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Mon, 3 Jun 2024 21:23:55 -0300 Subject: [PATCH 19/31] firmware: app: tasks: data_log: Fix memory page update after a write --- firmware/app/tasks/data_log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/app/tasks/data_log.c b/firmware/app/tasks/data_log.c index 40cd1493..71a3a46f 100644 --- a/firmware/app/tasks/data_log.c +++ b/firmware/app/tasks/data_log.c @@ -170,7 +170,7 @@ int write_data_to_flash_page(uint8_t *data, uint32_t *page, uint32_t page_size, if (media_write(MEDIA_NOR, (*page) * page_size, data, page_size) == 0) { - *page++; // cppcheck-suppress misra-c2012-17.8 + (*page)++; // cppcheck-suppress misra-c2012-17.8 if (*page > end_page) { From 04e412029914b3e7b1ca2a3d61c8ce895e626394 Mon Sep 17 00:00:00 2001 From: c-porto Date: Thu, 6 Jun 2024 20:08:50 -0300 Subject: [PATCH 20/31] firmware: Fix FRAM initialization --- firmware/app/tasks/startup.c | 2 +- firmware/app/utils/mem_mng.c | 28 ++++++++++++---------------- firmware/app/utils/mem_mng.h | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/firmware/app/tasks/startup.c b/firmware/app/tasks/startup.c index 8a10a627..07d76cf4 100644 --- a/firmware/app/tasks/startup.c +++ b/firmware/app/tasks/startup.c @@ -121,7 +121,7 @@ void vTaskStartup(void) mem_mng_load_obdh_data_from_default_values(&sat_data_buf.obdh); /* Write the OBDH data to the FRAM memory */ - if (mem_mng_save_obdh_data_to_fram(sat_data_buf.obdh) != 0) + if (mem_mng_save_obdh_data_to_fram(&sat_data_buf.obdh) != 0) { error_counter++; } diff --git a/firmware/app/utils/mem_mng.c b/firmware/app/utils/mem_mng.c index e3c83225..513dadc7 100644 --- a/firmware/app/utils/mem_mng.c +++ b/firmware/app/utils/mem_mng.c @@ -45,7 +45,7 @@ int mem_mng_check_fram(void) int err = -1; uint8_t mem_word_ref[8] = CONFIG_MEM_INIT_WORD; - uint8_t mem_word[8] = {0}; + uint8_t mem_word[8]; if (media_read(MEDIA_FRAM, CONFIG_MEM_ADR_INIT_WORD, mem_word, 8U) == 0) { @@ -109,9 +109,8 @@ void mem_mng_load_obdh_data_from_default_values(obdh_telemetry_t *tel) uint8_t tle_line1[70] = OBDH_PARAM_POSITION_TLE_LINE1_DEFAULT_VAL; uint8_t tle_line2[70] = OBDH_PARAM_POSITION_TLE_LINE2_DEFAULT_VAL; - void *null_ptr; - null_ptr = memcpy(&tel->data.position.tle_line1, &tle_line1[0], 70U); - null_ptr = memcpy(&tel->data.position.tle_line2, &tle_line2[0], 70U); + (void)memcpy(&tel->data.position.tle_line1, &tle_line1[0], 70U); + (void)memcpy(&tel->data.position.tle_line2, &tle_line2[0], 70U); tel->data.position.latitude = OBDH_PARAM_POSITION_LATITUDE_DEFAULT_VAL; tel->data.position.longitude = OBDH_PARAM_POSITION_LONGITUDE_DEFAULT_VAL; @@ -126,18 +125,17 @@ void mem_mng_load_obdh_data_from_default_values(obdh_telemetry_t *tel) tel->data.media.last_page_sbcd_pkts = OBDH_PARAM_MEDIA_LAST_SBCD_PKTS_DEFAULT_VAL; } -int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t tel) +int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t* tel) { int err = -1; - uint8_t buf[256] = {0}; + uint8_t buf[256]; + + (void)memcpy(buf, tel, sizeof(obdh_telemetry_t)); - if (memcpy(&buf[0], &tel, sizeof(obdh_telemetry_t)) == &buf[0]) + if (media_write(MEDIA_FRAM, CONFIG_MEM_ADR_SYS_PARAM, buf, 256U) == 0) { - if (media_write(MEDIA_FRAM, CONFIG_MEM_ADR_SYS_PARAM, buf, 256U) == 0) - { - err = 0; - } + err = 0; } return err; @@ -147,14 +145,12 @@ int mem_mng_load_obdh_data_from_fram(obdh_telemetry_t *tel) { int err = -1; - uint8_t sys_par[256] = {0}; + uint8_t sys_par[256]; if (media_read(MEDIA_FRAM, CONFIG_MEM_ADR_SYS_PARAM, sys_par, sizeof(obdh_telemetry_t)) == 0) { - if (memcpy(&tel, &sys_par[0], sizeof(obdh_telemetry_t)) == &tel) - { - err = 0; - } + (void)memcpy(tel, sys_par, sizeof(obdh_telemetry_t)); + err = 0; } return err; diff --git a/firmware/app/utils/mem_mng.h b/firmware/app/utils/mem_mng.h index cdb8dfcd..9a0dd296 100644 --- a/firmware/app/utils/mem_mng.h +++ b/firmware/app/utils/mem_mng.h @@ -78,7 +78,7 @@ void mem_mng_load_obdh_data_from_default_values(obdh_telemetry_t *tel); * * \return The status/error code. */ -int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t tel); +int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t *tel); /** * \brief Loads the last saved OBDH data from the FRAM memory. From df675c8a6e6fd8d0d9f7636d4c6e878cd72bbc6a Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Fri, 7 Jun 2024 16:00:38 -0300 Subject: [PATCH 21/31] firmware: app: tasks: Update initial delay for TTC tasks #351 --- firmware/app/tasks/process_tc.h | 2 +- firmware/app/tasks/read_ttc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/app/tasks/process_tc.h b/firmware/app/tasks/process_tc.h index ed2c28de..cc193e3e 100644 --- a/firmware/app/tasks/process_tc.h +++ b/firmware/app/tasks/process_tc.h @@ -45,7 +45,7 @@ #define TASK_PROCESS_TC_STACK_SIZE 500 /**< Stack size in bytes. */ #define TASK_PROCESS_TC_PRIORITY 4 /**< Task priority. */ #define TASK_PROCESS_TC_PERIOD_MS 1000 /**< Task period in milliseconds. */ -#define TASK_PROCESS_TC_INITIAL_DELAY_MS 2000 /**< Delay, in milliseconds, before the first execution. */ +#define TASK_PROCESS_TC_INITIAL_DELAY_MS 6500 /**< Delay, in milliseconds, before the first execution. */ #define TASK_PROCESS_TC_INIT_TIMEOUT_MS (10*1000) /**< Wait time to initialize the task in milliseconds. */ /** diff --git a/firmware/app/tasks/read_ttc.h b/firmware/app/tasks/read_ttc.h index 3baad073..8d4c7061 100644 --- a/firmware/app/tasks/read_ttc.h +++ b/firmware/app/tasks/read_ttc.h @@ -45,7 +45,7 @@ #define TASK_READ_TTC_STACK_SIZE 384 /**< Stack size in bytes. */ #define TASK_READ_TTC_PRIORITY 3 /**< Task priority. */ #define TASK_READ_TTC_PERIOD_MS (60000) /**< Task period in milliseconds. */ -#define TASK_READ_TTC_INITIAL_DELAY_MS 1000 /**< Delay, in milliseconds, before the first execution. */ +#define TASK_READ_TTC_INITIAL_DELAY_MS 5500 /**< Delay, in milliseconds, before the first execution. */ #define TASK_READ_TTC_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */ /** From 363315dd8fbc9f9e72bd4a79bd37046e42113087 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Thu, 20 Jun 2024 22:23:01 -0300 Subject: [PATCH 22/31] firmware: devices: temp_sensor: Fix raw data to Kelvin conversion --- firmware/devices/temp_sensor/temp_sensor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/devices/temp_sensor/temp_sensor.c b/firmware/devices/temp_sensor/temp_sensor.c index 8d18741e..383ff8cd 100644 --- a/firmware/devices/temp_sensor/temp_sensor.c +++ b/firmware/devices/temp_sensor/temp_sensor.c @@ -95,9 +95,9 @@ uint16_t temp_sensor_raw_to_k(uint16_t raw) { int16_t temp_c = temp_sensor_raw_to_c(raw); - if (temp_c < 273) + if (temp_c < -273) { - temp_c = 273; + temp_c = -273; } uint16_t res = temp_c + 273; From 067f377b6e8b64254a3b0b0ea51f810c1ea6317b Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Thu, 20 Jun 2024 22:23:52 -0300 Subject: [PATCH 23/31] firmware: app: tasks: read_sensors: Fix temperature param unit --- firmware/app/tasks/read_sensors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/app/tasks/read_sensors.c b/firmware/app/tasks/read_sensors.c index 5c6052f9..58d4f5bb 100644 --- a/firmware/app/tasks/read_sensors.c +++ b/firmware/app/tasks/read_sensors.c @@ -68,7 +68,7 @@ void vTaskReadSensors(void) } /* OBDH temperature */ - if (temp_sensor_read_raw(&buf) == 0) + if (temp_sensor_read_k(&buf) == 0) { sat_data_buf.obdh.data.temperature = buf; } From 0472aeffb2e499b36964030b13797a59f19bd3e4 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Fri, 21 Jun 2024 20:53:04 -0300 Subject: [PATCH 24/31] firmware: devices: current_sensor: Fix RL resistor value --- firmware/devices/current_sensor/current_sensor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/devices/current_sensor/current_sensor.h b/firmware/devices/current_sensor/current_sensor.h index 93a46bcd..562fced5 100644 --- a/firmware/devices/current_sensor/current_sensor.h +++ b/firmware/devices/current_sensor/current_sensor.h @@ -50,8 +50,8 @@ #define CURRENT_SENSOR_RSENSE_VALUE_MOHM 50 /**< Rsense resistor value in mOhm. */ /* Rload value */ -#define CURRENT_SENSOR_RL_VALUE_OHM 1650 /**< RL resistor value in Ohms. */ -#define CURRENT_SENSOR_RL_VALUE_KOHM 1.65 /**< RL resistor value in kOhms. */ +#define CURRENT_SENSOR_RL_VALUE_OHM 12000 /**< RL resistor value in Ohms. */ +#define CURRENT_SENSOR_RL_VALUE_KOHM 12 /**< RL resistor value in kOhms. */ /* Gain value */ #define CURRENT_SENSOR_GAIN_A_V 0.025 /**< Current gain of max9934 in A/V. */ From 62092e9ac461ce0485d7d4e0a134b02e20ef14fd Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 3 Jul 2024 00:20:03 -0300 Subject: [PATCH 25/31] firmware: app: Add logs to FRAM initialization --- firmware/app/tasks/startup.c | 6 ++++++ firmware/app/utils/mem_mng.c | 4 ++++ firmware/app/utils/mem_mng.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/firmware/app/tasks/startup.c b/firmware/app/tasks/startup.c index 07d76cf4..0ef41186 100644 --- a/firmware/app/tasks/startup.c +++ b/firmware/app/tasks/startup.c @@ -114,12 +114,18 @@ void vTaskStartup(void) } else { + sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_STARTUP_NAME, "FRAM was not initialized in previous cycles"); + sys_log_new_line(); + /* Initialize FRAM */ if (mem_mng_init_fram() == 0) { /* Load default values to the OBDH data buffer */ mem_mng_load_obdh_data_from_default_values(&sat_data_buf.obdh); + sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_STARTUP_NAME, "Loading default values to FRAM..."); + sys_log_new_line(); + /* Write the OBDH data to the FRAM memory */ if (mem_mng_save_obdh_data_to_fram(&sat_data_buf.obdh) != 0) { diff --git a/firmware/app/utils/mem_mng.c b/firmware/app/utils/mem_mng.c index 513dadc7..664b906a 100644 --- a/firmware/app/utils/mem_mng.c +++ b/firmware/app/utils/mem_mng.c @@ -37,6 +37,7 @@ #include #include +#include #include "mem_mng.h" @@ -51,6 +52,9 @@ int mem_mng_check_fram(void) { if (memcmp(&mem_word_ref[0], &mem_word[0], 8U) == 0) { + sys_log_print_event_from_module(SYS_LOG_INFO, MEM_MNG_NAME, "FRAM was already initalized"); + sys_log_new_line(); + err = 0; } } diff --git a/firmware/app/utils/mem_mng.h b/firmware/app/utils/mem_mng.h index 9a0dd296..467211f7 100644 --- a/firmware/app/utils/mem_mng.h +++ b/firmware/app/utils/mem_mng.h @@ -41,6 +41,8 @@ #include +#define MEM_MNG_NAME "Memory Management" + /** * \brief Checks if the FRAM memory is initialized or not. * From cba923eeb5a3db70a9409037a8c37dc9ba3266d6 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Wed, 10 Jul 2024 22:22:10 -0300 Subject: [PATCH 26/31] firmware: devices: voltage_sensor: Add a filter to voltage sensor measurements --- .../devices/voltage_sensor/voltage_sensor.c | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/firmware/devices/voltage_sensor/voltage_sensor.c b/firmware/devices/voltage_sensor/voltage_sensor.c index a48c5b5f..20460c49 100644 --- a/firmware/devices/voltage_sensor/voltage_sensor.c +++ b/firmware/devices/voltage_sensor/voltage_sensor.c @@ -37,6 +37,19 @@ #include "voltage_sensor.h" +#define ALPHA_ (0.05) + +static uint16_t voltage; + +/** + * \brief Filters voltage sensor samples. + * + * \param[in] new_sample is the newest voltage sample. + * + * \return The filtered sample. + */ +static inline uint16_t filter_voltage_sample(uint16_t new_sample); + int voltage_sensor_init(void) { sys_log_print_event_from_module(SYS_LOG_INFO, VOLTAGE_SENSOR_MODULE_NAME, "Initializing the voltage sensor..."); @@ -48,13 +61,18 @@ int voltage_sensor_init(void) { uint16_t volt = 0; - if (voltage_sensor_read_mv(&volt) == 0) + if (voltage_sensor_read_raw(&volt) == 0) { + volt = voltage_sensor_raw_to_mv(volt); + sys_log_print_event_from_module(SYS_LOG_INFO, VOLTAGE_SENSOR_MODULE_NAME, "Current input voltage: "); sys_log_print_uint(volt); sys_log_print_msg(" mV"); sys_log_new_line(); + /* First sample for the filter */ + voltage = volt; + err = 0; } else @@ -86,11 +104,13 @@ int voltage_sensor_read_mv(uint16_t *volt) { int err = -1; - uint16_t raw_volt = 0; + uint16_t sample; - if (voltage_sensor_read_raw(&raw_volt) == 0) + if (voltage_sensor_read_raw(&sample) == 0) { - *volt = voltage_sensor_raw_to_mv(raw_volt); + sample = voltage_sensor_raw_to_mv(sample); + + *volt = filter_voltage_sample(sample); err = 0; } @@ -103,4 +123,11 @@ int voltage_sensor_read_mv(uint16_t *volt) return err; } +static inline uint16_t filter_voltage_sample(uint16_t new_sample) +{ + voltage = (voltage * (1.0f - ALPHA_)) + (new_sample * ALPHA_); + + return voltage; +} + /** \} End of voltage_sensor group */ From 1a5fdb7ff089f0a4cd7a2ad4247165061b5a75c0 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Thu, 11 Jul 2024 17:33:53 -0300 Subject: [PATCH 27/31] firmware: app: tasks: read_sensors: Add log messages for sensor readings --- firmware/app/tasks/read_sensors.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/firmware/app/tasks/read_sensors.c b/firmware/app/tasks/read_sensors.c index 58d4f5bb..70e35df1 100644 --- a/firmware/app/tasks/read_sensors.c +++ b/firmware/app/tasks/read_sensors.c @@ -38,6 +38,7 @@ #include #include +#include #include "read_sensors.h" #include "startup.h" @@ -59,18 +60,33 @@ void vTaskReadSensors(void) if (current_sensor_read_ma(&buf) == 0) { sat_data_buf.obdh.data.current = buf; + + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_SENSORS_NAME, "Current input current: "); + sys_log_print_uint((uint32_t)buf); + sys_log_print_msg(" mA"); + sys_log_new_line(); } /* OBDH voltage */ if (voltage_sensor_read_mv(&buf) == 0) { sat_data_buf.obdh.data.voltage = buf; + + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_SENSORS_NAME, "Current input voltage: "); + sys_log_print_uint((uint32_t)buf); + sys_log_print_msg(" mV"); + sys_log_new_line(); } /* OBDH temperature */ if (temp_sensor_read_k(&buf) == 0) { sat_data_buf.obdh.data.temperature = buf; + + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_SENSORS_NAME, "Current uC temperature: "); + sys_log_print_uint((uint32_t)buf); + sys_log_print_msg(" K"); + sys_log_new_line(); } /* Data timestamp */ From b337df3f37069e48ef42f65880a9f9dd289ee3cd Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Thu, 11 Jul 2024 17:35:28 -0300 Subject: [PATCH 28/31] firmware: tests: drivers: Update tests for memory drivers --- firmware/tests/drivers/Makefile | 18 ++++++++++++------ firmware/tests/drivers/cy15x102qn_test.c | 8 ++++++++ firmware/tests/drivers/mt25q_test.c | 8 ++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/firmware/tests/drivers/Makefile b/firmware/tests/drivers/Makefile index a75b03bb..6d846445 100644 --- a/firmware/tests/drivers/Makefile +++ b/firmware/tests/drivers/Makefile @@ -15,7 +15,7 @@ CC=gcc INC=../../ FLAGS=-fpic -std=c99 -Wall -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -I$(INC) -I../../tests/freertos_sim/ -Wl,--wrap=sys_log_init,--wrap=sys_log_print_event,--wrap=sys_log_print_event_from_module,--wrap=sys_log_print_msg,--wrap=sys_log_print_str,--wrap=sys_log_new_line,--wrap=sys_log_print_uint,--wrap=sys_log_print_int,--wrap=sys_log_print_hex,--wrap=sys_log_dump_hex,--wrap=sys_log_print_float,--wrap=sys_log_print_byte,--wrap=sys_log_print_system_time,--wrap=sys_log_print_license_msg,--wrap=sys_log_print_splash_screen,--wrap=sys_log_print_firmware_version -CY15X102QN_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle +CY15X102QN_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle,--wrap=spi_mutex_take,--wrap=spi_mutex_give TPS382X_TEST_FLAGS=$(FLAGS),--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle,--wrap=gpio_init_mr_pin @@ -27,7 +27,7 @@ ISIS_ANTENNA_TEST_FLAGS=$(FLAGS),--wrap=tca4311a_init,--wrap=tca4311a_enable,--w SL_EPS2_TEST_FLAGS=$(FLAGS),--wrap=tca4311a_init,--wrap=tca4311a_enable,--wrap=tca4311a_disable,--wrap=tca4311a_is_ready,--wrap=tca4311a_write,--wrap=tca4311a_read,--wrap=tca4311a_write_byte,--wrap=tca4311a_read_byte -MT25Q_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle +MT25Q_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle,--wrap=spi_mutex_take,--wrap=spi_mutex_give SL_TTC2_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_write,--wrap=spi_read,--wrap=spi_transfer,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle,--wrap=spi_mutex_take,--wrap=spi_mutex_give,--wrap=sl_ttc2_spi_read @@ -36,8 +36,8 @@ SL_TTC2_TEST_FLAGS=$(FLAGS),--wrap=spi_init,--wrap=spi_select_slave,--wrap=spi_w all: cy15x102qn_test tps382x_test tca4311a_test edc_test isis_antenna_test sl_eps2_test mt25q_test sl_ttc2_test .PHONY: cy15x102qn_test -cy15x102qn_test: $(BUILD_DIR)/cy15x102qn.o $(BUILD_DIR)/cy15x102qn_gpio.o $(BUILD_DIR)/cy15x102qn_spi.o $(BUILD_DIR)/cy15x102qn_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o - $(CC) $(CY15X102QN_TEST_FLAGS) $(BUILD_DIR)/cy15x102qn.o $(BUILD_DIR)/cy15x102qn_gpio.o $(BUILD_DIR)/cy15x102qn_spi.o $(BUILD_DIR)/cy15x102qn_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o -o $(BUILD_DIR)/$(TARGET_CY15X102QN) -lcmocka +cy15x102qn_test: $(BUILD_DIR)/cy15x102qn.o $(BUILD_DIR)/cy15x102qn_mutex.o $(BUILD_DIR)/cy15x102qn_gpio.o $(BUILD_DIR)/cy15x102qn_spi.o $(BUILD_DIR)/cy15x102qn_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/semphr.o + $(CC) $(CY15X102QN_TEST_FLAGS) $(BUILD_DIR)/cy15x102qn.o $(BUILD_DIR)/cy15x102qn_mutex.o $(BUILD_DIR)/cy15x102qn_gpio.o $(BUILD_DIR)/cy15x102qn_spi.o $(BUILD_DIR)/cy15x102qn_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/semphr.o -o $(BUILD_DIR)/$(TARGET_CY15X102QN) -lcmocka .PHONY: tps382x_test tps382x_test: $(BUILD_DIR)/tps382x.o $(BUILD_DIR)/tps382x_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/gpio_wrap.o @@ -60,8 +60,8 @@ sl_eps2_test: $(BUILD_DIR)/sl_eps2.o $(BUILD_DIR)/sl_eps2_i2c.o $(BUILD_DIR)/sl_ $(CC) $(SL_EPS2_TEST_FLAGS) $(BUILD_DIR)/sl_eps2.o $(BUILD_DIR)/sl_eps2_i2c.o $(BUILD_DIR)/sl_eps2_delay.o $(BUILD_DIR)/sl_eps2_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/tca4311a_wrap.o $(BUILD_DIR)/task.o -o $(BUILD_DIR)/$(TARGET_SL_EPS2) -lm -lcmocka .PHONY: mt25q_test -mt25q_test: $(BUILD_DIR)/mt25q.o $(BUILD_DIR)/mt25q_delay.o $(BUILD_DIR)/mt25q_gpio.o $(BUILD_DIR)/mt25q_spi.o $(BUILD_DIR)/mt25q_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o - $(CC) $(MT25Q_TEST_FLAGS) $(BUILD_DIR)/mt25q.o $(BUILD_DIR)/mt25q_delay.o $(BUILD_DIR)/mt25q_gpio.o $(BUILD_DIR)/mt25q_spi.o $(BUILD_DIR)/mt25q_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o -o $(BUILD_DIR)/$(TARGET_MT25Q) -lm -lcmocka +mt25q_test: $(BUILD_DIR)/mt25q.o $(BUILD_DIR)/mt25q_mutex.o $(BUILD_DIR)/mt25q_delay.o $(BUILD_DIR)/mt25q_gpio.o $(BUILD_DIR)/mt25q_spi.o $(BUILD_DIR)/mt25q_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o $(BUILD_DIR)/semphr.o + $(CC) $(MT25Q_TEST_FLAGS) $(BUILD_DIR)/mt25q.o $(BUILD_DIR)/mt25q_mutex.o $(BUILD_DIR)/mt25q_delay.o $(BUILD_DIR)/mt25q_gpio.o $(BUILD_DIR)/mt25q_spi.o $(BUILD_DIR)/mt25q_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o $(BUILD_DIR)/semphr.o -o $(BUILD_DIR)/$(TARGET_MT25Q) -lm -lcmocka .PHONY: sl_ttc2_test sl_ttc2_test: $(BUILD_DIR)/sl_ttc2.o $(BUILD_DIR)/sl_ttc2_spi.o $(BUILD_DIR)/sl_ttc2_delay.o $(BUILD_DIR)/sl_ttc2_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o $(BUILD_DIR)/sl_ttc2_mutex.o $(BUILD_DIR)/sl_ttc2_wrap.o $(BUILD_DIR)/semphr.o @@ -77,6 +77,9 @@ $(BUILD_DIR)/cy15x102qn_gpio.o: ../../drivers/cy15x102qn/cy15x102qn_gpio.c $(BUILD_DIR)/cy15x102qn_spi.o: ../../drivers/cy15x102qn/cy15x102qn_spi.c $(CC) $(CY15X102QN_TEST_FLAGS) -c $< -o $@ +$(BUILD_DIR)/cy15x102qn_mutex.o: ../../drivers/cy15x102qn/cy15x102qn_mutex.c + $(CC) $(CY15X102QN_TEST_FLAGS) -c $< -o $@ + $(BUILD_DIR)/tps382x.o: ../../drivers/tps382x/tps382x.c $(CC) $(TPS382X_TEST_FLAGS) -c $< -o $@ @@ -128,6 +131,9 @@ $(BUILD_DIR)/mt25q_gpio.o: ../../drivers/mt25q/mt25q_gpio.c $(BUILD_DIR)/mt25q_spi.o: ../../drivers/mt25q/mt25q_spi.c $(CC) $(MT25Q_TEST_FLAGS) -c $< -o $@ +$(BUILD_DIR)/mt25q_mutex.o: ../../drivers/mt25q/mt25q_mutex.c + $(CC) $(MT25Q_TEST_FLAGS) -c $< -o $@ + $(BUILD_DIR)/sl_ttc2.o: ../../drivers/sl_ttc2/sl_ttc2.c $(CC) $(SL_TTC2_TEST_FLAGS) -c $< -o $@ diff --git a/firmware/tests/drivers/cy15x102qn_test.c b/firmware/tests/drivers/cy15x102qn_test.c index d21ec9b7..7ac23611 100644 --- a/firmware/tests/drivers/cy15x102qn_test.c +++ b/firmware/tests/drivers/cy15x102qn_test.c @@ -149,6 +149,8 @@ static void cy15x102qn_write_status_reg_test(void **state) static void cy15x102qn_write_test(void **state) { + will_return(__wrap_spi_mutex_take, 0); + /* Select device */ expect_value(__wrap_spi_select_slave, port, CY15X102QN_SPI_PORT); expect_value(__wrap_spi_select_slave, cs, CY15X102QN_SPI_CS); @@ -206,11 +208,15 @@ static void cy15x102qn_write_test(void **state) will_return(__wrap_spi_select_slave, 0); + will_return(__wrap_spi_mutex_give, 0); + assert_return_code(cy15x102qn_write(&conf, adr, data, data_len), 0); } static void cy15x102qn_read_test(void **state) { + will_return(__wrap_spi_mutex_take, 0); + /* Select device */ expect_value(__wrap_spi_select_slave, port, CY15X102QN_SPI_PORT); expect_value(__wrap_spi_select_slave, cs, CY15X102QN_SPI_CS); @@ -268,6 +274,8 @@ static void cy15x102qn_read_test(void **state) will_return(__wrap_spi_select_slave, 0); + will_return(__wrap_spi_mutex_give, 0); + uint8_t data_res[256] = {0xFF}; assert_return_code(cy15x102qn_read(&conf, adr, data_res, data_len), 0); diff --git a/firmware/tests/drivers/mt25q_test.c b/firmware/tests/drivers/mt25q_test.c index 85767335..be094c59 100644 --- a/firmware/tests/drivers/mt25q_test.c +++ b/firmware/tests/drivers/mt25q_test.c @@ -144,6 +144,8 @@ static void mt25q_read_device_id_test(void **state) expect_memory(__wrap_spi_transfer, wd, (void*)cmd, 4); expect_value(__wrap_spi_transfer, len, 4); + will_return(__wrap_spi_mutex_take, 0); + uint16_t i = 0; for(i=0; i<4; i++) { @@ -152,6 +154,8 @@ static void mt25q_read_device_id_test(void **state) will_return(__wrap_spi_transfer, 0); + will_return(__wrap_spi_mutex_give, 0); + mt25q_dev_id_t dev_id = {0}; assert_return_code(mt25q_read_device_id(&dev_id), 0); @@ -267,6 +271,8 @@ static void mt25q_read_flag_status_register_test(void **state) ans[1] = generate_random(0, UINT8_MAX); + will_return(__wrap_spi_mutex_take, 0); + expect_value(__wrap_spi_transfer, port, MT25Q_SPI_PORT); expect_value(__wrap_spi_transfer, cs, MT25Q_SPI_CS_PIN); expect_memory(__wrap_spi_transfer, wd, (void*)cmd, 2); @@ -277,6 +283,8 @@ static void mt25q_read_flag_status_register_test(void **state) will_return(__wrap_spi_transfer, 0); + will_return(__wrap_spi_mutex_give, 0); + uint8_t flag = UINT8_MAX; assert_return_code(mt25q_read_flag_status_register(&flag), 0); From 2ec68cbb22895bd64fc04cf6df631f0b1cd098be Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Thu, 11 Jul 2024 18:22:54 -0300 Subject: [PATCH 29/31] firmware: Update versions of modified files --- firmware/app/structs/obdh_data.h | 2 +- firmware/app/tasks/data_log.c | 2 +- firmware/app/tasks/housekeeping.c | 2 +- firmware/app/tasks/housekeeping.h | 2 +- firmware/app/tasks/process_tc.h | 2 +- firmware/app/tasks/read_sensors.c | 2 +- firmware/app/tasks/read_ttc.h | 2 +- firmware/app/tasks/startup.c | 2 +- firmware/app/tasks/tasks.c | 2 +- firmware/app/utils/mem_mng.c | 2 +- firmware/app/utils/mem_mng.h | 2 +- firmware/config/config.h | 2 +- firmware/devices/current_sensor/current_sensor.h | 2 +- firmware/devices/temp_sensor/temp_sensor.c | 2 +- firmware/devices/voltage_sensor/voltage_sensor.c | 2 +- firmware/drivers/cy15x102qn/cy15x102qn.c | 2 +- firmware/drivers/cy15x102qn/cy15x102qn.h | 2 +- firmware/drivers/cy15x102qn/cy15x102qn_mutex.c | 2 +- firmware/drivers/mt25q/mt25q.c | 2 +- firmware/drivers/mt25q/mt25q.h | 2 +- firmware/drivers/mt25q/mt25q_mutex.c | 2 +- firmware/drivers/sl_ttc2/sl_ttc2.c | 2 +- firmware/drivers/sl_ttc2/sl_ttc2.h | 2 +- firmware/drivers/sl_ttc2/sl_ttc2_spi.c | 2 +- firmware/drivers/spi/spi.c | 2 +- firmware/drivers/spi/spi.h | 2 +- firmware/drivers/spi/spi_mutex.c | 2 +- firmware/tests/drivers/cy15x102qn_test.c | 2 +- firmware/tests/drivers/mt25q_test.c | 2 +- firmware/tests/drivers/sl_ttc2_test.c | 2 +- firmware/tests/freertos_sim/semphr.c | 2 +- firmware/tests/freertos_sim/semphr.h | 2 +- firmware/tests/mockups/drivers/sl_ttc2_wrap.h | 2 +- firmware/tests/mockups/drivers/spi_wrap.c | 2 +- firmware/tests/mockups/drivers/spi_wrap.h | 2 +- 35 files changed, 35 insertions(+), 35 deletions(-) diff --git a/firmware/app/structs/obdh_data.h b/firmware/app/structs/obdh_data.h index 162a7a55..dca2474b 100644 --- a/firmware/app/structs/obdh_data.h +++ b/firmware/app/structs/obdh_data.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.9 + * \version 0.10.17 * * \date 2020/07/16 * diff --git a/firmware/app/tasks/data_log.c b/firmware/app/tasks/data_log.c index 71a3a46f..eb6b86a8 100644 --- a/firmware/app/tasks/data_log.c +++ b/firmware/app/tasks/data_log.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.9 + * \version 0.10.17 * * \date 2021/05/24 * diff --git a/firmware/app/tasks/housekeeping.c b/firmware/app/tasks/housekeeping.c index 7198276a..1bae9159 100644 --- a/firmware/app/tasks/housekeeping.c +++ b/firmware/app/tasks/housekeeping.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.9 + * \version 0.10.17 * * \date 2021/04/27 * diff --git a/firmware/app/tasks/housekeeping.h b/firmware/app/tasks/housekeeping.h index d5a4b713..d474d851 100644 --- a/firmware/app/tasks/housekeeping.h +++ b/firmware/app/tasks/housekeeping.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.8.33 + * \version 0.10.17 * * \date 2021/04/27 * diff --git a/firmware/app/tasks/process_tc.h b/firmware/app/tasks/process_tc.h index cc193e3e..2dcca29e 100644 --- a/firmware/app/tasks/process_tc.h +++ b/firmware/app/tasks/process_tc.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2021/07/06 * diff --git a/firmware/app/tasks/read_sensors.c b/firmware/app/tasks/read_sensors.c index 70e35df1..db2e62fe 100644 --- a/firmware/app/tasks/read_sensors.c +++ b/firmware/app/tasks/read_sensors.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.8.5 + * \version 0.10.17 * * \date 2020/07/12 * diff --git a/firmware/app/tasks/read_ttc.h b/firmware/app/tasks/read_ttc.h index 8d4c7061..cca8eeec 100644 --- a/firmware/app/tasks/read_ttc.h +++ b/firmware/app/tasks/read_ttc.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2021/05/14 * diff --git a/firmware/app/tasks/startup.c b/firmware/app/tasks/startup.c index 0ef41186..ffa039a7 100644 --- a/firmware/app/tasks/startup.c +++ b/firmware/app/tasks/startup.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.9 + * \version 0.10.17 * * \date 2019/12/04 * diff --git a/firmware/app/tasks/tasks.c b/firmware/app/tasks/tasks.c index 5a5d45de..384772e8 100644 --- a/firmware/app/tasks/tasks.c +++ b/firmware/app/tasks/tasks.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.7 + * \version 0.10.17 * * \date 2019/11/02 * diff --git a/firmware/app/utils/mem_mng.c b/firmware/app/utils/mem_mng.c index 664b906a..21dc9cc1 100644 --- a/firmware/app/utils/mem_mng.c +++ b/firmware/app/utils/mem_mng.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.9 + * \version 0.10.17 * * \date 2024/02/24 * diff --git a/firmware/app/utils/mem_mng.h b/firmware/app/utils/mem_mng.h index 467211f7..f35cc1e5 100644 --- a/firmware/app/utils/mem_mng.h +++ b/firmware/app/utils/mem_mng.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.9 + * \version 0.10.17 * * \date 2024/02/24 * diff --git a/firmware/config/config.h b/firmware/config/config.h index d99bfb11..6f8cb064 100644 --- a/firmware/config/config.h +++ b/firmware/config/config.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.15 + * \version 0.10.17 * * \date 2019/10/26 * diff --git a/firmware/devices/current_sensor/current_sensor.h b/firmware/devices/current_sensor/current_sensor.h index 562fced5..d78eada8 100644 --- a/firmware/devices/current_sensor/current_sensor.h +++ b/firmware/devices/current_sensor/current_sensor.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.6.2 + * \version 0.10.17 * * \date 2020/07/11 * diff --git a/firmware/devices/temp_sensor/temp_sensor.c b/firmware/devices/temp_sensor/temp_sensor.c index 383ff8cd..b5a06b09 100644 --- a/firmware/devices/temp_sensor/temp_sensor.c +++ b/firmware/devices/temp_sensor/temp_sensor.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.28 + * \version 0.10.17 * * \date 2020/03/17 * diff --git a/firmware/devices/voltage_sensor/voltage_sensor.c b/firmware/devices/voltage_sensor/voltage_sensor.c index 20460c49..646af43d 100644 --- a/firmware/devices/voltage_sensor/voltage_sensor.c +++ b/firmware/devices/voltage_sensor/voltage_sensor.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.28 + * \version 0.10.17 * * \date 2020/07/11 * diff --git a/firmware/drivers/cy15x102qn/cy15x102qn.c b/firmware/drivers/cy15x102qn/cy15x102qn.c index 7b082ff9..d070e5ab 100644 --- a/firmware/drivers/cy15x102qn/cy15x102qn.c +++ b/firmware/drivers/cy15x102qn/cy15x102qn.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.15 + * \version 0.10.17 * * \date 2021/06/04 * diff --git a/firmware/drivers/cy15x102qn/cy15x102qn.h b/firmware/drivers/cy15x102qn/cy15x102qn.h index 98f68dcd..4af94699 100644 --- a/firmware/drivers/cy15x102qn/cy15x102qn.h +++ b/firmware/drivers/cy15x102qn/cy15x102qn.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.28 + * \version 0.10.17 * * \date 2021/06/04 * diff --git a/firmware/drivers/cy15x102qn/cy15x102qn_mutex.c b/firmware/drivers/cy15x102qn/cy15x102qn_mutex.c index ca7bf0d3..0b822cbe 100644 --- a/firmware/drivers/cy15x102qn/cy15x102qn_mutex.c +++ b/firmware/drivers/cy15x102qn/cy15x102qn_mutex.c @@ -25,7 +25,7 @@ * * \author Carlos Augusto Porto Freitas * - * \version 0.10.15 + * \version 0.10.17 * * \date 2024/02/26 * diff --git a/firmware/drivers/mt25q/mt25q.c b/firmware/drivers/mt25q/mt25q.c index d21ed7f2..37d54f6d 100644 --- a/firmware/drivers/mt25q/mt25q.c +++ b/firmware/drivers/mt25q/mt25q.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.8.9 + * \version 0.10.17 * * \date 2019/11/15 * diff --git a/firmware/drivers/mt25q/mt25q.h b/firmware/drivers/mt25q/mt25q.h index a12316aa..266265d1 100644 --- a/firmware/drivers/mt25q/mt25q.h +++ b/firmware/drivers/mt25q/mt25q.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.42 + * \version 0.10.17 * * \date 2019/11/15 * diff --git a/firmware/drivers/mt25q/mt25q_mutex.c b/firmware/drivers/mt25q/mt25q_mutex.c index 404a51b8..27637423 100644 --- a/firmware/drivers/mt25q/mt25q_mutex.c +++ b/firmware/drivers/mt25q/mt25q_mutex.c @@ -25,7 +25,7 @@ * * \author Carlos Augusto Porto Freitas * - * \version 0.10.15 + * \version 0.10.17 * * \date 2024/02/26 * diff --git a/firmware/drivers/sl_ttc2/sl_ttc2.c b/firmware/drivers/sl_ttc2/sl_ttc2.c index 1edfb8c4..29c46949 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2.c +++ b/firmware/drivers/sl_ttc2/sl_ttc2.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2021/05/12 * diff --git a/firmware/drivers/sl_ttc2/sl_ttc2.h b/firmware/drivers/sl_ttc2/sl_ttc2.h index ef927ffd..6f9c717c 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2.h +++ b/firmware/drivers/sl_ttc2/sl_ttc2.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2021/05/12 * diff --git a/firmware/drivers/sl_ttc2/sl_ttc2_spi.c b/firmware/drivers/sl_ttc2/sl_ttc2_spi.c index 44c2c71c..25f0768d 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2_spi.c +++ b/firmware/drivers/sl_ttc2/sl_ttc2_spi.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2021/10/13 * diff --git a/firmware/drivers/spi/spi.c b/firmware/drivers/spi/spi.c index 1e2ab8f1..02a08bcf 100644 --- a/firmware/drivers/spi/spi.c +++ b/firmware/drivers/spi/spi.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.9.16 + * \version 0.10.17 * * \date 2019/12/07 * diff --git a/firmware/drivers/spi/spi.h b/firmware/drivers/spi/spi.h index 9a5abc0c..3a719de7 100644 --- a/firmware/drivers/spi/spi.h +++ b/firmware/drivers/spi/spi.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.33 + * \version 0.10.17 * * \date 2019/12/07 * diff --git a/firmware/drivers/spi/spi_mutex.c b/firmware/drivers/spi/spi_mutex.c index e2ceaeed..b1946f1e 100644 --- a/firmware/drivers/spi/spi_mutex.c +++ b/firmware/drivers/spi/spi_mutex.c @@ -25,7 +25,7 @@ * * \author Carlos Augusto Porto Freitas * - * \version 0.10.10 + * \version 0.10.17 * * \date 2024/02/27 * diff --git a/firmware/tests/drivers/cy15x102qn_test.c b/firmware/tests/drivers/cy15x102qn_test.c index 7ac23611..29f1acdd 100644 --- a/firmware/tests/drivers/cy15x102qn_test.c +++ b/firmware/tests/drivers/cy15x102qn_test.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.11 + * \version 0.10.17 * * \date 2021/08/29 * diff --git a/firmware/tests/drivers/mt25q_test.c b/firmware/tests/drivers/mt25q_test.c index be094c59..90d41d54 100644 --- a/firmware/tests/drivers/mt25q_test.c +++ b/firmware/tests/drivers/mt25q_test.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.20 + * \version 0.10.17 * * \date 2021/09/05 * diff --git a/firmware/tests/drivers/sl_ttc2_test.c b/firmware/tests/drivers/sl_ttc2_test.c index b33936ca..e61366f3 100644 --- a/firmware/tests/drivers/sl_ttc2_test.c +++ b/firmware/tests/drivers/sl_ttc2_test.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2021/09/08 * diff --git a/firmware/tests/freertos_sim/semphr.c b/firmware/tests/freertos_sim/semphr.c index 68d249b7..6b81ebfe 100644 --- a/firmware/tests/freertos_sim/semphr.c +++ b/firmware/tests/freertos_sim/semphr.c @@ -25,7 +25,7 @@ * \author Miguel Boing * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2024/04/25 * diff --git a/firmware/tests/freertos_sim/semphr.h b/firmware/tests/freertos_sim/semphr.h index 175351d4..f1f9e584 100644 --- a/firmware/tests/freertos_sim/semphr.h +++ b/firmware/tests/freertos_sim/semphr.h @@ -26,7 +26,7 @@ * \author Miguel Boing * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2024/04/25 * diff --git a/firmware/tests/mockups/drivers/sl_ttc2_wrap.h b/firmware/tests/mockups/drivers/sl_ttc2_wrap.h index 3d28c7cc..78ee072e 100644 --- a/firmware/tests/mockups/drivers/sl_ttc2_wrap.h +++ b/firmware/tests/mockups/drivers/sl_ttc2_wrap.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.17 * * \date 2021/08/06 * diff --git a/firmware/tests/mockups/drivers/spi_wrap.c b/firmware/tests/mockups/drivers/spi_wrap.c index 34fefc88..f2b8e071 100644 --- a/firmware/tests/mockups/drivers/spi_wrap.c +++ b/firmware/tests/mockups/drivers/spi_wrap.c @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.10 + * \version 0.10.17 * * \date 2021/08/25 * diff --git a/firmware/tests/mockups/drivers/spi_wrap.h b/firmware/tests/mockups/drivers/spi_wrap.h index b58f5b23..9f6217ed 100644 --- a/firmware/tests/mockups/drivers/spi_wrap.h +++ b/firmware/tests/mockups/drivers/spi_wrap.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.7.8 + * \version 0.10.17 * * \date 2021/08/25 * From 0dbd3772f102dbdff044377b93d32325bcad54c9 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Thu, 11 Jul 2024 18:23:36 -0300 Subject: [PATCH 30/31] firmware: Update the firmware version --- firmware/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/version.h b/firmware/version.h index 0b4148d1..04ede94e 100644 --- a/firmware/version.h +++ b/firmware/version.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.16 + * \version 0.10.17 * * \date 2019/10/25 * @@ -36,7 +36,7 @@ #ifndef VERSION_H_ #define VERSION_H_ -#define FIRMWARE_VERSION "0.10.16" +#define FIRMWARE_VERSION "0.10.17" #define FIRMWARE_STATUS "Development" From 4f1ad7b2023e325c0ff208d9f4be69a03f5c64ad Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Mon, 15 Jul 2024 14:47:04 -0300 Subject: [PATCH 31/31] firmware: devices: voltage_sensor: Change filter first sample --- firmware/devices/voltage_sensor/voltage_sensor.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/firmware/devices/voltage_sensor/voltage_sensor.c b/firmware/devices/voltage_sensor/voltage_sensor.c index 646af43d..53873428 100644 --- a/firmware/devices/voltage_sensor/voltage_sensor.c +++ b/firmware/devices/voltage_sensor/voltage_sensor.c @@ -37,7 +37,8 @@ #include "voltage_sensor.h" -#define ALPHA_ (0.05) +#define ALPHA_ (0.01) +#define VOLTAGE_INIT (3300U) static uint16_t voltage; @@ -59,20 +60,17 @@ int voltage_sensor_init(void) if (adc_init() == 0) { - uint16_t volt = 0; + uint16_t volt = 0U; - if (voltage_sensor_read_raw(&volt) == 0) + voltage = VOLTAGE_INIT; + + if (voltage_sensor_read_mv(&volt) == 0) { - volt = voltage_sensor_raw_to_mv(volt); - sys_log_print_event_from_module(SYS_LOG_INFO, VOLTAGE_SENSOR_MODULE_NAME, "Current input voltage: "); sys_log_print_uint(volt); sys_log_print_msg(" mV"); sys_log_new_line(); - - /* First sample for the filter */ - voltage = volt; - + err = 0; } else