From 19aee79e5758d078d3d6f739a6620ced256263b3 Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Tue, 23 Jun 2020 19:53:35 +0200 Subject: [PATCH] Minor visual arrangements --- Inc/config.h | 2 +- Inc/defines.h | 3 ++- Inc/util.h | 54 ++++++++++++++++----------------------------------- Src/i2c_it.c | 22 ++++++++++++++++++++- Src/setup.c | 2 +- Src/util.c | 3 +-- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Inc/config.h b/Inc/config.h index 650fe68..f8d66c1 100644 --- a/Inc/config.h +++ b/Inc/config.h @@ -69,8 +69,8 @@ #endif #define USART_MAIN_BAUD 38400 // [bit/s] MAIN Serial Tx/Rx baud rate #define SERIAL_START_FRAME 0xABCD // [-] Start frame definition for reliable serial communication -#define SERIAL_TIMEOUT 500 // [-] Number of wrong received data for Serial timeout detection. Depends on DELAY_IN_MAIN_LOOP #define SERIAL_BUFFER_SIZE 64 // [bytes] Size of Serial Rx buffer. Make sure it is always larger than the 'Feedback' structure size +#define SERIAL_TIMEOUT 600 // [-] Number of wrong received data for Serial timeout detection. Depends on DELAY_IN_MAIN_LOOP /* ==================================== SETTINGS AUX ==================================== */ diff --git a/Inc/defines.h b/Inc/defines.h index f6b66f4..203ed0b 100644 --- a/Inc/defines.h +++ b/Inc/defines.h @@ -25,6 +25,7 @@ // Includes #include "gd32f1x0.h" #include "config.h" +#include "util.h" #if defined(PRINTF_FLOAT_SUPPORT) && defined(SERIAL_DEBUG) && defined(__GNUC__) asm(".global _printf_float"); // this is the magic trick for printf to support float. Warning: It will increase code considerably! Better to avoid! @@ -179,4 +180,4 @@ typedef struct { int16_t temp; } MPU_Data; -#endif +#endif // DEFINES_H diff --git a/Inc/util.h b/Inc/util.h index 9da9405..0bdea4f 100644 --- a/Inc/util.h +++ b/Inc/util.h @@ -22,45 +22,9 @@ #define UTIL_H #include -#include "gd32f1x0.h" -#include "defines.h" -extern volatile int8_t i2c_status; -extern volatile i2c_cmd i2c_ReadWriteCmd; -extern volatile uint8_t i2c_slaveAddress; -extern volatile uint8_t i2c_regAddress; -extern volatile uint8_t* i2c_txbuffer; -extern volatile uint8_t* i2c_rxbuffer; -extern volatile uint8_t i2c_nDABytes; -extern volatile int8_t i2c_nRABytes; - -#ifdef AUX45_USE_I2C -extern volatile int8_t i2c_aux_status; -extern volatile i2c_cmd i2c_aux_ReadWriteCmd; -extern volatile uint8_t i2c_aux_slaveAddress; -extern volatile uint8_t i2c_aux_regAddress; -extern volatile uint8_t* i2c_aux_txbuffer; -extern volatile uint8_t* i2c_aux_rxbuffer; -extern volatile uint8_t i2c_aux_nDABytes; -extern volatile int8_t i2c_aux_nRABytes; -#endif - -/* general functions */ -void consoleLog(char *message); -void toggle_led(uint32_t gpio_periph, uint32_t pin); -void intro_demo_led(uint32_t tDelay); - -/* input initialization function */ -void input_init(void); - -/* usart read functions */ -void usart_rx_check(void); - -#ifdef SERIAL_DEBUG -void usart_process_debug(uint8_t *userCommand, uint32_t len); -#endif - +/* Rx Structures USART */ #ifdef SERIAL_CONTROL typedef struct{ uint16_t start; @@ -83,6 +47,22 @@ typedef struct{ uint16_t cmdLed; uint16_t checksum; } SerialFeedback; +#endif + +/* general functions */ +void consoleLog(char *message); +void toggle_led(uint32_t gpio_periph, uint32_t pin); +void intro_demo_led(uint32_t tDelay); + +/* input initialization function */ +void input_init(void); + +/* usart read functions */ +void usart_rx_check(void); +#ifdef SERIAL_DEBUG +void usart_process_debug(uint8_t *userCommand, uint32_t len); +#endif +#ifdef SERIAL_FEEDBACK void usart_process_data(SerialFeedback *Feedback_in, SerialFeedback *Feedback_out); #endif diff --git a/Src/i2c_it.c b/Src/i2c_it.c index b9f70f4..7b474a9 100644 --- a/Src/i2c_it.c +++ b/Src/i2c_it.c @@ -20,9 +20,29 @@ #include "gd32f1x0_i2c.h" #include "i2c_it.h" -#include "util.h" #include "systick.h" #include "config.h" +#include "defines.h" + +extern volatile int8_t i2c_status; +extern volatile i2c_cmd i2c_ReadWriteCmd; +extern volatile uint8_t i2c_slaveAddress; +extern volatile uint8_t i2c_regAddress; +extern volatile uint8_t* i2c_txbuffer; +extern volatile uint8_t* i2c_rxbuffer; +extern volatile uint8_t i2c_nDABytes; +extern volatile int8_t i2c_nRABytes; + +#ifdef AUX45_USE_I2C +extern volatile int8_t i2c_aux_status; +extern volatile i2c_cmd i2c_aux_ReadWriteCmd; +extern volatile uint8_t i2c_aux_slaveAddress; +extern volatile uint8_t i2c_aux_regAddress; +extern volatile uint8_t* i2c_aux_txbuffer; +extern volatile uint8_t* i2c_aux_rxbuffer; +extern volatile uint8_t i2c_aux_nDABytes; +extern volatile int8_t i2c_aux_nRABytes; +#endif void I2C0_EventIRQ_Handler(void) diff --git a/Src/setup.c b/Src/setup.c index 5bc4751..4a62826 100644 --- a/Src/setup.c +++ b/Src/setup.c @@ -26,7 +26,7 @@ #include "util.h" // Global variables -extern volatile ErrStatus status; + // Private variables static rcu_periph_enum USART_CLK[USARTn] = { USART_AUX_CLK, diff --git a/Src/util.c b/Src/util.c index 799b3ce..0f94169 100644 --- a/Src/util.c +++ b/Src/util.c @@ -36,6 +36,7 @@ SerialSideboard Sideboard; #if defined(SERIAL_DEBUG) || defined(SERIAL_FEEDBACK) static uint8_t rx_buffer[SERIAL_BUFFER_SIZE]; // USART Rx DMA circular buffer static uint32_t rx_buffer_len = ARRAY_LEN(rx_buffer); +static uint32_t old_pos; #endif #ifdef SERIAL_FEEDBACK @@ -178,7 +179,6 @@ void input_init(void) { void usart_rx_check(void) { #ifdef SERIAL_DEBUG - static uint32_t old_pos; uint32_t pos; pos = rx_buffer_len - dma_transfer_number_get(DMA_CH4); // Calculate current position in buffer @@ -199,7 +199,6 @@ void usart_rx_check(void) #endif // SERIAL_DEBUG #ifdef SERIAL_FEEDBACK - static uint32_t old_pos; uint32_t pos; uint8_t *ptr;