aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src/mac.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-03 12:35:41 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-03 12:35:41 +0000
commit792d85bcb5774e63100abef0125d5325312f916a (patch)
tree4f874b2123dcbaf591ccea388de3c3e09a0ddf51 /os/hal/src/mac.c
parent08dad7b1f54ff8eb6266e811533eecf53051249c (diff)
downloadChibiOS-792d85bcb5774e63100abef0125d5325312f916a.tar.gz
ChibiOS-792d85bcb5774e63100abef0125d5325312f916a.tar.bz2
ChibiOS-792d85bcb5774e63100abef0125d5325312f916a.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3287 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/src/mac.c')
-rw-r--r--os/hal/src/mac.c63
1 files changed, 52 insertions, 11 deletions
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);
}