diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-05-30 19:40:13 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-05-30 19:40:13 +0200 |
commit | 2f71862ddd434a4bd17fc92b9ad147658671fe9c (patch) | |
tree | 64f18a346c68dbf6338e66cda7ffd9db3212050d /src | |
parent | a08c05b2007051c850507f5f0567d87bd965f917 (diff) | |
download | glutte-o-matic-2f71862ddd434a4bd17fc92b9ad147658671fe9c.tar.gz glutte-o-matic-2f71862ddd434a4bd17fc92b9ad147658671fe9c.tar.bz2 glutte-o-matic-2f71862ddd434a4bd17fc92b9ad147658671fe9c.zip |
Add more USART debug prints
Diffstat (limited to 'src')
-rw-r--r-- | src/fsm/fsm.c | 37 | ||||
-rw-r--r-- | src/fsm/fsm.h | 2 | ||||
-rw-r--r-- | src/fsm/main.c | 9 | ||||
-rw-r--r-- | src/fsm/usart.c | 39 |
4 files changed, 82 insertions, 5 deletions
diff --git a/src/fsm/fsm.c b/src/fsm/fsm.c index 9c761e3..0c8cbed 100644 --- a/src/fsm/fsm.c +++ b/src/fsm/fsm.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015 Matthias P. Braendli + * Copyright (c) 2016 Matthias P. Braendli * * 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 <string.h> #include "common.h" #include "fsm.h" +#include "usart.h" static struct fsm_input_signals_t fsm_in; static struct fsm_output_signals_t fsm_out; @@ -359,6 +360,40 @@ void fsm_update() { if (next_state != current_state) { timestamp_state[next_state] = timestamp_now(); + switch (next_state) { + case FSM_OISIF: + usart_debug_puts("FSM: FSM_OISIF\r\n"); break; + case FSM_OPEN1: + usart_debug_puts("FSM: FSM_OPEN1\r\n"); break; + case FSM_OPEN2: + usart_debug_puts("FSM: FSM_OPEN2\r\n"); break; + case FSM_LETTRE: + usart_debug_puts("FSM: FSM_LETTRE\r\n"); break; + case FSM_ECOUTE: + usart_debug_puts("FSM: FSM_ECOUTE\r\n"); break; + case FSM_ATTENTE: + usart_debug_puts("FSM: FSM_ATTENTE\r\n"); break; + case FSM_QSO: + usart_debug_puts("FSM: FSM_QSO\r\n"); break; + case FSM_ANTI_BAVARD: + usart_debug_puts("FSM: FSM_ANTI_BAVARD\r\n"); break; + case FSM_BLOQUE: + usart_debug_puts("FSM: FSM_BLOQUE\r\n"); break; + case FSM_TEXTE_73: + usart_debug_puts("FSM: FSM_TEXTE_73\r\n"); break; + case FSM_TEXTE_HB9G: + usart_debug_puts("FSM: FSM_TEXTE_HB9G\r\n"); break; + case FSM_TEXTE_LONG: + usart_debug_puts("FSM: FSM_TEXTE_LONG\r\n"); break; + case FSM_BALISE_LONGUE: + usart_debug_puts("FSM: FSM_BALISE_LONGUE\r\n"); break; + case FSM_BALISE_SPECIALE: + usart_debug_puts("FSM: FSM_BALISE_SPECIALE\r\n"); break; + case FSM_BALISE_COURTE: + usart_debug_puts("FSM: FSM_BALISE_COURTE\r\n"); break; + default: + usart_debug_puts("FSM: ERROR!\r\n"); break; + } } current_state = next_state; } diff --git a/src/fsm/fsm.h b/src/fsm/fsm.h index 690fc2e..41f0503 100644 --- a/src/fsm/fsm.h +++ b/src/fsm/fsm.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015 Matthias P. Braendli + * Copyright (c) 2016 Matthias P. Braendli * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/fsm/main.c b/src/fsm/main.c index 3fe5de1..4abe610 100644 --- a/src/fsm/main.c +++ b/src/fsm/main.c @@ -88,7 +88,7 @@ int main(void) { TaskHandle_t task_handle; xTaskCreate( launcher_task, - "TaskLauncher", + "Launcher", configMINIMAL_STACK_SIZE, (void*) NULL, tskIDLE_PRIORITY + 2UL, @@ -324,6 +324,7 @@ static void exercise_fsm(void *pvParameters) int last_sq = 0; int last_1750 = 0; int last_qrp = 0; + int last_cw_done = 0; fsm_input.humidity = 0; fsm_input.temp = 15; @@ -360,6 +361,10 @@ static void exercise_fsm(void *pvParameters) last_tm_trigger = tm_trigger; fsm_input.cw_psk31_done = !cw_psk31_busy(); + if (last_cw_done != fsm_input.cw_psk31_done) { + last_cw_done = fsm_input.cw_psk31_done; + usart_debug("In CW done %d\r\n", last_cw_done); + } if (fsm_input.cw_psk31_done) { GPIO_ResetBits(GPIOD, GPIOD_BOARD_LED_ORANGE); @@ -381,6 +386,8 @@ static void exercise_fsm(void *pvParameters) // Add message to CW generator only on rising edge of trigger if (fsm_out.cw_psk31_trigger && !cw_last_trigger) { cw_psk31_push_message(fsm_out.msg, fsm_out.cw_dit_duration, fsm_out.msg_frequency); + + usart_debug_puts("Out CW trigger\r\n"); } cw_last_trigger = fsm_out.cw_psk31_trigger; diff --git a/src/fsm/usart.c b/src/fsm/usart.c index 5dff116..a1a5ab2 100644 --- a/src/fsm/usart.c +++ b/src/fsm/usart.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <stdarg.h> #include <string.h> +#include <inttypes.h> #include "common.h" #include "usart.h" #include <stm32f4xx.h> @@ -146,38 +147,72 @@ void usart_gps_init() USART_Cmd(USART3, ENABLE); } +// Make sure Tasks are suspended when this is called! static void usart_puts(USART_TypeDef* USART, const char* str) { - vTaskSuspendAll(); while(*str) { // wait until data register is empty USART_SendData(USART, *str); while(USART_GetFlagStatus(USART, USART_FLAG_TXE) == RESET) ; str++; } - xTaskResumeAll(); } void usart_gps_puts(const char* str) { + vTaskSuspendAll(); return usart_puts(USART3, str); + xTaskResumeAll(); } #define MAX_MSG_LEN 80 static char usart_debug_message[MAX_MSG_LEN]; +void usart_debug_timestamp() +{ + // Don't call printf here, to reduce stack usage + uint64_t now = timestamp_now(); + if (now == 0) { + usart_puts(USART2, "[0] "); + } + else { + char ts_str[64]; + int i = 63; + + ts_str[i--] = '\0'; + ts_str[i--] = ' '; + ts_str[i--] = ']'; + + while (now > 0 && i >= 0) { + ts_str[i--] = '0' + (now % 10); + now /= 10; + } + ts_str[i] = '['; + + usart_puts(USART2, &ts_str[i]); + } +} + void usart_debug(const char *format, ...) { va_list list; va_start(list, format); vsnprintf(usart_debug_message, MAX_MSG_LEN-1, format, list); + + vTaskSuspendAll(); + usart_debug_timestamp(); usart_puts(USART2, usart_debug_message); + xTaskResumeAll(); + va_end(list); } void usart_debug_puts(const char* str) { + vTaskSuspendAll(); + usart_debug_timestamp(); usart_puts(USART2, str); + xTaskResumeAll(); } int usart_get_nmea_sentence(char* nmea) |