From f361ff52b634ddcd97a3f63bad32732c00a89ae7 Mon Sep 17 00:00:00 2001 From: Adithya65 Date: Thu, 28 Aug 2025 21:41:16 +0530 Subject: [PATCH 1/3] I2C:add I2C read api >add I2C read api. >add RTC sample. --- drivers/i2c/stm_i2c.c | 76 ++++++++++++++++++++++++++++--------------- drivers/i2c/stm_i2c.h | 2 ++ samples/i2c_sample.c | 45 +++++++++++++++++++++++-- 3 files changed, 95 insertions(+), 28 deletions(-) diff --git a/drivers/i2c/stm_i2c.c b/drivers/i2c/stm_i2c.c index 277578a..d3d3f3b 100644 --- a/drivers/i2c/stm_i2c.c +++ b/drivers/i2c/stm_i2c.c @@ -13,8 +13,8 @@ static void init_rcc(); static void config_gpio(); static void init_i2c(); -static int32_t i2c_write_byte(uint8_t addr, uint8_t* data, uint16_t len, uint8_t start, - uint8_t reload); +static int32_t i2c_write_helper(uint8_t addr, uint8_t* data, uint16_t len, uint8_t start, + uint8_t reload); void i2c_init(void) { @@ -23,24 +23,6 @@ void i2c_init(void) init_i2c(); } -void i2c_stop() -{ - uint32_t volatile reg_val, timeout; - - reg_val = REG_RD(I2C1_BASE_ADDR + I2C_CR2_OFFSET); - reg_val |= 1 << 14; - REG_WR(I2C1_BASE_ADDR + I2C_CR2_OFFSET, reg_val); - - timeout = TIMEOUT; - while (!(REG_RD(I2C1_BASE_ADDR + I2C_ISR_OFFSET) & (1 << 5))) - { - if (--timeout == 0) - return; - } - REG_WR(I2C1_BASE_ADDR + I2C_ICR_OFFSET, (1 << 5)); -} - - int32_t i2c_write_data(uint8_t addr, uint8_t* data, uint32_t len, uint8_t start, uint8_t reload) { int32_t ret = 0; @@ -49,7 +31,7 @@ int32_t i2c_write_data(uint8_t addr, uint8_t* data, uint32_t len, uint8_t start, while( sent < len ) { uint16_t chunk = (((len - sent) < 255)?(len - sent):255); - ret = i2c_write_byte(addr, data + sent, chunk, start, reload); + ret = i2c_write_helper(addr, data + sent, chunk, start, reload); if(ret != 0) return -EINVAL; sent += chunk; @@ -59,8 +41,8 @@ int32_t i2c_write_data(uint8_t addr, uint8_t* data, uint32_t len, uint8_t start, } -static int32_t i2c_write_byte(uint8_t addr, uint8_t* data, uint16_t len, uint8_t start, - uint8_t reload) +static int32_t i2c_write_helper(uint8_t addr, uint8_t* data, uint16_t len, uint8_t start, + uint8_t reload) { uint32_t volatile reg_val, timeout; @@ -83,7 +65,7 @@ static int32_t i2c_write_byte(uint8_t addr, uint8_t* data, uint16_t len, uint8_t while (!(REG_RD(I2C1_BASE_ADDR + I2C_ISR_OFFSET) & (1 << 0))) { if (--timeout == 0) - return -EINVAL; + return -ETIMEDOUT; } } @@ -94,7 +76,7 @@ static int32_t i2c_write_byte(uint8_t addr, uint8_t* data, uint16_t len, uint8_t while (!(REG_RD(I2C1_BASE_ADDR + I2C_ISR_OFFSET) & (1 << 6))) { if (--timeout == 0) - return -EINVAL; + return -ETIMEDOUT; } } else @@ -102,13 +84,55 @@ static int32_t i2c_write_byte(uint8_t addr, uint8_t* data, uint16_t len, uint8_t while (!(REG_RD(I2C1_BASE_ADDR + I2C_ISR_OFFSET) & (1 << 7))) { if (--timeout == 0) - return -EINVAL; + return -ETIMEDOUT; + } + } + + return 0; +} + +int32_t i2c_read_data(uint8_t addr, uint8_t* data, uint16_t len) +{ + uint32_t volatile reg_val, timeout; + + reg_val = (addr << 1) | (len << 16) | (1 << 10); + REG_WR(I2C1_BASE_ADDR + I2C_CR2_OFFSET, reg_val); + reg_val |= (1 << 13); + REG_WR(I2C1_BASE_ADDR + I2C_CR2_OFFSET, reg_val); + + + for (uint16_t volatile i = 0; i < len; i++) + { + timeout = 100000; + while (!(REG_RD(I2C1_BASE_ADDR + I2C_ISR_OFFSET) & (1 << 2))) + { + if (--timeout == 0) + return -ETIMEDOUT; } + data[i] = (uint8_t)REG_RD(I2C1_BASE_ADDR + I2C_RXDR_OFFSET); } + return 0; } +void i2c_stop() +{ + uint32_t volatile reg_val, timeout; + + reg_val = REG_RD(I2C1_BASE_ADDR + I2C_CR2_OFFSET); + reg_val |= 1 << 14; + REG_WR(I2C1_BASE_ADDR + I2C_CR2_OFFSET, reg_val); + + timeout = TIMEOUT; + while (!(REG_RD(I2C1_BASE_ADDR + I2C_ISR_OFFSET) & (1 << 5))) + { + if (--timeout == 0) + return; + } + REG_WR(I2C1_BASE_ADDR + I2C_ICR_OFFSET, (1 << 5)); +} + static void init_rcc() { uint32_t reg_val; diff --git a/drivers/i2c/stm_i2c.h b/drivers/i2c/stm_i2c.h index 2381abc..7cd2488 100644 --- a/drivers/i2c/stm_i2c.h +++ b/drivers/i2c/stm_i2c.h @@ -19,10 +19,12 @@ #define I2C_ISR_OFFSET 0x18 #define I2C_TXDR_OFFSET 0x28 #define I2C_ICR_OFFSET 0x1C +#define I2C_RXDR_OFFSET 0x24 void i2c_init(void); void i2c_stop(); int32_t i2c_write_data(uint8_t addr, uint8_t* data, uint32_t len, uint8_t start, uint8_t reload); +int32_t i2c_read_data(uint8_t addr, uint8_t* data, uint16_t len); #endif diff --git a/samples/i2c_sample.c b/samples/i2c_sample.c index e969d66..c113e6a 100644 --- a/samples/i2c_sample.c +++ b/samples/i2c_sample.c @@ -17,6 +17,7 @@ static void i2c_scan_task(void *pvParameters); static void i2c_oled_display(); static int32_t oled_send_command(uint32_t cmd); static int32_t oled_send_data(uint8_t *data, uint16_t len); +static void i2c_read_rtc(void *pvParameters); uint8_t buff[256]; @@ -100,11 +101,18 @@ int32_t i2c_sample(void) xTaskCreate(i2c_oled_display, "I2C_OLED", - 512, + 256, NULL, 1, NULL); + xTaskCreate(i2c_read_rtc, + "I2C_RTC", + 256, + NULL, + 2, + NULL); + vTaskStartScheduler(); while(1) @@ -161,7 +169,7 @@ static void i2c_oled_display() if(oled_send_data(display_data, 1024)) { - printf("\r ERRORR!!\n"); + printf("\rNo Display Found!\n"); } while(1) @@ -233,3 +241,36 @@ static int32_t oled_send_data(uint8_t *data, uint16_t len) return ret; } #endif + +static inline uint8_t bcd2dec(uint8_t val) +{ + return ((val >> 4) * 10) + (val & 0x0F); +} + +static void i2c_read_rtc(void *pvParameters) +{ + uint8_t buf[7]; + uint8_t reg = 0x00; + + (void)pvParameters; + + while (1) + { + i2c_write_data(0x68, ®, 1, 1, 0); + + i2c_read_data(0x68, buf, 7); + + uint8_t sec = bcd2dec(buf[0] & 0x7F); + uint8_t min = bcd2dec(buf[1]); + uint8_t hour = bcd2dec(buf[2] & 0x3F); + uint8_t day = bcd2dec(buf[3]); + uint8_t date = bcd2dec(buf[4]); + uint8_t month = bcd2dec(buf[5] & 0x1F); + uint8_t year = bcd2dec(buf[6]); + + printf("\r %02d:%02d:%02d %02d-%02d-20%02d (Day:%d)\n", + hour, min, sec, date, month, year, day); + + vTaskDelay(pdMS_TO_TICKS(1000)); + } +} From 7291c646c5d1e39a54c061808fd87c8dd4bbbe1c Mon Sep 17 00:00:00 2001 From: Adithya65 Date: Fri, 29 Aug 2025 13:21:35 +0530 Subject: [PATCH 2/3] Add cli support for RTC --- cli/app/cli_app.c | 79 ++++++++++++++++++++ cli/app/cli_helper.c | 168 +++++++++++++++++++++++++++++++++++++++++++ sources/main.c | 4 +- 3 files changed, 249 insertions(+), 2 deletions(-) create mode 100644 cli/app/cli_app.c create mode 100644 cli/app/cli_helper.c diff --git a/cli/app/cli_app.c b/cli/app/cli_app.c new file mode 100644 index 0000000..153bb51 --- /dev/null +++ b/cli/app/cli_app.c @@ -0,0 +1,79 @@ +#include "FreeRTOS.h" +#include "task.h" +#include "FreeRTOS_CLI.h" +#include +#include +#include +#include "stm_i2c.h" + +extern void vRegisterCLICommands(void); + +#define MAX_INPUT_SIZE 60 +#define MAX_OUTPUT_SIZE 256 + +static char cInputBuffer[MAX_INPUT_SIZE]; +static char cOutputBuffer[MAX_OUTPUT_SIZE]; +static char cIsZeroBuffer[MAX_INPUT_SIZE]; + +void vCLITask(void *pvParameters) +{ + + BaseType_t xMoreDataToFollow; + int inputIndex = 0; + char c; + + (void)pvParameters; + + printf("\r\nSTM32#"); + + for (;;) + { + c = getchar(); + + if (c == '\r' || c == '\n') + { + if(!(memcmp(cInputBuffer, cIsZeroBuffer, MAX_INPUT_SIZE))) + { + printf("\r\nSTM32#"); + continue; + } + printf("\r\n"); + do + { + xMoreDataToFollow = FreeRTOS_CLIProcessCommand(cInputBuffer, cOutputBuffer, + MAX_OUTPUT_SIZE); + printf("%s", cOutputBuffer); + } + while (xMoreDataToFollow != pdFALSE); + + memset(cInputBuffer, 0, MAX_INPUT_SIZE); + inputIndex = 0; + printf("STM32#"); + } + else if (isprint((int)c) && inputIndex < MAX_INPUT_SIZE - 1) + { + cInputBuffer[inputIndex++] = c; + putchar(c); + } + else if (c == '\b' && inputIndex > 0) + { + inputIndex--; + cInputBuffer[inputIndex] = '\0'; + printf("\b \b"); + } + } +} + +int cli_task(void) +{ + i2c_init(); + vRegisterCLICommands(); + + xTaskCreate(vCLITask, "CLI", 1024, NULL, 1, NULL); + + vTaskStartScheduler(); + + while(1) + ; +} + diff --git a/cli/app/cli_helper.c b/cli/app/cli_helper.c new file mode 100644 index 0000000..6c094f1 --- /dev/null +++ b/cli/app/cli_helper.c @@ -0,0 +1,168 @@ +#include +#include +#include +#include "FreeRTOS.h" +#include "FreeRTOS_CLI.h" +#include "stm_i2c.h" + +/* Add Command */ +static BaseType_t prvAddCommand(char *pcWriteBuffer, size_t xWriteBufferLen, + const char *pcCommandString) +{ + const char *pcParameter1, *pcParameter2; + BaseType_t xParameter1Length, xParameter2Length; + int num1, num2; + + pcParameter1 = FreeRTOS_CLIGetParameter(pcCommandString, 1, &xParameter1Length); + pcParameter2 = FreeRTOS_CLIGetParameter(pcCommandString, 2, &xParameter2Length); + + if (pcParameter1 == NULL || pcParameter2 == NULL) + { + snprintf(pcWriteBuffer, xWriteBufferLen, "Error: Missing parameters\r\n"); + return pdFALSE; + } + + num1 = atoi(pcParameter1); + num2 = atoi(pcParameter2); + + snprintf(pcWriteBuffer, xWriteBufferLen, "Result: %d\r\n", num1 + num2); + return pdFALSE; +} + +/* Subtract Command */ +static BaseType_t prvSubCommand(char *pcWriteBuffer, size_t xWriteBufferLen, + const char *pcCommandString) +{ + const char *pcParameter1, *pcParameter2; + BaseType_t xParameter1Length, xParameter2Length; + int num1, num2; + + pcParameter1 = FreeRTOS_CLIGetParameter(pcCommandString, 1, &xParameter1Length); + pcParameter2 = FreeRTOS_CLIGetParameter(pcCommandString, 2, &xParameter2Length); + + if (pcParameter1 == NULL || pcParameter2 == NULL) + { + snprintf(pcWriteBuffer, xWriteBufferLen, "Error: Missing parameters\r\n"); + return pdFALSE; + } + + num1 = atoi(pcParameter1); + num2 = atoi(pcParameter2); + + snprintf(pcWriteBuffer, xWriteBufferLen, "Result: %d\r\n", num1 - num2); + return pdFALSE; +} + +static BaseType_t prvEchoCommand(char *pcWriteBuffer, size_t xWriteBufferLen, + const char *pcCommandString) +{ + const char *pcParameter1; + BaseType_t xParameter1Length; + + pcParameter1 = FreeRTOS_CLIGetParameter(pcCommandString, 1, &xParameter1Length); + + if (pcParameter1 == NULL) + { + snprintf(pcWriteBuffer, xWriteBufferLen, "Error: Missing parameters\r\n"); + return pdFALSE; + } + memcpy(pcWriteBuffer, pcParameter1, xWriteBufferLen); + strcat(pcWriteBuffer, "\r\n"); + return pdFALSE; +} + +static inline uint8_t bcd2dec(uint8_t val) +{ + return ((val >> 4) * 10) + (val & 0x0F); +} + +static BaseType_t prvDateCommand(char *pcWriteBuffer, size_t xWriteBufferLen, + const char *pcCommandString) +{ + (void)pcCommandString; + uint8_t buf[7]; + uint8_t reg = 0x00; + + i2c_write_data(0x68, ®, 1, 1, 0); + + i2c_read_data(0x68, buf, 7); + + uint8_t date = bcd2dec(buf[4]); + uint8_t month = bcd2dec(buf[5] & 0x1F); + uint8_t year = bcd2dec(buf[6]); + + snprintf(pcWriteBuffer, xWriteBufferLen, "%02d-%02d-20%02d \r\n", date, month, year); + + return pdFALSE; +} + +static BaseType_t prvTimeCommand(char *pcWriteBuffer, size_t xWriteBufferLen, + const char *pcCommandString) +{ + (void)pcCommandString; + + uint8_t buf[7]; + uint8_t reg = 0x00; + + i2c_write_data(0x68, ®, 1, 1, 0); + + i2c_read_data(0x68, buf, 7); + + uint8_t sec = bcd2dec(buf[0] & 0x7F); + uint8_t min = bcd2dec(buf[1]); + uint8_t hour = bcd2dec(buf[2] & 0x3F); + + snprintf(pcWriteBuffer, xWriteBufferLen, "%02d:%02d:%02d \r\n", hour, min, sec); + + return pdFALSE; +} + +static const CLI_Command_Definition_t xAddCommand = +{ + "add", + "add :\r\n Adds two numbers.\r\n", + prvAddCommand, + 2 +}; + +static const CLI_Command_Definition_t xSubCommand = +{ + "sub", + "sub :\r\n Subtracts second number from first.\r\n", + prvSubCommand, + 2 +}; + +static const CLI_Command_Definition_t xEchoCommand = +{ + "echo", + "echo :\r\n Echo input message\r\n", + prvEchoCommand, + -1 +}; + +static const CLI_Command_Definition_t xDateCommand = +{ + "get_date", + "get_date:\r\n Returns date,month and year\r\n", + prvDateCommand, + 0 +}; + +static const CLI_Command_Definition_t xTimeCommand = +{ + "get_time", + "get_time:\r\n Returns current time\r\n", + prvTimeCommand, + 0 +}; + +void vRegisterCLICommands(void) +{ + FreeRTOS_CLIRegisterCommand(&xAddCommand); + FreeRTOS_CLIRegisterCommand(&xSubCommand); + FreeRTOS_CLIRegisterCommand(&xEchoCommand); + FreeRTOS_CLIRegisterCommand(&xDateCommand); + FreeRTOS_CLIRegisterCommand(&xTimeCommand); +} + diff --git a/sources/main.c b/sources/main.c index 2a81230..1e13f93 100644 --- a/sources/main.c +++ b/sources/main.c @@ -3,8 +3,8 @@ #include #define RUN_FREERTOS_TESTS 0 -#define RUN_STM_SAMPLE 1 -#define RUN_CLI_TASK 0 +#define RUN_STM_SAMPLE 0 +#define RUN_CLI_TASK 1 void cli_task(); void stm_samples(); From cf87555a13074f1daa6204d3a8e418558165f591 Mon Sep 17 00:00:00 2001 From: Adithya65 Date: Fri, 29 Aug 2025 15:52:23 +0530 Subject: [PATCH 3/3] Build system:Modify build system >replaced manual target configuration to configuring in build time --- .github/workflows/buid.yml | 2 +- CMakeLists.txt | 35 +++++++++++-- cli/app/cli_cal.c | 103 ------------------------------------- cli/app/cli_sample.c | 77 --------------------------- sources/main.c | 14 ++--- 5 files changed, 40 insertions(+), 191 deletions(-) delete mode 100644 cli/app/cli_cal.c delete mode 100644 cli/app/cli_sample.c diff --git a/.github/workflows/buid.yml b/.github/workflows/buid.yml index 48b221c..f1ba749 100644 --- a/.github/workflows/buid.yml +++ b/.github/workflows/buid.yml @@ -34,7 +34,7 @@ jobs: - name: Build firmware run: | cd build - make -j$(nproc) + make cli -j$(nproc) # 5. Check ELF file size (helpful sanity check) - name: Firmware size diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e7bf11..842ab07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,34 @@ cmake_minimum_required(VERSION 3.15) + +option(BUILD_CLI "Build CLI mode" OFF) +option(BUILD_SAMPLES "Build Samples mode" OFF) +option(BUILD_TESTS "Build Tests mode" OFF) + +if(BUILD_CLI) + add_compile_definitions(APP_MODE=CLI) +elseif(BUILD_SAMPLES) + add_compile_definitions(APP_MODE=SAMPLES) +elseif(BUILD_TESTS) + add_compile_definitions(APP_MODE=TESTS) +endif() + + +add_custom_target(cli + COMMAND ${CMAKE_COMMAND} -DBUILD_CLI=ON -S ${CMAKE_SOURCE_DIR} -B ${CMAKE_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} +) + +add_custom_target(samples + COMMAND ${CMAKE_COMMAND} -DBUILD_SAMPLES=ON -S ${CMAKE_SOURCE_DIR} -B ${CMAKE_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} +) + +add_custom_target(tests + COMMAND ${CMAKE_COMMAND} -DBUILD_TESTS=ON -S ${CMAKE_SOURCE_DIR} -B ${CMAKE_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} +) + + set(FREERTOS_KERNEL_DIR ${CMAKE_SOURCE_DIR}/freertos/FreeRTOS-Kernel) set(FREERTOS_PORT_DIR ${CMAKE_SOURCE_DIR}/freertos/) set(FREERTOS_SRC @@ -28,7 +58,6 @@ set(I2C_DRIVER ${CMAKE_SOURCE_DIR}/drivers/i2c/stm_i2c.c ) - project(blinky C) set(CPU_FLAGS "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard") @@ -43,8 +72,8 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/sources/console.c ${CMAKE_SOURCE_DIR}/sources/main.c ${CMAKE_SOURCE_DIR}/cli/base/FreeRTOS_CLI.c - ${CMAKE_SOURCE_DIR}/cli/app/cli_sample.c - ${CMAKE_SOURCE_DIR}/cli/app/cli_cal.c + ${CMAKE_SOURCE_DIR}/cli/app/cli_app.c + ${CMAKE_SOURCE_DIR}/cli/app/cli_helper.c ${CMAKE_SOURCE_DIR}/samples/i2c_sample.c ${UART_DRIVER} ${I2C_DRIVER} diff --git a/cli/app/cli_cal.c b/cli/app/cli_cal.c deleted file mode 100644 index 3427ad8..0000000 --- a/cli/app/cli_cal.c +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -#include "FreeRTOS.h" -#include "FreeRTOS_CLI.h" - -/* Add Command */ -static BaseType_t prvAddCommand(char *pcWriteBuffer, size_t xWriteBufferLen, - const char *pcCommandString) -{ - const char *pcParameter1, *pcParameter2; - BaseType_t xParameter1Length, xParameter2Length; - int num1, num2; - - pcParameter1 = FreeRTOS_CLIGetParameter(pcCommandString, 1, &xParameter1Length); - pcParameter2 = FreeRTOS_CLIGetParameter(pcCommandString, 2, &xParameter2Length); - - if (pcParameter1 == NULL || pcParameter2 == NULL) - { - snprintf(pcWriteBuffer, xWriteBufferLen, "Error: Missing parameters\r\n"); - return pdFALSE; - } - - num1 = atoi(pcParameter1); - num2 = atoi(pcParameter2); - - snprintf(pcWriteBuffer, xWriteBufferLen, "Result: %d\r\n", num1 + num2); - return pdFALSE; -} - -/* Subtract Command */ -static BaseType_t prvSubCommand(char *pcWriteBuffer, size_t xWriteBufferLen, - const char *pcCommandString) -{ - const char *pcParameter1, *pcParameter2; - BaseType_t xParameter1Length, xParameter2Length; - int num1, num2; - - pcParameter1 = FreeRTOS_CLIGetParameter(pcCommandString, 1, &xParameter1Length); - pcParameter2 = FreeRTOS_CLIGetParameter(pcCommandString, 2, &xParameter2Length); - - if (pcParameter1 == NULL || pcParameter2 == NULL) - { - snprintf(pcWriteBuffer, xWriteBufferLen, "Error: Missing parameters\r\n"); - return pdFALSE; - } - - num1 = atoi(pcParameter1); - num2 = atoi(pcParameter2); - - snprintf(pcWriteBuffer, xWriteBufferLen, "Result: %d\r\n", num1 - num2); - return pdFALSE; -} - -static BaseType_t prvEchoCommand(char *pcWriteBuffer, size_t xWriteBufferLen, - const char *pcCommandString) -{ - const char *pcParameter1; - BaseType_t xParameter1Length; - - pcParameter1 = FreeRTOS_CLIGetParameter(pcCommandString, 1, &xParameter1Length); - - if (pcParameter1 == NULL) - { - snprintf(pcWriteBuffer, xWriteBufferLen, "Error: Missing parameters\r\n"); - return pdFALSE; - } - memcpy(pcWriteBuffer, pcParameter1, xWriteBufferLen); - strcat(pcWriteBuffer, "\r\n"); - return pdFALSE; -} - -static const CLI_Command_Definition_t xAddCommand = -{ - "add", - "add :\r\n Adds two numbers.\r\n", - prvAddCommand, - 2 -}; - -static const CLI_Command_Definition_t xSubCommand = -{ - "sub", - "sub :\r\n Subtracts second number from first.\r\n", - prvSubCommand, - 2 -}; - -static const CLI_Command_Definition_t xEchoCommand = -{ - "echo", - "echo :\r\n Echo input message\r\n", - prvEchoCommand, - -1 -}; - -void vRegisterCLICommands(void) -{ - FreeRTOS_CLIRegisterCommand(&xAddCommand); - FreeRTOS_CLIRegisterCommand(&xSubCommand); - FreeRTOS_CLIRegisterCommand(&xEchoCommand); -} - diff --git a/cli/app/cli_sample.c b/cli/app/cli_sample.c deleted file mode 100644 index 07f20e6..0000000 --- a/cli/app/cli_sample.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "FreeRTOS.h" -#include "task.h" -#include "FreeRTOS_CLI.h" -#include -#include -#include - -extern void vRegisterCLICommands(void); - -#define MAX_INPUT_SIZE 60 -#define MAX_OUTPUT_SIZE 256 - -static char cInputBuffer[MAX_INPUT_SIZE]; -static char cOutputBuffer[MAX_OUTPUT_SIZE]; -static char cIsZeroBuffer[MAX_INPUT_SIZE]; - -void vCLITask(void *pvParameters) -{ - - BaseType_t xMoreDataToFollow; - int inputIndex = 0; - char c; - - (void)pvParameters; - - printf("\r\nSTM32#"); - - for (;;) - { - c = getchar(); - - if (c == '\r' || c == '\n') - { - if(!(memcmp(cInputBuffer, cIsZeroBuffer, MAX_INPUT_SIZE))) - { - printf("\r\nSTM32#"); - continue; - } - printf("\r\n"); - do - { - xMoreDataToFollow = FreeRTOS_CLIProcessCommand(cInputBuffer, cOutputBuffer, - MAX_OUTPUT_SIZE); - printf("%s", cOutputBuffer); - } - while (xMoreDataToFollow != pdFALSE); - - memset(cInputBuffer, 0, MAX_INPUT_SIZE); - inputIndex = 0; - printf("STM32#"); - } - else if (isprint((int)c) && inputIndex < MAX_INPUT_SIZE - 1) - { - cInputBuffer[inputIndex++] = c; - putchar(c); - } - else if (c == '\b' && inputIndex > 0) - { - inputIndex--; - cInputBuffer[inputIndex] = '\0'; - printf("\b \b"); - } - } -} - -int cli_task(void) -{ - vRegisterCLICommands(); - - xTaskCreate(vCLITask, "CLI", 1024, NULL, 1, NULL); - - vTaskStartScheduler(); - - while(1) - ; -} - diff --git a/sources/main.c b/sources/main.c index 1e13f93..728af6c 100644 --- a/sources/main.c +++ b/sources/main.c @@ -2,21 +2,21 @@ #include "freertos_tests.h" #include -#define RUN_FREERTOS_TESTS 0 -#define RUN_STM_SAMPLE 0 -#define RUN_CLI_TASK 1 +#define CLI 1 +#define SAMPLES 2 +#define TESTS 3 void cli_task(); void stm_samples(); int main() { -#if RUN_STM_SAMPLE +#if APP_MODE == CLI + cli_task(); +#elif APP_MODE == SAMPLES stm_samples(); -#elif RUN_FREERTOS_TESTS +#elif APP_MODE == TESTS (void)freertos_tests(); -#elif RUN_CLI_TASK - cli_task(); #else #error "Invalid Source" #endif