aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/io/mac.c44
-rw-r--r--os/io/mac.h1
-rw-r--r--os/io/phy.c79
-rw-r--r--os/io/phy.h16
-rw-r--r--os/io/templates/mac_lld.h5
5 files changed, 125 insertions, 20 deletions
diff --git a/os/io/mac.c b/os/io/mac.c
index 823a1b4a7..e64f0bee0 100644
--- a/os/io/mac.c
+++ b/os/io/mac.c
@@ -28,11 +28,6 @@
#include <mac.h>
/**
- * @brief Interface status.
- */
-static enum {ifStopped = 0, ifStarted} state;
-
-/**
* @brief Transmit descriptors counter semaphore.
*/
static Semaphore tdsem, rdsem;
@@ -42,13 +37,22 @@ static Semaphore tdsem, rdsem;
*/
void macInit(void) {
- chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
- chSemInit(&rdsem, 0);
- state = ifStopped;
mac_lld_init();
}
/**
+ * @brief Initialize the standard part of a @p MACDriver structure.
+ *
+ * @param[in] macp pointer to the @p MACDriver object
+ */
+void macObjectInit(MACDriver *macp) {
+
+ chSemInit(&macp->md_tdsem, MAC_TRANSMIT_DESCRIPTORS);
+ chSemInit(&macp->md_rdsem, 0);
+ macp->md_state = ifStopped;
+}
+
+/**
* @brief MAC address setup.
*
* @param[in] macp pointer to the @p MACDriver object
@@ -61,7 +65,7 @@ void macInit(void) {
*/
void macSetAddress(MACDriver *macp, uint8_t *p) {
- if (state == ifStopped)
+ if (macp->md_state == ifStopped)
mac_lld_set_address(macp, p);
}
@@ -74,11 +78,11 @@ void macSetAddress(MACDriver *macp, uint8_t *p) {
void macStart(MACDriver *macp) {
chSysLock();
- if (state == ifStarted) {
+ if (macp->md_state == ifStarted) {
chSysUnlock();
return;
}
- state = ifStarted;
+ macp->md_state = ifStarted;
chSysUnlock();
mac_lld_start(macp);
}
@@ -91,13 +95,13 @@ void macStart(MACDriver *macp) {
void macStop(MACDriver *macp) {
chSysLock();
- if (state == ifStopped) {
+ if (macp->md_state == ifStopped) {
chSysUnlock();
return;
}
- state = ifStopped;
- chSemResetI(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
- chSemResetI(&rdsem, 0);
+ macp->md_state = ifStopped;
+ chSemResetI(&macp->md_tdsem, MAC_TRANSMIT_DESCRIPTORS);
+ chSemResetI(&macp->md_rdsem, 0);
chSchRescheduleS();
chSysUnlock();
mac_lld_stop(macp);
@@ -124,7 +128,8 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(MACDriver *macp,
chSysLock();
- if ((state == ifStopped) || (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
+ if ((macp->md_state == ifStopped) ||
+ (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
tdp = NULL;
else
tdp = max_lld_get_transmit_descriptor(macp);
@@ -143,7 +148,7 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(MACDriver *macp,
void macReleaseTransmitDescriptor(MACDriver *macp,
MACTransmitDescriptor *tdp) {
- if (state == ifStarted)
+ if (macp->md_state == ifStarted)
mac_lld_release_transmit_descriptor(macp, tdp);
}
@@ -169,7 +174,8 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(MACDriver *macp,
chSysLock();
- if ((state == ifStopped) || (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
+ if ((macp->md_state == ifStopped) ||
+ (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
rdp = NULL;
else
rdp = max_lld_get_receive_descriptor(macp);
@@ -189,7 +195,7 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(MACDriver *macp,
void macReleaseReceiveDescriptor(MACDriver *macp,
MACReceiveDescriptor *rdp) {
- if (state == ifStarted)
+ if (macp->md_state == ifStarted)
mac_lld_release_receive_descriptor(macp, rdp);
}
diff --git a/os/io/mac.h b/os/io/mac.h
index e79f29919..791b434be 100644
--- a/os/io/mac.h
+++ b/os/io/mac.h
@@ -49,6 +49,7 @@
extern "C" {
#endif
void macInit(void);
+ void macObjectInit(MACDriver *macp);
void macSetAddress(MACDriver *macp, uint8_t *p);
void macStart(MACDriver *macp);
void macStop(MACDriver *macp);
diff --git a/os/io/phy.c b/os/io/phy.c
index d03c5b1d3..7c61019dd 100644
--- a/os/io/phy.c
+++ b/os/io/phy.c
@@ -25,6 +25,85 @@
*/
#include <ch.h>
+#include <mac.h>
#include <phy.h>
+/**
+ * @brief Interface status.
+ */
+static enum {ifStopped = 0, ifStarted} state;
+
+/**
+ * @brief PHY Driver initialization.
+ */
+void phyInit(void) {
+
+ state = ifStopped;
+}
+
+/**
+ * Initializes a PHY device.
+ *
+ * @param[in] macp pointer to the @p MACDriver object
+ */
+void phyReset(MACDriver *macp) {
+
+}
+
+/**
+ * @brief Puts the PHY device in active mode.
+ *
+ * @param[in] macp pointer to the @p MACDriver object
+ */
+void phyStart(MACDriver *macp) {
+
+ chSysLock();
+ if (state == ifStarted) {
+ chSysUnlock();
+ return;
+ }
+ state = ifStarted;
+ chSysUnlock();
+ phy_lld_start(macp);
+}
+
+/**
+ * @brief Puts the PHY device in a low power mode.
+ *
+ * @param[in] macp pointer to the @p MACDriver object
+ */
+void phyStop(MACDriver *macp) {
+
+ chSysLock();
+ if (state == ifStopped) {
+ chSysUnlock();
+ return;
+ }
+ state = ifStopped;
+ chSysUnlock();
+ phy_lld_stop(macp);
+}
+
+/**
+ * @brief Reads a PHY register.
+ *
+ * @param[in] macp pointer to the @p MACDriver object
+ * @param addr the register address
+ * @return The register value.
+ */
+phyreg_t phyGet(MACDriver *macp, phyaddr_t addr) {
+
+}
+
+/**
+ * @brief Writes a PHY register.
+ *
+ * @param[in] macp pointer to the @p MACDriver object
+ * @param addr the register address
+ * @param value the new register value
+ */
+void phyPut(MACDriver *macp, phyaddr_t addr, phyreg_t value) {
+
+}
+
/** @} */
diff --git a/os/io/phy.h b/os/io/phy.h
index 7bf09b8c3..ffafa4025 100644
--- a/os/io/phy.h
+++ b/os/io/phy.h
@@ -27,12 +27,28 @@
#ifndef _PHY_H_
#define _PHY_H_
+#include "mac_lld.h"
#include "phy_lld.h"
+/**
+ * @brief Type of a PHY register value.
+ */
+typedef uint16_t phyreg_t;
+
+/**
+ * @brief Type of a PHY register address.
+ */
+typedef uint8_t phyaddr_t;
+
#ifdef __cplusplus
extern "C" {
#endif
void phyInit(void);
+ void phyReset(MACDriver *macp);
+ void phyStart(MACDriver *macp);
+ void phyStop(MACDriver *macp);
+ phyreg_t phyGet(MACDriver *macp, phyaddr_t addr);
+ void phyPut(MACDriver *macp, phyaddr_t addr, phyreg_t value);
#ifdef __cplusplus
}
#endif
diff --git a/os/io/templates/mac_lld.h b/os/io/templates/mac_lld.h
index 01889aa12..0ded4b690 100644
--- a/os/io/templates/mac_lld.h
+++ b/os/io/templates/mac_lld.h
@@ -46,7 +46,10 @@
* @brief Structure representing a MAC driver.
*/
typedef struct {
-
+ enum {ifStopped = 0,
+ ifStarted} md_state; /**< @brief Interface status.*/
+ Semaphore md_tdsem; /**< Transmit semaphore.*/
+ Semaphore md_rdsem; /**< Receive semaphore.*/
} MACDriver;
/**