From 2becaa5eab9e54ca36b389e8bc4000fe95864173 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 18 Aug 2020 18:58:00 +1000 Subject: [PATCH] Further work on Pinecil compile --- Dockerfile | 2 +- .../{Inc => BSP/Miniware}/FreeRTOSConfig.h | 0 .../GCC/ARM_CM3 => Core/BSP/Miniware}/port.c | 0 .../ARM_CM3 => Core/BSP/Miniware}/portmacro.h | 0 .../TS100/Core/BSP/Pine64/I2C_Wrapper.cpp | 247 ++-- .../TS100/Core/BSP/Pine64/Model_Config.h | 27 + workspace/TS100/Core/BSP/Pine64/N200/port.c | 192 ++- .../TS100/Core/BSP/Pine64/N200/portmacro.h | 152 +-- workspace/TS100/Core/Drivers/I2C_Wrapper.hpp | 18 +- workspace/TS100/Core/Drivers/LIS2DH12.cpp | 50 +- workspace/TS100/Core/Drivers/LIS2DH12.hpp | 17 +- workspace/TS100/Core/Inc/FreeRTOSHooks.h | 13 +- workspace/TS100/Core/Inc/Settings.h | 60 +- workspace/TS100/Core/Inc/main.hpp | 21 +- workspace/TS100/Core/Src/FreeRTOSHooks.c | 20 +- workspace/TS100/Core/Threads/PIDThread.cpp | 55 +- .../Lib/GD32VF103xB.lds => GD32VF103xB.ld} | 0 workspace/TS100/Makefile | 17 +- .../FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c | 1072 +++++++++-------- .../Source/include/deprecated_definitions.h | 279 ----- .../FreeRTOS/Source/include/portable.h | 115 +- workspace/TS100/configuration.h | 117 +- 22 files changed, 1214 insertions(+), 1260 deletions(-) rename workspace/TS100/Core/{Inc => BSP/Miniware}/FreeRTOSConfig.h (100%) rename workspace/TS100/{Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3 => Core/BSP/Miniware}/port.c (100%) rename workspace/TS100/{Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3 => Core/BSP/Miniware}/portmacro.h (100%) create mode 100644 workspace/TS100/Core/BSP/Pine64/Model_Config.h rename workspace/TS100/{Core/BSP/Pine64/Vendor/Lib/GD32VF103xB.lds => GD32VF103xB.ld} (100%) delete mode 100644 workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h diff --git a/Dockerfile b/Dockerfile index bcef5988..345acdc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,6 @@ RUN wget -qO- https://github.com/riscv-mcu/riscv-gnu-toolchain/releases/download # Add compiler to the path ENV PATH "/build/gcc-arm-none-eabi-9-2020-q2-update/bin:$PATH" -ENV PATH "/build/rv_linux_bare_1908291308/bin:$PATH" +ENV PATH "/build/rv_linux_bare_1908312208/bin/:$PATH" COPY . /build/source COPY ./ci /build/ci diff --git a/workspace/TS100/Core/Inc/FreeRTOSConfig.h b/workspace/TS100/Core/BSP/Miniware/FreeRTOSConfig.h similarity index 100% rename from workspace/TS100/Core/Inc/FreeRTOSConfig.h rename to workspace/TS100/Core/BSP/Miniware/FreeRTOSConfig.h diff --git a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c b/workspace/TS100/Core/BSP/Miniware/port.c similarity index 100% rename from workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c rename to workspace/TS100/Core/BSP/Miniware/port.c diff --git a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h b/workspace/TS100/Core/BSP/Miniware/portmacro.h similarity index 100% rename from workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h rename to workspace/TS100/Core/BSP/Miniware/portmacro.h diff --git a/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp b/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp index e73b9891..73f94629 100644 --- a/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -12,7 +12,8 @@ SemaphoreHandle_t FRToSI2C::I2CSemaphore; StaticSemaphore_t FRToSI2C::xSemaphoreBuffer; #define FLAG_TIMEOUT 1000 -void FRToSI2C::CpltCallback() { +void FRToSI2C::CpltCallback() +{ //TODO } @@ -20,28 +21,31 @@ void FRToSI2C::CpltCallback() { * * @param obj The I2C object */ -int i2c_start() { +int i2c_start() +{ int timeout; /* clear I2C_FLAG_AERR Flag */ i2c_flag_clear(I2C0, I2C_FLAG_AERR); /* wait until I2C_FLAG_I2CBSY flag is reset */ - timeout = FLAG_TIMEOUT - ; - while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) { - if ((timeout--) == 0) { + timeout = FLAG_TIMEOUT; + while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) + { + if ((timeout--) == 0) + { - return (int) -1; + return (int)-1; } } /* ensure the i2c has been stopped */ - timeout = FLAG_TIMEOUT - ; - while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP) == I2C_CTL0_STOP) { - if ((timeout--) == 0) { - return (int) -1; + timeout = FLAG_TIMEOUT; + while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP) == I2C_CTL0_STOP) + { + if ((timeout--) == 0) + { + return (int)-1; } } @@ -49,30 +53,34 @@ int i2c_start() { i2c_start_on_bus(I2C0); /* ensure the i2c has been started successfully */ - timeout = FLAG_TIMEOUT - ; - while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) { - if ((timeout--) == 0) { - return (int) -1; + timeout = FLAG_TIMEOUT; + while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) + { + if ((timeout--) == 0) + { + return (int)-1; } } - return (int) 0; + return (int)0; } /** Send STOP command * * @param obj The I2C object */ -int i2c_stop() { +int i2c_stop() +{ /* generate a STOP condition */ i2c_stop_on_bus(I2C0); /* wait for STOP bit reset */ int timeout = FLAG_TIMEOUT; - while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP)) { - if ((timeout--) == 0) { + while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP)) + { + if ((timeout--) == 0) + { return -1; } } @@ -86,26 +94,32 @@ int i2c_stop() { * @param last Acknoledge * @return The read byte */ -int i2c_byte_read(int last) { +int i2c_byte_read(int last) +{ int timeout; - if (last) { + if (last) + { /* disable acknowledge */ i2c_ack_config(I2C0, I2C_ACK_DISABLE); - } else { + } + else + { /* enable acknowledge */ i2c_ack_config(I2C0, I2C_ACK_ENABLE); } /* wait until the byte is received */ timeout = FLAG_TIMEOUT; - while ((i2c_flag_get(I2C0, I2C_FLAG_RBNE)) == RESET) { - if ((timeout--) == 0) { + while ((i2c_flag_get(I2C0, I2C_FLAG_RBNE)) == RESET) + { + if ((timeout--) == 0) + { return -1; } } - return (int) i2c_data_receive(I2C0); + return (int)i2c_data_receive(I2C0); } /** Write one byte @@ -114,15 +128,17 @@ int i2c_byte_read(int last) { * @param data Byte to be written * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout. */ -int i2c_byte_write(int data) { +int i2c_byte_write(int data) +{ int timeout; i2c_data_transmit(I2C0, data); /* wait until the byte is transmitted */ timeout = FLAG_TIMEOUT; - while (((i2c_flag_get(I2C0, I2C_FLAG_TBE)) == RESET) - || ((i2c_flag_get(I2C0, I2C_FLAG_BTC)) == RESET)) { - if ((timeout--) == 0) { + while (((i2c_flag_get(I2C0, I2C_FLAG_TBE)) == RESET) || ((i2c_flag_get(I2C0, I2C_FLAG_BTC)) == RESET)) + { + if ((timeout--) == 0) + { return 2; } } @@ -131,7 +147,8 @@ int i2c_byte_write(int data) { } bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, - uint8_t *pData, uint16_t Size) { + uint8_t *pData, uint16_t Size) +{ if (!lock()) return false; @@ -140,13 +157,18 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, /* wait until I2C_FLAG_I2CBSY flag is reset */ timeout = FLAG_TIMEOUT; - while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) { - if ((timeout--) == 0) { + while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) + { + if ((timeout--) == 0) + { i2c_stop(); unlock(); return false; - } else { - if (timeout % 5 == 0) { + } + else + { + if (timeout % 5 == 0) + { i2c_stop(); } } @@ -155,10 +177,11 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, i2c_start_on_bus(I2C0); /* ensure the i2c has been started successfully */ - timeout = FLAG_TIMEOUT - ; - while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) { - if ((timeout--) == 0) { + timeout = FLAG_TIMEOUT; + while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) + { + if ((timeout--) == 0) + { i2c_stop(); unlock(); return false; @@ -170,9 +193,11 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, timeout = 0; /* wait until I2C_FLAG_ADDSEND flag is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { + while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) + { timeout++; - if (timeout > 100000) { + if (timeout > 100000) + { i2c_stop(); unlock(); return false; @@ -180,7 +205,8 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, } bool no_ack = i2c_flag_get(I2C0, I2C_FLAG_AERR); no_ack |= i2c_flag_get(I2C0, I2C_FLAG_BERR); - if (no_ack) { + if (no_ack) + { i2c_stop(); unlock(); return false; @@ -190,21 +216,23 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, int status = i2c_byte_write(MemAddress); no_ack |= i2c_flag_get(I2C0, I2C_FLAG_BERR); no_ack |= i2c_flag_get(I2C0, I2C_FLAG_LOSTARB); - if (status == 2 || no_ack) { + if (status == 2 || no_ack) + { i2c_stop(); unlock(); return false; } -//////////////////////////// //Restart into read + //////////////////////////// //Restart into read /* generate a START condition */ i2c_start_on_bus(I2C0); /* ensure the i2c has been started successfully */ - timeout = FLAG_TIMEOUT - ; - while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) { - if ((timeout--) == 0) { + timeout = FLAG_TIMEOUT; + while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) + { + if ((timeout--) == 0) + { i2c_stop(); unlock(); return false; @@ -216,9 +244,11 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, timeout = 0; /* wait until I2C_FLAG_ADDSEND flag is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { + while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) + { timeout++; - if (timeout > 100000) { + if (timeout > 100000) + { i2c_stop(); unlock(); return false; @@ -228,13 +258,15 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, /* clear ADDSEND */ i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); no_ack = i2c_flag_get(I2C0, I2C_FLAG_AERR); - if (no_ack) { + if (no_ack) + { i2c_stop(); unlock(); return false; } - for (count = 0; count < Size; count++) { - pData[count] = i2c_byte_read(count == (Size - 1)); + for (count = 0; count < Size; count++) + { + pData[count] = i2c_byte_read(count == (uint32_t)(Size - 1)); } /* if not sequential write, then send stop */ @@ -243,17 +275,20 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, unlock(); return true; } -void FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { +void FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) +{ Mem_Write(address, reg, &data, 1); } -uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) { +uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) +{ uint8_t temp = 0; Mem_Read(add, reg, &temp, 1); return temp; } void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, - uint8_t *pData, uint16_t Size) { + uint8_t *pData, uint16_t Size) +{ if (!lock()) return; @@ -261,15 +296,19 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, int timeout = 0; /* wait until I2C_FLAG_I2CBSY flag is reset */ - timeout = FLAG_TIMEOUT - ; - while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) { - if ((timeout--) == 0) { + timeout = FLAG_TIMEOUT; + while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) + { + if ((timeout--) == 0) + { i2c_stop(); unlock(); return; - } else { - if (timeout % 5 == 0) { + } + else + { + if (timeout % 5 == 0) + { i2c_stop(); } } @@ -278,10 +317,11 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, i2c_start_on_bus(I2C0); /* ensure the i2c has been started successfully */ - timeout = FLAG_TIMEOUT - ; - while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) { - if ((timeout--) == 0) { + timeout = FLAG_TIMEOUT; + while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) + { + if ((timeout--) == 0) + { i2c_stop(); unlock(); return; @@ -293,9 +333,11 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, timeout = 0; /* wait until I2C_FLAG_ADDSEND flag is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { + while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) + { timeout++; - if (timeout > 100000) { + if (timeout > 100000) + { i2c_stop(); unlock(); return; @@ -305,9 +347,11 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, /* clear ADDSEND */ i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); int status = i2c_byte_write(MemAddress); - for (count = 0; count < Size; count++) { + for (count = 0; count < Size; count++) + { status = i2c_byte_write(pData[count]); - if (status != 1) { + if (status != 1) + { i2c_stop(); unlock(); return; @@ -320,7 +364,8 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, unlock(); } -void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { +void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) +{ if (!lock()) return; uint32_t count = 0; @@ -328,13 +373,18 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { /* wait until I2C_FLAG_I2CBSY flag is reset */ timeout = FLAG_TIMEOUT; - while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) { - if ((timeout--) == 0) { + while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) + { + if ((timeout--) == 0) + { i2c_stop(); unlock(); return; - } else { - if (timeout % 5 == 0) { + } + else + { + if (timeout % 5 == 0) + { i2c_stop(); } } @@ -343,10 +393,11 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { i2c_start_on_bus(I2C0); /* ensure the i2c has been started successfully */ - timeout = FLAG_TIMEOUT - ; - while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) { - if ((timeout--) == 0) { + timeout = FLAG_TIMEOUT; + while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) + { + if ((timeout--) == 0) + { i2c_stop(); unlock(); return; @@ -358,9 +409,11 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { timeout = 0; /* wait until I2C_FLAG_ADDSEND flag is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { + while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) + { timeout++; - if (timeout > 100000) { + if (timeout > 100000) + { i2c_stop(); unlock(); return; @@ -370,9 +423,11 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { /* clear ADDSEND */ i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - for (count = 0; count < Size; count++) { + for (count = 0; count < Size; count++) + { int status = i2c_byte_write(pData[count]); - if (status != 1) { + if (status != 1) + { i2c_stop(); unlock(); return; @@ -385,7 +440,8 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { unlock(); } -bool FRToSI2C::probe(uint16_t DevAddress) { +bool FRToSI2C::probe(uint16_t DevAddress) +{ if (!lock()) return false; i2c_start(); @@ -393,14 +449,16 @@ bool FRToSI2C::probe(uint16_t DevAddress) { i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); /* wait until ADDSEND bit is set */ int timeout = FLAG_TIMEOUT; - while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { - if (i2c_flag_get(I2C0, I2C_FLAG_AERR) - || i2c_flag_get(I2C0, I2C_FLAG_BERR)) { + while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) + { + if (i2c_flag_get(I2C0, I2C_FLAG_AERR) || i2c_flag_get(I2C0, I2C_FLAG_BERR)) + { i2c_stop(); unlock(); return false; } - if (timeout-- == 0) { + if (timeout-- == 0) + { i2c_stop(); unlock(); return false; @@ -422,17 +480,20 @@ bool FRToSI2C::probe(uint16_t DevAddress) { return !no_ack; } -void FRToSI2C::I2C_Unstick() { +void FRToSI2C::I2C_Unstick() +{ unstick_I2C(); } -bool FRToSI2C::lock() { +bool FRToSI2C::lock() +{ if (I2CSemaphore == nullptr) return true; - return xSemaphoreTake(I2CSemaphore,1000) == pdTRUE; + return xSemaphoreTake(I2CSemaphore, 1000) == pdTRUE; } -void FRToSI2C::unlock() { +void FRToSI2C::unlock() +{ if (I2CSemaphore == nullptr) return; xSemaphoreGive(I2CSemaphore); diff --git a/workspace/TS100/Core/BSP/Pine64/Model_Config.h b/workspace/TS100/Core/BSP/Pine64/Model_Config.h new file mode 100644 index 00000000..6d274997 --- /dev/null +++ b/workspace/TS100/Core/BSP/Pine64/Model_Config.h @@ -0,0 +1,27 @@ +/* + * Model_Config.h + * + * Created on: 25 Jul 2020 + * Author: Ralim + */ + +#ifndef BSP_MINIWARE_MODEL_CONFIG_H_ +#define BSP_MINIWARE_MODEL_CONFIG_H_ +/* + * Lookup for mapping features <-> Models + */ + +#if defined(MODEL_Pinecil) > 1 +#error "Multiple models defined!" +#elif defined(MODEL_Pinecil) == 0 +#error "No model defined!" +#endif + +#ifdef MODEL_Pinecil +#define ACCEL_LIS +#define TEMP_TMP36 +#define POW_QC +#define POW_PD +#endif + +#endif /* BSP_MINIWARE_MODEL_CONFIG_H_ */ diff --git a/workspace/TS100/Core/BSP/Pine64/N200/port.c b/workspace/TS100/Core/BSP/Pine64/N200/port.c index ac7c84fd..13b06f47 100644 --- a/workspace/TS100/Core/BSP/Pine64/N200/port.c +++ b/workspace/TS100/Core/BSP/Pine64/N200/port.c @@ -1,3 +1,4 @@ +#include "FreeRTOSConfig.h" #include "FreeRTOS.h" #include "task.h" #include "portmacro.h" @@ -6,36 +7,32 @@ #include "riscv_encoding.h" #include "n200_timer.h" #include "n200_eclic.h" - /* Standard Includes */ #include #include #include - /* Each task maintains its own interrupt status in the critical nesting variable. */ UBaseType_t uxCriticalNesting = 0xaaaaaaaa; #if USER_MODE_TASKS #ifdef __riscv_flen - unsigned long MSTATUS_INIT = (MSTATUS_MPIE | (0x1 << 13)); +unsigned long MSTATUS_INIT = (MSTATUS_MPIE | (0x1 << 13)); #else - unsigned long MSTATUS_INIT = (MSTATUS_MPIE); +unsigned long MSTATUS_INIT = (MSTATUS_MPIE); #endif #else #ifdef __riscv_flen - unsigned long MSTATUS_INIT = (MSTATUS_MPP | MSTATUS_MPIE | (0x1 << 13)); +unsigned long MSTATUS_INIT = (MSTATUS_MPP | MSTATUS_MPIE | (0x1 << 13)); #else - unsigned long MSTATUS_INIT = (MSTATUS_MPP | MSTATUS_MPIE); +unsigned long MSTATUS_INIT = (MSTATUS_MPP | MSTATUS_MPIE); #endif #endif - /* * Used to catch tasks that attempt to return from their implementing function. */ -static void prvTaskExitError( void ); - +static void prvTaskExitError(void); /** * @brief System Call Trap @@ -47,52 +44,51 @@ static void prvTaskExitError( void ); */ unsigned long ulSynchTrap(unsigned long mcause, unsigned long sp, unsigned long arg1) { - switch(mcause&0X00000fff) + switch (mcause & 0X00000fff) { - //on User and Machine ECALL, handler the request - case 8: - case 11: + //on User and Machine ECALL, handler the request + case 8: + case 11: + { + if (arg1 == IRQ_DISABLE) { - if(arg1==IRQ_DISABLE) - { - //zero out mstatus.mpie - clear_csr(mstatus,MSTATUS_MPIE); - } - else if(arg1==IRQ_ENABLE) - { - //set mstatus.mpie - set_csr(mstatus,MSTATUS_MPIE); - } - else if(arg1==PORT_YIELD) - { - //always yield from machine mode - //fix up mepc on sync trap - unsigned long epc = read_csr(mepc); - vPortYield_from_ulSynchTrap(sp,epc+4); - } - else if(arg1==PORT_YIELD_TO_RA) - { - vPortYield_from_ulSynchTrap(sp,(*(unsigned long*)(sp+1*sizeof(sp)))); - } - break; + //zero out mstatus.mpie + clear_csr(mstatus, MSTATUS_MPIE); } - default: + else if (arg1 == IRQ_ENABLE) { - /* 异常处理 */ - extern uintptr_t handle_trap(uintptr_t mcause, uintptr_t sp); - handle_trap(mcause,sp); + //set mstatus.mpie + set_csr(mstatus, MSTATUS_MPIE); } + else if (arg1 == PORT_YIELD) + { + //always yield from machine mode + //fix up mepc on sync trap + unsigned long epc = read_csr(mepc); + vPortYield_from_ulSynchTrap(sp, epc + 4); + } + else if (arg1 == PORT_YIELD_TO_RA) + { + vPortYield_from_ulSynchTrap(sp, (*(unsigned long *)(sp + 1 * sizeof(sp)))); + } + break; + } + default: + { + /* 异常处理 */ + extern uintptr_t handle_trap(uintptr_t mcause, uintptr_t sp); + handle_trap(mcause, sp); + } } //fix mepc and return unsigned long epc = read_csr(mepc); - write_csr(mepc,epc+4); + write_csr(mepc, epc + 4); return sp; } /*-----------------------------------------------------------*/ - /** * @brief 设置触发软中断 * @note 目的是在软中断内进行任务上下文切换 @@ -100,24 +96,22 @@ unsigned long ulSynchTrap(unsigned long mcause, unsigned long sp, unsigned long */ void vPortSetMSIPInt(void) { - *(volatile uint8_t *) (TIMER_CTRL_ADDR + TIMER_MSIP) |=0x01; + *(volatile uint8_t *)(TIMER_CTRL_ADDR + TIMER_MSIP) |= 0x01; __asm volatile("fence"); __asm volatile("fence.i"); } /*-----------------------------------------------------------*/ - /** * @brief 清除软中断 * */ void vPortClearMSIPInt(void) { - *(volatile uint8_t *) (TIMER_CTRL_ADDR + TIMER_MSIP) &= ~0x01; + *(volatile uint8_t *)(TIMER_CTRL_ADDR + TIMER_MSIP) &= ~0x01; } /*-----------------------------------------------------------*/ - /** * @brief 执行任务上下文切换,在portasm.S中被调用 * @@ -125,23 +119,22 @@ void vPortClearMSIPInt(void) * @param arg1 * @return unsigned long sp地址 */ -unsigned long taskswitch( unsigned long sp, unsigned long arg1) +unsigned long taskswitch(unsigned long sp, unsigned long arg1) { //always yield from machine mode //fix up mepc on unsigned long epc = read_csr(mepc); - vPortYield(sp,epc); //never returns + vPortYield(sp, epc); //never returns return sp; } /*-----------------------------------------------------------*/ - /** * @brief 调研freertos内建函数vTaskSwitchContext,在portasm.S中被调用 * */ -void vDoTaskSwitchContext( void ) +void vDoTaskSwitchContext(void) { portDISABLE_INTERRUPTS(); vTaskSwitchContext(); @@ -149,45 +142,42 @@ void vDoTaskSwitchContext( void ) } /*-----------------------------------------------------------*/ - /** * @brief 进入临界段 * */ -void vPortEnterCritical( void ) +void vPortEnterCritical(void) { - #if USER_MODE_TASKS - ECALL(IRQ_DISABLE); - #else - portDISABLE_INTERRUPTS(); - #endif +#if USER_MODE_TASKS + ECALL(IRQ_DISABLE); +#else + portDISABLE_INTERRUPTS(); +#endif uxCriticalNesting++; } /*-----------------------------------------------------------*/ - /** * @brief 退出临界段 * */ -void vPortExitCritical( void ) +void vPortExitCritical(void) { - configASSERT( uxCriticalNesting ); + configASSERT(uxCriticalNesting); uxCriticalNesting--; - if( uxCriticalNesting == 0 ) + if (uxCriticalNesting == 0) { - #if USER_MODE_TASKS - ECALL(IRQ_ENABLE); - #else - portENABLE_INTERRUPTS(); - #endif +#if USER_MODE_TASKS + ECALL(IRQ_ENABLE); +#else + portENABLE_INTERRUPTS(); +#endif } return; } /*-----------------------------------------------------------*/ - /** * @brief Clear current interrupt mask and set given mask * @@ -195,11 +185,10 @@ void vPortExitCritical( void ) */ void vPortClearInterruptMask(int int_mask) { - eclic_set_mth (int_mask); + eclic_set_mth(int_mask); } /*-----------------------------------------------------------*/ - /** * @brief Set interrupt mask and return current interrupt enable register * @@ -207,15 +196,14 @@ void vPortClearInterruptMask(int int_mask) */ int xPortSetInterruptMask(void) { - int int_mask=0; - int_mask=eclic_get_mth(); + int int_mask = 0; + int_mask = eclic_get_mth(); portDISABLE_INTERRUPTS(); return int_mask; } /*-----------------------------------------------------------*/ - /** * @brief 初始化任务栈帧 * @@ -224,30 +212,30 @@ int xPortSetInterruptMask(void) * @param pvParameters 任务参数 * @return StackType_t* 完成初始化后的栈顶 */ -StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) +StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters) { /* Simulate the stack frame as it would be created by a context switch interrupt. */ #ifdef __riscv_flen - pxTopOfStack -= 32; /* 浮点寄存器 */ + pxTopOfStack -= 32; /* 浮点寄存器 */ #endif pxTopOfStack--; - *pxTopOfStack = 0xb8000000; /* CSR_MCAUSE */ + *pxTopOfStack = 0xb8000000; /* CSR_MCAUSE */ pxTopOfStack--; - *pxTopOfStack = 0x40; /* CSR_SUBM */ + *pxTopOfStack = 0x40; /* CSR_SUBM */ pxTopOfStack--; - *pxTopOfStack = (portSTACK_TYPE)pxCode; /* Start address */ + *pxTopOfStack = (portSTACK_TYPE)pxCode; /* Start address */ pxTopOfStack--; - *pxTopOfStack = MSTATUS_INIT; /* CSR_MSTATUS */ + *pxTopOfStack = MSTATUS_INIT; /* CSR_MSTATUS */ pxTopOfStack -= 22; - *pxTopOfStack = (portSTACK_TYPE)pvParameters; /* Register a0 */ + *pxTopOfStack = (portSTACK_TYPE)pvParameters; /* Register a0 */ - pxTopOfStack -=9; + pxTopOfStack -= 9; *pxTopOfStack = (portSTACK_TYPE)prvTaskExitError; /* Register ra */ pxTopOfStack--; @@ -255,25 +243,24 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px } /*-----------------------------------------------------------*/ - /** * @brief 任务退出函数 * */ -void prvTaskExitError( void ) +void prvTaskExitError(void) { /* A function that implements a task must not exit or attempt to return to its caller as there is nothing to return to. If a task wants to exit it should instead call vTaskDelete( NULL ). Artificially force an assert() to be triggered if configASSERT() is defined, then stop here so application writers can catch the error. */ - configASSERT( uxCriticalNesting == ~0UL ); + configASSERT(uxCriticalNesting == ~0UL); portDISABLE_INTERRUPTS(); - for( ;; ); + for (;;) + ; } /*-----------------------------------------------------------*/ - /** * @brief tick中断 * @note 由于该中断配置为向量模式,则中断到来会调用portasm.S的MTIME_HANDLER,进行栈帧保存之后该函数会调用vPortSysTickHandler @@ -281,39 +268,38 @@ void prvTaskExitError( void ) */ void vPortSysTickHandler(void) { - volatile uint64_t * mtime = (uint64_t*) (TIMER_CTRL_ADDR + TIMER_MTIME); - volatile uint64_t * mtimecmp = (uint64_t*) (TIMER_CTRL_ADDR + TIMER_MTIMECMP); + volatile uint64_t *mtime = (uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIME); + volatile uint64_t *mtimecmp = (uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIMECMP); UBaseType_t uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); - #if CONFIG_SYSTEMVIEW_EN +#if CONFIG_SYSTEMVIEW_EN traceISR_ENTER(); - #endif +#endif uint64_t now = *mtime; now += (configRTC_CLOCK_HZ / configTICK_RATE_HZ); *mtimecmp = now; /* 调用freertos的tick增加接口 */ - if( xTaskIncrementTick() != pdFALSE ) + if (xTaskIncrementTick() != pdFALSE) { - #if CONFIG_SYSTEMVIEW_EN +#if CONFIG_SYSTEMVIEW_EN traceISR_EXIT_TO_SCHEDULER(); - #endif +#endif portYIELD(); } - #if CONFIG_SYSTEMVIEW_EN +#if CONFIG_SYSTEMVIEW_EN else { traceISR_EXIT(); } - #endif +#endif - portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedInterruptStatus); } /*-----------------------------------------------------------*/ - /** * @brief 初始化tick * @@ -321,21 +307,20 @@ void vPortSysTickHandler(void) void vPortSetupTimer(void) { /* 内核timer定时器使用64位的计数器来实现 */ - volatile uint64_t * mtime = (uint64_t*) (TIMER_CTRL_ADDR + TIMER_MTIME); - volatile uint64_t * mtimecmp = (uint64_t*) (TIMER_CTRL_ADDR + TIMER_MTIMECMP); + volatile uint64_t *mtime = (uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIME); + volatile uint64_t *mtimecmp = (uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIMECMP); portENTER_CRITICAL(); - uint64_t now = *mtime; - now += (configRTC_CLOCK_HZ / configTICK_RATE_HZ); - *mtimecmp = now; + uint64_t now = *mtime; + now += (configRTC_CLOCK_HZ / configTICK_RATE_HZ); + *mtimecmp = now; portEXIT_CRITICAL(); eclic_set_vmode(CLIC_INT_TMR); - eclic_irq_enable(CLIC_INT_TMR,configKERNEL_INTERRUPT_PRIORITY>>configPRIO_BITS,0); + eclic_irq_enable(CLIC_INT_TMR, configKERNEL_INTERRUPT_PRIORITY >> configPRIO_BITS, 0); } /*-----------------------------------------------------------*/ - /** * @brief 初始化软中断 * @@ -343,11 +328,10 @@ void vPortSetupTimer(void) void vPortSetupMSIP(void) { eclic_set_vmode(CLIC_INT_SFT); - eclic_irq_enable(CLIC_INT_SFT,configKERNEL_INTERRUPT_PRIORITY>>configPRIO_BITS,0); + eclic_irq_enable(CLIC_INT_SFT, configKERNEL_INTERRUPT_PRIORITY >> configPRIO_BITS, 0); } /*-----------------------------------------------------------*/ - /** * @brief 调度启动前的初始化准备 * diff --git a/workspace/TS100/Core/BSP/Pine64/N200/portmacro.h b/workspace/TS100/Core/BSP/Pine64/N200/portmacro.h index 50383ac5..29ccc744 100644 --- a/workspace/TS100/Core/BSP/Pine64/N200/portmacro.h +++ b/workspace/TS100/Core/BSP/Pine64/N200/portmacro.h @@ -1,14 +1,13 @@ -#ifndef PORTMACRO_H -#define PORTMACRO_H +#ifndef PINE_PORTMACRO_H +#define PINE_PORTMACRO_H #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif - #include "riscv_encoding.h" - /*----------------------------------------------------------- * Port specific definitions. * @@ -20,123 +19,128 @@ extern "C" { */ /* Type definitions. */ -#define portCHAR char -#define portFLOAT float -#define portDOUBLE double -#define portLONG long -#define portSHORT short -#define portSTACK_TYPE uint32_t -#define portBASE_TYPE long +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE uint32_t +#define portBASE_TYPE long -typedef portSTACK_TYPE StackType_t; -typedef long BaseType_t; -typedef unsigned long UBaseType_t; + typedef portSTACK_TYPE StackType_t; + typedef long BaseType_t; + typedef unsigned long UBaseType_t; -#if( configUSE_16_BIT_TICKS == 1 ) +#if (configUSE_16_BIT_TICKS == 1) typedef uint16_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffff +#define portMAX_DELAY (TickType_t)0xffff #else - typedef uint32_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffffffffUL +typedef uint32_t TickType_t; +#define portMAX_DELAY (TickType_t)0xffffffffUL #endif /*-----------------------------------------------------------*/ /* Architecture specifics. */ -#define portSTACK_GROWTH ( -1 ) -#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) -#define portBYTE_ALIGNMENT 8 -/*-----------------------------------------------------------*/ - -/* Architecture specifics. */ -extern void vPortYield(unsigned long,unsigned long); -extern void vPortYield_from_ulSynchTrap(unsigned long,unsigned long); -extern int xPortSetInterruptMask(void); -extern void vPortClearInterruptMask( int uxSavedStatusValue ); +#define portSTACK_GROWTH (-1) +#define portTICK_PERIOD_MS ((TickType_t)1000 / configTICK_RATE_HZ) +#define portBYTE_ALIGNMENT 8 + /*-----------------------------------------------------------*/ + /* Architecture specifics. */ + extern void vPortYield(unsigned long, unsigned long); + extern void vPortYield_from_ulSynchTrap(unsigned long, unsigned long); + extern int xPortSetInterruptMask(void); + extern void vPortClearInterruptMask(int uxSavedStatusValue); /*-----------------------------------------------------------*/ /*System Calls */ /*-----------------------------------------------------------*/ //ecall macro used to store argument in a3 -#define ECALL(arg) ({ \ - register uintptr_t a2 asm ("a2") = (uintptr_t)(arg); \ - asm volatile ("ecall" \ - : "+r" (a2) \ - : \ - : "memory"); \ - a2; \ +#define ECALL(arg) ({ \ + register uintptr_t a2 asm("a2") = (uintptr_t)(arg); \ + asm volatile("ecall" \ + : "+r"(a2) \ + : \ + : "memory"); \ + a2; \ }) - -extern void vPortSetMSIPInt(void); + extern void vPortSetMSIPInt(void); #define port_MSIPSET_BIT vPortSetMSIPInt() -#define IRQ_DISABLE 20 -#define IRQ_ENABLE 30 -#define PORT_YIELD 40 -#define PORT_YIELD_TO_RA 50 +#define IRQ_DISABLE 20 +#define IRQ_ENABLE 30 +#define PORT_YIELD 40 +#define PORT_YIELD_TO_RA 50 /*-----------------------------------------------------------*/ - /* Scheduler utilities. */ /* the return after the ECALL is VERY important */ //#define portYIELD() ECALL(PORT_YIELD); #define portYIELD() port_MSIPSET_BIT; -#if CONFIG_SYSTEMVIEW_EN -#define portEND_SWITCHING_ISR(xSwitchRequired) { if( xSwitchRequired != pdFALSE) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else {traceISR_EXIT(); } } +#ifdef CONFIG_SYSTEMVIEW_EN +#define portEND_SWITCHING_ISR(xSwitchRequired) \ + { \ + if (xSwitchRequired != pdFALSE) \ + { \ + traceISR_EXIT_TO_SCHEDULER(); \ + portYIELD(); \ + } \ + else \ + { \ + traceISR_EXIT(); \ + } \ + } #else -#define portEND_SWITCHING_ISR(xSwitchRequired) if( xSwitchRequired != pdFALSE) portYIELD() +#define portEND_SWITCHING_ISR(xSwitchRequired) \ + if (xSwitchRequired != pdFALSE) \ + portYIELD() #endif -#define portYIELD_FROM_ISR(x) portEND_SWITCHING_ISR(x) +#define portYIELD_FROM_ISR(x) portEND_SWITCHING_ISR(x) -/* Critical section management. */ -extern void vPortEnterCritical( void ); -extern void vPortExitCritical( void ); -extern void eclic_set_mth (uint8_t mth); -#define portDISABLE_INTERRUPTS() \ -{ \ - eclic_set_mth((configMAX_SYSCALL_INTERRUPT_PRIORITY)|0x1f); \ - __asm volatile("fence"); \ - __asm volatile("fence.i"); \ -} -#define portENABLE_INTERRUPTS() eclic_set_mth(0) -#define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask() -#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) vPortClearInterruptMask( uxSavedStatusValue ) -#define portENTER_CRITICAL() vPortEnterCritical() -#define portEXIT_CRITICAL() vPortExitCritical() + /* Critical section management. */ + extern void vPortEnterCritical(void); + extern void vPortExitCritical(void); + extern void eclic_set_mth(uint8_t mth); +#define portDISABLE_INTERRUPTS() \ + { \ + eclic_set_mth((configMAX_SYSCALL_INTERRUPT_PRIORITY) | 0x1f); \ + __asm volatile("fence"); \ + __asm volatile("fence.i"); \ + } +#define portENABLE_INTERRUPTS() eclic_set_mth(0) +#define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask() +#define portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedStatusValue) vPortClearInterruptMask(uxSavedStatusValue) +#define portENTER_CRITICAL() vPortEnterCritical() +#define portEXIT_CRITICAL() vPortExitCritical() /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. These are not necessary for to use this port. They are defined so the common demo files (which build with all the ports) will build. */ -#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) -#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION_PROTO(vFunction, pvParameters) void vFunction(void *pvParameters) +#define portTASK_FUNCTION(vFunction, pvParameters) void vFunction(void *pvParameters) /*-----------------------------------------------------------*/ /* Tickless idle/low power functionality. */ #ifndef portSUPPRESS_TICKS_AND_SLEEP - extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); - #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) + extern void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime); +#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vPortSuppressTicksAndSleep(xExpectedIdleTime) #endif -/*-----------------------------------------------------------*/ + /*-----------------------------------------------------------*/ - -#define portINLINE __inline +#define portINLINE __inline #ifndef portFORCE_INLINE - #define portFORCE_INLINE inline __attribute__(( always_inline)) +#define portFORCE_INLINE inline __attribute__((always_inline)) #endif - - - #ifdef __cplusplus } #endif #endif /* PORTMACRO_H */ - diff --git a/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp b/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp index 779ddc20..224b7d41 100644 --- a/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp +++ b/workspace/TS100/Core/Drivers/I2C_Wrapper.hpp @@ -18,14 +18,16 @@ * * */ -class FRToSI2C { +class FRToSI2C +{ public: - - static void init() { + static void init() + { I2CSemaphore = nullptr; } - static void FRToSInit() { + static void FRToSInit() + { I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer); xSemaphoreGive(I2CSemaphore); } @@ -33,20 +35,22 @@ public: static void CpltCallback(); //Normal Tx Callback static bool Mem_Read(uint16_t DevAddress, uint16_t MemAddress, - uint8_t *pData, uint16_t Size); + uint8_t *pData, uint16_t Size); static void Mem_Write(uint16_t DevAddress, uint16_t MemAddress, - uint8_t *pData, uint16_t Size); + uint8_t *pData, uint16_t Size); //Returns true if device ACK's being addressed static bool probe(uint16_t DevAddress); static void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size); static void Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size); static void TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx, - uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx); + uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx); static void I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data); static uint8_t I2C_RegisterRead(uint8_t address, uint8_t reg); private: + static bool lock(); + static void unlock(); static void I2C_Unstick(); static SemaphoreHandle_t I2CSemaphore; static StaticSemaphore_t xSemaphoreBuffer; diff --git a/workspace/TS100/Core/Drivers/LIS2DH12.cpp b/workspace/TS100/Core/Drivers/LIS2DH12.cpp index 888e1231..dfd2de43 100644 --- a/workspace/TS100/Core/Drivers/LIS2DH12.cpp +++ b/workspace/TS100/Core/Drivers/LIS2DH12.cpp @@ -10,43 +10,55 @@ #include "LIS2DH12.hpp" #include "cmsis_os.h" -typedef struct { +typedef struct +{ const uint8_t reg; const uint8_t value; } LIS_REG; -static const LIS_REG i2c_registers[] = { { LIS_CTRL_REG1, 0x17 }, // 25Hz - { LIS_CTRL_REG2, 0b00001000 }, // Highpass filter off - { LIS_CTRL_REG3, 0b01100000 }, // Setup interrupt pins - { LIS_CTRL_REG4, 0b00001000 }, // Block update mode off, HR on - { LIS_CTRL_REG5, 0b00000010 }, { LIS_CTRL_REG6, 0b01100010 }, - //Basically setup the unit to run, and enable 4D orientation detection - { LIS_INT2_CFG, 0b01111110 }, //setup for movement detection - { LIS_INT2_THS, 0x28 }, { LIS_INT2_DURATION, 64 }, { - LIS_INT1_CFG, 0b01111110 }, { LIS_INT1_THS, 0x28 }, { - LIS_INT1_DURATION, 64 } }; +static const LIS_REG i2c_registers[] = {{LIS_CTRL_REG1, 0x17}, // 25Hz + {LIS_CTRL_REG2, 0b00001000}, // Highpass filter off + {LIS_CTRL_REG3, 0b01100000}, // Setup interrupt pins + {LIS_CTRL_REG4, 0b00001000}, // Block update mode off, HR on + {LIS_CTRL_REG5, 0b00000010}, + {LIS_CTRL_REG6, 0b01100010}, + //Basically setup the unit to run, and enable 4D orientation detection + {LIS_INT2_CFG, 0b01111110}, //setup for movement detection + {LIS_INT2_THS, 0x28}, + {LIS_INT2_DURATION, 64}, + {LIS_INT1_CFG, 0b01111110}, + {LIS_INT1_THS, 0x28}, + {LIS_INT1_DURATION, 64}}; -void LIS2DH12::initalize() { +void LIS2DH12::initalize() +{ +#ifdef ACCEL_LIS for (size_t index = 0; - index < (sizeof(i2c_registers) / sizeof(i2c_registers[0])); - index++) { + index < (sizeof(i2c_registers) / sizeof(i2c_registers[0])); + index++) + { FRToSI2C::I2C_RegisterWrite(LIS2DH_I2C_ADDRESS, - i2c_registers[index].reg, i2c_registers[index].value); + i2c_registers[index].reg, i2c_registers[index].value); } +#endif } -void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) { +void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) +{ +#ifdef ACCEL_LIS std::array sensorData; FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, - reinterpret_cast(sensorData.begin()), - sensorData.size() * sizeof(int16_t)); + reinterpret_cast(sensorData.begin()), + sensorData.size() * sizeof(int16_t)); x = sensorData[0]; y = sensorData[1]; z = sensorData[2]; +#endif } -bool LIS2DH12::detect() { +bool LIS2DH12::detect() +{ return FRToSI2C::probe(LIS2DH_I2C_ADDRESS); } diff --git a/workspace/TS100/Core/Drivers/LIS2DH12.hpp b/workspace/TS100/Core/Drivers/LIS2DH12.hpp index 79346e98..e4bef50f 100644 --- a/workspace/TS100/Core/Drivers/LIS2DH12.hpp +++ b/workspace/TS100/Core/Drivers/LIS2DH12.hpp @@ -11,15 +11,18 @@ #include "LIS2DH12_defines.hpp" #include "BSP.h" -class LIS2DH12 { +class LIS2DH12 +{ public: static bool detect(); static void initalize(); //1 = rh, 2,=lh, 8=flat - static Orientation getOrientation() { + static Orientation getOrientation() + { #ifdef LIS_ORI_FLIP uint8_t val = (FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS, - LIS_INT2_SRC) >> 2); + LIS_INT2_SRC) >> + 2); if (val == 8) val = 3; else if (val == 1) @@ -30,11 +33,13 @@ public: val = 3; return static_cast(val); #endif -#ifdef MODEL_TS100 - return static_cast((FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS,LIS_INT2_SRC) >> 2) - 1); +#ifdef ACCEL_LIS + return static_cast((FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS, LIS_INT2_SRC) >> 2) - 1); +#else + return Orientation::ORIENTATION_FLAT; #endif } - static void getAxisReadings(int16_t& x, int16_t& y, int16_t& z); + static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z); private: }; diff --git a/workspace/TS100/Core/Inc/FreeRTOSHooks.h b/workspace/TS100/Core/Inc/FreeRTOSHooks.h index 8dca47e6..c7653775 100644 --- a/workspace/TS100/Core/Inc/FreeRTOSHooks.h +++ b/workspace/TS100/Core/Inc/FreeRTOSHooks.h @@ -9,20 +9,19 @@ #define INC_FREERTOSHOOKS_H_ #include "FreeRTOS.h" -#include "cmsis_os.h" #include "unit.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -// RToS -void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, - StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize); -void vApplicationIdleHook(void); + // RToS + void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, + StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize); + void vApplicationIdleHook(void); #ifdef __cplusplus } #endif - #endif /* INC_FREERTOSHOOKS_H_ */ diff --git a/workspace/TS100/Core/Inc/Settings.h b/workspace/TS100/Core/Inc/Settings.h index 21d4b35d..8ddd11d5 100644 --- a/workspace/TS100/Core/Inc/Settings.h +++ b/workspace/TS100/Core/Inc/Settings.h @@ -10,9 +10,8 @@ #ifndef SETTINGS_H_ #define SETTINGS_H_ #include -#include "stm32f1xx_hal.h" #include "unit.h" -#define SETTINGSVERSION ( 0x20 ) +#define SETTINGSVERSION (0x20) /*Change this if you change the struct below to prevent people getting \ out of sync*/ @@ -20,47 +19,48 @@ * This struct must be a multiple of 2 bytes as it is saved / restored from * flash in uint16_t chunks */ -typedef struct { - uint8_t version; // Used to track if a reset is needed on firmware upgrade +typedef struct +{ + uint8_t version; // Used to track if a reset is needed on firmware upgrade - uint16_t SolderingTemp; // current set point for the iron - uint16_t SleepTemp; // temp to drop to in sleep - uint8_t SleepTime; // minutes timeout to sleep - uint8_t cutoutSetting; // The voltage we cut out at for under voltage OR Power level for TS80 - uint8_t OrientationMode :2; // If true we want to invert the display for lefties - uint8_t sensitivity :4; // Sensitivity of accelerometer (5 bits) - uint8_t autoStartMode :2; // Should the unit automatically jump straight - // into soldering mode when power is applied - uint8_t ShutdownTime; // Time until unit shuts down if left alone - uint8_t boostModeEnabled :1; // Boost mode swaps BUT_A in soldering mode to - // temporary soldering temp over-ride - uint8_t coolingTempBlink :1; // Should the temperature blink on the cool - // down screen until its <50C - uint8_t detailedIDLE :1; // Detailed idle screen - uint8_t detailedSoldering :1; // Detailed soldering screens + uint16_t SolderingTemp; // current set point for the iron + uint16_t SleepTemp; // temp to drop to in sleep + uint8_t SleepTime; // minutes timeout to sleep + uint8_t cutoutSetting; // The voltage we cut out at for under voltage OR Power level for TS80 + uint8_t OrientationMode : 2; // If true we want to invert the display for lefties + uint8_t sensitivity : 4; // Sensitivity of accelerometer (5 bits) + uint8_t autoStartMode : 2; // Should the unit automatically jump straight + // into soldering mode when power is applied + uint8_t ShutdownTime; // Time until unit shuts down if left alone + uint8_t boostModeEnabled : 1; // Boost mode swaps BUT_A in soldering mode to + // temporary soldering temp over-ride + uint8_t coolingTempBlink : 1; // Should the temperature blink on the cool + // down screen until its <50C + uint8_t detailedIDLE : 1; // Detailed idle screen + uint8_t detailedSoldering : 1; // Detailed soldering screens #ifdef ENABLED_FAHRENHEIT_SUPPORT - uint8_t temperatureInF :1; // Should the temp be in F or C (true is F) + uint8_t temperatureInF : 1; // Should the temp be in F or C (true is F) #endif - uint8_t descriptionScrollSpeed :1; // Description scroll speed - uint8_t KeepAwakePulse; // Keep Awake pulse power in 0.1 watts (10 = 1Watt) + uint8_t descriptionScrollSpeed : 1; // Description scroll speed + uint8_t KeepAwakePulse; // Keep Awake pulse power in 0.1 watts (10 = 1Watt) - uint16_t voltageDiv; // Voltage divisor factor - uint16_t BoostTemp; // Boost mode set point for the iron + uint16_t voltageDiv; // Voltage divisor factor + uint16_t BoostTemp; // Boost mode set point for the iron uint16_t CalibrationOffset; // This stores the temperature offset for this tip // in the iron. uint8_t powerLimitEnable; // Allow toggling of power limit without changing value - uint8_t powerLimit; // Maximum power iron allowed to output + uint8_t powerLimit; // Maximum power iron allowed to output uint16_t TipGain; // uV/C * 10, it can be used to convert tip thermocouple voltage to temperateture TipV/TipGain = TipTemp uint8_t ReverseButtonTempChangeEnabled; // Change the plus and minus button assigment - uint16_t TempChangeLongStep; // Change the plus and minus button assigment - uint16_t TempChangeShortStep; // Change the plus and minus button assigment + uint16_t TempChangeLongStep; // Change the plus and minus button assigment + uint16_t TempChangeShortStep; // Change the plus and minus button assigment - uint32_t padding; // This is here for in case we are not an even divisor so - // that nothing gets cut off - //MUST BE LAST + uint32_t padding; // This is here for in case we are not an even divisor so + // that nothing gets cut off + //MUST BE LAST } systemSettingsType; diff --git a/workspace/TS100/Core/Inc/main.hpp b/workspace/TS100/Core/Inc/main.hpp index edfde783..0024c3a4 100644 --- a/workspace/TS100/Core/Inc/main.hpp +++ b/workspace/TS100/Core/Inc/main.hpp @@ -8,19 +8,20 @@ extern uint32_t currentTempTargetDegC; extern bool settingsWereReset; extern bool usb_pd_available; #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void vApplicationStackOverflowHook(xTaskHandle *pxTask, - signed portCHAR *pcTaskName); + void vApplicationStackOverflowHook(TaskHandle_t *pxTask, + signed portCHAR *pcTaskName); -//Threads -void startGUITask(void const *argument); -void startPIDTask(void const *argument); -void startMOVTask(void const *argument); -extern TaskHandle_t pidTaskNotification; -extern uint8_t accelInit; -extern uint32_t lastMovementTime; + //Threads + void startGUITask(void const *argument); + void startPIDTask(void const *argument); + void startMOVTask(void const *argument); + extern TaskHandle_t pidTaskNotification; + extern uint8_t accelInit; + extern uint32_t lastMovementTime; #ifdef __cplusplus } #endif diff --git a/workspace/TS100/Core/Src/FreeRTOSHooks.c b/workspace/TS100/Core/Src/FreeRTOSHooks.c index f7c56c6a..ee29864f 100644 --- a/workspace/TS100/Core/Src/FreeRTOSHooks.c +++ b/workspace/TS100/Core/Src/FreeRTOSHooks.c @@ -7,7 +7,9 @@ #include "FreeRTOSHooks.h" #include "BSP.h" -void vApplicationIdleHook(void) { +#include "cmsis_os.h" +void vApplicationIdleHook(void) +{ resetWatchdog(); } @@ -16,19 +18,19 @@ static StaticTask_t xIdleTaskTCBBuffer; static StackType_t xIdleStack[configMINIMAL_STACK_SIZE]; void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, - StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) { + StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) +{ *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; *ppxIdleTaskStackBuffer = &xIdleStack[0]; *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; /* place for user code */ } - -void vApplicationStackOverflowHook(xTaskHandle *pxTask, - signed portCHAR *pcTaskName) { - (void) pxTask; - (void) pcTaskName; - asm("bkpt"); -// We dont have a good way to handle a stack overflow at this point in time +void vApplicationStackOverflowHook(TaskHandle_t *pxTask, + signed portCHAR *pcTaskName) +{ + (void)pxTask; + (void)pcTaskName; + // We dont have a good way to handle a stack overflow at this point in time reboot(); } diff --git a/workspace/TS100/Core/Threads/PIDThread.cpp b/workspace/TS100/Core/Threads/PIDThread.cpp index b0e523dc..95ffedd1 100644 --- a/workspace/TS100/Core/Threads/PIDThread.cpp +++ b/workspace/TS100/Core/Threads/PIDThread.cpp @@ -20,7 +20,8 @@ TaskHandle_t pidTaskNotification = NULL; uint32_t currentTempTargetDegC = 0; // Current temperature target in C /* StartPIDTask function */ -void startPIDTask(void const *argument __unused) { +void startPIDTask(void const *argument __unused) +{ /* * We take the current tip temperature & evaluate the next step for the tip * control PWM. @@ -29,27 +30,32 @@ void startPIDTask(void const *argument __unused) { TickType_t lastPowerPulseStart = 0; TickType_t lastPowerPulseEnd = 0; - history tempError = { { 0 }, 0, 0 }; + history tempError = {{0}, 0, 0}; currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will // be over-ridden rapidly pidTaskNotification = xTaskGetCurrentTaskHandle(); uint32_t PIDTempTarget = 0; - for (;;) { + for (;;) + { - if (ulTaskNotifyTake(pdTRUE, 2000)) { + if (ulTaskNotifyTake(pdTRUE, 2000)) + { // This is a call to block this thread until the ADC does its samples int32_t x10WattsOut = 0; // Do the reading here to keep the temp calculations churning along uint32_t currentTipTempInC = TipThermoModel::getTipInC(true); PIDTempTarget = currentTempTargetDegC; - if (PIDTempTarget) { + if (PIDTempTarget) + { // Cap the max set point to 450C - if (PIDTempTarget > (450)) { + if (PIDTempTarget > (450)) + { //Maximum allowed output PIDTempTarget = (450); } //Safety check that not aiming higher than current tip can measure - if (PIDTempTarget > TipThermoModel::getTipMaxInC()) { + if (PIDTempTarget > TipThermoModel::getTipMaxInC()) + { PIDTempTarget = TipThermoModel::getTipMaxInC(); } // Convert the current tip to degree's C @@ -73,7 +79,7 @@ void startPIDTask(void const *argument __unused) { // Once we have feed-forward temp estimation we should be able to better tune this. int32_t x10WattsNeeded = tempToX10Watts(tError); -// tempError.average()); + // tempError.average()); // note that milliWattsNeeded is sometimes negative, this counters overshoot // from I term's inertia. x10WattsOut += x10WattsNeeded; @@ -89,38 +95,41 @@ void startPIDTask(void const *argument __unused) { // and counters extra power if the iron is no longer losing temp. // basically: temp - lastTemp // Unfortunately, our temp signal is too noisy to really help. - } //If the user turns on the option of using an occasional pulse to keep the power bank on - if (systemSettings.KeepAwakePulse) { + if (systemSettings.KeepAwakePulse) + { - if (xTaskGetTickCount() - lastPowerPulseStart - > powerPulseRate) { + if (xTaskGetTickCount() - lastPowerPulseStart > powerPulseRate) + { lastPowerPulseStart = xTaskGetTickCount(); - lastPowerPulseEnd = lastPowerPulseStart - + powerPulseDuration; + lastPowerPulseEnd = lastPowerPulseStart + powerPulseDuration; } //If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor - if (x10WattsOut < systemSettings.KeepAwakePulse - && xTaskGetTickCount() < lastPowerPulseEnd) { + if (x10WattsOut < systemSettings.KeepAwakePulse && xTaskGetTickCount() < lastPowerPulseEnd) + { x10WattsOut = systemSettings.KeepAwakePulse; } } //Secondary safety check to forcefully disable header when within ADC noise of top of ADC - if (getTipRawTemp(0) > (0x7FFF - 150)) { + if (getTipRawTemp(0) > (0x7FFF - 150)) + { x10WattsOut = 0; } - if (systemSettings.powerLimitEnable - && x10WattsOut > (systemSettings.powerLimit * 10)) { + if (systemSettings.powerLimitEnable && x10WattsOut > (systemSettings.powerLimit * 10)) + { setTipX10Watts(systemSettings.powerLimit * 10); - } else { + } + else + { setTipX10Watts(x10WattsOut); } - - HAL_IWDG_Refresh(&hiwdg); - } else { + resetWatchdog(); + } + else + { //ADC interrupt timeout setTipPWM(0); } diff --git a/workspace/TS100/Core/BSP/Pine64/Vendor/Lib/GD32VF103xB.lds b/workspace/TS100/GD32VF103xB.ld similarity index 100% rename from workspace/TS100/Core/BSP/Pine64/Vendor/Lib/GD32VF103xB.lds rename to workspace/TS100/GD32VF103xB.ld diff --git a/workspace/TS100/Makefile b/workspace/TS100/Makefile index 94c29c24..75dfc3a0 100644 --- a/workspace/TS100/Makefile +++ b/workspace/TS100/Makefile @@ -27,6 +27,7 @@ MINIWARE_INC_DIR = ./Core/BSP/Miniware PINE_INC_DIR = ./Core/BSP/Pine64 PINE_VENDOR_INC_DIR = ./Core/BSP/Pine64/Vendor/Lib PINE_RISCV_INC_DIR = ./Core/BSP/Pine64/Vendor/RISCV +PINE_N200_INC_DIR = ./Core/BSP/Pine64/N200 SOURCE_THREADS_DIR = ./Core/Threads SOURCE_CORE_DIR = ./Core/Src SOURCE_DRIVERS_DIR = ./Core/Drivers @@ -45,6 +46,9 @@ DEVICE_INCLUDES = -I$(MINIWARE_INC_DIR) \ DEVICE_BSP_DIR = ./Core/BSP/Miniware S_SRCS := ./Startup/startup_stm32f103t8ux.S LDSCRIPT=stm32f103.ld +DEV_GLOBAL_DEFS= -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D GCC_ARMCM3 \ + -D ARM_MATH_CM3 \ + -D STM32F10X_MD DEV_LDFLAGS= DEV_AFLAGS= DEV_CFLAGS= @@ -55,12 +59,14 @@ ifeq ($(model),Pinecil) DEVICE_INCLUDES = -I$(PINE_INC_DIR) \ -I$(PINE_INC_DIR)/N200 \ -I$(PINE_VENDOR_INC_DIR) \ - -I$(PINE_RISCV_INC_DIR) + -I$(PINE_RISCV_INC_DIR) \ + -I$(PINE_N200_INC_DIR)\ + -I$(INC_PD_DRIVERS_DIR) DEVICE_BSP_DIR = ./Core/BSP/Pine64 -S_SRCS := $(shell find $(PINE_INC_DIR) -type f -name '*.s') +S_SRCS := $(shell find $(PINE_INC_DIR) -type f -name '*.S') ASM_INC = -I$(PINE_RISCV_INC_DIR) -LDSCRIPT=GD32VF103x8.ld +LDSCRIPT=GD32VF103xB.ld DEV_LDFLAGS=-nostartfiles DEV_AFLAGS = -msmall-data-limit=8 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections DEV_CFLAGS= -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" @@ -97,9 +103,7 @@ OPTIM=-Os -flto -ffat-lto-objects -finline-small-functions -findirect-inlining - # global defines --------------------------------------------------------------- -GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model) -D GCC_ARMCM3 \ - -D ARM_MATH_CM3 \ - -D STM32F10X_MD \ +GLOBAL_DEFINES += -D LANG_$(lang) -D LANG -D MODEL_$(model) $(DEV_GLOBAL_DEFS) # Enable debug code generation DEBUG=-g3 @@ -277,6 +281,7 @@ $(OUT_HEXFILE).elf : $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) Makefile $(LDSCR $(OUT_OBJS): $(OUTPUT_DIR)/%.o : %.c Makefile @test -d $(@D) || mkdir -p $(@D) @echo Compiling ${<} + @echo @$(CC) -c $(CFLAGS) $< -o $@ @$(CC) -c $(CFLAGS) $< -o $@ @$(OBJDUMP) -d -S $@ > $@.lst diff --git a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c b/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c index 7ff30e9d..01593c8b 100644 --- a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c +++ b/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c @@ -26,7 +26,7 @@ * *---------------------------------------------------------------------------- * - * Portions Copyright 2016 STMicroelectronics International N.V. All rights reserved. + * Portions Copyright � 2016 STMicroelectronics International N.V. All rights reserved. * Portions Copyright (c) 2013 ARM LIMITED * All rights reserved. * Redistribution and use in source and binary forms, with or without @@ -53,7 +53,7 @@ * POSSIBILITY OF SUCH DAMAGE. *---------------------------------------------------------------------------*/ - /** +/** ****************************************************************************** * @file cmsis_os.c * @author MCD Application Team @@ -94,7 +94,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** - */ + */ #include #include "cmsis_os.h" @@ -102,75 +102,74 @@ /* * ARM Compiler 4/5 */ -#if defined ( __CC_ARM ) +#if defined(__CC_ARM) - #define __ASM __asm - #define __INLINE __inline - #define __STATIC_INLINE static __inline - #include "cmsis_armcc.h" +#define __ASM __asm +#define __INLINE __inline +#define __STATIC_INLINE static __inline +#include "cmsis_armcc.h" /* * GNU Compiler */ -#elif defined ( __GNUC__ ) +#elif defined(__GNUC__) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - - - #include "cmsis_gcc.h" +#define __ASM __asm /*!< asm keyword for GNU Compiler */ +#define __INLINE inline /*!< inline keyword for GNU Compiler */ +#define __STATIC_INLINE static inline +// #include "cmsis_gcc.h" /* * IAR Compiler */ -#elif defined ( __ICCARM__ ) +#elif defined(__ICCARM__) - #ifndef __ASM - #define __ASM __asm - #endif - #ifndef __INLINE - #define __INLINE inline - #endif - #ifndef __STATIC_INLINE - #define __STATIC_INLINE static inline - #endif +#ifndef __ASM +#define __ASM __asm +#endif +#ifndef __INLINE +#define __INLINE inline +#endif +#ifndef __STATIC_INLINE +#define __STATIC_INLINE static inline +#endif - #include +#include #endif extern void xPortSysTickHandler(void); /* Convert from CMSIS type osPriority to FreeRTOS priority number */ -static unsigned portBASE_TYPE makeFreeRtosPriority (osPriority priority) +static unsigned portBASE_TYPE makeFreeRtosPriority(osPriority priority) { unsigned portBASE_TYPE fpriority = tskIDLE_PRIORITY; - - if (priority != osPriorityError) { + + if (priority != osPriorityError) + { fpriority += (priority - osPriorityIdle); } - + return fpriority; } #if (INCLUDE_uxTaskPriorityGet == 1) /* Convert from FreeRTOS priority number to CMSIS type osPriority */ -static osPriority makeCmsisPriority (unsigned portBASE_TYPE fpriority) +static osPriority makeCmsisPriority(unsigned portBASE_TYPE fpriority) { osPriority priority = osPriorityError; - - if ((fpriority - tskIDLE_PRIORITY) <= (osPriorityRealtime - osPriorityIdle)) { + + if ((fpriority - tskIDLE_PRIORITY) <= (osPriorityRealtime - osPriorityIdle)) + { priority = (osPriority)((int)osPriorityIdle + (int)(fpriority - tskIDLE_PRIORITY)); } - + return priority; } #endif - /* Determine whether we are in thread mode or handler mode. */ -static int inHandlerMode (void) +static int inHandlerMode(void) { return __get_IPSR() != 0; } @@ -181,7 +180,7 @@ static int inHandlerMode (void) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS. */ -osStatus osKernelInitialize (void); +osStatus osKernelInitialize(void); /** * @brief Start the RTOS Kernel with executing the specified thread. @@ -190,10 +189,10 @@ osStatus osKernelInitialize (void); * @retval status code that indicates the execution status of the function * @note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. */ -osStatus osKernelStart (void) +osStatus osKernelStart(void) { vTaskStartScheduler(); - + return osOK; } @@ -207,17 +206,17 @@ osStatus osKernelStart (void) */ int32_t osKernelRunning(void) { -#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) +#if ((INCLUDE_xTaskGetSchedulerState == 1) || (configUSE_TIMERS == 1)) if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) return 0; else return 1; #else - return (-1); -#endif + return (-1); +#endif } -#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available +#if (defined(osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available /** * @brief Get the value of the Kernel SysTick timer * @param None @@ -226,14 +225,16 @@ int32_t osKernelRunning(void) */ uint32_t osKernelSysTick(void) { - if (inHandlerMode()) { + if (inHandlerMode()) + { return xTaskGetTickCountFromISR(); } - else { + else + { return xTaskGetTickCount(); } } -#endif // System Timer available +#endif // System Timer available /*********************** Thread Management *****************************/ /** * @brief Create a thread and add it to Active Threads and set it to state READY. @@ -242,36 +243,40 @@ uint32_t osKernelSysTick(void) * @retval thread ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS. */ -osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) +osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *argument) { TaskHandle_t handle; - -#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) - if((thread_def->buffer != NULL) && (thread_def->controlblock != NULL)) { - handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, - thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), - thread_def->buffer, thread_def->controlblock); - } - else { - if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, - thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), - &handle) != pdPASS) { - return NULL; - } - } -#elif( configSUPPORT_STATIC_ALLOCATION == 1 ) - handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, - thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), - thread_def->buffer, thread_def->controlblock); +#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1) + if ((thread_def->buffer != NULL) && (thread_def->controlblock != NULL)) + { + handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + thread_def->buffer, thread_def->controlblock); + } + else + { + if (xTaskCreate((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + &handle) != pdPASS) + { + return NULL; + } + } +#elif (configSUPPORT_STATIC_ALLOCATION == 1) + + handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + thread_def->buffer, thread_def->controlblock); #else - if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, - thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), - &handle) != pdPASS) { + if (xTaskCreate((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + &handle) != pdPASS) + { return NULL; - } + } #endif - + return handle; } @@ -280,12 +285,12 @@ osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) * @retval thread ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS. */ -osThreadId osThreadGetId (void) +osThreadId osThreadGetId(void) { -#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) +#if ((INCLUDE_xTaskGetCurrentTaskHandle == 1) || (configUSE_MUTEXES == 1)) return xTaskGetCurrentTaskHandle(); #else - return NULL; + return NULL; #endif } @@ -295,7 +300,7 @@ osThreadId osThreadGetId (void) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS. */ -osStatus osThreadTerminate (osThreadId thread_id) +osStatus osThreadTerminate(osThreadId thread_id) { #if (INCLUDE_vTaskDelete == 1) vTaskDelete(thread_id); @@ -310,10 +315,10 @@ osStatus osThreadTerminate (osThreadId thread_id) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS. */ -osStatus osThreadYield (void) +osStatus osThreadYield(void) { taskYIELD(); - + return osOK; } @@ -324,7 +329,7 @@ osStatus osThreadYield (void) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS. */ -osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority) +osStatus osThreadSetPriority(osThreadId thread_id, osPriority priority) { #if (INCLUDE_vTaskPrioritySet == 1) vTaskPrioritySet(thread_id, makeFreeRtosPriority(priority)); @@ -340,15 +345,15 @@ osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority) * @retval current priority value of the thread function. * @note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS. */ -osPriority osThreadGetPriority (osThreadId thread_id) +osPriority osThreadGetPriority(osThreadId thread_id) { #if (INCLUDE_uxTaskPriorityGet == 1) if (inHandlerMode()) { - return makeCmsisPriority(uxTaskPriorityGetFromISR(thread_id)); + return makeCmsisPriority(uxTaskPriorityGetFromISR(thread_id)); } else - { + { return makeCmsisPriority(uxTaskPriorityGet(thread_id)); } #else @@ -362,31 +367,31 @@ osPriority osThreadGetPriority (osThreadId thread_id) * @param millisec time delay value * @retval status code that indicates the execution status of the function. */ -osStatus osDelay (uint32_t millisec) +osStatus osDelay(uint32_t millisec) { #if INCLUDE_vTaskDelay TickType_t ticks = millisec / portTICK_PERIOD_MS; - - vTaskDelay(ticks ? ticks : 1); /* Minimum delay = 1 tick */ - + + vTaskDelay(ticks ? ticks : 1); /* Minimum delay = 1 tick */ + return osOK; #else - (void) millisec; - + (void)millisec; + return osErrorResource; #endif } -#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) /* Generic Wait available */ +#if (defined(osFeature_Wait) && (osFeature_Wait != 0)) /* Generic Wait available */ /** * @brief Wait for Signal, Message, Mail, or Timeout * @param millisec timeout value or 0 in case of no time-out * @retval event that contains signal, message, or mail information or error code. * @note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS. */ -osEvent osWait (uint32_t millisec); +osEvent osWait(uint32_t millisec); -#endif /* Generic Wait available */ +#endif /* Generic Wait available */ /*********************** Timer Management Functions ***************************/ /** @@ -397,43 +402,45 @@ osEvent osWait (uint32_t millisec); * @retval timer ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS. */ -osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) +osTimerId osTimerCreate(const osTimerDef_t *timer_def, os_timer_type type, void *argument) { #if (configUSE_TIMERS == 1) -#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) - if(timer_def->controlblock != NULL) { +#if ((configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)) + if (timer_def->controlblock != NULL) + { return xTimerCreateStatic((const char *)"", - 1, // period should be filled when starting the Timer using osTimerStart - (type == osTimerPeriodic) ? pdTRUE : pdFALSE, - (void *) argument, - (TaskFunction_t)timer_def->ptimer, - (StaticTimer_t *)timer_def->controlblock); + 1, // period should be filled when starting the Timer using osTimerStart + (type == osTimerPeriodic) ? pdTRUE : pdFALSE, + (void *)argument, + (TaskFunction_t)timer_def->ptimer, + (StaticTimer_t *)timer_def->controlblock); } - else { + else + { return xTimerCreate((const char *)"", - 1, // period should be filled when starting the Timer using osTimerStart - (type == osTimerPeriodic) ? pdTRUE : pdFALSE, - (void *) argument, - (TaskFunction_t)timer_def->ptimer); - } -#elif( configSUPPORT_STATIC_ALLOCATION == 1 ) + 1, // period should be filled when starting the Timer using osTimerStart + (type == osTimerPeriodic) ? pdTRUE : pdFALSE, + (void *)argument, + (TaskFunction_t)timer_def->ptimer); + } +#elif (configSUPPORT_STATIC_ALLOCATION == 1) return xTimerCreateStatic((const char *)"", - 1, // period should be filled when starting the Timer using osTimerStart - (type == osTimerPeriodic) ? pdTRUE : pdFALSE, - (void *) argument, - (TaskFunction_t)timer_def->ptimer, - (StaticTimer_t *)timer_def->controlblock); + 1, // period should be filled when starting the Timer using osTimerStart + (type == osTimerPeriodic) ? pdTRUE : pdFALSE, + (void *)argument, + (TaskFunction_t)timer_def->ptimer, + (StaticTimer_t *)timer_def->controlblock); #else return xTimerCreate((const char *)"", 1, // period should be filled when starting the Timer using osTimerStart (type == osTimerPeriodic) ? pdTRUE : pdFALSE, - (void *) argument, + (void *)argument, (TaskFunction_t)timer_def->ptimer); #endif -#else - return NULL; +#else + return NULL; #endif } @@ -444,17 +451,17 @@ osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void * @retval status code that indicates the execution status of the function * @note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. */ -osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) +osStatus osTimerStart(osTimerId timer_id, uint32_t millisec) { osStatus result = osOK; -#if (configUSE_TIMERS == 1) +#if (configUSE_TIMERS == 1) portBASE_TYPE taskWoken = pdFALSE; TickType_t ticks = millisec / portTICK_PERIOD_MS; if (ticks == 0) ticks = 1; - - if (inHandlerMode()) + + if (inHandlerMode()) { if (xTimerChangePeriodFromISR(timer_id, ticks, &taskWoken) != pdPASS) { @@ -462,16 +469,16 @@ osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) } else { - portEND_SWITCHING_ISR(taskWoken); + portEND_SWITCHING_ISR(taskWoken); } } - else + else { if (xTimerChangePeriod(timer_id, ticks, 0) != pdPASS) result = osErrorOS; } -#else +#else result = osErrorOS; #endif return result; @@ -483,26 +490,30 @@ osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS. */ -osStatus osTimerStop (osTimerId timer_id) +osStatus osTimerStop(osTimerId timer_id) { osStatus result = osOK; -#if (configUSE_TIMERS == 1) +#if (configUSE_TIMERS == 1) portBASE_TYPE taskWoken = pdFALSE; - if (inHandlerMode()) { - if (xTimerStopFromISR(timer_id, &taskWoken) != pdPASS) { + if (inHandlerMode()) + { + if (xTimerStopFromISR(timer_id, &taskWoken) != pdPASS) + { return osErrorOS; } portEND_SWITCHING_ISR(taskWoken); } - else { - if (xTimerStop(timer_id, 0) != pdPASS) { + else + { + if (xTimerStop(timer_id, 0) != pdPASS) + { result = osErrorOS; } } -#else +#else result = osErrorOS; -#endif +#endif return result; } @@ -512,25 +523,28 @@ osStatus osTimerStop (osTimerId timer_id) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS. */ -osStatus osTimerDelete (osTimerId timer_id) +osStatus osTimerDelete(osTimerId timer_id) { -osStatus result = osOK; + osStatus result = osOK; #if (configUSE_TIMERS == 1) - if (inHandlerMode()) { - return osErrorISR; + if (inHandlerMode()) + { + return osErrorISR; } - else { - if ((xTimerDelete(timer_id, osWaitForever )) != pdPASS) { + else + { + if ((xTimerDelete(timer_id, osWaitForever)) != pdPASS) + { result = osErrorOS; } - } - -#else + } + +#else result = osErrorOS; -#endif - +#endif + return result; } @@ -542,28 +556,28 @@ osStatus result = osOK; * @retval previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. * @note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS. */ -int32_t osSignalSet (osThreadId thread_id, int32_t signal) +int32_t osSignalSet(osThreadId thread_id, int32_t signal) { -#if( configUSE_TASK_NOTIFICATIONS == 1 ) +#if (configUSE_TASK_NOTIFICATIONS == 1) BaseType_t xHigherPriorityTaskWoken = pdFALSE; uint32_t ulPreviousNotificationValue = 0; - + if (inHandlerMode()) { - if(xTaskGenericNotifyFromISR( thread_id , (uint32_t)signal, eSetBits, &ulPreviousNotificationValue, &xHigherPriorityTaskWoken ) != pdPASS ) + if (xTaskGenericNotifyFromISR(thread_id, (uint32_t)signal, eSetBits, &ulPreviousNotificationValue, &xHigherPriorityTaskWoken) != pdPASS) return 0x80000000; - - portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); - } - else if(xTaskGenericNotify( thread_id , (uint32_t)signal, eSetBits, &ulPreviousNotificationValue) != pdPASS ) + + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } + else if (xTaskGenericNotify(thread_id, (uint32_t)signal, eSetBits, &ulPreviousNotificationValue) != pdPASS) return 0x80000000; - + return ulPreviousNotificationValue; #else - (void) thread_id; - (void) signal; + (void)thread_id; + (void)signal; - return 0x80000000; /* Task Notification not supported */ + return 0x80000000; /* Task Notification not supported */ #endif } @@ -574,7 +588,7 @@ int32_t osSignalSet (osThreadId thread_id, int32_t signal) * @retval previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. * @note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS. */ -int32_t osSignalClear (osThreadId thread_id, int32_t signal); +int32_t osSignalClear(osThreadId thread_id, int32_t signal); /** * @brief Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. @@ -583,50 +597,56 @@ int32_t osSignalClear (osThreadId thread_id, int32_t signal); * @retval event flag information or error code. * @note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS. */ -osEvent osSignalWait (int32_t signals, uint32_t millisec) +osEvent osSignalWait(int32_t signals, uint32_t millisec) { osEvent ret; -#if( configUSE_TASK_NOTIFICATIONS == 1 ) - +#if (configUSE_TASK_NOTIFICATIONS == 1) + TickType_t ticks; - ret.value.signals = 0; + ret.value.signals = 0; ticks = 0; - if (millisec == osWaitForever) { + if (millisec == osWaitForever) + { ticks = portMAX_DELAY; } - else if (millisec != 0) { + else if (millisec != 0) + { ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) { + if (ticks == 0) + { ticks = 1; } - } - + } + if (inHandlerMode()) { - ret.status = osErrorISR; /*Not allowed in ISR*/ + ret.status = osErrorISR; /*Not allowed in ISR*/ } else { - if(xTaskNotifyWait( 0,(uint32_t) signals, (uint32_t *)&ret.value.signals, ticks) != pdTRUE) + if (xTaskNotifyWait(0, (uint32_t)signals, (uint32_t *)&ret.value.signals, ticks) != pdTRUE) { - if(ticks == 0) ret.status = osOK; - else ret.status = osEventTimeout; + if (ticks == 0) + ret.status = osOK; + else + ret.status = osEventTimeout; } - else if(ret.value.signals < 0) + else if (ret.value.signals < 0) { - ret.status = osErrorValue; + ret.status = osErrorValue; } - else ret.status = osEventSignal; + else + ret.status = osEventSignal; } #else - (void) signals; - (void) millisec; - - ret.status = osErrorOS; /* Task Notification not supported */ + (void)signals; + (void)millisec; + + ret.status = osErrorOS; /* Task Notification not supported */ #endif - + return ret; } @@ -637,22 +657,24 @@ osEvent osSignalWait (int32_t signals, uint32_t millisec) * @retval mutex ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. */ -osMutexId osMutexCreate (const osMutexDef_t *mutex_def) +osMutexId osMutexCreate(const osMutexDef_t *mutex_def) { -#if ( configUSE_MUTEXES == 1) +#if (configUSE_MUTEXES == 1) -#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) +#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1) - if (mutex_def->controlblock != NULL) { - return xSemaphoreCreateMutexStatic( mutex_def->controlblock ); - } - else { - return xSemaphoreCreateMutex(); + if (mutex_def->controlblock != NULL) + { + return xSemaphoreCreateMutexStatic(mutex_def->controlblock); } -#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) - return xSemaphoreCreateMutexStatic( mutex_def->controlblock ); -#else - return xSemaphoreCreateMutex(); + else + { + return xSemaphoreCreateMutex(); + } +#elif (configSUPPORT_STATIC_ALLOCATION == 1) + return xSemaphoreCreateMutexStatic(mutex_def->controlblock); +#else + return xSemaphoreCreateMutex(); #endif #else return NULL; @@ -666,37 +688,43 @@ osMutexId osMutexCreate (const osMutexDef_t *mutex_def) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS. */ -osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec) +osStatus osMutexWait(osMutexId mutex_id, uint32_t millisec) { TickType_t ticks; - portBASE_TYPE taskWoken = pdFALSE; - - - if (mutex_id == NULL) { + portBASE_TYPE taskWoken = pdFALSE; + + if (mutex_id == NULL) + { return osErrorParameter; } - + ticks = 0; - if (millisec == osWaitForever) { + if (millisec == osWaitForever) + { ticks = portMAX_DELAY; } - else if (millisec != 0) { + else if (millisec != 0) + { ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) { + if (ticks == 0) + { ticks = 1; } } - - if (inHandlerMode()) { - if (xSemaphoreTakeFromISR(mutex_id, &taskWoken) != pdTRUE) { + + if (inHandlerMode()) + { + if (xSemaphoreTakeFromISR(mutex_id, &taskWoken) != pdTRUE) + { return osErrorOS; } - portEND_SWITCHING_ISR(taskWoken); - } - else if (xSemaphoreTake(mutex_id, ticks) != pdTRUE) { + portEND_SWITCHING_ISR(taskWoken); + } + else if (xSemaphoreTake(mutex_id, ticks) != pdTRUE) + { return osErrorOS; } - + return osOK; } @@ -706,18 +734,20 @@ osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS. */ -osStatus osMutexRelease (osMutexId mutex_id) +osStatus osMutexRelease(osMutexId mutex_id) { osStatus result = osOK; portBASE_TYPE taskWoken = pdFALSE; - - if (inHandlerMode()) { - if (xSemaphoreGiveFromISR(mutex_id, &taskWoken) != pdTRUE) { + + if (inHandlerMode()) + { + if (xSemaphoreGiveFromISR(mutex_id, &taskWoken) != pdTRUE) + { return osErrorOS; } portEND_SWITCHING_ISR(taskWoken); } - else if (xSemaphoreGive(mutex_id) != pdTRUE) + else if (xSemaphoreGive(mutex_id) != pdTRUE) { result = osErrorOS; } @@ -730,9 +760,10 @@ osStatus osMutexRelease (osMutexId mutex_id) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS. */ -osStatus osMutexDelete (osMutexId mutex_id) +osStatus osMutexDelete(osMutexId mutex_id) { - if (inHandlerMode()) { + if (inHandlerMode()) + { return osErrorISR; } @@ -743,7 +774,7 @@ osStatus osMutexDelete (osMutexId mutex_id) /******************** Semaphore Management Functions **************************/ -#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) +#if (defined(osFeature_Semaphore) && (osFeature_Semaphore != 0)) /** * @brief Create and Initialize a Semaphore object used for managing resources @@ -752,58 +783,67 @@ osStatus osMutexDelete (osMutexId mutex_id) * @retval semaphore ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS. */ -osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count) -{ -#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) +osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, int32_t count) +{ +#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1) osSemaphoreId sema; - - if (semaphore_def->controlblock != NULL){ - if (count == 1) { - return xSemaphoreCreateBinaryStatic( semaphore_def->controlblock ); + + if (semaphore_def->controlblock != NULL) + { + if (count == 1) + { + return xSemaphoreCreateBinaryStatic(semaphore_def->controlblock); } - else { -#if (configUSE_COUNTING_SEMAPHORES == 1 ) - return xSemaphoreCreateCountingStatic( count, count, semaphore_def->controlblock ); + else + { +#if (configUSE_COUNTING_SEMAPHORES == 1) + return xSemaphoreCreateCountingStatic(count, count, semaphore_def->controlblock); #else return NULL; #endif } } - else { - if (count == 1) { + else + { + if (count == 1) + { vSemaphoreCreateBinary(sema); return sema; } - else { -#if (configUSE_COUNTING_SEMAPHORES == 1 ) + else + { +#if (configUSE_COUNTING_SEMAPHORES == 1) return xSemaphoreCreateCounting(count, count); #else return NULL; -#endif +#endif } } -#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) // configSUPPORT_DYNAMIC_ALLOCATION == 0 - if(count == 1) { - return xSemaphoreCreateBinaryStatic( semaphore_def->controlblock ); +#elif (configSUPPORT_STATIC_ALLOCATION == 1) // configSUPPORT_DYNAMIC_ALLOCATION == 0 + if (count == 1) + { + return xSemaphoreCreateBinaryStatic(semaphore_def->controlblock); } else { -#if (configUSE_COUNTING_SEMAPHORES == 1 ) - return xSemaphoreCreateCountingStatic( count, count, semaphore_def->controlblock ); +#if (configUSE_COUNTING_SEMAPHORES == 1) + return xSemaphoreCreateCountingStatic(count, count, semaphore_def->controlblock); #else - return NULL; -#endif + return NULL; +#endif } -#else // configSUPPORT_STATIC_ALLOCATION == 0 && configSUPPORT_DYNAMIC_ALLOCATION == 1 +#else // configSUPPORT_STATIC_ALLOCATION == 0 && configSUPPORT_DYNAMIC_ALLOCATION == 1 osSemaphoreId sema; - - if (count == 1) { + + if (count == 1) + { vSemaphoreCreateBinary(sema); return sema; } - else { -#if (configUSE_COUNTING_SEMAPHORES == 1 ) + else + { +#if (configUSE_COUNTING_SEMAPHORES == 1) return xSemaphoreCreateCounting(count, count); #else return NULL; @@ -819,37 +859,43 @@ osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t * @retval number of available tokens, or -1 in case of incorrect parameters. * @note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS. */ -int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec) +int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec) { TickType_t ticks; - portBASE_TYPE taskWoken = pdFALSE; - - - if (semaphore_id == NULL) { + portBASE_TYPE taskWoken = pdFALSE; + + if (semaphore_id == NULL) + { return osErrorParameter; } - + ticks = 0; - if (millisec == osWaitForever) { + if (millisec == osWaitForever) + { ticks = portMAX_DELAY; } - else if (millisec != 0) { + else if (millisec != 0) + { ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) { + if (ticks == 0) + { ticks = 1; } } - - if (inHandlerMode()) { - if (xSemaphoreTakeFromISR(semaphore_id, &taskWoken) != pdTRUE) { + + if (inHandlerMode()) + { + if (xSemaphoreTakeFromISR(semaphore_id, &taskWoken) != pdTRUE) + { return osErrorOS; } - portEND_SWITCHING_ISR(taskWoken); - } - else if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE) { + portEND_SWITCHING_ISR(taskWoken); + } + else if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE) + { return osErrorOS; } - + return osOK; } @@ -859,24 +905,27 @@ int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS. */ -osStatus osSemaphoreRelease (osSemaphoreId semaphore_id) +osStatus osSemaphoreRelease(osSemaphoreId semaphore_id) { osStatus result = osOK; portBASE_TYPE taskWoken = pdFALSE; - - - if (inHandlerMode()) { - if (xSemaphoreGiveFromISR(semaphore_id, &taskWoken) != pdTRUE) { + + if (inHandlerMode()) + { + if (xSemaphoreGiveFromISR(semaphore_id, &taskWoken) != pdTRUE) + { return osErrorOS; } portEND_SWITCHING_ISR(taskWoken); } - else { - if (xSemaphoreGive(semaphore_id) != pdTRUE) { + else + { + if (xSemaphoreGive(semaphore_id) != pdTRUE) + { result = osErrorOS; } } - + return result; } @@ -886,29 +935,30 @@ osStatus osSemaphoreRelease (osSemaphoreId semaphore_id) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS. */ -osStatus osSemaphoreDelete (osSemaphoreId semaphore_id) +osStatus osSemaphoreDelete(osSemaphoreId semaphore_id) { - if (inHandlerMode()) { + if (inHandlerMode()) + { return osErrorISR; } vSemaphoreDelete(semaphore_id); - return osOK; + return osOK; } -#endif /* Use Semaphores */ +#endif /* Use Semaphores */ /******************* Memory Pool Management Functions ***********************/ -#if (defined (osFeature_Pool) && (osFeature_Pool != 0)) +#if (defined(osFeature_Pool) && (osFeature_Pool != 0)) //TODO //This is a primitive and inefficient wrapper around the existing FreeRTOS memory management. //A better implementation will have to modify heap_x.c! - -typedef struct os_pool_cb { +typedef struct os_pool_cb +{ void *pool; uint8_t *markers; uint32_t pool_sz; @@ -916,55 +966,59 @@ typedef struct os_pool_cb { uint32_t currentIndex; } os_pool_cb_t; - /** * @brief Create and Initialize a memory pool * @param pool_def memory pool definition referenced with \ref osPool. * @retval memory pool ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS. */ -osPoolId osPoolCreate (const osPoolDef_t *pool_def) +osPoolId osPoolCreate(const osPoolDef_t *pool_def) { #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) osPoolId thePool; int itemSize = 4 * ((pool_def->item_sz + 3) / 4); uint32_t i; - - /* First have to allocate memory for the pool control block. */ - thePool = pvPortMalloc(sizeof(os_pool_cb_t)); - - if (thePool) { + /* First have to allocate memory for the pool control block. */ + thePool = pvPortMalloc(sizeof(os_pool_cb_t)); + + if (thePool) + { thePool->pool_sz = pool_def->pool_sz; thePool->item_sz = itemSize; thePool->currentIndex = 0; - + /* Memory for markers */ thePool->markers = pvPortMalloc(pool_def->pool_sz); - - if (thePool->markers) { + + if (thePool->markers) + { /* Now allocate the pool itself. */ - thePool->pool = pvPortMalloc(pool_def->pool_sz * itemSize); - - if (thePool->pool) { - for (i = 0; i < pool_def->pool_sz; i++) { + thePool->pool = pvPortMalloc(pool_def->pool_sz * itemSize); + + if (thePool->pool) + { + for (i = 0; i < pool_def->pool_sz; i++) + { thePool->markers[i] = 0; } } - else { + else + { vPortFree(thePool->markers); vPortFree(thePool); thePool = NULL; } } - else { + else + { vPortFree(thePool); thePool = NULL; } } return thePool; - + #else return NULL; #endif @@ -976,41 +1030,48 @@ osPoolId osPoolCreate (const osPoolDef_t *pool_def) * @retval address of the allocated memory block or NULL in case of no memory available. * @note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS. */ -void *osPoolAlloc (osPoolId pool_id) +void *osPoolAlloc(osPoolId pool_id) { int dummy = 0; void *p = NULL; uint32_t i; uint32_t index; - - if (inHandlerMode()) { + + if (inHandlerMode()) + { dummy = portSET_INTERRUPT_MASK_FROM_ISR(); } - else { + else + { vPortEnterCritical(); } - - for (i = 0; i < pool_id->pool_sz; i++) { + + for (i = 0; i < pool_id->pool_sz; i++) + { index = pool_id->currentIndex + i; - if (index >= pool_id->pool_sz) { + if (index >= pool_id->pool_sz) + { index = 0; } - - if (pool_id->markers[index] == 0) { + + if (pool_id->markers[index] == 0) + { pool_id->markers[index] = 1; p = (void *)((uint32_t)(pool_id->pool) + (index * pool_id->item_sz)); pool_id->currentIndex = index; break; } } - - if (inHandlerMode()) { + + if (inHandlerMode()) + { portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy); } - else { + else + { vPortExitCritical(); } - + return p; } @@ -1020,15 +1081,15 @@ void *osPoolAlloc (osPoolId pool_id) * @retval address of the allocated memory block or NULL in case of no memory available. * @note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS. */ -void *osPoolCAlloc (osPoolId pool_id) +void *osPoolCAlloc(osPoolId pool_id) { void *p = osPoolAlloc(pool_id); - + if (p != NULL) { memset(p, 0, sizeof(pool_id->pool_sz)); } - + return p; } @@ -1039,42 +1100,46 @@ void *osPoolCAlloc (osPoolId pool_id) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS. */ -osStatus osPoolFree (osPoolId pool_id, void *block) +osStatus osPoolFree(osPoolId pool_id, void *block) { uint32_t index; - - if (pool_id == NULL) { + + if (pool_id == NULL) + { return osErrorParameter; } - - if (block == NULL) { + + if (block == NULL) + { return osErrorParameter; } - - if (block < pool_id->pool) { + + if (block < pool_id->pool) + { return osErrorParameter; } - + index = (uint32_t)block - (uint32_t)(pool_id->pool); - if (index % pool_id->item_sz) { + if (index % pool_id->item_sz) + { return osErrorParameter; } index = index / pool_id->item_sz; - if (index >= pool_id->pool_sz) { + if (index >= pool_id->pool_sz) + { return osErrorParameter; } - + pool_id->markers[index] = 0; - + return osOK; } - -#endif /* Use Memory Pool Management */ +#endif /* Use Memory Pool Management */ /******************* Message Queue Management Functions *********************/ -#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) /* Use Message Queues */ +#if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0)) /* Use Message Queues */ /** * @brief Create and Initialize a Message Queue @@ -1083,21 +1148,23 @@ osStatus osPoolFree (osPoolId pool_id, void *block) * @retval message queue ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS. */ -osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id) +osMessageQId osMessageCreate(const osMessageQDef_t *queue_def, osThreadId thread_id) { - (void) thread_id; - -#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + (void)thread_id; - if ((queue_def->buffer != NULL) && (queue_def->controlblock != NULL)) { +#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1) + + if ((queue_def->buffer != NULL) && (queue_def->controlblock != NULL)) + { return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock); } - else { + else + { return xQueueCreate(queue_def->queue_sz, queue_def->item_sz); } -#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) +#elif (configSUPPORT_STATIC_ALLOCATION == 1) return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock); -#else +#else return xQueueCreate(queue_def->queue_sz, queue_def->item_sz); #endif } @@ -1110,28 +1177,33 @@ osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId threa * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. */ -osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) +osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec) { portBASE_TYPE taskWoken = pdFALSE; TickType_t ticks; - + ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) { + if (ticks == 0) + { ticks = 1; } - - if (inHandlerMode()) { - if (xQueueSendFromISR(queue_id, &info, &taskWoken) != pdTRUE) { + + if (inHandlerMode()) + { + if (xQueueSendFromISR(queue_id, &info, &taskWoken) != pdTRUE) + { return osErrorOS; } portEND_SWITCHING_ISR(taskWoken); } - else { - if (xQueueSend(queue_id, &info, ticks) != pdTRUE) { + else + { + if (xQueueSend(queue_id, &info, ticks) != pdTRUE) + { return osErrorOS; } } - + return osOK; } @@ -1142,63 +1214,73 @@ osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) * @retval event information that includes status code. * @note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS. */ -osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec) +osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec) { portBASE_TYPE taskWoken; TickType_t ticks; osEvent event; - + event.def.message_id = queue_id; event.value.v = 0; - - if (queue_id == NULL) { + + if (queue_id == NULL) + { event.status = osErrorParameter; return event; } - + taskWoken = pdFALSE; - + ticks = 0; - if (millisec == osWaitForever) { + if (millisec == osWaitForever) + { ticks = portMAX_DELAY; } - else if (millisec != 0) { + else if (millisec != 0) + { ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) { + if (ticks == 0) + { ticks = 1; } } - - if (inHandlerMode()) { - if (xQueueReceiveFromISR(queue_id, &event.value.v, &taskWoken) == pdTRUE) { + + if (inHandlerMode()) + { + if (xQueueReceiveFromISR(queue_id, &event.value.v, &taskWoken) == pdTRUE) + { /* We have mail */ event.status = osEventMessage; } - else { + else + { event.status = osOK; } portEND_SWITCHING_ISR(taskWoken); } - else { - if (xQueueReceive(queue_id, &event.value.v, ticks) == pdTRUE) { + else + { + if (xQueueReceive(queue_id, &event.value.v, ticks) == pdTRUE) + { /* We have mail */ event.status = osEventMessage; } - else { + else + { event.status = (ticks == 0) ? osOK : osEventTimeout; } } - + return event; } -#endif /* Use Message Queues */ +#endif /* Use Message Queues */ /******************** Mail Queue Management Functions ***********************/ -#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) /* Use Mail Queues */ +#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) /* Use Mail Queues */ - -typedef struct os_mailQ_cb { +typedef struct os_mailQ_cb +{ const osMailQDef_t *queue_def; QueueHandle_t handle; osPoolId pool; @@ -1211,39 +1293,41 @@ typedef struct os_mailQ_cb { * @retval mail queue ID for reference by other functions or NULL in case of error. * @note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS. */ -osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id) +osMailQId osMailCreate(const osMailQDef_t *queue_def, osThreadId thread_id) { #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - (void) thread_id; - + (void)thread_id; + osPoolDef_t pool_def = {queue_def->queue_sz, queue_def->item_sz, NULL}; - + /* Create a mail queue control block */ *(queue_def->cb) = pvPortMalloc(sizeof(struct os_mailQ_cb)); - if (*(queue_def->cb) == NULL) { + if (*(queue_def->cb) == NULL) + { return NULL; } (*(queue_def->cb))->queue_def = queue_def; - + /* Create a queue in FreeRTOS */ (*(queue_def->cb))->handle = xQueueCreate(queue_def->queue_sz, sizeof(void *)); - - if ((*(queue_def->cb))->handle == NULL) { + if ((*(queue_def->cb))->handle == NULL) + { vPortFree(*(queue_def->cb)); return NULL; } - + /* Create a mail pool */ (*(queue_def->cb))->pool = osPoolCreate(&pool_def); - if ((*(queue_def->cb))->pool == NULL) { + if ((*(queue_def->cb))->pool == NULL) + { //TODO: Delete queue. How to do it in FreeRTOS? vPortFree(*(queue_def->cb)); return NULL; } - + return *(queue_def->cb); #else return NULL; @@ -1257,18 +1341,18 @@ osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id) * @retval pointer to memory block that can be filled with mail or NULL in case error. * @note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS. */ -void *osMailAlloc (osMailQId queue_id, uint32_t millisec) +void *osMailAlloc(osMailQId queue_id, uint32_t millisec) { - (void) millisec; + (void)millisec; void *p; - - - if (queue_id == NULL) { + + if (queue_id == NULL) + { return NULL; } - + p = osPoolAlloc(queue_id->pool); - + return p; } @@ -1279,17 +1363,19 @@ void *osMailAlloc (osMailQId queue_id, uint32_t millisec) * @retval pointer to memory block that can be filled with mail or NULL in case error. * @note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS. */ -void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) +void *osMailCAlloc(osMailQId queue_id, uint32_t millisec) { uint32_t i; void *p = osMailAlloc(queue_id, millisec); - - if (p) { - for (i = 0; i < queue_id->queue_def->item_sz; i++) { + + if (p) + { + for (i = 0; i < queue_id->queue_def->item_sz; i++) + { ((uint8_t *)p)[i] = 0; } } - + return p; } @@ -1300,29 +1386,33 @@ void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS. */ -osStatus osMailPut (osMailQId queue_id, void *mail) +osStatus osMailPut(osMailQId queue_id, void *mail) { portBASE_TYPE taskWoken; - - - if (queue_id == NULL) { + + if (queue_id == NULL) + { return osErrorParameter; } - + taskWoken = pdFALSE; - - if (inHandlerMode()) { - if (xQueueSendFromISR(queue_id->handle, &mail, &taskWoken) != pdTRUE) { + + if (inHandlerMode()) + { + if (xQueueSendFromISR(queue_id->handle, &mail, &taskWoken) != pdTRUE) + { return osErrorOS; } portEND_SWITCHING_ISR(taskWoken); } - else { - if (xQueueSend(queue_id->handle, &mail, 0) != pdTRUE) { + else + { + if (xQueueSend(queue_id->handle, &mail, 0) != pdTRUE) + { return osErrorOS; } } - + return osOK; } @@ -1333,52 +1423,62 @@ osStatus osMailPut (osMailQId queue_id, void *mail) * @retval event that contains mail information or error code. * @note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS. */ -osEvent osMailGet (osMailQId queue_id, uint32_t millisec) +osEvent osMailGet(osMailQId queue_id, uint32_t millisec) { portBASE_TYPE taskWoken; TickType_t ticks; osEvent event; - + event.def.mail_id = queue_id; - - if (queue_id == NULL) { + + if (queue_id == NULL) + { event.status = osErrorParameter; return event; } - + taskWoken = pdFALSE; - + ticks = 0; - if (millisec == osWaitForever) { + if (millisec == osWaitForever) + { ticks = portMAX_DELAY; } - else if (millisec != 0) { + else if (millisec != 0) + { ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) { + if (ticks == 0) + { ticks = 1; } } - - if (inHandlerMode()) { - if (xQueueReceiveFromISR(queue_id->handle, &event.value.p, &taskWoken) == pdTRUE) { + + if (inHandlerMode()) + { + if (xQueueReceiveFromISR(queue_id->handle, &event.value.p, &taskWoken) == pdTRUE) + { /* We have mail */ event.status = osEventMail; } - else { + else + { event.status = osOK; } portEND_SWITCHING_ISR(taskWoken); } - else { - if (xQueueReceive(queue_id->handle, &event.value.p, ticks) == pdTRUE) { + else + { + if (xQueueReceive(queue_id->handle, &event.value.p, ticks) == pdTRUE) + { /* We have mail */ event.status = osEventMail; } - else { + else + { event.status = (ticks == 0) ? osOK : osEventTimeout; } } - + return event; } @@ -1389,15 +1489,16 @@ osEvent osMailGet (osMailQId queue_id, uint32_t millisec) * @retval status code that indicates the execution status of the function. * @note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS. */ -osStatus osMailFree (osMailQId queue_id, void *mail) +osStatus osMailFree(osMailQId queue_id, void *mail) { - if (queue_id == NULL) { + if (queue_id == NULL) + { return osErrorParameter; } - + return osPoolFree(queue_id->pool, mail); } -#endif /* Use Mail Queues */ +#endif /* Use Mail Queues */ /*************************** Additional specific APIs to Free RTOS ************/ /** @@ -1408,17 +1509,17 @@ osStatus osMailFree (osMailQId queue_id, void *mail) void osSystickHandler(void) { -#if (INCLUDE_xTaskGetSchedulerState == 1 ) +#if (INCLUDE_xTaskGetSchedulerState == 1) if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { -#endif /* INCLUDE_xTaskGetSchedulerState */ +#endif /* INCLUDE_xTaskGetSchedulerState */ xPortSysTickHandler(); -#if (INCLUDE_xTaskGetSchedulerState == 1 ) +#if (INCLUDE_xTaskGetSchedulerState == 1) } -#endif /* INCLUDE_xTaskGetSchedulerState */ +#endif /* INCLUDE_xTaskGetSchedulerState */ } -#if ( INCLUDE_eTaskGetState == 1 ) +#if (INCLUDE_eTaskGetState == 1) /** * @brief Obtain the state of any thread. * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. @@ -1428,30 +1529,30 @@ osThreadState osThreadGetState(osThreadId thread_id) { eTaskState ThreadState; osThreadState result; - + ThreadState = eTaskGetState(thread_id); - + switch (ThreadState) { - case eRunning : + case eRunning: result = osThreadRunning; break; - case eReady : + case eReady: result = osThreadReady; break; - case eBlocked : + case eBlocked: result = osThreadBlocked; break; - case eSuspended : + case eSuspended: result = osThreadSuspended; break; - case eDeleted : + case eDeleted: result = osThreadDeleted; break; default: result = osThreadError; - } - + } + return result; } #endif /* INCLUDE_eTaskGetState */ @@ -1475,11 +1576,11 @@ osStatus osThreadIsSuspended(osThreadId thread_id) * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. * @retval status code that indicates the execution status of the function. */ -osStatus osThreadSuspend (osThreadId thread_id) +osStatus osThreadSuspend(osThreadId thread_id) { #if (INCLUDE_vTaskSuspend == 1) - vTaskSuspend(thread_id); - + vTaskSuspend(thread_id); + return osOK; #else return osErrorResource; @@ -1491,10 +1592,10 @@ osStatus osThreadSuspend (osThreadId thread_id) * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. * @retval status code that indicates the execution status of the function. */ -osStatus osThreadResume (osThreadId thread_id) +osStatus osThreadResume(osThreadId thread_id) { -#if (INCLUDE_vTaskSuspend == 1) - if(inHandlerMode()) +#if (INCLUDE_vTaskSuspend == 1) + if (inHandlerMode()) { if (xTaskResumeFromISR(thread_id) == pdTRUE) { @@ -1515,10 +1616,10 @@ osStatus osThreadResume (osThreadId thread_id) * @brief Suspend execution of a all active threads. * @retval status code that indicates the execution status of the function. */ -osStatus osThreadSuspendAll (void) +osStatus osThreadSuspendAll(void) { vTaskSuspendAll(); - + return osOK; } @@ -1526,13 +1627,12 @@ osStatus osThreadSuspendAll (void) * @brief Resume execution of a all suspended threads. * @retval status code that indicates the execution status of the function. */ -osStatus osThreadResumeAll (void) +osStatus osThreadResumeAll(void) { if (xTaskResumeAll() == pdTRUE) return osOK; else return osErrorOS; - } /** @@ -1543,17 +1643,17 @@ osStatus osThreadResumeAll (void) * @param millisec time delay value * @retval status code that indicates the execution status of the function. */ -osStatus osDelayUntil (uint32_t *PreviousWakeTime, uint32_t millisec) +osStatus osDelayUntil(uint32_t *PreviousWakeTime, uint32_t millisec) { #if INCLUDE_vTaskDelayUntil TickType_t ticks = (millisec / portTICK_PERIOD_MS); - vTaskDelayUntil((TickType_t *) PreviousWakeTime, ticks ? ticks : 1); - + vTaskDelayUntil((TickType_t *)PreviousWakeTime, ticks ? ticks : 1); + return osOK; #else - (void) millisec; - (void) PreviousWakeTime; - + (void)millisec; + (void)PreviousWakeTime; + return osErrorResource; #endif } @@ -1566,13 +1666,13 @@ osStatus osDelayUntil (uint32_t *PreviousWakeTime, uint32_t millisec) osStatus osAbortDelay(osThreadId thread_id) { #if INCLUDE_xTaskAbortDelay - + xTaskAbortDelay(thread_id); - + return osOK; #else - (void) thread_id; - + (void)thread_id; + return osErrorResource; #endif } @@ -1584,9 +1684,9 @@ osStatus osAbortDelay(osThreadId thread_id) * will be written * @retval status code that indicates the execution status of the function. */ -osStatus osThreadList (uint8_t *buffer) +osStatus osThreadList(uint8_t *buffer) { -#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) +#if ((configUSE_TRACE_FACILITY == 1) && (configUSE_STATS_FORMATTING_FUNCTIONS == 1)) vTaskList((char *)buffer); #endif return osOK; @@ -1598,39 +1698,43 @@ osStatus osThreadList (uint8_t *buffer) * @param millisec timeout value or 0 in case of no time-out. * @retval event information that includes status code. */ -osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec) +osEvent osMessagePeek(osMessageQId queue_id, uint32_t millisec) { TickType_t ticks; osEvent event; - + event.def.message_id = queue_id; - - if (queue_id == NULL) { + + if (queue_id == NULL) + { event.status = osErrorParameter; return event; } - + ticks = 0; - if (millisec == osWaitForever) { + if (millisec == osWaitForever) + { ticks = portMAX_DELAY; } - else if (millisec != 0) { + else if (millisec != 0) + { ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) { + if (ticks == 0) + { ticks = 1; } } - - if (xQueuePeek(queue_id, &event.value.v, ticks) == pdTRUE) + + if (xQueuePeek(queue_id, &event.value.v, ticks) == pdTRUE) { /* We have mail */ event.status = osEventMessage; } - else + else { event.status = (ticks == 0) ? osOK : osEventTimeout; } - + return event; } @@ -1641,7 +1745,8 @@ osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec) */ uint32_t osMessageWaiting(osMessageQId queue_id) { - if (inHandlerMode()) { + if (inHandlerMode()) + { return uxQueueMessagesWaitingFromISR(queue_id); } else @@ -1655,7 +1760,7 @@ uint32_t osMessageWaiting(osMessageQId queue_id) * @param queue_id message queue ID obtained with \ref osMessageCreate. * @retval available space in a message queue. */ -uint32_t osMessageAvailableSpace(osMessageQId queue_id) +uint32_t osMessageAvailableSpace(osMessageQId queue_id) { return uxQueueSpacesAvailable(queue_id); } @@ -1665,15 +1770,16 @@ uint32_t osMessageAvailableSpace(osMessageQId queue_id) * @param queue_id message queue ID obtained with \ref osMessageCreate. * @retval status code that indicates the execution status of the function. */ -osStatus osMessageDelete (osMessageQId queue_id) +osStatus osMessageDelete(osMessageQId queue_id) { - if (inHandlerMode()) { + if (inHandlerMode()) + { return osErrorISR; } vQueueDelete(queue_id); - return osOK; + return osOK; } /** @@ -1681,25 +1787,27 @@ osStatus osMessageDelete (osMessageQId queue_id) * @param mutex_def mutex definition referenced with \ref osMutex. * @retval mutex ID for reference by other functions or NULL in case of error.. */ -osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def) +osMutexId osRecursiveMutexCreate(const osMutexDef_t *mutex_def) { #if (configUSE_RECURSIVE_MUTEXES == 1) -#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) +#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1) - if (mutex_def->controlblock != NULL){ - return xSemaphoreCreateRecursiveMutexStatic( mutex_def->controlblock ); + if (mutex_def->controlblock != NULL) + { + return xSemaphoreCreateRecursiveMutexStatic(mutex_def->controlblock); } - else { + else + { return xSemaphoreCreateRecursiveMutex(); } -#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) - return xSemaphoreCreateRecursiveMutexStatic( mutex_def->controlblock ); -#else +#elif (configSUPPORT_STATIC_ALLOCATION == 1) + return xSemaphoreCreateRecursiveMutexStatic(mutex_def->controlblock); +#else return xSemaphoreCreateRecursiveMutex(); #endif #else return NULL; -#endif +#endif } /** @@ -1707,18 +1815,18 @@ osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def) * @param mutex_id mutex ID obtained by \ref osRecursiveMutexCreate. * @retval status code that indicates the execution status of the function. */ -osStatus osRecursiveMutexRelease (osMutexId mutex_id) +osStatus osRecursiveMutexRelease(osMutexId mutex_id) { #if (configUSE_RECURSIVE_MUTEXES == 1) osStatus result = osOK; - - if (xSemaphoreGiveRecursive(mutex_id) != pdTRUE) + + if (xSemaphoreGiveRecursive(mutex_id) != pdTRUE) { result = osErrorOS; } return result; #else - return osErrorResource; + return osErrorResource; #endif } @@ -1728,37 +1836,37 @@ osStatus osRecursiveMutexRelease (osMutexId mutex_id) * @param millisec timeout value or 0 in case of no time-out. * @retval status code that indicates the execution status of the function. */ -osStatus osRecursiveMutexWait (osMutexId mutex_id, uint32_t millisec) +osStatus osRecursiveMutexWait(osMutexId mutex_id, uint32_t millisec) { #if (configUSE_RECURSIVE_MUTEXES == 1) TickType_t ticks; - + if (mutex_id == NULL) { return osErrorParameter; } - + ticks = 0; - if (millisec == osWaitForever) + if (millisec == osWaitForever) { ticks = portMAX_DELAY; } - else if (millisec != 0) + else if (millisec != 0) { ticks = millisec / portTICK_PERIOD_MS; - if (ticks == 0) + if (ticks == 0) { ticks = 1; } } - - if (xSemaphoreTakeRecursive(mutex_id, ticks) != pdTRUE) + + if (xSemaphoreTakeRecursive(mutex_id, ticks) != pdTRUE) { return osErrorOS; } return osOK; #else - return osErrorResource; + return osErrorResource; #endif } diff --git a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h b/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h deleted file mode 100644 index e048e6cd..00000000 --- a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h +++ /dev/null @@ -1,279 +0,0 @@ -/* - * FreeRTOS Kernel V10.3.1 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ - -#ifndef DEPRECATED_DEFINITIONS_H -#define DEPRECATED_DEFINITIONS_H - - -/* Each FreeRTOS port has a unique portmacro.h header file. Originally a -pre-processor definition was used to ensure the pre-processor found the correct -portmacro.h file for the port being used. That scheme was deprecated in favour -of setting the compiler's include path such that it found the correct -portmacro.h file - removing the need for the constant and allowing the -portmacro.h file to be located anywhere in relation to the port being used. The -definitions below remain in the code for backward compatibility only. New -projects should not use them. */ - -#ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT - #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef OPEN_WATCOM_FLASH_LITE_186_PORT - #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef GCC_MEGA_AVR - #include "../portable/GCC/ATMega323/portmacro.h" -#endif - -#ifdef IAR_MEGA_AVR - #include "../portable/IAR/ATMega323/portmacro.h" -#endif - -#ifdef MPLAB_PIC24_PORT - #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" -#endif - -#ifdef MPLAB_DSPIC_PORT - #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" -#endif - -#ifdef MPLAB_PIC18F_PORT - #include "../../Source/portable/MPLAB/PIC18F/portmacro.h" -#endif - -#ifdef MPLAB_PIC32MX_PORT - #include "../../Source/portable/MPLAB/PIC32MX/portmacro.h" -#endif - -#ifdef _FEDPICC - #include "libFreeRTOS/Include/portmacro.h" -#endif - -#ifdef SDCC_CYGNAL - #include "../../Source/portable/SDCC/Cygnal/portmacro.h" -#endif - -#ifdef GCC_ARM7 - #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" -#endif - -#ifdef GCC_ARM7_ECLIPSE - #include "portmacro.h" -#endif - -#ifdef ROWLEY_LPC23xx - #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" -#endif - -#ifdef IAR_MSP430 - #include "..\..\Source\portable\IAR\MSP430\portmacro.h" -#endif - -#ifdef GCC_MSP430 - #include "../../Source/portable/GCC/MSP430F449/portmacro.h" -#endif - -#ifdef ROWLEY_MSP430 - #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" -#endif - -#ifdef ARM7_LPC21xx_KEIL_RVDS - #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" -#endif - -#ifdef SAM7_GCC - #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" -#endif - -#ifdef SAM7_IAR - #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" -#endif - -#ifdef SAM9XE_IAR - #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" -#endif - -#ifdef LPC2000_IAR - #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" -#endif - -#ifdef STR71X_IAR - #include "..\..\Source\portable\IAR\STR71x\portmacro.h" -#endif - -#ifdef STR75X_IAR - #include "..\..\Source\portable\IAR\STR75x\portmacro.h" -#endif - -#ifdef STR75X_GCC - #include "..\..\Source\portable\GCC\STR75x\portmacro.h" -#endif - -#ifdef STR91X_IAR - #include "..\..\Source\portable\IAR\STR91x\portmacro.h" -#endif - -#ifdef GCC_H8S - #include "../../Source/portable/GCC/H8S2329/portmacro.h" -#endif - -#ifdef GCC_AT91FR40008 - #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" -#endif - -#ifdef RVDS_ARMCM3_LM3S102 - #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" -#endif - -#ifdef GCC_ARMCM3_LM3S102 - #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" -#endif - -#ifdef GCC_ARMCM3 - #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" -#endif - -#ifdef IAR_ARM_CM3 - #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" -#endif - -#ifdef IAR_ARMCM3_LM - #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" -#endif - -#ifdef HCS12_CODE_WARRIOR - #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" -#endif - -#ifdef MICROBLAZE_GCC - #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" -#endif - -#ifdef TERN_EE - #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" -#endif - -#ifdef GCC_HCS12 - #include "../../Source/portable/GCC/HCS12/portmacro.h" -#endif - -#ifdef GCC_MCF5235 - #include "../../Source/portable/GCC/MCF5235/portmacro.h" -#endif - -#ifdef COLDFIRE_V2_GCC - #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" -#endif - -#ifdef COLDFIRE_V2_CODEWARRIOR - #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" -#endif - -#ifdef GCC_PPC405 - #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" -#endif - -#ifdef GCC_PPC440 - #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" -#endif - -#ifdef _16FX_SOFTUNE - #include "..\..\Source\portable\Softune\MB96340\portmacro.h" -#endif - -#ifdef BCC_INDUSTRIAL_PC_PORT - /* A short file name has to be used in place of the normal - FreeRTOSConfig.h when using the Borland compiler. */ - #include "frconfig.h" - #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef BCC_FLASH_LITE_186_PORT - /* A short file name has to be used in place of the normal - FreeRTOSConfig.h when using the Borland compiler. */ - #include "frconfig.h" - #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef __GNUC__ - #ifdef __AVR32_AVR32A__ - #include "portmacro.h" - #endif -#endif - -#ifdef __ICCAVR32__ - #ifdef __CORE__ - #if __CORE__ == __AVR32A__ - #include "portmacro.h" - #endif - #endif -#endif - -#ifdef __91467D - #include "portmacro.h" -#endif - -#ifdef __96340 - #include "portmacro.h" -#endif - - -#ifdef __IAR_V850ES_Fx3__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Jx3__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Jx3_L__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Jx2__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Hx2__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_78K0R_Kx3__ - #include "../../Source/portable/IAR/78K0R/portmacro.h" -#endif - -#ifdef __IAR_78K0R_Kx3L__ - #include "../../Source/portable/IAR/78K0R/portmacro.h" -#endif - -#endif /* DEPRECATED_DEFINITIONS_H */ - diff --git a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/portable.h b/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/portable.h index 47ceab9f..ac644e45 100644 --- a/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/portable.h +++ b/workspace/TS100/Middlewares/Third_Party/FreeRTOS/Source/include/portable.h @@ -42,58 +42,58 @@ Purely for reasons of backward compatibility the old method is still valid, but to make it clear that new projects should not use it, support for the port specific constants has been moved into the deprecated_definitions.h header file. */ -#include "deprecated_definitions.h" /* If portENTER_CRITICAL is not defined then including deprecated_definitions.h did not result in a portmacro.h header file being included - and it should be included here. In this case the path to the correct portmacro.h header file must be set in the compiler's include path. */ #ifndef portENTER_CRITICAL - #include "portmacro.h" +#include "portmacro.h" #endif #if portBYTE_ALIGNMENT == 32 - #define portBYTE_ALIGNMENT_MASK ( 0x001f ) +#define portBYTE_ALIGNMENT_MASK (0x001f) #endif #if portBYTE_ALIGNMENT == 16 - #define portBYTE_ALIGNMENT_MASK ( 0x000f ) +#define portBYTE_ALIGNMENT_MASK (0x000f) #endif #if portBYTE_ALIGNMENT == 8 - #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) +#define portBYTE_ALIGNMENT_MASK (0x0007) #endif #if portBYTE_ALIGNMENT == 4 - #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) +#define portBYTE_ALIGNMENT_MASK (0x0003) #endif #if portBYTE_ALIGNMENT == 2 - #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) +#define portBYTE_ALIGNMENT_MASK (0x0001) #endif #if portBYTE_ALIGNMENT == 1 - #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) +#define portBYTE_ALIGNMENT_MASK (0x0000) #endif #ifndef portBYTE_ALIGNMENT_MASK - #error "Invalid portBYTE_ALIGNMENT definition" +#error "Invalid portBYTE_ALIGNMENT definition" #endif #ifndef portNUM_CONFIGURABLE_REGIONS - #define portNUM_CONFIGURABLE_REGIONS 1 +#define portNUM_CONFIGURABLE_REGIONS 1 #endif #ifndef portHAS_STACK_OVERFLOW_CHECKING - #define portHAS_STACK_OVERFLOW_CHECKING 0 +#define portHAS_STACK_OVERFLOW_CHECKING 0 #endif #ifndef portARCH_NAME - #define portARCH_NAME NULL +#define portARCH_NAME NULL #endif #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #include "mpu_wrappers.h" @@ -104,41 +104,41 @@ extern "C" { * the order that the port expects to find them. * */ -#if( portUSING_MPU_WRAPPERS == 1 ) - #if( portHAS_STACK_OVERFLOW_CHECKING == 1 ) - StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; - #else - StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; - #endif +#if (portUSING_MPU_WRAPPERS == 1) +#if (portHAS_STACK_OVERFLOW_CHECKING == 1) + StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged) PRIVILEGED_FUNCTION; #else - #if( portHAS_STACK_OVERFLOW_CHECKING == 1 ) - StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; - #else - StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; - #endif + StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged) PRIVILEGED_FUNCTION; +#endif +#else +#if (portHAS_STACK_OVERFLOW_CHECKING == 1) +StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters) PRIVILEGED_FUNCTION; +#else +StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters) PRIVILEGED_FUNCTION; +#endif #endif -/* Used by heap_5.c to define the start address and size of each memory region + /* Used by heap_5.c to define the start address and size of each memory region that together comprise the total FreeRTOS heap space. */ -typedef struct HeapRegion -{ - uint8_t *pucStartAddress; - size_t xSizeInBytes; -} HeapRegion_t; + typedef struct HeapRegion + { + uint8_t *pucStartAddress; + size_t xSizeInBytes; + } HeapRegion_t; -/* Used to pass information about the heap out of vPortGetHeapStats(). */ -typedef struct xHeapStats -{ - size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */ - size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ - size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ - size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */ - size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */ - size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */ - size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */ -} HeapStats_t; + /* Used to pass information about the heap out of vPortGetHeapStats(). */ + typedef struct xHeapStats + { + size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */ + size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ + size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ + size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */ + size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */ + size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */ + size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */ + } HeapStats_t; -/* + /* * Used to define multiple heap regions for use by heap_5.c. This function * must be called before any calls to pvPortMalloc() - not creating a task, * queue, semaphore, mutex, software timer, event group, etc. will result in @@ -149,35 +149,35 @@ typedef struct xHeapStats * terminated by a HeapRegions_t structure that has a size of 0. The region * with the lowest start address must appear first in the array. */ -void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION; + void vPortDefineHeapRegions(const HeapRegion_t *const pxHeapRegions) PRIVILEGED_FUNCTION; -/* + /* * Returns a HeapStats_t structure filled with information about the current * heap state. */ -void vPortGetHeapStats( HeapStats_t *pxHeapStats ); + void vPortGetHeapStats(HeapStats_t *pxHeapStats); -/* + /* * Map to the memory management routines required for the port. */ -void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; -void vPortFree( void *pv ) PRIVILEGED_FUNCTION; -void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; -size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; -size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; + void *pvPortMalloc(size_t xSize) PRIVILEGED_FUNCTION; + void vPortFree(void *pv) PRIVILEGED_FUNCTION; + void vPortInitialiseBlocks(void) PRIVILEGED_FUNCTION; + size_t xPortGetFreeHeapSize(void) PRIVILEGED_FUNCTION; + size_t xPortGetMinimumEverFreeHeapSize(void) PRIVILEGED_FUNCTION; -/* + /* * Setup the hardware ready for the scheduler to take control. This generally * sets up a tick interrupt and sets timers for the correct tick frequency. */ -BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION; + BaseType_t xPortStartScheduler(void) PRIVILEGED_FUNCTION; -/* + /* * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so * the hardware is left in its original condition after the scheduler stops * executing. */ -void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; + void vPortEndScheduler(void) PRIVILEGED_FUNCTION; /* * The structures and methods of manipulating the MPU are contained within the @@ -186,9 +186,9 @@ void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; * Fills the xMPUSettings structure with the memory region information * contained in xRegions. */ -#if( portUSING_MPU_WRAPPERS == 1 ) +#if (portUSING_MPU_WRAPPERS == 1) struct xMEMORY_REGION; - void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth ) PRIVILEGED_FUNCTION; + void vPortStoreTaskMPUSettings(xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION *const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth) PRIVILEGED_FUNCTION; #endif #ifdef __cplusplus @@ -196,4 +196,3 @@ void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; #endif #endif /* PORTABLE_H */ - diff --git a/workspace/TS100/configuration.h b/workspace/TS100/configuration.h index 57bdc23e..01990aed 100644 --- a/workspace/TS100/configuration.h +++ b/workspace/TS100/configuration.h @@ -13,22 +13,22 @@ * Default soldering temp is 320.0 C * Temperature the iron sleeps at - default 150.0 C */ -#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C -#define SLEEP_TEMP 150 // Default sleep temperature -#define BOOST_TEMP 420 // Default boost temp. -#define BOOST_MODE_ENABLED 1 // 0: Disable 1: Enable +#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C +#define SLEEP_TEMP 150 // Default sleep temperature +#define BOOST_TEMP 420 // Default boost temp. +#define BOOST_MODE_ENABLED 1 // 0: Disable 1: Enable /** * Blink the temperature on the cooling screen when its > 50C */ -#define COOLING_TEMP_BLINK 0 // 0: Disable 1: Enable +#define COOLING_TEMP_BLINK 0 // 0: Disable 1: Enable /** * How many seconds/minutes we wait until going to sleep/shutdown. * Values -> SLEEP_TIME * 10; i.e. 5*10 = 50 Seconds! */ -#define SLEEP_TIME 5 // x10 Seconds -#define SHUTDOWN_TIME 10 // Minutes +#define SLEEP_TIME 5 // x10 Seconds +#define SHUTDOWN_TIME 10 // Minutes /** * Auto start off for safety. @@ -38,22 +38,22 @@ * 2 - Sleep Temperature * 3 - Sleep Off Temperature */ -#define AUTO_START_MODE 0 // Default to none +#define AUTO_START_MODE 0 // Default to none /** * OLED Orientation * */ -#define ORIENTATION_MODE 0 // 0: Right 1:Left 2:Automatic - Default right -#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperatur change +#define ORIENTATION_MODE 0 // 0: Right 1:Left 2:Automatic - Default right +#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperatur change /** * Temp change settings */ -#define TEMP_CHANGE_SHORT_STEP 1 // Default temp change short step +1 -#define TEMP_CHANGE_LONG_STEP 10 // Default temp change long step +10 -#define TEMP_CHANGE_SHORT_STEP_MAX 50 // Temp change short step MAX value -#define TEMP_CHANGE_LONG_STEP_MAX 100 // Temp change long step MAX value +#define TEMP_CHANGE_SHORT_STEP 1 // Default temp change short step +1 +#define TEMP_CHANGE_LONG_STEP 10 // Default temp change long step +10 +#define TEMP_CHANGE_SHORT_STEP_MAX 50 // Temp change short step MAX value +#define TEMP_CHANGE_LONG_STEP_MAX 100 // Temp change long step MAX value /* Power pulse for keeping power banks awake*/ #define POWER_PULSE_INCREMENT 1 @@ -68,70 +68,83 @@ * OLED Orientation Sensitivity on Automatic mode! * Motion Sensitivity <0=Off 1=Least Sensitive 9=Most Sensitive> */ -#define SENSITIVITY 7 // Default 7 +#define SENSITIVITY 7 // Default 7 /** * Detailed soldering screen * Detailed idle screen (off for first time users) */ -#define DETAILED_SOLDERING 0 // 0: Disable 1: Enable - Default 0 -#define DETAILED_IDLE 0 // 0: Disable 1: Enable - Default 0 +#define DETAILED_SOLDERING 0 // 0: Disable 1: Enable - Default 0 +#define DETAILED_IDLE 0 // 0: Disable 1: Enable - Default 0 -#define CUT_OUT_SETTING 0 // default to no cut-off voltage (or 18W for TS80) -#define TEMPERATURE_INF 0 // default to 0 -#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow -#define POWER_LIMIT_ENABLE 0 // 0: Disable 1: Enable - Default disabled power limit +#define CUT_OUT_SETTING 0 // default to no cut-off voltage (or 18W for TS80) +#define TEMPERATURE_INF 0 // default to 0 +#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow +#define POWER_LIMIT_ENABLE 0 // 0: Disable 1: Enable - Default disabled power limit -#define TIP_GAIN 210 // 21 uV/C * 10, uV per deg C constant of the tip, Tip uV * 10 / coeff = tip temp +#define TIP_GAIN 210 // 21 uV/C * 10, uV per deg C constant of the tip, Tip uV * 10 / coeff = tip temp -#define OP_AMP_Rf_TS100 750*1000 // 750 Kilo-ohms -> From schematic, R1 -#define OP_AMP_Rin_TS100 2370 // 2.37 Kilo-ohms -> From schematic, R2 +#define OP_AMP_Rf_TS100 750 * 1000 // 750 Kilo-ohms -> From schematic, R1 +#define OP_AMP_Rin_TS100 2370 // 2.37 Kilo-ohms -> From schematic, R2 -#define OP_AMP_GAIN_STAGE_TS100 (1+(OP_AMP_Rf_TS100/OP_AMP_Rin_TS100)) +#define OP_AMP_GAIN_STAGE_TS100 (1 + (OP_AMP_Rf_TS100 / OP_AMP_Rin_TS100)) -#define OP_AMP_Rf_TS80 180*1000 // 180 Kilo-ohms -> From schematic, R6 -#define OP_AMP_Rin_TS80 2000 // 2.0 Kilo-ohms -> From schematic, R3 +#define OP_AMP_Rf_TS80 180 * 1000 // 180 Kilo-ohms -> From schematic, R6 +#define OP_AMP_Rin_TS80 2000 // 2.0 Kilo-ohms -> From schematic, R3 -#define OP_AMP_GAIN_STAGE_TS80 (1+(OP_AMP_Rf_TS80/OP_AMP_Rin_TS80)) +#define OP_AMP_GAIN_STAGE_TS80 (1 + (OP_AMP_Rf_TS80 / OP_AMP_Rin_TS80)) //Deriving the Voltage div: // Vin_max = (3.3*(r1+r2))/(r2) //vdiv = (32768*4)/(vin_max*10) #ifdef MODEL_TS100 - #define VOLTAGE_DIV 467 // 467 - Default divider from schematic - #define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV - #define PID_POWER_LIMIT 70 // Sets the max pwm power limit - #define POWER_LIMIT 30 // 30 watts default limit - #define MAX_POWER_LIMIT 65 // - #define POWER_LIMIT_STEPS 5 // - #define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100 +#define VOLTAGE_DIV 467 // 467 - Default divider from schematic +#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV +#define PID_POWER_LIMIT 70 // Sets the max pwm power limit +#define POWER_LIMIT 30 // 30 watts default limit +#define MAX_POWER_LIMIT 65 // +#define POWER_LIMIT_STEPS 5 // +#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100 +#endif + +#ifdef MODEL_Pinecil +#define VOLTAGE_DIV 467 // 467 - Default divider from schematic +#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV +#define PID_POWER_LIMIT 70 // Sets the max pwm power limit +#define POWER_LIMIT 30 // 30 watts default limit +#define MAX_POWER_LIMIT 65 // +#define POWER_LIMIT_STEPS 5 // +#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100 #endif #ifdef MODEL_TS80 -#define VOLTAGE_DIV 780 // Default divider from schematic -#define PID_POWER_LIMIT 24 // Sets the max pwm power limit -#define CALIBRATION_OFFSET 900 // the adc offset in uV -#define POWER_LIMIT 24 // 24 watts default power limit -#define MAX_POWER_LIMIT 30 // -#define POWER_LIMIT_STEPS 2 -#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80 +#define VOLTAGE_DIV 780 // Default divider from schematic +#define PID_POWER_LIMIT 24 // Sets the max pwm power limit +#define CALIBRATION_OFFSET 900 // the adc offset in uV +#define POWER_LIMIT 24 // 24 watts default power limit +#define MAX_POWER_LIMIT 30 // +#define POWER_LIMIT_STEPS 2 +#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80 #endif #ifdef MODEL_TS80P -#define VOLTAGE_DIV 650 // Default for TS80P with slightly different resistors -#define PID_POWER_LIMIT 35 // Sets the max pwm power limit -#define CALIBRATION_OFFSET 900 // the adc offset in uV -#define POWER_LIMIT 30 // 30 watts default power limit -#define MAX_POWER_LIMIT 35 // -#define POWER_LIMIT_STEPS 2 -#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80 +#define VOLTAGE_DIV 650 // Default for TS80P with slightly different resistors +#define PID_POWER_LIMIT 35 // Sets the max pwm power limit +#define CALIBRATION_OFFSET 900 // the adc offset in uV +#define POWER_LIMIT 30 // 30 watts default power limit +#define MAX_POWER_LIMIT 35 // +#define POWER_LIMIT_STEPS 2 +#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80 #endif - - #ifdef MODEL_TS100 -const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second +const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second +const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 +#endif + +#ifdef MODEL_Pinecil +const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 #endif