git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1181 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
df471c9756
commit
7c2813c271
44
os/io/mac.c
44
os/io/mac.c
|
@ -27,11 +27,6 @@
|
|||
#include <ch.h>
|
||||
#include <mac.h>
|
||||
|
||||
/**
|
||||
* @brief Interface status.
|
||||
*/
|
||||
static enum {ifStopped = 0, ifStarted} state;
|
||||
|
||||
/**
|
||||
* @brief Transmit descriptors counter semaphore.
|
||||
*/
|
||||
|
@ -42,12 +37,21 @@ 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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
79
os/io/phy.c
79
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) {
|
||||
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
16
os/io/phy.h
16
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
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue