diff options
Diffstat (limited to 'src/common/Core/main.c')
-rw-r--r-- | src/common/Core/main.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/common/Core/main.c b/src/common/Core/main.c index 54cee12..1321517 100644 --- a/src/common/Core/main.c +++ b/src/common/Core/main.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony + * Copyright (c) 2020 Matthias P. Braendli, Maximilien Cuony * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,6 +25,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <string.h> #include <math.h> /* Kernel includes. */ @@ -85,6 +86,7 @@ void init(void); static void detect_button_press(void *pvParameters); static void exercise_fsm(void *pvParameters); static void nf_analyse(void *pvParameters); +static void read_in_coulomb_counter(void *pvParameters); static void gps_monit_task(void *pvParameters); static void launcher_task(void *pvParameters); @@ -233,6 +235,20 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters) trigger_fault(FAULT_SOURCE_MAIN); } + usart_debug_puts("TaskCC init\r\n"); + + xTaskCreate( + read_in_coulomb_counter, + "TaskCC", + 2*configMINIMAL_STACK_SIZE, + (void*) NULL, + tskIDLE_PRIORITY + 3UL, + &task_handle); + + if (!task_handle) { + trigger_fault(FAULT_SOURCE_MAIN); + } + usart_debug_puts("Init done.\r\n"); int last_qrp_from_supply = 0; @@ -698,6 +714,28 @@ static void nf_analyse(void __attribute__ ((unused))*pvParameters) } } +static char ccounter_msg[MAX_CCOUNTER_SENTENCE_LEN]; +static void read_in_coulomb_counter(void __attribute__ ((unused))*pvParameters) +{ + while (1) { + int ok = usart_get_ccounter_msg(ccounter_msg); + if (ok) { + size_t len = strlen(ccounter_msg); + /* Ignore if \n follows \r or not, as that should never happen, and in any case + * we don't want to send the \r or whatever could come after + */ + if (len > 2 && ccounter_msg[len-2] == '\r') { + ccounter_msg[len-2] = '\0'; + } + usart_debug_puts_header("CC:", ccounter_msg); + } + else { + usart_debug_puts("WARNING: Read from ccounter queue failed\r\n"); + vTaskDelay(5000 / portTICK_PERIOD_MS); + } + } +} + #if configGENERATE_RUN_TIME_STATS #include "stm32f4xx_conf.h" #include "stm32f4xx_tim.h" |