new context aware serial drivers tested with HW-RevA

pull/2/head
Mateusz Lubecki 2020-04-13 14:01:07 +02:00
rodzic 7b63ce16fe
commit 521aeb6686
7 zmienionych plików z 70 dodań i 36 usunięć

Wyświetl plik

@ -5,7 +5,7 @@
#include "drivers/serial.h"
#define SW_VER "DF00"
#define SW_DATE "11042020"
#define SW_DATE "13042020"
#define SYSTICK_TICKS_PER_SECONDS 100
#define SYSTICK_TICKS_PERIOD 10

Wyświetl plik

@ -58,8 +58,9 @@ void it_handlers_set_priorities(void) {
NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 6); // TX20 anemometer
NVIC_SetPriority(EXTI9_5_IRQn, 7); // TX20 anemometer
NVIC_SetPriority(EXTI4_IRQn, 8); // DHT22 humidity sensor
NVIC_SetPriority(USART1_IRQn, 9);
NVIC_SetPriority(I2C1_ER_IRQn, 10);
NVIC_SetPriority(USART2_IRQn, 9); // wx
NVIC_SetPriority(USART1_IRQn, 10); // kiss
NVIC_SetPriority(I2C1_ER_IRQn, 11);
}

Wyświetl plik

@ -112,6 +112,12 @@ srl_context_t* main_kiss_srl_ctx_ptr;
// a pointer to wx comms context
srl_context_t* main_wx_srl_ctx_ptr;
// target USART1 (kiss) baudrate
uint32_t main_target_kiss_baudrate;
// target USART2 (wx) baudrate
uint32_t main_target_wx_baudrate;
// global variables represending the AX25/APRS stack
AX25Ctx main_ax25;
Afsk main_afsk;
@ -234,15 +240,32 @@ main(int argc, char* argv[]){
#if defined(PARATNC_HWREV_A)
main_kiss_srl_ctx_ptr = &main_kiss_srl_ctx;
main_wx_srl_ctx_ptr = &main_kiss_srl_ctx;
main_target_kiss_baudrate = 9600u;
#if defined(_UMB_MASTER)
main_target_kiss_baudrate = _SERIAL_BAUDRATE;
#endif
#endif
#if defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)
main_kiss_srl_ctx_ptr = &main_kiss_srl_ctx;
main_wx_srl_ctx_ptr = &main_wx_srl_ctx;
main_target_kiss_baudrate = 9600u;
main_target_wx_baudrate = _SERIAL_BAUDRATE;
#endif
// initializing UART drvier
srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN);
srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN);
srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate);
srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate);
#if defined(PARATNC_HWREV_A) || defined(PARATNC_HWREV_B)
main_wx_srl_ctx_ptr->te_pin = GPIO_Pin_7;
main_wx_srl_ctx_ptr->te_port = GPIOA;
#endif
#if defined(PARATNC_HWREV_C)
main_wx_srl_ctx_ptr->te_pin = GPIO_Pin_8;
main_wx_srl_ctx_ptr->te_port = GPIOA;
#endif
// configuring an APRS path used to transmit own packets (telemetry, wx, beacons)
main_own_path_ln = ConfigPath(main_own_path);
@ -287,7 +310,7 @@ main(int argc, char* argv[]){
#undef _ANEMOMETER_ANALOGUE
// client initialization
umb_master_init(main_wx_srl_ctx_ptr, &rte_wx_umb_context);
umb_master_init(&rte_wx_umb_context, main_wx_srl_ctx_ptr);
#endif
#ifdef _ANEMOMETER_TX20
@ -343,12 +366,12 @@ main(int argc, char* argv[]){
retval = srl_start_tx(main_kiss_srl_ctx_ptr, ln);
#ifdef SERIAL_TX_TEST_MODE
while(srl_tx_state != SRL_TX_IDLE);
while(main_kiss_srl_ctx_ptr->srl_tx_state != SRL_TX_IDLE);
// while(srl_rx_state != SRL_RX_DONE);
GPIOC->ODR = (GPIOC->ODR ^ GPIO_Pin_9);
if (srl_rx_state == SRL_RX_DONE) {
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_DONE) {
GPIOC->ODR = (GPIOC->ODR ^ GPIO_Pin_8);
retval = 200;
@ -493,19 +516,19 @@ main(int argc, char* argv[]){
}
#else
// if new KISS message has been received from the host
if (srl_rx_state == SRL_RX_DONE) {
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_DONE) {
// parse incoming data and then transmit on radio freq
short res = ParseReceivedKISS(srl_get_rx_buffer(), srl_get_num_bytes_rxed(), &main_ax25, &main_afsk);
short res = ParseReceivedKISS(srl_get_rx_buffer(main_kiss_srl_ctx_ptr), srl_get_num_bytes_rxed(main_kiss_srl_ctx_ptr), &main_ax25, &main_afsk);
if (res == 0)
kiss10m++; // increase kiss messages counter
// restart KISS receiving to be ready for next frame
srl_receive_data(120, FEND, FEND, 0, 0, 0);
srl_receive_data(main_kiss_srl_ctx_ptr, 120, FEND, FEND, 0, 0, 0);
}
// if there were an error during receiving frame from host, restart rxing once again
if (srl_rx_state == SRL_RX_ERROR) {
srl_receive_data(120, FEND, FEND, 0, 0, 0);
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_ERROR) {
srl_receive_data(main_kiss_srl_ctx_ptr, 120, FEND, FEND, 0, 0, 0);
}
#endif

Wyświetl plik

@ -181,9 +181,9 @@ void packet_tx_handler(void) {
main_wait_for_tx_complete();
#endif
#if defined _UMB_MASTER
umb_clear_error_history(&rte_wx_umb_context);
#endif
packet_tx_telemetry_descr_counter = 0;
}

Wyświetl plik

@ -107,7 +107,7 @@ extern "C" {
#endif
void srl_init(srl_context_t *ctx, USART_TypeDef *port, uint8_t *rx_buffer, uint16_t rx_buffer_size, uint8_t *tx_buffer, uint16_t tx_buffer_size);
void srl_init(srl_context_t *ctx, USART_TypeDef *port, uint8_t *rx_buffer, uint16_t rx_buffer_size, uint8_t *tx_buffer, uint16_t tx_buffer_size, uint32_t baudrate);
uint8_t srl_send_data(srl_context_t *ctx, uint8_t* data, uint8_t mode, uint16_t leng, uint8_t internal_external);
uint8_t srl_start_tx(srl_context_t *ctx, short leng);
void srl_wait_for_tx_completion(srl_context_t *ctx);

Wyświetl plik

@ -1,7 +1,7 @@
#include "drivers/serial.h"
#include "drivers/gpio_conf.h"
#define PORT USART1
//#define PORT USART1
#include "station_config.h"
@ -67,7 +67,15 @@ uint8_t srl_usart2_rx_buffer[RX_BUFFER_2_LN] = {'\0'}; // dane odebrane od zdal
//uint8_t srl_rx_lenght_param_modifier = 0;
void srl_init(srl_context_t *ctx, USART_TypeDef *port, uint8_t *rx_buffer, uint16_t rx_buffer_size, uint8_t *tx_buffer, uint16_t tx_buffer_size) {
void srl_init(
srl_context_t *ctx,
USART_TypeDef *port,
uint8_t *rx_buffer,
uint16_t rx_buffer_size,
uint8_t *tx_buffer,
uint16_t tx_buffer_size,
uint32_t baudrate
) {
if (ctx->srl_rx_state == SRL_RX_IDLE)
return;
@ -87,7 +95,7 @@ void srl_init(srl_context_t *ctx, USART_TypeDef *port, uint8_t *rx_buffer, uint1
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = _SERIAL_BAUDRATE;
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
@ -205,12 +213,12 @@ uint8_t srl_send_data(srl_context_t *ctx, uint8_t* data, uint8_t mode, uint16_t
GPIO_SetBits(ctx->te_port, ctx->te_pin);
// enabling transmitter
PORT->CR1 |= USART_CR1_TE;
PORT->SR &= (0xFFFFFFFF ^ USART_SR_TC);
PORT->DR = ctx->srl_tx_buf_pointer[0];
ctx->port->CR1 |= USART_CR1_TE;
ctx->port->SR &= (0xFFFFFFFF ^ USART_SR_TC);
ctx->port->DR = ctx->srl_tx_buf_pointer[0];
ctx->srl_tx_state = SRL_TXING;
PORT->CR1 |= USART_CR1_TXEIE; // przerwanie zg<7A>aszane kiedy rejsetr DR jest pusty
PORT->CR1 |= USART_CR1_TCIE; // przerwanie zg<7A>aszane po transmisji bajtu
ctx->port->CR1 |= USART_CR1_TXEIE; // przerwanie zg<7A>aszane kiedy rejsetr DR jest pusty
ctx->port->CR1 |= USART_CR1_TCIE; // przerwanie zg<7A>aszane po transmisji bajtu
// je<6A>eli rejestr DR jest nadal pusty
return SRL_OK;
@ -238,9 +246,9 @@ uint8_t srl_start_tx(srl_context_t *ctx, short leng) {
if (ctx->te_port != 0)
GPIO_SetBits(ctx->te_port, ctx->te_pin);
PORT->CR1 |= USART_CR1_TE;
PORT->SR &= (0xFFFFFFFF ^ USART_SR_TC);
PORT->DR = ctx->srl_tx_buf_pointer[0];
ctx->port->CR1 |= USART_CR1_TE;
ctx->port->SR &= (0xFFFFFFFF ^ USART_SR_TC);
ctx->port->DR = ctx->srl_tx_buf_pointer[0];
ctx->srl_tx_state = SRL_TXING;
@ -264,7 +272,7 @@ uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, cha
if (num >= RX_BUFFER_1_LN)
return SRL_DATA_TOO_LONG;
memset(ctx->srl_rx_buf_pointer, 0x00, RX_BUFFER_1_LN);
memset(ctx->srl_rx_buf_pointer, 0x00, ctx->srl_rx_buf_ln);
// checking if user want
if (start != 0x00) {
@ -300,8 +308,8 @@ uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, cha
ctx->srl_rx_timeout_calc_started = 0;
PORT->CR1 |= USART_CR1_RE; // uruchamianie odbiornika
PORT->CR1 |= USART_CR1_RXNEIE; // przerwanie od przepe<70>nionego bufora odbioru
ctx->port->CR1 |= USART_CR1_RE; // uruchamianie odbiornika
ctx->port->CR1 |= USART_CR1_RXNEIE; // przerwanie od przepe<70>nionego bufora odbioru
// PORT->CR1 |= USART_CR1_IDLEIE; // przerwanie od bezczynno<6E>ci szyny RS przy odbiorze
// spowodowanej zako<6B>czeniem transmisji przez urz<72>dzenie
return SRL_OK;
@ -324,13 +332,13 @@ void srl_irq_handler(srl_context_t *ctx) {
if ((ctx->port->SR & USART_SR_ORE) == USART_SR_ORE) {
switch (ctx->srl_rx_state) {
case SRL_RXING:
ctx->srl_garbage_storage = (uint8_t)PORT->DR;
ctx->srl_garbage_storage = (uint8_t)ctx->port->DR;
break;
default:
// if the UART driver is not receiving actually but hardware controler received any data
// it is required to read value of DR register to clear the interrupt
ctx->srl_garbage_storage = (uint8_t)PORT->DR;
ctx->srl_garbage_storage = (uint8_t)ctx->port->DR;
break;
}
}
@ -349,7 +357,7 @@ void srl_irq_handler(srl_context_t *ctx) {
if (ctx->srl_rx_bytes_counter < ctx->srl_rx_bytes_req) {
// storing received byte into buffer
ctx->srl_rx_buf_pointer[ctx->srl_rx_bytes_counter] = (uint8_t)PORT->DR;
ctx->srl_rx_buf_pointer[ctx->srl_rx_bytes_counter] = (uint8_t)ctx->port->DR;
// checking if this byte in stream holds the protocol information about
// how many bytes needs to be received.
@ -437,7 +445,7 @@ void srl_irq_handler(srl_context_t *ctx) {
}
// if one byte was successfully transferred from DR to shift register for transmission over USART
if ((PORT->SR & USART_SR_TXE) == USART_SR_TXE) {
if ((ctx->port->SR & USART_SR_TXE) == USART_SR_TXE) {
switch (ctx->srl_tx_state) {
case SRL_TXING:
if (ctx->srl_tx_bytes_counter < ctx->srl_tx_bytes_req) {
@ -456,8 +464,8 @@ void srl_irq_handler(srl_context_t *ctx) {
}
if (ctx->srl_tx_bytes_counter >= TX_BUFFER_1_LN ||
ctx->srl_tx_bytes_req >= TX_BUFFER_1_LN) {
if (ctx->srl_tx_bytes_counter >= ctx->srl_tx_buf_ln ||
ctx->srl_tx_bytes_req >= ctx->srl_tx_buf_ln) {
ctx->port->CR1 &= (0xFFFFFFFF ^ USART_CR1_TE); //wyġṗczanie nadajnika portu szeregowego
ctx->port->CR1 &= (0xFFFFFFFF ^ USART_CR1_TXEIE);

Wyświetl plik

@ -40,6 +40,8 @@ void umb_master_init(umb_context_t* ctx, srl_context_t* serial_ctx) {
ctx->last_fault_channel = 0;
ctx->serial_context = serial_ctx;
for (int i = 0; i < UMB_CONTEXT_ERR_HISTORY_LN; i++) {
ctx->nok_error_codes[i] = 0;
}