Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid task queue overrun for serial input #1540

Merged
merged 1 commit into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

// For event signalling
static task_handle_t sig = 0;
static uint8 *sig_flag;
static uint8 isr_flag = 0;

// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;
Expand Down Expand Up @@ -277,8 +279,12 @@ uart0_rx_intr_handler(void *para)
got_input = true;
}

if (got_input && sig)
task_post_low (sig, false);
if (got_input && sig) {
if (isr_flag == *sig_flag) {
isr_flag ^= 0x01;
task_post_low (sig, 0x8000 | isr_flag << 14 | false);
}
}
}

static void
Expand Down Expand Up @@ -316,14 +322,15 @@ uart_stop_autobaud()
* Description : user interface for init uart
* Parameters : UartBautRate uart0_br - uart0 bautrate
* UartBautRate uart1_br - uart1 bautrate
* uint8 task_prio - task priority to signal on input
* os_signal_t sig_input - signal to post
* uint8 *flag_input - flag of consumer task
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input)
uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input, uint8 *flag_input)
{
sig = sig_input;
sig_flag = flag_input;

// rom use 74880 baut_rate, here reinitialize
UartDev.baut_rate = uart0_br;
Expand Down
2 changes: 1 addition & 1 deletion app/include/driver/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ typedef struct {
int buff_uart_no; //indicate which uart use tx/rx buffer
} UartDevice;

void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input);
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input, uint8 *flag_input);
void uart0_alt(uint8 on);
void uart0_sendStr(const char *str);
void uart0_putc(const char c);
Expand Down
8 changes: 6 additions & 2 deletions app/user/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#endif

static task_handle_t input_sig;
static uint8 input_sig_flag = 0;

/* Contents of esp_init_data_default.bin */
extern const uint32_t init_data[];
Expand Down Expand Up @@ -100,7 +101,10 @@ static void start_lua(task_param_t param, uint8 priority) {

static void handle_input(task_param_t flag, uint8 priority) {
(void)priority;
lua_handle_input (flag);
if (flag & 0x8000) {
input_sig_flag = flag & 0x4000 ? 1 : 0;
}
lua_handle_input (flag & 0x01);
}

bool user_process_input(bool force) {
Expand Down Expand Up @@ -231,7 +235,7 @@ void user_init(void)
UartBautRate br = BIT_RATE_DEFAULT;

input_sig = task_get_id(handle_input);
uart_init (br, br, input_sig);
uart_init (br, br, input_sig, &input_sig_flag);

#ifndef NODE_DEBUG
system_set_os_print(0);
Expand Down