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

This commit is contained in:
Giovanni Di Sirio 2021-10-17 13:36:49 +00:00
parent f83396ec38
commit ff2b03c863
3 changed files with 150 additions and 98 deletions

View File

@ -48,8 +48,11 @@
* @name SPI-specific messages * @name SPI-specific messages
* @{ * @{
*/ */
#define MSG_SPI_BUFFER_FULL MSG_OK
#define MSG_SPI_BUFFER_HALF (msg_t)-3 #define MSG_SPI_BUFFER_HALF (msg_t)-3
#define MSG_SPI_BUFFER_FULL (msg_t)-4
#define MSG_SPI_COMPLETE MSG_OK
#define MSG_SPI_TIMEOUT MSG_TIMEOUT
#define MSG_SPI_STOPPED MSG_RESET
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/
@ -152,8 +155,8 @@ typedef struct hal_spi_config SPIConfig;
/** /**
* @brief SPI notification callback type. * @brief SPI notification callback type.
* *
* @param[in] spip pointer to the @p SPIDriver object triggering the * @param[in] spip pointer to the @p SPIDriver object
* callback * triggering the callback
*/ */
typedef void (*spicb_t)(SPIDriver *spip); typedef void (*spicb_t)(SPIDriver *spip);
@ -271,10 +274,10 @@ struct hal_spi_driver {
* *
* @param[in] spip pointer to the @p SPIDriver object * @param[in] spip pointer to the @p SPIDriver object
* @return The buffer state. * @return The buffer state.
* @retval false if the driver filled/sent the first half of the * @retval false if the driver filled/sent the first half of
* buffer. * the buffer.
* @retval true if the driver filled/sent the second half of the * @retval true if the driver filled/sent the second half of
* buffer. * the buffer.
* *
* @special * @special
*/ */
@ -382,6 +385,33 @@ do { \
#define __spi_wakeup_isr(spip) #define __spi_wakeup_isr(spip)
#endif /* !SPI_USE_SYNCHRONIZATION */ #endif /* !SPI_USE_SYNCHRONIZATION */
/**
* @brief Common ISR code in linear mode.
* @details This code handles the portable part of the ISR code:
* - Callback invocation.
* - Waiting thread wakeup, if any.
* - Driver state transitions.
* .
* @note This macro is meant to be used in the low level drivers
* implementation only.
*
* @param[in] spip pointer to the @p SPIDriver object
*
* @notapi
*/
#define __spi_isr_complete_code(spip) { \
if ((spip)->config->end_cb) { \
(spip)->state = SPI_COMPLETE; \
(spip)->config->end_cb(spip); \
if ((spip)->state == SPI_COMPLETE) \
(spip)->state = SPI_READY; \
} \
else { \
(spip)->state = SPI_READY; \
} \
__spi_wakeup_isr(spip, MSG_OK); \
}
/** /**
* @brief Half buffer filled ISR code in circular mode. * @brief Half buffer filled ISR code in circular mode.
* @details This code handles the portable part of the ISR code: * @details This code handles the portable part of the ISR code:

View File

@ -155,9 +155,8 @@ static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags) {
} }
} }
else { else {
/* Portable SPI ISR code defined in the high level driver, note, it is /* Operation finished interrupt.*/
a macro.*/ __spi_isr_complete_code(spip);
__spi_isr_full_code(spip);
} }
} }

View File

@ -436,8 +436,8 @@ msg_t spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) {
* @brief Stops the ongoing SPI operation. * @brief Stops the ongoing SPI operation.
* *
* @param[in] spip pointer to the @p SPIDriver object * @param[in] spip pointer to the @p SPIDriver object
* @param[out sizep pointer to the counter of frames not yet transferred * @param[out sizep pointer to the counter of frames not yet
* or @p NULL * transferred or @p NULL
* @return The operation status. * @return The operation status.
* *
* @iclass * @iclass
@ -461,7 +461,7 @@ msg_t spiStopTranferI(SPIDriver *spip, size_t *sizep) {
spip->state = SPI_READY; spip->state = SPI_READY;
#if SPI_USE_SYNCHRONIZATION == TRUE #if SPI_USE_SYNCHRONIZATION == TRUE
osalThreadResumeI(&spip->sync_transfer, MSG_OK); osalThreadResumeI(&spip->sync_transfer, MSG_SPI_STOPPED);
#endif #endif
} }
else { else {
@ -475,8 +475,8 @@ msg_t spiStopTranferI(SPIDriver *spip, size_t *sizep) {
* @brief Stops the ongoing SPI operation, if any. * @brief Stops the ongoing SPI operation, if any.
* *
* @param[in] spip pointer to the @p SPIDriver object * @param[in] spip pointer to the @p SPIDriver object
* @param[out sizep pointer to the counter of frames not yet transferred * @param[out sizep pointer to the counter of frames not yet
* or @p NULL * transferred or @p NULL
* @return The operation status. * @return The operation status.
* *
* @api * @api
@ -502,8 +502,13 @@ msg_t spiStopTranfer(SPIDriver *spip, size_t *sizep) {
* @param[in] spip pointer to the @p SPIDriver object * @param[in] spip pointer to the @p SPIDriver object
* @param[in] timeout synchronization timeout * @param[in] timeout synchronization timeout
* @return The synchronization result. * @return The synchronization result.
* @retval MSG_OK if TX operation finished. * @retval MSG_SPI_COMPLETE if operation completed without errors.
* @retval MSG_TIMEOUT if synchronization timed out. * @retval MSG_SPI_TIMEOUT if synchronization timed out.
* @retval MSG_SPI_STOPPED if the transfer has been stopped.
* @retval MSG_SPI_BUFFER_FULL if operation finished on buffer full (circular
* mode only).
* @retval MSG_SPI_BUFFER_HALF if operation finished on buffer half (circular
* mode only).
* *
* @sclass * @sclass
*/ */
@ -518,7 +523,7 @@ msg_t spiSynchronizeS(SPIDriver *spip, sysinterval_t timeout) {
msg = osalThreadSuspendTimeoutS(&spip->sync_transfer, timeout); msg = osalThreadSuspendTimeoutS(&spip->sync_transfer, timeout);
} }
else { else {
msg = MSG_OK; msg = MSG_SPI_COMPLETE;
} }
return msg; return msg;
@ -531,8 +536,13 @@ msg_t spiSynchronizeS(SPIDriver *spip, sysinterval_t timeout) {
* @param[in] spip pointer to the @p SPIDriver object * @param[in] spip pointer to the @p SPIDriver object
* @param[in] timeout synchronization timeout * @param[in] timeout synchronization timeout
* @return The synchronization result. * @return The synchronization result.
* @retval MSG_OK if TX operation finished. * @retval MSG_SPI_COMPLETE if operation completed without errors.
* @retval MSG_TIMEOUT if synchronization timed out. * @retval MSG_SPI_TIMEOUT if synchronization timed out.
* @retval MSG_SPI_STOPPED if the transfer has been stopped.
* @retval MSG_SPI_BUFFER_FULL if operation finished on buffer full (circular
* mode only).
* @retval MSG_SPI_BUFFER_HALF if operation finished on buffer half (circular
* mode only).
* *
* @api * @api
*/ */
@ -556,6 +566,9 @@ msg_t spiSynchronize(SPIDriver *spip, sysinterval_t timeout) {
* @param[in] spip pointer to the @p SPIDriver object * @param[in] spip pointer to the @p SPIDriver object
* @param[in] n number of words to be ignored * @param[in] n number of words to be ignored
* @return The operation status. * @return The operation status.
* @retval MSG_SPI_COMPLETE if operation completed without errors.
* @retval MSG_SPI_TIMEOUT if synchronization timed out.
* @retval MSG_SPI_STOPPED if the transfer has been stopped.
* *
* @api * @api
*/ */
@ -588,6 +601,10 @@ msg_t spiIgnore(SPIDriver *spip, size_t n) {
* @param[in] txbuf the pointer to the transmit buffer * @param[in] txbuf the pointer to the transmit buffer
* @param[out] rxbuf the pointer to the receive buffer * @param[out] rxbuf the pointer to the receive buffer
* @return The operation status. * @return The operation status.
* @retval MSG_SPI_COMPLETE if operation completed without errors.
* mode only).
* @retval MSG_SPI_TIMEOUT if synchronization timed out.
* @retval MSG_SPI_STOPPED if the transfer has been stopped.
* *
* @api * @api
*/ */
@ -619,6 +636,9 @@ msg_t spiExchange(SPIDriver *spip, size_t n,
* @param[in] n number of words to send * @param[in] n number of words to send
* @param[in] txbuf the pointer to the transmit buffer * @param[in] txbuf the pointer to the transmit buffer
* @return The operation status. * @return The operation status.
* @retval MSG_SPI_COMPLETE if operation completed without errors.
* @retval MSG_SPI_TIMEOUT if synchronization timed out.
* @retval MSG_SPI_STOPPED if the transfer has been stopped.
* *
* @api * @api
*/ */
@ -649,6 +669,9 @@ msg_t spiSend(SPIDriver *spip, size_t n, const void *txbuf) {
* @param[in] n number of words to receive * @param[in] n number of words to receive
* @param[out] rxbuf the pointer to the receive buffer * @param[out] rxbuf the pointer to the receive buffer
* @return The operation status. * @return The operation status.
* @retval MSG_SPI_COMPLETE if operation completed without errors.
* @retval MSG_SPI_TIMEOUT if synchronization timed out.
* @retval MSG_SPI_STOPPED if the transfer has been stopped.
* *
* @api * @api
*/ */