diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 05a1adbc..00000000 --- a/.clang-tidy +++ /dev/null @@ -1,79 +0,0 @@ ---- -# Only check project files, not external/ or ESP-IDF headers -HeaderFilterRegex: '.*/solaris-v1/(components|main)/.*' - -Checks: > - -*, - readability-identifier-naming, - bugprone-macro-parentheses, - bugprone-sizeof-expression, - bugprone-suspicious-memset-usage, - bugprone-too-small-loop-variable, - bugprone-integer-division, - bugprone-misplaced-widening-cast - -CheckOptions: - # --- Local variables: camelBack --- - # fifoCount, txBuffer, regBankSel - - key: readability-identifier-naming.LocalVariableCase - value: camelBack - - # --- Parameters (value): camelBack --- - # reg, value, regBank - - key: readability-identifier-naming.ParameterCase - value: camelBack - - # --- Parameters (pointer): p_ prefix + camelBack --- - # p_spi, p_data, p_value - - key: readability-identifier-naming.PointerParameterCase - value: camelBack - - key: readability-identifier-naming.PointerParameterPrefix - value: 'p_' - - # --- Struct/union members: camelBack --- - # bankSel, i2cMstEn, rawData0Rdy - - key: readability-identifier-naming.MemberCase - value: camelBack - - # --- Static variables (non-const): s_ prefix + camelBack --- - # s_variableName - - key: readability-identifier-naming.StaticVariableCase - value: camelBack - - key: readability-identifier-naming.StaticVariablePrefix - value: 's_' - - # --- Macros: UPPER_CASE --- - # K_ICM20948_REG_BANK_SEL, BMP390_* - - key: readability-identifier-naming.MacroDefinitionCase - value: UPPER_CASE - - # --- Enum constants: UPPER_CASE --- - # K_ICM20948_REG_BANK_0, K_ICM20948_CLK_AUTO - - key: readability-identifier-naming.EnumConstantCase - value: UPPER_CASE - - # --- Typedefs: enforce _t suffix only (case varies) --- - # ICM20948_RegBankSel_t, retval_t - - key: readability-identifier-naming.TypedefCase - value: aNy_CasE - - key: readability-identifier-naming.TypedefSuffix - value: '_t' - - # --- Functions, enum types, struct/union tags: not enforced --- - # Naming like ICM20948_writeReg doesn't fit standard patterns - - key: readability-identifier-naming.FunctionCase - value: aNy_CasE - - key: readability-identifier-naming.EnumCase - value: aNy_CasE - - key: readability-identifier-naming.UnionCase - value: aNy_CasE - - key: readability-identifier-naming.StructCase - value: aNy_CasE - - # --- Global/static constants: not enforced --- - # Mixed patterns: TAG (ESP-IDF convention) vs s_dmp3Image - - key: readability-identifier-naming.StaticConstantCase - value: aNy_CasE - - key: readability-identifier-naming.GlobalConstantCase - value: aNy_CasE -... diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8b7c822f..b015c7dc 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -20,11 +20,7 @@ RUN apt-get update && apt-get install -y \ texlive-fonts-recommended \ texlive-plain-generic \ latexmk \ - clang \ - clangd \ clang-format \ - clang-tidy \ - clang-tools \ cppcheck \ flawfinder \ python3-pip \ @@ -43,7 +39,8 @@ RUN curl -fsSL -o /tmp/sonar-scanner.zip \ && rm /tmp/sonar-scanner.zip \ && rm -rf /var/lib/apt/lists/* -RUN git config --global core.editor "nano" +RUN git config --system core.editor "nano" \ + && git config --system --add safe.directory /home/user/Documents/solaris-software WORKDIR /root diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 02a12789..a3035f16 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -14,8 +14,7 @@ ], "remoteUser": "root", "mounts": [ - "source=${localEnv:HOME}/.ssh,target=/tmp/host-ssh,type=bind,consistency=cached,readonly", - "source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached,readonly" + "source=${localEnv:HOME}/.ssh,target=/tmp/host-ssh,type=bind,consistency=cached,readonly" ], "postCreateCommand": "/bin/bash -lc 'echo \"source /opt/esp/idf/export.sh\" >> ~/.bashrc && mkdir -p /root/.ssh && cp -a /tmp/host-ssh/. /root/.ssh/ 2>/dev/null || true && chown -R root:root /root/.ssh && chmod 700 /root/.ssh && for f in /root/.ssh/config /root/.ssh/known_hosts /root/.ssh/id_rsa /root/.ssh/raspberrypi /root/.ssh/id_ed25519; do [ -f \"$f\" ] && chmod 600 \"$f\"; done && for f in /root/.ssh/id_rsa.pub /root/.ssh/raspberrypi.pub /root/.ssh/id_ed25519.pub; do [ -f \"$f\" ] && chmod 644 \"$f\"; done && echo \"Dev container ready for ESP-IDF development!\"'", "remoteEnv": { @@ -26,9 +25,15 @@ "vscode": { "settings": { "terminal.integrated.defaultProfile.linux": "bash", - "C_Cpp.intelliSenseEngine": "disabled", + "C_Cpp.intelliSenseEngine": "default", + "C_Cpp.autocomplete": "default", + "C_Cpp.errorSquiggles": "enabled", + "C_Cpp.default.compileCommands": "/home/user/Documents/solaris-software/solaris-v1/build/compile_commands.json", "editor.formatOnSave": true, - "clangd.path": "/usr/bin/clangd", + "files.associations": { + "*.h": "c", + "*.c": "c" + }, "[c]": { "editor.defaultFormatter": "xaver.clang-format" }, @@ -44,9 +49,7 @@ "samubarb.vscode-doxyfile", "openai.tu-extension-codex", "github.vscode-pull-request-github", - "llvm-vs-code-extensions.vscode-clangd", - "xaver.clang-format", - "jbenden.c-cpp-flylint" + "xaver.clang-format" ] } } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 0d709124..bcab1143 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -7,6 +7,9 @@ services: USERNAME: root USER_UID: 1000 USER_GID: 1000 + devices: + - "/dev/ttyACM0:/dev/ttyACM0" + privileged: true user: root tty: true stdin_open: true diff --git a/solaris-v1/components/datalogger_driver/dataloggerSD.c b/solaris-v1/components/datalogger_driver/dataloggerSD.c index e69de29b..ac614bc9 100644 --- a/solaris-v1/components/datalogger_driver/dataloggerSD.c +++ b/solaris-v1/components/datalogger_driver/dataloggerSD.c @@ -0,0 +1,141 @@ +#include "dataloggerSD.h" + +#include "storage.h" +#include "spp_log.h" +#include "types.h" +#include + +static const char *TAG = "DATALOGGER"; + +retval_t DATALOGGER_Init(Datalogger_t *p_logger, void *p_storage_cfg, const char *p_file_path) +{ + retval_t ret; + + memset(p_logger, 0, sizeof(Datalogger_t)); + p_logger->p_storage_cfg = p_storage_cfg; + + ret = SPP_HAL_Storage_Mount(p_storage_cfg); + if (ret != SPP_OK) + { + SPP_LOGE(TAG, "Storage mount failed"); + return ret; + } + + p_logger->p_file = fopen(p_file_path, "w"); + if (p_logger->p_file == NULL) + { + SPP_LOGE(TAG, "Failed to open file: %s", p_file_path); + (void)SPP_HAL_Storage_Unmount(p_storage_cfg); + return SPP_ERROR; + } + + p_logger->is_initialized = 1U; + p_logger->logged_packets = 0U; + + SPP_LOGI(TAG, "Init OK file=%s", p_file_path); + return SPP_OK; +} + +retval_t DATALOGGER_LogPacket(Datalogger_t *p_logger, const spp_packet_t *p_packet) +{ + if ((p_logger->is_initialized == 0U) || (p_logger->p_file == NULL)) + { + return SPP_ERROR; + } + + int logSD; + logSD = + fprintf(p_logger->p_file, + "pkt=%lu ver=%u apid=0x%04X seq=%u len=%u ts=%lu drop=%u crc=%u payload_hex=", + (unsigned long)p_logger->logged_packets, (unsigned)p_packet->primary_header.version, + (unsigned)p_packet->primary_header.apid, (unsigned)p_packet->primary_header.seq, + (unsigned)p_packet->primary_header.payload_len, + (unsigned long)p_packet->secondary_header.timestamp_ms, + (unsigned)p_packet->secondary_header.drop_counter, (unsigned)p_packet->crc); + + if (logSD < 0) + { + SPP_LOGE(TAG, "fprintf header failed"); + return SPP_ERROR; + } + + + for (spp_uint16_t i = 0U; i < p_packet->primary_header.payload_len; i++) + { + // Write payload in hexa. + logSD = fprintf(p_logger->p_file, "%02X", (unsigned)p_packet->payload[i]); + if (logSD < 0) + { + SPP_LOGE(TAG, "fprintf payload failed"); + return SPP_ERROR; + } + + // Add a separator + if (i + 1U < p_packet->primary_header.payload_len) + { + logSD = fprintf(p_logger->p_file, " "); + } + } + // New line after writing the packet + logSD = fprintf(p_logger->p_file, "\n"); + + p_logger->logged_packets++; + + return SPP_OK; +} + +retval_t DATALOGGER_Flush(Datalogger_t *p_logger) +{ + if ((p_logger->is_initialized == 0U) || (p_logger->p_file == NULL)) + { + return SPP_ERROR; + } + + if (fflush(p_logger->p_file) != 0) + { + SPP_LOGE(TAG, "fflush failed"); + return SPP_ERROR; + } + + SPP_LOGI(TAG, "fflush OK"); + return SPP_OK; +} + +retval_t DATALOGGER_Deinit(Datalogger_t *p_logger) +{ + retval_t ret; + + if (p_logger == NULL) + { + return SPP_ERROR_NULL_POINTER; + } + + if (p_logger->p_file != NULL) + { + if (fflush(p_logger->p_file) != 0) + { + SPP_LOGE(TAG, "fflush failed during deinit"); + } + + fclose(p_logger->p_file); + p_logger->p_file = NULL; + } + + if (p_logger->p_storage_cfg != NULL) + { + ret = SPP_HAL_Storage_Unmount(p_logger->p_storage_cfg); + if (ret != SPP_OK) + { + SPP_LOGE(TAG, "Storage unmount failed"); + p_logger->is_initialized = 0U; + p_logger->p_storage_cfg = NULL; + return ret; + } + } + + p_logger->is_initialized = 0U; + p_logger->p_storage_cfg = NULL; + + SPP_LOGI(TAG, "Deinit OK"); + return SPP_OK; +} \ No newline at end of file diff --git a/solaris-v1/components/datalogger_driver/include/dataloggerSD.h b/solaris-v1/components/datalogger_driver/include/dataloggerSD.h index e69de29b..52041d33 100644 --- a/solaris-v1/components/datalogger_driver/include/dataloggerSD.h +++ b/solaris-v1/components/datalogger_driver/include/dataloggerSD.h @@ -0,0 +1,25 @@ +#ifndef DATALOGGER_H +#define DATALOGGER_H + +#include "spp/core/returntypes.h" +#include "spp/core/packet.h" +#include +#include + +typedef struct +{ + void *p_storage_cfg; + FILE *p_file; + uint8_t is_initialized; + uint32_t logged_packets; +} Datalogger_t; + +retval_t DATALOGGER_Init(Datalogger_t *p_logger, void *p_storage_cfg, const char *p_file_path); + +retval_t DATALOGGER_LogPacket(Datalogger_t *p_logger, const spp_packet_t *p_packet); + +retval_t DATALOGGER_Flush(Datalogger_t *p_logger); + +retval_t DATALOGGER_Deinit(Datalogger_t *p_logger); + +#endif /* DATALOGGER_H */ \ No newline at end of file diff --git a/solaris-v1/external/spp b/solaris-v1/external/spp index 675b39c9..34c411fd 160000 --- a/solaris-v1/external/spp +++ b/solaris-v1/external/spp @@ -1 +1 @@ -Subproject commit 675b39c900e39acb2d6d50b8e0d981743aba7140 +Subproject commit 34c411fd86a63e6b504a9be562d89334d09a0064 diff --git a/solaris-v1/external/spp-ports b/solaris-v1/external/spp-ports index 024c8299..03851388 160000 --- a/solaris-v1/external/spp-ports +++ b/solaris-v1/external/spp-ports @@ -1 +1 @@ -Subproject commit 024c8299e9bd6edba0a33d15dc1d823ad449256d +Subproject commit 0385138829adf7455bea55941e7b79a06548808a diff --git a/solaris-v1/main/bmpService.c b/solaris-v1/main/bmpService.c index bb4839fc..30843390 100644 --- a/solaris-v1/main/bmpService.c +++ b/solaris-v1/main/bmpService.c @@ -2,6 +2,10 @@ #include "bmp390.h" #include "gpio_int.h" +#include "dataloggerSD.h" +#include "storage.h" +#include "spi.h" +#include "macros_esp.h" #include "services/databank/databank.h" #include "services/db_flow/db_flow.h" @@ -15,146 +19,55 @@ * Private constants * ---------------------------------------------------------------- */ -/** - * @brief Log tag used by the BMP390 service. - */ static const char *s_bmpServiceLogTag = "BMP_SERVICE"; -/** - * @brief Application Process Identifier used for BMP debug packets. - */ -#define K_BMP_SERVICE_APID_DBG 0x0101U +#define K_BMP_SERVICE_APID_DBG 0x0101U +#define K_BMP_SERVICE_TASK_PRIO 5U +#define K_BMP_SERVICE_TASK_DELAY_MS 200U +#define K_BMP_SERVICE_TASK_STACK_SIZE 4096U +#define K_BMP_SERVICE_PAYLOAD_LEN 12U -/** - * @brief Priority of the BMP service task. - */ -#define K_BMP_SERVICE_TASK_PRIO 5U - -/** - * @brief Delay between iterations of the BMP service task, in milliseconds. - */ -#define K_BMP_SERVICE_TASK_DELAY_MS 200U - -/** - * @brief Stack size of the BMP service task. - */ -#define K_BMP_SERVICE_TASK_STACK_SIZE 4096U - -/** - * @brief Payload length in bytes for altitude, pressure and temperature floats. - */ -#define K_BMP_SERVICE_PAYLOAD_LEN 12U +#define K_BMP_SERVICE_LOG_FILE_PATH "/sdcard/log.txt" +#define K_BMP_SERVICE_LOG_MAX_PACKETS 10U /* ---------------------------------------------------------------- * Private state * ---------------------------------------------------------------- */ -/** - * @brief SPI handler associated with the BMP sensor. - */ static void *s_pSpi = NULL; - -/** - * @brief BMP390 service context. - */ static BMP390_Data_t s_bmpData; - -/** - * @brief Packet sequence counter used by the BMP service. - */ static spp_uint16_t s_seq = 0U; -/* ---------------------------------------------------------------- - * Private helpers - * ---------------------------------------------------------------- */ +static SPP_Storage_InitCfg s_sdCfg = {.p_base_path = "/sdcard", + .spi_host_id = USED_HOST, + .pin_cs = CS_PIN_SDC, + .max_files = 5U, + .allocation_unit_size = (16U * 1024U), + .format_if_mount_failed = false}; -/** - * @brief Logs the basic contents of a packet header. - * - * @param[in] p_prefix Prefix string to identify the log source. - * @param[in] p_packet Pointer to the packet to log. - */ -static void BMP_ServiceLogPacketBasic(const char *p_prefix, const spp_packet_t *p_packet) +static void BMP_ServiceTask(void *p_arg) { - if (p_packet == NULL) - { - SPP_LOGE(s_bmpServiceLogTag, "%s pkt=NULL", p_prefix); - return; - } + Datalogger_t logger; + retval_t ret; + uint8_t logger_active = 0U; - SPP_LOGI(s_bmpServiceLogTag, - "%s pkt=%p ver=%u apid=0x%04X seq=%u len=%u crc=%u", - p_prefix, - (void *)p_packet, - (unsigned)p_packet->primary_header.version, - (unsigned)p_packet->primary_header.apid, - (unsigned)p_packet->primary_header.seq, - (unsigned)p_packet->primary_header.payload_len, - (unsigned)p_packet->crc); -} + (void)p_arg; -/** - * @brief Logs the payload of a packet as three float values. - * - * The payload is interpreted as: - * - altitude at payload[0] - * - pressure at payload[4] - * - temperature at payload[8] - * - * @param[in] p_prefix Prefix string to identify the log source. - * @param[in] p_packet Pointer to the packet to log. - */ -static void BMP_ServiceLogPacketPayloadFloats(const char *p_prefix, const spp_packet_t *p_packet) -{ - float altitude = 0.0f; - float pressure = 0.0f; - float temperature = 0.0f; + SPP_LOGI(s_bmpServiceLogTag, "Task start"); - if (p_packet == NULL) + ret = DATALOGGER_Init(&logger, (void *)&s_sdCfg, K_BMP_SERVICE_LOG_FILE_PATH); + if (ret != SPP_OK) { - return; + SPP_LOGE(s_bmpServiceLogTag, "DATALOGGER_Init failed ret=%d", (int)ret); } - - if (p_packet->primary_header.payload_len < K_BMP_SERVICE_PAYLOAD_LEN) + else { - SPP_LOGI(s_bmpServiceLogTag, - "%s payload too small len=%u", - p_prefix, - (unsigned)p_packet->primary_header.payload_len); - return; + logger_active = 1U; + SPP_LOGI(s_bmpServiceLogTag, "Datalogger ready"); } - memcpy(&altitude, &p_packet->payload[0], sizeof(float)); - memcpy(&pressure, &p_packet->payload[4], sizeof(float)); - memcpy(&temperature, &p_packet->payload[8], sizeof(float)); - - SPP_LOGI(s_bmpServiceLogTag, - "%s payload alt=%.2f p=%.2f t=%.2f", - p_prefix, - altitude, - pressure, - temperature); -} - -/** - * @brief BMP390 service task. - * - * This task waits for the BMP390 data-ready interrupt, acquires altitude, - * pressure and temperature from the sensor, stores them in a packet, - * publishes the packet to the ready flow, then simulates a consumer that - * pops the packet and returns it to the databank. - * - * @param[in] p_arg Unused task argument. - */ -static void BMP_ServiceTask(void *p_arg) -{ - (void)p_arg; - - SPP_LOGI(s_bmpServiceLogTag, "Task start"); - for (;;) { - retval_t ret; spp_packet_t *p_packet; float altitude = 0.0f; float pressure = 0.0f; @@ -168,9 +81,6 @@ static void BMP_ServiceTask(void *p_arg) continue; } - SPP_LOGI(s_bmpServiceLogTag, "DRDY received"); - - SPP_LOGI(s_bmpServiceLogTag, "Requesting free packet..."); p_packet = SPP_DATABANK_getPacket(); if (p_packet == NULL) { @@ -178,25 +88,15 @@ static void BMP_ServiceTask(void *p_arg) continue; } - SPP_LOGI(s_bmpServiceLogTag, "Got free packet ptr=%p", (void *)p_packet); - BMP_ServiceLogPacketBasic("FREE_PKT", p_packet); - ret = BMP390_getAltitude(s_pSpi, &s_bmpData, &altitude, &pressure, &temperature); if (ret != SPP_OK) { - SPP_LOGE(s_bmpServiceLogTag, - "BMP390_getAltitude failed ret=%d -> return packet", + SPP_LOGE(s_bmpServiceLogTag, "BMP390_getAltitude failed ret=%d -> return packet", (int)ret); (void)SPP_DATABANK_returnPacket(p_packet); continue; } - SPP_LOGI(s_bmpServiceLogTag, - "BMP read alt=%.2f p=%.2f t=%.2f", - altitude, - pressure, - temperature); - p_packet->primary_header.version = SPP_PKT_VERSION; p_packet->primary_header.apid = K_BMP_SERVICE_APID_DBG; p_packet->primary_header.seq = s_seq++; @@ -212,65 +112,65 @@ static void BMP_ServiceTask(void *p_arg) memcpy(&p_packet->payload[4], &pressure, sizeof(float)); memcpy(&p_packet->payload[8], &temperature, sizeof(float)); - BMP_ServiceLogPacketBasic("FILLED", p_packet); - BMP_ServiceLogPacketPayloadFloats("FILLED", p_packet); - - SPP_LOGI(s_bmpServiceLogTag, "Publishing to DB_FLOW..."); ret = DB_FLOW_PushReady(p_packet); if (ret != SPP_OK) { - SPP_LOGE(s_bmpServiceLogTag, - "DB_FLOW_PushReady failed ret=%d -> return packet", + SPP_LOGE(s_bmpServiceLogTag, "DB_FLOW_PushReady failed ret=%d -> return packet", (int)ret); (void)SPP_DATABANK_returnPacket(p_packet); continue; } - SPP_LOGI(s_bmpServiceLogTag, - "Published ok ready=%lu", - (unsigned long)DB_FLOW_ReadyCount()); - - SPP_LOGI(s_bmpServiceLogTag, "Consumer pop..."); ret = DB_FLOW_PopReady(&p_packetRx); if ((ret != SPP_OK) || (p_packetRx == NULL)) { - SPP_LOGE(s_bmpServiceLogTag, - "DB_FLOW_PopReady failed ret=%d pkt_rx=%p", - (int)ret, + SPP_LOGE(s_bmpServiceLogTag, "DB_FLOW_PopReady failed ret=%d pkt_rx=%p", (int)ret, (void *)p_packetRx); continue; } - SPP_LOGI(s_bmpServiceLogTag, - "Consumer got ptr=%p ready=%lu", - (void *)p_packetRx, - (unsigned long)DB_FLOW_ReadyCount()); - - BMP_ServiceLogPacketBasic("RECEIVED", p_packetRx); - BMP_ServiceLogPacketPayloadFloats("RECEIVED", p_packetRx); + if (logger_active == 1U) + { + ret = DATALOGGER_LogPacket(&logger, p_packetRx); + if (ret != SPP_OK) + { + SPP_LOGE(s_bmpServiceLogTag, "DATALOGGER_LogPacket failed ret=%d", (int)ret); + } + + if (logger.logged_packets >= K_BMP_SERVICE_LOG_MAX_PACKETS) + { + ret = DATALOGGER_Flush(&logger); + if (ret != SPP_OK) + { + SPP_LOGE(s_bmpServiceLogTag, "DATALOGGER_Flush failed ret=%d", (int)ret); + } + + ret = DATALOGGER_Deinit(&logger); + if (ret != SPP_OK) + { + SPP_LOGE(s_bmpServiceLogTag, "DATALOGGER_Deinit failed ret=%d", (int)ret); + } + else + { + SPP_LOGI(s_bmpServiceLogTag, "Datalogger finished after %u packets", + (unsigned)K_BMP_SERVICE_LOG_MAX_PACKETS); + } + + logger_active = 0U; + } + } - SPP_LOGI(s_bmpServiceLogTag, "Returning packet to databank..."); ret = SPP_DATABANK_returnPacket(p_packetRx); if (ret != SPP_OK) { - SPP_LOGE(s_bmpServiceLogTag, - "SPP_DATABANK_returnPacket failed ret=%d", - (int)ret); + SPP_LOGE(s_bmpServiceLogTag, "SPP_DATABANK_returnPacket failed ret=%d", (int)ret); continue; } - BMP_ServiceLogPacketBasic("AFTER_RETURN", p_packetRx); - BMP_ServiceLogPacketPayloadFloats("AFTER_RETURN", p_packetRx); - SPP_OSAL_TaskDelay(K_BMP_SERVICE_TASK_DELAY_MS); } } -/* ---------------------------------------------------------------- - * Public API - * ---------------------------------------------------------------- */ - -/** @copydoc BMP_ServiceInit */ retval_t BMP_ServiceInit(void *p_spi_bmp) { retval_t ret; @@ -309,13 +209,6 @@ retval_t BMP_ServiceInit(void *p_spi_bmp) return SPP_OK; } -/** - * @brief Starts the BMP service task. - * - * This function allocates task storage and creates the BMP service task. - * - * @return SPP_OK on success, or an error code otherwise. - */ retval_t BMP_ServiceStart(void) { void *p_storage; @@ -328,13 +221,9 @@ retval_t BMP_ServiceStart(void) return SPP_ERROR; } - p_taskHandle = SPP_OSAL_TaskCreate( - (void *)BMP_ServiceTask, - "bmp_service", - K_BMP_SERVICE_TASK_STACK_SIZE, - NULL, - K_BMP_SERVICE_TASK_PRIO, - p_storage); + p_taskHandle = + SPP_OSAL_TaskCreate((void *)BMP_ServiceTask, "bmp_service", K_BMP_SERVICE_TASK_STACK_SIZE, + NULL, K_BMP_SERVICE_TASK_PRIO, p_storage); if (p_taskHandle == NULL) { diff --git a/solaris-v1/main/bmpService.h b/solaris-v1/main/bmpService.h index 9540c46f..e459e849 100644 --- a/solaris-v1/main/bmpService.h +++ b/solaris-v1/main/bmpService.h @@ -4,10 +4,11 @@ #include "core/returntypes.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -/** + /** * @file bmp_service.h * @brief Public API for the BMP390 service layer. * @@ -23,7 +24,7 @@ extern "C" { * through the system data services. */ -/** + /** * @brief Initializes the BMP390 service. * * This function prepares the BMP390 service context and associates it @@ -36,9 +37,9 @@ extern "C" { * - SPP_OK if initialization succeeds * - Error code otherwise */ -retval_t BMP_ServiceInit(void *p_spi_bmp); + retval_t BMP_ServiceInit(void *p_spi_bmp); -/** + /** * @brief Starts the BMP390 service. * * This function starts the internal service execution, typically by @@ -49,7 +50,7 @@ retval_t BMP_ServiceInit(void *p_spi_bmp); * - SPP_OK if the service starts correctly * - Error code otherwise */ -retval_t BMP_ServiceStart(void); + retval_t BMP_ServiceStart(void); #ifdef __cplusplus } diff --git a/solaris-v1/main/main.c b/solaris-v1/main/main.c index c258e744..75b54413 100644 --- a/solaris-v1/main/main.c +++ b/solaris-v1/main/main.c @@ -1,161 +1,103 @@ -#include "core.h" -#include "icm20948.h" -#include "spi.h" - -#include "gpio_int.h" -#include "driver/gpio.h" +#include "core/core.h" #include "core/returntypes.h" +#include "spi.h" #include "spp_log.h" #include "osal/task.h" #include "services/databank/databank.h" #include "services/db_flow/db_flow.h" -#include "bmpService.h" - -#include -/** - * @file main.c - * @brief Application entry point for ICM20948 initialization, BMP service - * startup and FIFO polling. - */ +#include "bmpService.h" static const char *TAG = "MAIN"; -/** - * @brief Main application entry point. - * - * This function initializes the core services, configures the SPI bus, - * initializes both SPI devices in order (ICM first, BMP second), configures - * the ICM20948, initializes the databank and DB flow services, starts the BMP - * service and continuously polls the ICM20948 FIFO. - */ void app_main(void) { - retval_t ret = SPP_ERROR; - void *p_spiIcm = NULL; - void *p_spiBmp = NULL; - Core_Init(); + retval_t ret; + Core_Init(); SPP_LOGI(TAG, "Boot"); - ret = SPP_HAL_SPI_BusInit(); + ret = SPP_DATABANK_init(); if (ret != SPP_OK) { - SPP_LOGE(TAG, "SPI bus init failed"); + SPP_LOGE(TAG, "Databank init failed"); for (;;) { SPP_OSAL_TaskDelay(1000); } } - /* ---------------------------------------------------------------- - * ICM SPI device init - * ---------------------------------------------------------------- */ - p_spiIcm = SPP_HAL_SPI_GetHandler(); - if (p_spiIcm == NULL) + ret = DB_FLOW_Init(); + if (ret != SPP_OK) { - SPP_LOGE(TAG, "SPI handler ICM is NULL"); + SPP_LOGE(TAG, "DB_FLOW init failed"); for (;;) { SPP_OSAL_TaskDelay(1000); } } - ret = SPP_HAL_SPI_DeviceInit(p_spiIcm); + ret = SPP_HAL_SPI_BusInit(); if (ret != SPP_OK) { - SPP_LOGE(TAG, "SPI dev init ICM failed"); + SPP_LOGE(TAG, "SPI bus init failed"); for (;;) { SPP_OSAL_TaskDelay(1000); } } - ret = ICM20948_configDmpInit(p_spiIcm); + // Keep handler order: 1st ICM dummy, 2nd BMP + void *p_spi_icm_dummy = SPP_HAL_SPI_GetHandler(); + ret = SPP_HAL_SPI_DeviceInit(p_spi_icm_dummy); if (ret != SPP_OK) { - SPP_LOGE(TAG, "ICM20948_configDmpInit failed"); + SPP_LOGE(TAG, "SPI dev init ICM dummy failed"); for (;;) { SPP_OSAL_TaskDelay(1000); } } - /* ---------------------------------------------------------------- - * Common services init - * ---------------------------------------------------------------- */ - ret = SPP_DATABANK_init(); + void *p_spi_bmp = SPP_HAL_SPI_GetHandler(); + ret = SPP_HAL_SPI_DeviceInit(p_spi_bmp); if (ret != SPP_OK) { - SPP_LOGE(TAG, "Databank init failed"); + SPP_LOGE(TAG, "SPI dev init BMP failed"); for (;;) { SPP_OSAL_TaskDelay(1000); } } - // ret = DB_FLOW_Init(); - // if (ret != SPP_OK) - // { - // SPP_LOGE(TAG, "DB_FLOW init failed"); - // for (;;) - // { - // SPP_OSAL_TaskDelay(1000); - // } - // } - - /* ---------------------------------------------------------------- - * BMP SPI device init - * ---------------------------------------------------------------- */ - p_spiBmp = SPP_HAL_SPI_GetHandler(); - if (p_spiBmp == NULL) + SPP_LOGI(TAG, "BMP service init"); + ret = BMP_ServiceInit(p_spi_bmp); + if (ret != SPP_OK) { - SPP_LOGE(TAG, "SPI handler BMP is NULL"); + SPP_LOGE(TAG, "BMP_ServiceInit failed ret=%d", (int)ret); for (;;) { SPP_OSAL_TaskDelay(1000); } } - ret = SPP_HAL_SPI_DeviceInit(p_spiBmp); + SPP_LOGI(TAG, "BMP service start"); + ret = BMP_ServiceStart(); if (ret != SPP_OK) { - SPP_LOGE(TAG, "SPI dev init BMP failed"); + SPP_LOGE(TAG, "BMP_ServiceStart failed ret=%d", (int)ret); for (;;) { SPP_OSAL_TaskDelay(1000); } } - // SPP_LOGI(TAG, "BMP service init"); - // ret = BMP_ServiceInit(p_spiBmp); - // if (ret != SPP_OK) - // { - // SPP_LOGE(TAG, "BMP_ServiceInit failed ret=%d", (int)ret); - // for (;;) - // { - // SPP_OSAL_TaskDelay(1000); - // } - // } - - // SPP_LOGI(TAG, "BMP service start"); - // ret = BMP_ServiceStart(); - // if (ret != SPP_OK) - // { - // SPP_LOGE(TAG, "BMP_ServiceStart failed ret=%d", (int)ret); - // for (;;) - // { - // SPP_OSAL_TaskDelay(1000); - // } - // } - SPP_LOGI(TAG, "Main idle"); - - while (true) + for (;;) { - ICM20948_checkFifoData(p_spiIcm); + SPP_OSAL_TaskDelay(1000); } } \ No newline at end of file