Skip to content
Snippets Groups Projects
Commit 2cd151e7 authored by schneider's avatar schneider
Browse files

Merge branch 'rahix/more-mutex' into 'master'

Fix LED mutex stuff

See merge request card10/firmware!369
parents 3b436505 cb1712d5
No related branches found
No related tags found
No related merge requests found
...@@ -7,19 +7,22 @@ ...@@ -7,19 +7,22 @@
#include <stdbool.h> #include <stdbool.h>
//TODO: create smth like vTaskDelay(pdMS_TO_TICKS(//put ms here)) for us, remove blocking delay from /lib/leds.c to avoid process blocking /*
* TODO: create smth like vTaskDelay(pdMS_TO_TICKS(//put ms here)) for us,
* remove blocking delay from /lib/leds.c to avoid process blocking
*/
#define NUM_LEDS 15 /* Take from lib/card10/leds.c */ #define NUM_LEDS 15 /* Take from lib/card10/leds.c */
static void do_update() static void do_update(void)
{ {
while (hwlock_acquire_timeout(HWLOCK_LED, portMAX_DELAY) < 0) { hwlock_acquire(HWLOCK_LED);
vTaskDelay(pdMS_TO_TICKS(1)); hwlock_acquire(HWLOCK_I2C);
}
leds_update_power(); leds_update_power();
leds_update(); leds_update();
hwlock_release(HWLOCK_I2C);
hwlock_release(HWLOCK_LED); hwlock_release(HWLOCK_LED);
} }
...@@ -96,13 +99,7 @@ void epic_leds_dim_top(uint8_t value) ...@@ -96,13 +99,7 @@ void epic_leds_dim_top(uint8_t value)
{ {
leds_set_dim_top(value); leds_set_dim_top(value);
if (personal_state_enabled() == 0) { if (personal_state_enabled() == 0) {
while (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { do_update();
vTaskDelay(pdMS_TO_TICKS(1));
}
leds_update();
hwlock_release(HWLOCK_I2C);
} }
} }
...@@ -110,35 +107,22 @@ void epic_leds_dim_bottom(uint8_t value) ...@@ -110,35 +107,22 @@ void epic_leds_dim_bottom(uint8_t value)
{ {
leds_set_dim_bottom(value); leds_set_dim_bottom(value);
if (personal_state_enabled() == 0) { if (personal_state_enabled() == 0) {
while (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { do_update();
vTaskDelay(pdMS_TO_TICKS(1));
}
leds_update();
hwlock_release(HWLOCK_I2C);
} }
} }
void epic_leds_set_rocket(int led, uint8_t value) void epic_leds_set_rocket(int led, uint8_t value)
{ {
while (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { hwlock_acquire(HWLOCK_I2C);
vTaskDelay(pdMS_TO_TICKS(1)); pmic_set_led(led, value > 31 ? 31 : value);
}
value = value > 31 ? 31 : value;
pmic_set_led(led, value);
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
} }
int epic_leds_get_rocket(int led) int epic_leds_get_rocket(int led)
{ {
int ret = 0; int ret = 0;
while (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) {
vTaskDelay(pdMS_TO_TICKS(1));
}
hwlock_acquire(HWLOCK_I2C);
ret = pmic_get_led(led); ret = pmic_get_led(led);
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
return ret; return ret;
...@@ -146,12 +130,8 @@ int epic_leds_get_rocket(int led) ...@@ -146,12 +130,8 @@ int epic_leds_get_rocket(int led)
void epic_set_flashlight(bool power) void epic_set_flashlight(bool power)
{ {
while (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { hwlock_acquire(HWLOCK_I2C);
vTaskDelay(pdMS_TO_TICKS(1));
}
leds_flashlight(power); leds_flashlight(power);
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
} }
...@@ -162,12 +142,8 @@ void epic_leds_update(void) ...@@ -162,12 +142,8 @@ void epic_leds_update(void)
void epic_leds_set_powersave(bool eco) void epic_leds_set_powersave(bool eco)
{ {
while (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) { hwlock_acquire(HWLOCK_I2C);
vTaskDelay(pdMS_TO_TICKS(1));
}
leds_powersave(eco); leds_powersave(eco);
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
} }
......
...@@ -31,15 +31,8 @@ int epic_personal_state_set(uint8_t state, bool persistent) ...@@ -31,15 +31,8 @@ int epic_personal_state_set(uint8_t state, bool persistent)
personal_state_persistent = persistent; personal_state_persistent = persistent;
if (was_enabled && !_personal_state_enabled) { if (was_enabled && !_personal_state_enabled) {
while (hwlock_acquire_timeout(HWLOCK_LED, portMAX_DELAY) < 0) {
vTaskDelay(pdMS_TO_TICKS(1));
}
leds_prep(PERSONAL_STATE_LED, 0, 0, 0); leds_prep(PERSONAL_STATE_LED, 0, 0, 0);
leds_update_power(); epic_leds_update();
leds_update();
hwlock_release(HWLOCK_LED);
} }
return 0; return 0;
...@@ -60,11 +53,6 @@ void vLedTask(void *pvParameters) ...@@ -60,11 +53,6 @@ void vLedTask(void *pvParameters)
const int led_animation_rate = 1000 / 25; /* 25Hz -> 40ms*/ const int led_animation_rate = 1000 / 25; /* 25Hz -> 40ms*/
while (1) { while (1) {
if (_personal_state_enabled) { if (_personal_state_enabled) {
while (hwlock_acquire_timeout(
HWLOCK_LED, portMAX_DELAY) < 0) {
vTaskDelay(pdMS_TO_TICKS(1));
}
led_animation_ticks++; led_animation_ticks++;
if (personal_state == STATE_NO_CONTACT) { if (personal_state == STATE_NO_CONTACT) {
leds_prep(PERSONAL_STATE_LED, 255, 0, 0); leds_prep(PERSONAL_STATE_LED, 255, 0, 0);
...@@ -130,10 +118,8 @@ void vLedTask(void *pvParameters) ...@@ -130,10 +118,8 @@ void vLedTask(void *pvParameters)
(float)(1000 / (float)(1000 /
led_animation_rate)))); led_animation_rate))));
} }
leds_update_power();
leds_update();
hwlock_release(HWLOCK_LED); epic_leds_update();
} }
vTaskDelay(led_animation_rate / portTICK_PERIOD_MS); vTaskDelay(led_animation_rate / portTICK_PERIOD_MS);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment