From dd5d6d0affd6ee564836aba9e1429925d7a39d63 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 29 Aug 2017 11:30:45 +0000 Subject: Added an ioctl()-like function to the serial driver. No specific codes implemented yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10505 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal_serial.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/hal_serial.c b/os/hal/src/hal_serial.c index 22723e3e6..573b139be 100644 --- a/os/hal/src/hal_serial.c +++ b/os/hal/src/hal_serial.c @@ -89,9 +89,31 @@ static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) { return iqReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, timeout); } +static msg_t _ctl(void *ip, unsigned int operation, void *arg) { + SerialDriver *sdp = (SerialDriver *)ip; + + osalDbgCheck(sdp != NULL); + + switch (operation) { + case CHN_CTL_NOP: + osalDbgCheck(arg == NULL); + break; + default: +#if defined(SD_LLD_IMPLEMENTS_CTL) + return sd_lld_control(sdp, operation, arg); +#else + case CHN_CTL_INVALID: + osalDbgAssert(false, "invalid CTL operation"); + break; +#endif + } + return MSG_OK; +} + static const struct SerialDriverVMT vmt = { _write, _read, _put, _get, - _putt, _gett, _writet, _readt + _putt, _gett, _writet, _readt, + _ctl }; /*===========================================================================*/ @@ -298,6 +320,25 @@ bool sdGetWouldBlock(SerialDriver *sdp) { return b; } +/** + * @brief Control operation on a serial port. + * + * @param[in] sdp pointer to a @p SerialDriver object + * @param[in] operation control operation code + * @param[in,out] arg operation argument + * + * @return The control operation status. + * @retval MSG_OK in case of success. + * @retval MSG_TIMEOUT in case of operation timeout. + * @retval MSG_RESET in case of operation reset. + * + * @api + */ +msg_t sdControl(SerialDriver *sdp, unsigned int operation, void *arg) { + + return _ctl((void *)sdp, operation, arg); +} + #endif /* HAL_USE_SERIAL == TRUE */ /** @} */ -- cgit v1.2.3