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