aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-06-05 20:28:32 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-06-05 20:28:32 +0200
commit97a104555de59091124a854cad3a5a4ff6bd285b (patch)
treef3f0bcb9cdcaa908bc3384da1759bef6998acf40
parentff3d9f84a14ca5c2d4c44bf946b0f0def8abe6b6 (diff)
downloadglutte-o-matic-97a104555de59091124a854cad3a5a4ff6bd285b.tar.gz
glutte-o-matic-97a104555de59091124a854cad3a5a4ff6bd285b.tar.bz2
glutte-o-matic-97a104555de59091124a854cad3a5a4ff6bd285b.zip
Fix USART concurrency, create common usart object
-rw-r--r--src/common/includes/GPIO/usart.h10
-rw-r--r--src/common/sourcelist.txt1
-rw-r--r--src/common/src/GPIO/usart.c5
-rw-r--r--src/glutt-o-logique/Makefile6
-rw-r--r--src/glutt-o-logique/cw.c4
-rw-r--r--src/glutt-o-logique/fsm.c4
-rw-r--r--src/glutt-o-logique/usart.c5
-rw-r--r--src/simulator/Makefile4
-rw-r--r--src/simulator/src/Core/fsm.c4
-rw-r--r--src/simulator/src/GPIO/usart.c16
10 files changed, 29 insertions, 30 deletions
diff --git a/src/common/includes/GPIO/usart.h b/src/common/includes/GPIO/usart.h
index 21936d7..0ad1034 100644
--- a/src/common/includes/GPIO/usart.h
+++ b/src/common/includes/GPIO/usart.h
@@ -31,6 +31,14 @@
#ifndef __USART_H_
#define __USART_H_
+#ifdef STM32F4XX
+# include <stm32f4xx_usart.h>
+#else
+# define USART_TypeDef int
+# define USART2 ((USART_TypeDef*)2)
+# define USART3 ((USART_TypeDef*)3)
+#endif
+
#define MAX_NMEA_SENTENCE_LEN 256
// Initialise USART2 for PC debugging
@@ -48,7 +56,7 @@ void usart_debug(const char *format, ...);
// Send a string to the PC
void usart_debug_puts(const char* str);
-void usart_debug_puts_no_header(const char* str);
+void usart_debug_puts_header(const char* hdr, const char* str);
// Get a MAX_NMEA_SENTENCE_LEN sized NMEA sentence
// Return 1 on success
diff --git a/src/common/sourcelist.txt b/src/common/sourcelist.txt
new file mode 100644
index 0000000..a8602d6
--- /dev/null
+++ b/src/common/sourcelist.txt
@@ -0,0 +1 @@
+src/GPIO/usart.c
diff --git a/src/common/src/GPIO/usart.c b/src/common/src/GPIO/usart.c
index cf7e517..b96fa27 100644
--- a/src/common/src/GPIO/usart.c
+++ b/src/common/src/GPIO/usart.c
@@ -104,9 +104,12 @@ void usart_debug_puts(const char* str) {
xTaskResumeAll();
}
-void usart_debug_puts_no_header(const char* str) {
+void usart_debug_puts_header(const char* hdr, const char* str) {
vTaskSuspendAll();
+ usart_debug_timestamp();
+ usart_puts(USART2, hdr);
usart_puts(USART2, str);
+ usart_puts(USART2, "\r\n");
xTaskResumeAll();
}
diff --git a/src/glutt-o-logique/Makefile b/src/glutt-o-logique/Makefile
index 2fd5f91..4f0aa14 100644
--- a/src/glutt-o-logique/Makefile
+++ b/src/glutt-o-logique/Makefile
@@ -17,8 +17,12 @@ ASOURCES=$(shell find -L $(SRCDIR) -name '*.s')
CSOURCES+=$(shell find -L $(SRCDIR) -name '*.c')
HEADERS=$(shell find -L $(SRCDIR) -name '*.h')
+COMMON_DIR=../common
+COMMON_SOURCE_LIST=$(shell cat ../common/sourcelist.txt)
+CSOURCES+=$(COMMON_SOURCE_LIST:%.c=../common/%.c)
+
INC=$(shell find -L $(SRCDIR) -name '*.h' -exec dirname {} \; | uniq)
-INC+=../common/includes
+INC+=$(COMMON_DIR)/includes
INCLUDES=$(INC:%=-I%)
# Create object list
diff --git a/src/glutt-o-logique/cw.c b/src/glutt-o-logique/cw.c
index 36e5654..a54ca83 100644
--- a/src/glutt-o-logique/cw.c
+++ b/src/glutt-o-logique/cw.c
@@ -27,8 +27,6 @@
// Function to display message in GUI, unused on STM32 firmware
void cw_message_sent(const char* str) {
- usart_debug_puts("CW: ");
- usart_debug_puts(str);
- usart_debug_puts("\r\n");
+ usart_debug_puts_header("CW: ", str);
}
diff --git a/src/glutt-o-logique/fsm.c b/src/glutt-o-logique/fsm.c
index aed633b..edc6f6f 100644
--- a/src/glutt-o-logique/fsm.c
+++ b/src/glutt-o-logique/fsm.c
@@ -26,8 +26,6 @@
#include "GPIO/usart.h"
void fsm_state_switched(char * new_state) {
- usart_debug_puts("FSM: ");
- usart_debug_puts(new_state);
- usart_debug_puts("\r\n");
+ usart_debug_puts_header("FSM: ", new_state);
}
diff --git a/src/glutt-o-logique/usart.c b/src/glutt-o-logique/usart.c
index 4c5869d..4bef27a 100644
--- a/src/glutt-o-logique/usart.c
+++ b/src/glutt-o-logique/usart.c
@@ -36,10 +36,7 @@ const uint16_t GPIOD_PIN_USART3_RX = GPIO_Pin_9;
const uint16_t GPIOA_PIN_USART2_RX = GPIO_Pin_3;
const uint16_t GPIOA_PIN_USART2_TX = GPIO_Pin_2;
-static void usart_puts(USART_TypeDef*, const char*);
-
#include "../common/includes/GPIO/usart.h"
-#include "../common/src/GPIO/usart.c"
void usart_init() {
@@ -132,7 +129,7 @@ void usart_gps_specific_init() {
}
// Make sure Tasks are suspended when this is called!
-static void usart_puts(USART_TypeDef* USART, const char* str) {
+void usart_puts(USART_TypeDef* USART, const char* str) {
while(*str) {
// wait until data register is empty
USART_SendData(USART, *str);
diff --git a/src/simulator/Makefile b/src/simulator/Makefile
index 663570e..484ddda 100644
--- a/src/simulator/Makefile
+++ b/src/simulator/Makefile
@@ -31,6 +31,10 @@ C_FILES += timers.c
C_FILES += heap_3.c
C_FILES += port.c
+# common Objects
+COMMON_SOURCE_LIST=$(shell cat ../common/sourcelist.txt)
+C_FILES+=$(COMMON_SOURCE_LIST:%.c=../common/%.c)
+
# Main Object
SRC_SOURCES+=$(shell find -L src/ -name '*.c')
C_FILES += $(SRC_SOURCES)
diff --git a/src/simulator/src/Core/fsm.c b/src/simulator/src/Core/fsm.c
index 6f771c2..4c52525 100644
--- a/src/simulator/src/Core/fsm.c
+++ b/src/simulator/src/Core/fsm.c
@@ -6,9 +6,7 @@ extern int * gui_last_fsm_states_timestamps[];
void fsm_state_switched(char * new_state) {
- usart_debug_puts("FSM: ");
- usart_debug_puts_no_header(new_state);
- usart_debug_puts_no_header("\r\n");
+ usart_debug_puts_header("FSM: ", new_state);
for (int i = 8; i >= 0; i--) {
gui_last_fsm_states[i + 1] = gui_last_fsm_states[i];
diff --git a/src/simulator/src/GPIO/usart.c b/src/simulator/src/GPIO/usart.c
index 650602a..37822d6 100644
--- a/src/simulator/src/GPIO/usart.c
+++ b/src/simulator/src/GPIO/usart.c
@@ -23,19 +23,7 @@
*/
-#define USART_TypeDef int
-
-int _USART2 = 2;
-int _USART3 = 3;
-
-#define USART2 &_USART2
-#define USART3 &_USART3
-
-static void usart_puts(USART_TypeDef*, const char*);
-
#include "../../../common/includes/GPIO/usart.h"
-#include "../../../common/src/GPIO/usart.c"
-
extern char uart_recv_txt[4096];
int uart_recv_pointer = 0;
@@ -68,9 +56,9 @@ void usart_move_buffer_up() {
}
// Make sure Tasks are suspended when this is called!
-static void usart_puts(USART_TypeDef* USART, const char* str) {
+void usart_puts(USART_TypeDef* USART, const char* str) {
- if (*USART == _USART2) {
+ if (USART == USART2) {
while(*str) {
if (*str != '\r') {
uart_recv_txt[uart_recv_pointer+1] = '\0';