git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16335 27425a3e-05d8-49a3-a47f-9c15f0e5edd8

This commit is contained in:
Giovanni Di Sirio 2023-07-19 13:02:13 +00:00
parent 5a2a48ae62
commit 50e2ad5404
2 changed files with 121 additions and 2 deletions

View File

@ -112,6 +112,10 @@
*/
#define SB_VSPI_INIT 0
#define SB_VSPI_DEINIT 1
#define SB_VSPI_PULSES 2
#define SB_VSPI_RECEIVE 3
#define SB_VSPI_SEND 4
#define SB_VSPI_EXCHANGE 5
#define SB_VSPI_SETCFG 0
#define SB_VSPI_SELECT 1
#define SB_VSPI_UNSELECT 2

View File

@ -85,8 +85,7 @@ void sb_sysc_vio_spi(struct port_extctx *ectxp) {
msg = drvStart(unitp->spip);
if (msg == HAL_RET_SUCCESS) {
/* Starting with disabled events, enabling the callback.*/
sioWriteEnableFlags(unitp->spip, SIO_EV_NONE);
/* Enabling the callback.*/
drvSetCallbackX(unitp->spip, vspi_cb);
}
@ -100,6 +99,122 @@ void sb_sysc_vio_spi(struct port_extctx *ectxp) {
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
break;
}
case SB_VSPI_PULSES:
{
msg_t msg;
uint32_t n = ectxp->r1;
if (n == 0U) {
ectxp->r0 = CH_RET_EINVAL;
break;
}
chSysLock();
if (drvGetStateX(unitp->spip) != HAL_DRV_STATE_READY) {
msg = HAL_RET_INV_STATE;
}
else {
msg = spiStartIgnoreI(unitp->spip, n);
}
chSysUnlock();
ectxp->r0 = (uint32_t)msg;
break;
}
case SB_VSPI_RECEIVE:
{
msg_t msg;
uint32_t n = ectxp->r1;
void *rxbuf = (void *)ectxp->r2;
if (n == 0U) {
ectxp->r0 = CH_RET_EINVAL;
break;
}
if (!sb_is_valid_write_range(sbp, rxbuf, n)) { /* TODO frame size */
ectxp->r0 = (uint32_t)0;
/* TODO enforce fault instead.*/
break;
}
chSysLock();
if (drvGetStateX(unitp->spip) != HAL_DRV_STATE_READY) {
msg = HAL_RET_INV_STATE;
}
else {
msg = spiStartReceiveI(unitp->spip, n, rxbuf);
}
chSysUnlock();
ectxp->r0 = (uint32_t)msg;
break;
}
case SB_VSPI_SEND:
{
msg_t msg;
uint32_t n = ectxp->r1;
const void *txbuf = (const void *)ectxp->r2;
if (n == 0U) {
ectxp->r0 = CH_RET_EINVAL;
break;
}
if (!sb_is_valid_read_range(sbp, txbuf, n)) { /* TODO frame size */
ectxp->r0 = (uint32_t)0;
/* TODO enforce fault instead.*/
break;
}
chSysLock();
if (drvGetStateX(unitp->spip) != HAL_DRV_STATE_READY) {
msg = HAL_RET_INV_STATE;
}
else {
msg = spiStartSendI(unitp->spip, n, txbuf);
}
chSysUnlock();
ectxp->r0 = (uint32_t)msg;
break;
}
case SB_VSPI_EXCHANGE:
{
msg_t msg;
uint32_t n = ectxp->r1;
void *rxbuf = (void *)ectxp->r2;
const void *txbuf = (const void *)ectxp->r3;
if (n == 0U) {
ectxp->r0 = CH_RET_EINVAL;
break;
}
if (!sb_is_valid_write_range(sbp, rxbuf, n)) { /* TODO frame size */
ectxp->r0 = (uint32_t)0;
/* TODO enforce fault instead.*/
break;
}
if (!sb_is_valid_read_range(sbp, txbuf, n)) { /* TODO frame size */
ectxp->r0 = (uint32_t)0;
/* TODO enforce fault instead.*/
break;
}
chSysLock();
if (drvGetStateX(unitp->spip) != HAL_DRV_STATE_READY) {
msg = HAL_RET_INV_STATE;
}
else {
msg = spiStartExchangeI(unitp->spip, n, txbuf, rxbuf);
}
chSysUnlock();
ectxp->r0 = (uint32_t)msg;
break;
}
default:
ectxp->r0 = (uint32_t)CH_RET_ENOSYS;
break;