added serial receive function with immediate timeout calculation. first test and minor bugfixes in davis code

pull/2/head
Mateusz Lubecki 2020-08-25 20:05:04 +02:00
rodzic dd4e05717d
commit 26fa8c00bf
6 zmienionych plików z 90 dodań i 5 usunięć

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -43,6 +43,11 @@
#include "aprs/wx.h"
#include "drivers/gpio_conf.h"
#ifdef _DAVIS_SERIAL
#include "../system/include/davis_vantage/davis.h"
#include "../system/include/davis_vantage/davis_parsers.h"
#endif
#ifdef _SENSOR_MS5611
#include "drivers/ms5611.h"
#endif
@ -288,6 +293,25 @@ int main(int argc, char* argv[]){
main_wx_srl_ctx_ptr->te_port = GPIOA;
#endif
#if (defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)) && defined(_DAVIS_SERIAL)
// reinitialize the KISS serial port temporary to davis baudrate
main_target_kiss_baudrate = DAVIS_DEFAULT_BAUDRATE;
// reset RX state to allow reinitialization with changed baudrate
main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG;
// reinitializing serial hardware
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_switch_timeout(main_kiss_srl_ctx_ptr, SRL_TIMEOUT_ENABLE, 1500);
davis_init(main_kiss_srl_ctx_ptr);
davis_wake_up(1);
#endif
// configuring an APRS path used to transmit own packets (telemetry, wx, beacons)
main_own_path_ln = ConfigPath(main_own_path);

Wyświetl plik

@ -12,6 +12,8 @@
#include "davis_retval_def.h"
#define DAVIS_DEFAULT_BAUDRATE 19200u
uint32_t davis_init(srl_context_t* srl_port);
uint32_t davis_wake_up(uint8_t is_io_blocking);
uint32_t davis_do_test(void);

Wyświetl plik

@ -16,6 +16,9 @@
#define SRL_DEFAULT_RX_TIMEOUT_IN_MS 400
#define SRL_TIMEOUT_ENABLE 1
#define SRL_TIMEOUT_DISABLE 0
typedef enum srlRxState {
SRL_RX_NOT_CONFIG,
SRL_RX_IDLE,
@ -116,6 +119,7 @@ void srl_wait_for_tx_completion(srl_context_t *ctx);
uint8_t srl_wait_for_rx_completion_or_timeout(srl_context_t *ctx, uint8_t* output);
void srl_irq_handler(srl_context_t *ctx);
uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, char echo, char len_addr, char len_modifier);
uint8_t srl_receive_data_with_instant_timeout(srl_context_t *ctx, int num, char start, char stop, char echo, char len_addr, char len_modifier);
uint16_t srl_get_num_bytes_rxed(srl_context_t *ctx);
uint8_t* srl_get_rx_buffer(srl_context_t *ctx);
void srl_keep_timeout(srl_context_t *ctx);

Wyświetl plik

@ -46,7 +46,7 @@ uint8_t davis_avaliable;
*/
uint8_t davis_loop_avaliable;
static const char line_feed[] = "\n";
static const char line_feed = '\n';
static const char line_feed_return[] = {'\n', '\r'};
static const char loop_command[] = "LOOP 1\n";
@ -82,7 +82,7 @@ uint32_t davis_wake_up(uint8_t is_io_blocking) {
int comparation_result = -1;
// sending the new line to wake up the console
srl_send_data(davis_serial_context, (uint8_t*)line_feed, 1, 1, 0);
srl_send_data(davis_serial_context, (uint8_t*)&line_feed, 1, 1, 0);
// check if a user want to have blocking I/O
if (is_io_blocking == 1) {
@ -90,7 +90,7 @@ uint32_t davis_wake_up(uint8_t is_io_blocking) {
srl_wait_for_tx_completion(davis_serial_context);
// start waiting for console response
srl_receive_data(davis_serial_context, 2, 0, 0, 0, 0, 0);
srl_receive_data_with_instant_timeout(davis_serial_context, 2, 0, 0, 0, 0, 0);
// wait for station response or for timeout
srl_wait_for_rx_completion_or_timeout(davis_serial_context, ((uint8_t*)&retval));
@ -110,7 +110,7 @@ uint32_t davis_wake_up(uint8_t is_io_blocking) {
// send the wake up command one more time
// sending the new line to wake up the console
srl_send_data(davis_serial_context, (uint8_t*)line_feed, 1, 1, 0);
srl_send_data(davis_serial_context, (uint8_t*)&line_feed, 1, 1, 0);
// if yes wait for transmission completion and then wait for response
srl_wait_for_tx_completion(davis_serial_context);
@ -143,7 +143,7 @@ uint32_t davis_wake_up(uint8_t is_io_blocking) {
switch (davis_wake_up_state) {
case DAVIS_QUERY_IDLE: {
// sending the new line to wake up the console
srl_send_data(davis_serial_context, (uint8_t*)line_feed, 1, 1, 0);
srl_send_data(davis_serial_context, (uint8_t*)&line_feed, 1, 1, 0);
// switching the internal state
davis_wake_up_state = DAVIS_QUERY_SENDING_QUERY;

Wyświetl plik

@ -346,6 +346,61 @@ uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, cha
return SRL_OK;
}
uint8_t srl_receive_data_with_instant_timeout(srl_context_t *ctx, int num, char start, char stop, char echo, char len_addr, char len_modifier) {
if (ctx->srl_rx_state == SRL_RXING)
return SRL_BUSY;
//trace_printf("Serial:SrlReceiveData()\r\n");
if (num >= RX_BUFFER_1_LN)
return SRL_DATA_TOO_LONG;
memset(ctx->srl_rx_buf_pointer, 0x00, ctx->srl_rx_buf_ln);
// checking if user want
if (start != 0x00) {
ctx->srl_triggered_start = 1;
ctx->srl_start_trigger = start;
}
else {
ctx->srl_triggered_start = 0;
}
if (stop != 0x00) {
ctx->srl_triggered_stop = 1;
ctx->srl_stop_trigger = stop;
}
else {
ctx->srl_triggered_stop = 0;
}
if (ctx->srl_triggered_start == 1 || ctx->srl_triggered_stop == 1) {
if (num < 3)
return SRL_WRONG_PARAMS_COMBINATION;
ctx->srl_rx_state = SRL_WAITING_TO_RX;
ctx->srl_rx_waiting_start_time = master_time;
}
ctx->srl_enable_echo = echo;
ctx->srl_rx_bytes_counter = 0;
ctx->srl_rx_bytes_req = num;
ctx->srl_rx_lenght_param_addres = len_addr;
ctx->srl_rx_lenght_param_modifier = len_modifier;
// set current time as receive start time
ctx->srl_rx_start_time = master_time;
ctx->srl_rx_timeout_calc_started = 1;
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;
}
void srl_irq_handler(srl_context_t *ctx) {