mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Use mutex for priority inversion prevention
This commit is contained in:
@@ -17,14 +17,19 @@ void I2CBB::init() {
|
|||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||||
GPIO_InitStruct.Pin = SDA2_Pin | SCL2_Pin;
|
GPIO_InitStruct.Pin = SDA2_Pin ;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
HAL_GPIO_Init(SDA2_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(SDA2_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||||
|
GPIO_InitStruct.Pin = SCL2_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
|
HAL_GPIO_Init(SCL2_GPIO_Port, &GPIO_InitStruct);
|
||||||
SOFT_SDA_HIGH();
|
SOFT_SDA_HIGH();
|
||||||
SOFT_SCL_HIGH();
|
SOFT_SCL_HIGH();
|
||||||
I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer);
|
I2CSemaphore = xSemaphoreCreateMutexStatic (&xSemaphoreBuffer);
|
||||||
I2CSemaphore2 = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer2);
|
I2CSemaphore2 = xSemaphoreCreateMutexStatic (&xSemaphoreBuffer2);
|
||||||
unlock();
|
unlock();
|
||||||
unlock2();
|
unlock2();
|
||||||
|
|
||||||
@@ -274,9 +279,6 @@ bool I2CBB::lock() {
|
|||||||
asm("bkpt");
|
asm("bkpt");
|
||||||
}
|
}
|
||||||
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 100) == pdTRUE;
|
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 100) == pdTRUE;
|
||||||
if (!a) {
|
|
||||||
asm("bkpt");
|
|
||||||
}
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,9 +304,7 @@ bool I2CBB::lock2() {
|
|||||||
asm("bkpt");
|
asm("bkpt");
|
||||||
}
|
}
|
||||||
bool a = xSemaphoreTake(I2CSemaphore2, (TickType_t) 500) == pdTRUE;
|
bool a = xSemaphoreTake(I2CSemaphore2, (TickType_t) 500) == pdTRUE;
|
||||||
if (!a) {
|
|
||||||
asm("bkpt");
|
|
||||||
}
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user