It kinda works but still problems with VUART, hangs randomly while writing.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15755 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2022-09-03 10:37:14 +00:00
parent fae48a7fc7
commit e922e31a74
4 changed files with 127 additions and 11 deletions

View File

@ -105,6 +105,7 @@ include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/sandbox/platform.mk
include $(CHIBIOS)/os/hal/boards/SB_GENERIC/board.mk
include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk
include $(CHIBIOS)/os/hal/lib/complex/buffered_sio/hal_buffered_sio.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMvx-M-SB/compilers/GCC/mk/port.mk
@ -116,7 +117,7 @@ include $(CHIBIOS)/tools/mk/autobuild.mk
#include $(CHIBIOS)/test/rt/rt_test.mk
#include $(CHIBIOS)/test/oslib/oslib_test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
#include $(CHIBIOS)/os/various/shell/shell.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here.
LDSCRIPT= ./sandbox.ld
@ -155,7 +156,7 @@ CPPWARN = -Wall -Wextra -Wundef
#
# List all user C define here, like -D_DEBUG=1
UDEFS =
UDEFS = -DSHELL_CMD_TEST_ENABLED=0
# Define ASM defines here
UADEFS =

View File

@ -16,8 +16,66 @@
#include "ch.h"
#include "hal.h"
#include "hal_buffered_sio.h"
#include "chprintf.h"
#include "shell.h"
static BufferedSIODriver bsio1;
static uint8_t rxbuf[32];
static uint8_t txbuf[32];
/*===========================================================================*/
/* Command line related. */
/*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
/* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
static uint8_t buf[] =
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: write\r\n");
return;
}
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
chnWrite(&bsio1, buf, sizeof buf - 1);
}
chprintf(chp, "\r\n\nstopped\r\n");
}
static const ShellCommand commands[] = {
{"write", cmd_write},
{NULL, NULL}
};
static const ShellConfig shell_cfg1 = {
(BaseSequentialStream *)&bsio1,
commands
};
/*===========================================================================*/
/* Generic code. */
/*===========================================================================*/
/*
* Blinker thread, times are in milliseconds.
@ -38,6 +96,7 @@ static THD_FUNCTION(Thread1, arg) {
* Application entry point.
*/
int main(void) {
thread_t *tp;
/*
* System initializations.
@ -49,17 +108,26 @@ int main(void) {
chSysInit();
/*
* Activates the Serial or SIO driver using the default configuration.
* Starting a buffered SIO, it must behave exactly as a serial driver.
*/
sioStart(&SIOD1, NULL);
bsioObjectInit(&bsio1, &SIOD1,
rxbuf, sizeof rxbuf,
txbuf, sizeof txbuf);
bsioStart(&bsio1, NULL);
/* Creating a blinker thread.*/
/*
* Creating a blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL);
chprintf((BaseSequentialStream *)&SIOD1, "Hello World!!\r\n");
/* Just sleeping in a loop.*/
/*
* Normal main() thread activity, spawning shells.
*/
while (true) {
chThdSleepMilliseconds(500);
tp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
"shell", NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1);
chThdWait(tp); /* Waiting termination. */
chThdSleepMilliseconds(1000);
}
}

View File

@ -85,7 +85,11 @@ static inline uint32_t __sio_vuart_deinit(uint32_t nvuart) {
#if !defined(SB_VUART1_SUPPRESS_ISR)
OSAL_IRQ_HANDLER(MK_VECTOR(SB_SIO_VUART1_IRQ)) {
OSAL_IRQ_PROLOGUE();
sio_lld_serve_interrupt(&SIOD1);
OSAL_IRQ_EPILOGUE();
}
#endif
#endif
@ -94,7 +98,11 @@ OSAL_IRQ_HANDLER(MK_VECTOR(SB_SIO_VUART1_IRQ)) {
#if !defined(SB_VUART2_SUPPRESS_ISR)
OSAL_IRQ_HANDLER(MK_VECTOR(SB_SIO_VUART2_IRQ)) {
OSAL_IRQ_PROLOGUE();
sio_lld_serve_interrupt(&SIOD2);
OSAL_IRQ_EPILOGUE();
}
#endif
#endif
@ -454,10 +462,48 @@ void sio_lld_serve_interrupt(SIODriver *siop) {
__syscall2rr(201, SB_VUART_GEVT, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
/* Processing events, if any.*/
events = (sioevents_t)r1;
/* Processing enabled events, if any.*/
events = (sioevents_t)r1 & siop->enabled;
if (events != (sioevents_t)0) {
/* Error events handled as a group.*/
if ((events & SIO_EV_ALL_ERRORS) != 0U) {
/* Waiting thread woken, if any.*/
__sio_wakeup_errors(siop);
}
/* If there are no errors then we check for the other RX events.*/
else {
/* Idle RX event.*/
if ((events & SIO_EV_RXIDLE) != 0U) {
/* Waiting thread woken, if any.*/
__sio_wakeup_rxidle(siop);
}
/* RX FIFO is non-empty.*/
if ((events & SIO_EV_RXNOTEMPY) != 0U) {
/* Waiting thread woken, if any.*/
__sio_wakeup_rx(siop);
}
}
/* TX FIFO is non-full.*/
if ((events & SIO_EV_TXNOTFULL) != 0U) {
/* Waiting thread woken, if any.*/
__sio_wakeup_tx(siop);
}
/* Physical transmission end.*/
if ((events & SIO_EV_TXDONE) != 0U) {
/* Waiting thread woken, if any.*/
__sio_wakeup_txend(siop);
}
/* The callback is finally invoked.*/
__sio_callback(siop);
}

View File

@ -132,6 +132,7 @@ extern "C" {
void sio_lld_update_enable_flags(SIODriver *siop);
sioevents_t sio_lld_get_and_clear_errors(SIODriver *siop);
sioevents_t sio_lld_get_and_clear_events(SIODriver *siop);
sioevents_t sio_lld_get_events(SIODriver *siop);
size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t n);
size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t n);
msg_t sio_lld_get(SIODriver *siop);