diff options
author | JF <jf@codingfield.com> | 2020-05-24 16:51:50 +0200 |
---|---|---|
committer | JF <jf@codingfield.com> | 2020-05-24 16:51:50 +0200 |
commit | 073717980f5c00f553ac3b58a50b792b32a14c7a (patch) | |
tree | 8eeafef1f4150a1cf238ee80e53c8901b0ec67af /src/drivers | |
parent | 331481cd0c6ba804860f7cdbd5110a87ff0160fe (diff) | |
parent | be1ad9b07083e656a649d223750ff4b14b781b7b (diff) |
Merge develop
Diffstat (limited to 'src/drivers')
-rw-r--r-- | src/drivers/SpiMaster.cpp | 63 | ||||
-rw-r--r-- | src/drivers/SpiMaster.h | 4 |
2 files changed, 31 insertions, 36 deletions
diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp index 4d44a435..18bf336f 100644 --- a/src/drivers/SpiMaster.cpp +++ b/src/drivers/SpiMaster.cpp @@ -84,6 +84,7 @@ void SpiMaster::SetupWorkaroundForFtpan58(NRF_SPIM_Type *spim, uint32_t ppi_chan NRF_PPI->CH[ppi_channel].EEP = (uint32_t) &NRF_GPIOTE->EVENTS_IN[gpiote_channel]; NRF_PPI->CH[ppi_channel].TEP = (uint32_t) &spim->TASKS_STOP; NRF_PPI->CHENSET = 1U << ppi_channel; + spiBaseAddress->EVENTS_END = 0; // Disable IRQ spim->INTENCLR = (1<<6); @@ -104,7 +105,6 @@ void SpiMaster::DisableWorkaroundForFtpan58(NRF_SPIM_Type *spim, uint32_t ppi_ch void SpiMaster::OnEndEvent() { if(currentBufferAddr == 0) { - asm("nop"); return; } @@ -119,20 +119,17 @@ void SpiMaster::OnEndEvent() { } else { uint8_t* buffer = nullptr; size_t size = 0; - - - - if(taskToNotify != nullptr) { + if(taskToNotify != nullptr) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + vTaskNotifyGiveFromISR(taskToNotify, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } + + nrf_gpio_pin_set(this->pinCsn); + currentBufferAddr = 0; BaseType_t xHigherPriorityTaskWoken = pdFALSE; - vTaskNotifyGiveFromISR(taskToNotify, &xHigherPriorityTaskWoken); + xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - } - - nrf_gpio_pin_set(this->pinCsn); - currentBufferAddr = 0; - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } } @@ -188,8 +185,6 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t *data, size_t size) { if(size == 1) { while (spiBaseAddress->EVENTS_END == 0); - nrf_gpio_pin_set(this->pinCsn); - currentBufferAddr = 0; xSemaphoreGive(mutex); } @@ -197,35 +192,35 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t *data, size_t size) { } bool SpiMaster::Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t *data, size_t dataSize) { - xSemaphoreTake(mutex, portMAX_DELAY); + xSemaphoreTake(mutex, portMAX_DELAY); - taskToNotify = nullptr; + taskToNotify = nullptr; - this->pinCsn = pinCsn; - DisableWorkaroundForFtpan58(spiBaseAddress, 0,0); - spiBaseAddress->INTENCLR = (1<<6); - spiBaseAddress->INTENCLR = (1<<1); - spiBaseAddress->INTENCLR = (1<<19); + this->pinCsn = pinCsn; + DisableWorkaroundForFtpan58(spiBaseAddress, 0,0); + spiBaseAddress->INTENCLR = (1<<6); + spiBaseAddress->INTENCLR = (1<<1); + spiBaseAddress->INTENCLR = (1<<19); - nrf_gpio_pin_clear(this->pinCsn); + nrf_gpio_pin_clear(this->pinCsn); - currentBufferAddr = 0; - currentBufferSize = 0; + currentBufferAddr = 0; + currentBufferSize = 0; - PrepareTx((uint32_t)cmd, cmdSize); - spiBaseAddress->TASKS_START = 1; - while (spiBaseAddress->EVENTS_END == 0); + PrepareTx((uint32_t)cmd, cmdSize); + spiBaseAddress->TASKS_START = 1; + while (spiBaseAddress->EVENTS_END == 0); - PrepareRx((uint32_t)cmd, cmdSize, (uint32_t)data, dataSize); - spiBaseAddress->TASKS_START = 1; + PrepareRx((uint32_t)cmd, cmdSize, (uint32_t)data, dataSize); + spiBaseAddress->TASKS_START = 1; - while (spiBaseAddress->EVENTS_END == 0); - nrf_gpio_pin_set(this->pinCsn); + while (spiBaseAddress->EVENTS_END == 0); + nrf_gpio_pin_set(this->pinCsn); - xSemaphoreGive(mutex); + xSemaphoreGive(mutex); - return true; + return true; } diff --git a/src/drivers/SpiMaster.h b/src/drivers/SpiMaster.h index 7b35dfc8..88b37a35 100644 --- a/src/drivers/SpiMaster.h +++ b/src/drivers/SpiMaster.h @@ -8,6 +8,8 @@ #include <semphr.h> #include "BufferProvider.h" +#include <semphr.h> + namespace Pinetime { namespace Drivers { class SpiMaster { @@ -55,11 +57,9 @@ namespace Pinetime { SpiMaster::SpiModule spi; SpiMaster::Parameters params; -// volatile bool busy = false; volatile uint32_t currentBufferAddr = 0; volatile size_t currentBufferSize = 0; volatile TaskHandle_t taskToNotify; - SemaphoreHandle_t mutex; }; } |