diff options
author | Ben V. Brown <[email protected]> | 2018-04-14 16:33:16 +1000 |
---|---|---|
committer | Ben V. Brown <[email protected]> | 2018-04-14 16:33:16 +1000 |
commit | 576575d7ba386757c8723987e0162f4877cea79e (patch) | |
tree | 2da498322a580cff7c85ec964e81e49dbabc2667 | |
parent | 7c1937b4126bf32f584f3ea1d4df554a93b32a05 (diff) | |
download | IronOS-576575d7ba386757c8723987e0162f4877cea79e.tar.gz IronOS-576575d7ba386757c8723987e0162f4877cea79e.zip |
More FRToS I2C cleanup
-rw-r--r-- | workspace/TS100/inc/FRToSI2C.hpp | 5 | ||||
-rw-r--r-- | workspace/TS100/inc/main.hpp | 13 | ||||
-rw-r--r-- | workspace/TS100/src/FRToSI2C.cpp | 26 | ||||
-rw-r--r-- | workspace/TS100/src/main.cpp | 15 |
4 files changed, 33 insertions, 26 deletions
diff --git a/workspace/TS100/inc/FRToSI2C.hpp b/workspace/TS100/inc/FRToSI2C.hpp index 0bf52ebd..d3959e35 100644 --- a/workspace/TS100/inc/FRToSI2C.hpp +++ b/workspace/TS100/inc/FRToSI2C.hpp @@ -14,9 +14,7 @@ class FRToSI2C { public: FRToSI2C(I2C_HandleTypeDef* i2chandle); void FRToSInit(); - void MasterTxCpltCallback(); //Normal Tx Callback - void MemRxCpltCallback(); //Callback from memory read cycles - void MemTxCpltCallback(); //Callback from memory write cycles + void CpltCallback(); //Normal Tx Callback void Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); @@ -26,7 +24,6 @@ public: void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size); private: - bool RToSUP=false; I2C_HandleTypeDef* i2c; SemaphoreHandle_t I2CSemaphore; }; diff --git a/workspace/TS100/inc/main.hpp b/workspace/TS100/inc/main.hpp index 91ebaa86..f88c52f0 100644 --- a/workspace/TS100/inc/main.hpp +++ b/workspace/TS100/inc/main.hpp @@ -26,10 +26,17 @@ enum ButtonState { ButtonState getButtonState(); void waitForButtonPressOrTimeout(uint32_t timeout); #ifdef __cplusplus - extern "C" { +extern "C" { #endif - void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc); +void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc); +void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c); +void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c); +void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c); +void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); +void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); +void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); + #ifdef __cplusplus - } +} #endif #endif /* __MAIN_H */ diff --git a/workspace/TS100/src/FRToSI2C.cpp b/workspace/TS100/src/FRToSI2C.cpp index 59b4d704..c5bc8b59 100644 --- a/workspace/TS100/src/FRToSI2C.cpp +++ b/workspace/TS100/src/FRToSI2C.cpp @@ -9,24 +9,23 @@ FRToSI2C::FRToSI2C(I2C_HandleTypeDef* i2chandle) { i2c = i2chandle; - + I2CSemaphore = NULL; } -void FRToSI2C::MasterTxCpltCallback() { - xSemaphoreGive(I2CSemaphore); -} +void FRToSI2C::CpltCallback() { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + + if (I2CSemaphore) { + xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } -void FRToSI2C::MemRxCpltCallback() { - xSemaphoreGive(I2CSemaphore); -} -void FRToSI2C::MemTxCpltCallback() { - xSemaphoreGive(I2CSemaphore); } void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t* pData, uint16_t Size) { if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED - || RToSUP == false) { + || I2CSemaphore == NULL) { //no RToS, run blocking code HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, 5000); @@ -48,7 +47,7 @@ void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t* pData, uint16_t Size) { if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED - || RToSUP == false) { + || I2CSemaphore == NULL) { //no RToS, run blocking code HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, 5000); @@ -70,12 +69,11 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, void FRToSI2C::FRToSInit() { I2CSemaphore = xSemaphoreCreateMutex(); xSemaphoreGive(I2CSemaphore); - RToSUP = true; } void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) { if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED - || RToSUP == false) { + || I2CSemaphore == NULL) { //no RToS, run blocking code HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000); } else { @@ -84,9 +82,7 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) { //Wait up to 1 second for the mutex if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) { HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000); - xSemaphoreGive(I2CSemaphore); - } } diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index 0f24708d..40b5867b 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -1089,14 +1089,21 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc) { } void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c) { + i2cDev.CpltCallback(); } void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c) { - i2cDev.MasterTxCpltCallback(); + i2cDev.CpltCallback(); } void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c) { - i2cDev.MemTxCpltCallback(); -} + i2cDev.CpltCallback(); +} +void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c){ + i2cDev.CpltCallback(); +} +void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c){ + i2cDev.CpltCallback(); +} void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c) { -i2cDev.MemRxCpltCallback(); + i2cDev.CpltCallback(); } |