Move most of the code from the constructor of the objects statically initialized in main() into Start()/Init() functions to avoid Static Initialization Order Fiasco (https://en.cppreference.com/w/cpp/language/siof). See https://github.com/JF002/InfiniTime/pull/415#issuecomment-859004238.
This commit is contained in:
@@ -7,11 +7,14 @@
|
||||
using namespace Pinetime::Drivers;
|
||||
|
||||
SpiMaster::SpiMaster(const SpiMaster::SpiModule spi, const SpiMaster::Parameters& params) : spi {spi}, params {params} {
|
||||
mutex = xSemaphoreCreateBinary();
|
||||
ASSERT(mutex != NULL);
|
||||
}
|
||||
|
||||
bool SpiMaster::Init() {
|
||||
if(mutex == nullptr) {
|
||||
mutex = xSemaphoreCreateBinary();
|
||||
ASSERT(mutex != nullptr);
|
||||
}
|
||||
|
||||
/* Configure GPIO pins used for pselsck, pselmosi, pselmiso and pselss for SPI0 */
|
||||
nrf_gpio_pin_set(params.pinSCK);
|
||||
nrf_gpio_cfg_output(params.pinSCK);
|
||||
|
@@ -59,7 +59,7 @@ namespace Pinetime {
|
||||
volatile uint32_t currentBufferAddr = 0;
|
||||
volatile size_t currentBufferSize = 0;
|
||||
volatile TaskHandle_t taskToNotify;
|
||||
SemaphoreHandle_t mutex;
|
||||
SemaphoreHandle_t mutex = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -9,10 +9,12 @@ using namespace Pinetime::Drivers;
|
||||
// TODO use DMA/IRQ
|
||||
|
||||
TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {module}, params {params} {
|
||||
mutex = xSemaphoreCreateBinary();
|
||||
}
|
||||
|
||||
void TwiMaster::Init() {
|
||||
if(mutex == nullptr)
|
||||
mutex = xSemaphoreCreateBinary();
|
||||
|
||||
NRF_GPIO->PIN_CNF[params.pinScl] =
|
||||
((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
|
||||
((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) |
|
||||
|
@@ -31,7 +31,7 @@ namespace Pinetime {
|
||||
ErrorCodes Write(uint8_t deviceAddress, const uint8_t* data, size_t size, bool stop);
|
||||
void FixHwFreezed();
|
||||
NRF_TWIM_Type* twiBaseAddress;
|
||||
SemaphoreHandle_t mutex;
|
||||
SemaphoreHandle_t mutex = nullptr;
|
||||
const Modules module;
|
||||
const Parameters params;
|
||||
static constexpr uint8_t maxDataSize {16};
|
||||
|
Reference in New Issue
Block a user