Systick configuration and timeout keeper for uart

pull/2/head
Mateusz Lubecki 2019-01-13 21:55:09 +01:00
rodzic cb3b311b7b
commit 10ed67f325
6 zmienionych plików z 80 dodań i 76 usunięć

Wyświetl plik

@ -13,7 +13,6 @@ C_SRCS += \
CPP_SRCS += \
../src/BlinkLed.cpp \
../src/Timer.cpp \
../src/main.cpp
OBJS += \
@ -21,7 +20,6 @@ OBJS += \
./src/KissCommunication.o \
./src/LedConfig.o \
./src/PathConfig.o \
./src/Timer.o \
./src/TimerConfig.o \
./src/_write.o \
./src/it_handlers.o \
@ -37,7 +35,6 @@ C_DEPS += \
CPP_DEPS += \
./src/BlinkLed.d \
./src/Timer.d \
./src/main.d

Wyświetl plik

@ -3,6 +3,8 @@
#include "aprs/ax25.h"
extern uint32_t master_time;
extern AX25Ctx ax25;
extern Afsk a;

Wyświetl plik

@ -10,6 +10,7 @@
#include "drivers/tx20.h"
#include "drivers/ms5611.h"
#include "drivers/_dht22.h"
#include "drivers/serial.h"
#include "aprs/wx.h"
#include "aprs/telemetry.h"
#include "aprs/beacon.h"
@ -28,6 +29,13 @@ char adc_sample_count = 0, adc_sample_c2 = 0; // Zmienna odliczająca próbki
unsigned short int AdcBuffer[4]; // Bufor przechowujący kolejne wartości rejestru DR
short int AdcValue;
// Systick interrupt used for time measurements, checking timeouts andSysTick_Handler
void SysTick_Handler(void) {
master_time++;
srl_keep_timeout();
}
void USART1_IRQHandler(void) {
NVIC_ClearPendingIRQ(USART1_IRQn);
srl_irq_handler();

Wyświetl plik

@ -22,8 +22,8 @@
#include "aprs/beacon.h"
#include "Timer.h"
#include "BlinkLed.h"
//#include "Timer.h"
//#include "BlinkLed.h"
#ifdef _METEO
#include "drivers/dallas.h"
@ -55,18 +55,23 @@
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wempty-body"
// global variable incremented by the SysTick handler to measure time
uint32_t master_time = 0;
// global variables represending the AX25/APRS stack
AX25Ctx ax25;
Afsk a;
// global variable used to store return value from various functions
volatile uint8_t retval = 100;
AX25Call path[3];
uint8_t path_len = 0;
uint8_t aprs_msg_len;
char aprs_msg[128];
// global variable used to store return value from various functions
volatile uint8_t retval = 100;
char after_tx_lock;
unsigned char BcnInterval, WXInterval, BcnI = _BCN_INTERVAL - 2, WXI = _WX_INTERVAL - 1, TelemInterval, TelemI = 1;
@ -98,6 +103,12 @@ main(int argc, char* argv[])
memset(aprs_msg, 0x00, 128);
// choosing the signal source for the SysTick timer.
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
// Configuring the SysTick timer to generate interrupt 100x per second (one interrupt = 10ms)
SysTick_Config(SystemCoreClock / 100);
path_len = ConfigPath(path);
#ifdef _METEO

Wyświetl plik

@ -9,6 +9,8 @@
#define SEPARATE_RX_BUFF
#define SEPARATE_TX_BUFF
#define SRL_RX_TIMEOUT_IN_MS 1000
typedef enum srlRxState {
SRL_RX_NOT_CONFIG,
SRL_RX_IDLE,
@ -46,7 +48,8 @@ uint8_t srl_start_tx(short leng);
void srl_irq_handler(void);
uint8_t srl_receive_data(int num, char start, char stop, char echo, char len_addr, char len_modifier);
uint8_t* srl_get_rx_buffer();
void srl_keep_timeout();
void srl_keep_timeout(void);
void srl_switch_timeout(uint8_t disable_enable);
#ifdef __cplusplus
}

Wyświetl plik

@ -8,6 +8,8 @@
#include "station_config.h"
#include "diag/Trace.h"
#include "main.h" // global_time is here
#include <string.h>
int srlBRRegValue = 0x09C4 ; // dla symulacji ---- baudrate 9600bps
@ -41,6 +43,10 @@ uint8_t srl_stop_trigger = 0x00; // znak oznaczaj<61>cy koniec istotnych danyc
volatile uint8_t srl_garbage_storage;
uint8_t srl_rx_timeout_enable = 0;
uint8_t srl_rx_timeout_calc_started = 0;
uint32_t srl_rx_start_time = 0;
srlRxState srl_rx_state = SRL_RX_NOT_CONFIG;
srlTxState srl_tx_state = SRL_TX_NOT_CONFIG;
@ -49,8 +55,6 @@ uint8_t srl_enable_echo = 0;
uint8_t srl_rx_lenght_param_addres = 0;
uint8_t srl_rx_lenght_param_modifier = 0;
//char srlLenAddr = 0;
//char srlLenModif = 0;
void srl_init(void) {
#ifdef SEPARATE_TX_BUFF
@ -95,6 +99,38 @@ void srl_init(void) {
srl_tx_state = SRL_TX_IDLE;
}
// this function shall be called in 10ms periods by some timer to check the timeout
// during receive. This method works differently depends on what receive mode was initiaded
//
// if start & stop characters are in use the timeout will be calculted from the time when
// start character was received and operation mode has been switched from SRL_WAITING_TO_RX
// to SRL_RXING
//
// if no start & stop character is used by software timeout is calculated from the time when
// first character was received after calling srl_receive_data
void srl_keep_timeout() {
if (srl_rx_state != SRL_RX_NOT_CONFIG && srl_rx_timeout_enable == 1) {
// checking if flag to check a timeout is raised
if (srl_rx_timeout_calc_started == 1) {
// check if timeout expired
if (master_time - srl_rx_start_time > SRL_RX_TIMEOUT_IN_MS) {
// disable the receiving part of UART, disable interrupt and switch to an error state
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_RE);
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_RXNEIE);
srl_rx_state = SRL_RX_ERROR;
}
}
}
else {
;
}
}
uint8_t srl_send_data(uint8_t* data, uint8_t mode, uint16_t leng, uint8_t internal_external) {
if (srl_tx_state == SRL_TXING)
return SRL_BUSY;
@ -273,6 +309,9 @@ void srl_irq_handler(void) {
switch (srl_rx_state) {
case SRL_RXING: {
// raise a flag to signalize that timeout shall be calulated from now.
srl_rx_timeout_calc_started = 1;
// if there is any data remaining to receive
if (srl_rx_bytes_counter < srl_rx_bytes_req) {
@ -320,6 +359,9 @@ void srl_irq_handler(void) {
}
if (stop_rxing == 1) {
srl_rx_timeout_calc_started = 0;
// disabling UART receiver and its interrupt
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_RE);
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_RXNEIE);
@ -378,75 +420,16 @@ void srl_irq_handler(void) {
}
}
/*
if ((PORT->SR & USART_SR_TXE) == USART_SR_TXE && srlTXing == 1) {
if(srlTXQueueLen == 1 || srlTRXDataCounter + 1 == srlTXQueueLen) {
while((PORT->SR & USART_SR_TC) != USART_SR_TC);
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_TE); //wyġṗczanie nadajnika portu szeregowego
srlTXing = 0;
srlIdle = 1;
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_TXEIE);
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_TCIE); // wyġṗczanie przerwañ od portu szeregowego
srlTRXDataCounter = 0;
PORT->SR &= (0xFFFFFFFF ^ USART_SR_TC);
}
else {
srlTRXDataCounter++;
PORT->DR = srl_tx_buf_pointer[srlTRXDataCounter]; // wczytywanie do DR nastêpnego bajtu do transmisji
}
}
if ((PORT->SR & USART_SR_RXNE) == USART_SR_RXNE && srlIdle == 0) {
uint8_t data = ((uint8_t)PORT->DR & 0xFF);
if ((data == srlStartChar) && srlRXing == 0)
// Jeṡeli zlecono odbiór danych sprawdza czy odebrany bajt jest pierwszym bajtem znaczṗcym
srlRXing = 1, srlStartStopS = 1; // Jeṡeli zostaġ odebrany to ustaw flagê odbioru ṡeby umoṡliwiæ kopiowanie do bufora
else if (srlRXing == 0) {
srlRxDummy = data; // jeṡeli bajt nie byġ znaczṗcy to go usuñ
if (srlEchoOn == 1) {
PORT->CR1 |= USART_CR1_TE;
PORT->SR &= (0xFFFFFFFF ^ USART_SR_TC);
PORT->DR = srlRxDummy;
}
else {
}
}
else {
}
if (srlRXing == 1) {
srl_rx_buf_pointer[srlTRXDataCounter] = data; // przenoszenie pierwszego odebranego bajtu
if (srlEchoOn == 1) {
PORT->CR1 |= USART_CR1_TE;
PORT->SR &= (0xFFFFFFFF ^ USART_SR_TC);
PORT->DR = srl_rx_buf_pointer[srlTRXDataCounter];
}
if ((srlRXBytesNum == srlTRXDataCounter + 1) || (srl_rx_buf_pointer[srlTRXDataCounter] == srlStopChar && srlStartStopS == 0)) {
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_RE); // wyġṗczanie odbiornika po odbiorze ostatniego bajtu
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_RXNEIE);
// PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_IDLEIE); // wyġṗczanie przerwañ
srlRXing = 0;
srlTRXDataCounter++;
srl_rx_buf_pointer[srlTRXDataCounter] = '\0';
srlTRXDataCounter = 0;
srlIdle = 1;
}
srlTRXDataCounter++;
}
else {
}
srlStartStopS = 0;
}
if ((PORT->SR & USART_SR_IDLE) == USART_SR_IDLE && srlRXing == 1) {
}
*/
}
uint8_t* srl_get_rx_buffer() {
return srl_rx_buf_pointer;
}
void srl_keep_timeout() {
void srl_switch_timeout(uint8_t disable_enable) {
if (disable_enable == 1)
srl_rx_timeout_enable = 1;
else if (disable_enable == 0)
srl_rx_timeout_enable = 0;
else;
}