add sim idle and log for at, update to 2.4.1

This commit is contained in:
mculover666
2021-07-16 16:12:10 +08:00
committed by vitoswwang
parent 51b27e3317
commit 0193dc6142
4 changed files with 102 additions and 8 deletions

View File

@@ -318,6 +318,8 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
HAL_UART_Receive_IT(&hlpuart1, &data, 1);
#if AT_INPUT_TYPE_FRAME_EN
uart_frame_buffer[uart_frame_buffer_index++] = data;
#elif AT_INPUT_SIMULATE_IDLE_EN
tos_at_uart_input_byte_no_notify(data);
#else
tos_at_uart_input_byte(data);
#endif /* AT_INPUT_TYPE_FRAME_EN */

View File

@@ -25,8 +25,8 @@
#define TOS_VERSION_MAJOR 0x02
#define TOS_VERSION_MINOR 0x04
#define TOS_VERSION_PATCH 0x00
#define TOS_VERSION "2.4.0"
#define TOS_VERSION_PATCH 0x01
#define TOS_VERSION "2.4.1"
#endif /* _TOS_VERSION_H_ */

View File

@@ -35,6 +35,23 @@
#define AT_INPUT_TYPE_FRAME_EN 0
#define AT_FRAME_LEN_MAIL_MAX 5
#define AT_INPUT_SIMULATE_IDLE_EN 0
#define SIMULATE_IDLE_DEFAULT_TIME 5
#define AT_DEBUG_LOG_EN 0
#if AT_DEBUG_LOG_EN
#define AT_LOG(...) tos_kprintf(__VA_ARGS__)
#else
#define AT_LOG(...)
#endif
#if (AT_INPUT_SIMULATE_IDLE_EN == 1) && (AT_INPUT_TYPE_FRAME_EN == 1)
#error "please choose AT_INPUT_SIMULATE_IDLE or AT_INPUT_TYPE_FRAM!"
#elif (AT_INPUT_SIMULATE_IDLE_EN == 1) && (TOS_CFG_TIMER_EN == 0)
#error "please enable TOS_CFG_TIMER_EN!"
#endif
typedef enum at_status_en {
AT_STATUS_OK,
AT_STATUS_ERROR,
@@ -137,7 +154,12 @@ typedef struct at_agent_st {
uint16_t fifo_available_len;
#else
k_sem_t uart_rx_sem;
#if AT_INPUT_SIMULATE_IDLE_EN
k_timer_t idle_check_timer;
#endif /* AT_INPUT_SIMULATE_IDLE_EN */
#endif /* AT_INPUT_TYPE_FRAME_EN */
k_chr_fifo_t uart_rx_fifo;
uint8_t *uart_rx_fifo_buffer;
} at_agent_t;
@@ -413,6 +435,19 @@ __API__ int tos_at_raw_data_send_until(at_echo_t *echo, uint32_t timeout, const
* @return None
*/
__API__ void tos_at_uart_input_frame(uint8_t *pdata, uint16_t len);
#elif AT_INPUT_SIMULATE_IDLE_EN
/**
* @brief Write byte to the at uart.
* The function called by the uart receive interrupt.
*
* @attention No notification is given after writing.
*
* @param[in] data uart received data.
*
* @return None
*/
__API__ void tos_at_uart_input_byte_no_notify(uint8_t data);
#else
/**
* @brief Write byte to the at uart.

View File

@@ -77,6 +77,19 @@ __STATIC__ int at_uart_getchar(uint8_t *data, k_tick_t timeout)
AT_AGENT->fifo_available_len -= 1;
return 0;
#elif AT_INPUT_SIMULATE_IDLE_EN
if (tos_chr_fifo_is_empty(&AT_AGENT->uart_rx_fifo)) {
if (tos_sem_pend(&AT_AGENT->uart_rx_sem, timeout) != K_ERR_NONE) {
return -1;
}
}
if (at_uart_getchar_from_fifo(data) != K_ERR_NONE) {
return -1;
}
return 0;
#else
tos_stopwatch_delay(1);
@@ -274,6 +287,8 @@ __STATIC__ at_parse_status_t at_uart_line_parse(void)
return AT_PARSE_STATUS_EXPECT;
}
AT_LOG("recv_cache:[%s](%d)\r\n", recv_cache->buffer, recv_cache->recv_len);
if (strstr((char*)recv_cache->buffer, "OK")) {
return AT_PARSE_STATUS_OK;
} else if (strstr((char*)recv_cache->buffer, "FAIL")) {
@@ -331,8 +346,11 @@ __STATIC__ void at_parser(void *arg)
recv_cache = &AT_AGENT->recv_cache;
while (K_TRUE) {
at_parse_status = at_uart_line_parse();
AT_LOG("at line parser end!(%d)\r\n", at_parse_status);
tos_kprintln("--->%s", recv_cache->buffer);
if (at_parse_status == AT_PARSE_STATUS_OVERFLOW) {
@@ -921,6 +939,19 @@ __STATIC__ void at_event_table_set(at_event_t *event_table, size_t event_table_s
AT_AGENT->event_table_size = event_table_size;
}
#if AT_INPUT_SIMULATE_IDLE_EN
__STATIC__ void tos_at_uart_input_notify()
{
tos_sem_post(&AT_AGENT->uart_rx_sem);
}
__STATIC__ void idle_check_timer_callback(void *args)
{
tos_at_uart_input_notify();
}
#endif /* #if AT_INPUT_SIMULATE_IDLE_EN */
__API__ int tos_at_init(hal_uart_port_t uart_port, at_event_t *event_table, size_t event_table_size)
{
void *buffer = K_NULL;
@@ -982,21 +1013,33 @@ __API__ int tos_at_init(hal_uart_port_t uart_port, at_event_t *event_table, size
goto errout7;
}
if (tos_hal_uart_init(&AT_AGENT->uart, uart_port) != 0) {
#if AT_INPUT_SIMULATE_IDLE_EN
if (tos_timer_create(&AT_AGENT->idle_check_timer, SIMULATE_IDLE_DEFAULT_TIME,
0, idle_check_timer_callback, NULL, TOS_OPT_TIMER_ONESHOT) != K_ERR_NONE) {
goto errout8;
}
#endif /* AT_INPUT_SIMULATE_IDLE_EN */
if (tos_hal_uart_init(&AT_AGENT->uart, uart_port) != 0) {
goto errout9;
}
if (tos_task_create(&AT_AGENT->parser, "at_parser", at_parser,
K_NULL, AT_PARSER_TASK_PRIO, at_parser_task_stack,
AT_PARSER_TASK_STACK_SIZE, 0) != K_ERR_NONE) {
goto errout9;
goto errout10;
}
return 0;
errout9:
errout10:
tos_hal_uart_deinit(&AT_AGENT->uart);
errout9:
#if AT_INPUT_SIMULATE_IDLE_EN
tos_timer_destroy(&AT_AGENT->idle_check_timer);
errout8:
#endif /* AT_INPUT_SIMULATE_IDLE_EN */
tos_mutex_destroy(&AT_AGENT->global_lock);
errout7:
@@ -1048,6 +1091,10 @@ __API__ void tos_at_deinit(void)
//tos_mutex_destroy(&AT_AGENT->uart_tx_lock);
#if AT_INPUT_SIMULATE_IDLE_EN
tos_timer_destroy(&AT_AGENT->idle_check_timer);
#endif /* AT_INPUT_SIMULATE_IDLE_EN */
#if AT_INPUT_TYPE_FRAME_EN
tos_mail_q_destroy(&AT_AGENT->uart_rx_frame_mail);
tos_mmheap_free(AT_AGENT->uart_rx_frame_mail_buffer);
@@ -1087,6 +1134,15 @@ __API__ void tos_at_uart_input_frame(uint8_t *pdata, uint16_t len)
at_frame_len_mail.frame_len = len;
tos_mail_q_post(&AT_AGENT->uart_rx_frame_mail, &at_frame_len_mail, sizeof(at_frame_len_mail_t));
}
#elif AT_INPUT_SIMULATE_IDLE_EN
__API__ void tos_at_uart_input_byte_no_notify(uint8_t data)
{
tos_timer_stop(&AT_AGENT->idle_check_timer);
tos_chr_fifo_push(&AT_AGENT->uart_rx_fifo, data);
tos_timer_start(&AT_AGENT->idle_check_timer);
}
#else
__API__ void tos_at_uart_input_byte(uint8_t data)
{
@@ -1094,4 +1150,5 @@ __API__ void tos_at_uart_input_byte(uint8_t data)
tos_sem_post(&AT_AGENT->uart_rx_sem);
}
}
#endif /* AT_INPUT_TYPE_FRAME_EN */
#endif /* AT_INPUT_TYPE_FRAME_EN or AT_INPUT_SIMULATE_IDLE_EN */