Merge pull request #44 from sophiekovalevsky/refactor-tasks
app: refactor tasks creation
This commit is contained in:
commit
055ed57744
@ -27,6 +27,7 @@
|
|||||||
static Protocol::PacketInfo recv_packet;
|
static Protocol::PacketInfo recv_packet;
|
||||||
static Protocol::PacketInfo last_measure_packet; // contains the command that started the last measured (replay in case of timeout)
|
static Protocol::PacketInfo last_measure_packet; // contains the command that started the last measured (replay in case of timeout)
|
||||||
static TaskHandle_t handle;
|
static TaskHandle_t handle;
|
||||||
|
static bool sweepActive;
|
||||||
|
|
||||||
#if HW_REVISION >= 'B'
|
#if HW_REVISION >= 'B'
|
||||||
// has MCU controllable flash chip, firmware update supported
|
// has MCU controllable flash chip, firmware update supported
|
||||||
@ -45,7 +46,7 @@ static void USBPacketReceived(const Protocol::PacketInfo &p) {
|
|||||||
portYIELD_FROM_ISR(woken);
|
portYIELD_FROM_ISR(woken);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App_Start() {
|
inline void App_Init() {
|
||||||
STM::Init();
|
STM::Init();
|
||||||
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
|
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
|
||||||
handle = xTaskGetCurrentTaskHandle();
|
handle = xTaskGetCurrentTaskHandle();
|
||||||
@ -98,10 +99,13 @@ void App_Start() {
|
|||||||
USB_EN_GPIO_Port->BSRR = USB_EN_Pin;
|
USB_EN_GPIO_Port->BSRR = USB_EN_Pin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool sweepActive = false;
|
|
||||||
|
|
||||||
LED::Off();
|
LED::Off();
|
||||||
while (1) {
|
|
||||||
|
sweepActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void App_Process() {
|
||||||
|
while(1) {
|
||||||
uint32_t notification;
|
uint32_t notification;
|
||||||
if(xTaskNotifyWait(0x00, UINT32_MAX, ¬ification, 100) == pdPASS) {
|
if(xTaskNotifyWait(0x00, UINT32_MAX, ¬ification, 100) == pdPASS) {
|
||||||
// something happened
|
// something happened
|
||||||
@ -153,7 +157,7 @@ void App_Start() {
|
|||||||
sweepActive = false;
|
sweepActive = false;
|
||||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||||
break;
|
break;
|
||||||
#ifdef HAS_FLASH
|
#ifdef HAS_FLASH
|
||||||
case Protocol::PacketType::ClearFlash:
|
case Protocol::PacketType::ClearFlash:
|
||||||
HW::SetMode(HW::Mode::Idle);
|
HW::SetMode(HW::Mode::Idle);
|
||||||
sweepActive = false;
|
sweepActive = false;
|
||||||
@ -188,7 +192,7 @@ void App_Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case Protocol::PacketType::RequestSourceCal:
|
case Protocol::PacketType::RequestSourceCal:
|
||||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||||
Cal::SendSource();
|
Cal::SendSource();
|
||||||
@ -232,3 +236,8 @@ void App_Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App_Start() {
|
||||||
|
App_Init();
|
||||||
|
App_Process();
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#if HW_REVISION == 'B'
|
#if HW_REVISION == 'B'
|
||||||
|
|
||||||
#define LED_TASK_STACK 128
|
#define LED_STATUS_TASK_STACK_SIZE_WORDS 128
|
||||||
|
|
||||||
extern TIM_HandleTypeDef htim2;
|
extern TIM_HandleTypeDef htim2;
|
||||||
|
|
||||||
@ -21,9 +21,11 @@ enum class Mode {
|
|||||||
static Mode mode;
|
static Mode mode;
|
||||||
static uint8_t led_statecnt;
|
static uint8_t led_statecnt;
|
||||||
static int8_t led_ncnt;
|
static int8_t led_ncnt;
|
||||||
static xTaskHandle task;
|
|
||||||
static StaticTask_t xTask;
|
static StackType_t LedStatusStack[LED_STATUS_TASK_STACK_SIZE_WORDS];
|
||||||
static StackType_t xStack[LED_TASK_STACK];
|
static StaticTask_t LedStatusCB;
|
||||||
|
static xTaskHandle LedStatusHandle = NULL;
|
||||||
|
|
||||||
static uint8_t err_cnt;
|
static uint8_t err_cnt;
|
||||||
|
|
||||||
static void led_set_percentage(uint8_t val) {
|
static void led_set_percentage(uint8_t val) {
|
||||||
@ -31,8 +33,8 @@ static void led_set_percentage(uint8_t val) {
|
|||||||
TIM2->CCR1 = compare;
|
TIM2->CCR1 = compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void led_task(void* unused) {
|
static void LedStatus(void * const argument) {
|
||||||
UNUSED(unused);
|
UNUSED(argument);
|
||||||
while (1) {
|
while (1) {
|
||||||
if (led_statecnt < 199) {
|
if (led_statecnt < 199) {
|
||||||
led_statecnt++;
|
led_statecnt++;
|
||||||
@ -88,9 +90,10 @@ void LED::Init() {
|
|||||||
HAL_TIM_Base_Start(&htim2);
|
HAL_TIM_Base_Start(&htim2);
|
||||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
|
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
|
||||||
|
|
||||||
task = xTaskCreateStatic(led_task, "LED",
|
LedStatusHandle = xTaskCreateStatic(LedStatus, "LedStatusTask", LED_STATUS_TASK_STACK_SIZE_WORDS,
|
||||||
LED_TASK_STACK, NULL, 6, xStack, &xTask);
|
NULL, 6, LedStatusStack, &LedStatusCB);
|
||||||
vTaskSuspend(task);
|
|
||||||
|
vTaskSuspend(LedStatusHandle);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +102,9 @@ void LED::Pulsating() {
|
|||||||
if(led_ncnt) {
|
if(led_ncnt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vTaskSuspend(task);
|
vTaskSuspend(LedStatusHandle);
|
||||||
mode = Mode::Pulsating;
|
mode = Mode::Pulsating;
|
||||||
vTaskResume(task);
|
vTaskResume(LedStatusHandle);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,9 +113,9 @@ void LED::Off() {
|
|||||||
if(led_ncnt) {
|
if(led_ncnt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vTaskSuspend(task);
|
vTaskSuspend(LedStatusHandle);
|
||||||
mode = Mode::Off;
|
mode = Mode::Off;
|
||||||
vTaskResume(task);
|
vTaskResume(LedStatusHandle);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +124,11 @@ void LED::Error(uint8_t code) {
|
|||||||
if(led_ncnt) {
|
if(led_ncnt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vTaskSuspend(task);
|
vTaskSuspend(LedStatusHandle);
|
||||||
mode = Mode::Error;
|
mode = Mode::Error;
|
||||||
led_statecnt = 0;
|
led_statecnt = 0;
|
||||||
err_cnt = 0;
|
err_cnt = 0;
|
||||||
led_ncnt = code;
|
led_ncnt = code;
|
||||||
vTaskResume(task);
|
vTaskResume(LedStatusHandle);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user