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

master
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 <mac.h>
/**
* @brief Interface status.
*/
static enum {ifStopped = 0, ifStarted} state;
/**
* @brief Transmit descriptors counter semaphore.
*/
@ -39,6 +44,7 @@ void macInit(void) {
chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemInit(&rdsem, 0);
state = ifStopped;
mac_lld_init();
}
@ -62,6 +68,13 @@ void macSetAddress(uint8_t *p) {
*/
void macStart(void) {
chSysLock();
if (state == ifStarted) {
chSysUnlock();
return;
}
state = ifStarted;
chSysUnlock();
mac_lld_start();
}
@ -70,9 +83,17 @@ void macStart(void) {
*/
void macStop(void) {
max_lld_stop();
chSemReset(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemReset(&rdsem, 0);
chSysLock();
if (state == ifStopped) {
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();
if (chSemWaitTimeoutS(&tdsem, time) == RDY_OK)
tdp = max_lld_get_transmit_descriptor();
else
if ((state == ifStopped) || (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
tdp = NULL;
else
tdp = max_lld_get_transmit_descriptor();
chSysUnlock();
return tdp;
@ -111,7 +132,8 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
*/
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();
if (chSemWaitTimeoutS(&rdsem, time) == RDY_OK)
rdp = max_lld_get_receive_descriptor();
else
if ((state == ifStopped) || (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
rdp = NULL;
else
rdp = max_lld_get_receive_descriptor();
chSysUnlock();
return rdp;
@ -150,9 +172,10 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
*
* @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 macStart(void);
void macStop(void);
MACTransmissionDescriptor *macWaitTransmitDescriptor(systime_t time);
MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time);
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
void macAddTransmitData(MACTransmitDescriptor *tdp,
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) {
return NULL;
}
/**

View File

@ -34,7 +34,7 @@
/**
* @brief Number of available descriptors/buffers.
*/
#ifndef MAC_TRANSMIT_DESCRIPTORS !! defined(__DOXYGEN__)
#if !defined(MAC_TRANSMIT_DESCRIPTORS) || defined(__DOXYGEN__)
#define MAC_TRANSMIT_DESCRIPTORS 2
#endif
@ -42,9 +42,13 @@
/* Driver data structures and types. */
/*===========================================================================*/
typedef struct MACTransmitDescriptor {
typedef struct {
};
} MACTransmitDescriptor;
typedef struct {
} MACReceiveDescriptor;
/*===========================================================================*/
/* External declarations. */
@ -60,6 +64,9 @@ extern "C" {
MACTransmitDescriptor *max_lld_get_transmit_descriptor(void);
void mac_lld_release_transmit_descriptor(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
}
#endif