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

[Bouffalolab] Fix crash issue caused by button action and fix UART tx/rx for command line #25267

Merged
merged 11 commits into from
Mar 7, 2023
5 changes: 2 additions & 3 deletions examples/lighting-app/bouffalolab/common/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,18 +644,17 @@ void AppTask::ButtonEventHandler(void * arg)
uint32_t presstime;
if (ButtonPressed())
{
hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_NEG_LEVEL, GetAppTask().ButtonEventHandler, NULL);
bl_set_gpio_intmod(gpio_key.port, 1, HOSAL_IRQ_TRIG_NEG_LEVEL);

GetAppTask().mButtonPressedTime = chip::System::SystemClock().GetMonotonicMilliseconds64().count();
GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_PRESS);
}
else
{
hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_POS_PULSE, GetAppTask().ButtonEventHandler, NULL);
bl_set_gpio_intmod(gpio_key.port, 1, HOSAL_IRQ_TRIG_POS_PULSE);

if (GetAppTask().mButtonPressedTime)
{

presstime = chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime;
if (presstime >= APP_BUTTON_PRESS_LONG)
{
Expand Down
11 changes: 4 additions & 7 deletions examples/platform/bouffalolab/common/plat/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,30 @@ static int uartTxCallback(void * p_arg)

static int uartRxCallback(void * p_arg)
{
uint32_t len = 0, readlen = 0;
uint32_t len = 0;
BaseType_t xHigherPriorityTaskWoken = 1;

if (chipUart_var.head >= chipUart_var.tail)
{
if (chipUart_var.head < MAX_BUFFER_SIZE)
{
readlen = len =
hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf + chipUart_var.head, MAX_BUFFER_SIZE - chipUart_var.head);
len = hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf + chipUart_var.head, MAX_BUFFER_SIZE - chipUart_var.head);
chipUart_var.head = (chipUart_var.head + len) % MAX_BUFFER_SIZE;
}

if (0 == chipUart_var.head)
{
len = hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf, chipUart_var.tail - 1);
chipUart_var.head += len;
readlen += len;
}
}
else
{
readlen =
chipUart_var.head +=
hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf + chipUart_var.head, chipUart_var.tail - chipUart_var.head - 1);
chipUart_var.head += readlen;
}

if (0 == readlen || (chipUart_var.head + 1) % MAX_BUFFER_SIZE == chipUart_var.tail)
if (chipUart_var.head != chipUart_var.tail)
{
xSemaphoreGiveFromISR(chipUart_var.sema, &xHigherPriorityTaskWoken);
}
Expand Down