Moved most of VUART to fastcalls.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15775 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2022-09-08 18:02:55 +00:00
parent 280eff4554
commit 750d88c7b8
5 changed files with 120 additions and 139 deletions

View File

@ -75,7 +75,7 @@ static void __bsio_default_cb(SIODriver *siop) {
/* Posting the non-data SIO events as channel event flags, the masks are
made to match.*/
events = sioGetAndClearEventsI(siop);
events = sioGetAndClearEventsX(siop);
chnAddFlagsI(bsiop, (eventflags_t)(events & ~SIO_EV_ALL_DATA));
/* RX FIFO event.*/
@ -207,7 +207,7 @@ msg_t bsioStart(BufferedSIODriver *bsiop, const BufferedSIOConfig *config) {
if (msg == HAL_RET_SUCCESS) {
osalSysLock();
sioSetCallbackX(bsiop->siop, &__bsio_default_cb);
sioWriteEnableFlagsI(bsiop->siop, SIO_EV_ALL_EVENTS);
sioWriteEnableFlagsX(bsiop->siop, SIO_EV_ALL_EVENTS);
bsiop->state = BS_READY;
osalSysUnlock();
}

View File

@ -66,14 +66,14 @@ static const SIOConfig default_config = {
__attribute__((always_inline))
static inline uint32_t __sio_vuart_init(uint32_t nvuart, uint32_t ncfg) {
__syscall3r(201, SB_VUART_INIT, nvuart, ncfg);
__syscall3r(96, SB_VUART_INIT, nvuart, ncfg);
return (uint32_t)r0;
}
__attribute__((always_inline))
static inline uint32_t __sio_vuart_deinit(uint32_t nvuart) {
__syscall2r(201, SB_VUART_INIT, nvuart);
__syscall2r(96, SB_VUART_DEINIT, nvuart);
return (uint32_t)r0;
}
@ -217,10 +217,10 @@ void sio_lld_stop(SIODriver *siop) {
*/
bool sio_lld_is_rx_empty(SIODriver *siop) {
__syscall2rr(201, SB_VUART_ISRXE, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_ISRXE, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (bool)r1;
return (bool)r0;
}
/**
@ -235,10 +235,10 @@ bool sio_lld_is_rx_empty(SIODriver *siop) {
*/
bool sio_lld_is_rx_idle(SIODriver *siop) {
__syscall2rr(201, SB_VUART_ISRXI, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_ISRXI, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (bool)r1;
return (bool)r0;
}
/**
@ -255,10 +255,10 @@ bool sio_lld_is_rx_idle(SIODriver *siop) {
*/
bool sio_lld_has_rx_errors(SIODriver *siop) {
__syscall2rr(201, SB_VUART_HASERR, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_HASERR, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (bool)r1;
return (bool)r0;
}
/**
@ -273,10 +273,10 @@ bool sio_lld_has_rx_errors(SIODriver *siop) {
*/
bool sio_lld_is_tx_full(SIODriver *siop) {
__syscall2rr(201, SB_VUART_ISTXF, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_ISTXF, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (bool)r1;
return (bool)r0;
}
/**
@ -291,10 +291,10 @@ bool sio_lld_is_tx_full(SIODriver *siop) {
*/
bool sio_lld_is_tx_ongoing(SIODriver *siop) {
__syscall2rr(201, SB_VUART_ISTXO, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_ISTXO, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (bool)r1;
return (bool)r0;
}
/**
@ -304,8 +304,8 @@ bool sio_lld_is_tx_ongoing(SIODriver *siop) {
*/
void sio_lld_update_enable_flags(SIODriver *siop) {
__syscall3r(201, SB_VUART_WREN, siop->nvuart, siop->enabled);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall3r(225, SB_VUART_WREN, siop->nvuart, siop->enabled);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
}
/**
@ -318,10 +318,10 @@ void sio_lld_update_enable_flags(SIODriver *siop) {
*/
sioevents_t sio_lld_get_and_clear_errors(SIODriver *siop) {
__syscall2rr(201, SB_VUART_GCERR, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_GCERR, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (sioevents_t)r1;
return (sioevents_t)r0;
}
/**
@ -334,10 +334,10 @@ sioevents_t sio_lld_get_and_clear_errors(SIODriver *siop) {
*/
sioevents_t sio_lld_get_and_clear_events(SIODriver *siop) {
__syscall2rr(201, SB_VUART_GCEVT, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_GCEVT, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (sioevents_t)r1;
return (sioevents_t)r0;
}
/**
@ -350,10 +350,10 @@ sioevents_t sio_lld_get_and_clear_events(SIODriver *siop) {
*/
sioevents_t sio_lld_get_events(SIODriver *siop) {
__syscall2rr(201, SB_VUART_GEVT, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_GEVT, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (sioevents_t)r1;
return (sioevents_t)r0;
}
/**
@ -369,10 +369,10 @@ sioevents_t sio_lld_get_events(SIODriver *siop) {
*/
size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t n) {
__syscall4rr(201, SB_VUART_READ, siop->nvuart, buffer, n);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall4r(225, SB_VUART_READ, siop->nvuart, buffer, n);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (size_t)r1;
return (size_t)r0;
}
/**
@ -388,10 +388,10 @@ 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) {
__syscall4rr(201, SB_VUART_WRITE, siop->nvuart, buffer, n);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall4r(225, SB_VUART_WRITE, siop->nvuart, buffer, n);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (size_t)r1;
return (size_t)r0;
}
/**
@ -405,10 +405,10 @@ size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t n) {
*/
msg_t sio_lld_get(SIODriver *siop) {
__syscall2rr(201, SB_VUART_GET, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2r(225, SB_VUART_GET, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (size_t)r1;
return (size_t)r0;
}
/**
@ -422,8 +422,8 @@ msg_t sio_lld_get(SIODriver *siop) {
*/
void sio_lld_put(SIODriver *siop, uint_fast16_t data) {
__syscall3r(201, SB_VUART_PUT, siop->nvuart, data);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall3r(225, SB_VUART_PUT, siop->nvuart, data);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
}
/**
@ -442,10 +442,10 @@ void sio_lld_put(SIODriver *siop, uint_fast16_t data) {
*/
msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg) {
__syscall4rr(201, SB_VUART_CTL, siop->nvuart, operation, arg);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall4r(225, SB_VUART_CTL, siop->nvuart, operation, arg);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
return (size_t)r1;
return (msg_t)r0;
}
/**
@ -459,11 +459,11 @@ void sio_lld_serve_interrupt(SIODriver *siop) {
sioevents_t events;
#if SIO_USE_SYNCHRONIZATION == TRUE
__syscall2rr(201, SB_VUART_GEVT, siop->nvuart);
osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure");
__syscall2rr(225, SB_VUART_GEVT, siop->nvuart);
osalDbgAssert(r0 != (uint32_t)-1, "unexpected failure");
/* Processing enabled events, if any.*/
events = (sioevents_t)r1 & siop->enabled;
events = (sioevents_t)r0 & siop->enabled;
if (events != (sioevents_t)0) {
/* Error events handled as a group.*/

View File

@ -60,6 +60,7 @@
* @{
*/
#define SB_FASTC_VHAL_VGPIO 224
#define SB_FASTC_VHAL_VUART 225
#define SB_FASTC_VRQ_SETWT 248
#define SB_FASTC_VRQ_CLRWT 249
#define SB_FASTC_VRQ_SETEN 250
@ -111,20 +112,20 @@
*/
#define SB_VUART_INIT 0
#define SB_VUART_DEINIT 1
#define SB_VUART_ISRXE 2
#define SB_VUART_ISRXI 3
#define SB_VUART_ISTXF 4
#define SB_VUART_ISTXO 5
#define SB_VUART_HASERR 6
#define SB_VUART_READ 7
#define SB_VUART_WRITE 8
#define SB_VUART_GET 9
#define SB_VUART_PUT 10
#define SB_VUART_WREN 11
#define SB_VUART_GCERR 12
#define SB_VUART_GCEVT 13
#define SB_VUART_GEVT 14
#define SB_VUART_CTL 15
#define SB_VUART_ISRXE 0
#define SB_VUART_ISRXI 1
#define SB_VUART_ISTXF 2
#define SB_VUART_ISTXO 3
#define SB_VUART_HASERR 4
#define SB_VUART_READ 5
#define SB_VUART_WRITE 6
#define SB_VUART_GET 7
#define SB_VUART_PUT 8
#define SB_VUART_WREN 9
#define SB_VUART_GCERR 10
#define SB_VUART_GCEVT 11
#define SB_VUART_GEVT 12
#define SB_VUART_CTL 13
/** @} */
/*===========================================================================*/

View File

@ -59,12 +59,11 @@ static void vuart_cb(SIODriver *siop) {
/* Module exported functions. */
/*===========================================================================*/
void sb_api_vio_uart(struct port_extctx *ectxp) {
void sb_sysc_vio_uart(struct port_extctx *ectxp) {
sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
uint32_t sub = ectxp->r0;
uint32_t unit = ectxp->r1;
ectxp->r0 = (uint32_t)CH_RET_INNER_ERROR;
ectxp->r1 = (uint32_t)0;
const vio_uart_unit_t *unitp;
if (unit >= sbp->config->vioconf->uarts->n) {
@ -110,34 +109,57 @@ void sb_api_vio_uart(struct port_extctx *ectxp) {
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
break;
}
default:
ectxp->r0 = (uint32_t)CH_RET_ENOSYS;
break;
}
}
void sb_fastc_vio_uart(struct port_extctx *ectxp) {
sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
uint32_t sub = ectxp->r0;
uint32_t unit = ectxp->r1;
const vio_uart_unit_t *unitp;
/* Returned value in case of error or illegal sub-code.*/
ectxp->r0 = (uint32_t)-1;
if (unit >= sbp->config->vioconf->uarts->n) {
return;
}
unitp = &sbp->config->vioconf->uarts->units[unit];
/* We don't want assertion or errors to be caused in host, making sure
all functions are called in the proper state.*/
if (unitp->siop->state != SIO_READY) {
return;
}
switch (sub) {
case SB_VUART_ISRXE:
{
ectxp->r1 = (uint32_t)sioIsRXEmptyX(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = (uint32_t)sioIsRXEmptyX(unitp->siop);
break;
}
case SB_VUART_ISRXI:
{
ectxp->r1 = (uint32_t)sioIsRXIdleX(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = (uint32_t)sioIsRXIdleX(unitp->siop);
break;
}
case SB_VUART_ISTXF:
{
ectxp->r1 = (uint32_t)sioIsTXFullX(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = (uint32_t)sioIsTXFullX(unitp->siop);
break;
}
case SB_VUART_ISTXO:
{
ectxp->r1 = (uint32_t)sioIsTXOngoingX(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = (uint32_t)sioIsTXOngoingX(unitp->siop);
break;
}
case SB_VUART_HASERR:
{
ectxp->r1 = (uint32_t)sioHasRXErrorsX(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = (uint32_t)sioHasRXErrorsX(unitp->siop);
break;
}
case SB_VUART_READ:
@ -145,18 +167,13 @@ void sb_api_vio_uart(struct port_extctx *ectxp) {
uint8_t *buffer = (uint8_t *)ectxp->r2;
size_t n = (size_t)ectxp->r3;
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
break;
}
if (!sb_is_valid_write_range(sbp, buffer, n)) {
ectxp->r0 = (uint32_t)CH_RET_EFAULT;
ectxp->r0 = (uint32_t)0;
/* TODO enforce fault instead.*/
break;
}
ectxp->r1 = sioAsyncRead(unitp->siop, buffer, n);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = sioAsyncReadX(unitp->siop, buffer, n);
break;
}
case SB_VUART_WRITE:
@ -164,94 +181,51 @@ void sb_api_vio_uart(struct port_extctx *ectxp) {
const uint8_t *buffer = (const uint8_t *)ectxp->r2;
size_t n = (size_t)ectxp->r3;
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
break;
}
if (!sb_is_valid_read_range(sbp, buffer, n)) {
ectxp->r0 = (uint32_t)CH_RET_EFAULT;
ectxp->r0 = (uint32_t)0;
/* TODO enforce fault instead.*/
break;
}
ectxp->r1 = sioAsyncWrite(unitp->siop, buffer, n);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = sioAsyncWriteX(unitp->siop, buffer, n);
break;
}
case SB_VUART_GET:
{
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
break;
}
ectxp->r1 = sioGetX(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = sioGetX(unitp->siop);
break;
}
case SB_VUART_PUT:
{
uint_fast16_t data = (uint_fast16_t)ectxp->r2;
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
break;
}
sioPutX(unitp->siop, data);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
sioPutX(unitp->siop, (uint_fast16_t)ectxp->r2);
ectxp->r0 = (uint32_t)0;
break;
}
case SB_VUART_WREN:
{
sioevents_t flags = (sioevents_t)ectxp->r2;
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
break;
}
sioWriteEnableFlags(unitp->siop, flags);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
sioWriteEnableFlagsX(unitp->siop, (sioevents_t)ectxp->r2);
ectxp->r0 = (uint32_t)0;
break;
}
case SB_VUART_GCERR:
{
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
break;
}
ectxp->r1 = (uint32_t)sioGetAndClearErrors(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = (uint32_t)sioGetAndClearErrorsX(unitp->siop);
break;
}
case SB_VUART_GCEVT:
{
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
break;
}
ectxp->r1 = (uint32_t)sioGetAndClearEvents(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
ectxp->r0 = (uint32_t)sioGetAndClearEventsX(unitp->siop);
break;
}
case SB_VUART_GEVT:
{
if (unitp->siop->state != SIO_READY) {
ectxp->r0 = (uint32_t)CH_RET_EIO;
{
ectxp->r0 = (uint32_t)sioGetEventsX(unitp->siop);
break;
}
ectxp->r1 = (uint32_t)sioGetEvents(unitp->siop);
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
break;
}
case SB_VUART_CTL:
/* falls through */
default:
ectxp->r0 = (uint32_t)CH_RET_ENOSYS;
/* Silently ignored.*/
break;
}
}

View File

@ -37,7 +37,12 @@
/**
* @brief API handler for VHAL PAL driver.
*/
#define SB_SVC201_HANDLER sb_api_vio_uart
#define SB_SVC96_HANDLER sb_sysc_vio_uart
/**
* @brief Fast API handler for VHAL PAL driver.
*/
#define SB_SVC225_HANDLER sb_fastc_vio_uart
/*===========================================================================*/
/* Module pre-compile time settings. */
@ -94,7 +99,8 @@ typedef struct vio_uart_configs {
#ifdef __cplusplus
extern "C" {
#endif
void sb_api_vio_uart(struct port_extctx *ectxp);
void sb_sysc_vio_uart(struct port_extctx *ectxp);
void sb_fastc_vio_uart(struct port_extctx *ectxp);
#ifdef __cplusplus
}
#endif