git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1179 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2009-09-25 07:35:57 +00:00
parent ac7438357d
commit d107ffedee
4 changed files with 47 additions and 16 deletions

View File

@ -27,6 +27,11 @@
#include <ch.h> #include <ch.h>
#include <mac.h> #include <mac.h>
/**
* @brief Interface status.
*/
static enum {ifStopped = 0, ifStarted} state;
/** /**
* @brief Transmit descriptors counter semaphore. * @brief Transmit descriptors counter semaphore.
*/ */
@ -39,6 +44,7 @@ void macInit(void) {
chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS); chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemInit(&rdsem, 0); chSemInit(&rdsem, 0);
state = ifStopped;
mac_lld_init(); mac_lld_init();
} }
@ -62,6 +68,13 @@ void macSetAddress(uint8_t *p) {
*/ */
void macStart(void) { void macStart(void) {
chSysLock();
if (state == ifStarted) {
chSysUnlock();
return;
}
state = ifStarted;
chSysUnlock();
mac_lld_start(); mac_lld_start();
} }
@ -70,9 +83,17 @@ void macStart(void) {
*/ */
void macStop(void) { void macStop(void) {
max_lld_stop(); chSysLock();
chSemReset(&tdsem, MAC_TRANSMIT_DESCRIPTORS); if (state == ifStopped) {
chSemReset(&rdsem, 0); chSysUnlock();
return;
}
state = ifStopped;
chSemResetI(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemResetI(&rdsem, 0);
chSchRescheduleS();
chSysUnlock();
mac_lld_stop();
} }
/** /**
@ -94,10 +115,10 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
chSysLock(); chSysLock();
if (chSemWaitTimeoutS(&tdsem, time) == RDY_OK) if ((state == ifStopped) || (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
tdp = max_lld_get_transmit_descriptor();
else
tdp = NULL; tdp = NULL;
else
tdp = max_lld_get_transmit_descriptor();
chSysUnlock(); chSysUnlock();
return tdp; return tdp;
@ -111,7 +132,8 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
*/ */
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) { void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
mac_lld_release_transmit_descriptor(tdp); if (state == ifStarted)
mac_lld_release_transmit_descriptor(tdp);
} }
/** /**
@ -134,10 +156,10 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
chSysLock(); chSysLock();
if (chSemWaitTimeoutS(&rdsem, time) == RDY_OK) if ((state == ifStopped) || (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
rdp = max_lld_get_receive_descriptor();
else
rdp = NULL; rdp = NULL;
else
rdp = max_lld_get_receive_descriptor();
chSysUnlock(); chSysUnlock();
return rdp; return rdp;
@ -150,9 +172,10 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
* *
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
*/ */
void macReleaseTransmitDescriptor(MACReceiveDescriptor *rdp) { void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) {
mac_lld_release_receive_descriptor(rdp); if (state == ifStarted)
mac_lld_release_receive_descriptor(rdp);
} }
/** @} */ /** @} */

View File

@ -52,7 +52,7 @@ extern "C" {
void macSetAddress(uint8_t *p); void macSetAddress(uint8_t *p);
void macStart(void); void macStart(void);
void macStop(void); void macStop(void);
MACTransmissionDescriptor *macWaitTransmitDescriptor(systime_t time); MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time);
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp); void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
void macAddTransmitData(MACTransmitDescriptor *tdp, void macAddTransmitData(MACTransmitDescriptor *tdp,
uint8_t *buf, uint8_t *buf,

View File

@ -93,6 +93,7 @@ void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) {
*/ */
uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp) { uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp) {
return NULL;
} }
/** /**

View File

@ -34,7 +34,7 @@
/** /**
* @brief Number of available descriptors/buffers. * @brief Number of available descriptors/buffers.
*/ */
#ifndef MAC_TRANSMIT_DESCRIPTORS !! defined(__DOXYGEN__) #if !defined(MAC_TRANSMIT_DESCRIPTORS) || defined(__DOXYGEN__)
#define MAC_TRANSMIT_DESCRIPTORS 2 #define MAC_TRANSMIT_DESCRIPTORS 2
#endif #endif
@ -42,9 +42,13 @@
/* Driver data structures and types. */ /* Driver data structures and types. */
/*===========================================================================*/ /*===========================================================================*/
typedef struct MACTransmitDescriptor { typedef struct {
}; } MACTransmitDescriptor;
typedef struct {
} MACReceiveDescriptor;
/*===========================================================================*/ /*===========================================================================*/
/* External declarations. */ /* External declarations. */
@ -60,6 +64,9 @@ extern "C" {
MACTransmitDescriptor *max_lld_get_transmit_descriptor(void); MACTransmitDescriptor *max_lld_get_transmit_descriptor(void);
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp); void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp);
uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp); uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp);
MACReceiveDescriptor *max_lld_get_receive_descriptor(void);
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp);
uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif