From 22d2162db773e677c900b8b397889b7087470248 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 30 Aug 2011 22:52:11 +0000 Subject: RTC. Initial commit. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3269 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal.c | 3 ++ os/hal/src/rtc.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 os/hal/src/rtc.c (limited to 'os/hal/src') diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index ef7d7af8b..3c8fb2fe6 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -106,6 +106,9 @@ void halInit(void) { #endif #if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) sduInit(); +#endif +#if HAL_USE_RTC || defined(__DOXYGEN__) + rtcInit(); #endif /* Board specific initialization.*/ boardInit(); diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c new file mode 100644 index 000000000..bb0dc11f0 --- /dev/null +++ b/os/hal/src/rtc.c @@ -0,0 +1,108 @@ +/** + * @file rtc.c + * @brief Real Time Clock Abstraction Layer code. + * + * @addtogroup RTC + * @{ + */ + +#include "ch.h" +#include "hal.h" + + +#if HAL_USE_RTC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ +/** + * @brief Enable access to registers and initialize RTC if BKP doamin + * was previously reseted. + */ +void rtcInit(void){ + rtc_lld_init(); +} + +#if RTC_SUPPORTS_CALLBACKS +/** + * @brief Configure and start interrupt servicing routines. + * @param[in] rtcp - pointer to RTC driver structure. + * @param[in] rtccfgp - pointer to RTC config structure. + */ +void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp){ + chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); + rtc_lld_start(rtcp, rtccfgp); +} + +/** + * @brief Stop interrupt servicing routines. + */ +void rtcStop(void){ + rtc_lld_stop(); +} +#endif /* RTC_SUPPORTS_CALLBACKS */ + +/** + * @brief Set current time. + * @param[in] tv_sec - time value in UNIX notation. + */ +void rtcSetTime(uint32_t tv_sec){ + rtc_lld_set_time(tv_sec); +} + +/** + * @brief Return current time in UNIX notation. + */ +uint32_t rtcGetSec(void){ + return rtc_lld_get_sec(); +} + +/** + * @brief Return fractional part of current time (milliseconds). + */ +uint16_t rtcGetMsec(void){ + return rtc_lld_get_msec(); +} + +/** + * @brief Set alarm date in UNIX notation. + */ +void rtcSetAlarm(uint32_t tv_alarm){ + rtc_lld_set_alarm(tv_alarm); +} + +/** + * @brief Get current alarm date in UNIX notation. + */ +uint32_t rtcGetAlarm(void){ + return rtc_lld_get_alarm(); +} + + + + + + +#endif /* HAL_USE_RTC */ + + + +/** @} */ + + -- cgit v1.2.3 From 2991a477339a28ec275647930df45443a9f8a253 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 09:34:42 +0000 Subject: RTC. nop git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3270 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index bb0dc11f0..c6edca4a2 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -9,6 +9,7 @@ #include "ch.h" #include "hal.h" +#include "rtc_lld.h" #if HAL_USE_RTC || defined(__DOXYGEN__) @@ -45,7 +46,7 @@ void rtcInit(void){ * @param[in] rtcp - pointer to RTC driver structure. * @param[in] rtccfgp - pointer to RTC config structure. */ -void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp){ +void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); } -- cgit v1.2.3 From 3da3cc27891650180b1e725d1efb6f07005e9d3e Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 15:31:32 +0000 Subject: RTC. Copyrights added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3274 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index c6edca4a2..0db21d4d5 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** * @file rtc.c * @brief Real Time Clock Abstraction Layer code. @@ -40,12 +60,14 @@ void rtcInit(void){ rtc_lld_init(); } -#if RTC_SUPPORTS_CALLBACKS /** - * @brief Configure and start interrupt servicing routines. + * @brief Configure and start interrupt servicing routines. + * This function do nothing if callbacks disabled. + * * @param[in] rtcp - pointer to RTC driver structure. * @param[in] rtccfgp - pointer to RTC config structure. */ +#if RTC_SUPPORTS_CALLBACKS void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); @@ -95,15 +117,8 @@ uint32_t rtcGetAlarm(void){ return rtc_lld_get_alarm(); } - - - - - #endif /* HAL_USE_RTC */ - - /** @} */ -- cgit v1.2.3 From 5e62285d1745cd498f89b1a42ae4b28b3ece59a2 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 16:32:34 +0000 Subject: RTC. Final polishing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3275 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 0db21d4d5..f1aa03a34 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -92,14 +92,14 @@ void rtcSetTime(uint32_t tv_sec){ /** * @brief Return current time in UNIX notation. */ -uint32_t rtcGetSec(void){ +inline uint32_t rtcGetSec(void){ return rtc_lld_get_sec(); } /** * @brief Return fractional part of current time (milliseconds). */ -uint16_t rtcGetMsec(void){ +inline uint16_t rtcGetMsec(void){ return rtc_lld_get_msec(); } @@ -113,7 +113,7 @@ void rtcSetAlarm(uint32_t tv_alarm){ /** * @brief Get current alarm date in UNIX notation. */ -uint32_t rtcGetAlarm(void){ +inline uint32_t rtcGetAlarm(void){ return rtc_lld_get_alarm(); } -- cgit v1.2.3 From ac429a2a76727c72d6a7b8273c9643560fcd6222 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Sep 2011 18:09:40 +0000 Subject: RTC. Added state checks. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3279 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index f1aa03a34..1341bb2dd 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -68,7 +68,8 @@ void rtcInit(void){ * @param[in] rtccfgp - pointer to RTC config structure. */ #if RTC_SUPPORTS_CALLBACKS -void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ +void rtcStartI(RTCDriver *rtcp, const RTCConfig *rtccfgp){ + chDbgCheckClassI(); chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); } @@ -76,7 +77,8 @@ void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ /** * @brief Stop interrupt servicing routines. */ -void rtcStop(void){ +void rtcStopI(void){ + chDbgCheckClassI(); rtc_lld_stop(); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From c57e9ca9981e20e50630ace1656431ad84d73852 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 3 Sep 2011 08:22:04 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3285 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 1341bb2dd..bd934b11b 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -29,8 +29,6 @@ #include "ch.h" #include "hal.h" -#include "rtc_lld.h" - #if HAL_USE_RTC || defined(__DOXYGEN__) /*===========================================================================*/ -- cgit v1.2.3 From 792d85bcb5774e63100abef0125d5325312f916a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 3 Sep 2011 12:35:41 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3287 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/mac.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 11 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/mac.c b/os/hal/src/mac.c index 0f1c47576..edd15d087 100644 --- a/os/hal/src/mac.c +++ b/os/hal/src/mac.c @@ -21,8 +21,6 @@ /** * @file mac.c * @brief MAC Driver code. - * @note This function is implicitly invoked by @p halInit(), there is - * no need to explicitly initialize the driver. * * @addtogroup MAC * @{ @@ -59,6 +57,8 @@ /** * @brief MAC Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ @@ -76,28 +76,53 @@ void macInit(void) { */ void macObjectInit(MACDriver *macp) { + macp->state = MAC_STOP; + macp->config = NULL; chSemInit(&macp->tdsem, 0); chSemInit(&macp->rdsem, 0); -#if CH_USE_EVENTS +#if MAC_USE_EVENTS chEvtInit(&macp->rdevent); #endif } /** - * @brief MAC address setup. - * @pre This function must be invoked with the driver in the stopped - * state. If invoked on an active interface then it is ignored. + * @brief Configures and activates the MAC peripheral. + * + * @param[in] macp pointer to the @p MACDriver object + * @param[in] config pointer to the @p MACConfig object + * + * @api + */ +void macStart(MACDriver *macp, const MACConfig *config) { + + chDbgCheck((macp != NULL) && (config != NULL), "macStart"); + + chSysLock(); + chDbgAssert(macp->state == MAC_STOP, + "macStart(), #1", "invalid state"); + macp->config = config; + mac_lld_start(macp); + macp->state = MAC_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deactivates the MAC peripheral. * * @param[in] macp pointer to the @p MACDriver object - * @param[in] p pointer to a six bytes buffer containing the MAC - * address. If this parameter is set to @p NULL then MAC - * a system default is used. * * @api */ -void macSetAddress(MACDriver *macp, const uint8_t *p) { +void macStop(MACDriver *macp) { + + chDbgCheck(macp != NULL, "macStop"); - mac_lld_set_address(macp, p); + chSysLock(); + chDbgAssert((macp->state == MAC_STOP) || (macp->state == MAC_ACTIVE), + "macStop(), #1", "invalid state"); + mac_lld_stop(macp); + macp->state = MAC_STOP; + chSysUnlock(); } /** @@ -124,6 +149,10 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, systime_t time) { msg_t msg; + chDbgCheck((macp != NULL) && (tdp != NULL), "macWaitTransmitDescriptor"); + chDbgAssert(macp->state == MAC_ACTIVE, "macWaitTransmitDescriptor(), #1", + "not active"); + while (((msg = max_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && (time > 0)) { chSysLock(); @@ -149,6 +178,8 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp, */ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { + chDbgCheck((tdp != NULL), "macReleaseTransmitDescriptor"); + mac_lld_release_transmit_descriptor(tdp); } @@ -176,6 +207,10 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, systime_t time) { msg_t msg; + chDbgCheck((macp != NULL) && (rdp != NULL), "macWaitReceiveDescriptor"); + chDbgAssert(macp->state == MAC_ACTIVE, "macWaitReceiveDescriptor(), #1", + "not active"); + while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) && (time > 0)) { chSysLock(); @@ -202,6 +237,8 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp, */ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { + chDbgCheck((rdp != NULL), "macReleaseReceiveDescriptor"); + mac_lld_release_receive_descriptor(rdp); } @@ -217,6 +254,10 @@ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) { */ bool_t macPollLinkStatus(MACDriver *macp) { + chDbgCheck((macp != NULL), "macPollLinkStatus"); + chDbgAssert(macp->state == MAC_ACTIVE, "macPollLinkStatus(), #1", + "not active"); + return mac_lld_poll_link_status(macp); } -- cgit v1.2.3 From d15f612b861af72fffb8ee2e4f3b95e991bfcf10 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 3 Sep 2011 18:25:04 +0000 Subject: RTC. Tiny improvement in documentation. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3288 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index bd934b11b..8f9025364 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -53,6 +53,9 @@ /** * @brief Enable access to registers and initialize RTC if BKP doamin * was previously reseted. + * + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. */ void rtcInit(void){ rtc_lld_init(); -- cgit v1.2.3 From d0771593893ef9f8a9ae4ab689c569b88e3631a9 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Sep 2011 12:53:27 +0000 Subject: RTC. rtcStart() and rtcStop() functions replaced by rtcSetCallback() git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3293 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 8f9025364..ab916cf52 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -61,26 +61,23 @@ void rtcInit(void){ rtc_lld_init(); } +#if RTC_SUPPORTS_CALLBACKS /** - * @brief Configure and start interrupt servicing routines. - * This function do nothing if callbacks disabled. + * @brief Enables and disables callbacks on the fly. + * @details Pass callback function(s) in argument(s) to enable callback(s). + * Pass NULL to disable callback. + * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS + * to @p TRUE. * * @param[in] rtcp - pointer to RTC driver structure. - * @param[in] rtccfgp - pointer to RTC config structure. - */ -#if RTC_SUPPORTS_CALLBACKS -void rtcStartI(RTCDriver *rtcp, const RTCConfig *rtccfgp){ - chDbgCheckClassI(); - chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); - rtc_lld_start(rtcp, rtccfgp); -} - -/** - * @brief Stop interrupt servicing routines. + * @param[in] overflowcb - overflow callback function. + * @param[in] secondcb - every second callback function. + * @param[in] alarmcb - alarm callback function. */ -void rtcStopI(void){ - chDbgCheckClassI(); - rtc_lld_stop(); +void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, + rtccb_t secondcb, rtccb_t alarmcb){ + chDbgCheck((rtcp != NULL), "rtcStart"); + rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From a08f38d06c5dabf25751bac2deb4259e67fac530 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 11 Sep 2011 18:30:56 +0000 Subject: I2C. Remove const qualifier from pointer to I2CSlaveConfig. Step 2. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3307 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9ce2cc76f..68735b037 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -166,7 +166,7 @@ void i2cStop(I2CDriver *i2cp) { * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, + I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *txbuf, size_t txbytes, @@ -210,7 +210,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, + I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ -- cgit v1.2.3 From 7148a664b5c73138a504cd61a1882cfb91ba3b7a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 12 Sep 2011 13:40:44 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3309 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/ext.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ os/hal/src/hal.c | 3 ++ 2 files changed, 124 insertions(+) create mode 100644 os/hal/src/ext.c (limited to 'os/hal/src') diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c new file mode 100644 index 000000000..d68758684 --- /dev/null +++ b/os/hal/src/ext.c @@ -0,0 +1,121 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file ext.c + * @brief EXT Driver code. + * + * @addtogroup EXT + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_EXT || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief EXT Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void extInit(void) { + + ext_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p EXTDriver structure. + * + * @param[out] extp pointer to the @p EXTDriver object + * + * @init + */ +void extObjectInit(EXTDriver *extp) { + + extp->state = EXT_STOP; + extp->config = NULL; +} + +/** + * @brief Configures and activates the EXT peripheral. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] config pointer to the @p EXTConfig object + * + * @api + */ +void extStart(EXTDriver *extp, const EXTConfig *config) { + + chDbgCheck((extp != NULL) && (config != NULL), "extStart"); + + chSysLock(); + chDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE), + "extStart(), #1", "invalid state"); + extp->config = config; + ext_lld_start(extp); + extp->state = EXT_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deactivates the EXT peripheral. + * + * @param[in] extp pointer to the @p EXTDriver object + * + * @api + */ +void extStop(EXTDriver *extp) { + + chDbgCheck(extp != NULL, "extStop"); + + chSysLock(); + chDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE), + "extStop(), #1", "invalid state"); + ext_lld_stop(extp); + extp->state = EXT_STOP; + chSysUnlock(); +} + +#endif /* HAL_USE_EXT */ + +/** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 3c8fb2fe6..d5a8082e9 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -71,6 +71,9 @@ void halInit(void) { #if HAL_USE_CAN || defined(__DOXYGEN__) canInit(); #endif +#if HAL_USE_EXT || defined(__DOXYGEN__) + extInit(); +#endif #if HAL_USE_GPT || defined(__DOXYGEN__) gptInit(); #endif -- cgit v1.2.3 From d3e15bccfc41af4e4d3972003ff06b69de2225bc Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 12 Sep 2011 15:50:35 +0000 Subject: I2C. Revert const qualifier to the pointer to I2CSlaveConfig. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3310 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 68735b037..9ce2cc76f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -166,7 +166,7 @@ void i2cStop(I2CDriver *i2cp) { * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, - I2CSlaveConfig *i2cscfg, + const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *txbuf, size_t txbytes, @@ -210,7 +210,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, - I2CSlaveConfig *i2cscfg, + const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ -- cgit v1.2.3 From fbac4d253d67cc5b1ec39166ce1abb8124b1e3a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 13 Sep 2011 12:40:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3314 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/ext.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index d68758684..1c83cd2e6 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -78,6 +78,8 @@ void extObjectInit(EXTDriver *extp) { /** * @brief Configures and activates the EXT peripheral. + * @post After activation all EXT channels are in the disabled state, + * use @p extChannelEnable() in order to activate them. * * @param[in] extp pointer to the @p EXTDriver object * @param[in] config pointer to the @p EXTConfig object @@ -116,6 +118,50 @@ void extStop(EXTDriver *extp) { chSysUnlock(); } +/** + * @brief Enables an EXT channel. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be enabled + * + * @api + */ +void extChannelEnable(EXTDriver *extp, expchannel_t channel) { + + chDbgCheck((extp != NULL) && + (channel < EXT_MAX_CHANNELS) && + (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED), + "extChannelEnable"); + + chSysLock(); + chDbgAssert(extp->state == EXT_ACTIVE, + "extChannelEnable(), #1", "invalid state"); + extChannelEnableI(extp, channel); + chSysUnlock(); +} + +/** + * @brief Disables an EXT channel. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be disabled + * + * @api + */ +void extChannelDisable(EXTDriver *extp, expchannel_t channel) { + + chDbgCheck((extp != NULL) && + (channel < EXT_MAX_CHANNELS) && + (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED), + "extChannelDisable"); + + chSysLock(); + chDbgAssert(extp->state == EXT_ACTIVE, + "extChannelDisable(), #1", "invalid state"); + extChannelDisableI(extp, channel); + chSysUnlock(); +} + #endif /* HAL_USE_EXT */ /** @} */ -- cgit v1.2.3 From bae85ff69f0037ae22bb9bf1fada5762f7db4292 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 19 Sep 2011 12:54:13 +0000 Subject: Fixed problem in gptPolledDelay(). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3350 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'os/hal/src') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index c677f5284..726936ca8 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -236,6 +236,7 @@ void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval) { gptp->state = GPT_ONESHOT; gpt_lld_polled_delay(gptp, interval); + gptp->state = GPT_READY; } #endif /* HAL_USE_GPT */ -- cgit v1.2.3 From 95713cae20050dd58b41f52edead1b05c1c982a2 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 21 Sep 2011 12:46:09 +0000 Subject: RTC. API cnahge. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3376 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index ab916cf52..3b4b5824b 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -90,17 +90,15 @@ void rtcSetTime(uint32_t tv_sec){ } /** - * @brief Return current time in UNIX notation. - */ -inline uint32_t rtcGetSec(void){ - return rtc_lld_get_sec(); -} - -/** - * @brief Return fractional part of current time (milliseconds). + * @brief Return return seconds since UNIX epoch. + * + * @param[in] msec pointer to variable for storing fractional part of + * time (milliseconds). + * + * @notapi */ -inline uint16_t rtcGetMsec(void){ - return rtc_lld_get_msec(); +inline uint32_t rtcGetTime(uint16_t *msec){ + return rtc_lld_get_time(msec); } /** -- cgit v1.2.3 From 4a3e3fc01ec6dfb4a710db771bee262d5dc9327e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 22 Sep 2011 14:53:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3381 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/adc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index c375818a6..08aa830f0 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -162,6 +162,8 @@ void adcStartConversion(ADCDriver *adcp, /** * @brief Starts an ADC conversion. * @details Starts an asynchronous conversion operation. + * @post The callbacks associated to the conversion group will be invoked + * on buffer fill and error events. * @note The buffer is organized as a matrix of M*N elements where M is the * channels number configured into the conversion group and N is the * buffer depth. The samples are sequentially written into the buffer @@ -185,7 +187,8 @@ void adcStartConversionI(ADCDriver *adcp, ((depth == 1) || ((depth & 1) == 0)), "adcStartConversionI"); chDbgAssert((adcp->state == ADC_READY) || - (adcp->state == ADC_COMPLETE), + (adcp->state == ADC_COMPLETE) || + (adcp->state == ADC_ERROR), "adcStartConversionI(), #1", "not ready"); adcp->samples = samples; @@ -268,6 +271,8 @@ void adcStopConversionI(ADCDriver *adcp) { * @retval RDY_RESET The conversion has been stopped using * @p acdStopConversion() or @p acdStopConversionI(), * the result buffer may contain incorrect data. + * @retval RDY_TIMEOUT The conversion has been stopped because an hardware + * error. * * @api */ -- cgit v1.2.3 From 41fd0fb5fb2d446605e7a99c11f46d7c28071500 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 25 Sep 2011 10:03:59 +0000 Subject: RTC. API changes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3405 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 3b4b5824b..0c8959ea6 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -83,36 +83,42 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, /** * @brief Set current time. - * @param[in] tv_sec - time value in UNIX notation. + * + * @param[in] timespec pointer to variable storing time. */ -void rtcSetTime(uint32_t tv_sec){ - rtc_lld_set_time(tv_sec); +void rtcSetTime(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcSetTime"); + rtc_lld_set_time(timespec); } /** - * @brief Return return seconds since UNIX epoch. - * - * @param[in] msec pointer to variable for storing fractional part of - * time (milliseconds). + * @brief Get current time. * - * @notapi + * @param[in] timespec pointer to variable storing time. */ -inline uint32_t rtcGetTime(uint16_t *msec){ - return rtc_lld_get_time(msec); +void rtcGetTime(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcGetTime"); + rtc_lld_get_time(timespec); } /** - * @brief Set alarm date in UNIX notation. + * @brief Set alarm time. + * + * @param[in] timespec pointer to variable storing time of alarm. */ -void rtcSetAlarm(uint32_t tv_alarm){ - rtc_lld_set_alarm(tv_alarm); +void rtcSetAlarm(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcSetAlarm"); + rtc_lld_set_alarm(timespec); } /** - * @brief Get current alarm date in UNIX notation. + * @brief Get current alarm. + * + * @param[in] timespec pointer to variable to store alarm time. */ -inline uint32_t rtcGetAlarm(void){ - return rtc_lld_get_alarm(); +void rtcGetAlarm(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcGetAlarm"); + rtc_lld_get_alarm(timespec); } #endif /* HAL_USE_RTC */ -- cgit v1.2.3 From 0af85bab42eda2d80ce6efd2a0c1f5a94bad5f34 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 25 Sep 2011 10:32:39 +0000 Subject: RTC. Test updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3408 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 0c8959ea6..17c83f4b3 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -76,7 +76,7 @@ void rtcInit(void){ */ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, rtccb_t secondcb, rtccb_t alarmcb){ - chDbgCheck((rtcp != NULL), "rtcStart"); + chDbgCheck((rtcp != NULL), "rtcSetCallback"); rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3 From d2fa0e3fdee679a6cdd5dd6616aca527eca3f080 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 26 Sep 2011 08:23:10 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3412 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 65 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 17c83f4b3..24ccce84e 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -20,7 +20,7 @@ /** * @file rtc.c - * @brief Real Time Clock Abstraction Layer code. + * @brief RTC Driver code. * * @addtogroup RTC * @{ @@ -50,74 +50,85 @@ /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ + /** - * @brief Enable access to registers and initialize RTC if BKP doamin - * was previously reseted. - * + * @brief Enable access to registers and initialize RTC if BKP domain + * was previously reset. * @note This function is implicitly invoked by @p halInit(), there is * no need to explicitly initialize the driver. + * + * @init */ -void rtcInit(void){ +void rtcInit(void) { rtc_lld_init(); } -#if RTC_SUPPORTS_CALLBACKS +#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** - * @brief Enables and disables callbacks on the fly. - * @details Pass callback function(s) in argument(s) to enable callback(s). - * Pass NULL to disable callback. - * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS - * to @p TRUE. + * @brief Enables or disables callbacks. + * @details This function enables or disables callbacks, use a @p NULL pointer + * in order to disable a callback. + * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS + * to @p TRUE. * - * @param[in] rtcp - pointer to RTC driver structure. - * @param[in] overflowcb - overflow callback function. - * @param[in] secondcb - every second callback function. - * @param[in] alarmcb - alarm callback function. + * @param[in] rtcp pointer to RTC driver structure + * @param[in] overflowcb overflow callback function + * @param[in] secondcb every second callback function + * @param[in] alarmcb alarm callback function */ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, - rtccb_t secondcb, rtccb_t alarmcb){ + rtccb_t secondcb, rtccb_t alarmcb) { + chDbgCheck((rtcp != NULL), "rtcSetCallback"); + rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); } #endif /* RTC_SUPPORTS_CALLBACKS */ /** - * @brief Set current time. + * @brief Set current time. * - * @param[in] timespec pointer to variable storing time. + * @param[in] timespec pointer to a @p RTCDateTime structure */ -void rtcSetTime(RTCDateTime *timespec){ +void rtcSetTime(RTCDateTime *timespec) { + chDbgCheck((timespec != NULL), "rtcSetTime"); + rtc_lld_set_time(timespec); } /** - * @brief Get current time. + * @brief Get current time. * - * @param[in] timespec pointer to variable storing time. + * @param[in] timespec pointer to a @p RTCDateTime structure */ -void rtcGetTime(RTCDateTime *timespec){ +void rtcGetTime(RTCDateTime *timespec) { + chDbgCheck((timespec != NULL), "rtcGetTime"); rtc_lld_get_time(timespec); } /** - * @brief Set alarm time. + * @brief Set alarm time. * - * @param[in] timespec pointer to variable storing time of alarm. + * @param[in] timespec pointer to a @p RTCDateTime structure */ -void rtcSetAlarm(RTCDateTime *timespec){ +void rtcSetAlarm(RTCDateTime *timespec) { + chDbgCheck((timespec != NULL), "rtcSetAlarm"); + rtc_lld_set_alarm(timespec); } /** - * @brief Get current alarm. + * @brief Get current alarm. * - * @param[in] timespec pointer to variable to store alarm time. + * @param[in] timespec pointer to a @p RTCDateTime structure */ void rtcGetAlarm(RTCDateTime *timespec){ + chDbgCheck((timespec != NULL), "rtcGetAlarm"); + rtc_lld_get_alarm(timespec); } -- cgit v1.2.3 From 2950a0a7b8316a742a7a67b5acb4f224a98397ff Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 1 Oct 2011 08:04:14 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3413 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/rtc.c | 95 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 38 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 24ccce84e..dda5a9c95 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -52,88 +52,107 @@ /*===========================================================================*/ /** - * @brief Enable access to registers and initialize RTC if BKP domain - * was previously reset. + * @brief RTC Driver initialization. * @note This function is implicitly invoked by @p halInit(), there is * no need to explicitly initialize the driver. * * @init */ void rtcInit(void) { + rtc_lld_init(); } -#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** - * @brief Enables or disables callbacks. - * @details This function enables or disables callbacks, use a @p NULL pointer - * in order to disable a callback. - * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS - * to @p TRUE. + * @brief Set current time. * * @param[in] rtcp pointer to RTC driver structure - * @param[in] overflowcb overflow callback function - * @param[in] secondcb every second callback function - * @param[in] alarmcb alarm callback function + * @param[in] timespec pointer to a @p RTCTime structure + * + * @api */ -void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, - rtccb_t secondcb, rtccb_t alarmcb) { +void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec) { - chDbgCheck((rtcp != NULL), "rtcSetCallback"); + chDbgCheck((rtcp != NULL) && (timespec != NULL), "rtcSetTime"); - rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); + rtc_lld_set_time(rtcp, timespec); } -#endif /* RTC_SUPPORTS_CALLBACKS */ /** - * @brief Set current time. + * @brief Get current time. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[out] timespec pointer to a @p RTCTime structure * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcSetTime(RTCDateTime *timespec) { +void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec) { - chDbgCheck((timespec != NULL), "rtcSetTime"); + chDbgCheck((rtcp != NULL) && (timespec != NULL), "rtcGetTime"); - rtc_lld_set_time(timespec); + rtc_lld_get_time(rtcp, timespec); } +#if (RTC_ALARMS > 0) || defined(__DOXYGEN__) /** - * @brief Get current time. + * @brief Set alarm time. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier + * @param[in] alarmspec pointer to a @p RTCAlarm structure or @p NULL * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcGetTime(RTCDateTime *timespec) { +void rtcSetAlarm(RTCDriver *rtcp, + rtcalarm_t alarm, + const RTCAlarm *alarmspec) { - chDbgCheck((timespec != NULL), "rtcGetTime"); - rtc_lld_get_time(timespec); + chDbgCheck((rtcp != NULL) && (alarm < RTC_ALARMS), "rtcSetAlarm"); + + rtc_lld_set_alarm(rtcp, alarm, alarmspec); } /** - * @brief Set alarm time. + * @brief Get current alarm. + * @note If an alarm has not been set then the returned alarm specification + * is not meaningful. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier + * @param[out] alarmspec pointer to a @p RTCAlarm structure * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcSetAlarm(RTCDateTime *timespec) { +void rtcGetAlarm(RTCDriver *rtcp, + rtcalarm_t alarm, + RTCAlarm *alarmspec) { - chDbgCheck((timespec != NULL), "rtcSetAlarm"); + chDbgCheck((rtcp != NULL) && (alarm < RTC_ALARMS) && (alarmspec != NULL), + "rtcGetAlarm"); - rtc_lld_set_alarm(timespec); + rtc_lld_get_alarm(rtcp, alarm, alarmspec); } +#endif /* RTC_ALARMS > 0 */ +#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__) /** - * @brief Get current alarm. + * @brief Enables or disables RTC callbacks. + * @details This function enables or disables callbacks, use a @p NULL pointer + * in order to disable a callback. + * + * @param[in] rtcp pointer to RTC driver structure + * @param[in] callback callback function pointer or @p NULL * - * @param[in] timespec pointer to a @p RTCDateTime structure + * @api */ -void rtcGetAlarm(RTCDateTime *timespec){ +void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) { - chDbgCheck((timespec != NULL), "rtcGetAlarm"); + chDbgCheck((rtcp != NULL), "rtcSetCallback"); - rtc_lld_get_alarm(timespec); + rtc_lld_set_callback(rtcp, callback); } +#endif /* RTC_SUPPORTS_CALLBACKS */ #endif /* HAL_USE_RTC */ /** @} */ - - -- cgit v1.2.3 From 309b1e411426e8d36d9a552ef2870da3db912a80 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 23 Oct 2011 11:39:45 +0000 Subject: Improvements to the USB driver, first phase. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3449 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 91 +++++++++++++++++++++++++--------------- os/hal/src/usb.c | 107 ++++++++++-------------------------------------- 2 files changed, 78 insertions(+), 120 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 16822502a..ea434b197 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -118,21 +118,26 @@ static const struct SerialUSBDriverVMT vmt = { */ static void inotify(GenericQueue *qp) { SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr; - size_t n; /* Writes to the input queue can only happen when the queue has been emptied, then a whole packet is loaded in the queue.*/ - if (chIQIsEmptyI(&sdup->iqueue)) { - - n = usbReadPacketI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP, - sdup->iqueue.q_buffer, SERIAL_USB_BUFFERS_SIZE); - if (n != USB_ENDPOINT_BUSY) { - chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - sdup->iqueue.q_counter = n; - while (notempty(&sdup->iqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; - } + if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) && + chIQIsEmptyI(&sdup->iqueue)) { + chSysUnlock(); + + /* Unlocked to make the potentially long read operation preemptable.*/ + size_t n = usbReadPacketBuffer(sdup->config->usbp, + USB_CDC_DATA_AVAILABLE_EP, + sdup->iqueue.q_buffer, + SERIAL_USB_BUFFERS_SIZE); + + chSysLock(); + usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); + chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + sdup->iqueue.q_counter = n; + while (notempty(&sdup->iqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } } @@ -141,14 +146,20 @@ static void inotify(GenericQueue *qp) { */ static void onotify(GenericQueue *qp) { SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr; - size_t w, n; + size_t n; /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); - w = usbWritePacketI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP, - sdup->oqueue.q_buffer, n); - if (w != USB_ENDPOINT_BUSY) { + if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP)) { + chSysUnlock(); + + /* Unlocked to make the potentially long write operation preemptable.*/ + usbWritePacketBuffer(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP, + sdup->oqueue.q_buffer, n); + + chSysLock(); + usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP); chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); @@ -285,21 +296,27 @@ bool_t sduRequestsHook(USBDriver *usbp) { */ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { SerialUSBDriver *sdup = usbp->param; - size_t n, w; + size_t n; chSysLockFromIsr(); /* If there is any data in the output queue then it is sent within a single packet and the queue is emptied.*/ n = chOQGetFullI(&sdup->oqueue); if (n > 0) { - w = usbWritePacketI(usbp, ep, sdup->oqueue.q_buffer, n); - if (w != USB_ENDPOINT_BUSY) { - chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); - sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; - sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); - while (notempty(&sdup->oqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; - } + /* The endpoint cannot be busy, we are in the context of the callback, + so it is safe to transmit without a check.*/ + chSysUnlockFromIsr(); + + /* Unlocked to make the potentially long write operation preemptable.*/ + usbWritePacketBuffer(usbp, ep, sdup->oqueue.q_buffer, n); + + chSysLockFromIsr(); + usbStartTransmitI(usbp, ep); + chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); + sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; + sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue); + while (notempty(&sdup->oqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; } chSysUnlockFromIsr(); } @@ -319,17 +336,23 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) { /* Writes to the input queue can only happen when the queue has been emptied, then a whole packet is loaded in the queue.*/ if (chIQIsEmptyI(&sdup->iqueue)) { + /* The endpoint cannot be busy, we are in the context of the callback, + so a packet is in the buffer for sure.*/ size_t n; - n = usbReadPacketI(usbp, ep, sdup->iqueue.q_buffer, - SERIAL_USB_BUFFERS_SIZE); - if (n != USB_ENDPOINT_BUSY) { - chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); - sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; - sdup->iqueue.q_counter = n; - while (notempty(&sdup->iqueue.q_waiting)) - chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; - } + chSysUnlockFromIsr(); + + /* Unlocked to make the potentially long write operation preemptable.*/ + n = usbReadPacketBuffer(usbp, ep, sdup->iqueue.q_buffer, + SERIAL_USB_BUFFERS_SIZE); + + chSysLockFromIsr(); + usbStartReceiveI(usbp, ep); + chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); + sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; + sdup->iqueue.q_counter = n; + while (notempty(&sdup->iqueue.q_waiting)) + chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; } chSysUnlockFromIsr(); } diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 44a772ab1..30919580c 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -309,7 +309,7 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep, chDbgCheck((usbp != NULL) && (epcp != NULL), "usbInitEndpointI"); chDbgAssert(usbp->state == USB_ACTIVE, "usbEnableEndpointI(), #1", "invalid state"); - chDbgAssert(usbp->epc[ep] != NULL, + chDbgAssert(usbp->epc[ep] == NULL, "usbEnableEndpointI(), #2", "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ @@ -351,127 +351,55 @@ void usbDisableEndpointsI(USBDriver *usbp) { usb_lld_disable_endpoints(usbp); } -/** - * @brief Reads a packet from the dedicated packet buffer. - * @pre In order to use this function he endpoint must have been - * initialized in packet mode. - * @post The endpoint is ready to accept another packet. - * - * @param[in] usbp pointer to the @p USBDriver object - * @param[in] ep endpoint number - * @param[out] buf buffer where to copy the packet data - * @param[in] n maximum number of bytes to copy. This value must - * not exceed the maximum packet size for this endpoint. - * @return The received packet size regardless the specified - * @p n parameter. - * @retval USB_ENDPOINT_BUSY Endpoint busy receiving. - * @retval 0 Zero size packet received. - * - * @iclass - */ -size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, - uint8_t *buf, size_t n) { - - chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbReadPacketI"); - - if (usbGetReceiveStatusI(usbp, ep)) - return USB_ENDPOINT_BUSY; - - usbp->receiving |= (1 << ep); - return usb_lld_read_packet(usbp, ep, buf, n);; -} - -/** - * @brief Writes a packet to the dedicated packet buffer. - * @pre In order to use this function he endpoint must have been - * initialized in packet mode. - * @post The endpoint is ready to transmit the packet. - * - * @param[in] usbp pointer to the @p USBDriver object - * @param[in] ep endpoint number - * @param[in] buf buffer where to fetch the packet data - * @param[in] n maximum number of bytes to copy. This value must - * not exceed the maximum packet size for this endpoint. - * @return The operation status. - * @retval USB_ENDPOINT_BUSY Endpoint busy transmitting. - * @retval 0 Operation complete. - * - * @iclass - */ -size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, - const uint8_t *buf, size_t n) { - - chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbWritePacketI"); - - if (usbGetTransmitStatusI(usbp, ep)) - return USB_ENDPOINT_BUSY; - - usbp->transmitting |= (1 << ep); - usb_lld_write_packet(usbp, ep, buf, n); - return 0; -} - /** * @brief Starts a receive transaction on an OUT endpoint. - * @pre In order to use this function he endpoint must have been - * initialized in transaction mode. * @post The endpoint callback is invoked when the transfer has been * completed. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number - * @param[out] buf buffer where to copy the received data - * @param[in] n maximum number of bytes to copy * @return The operation status. * @retval FALSE Operation started successfully. * @retval TRUE Endpoint busy, operation not started. * * @iclass */ -bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, - uint8_t *buf, size_t n) { +bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep) { chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbStartReceiveI"); + chDbgCheck(usbp != NULL, "usbStartReceiveI"); if (usbGetReceiveStatusI(usbp, ep)) return TRUE; usbp->receiving |= (1 << ep); - usb_lld_start_out(usbp, ep, buf, n); + usb_lld_start_out(usbp, ep); return FALSE; } /** * @brief Starts a transmit transaction on an IN endpoint. - * @pre In order to use this function he endpoint must have been - * initialized in transaction mode. * @post The endpoint callback is invoked when the transfer has been * completed. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number - * @param[in] buf buffer where to fetch the data to be transmitted - * @param[in] n maximum number of bytes to copy * @return The operation status. * @retval FALSE Operation started successfully. * @retval TRUE Endpoint busy, operation not started. * * @iclass */ -bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, - const uint8_t *buf, size_t n) { +bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep) { chDbgCheckClassI(); - chDbgCheck((usbp != NULL) && (buf != NULL), "usbStartTransmitI"); + chDbgCheck(usbp != NULL, "usbStartTransmitI"); if (usbGetTransmitStatusI(usbp, ep)) return TRUE; usbp->transmitting |= (1 << ep); - usb_lld_start_in(usbp, ep, buf, n); + usb_lld_start_in(usbp, ep); return FALSE; } @@ -597,13 +525,15 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { if (usbp->ep0n > 0) { /* Starts the transmit phase.*/ usbp->ep0state = USB_EP0_TX; - usb_lld_start_in(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_prepare_transmit(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_start_in(usbp, 0); } else { /* No transmission phase, directly receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_start_out(usbp, 0, NULL, 0); + usb_lld_prepare_receive(usbp, 0, NULL, 0); + usb_lld_start_out(usbp, 0); } } else { @@ -611,13 +541,15 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) { if (usbp->ep0n > 0) { /* Starts the receive phase.*/ usbp->ep0state = USB_EP0_RX; - usb_lld_start_out(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_prepare_receive(usbp, 0, usbp->ep0next, usbp->ep0n); + usb_lld_start_out(usbp, 0); } else { /* No receive phase, directly sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; - usb_lld_start_in(usbp, 0, NULL, 0); + usb_lld_prepare_transmit(usbp, 0, NULL, 0); + usb_lld_start_in(usbp, 0); } } } @@ -644,13 +576,15 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) { transmitted.*/ if ((usbp->ep0n < max) && ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) { - usb_lld_start_in(usbp, 0, NULL, 0); + usb_lld_prepare_transmit(usbp, 0, NULL, 0); + usb_lld_start_in(usbp, 0); return; } /* Transmit phase over, receiving the zero sized status packet.*/ usbp->ep0state = USB_EP0_WAITING_STS; - usb_lld_start_out(usbp, 0, NULL, 0); + usb_lld_prepare_receive(usbp, 0, NULL, 0); + usb_lld_start_out(usbp, 0); return; case USB_EP0_SENDING_STS: /* Status packet sent, invoking the callback if defined.*/ @@ -687,7 +621,8 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) { case USB_EP0_RX: /* Receive phase over, sending the zero sized status packet.*/ usbp->ep0state = USB_EP0_SENDING_STS; - usb_lld_start_in(usbp, 0, NULL, 0); + usb_lld_prepare_transmit(usbp, 0, NULL, 0); + usb_lld_start_in(usbp, 0); return; case USB_EP0_WAITING_STS: /* Status packet received, it must be zero sized, invoking the callback -- cgit v1.2.3