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

This commit is contained in:
gdisirio 2009-09-27 15:00:08 +00:00
parent 85eea6f195
commit 0055ceb084
5 changed files with 49 additions and 19 deletions

View File

@ -47,8 +47,11 @@ void macInit(void) {
*/
void macObjectInit(MACDriver *macp) {
chSemInit(&macp->md_tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemInit(&macp->md_tdsem, 0);
chSemInit(&macp->md_rdsem, 0);
#if CH_USE_EVENTS
chEvtInit(&macp->md_rdevent);
#endif
}
/**
@ -88,14 +91,18 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(MACDriver *macp,
systime_t time) {
MACTransmitDescriptor *tdp;
chSysLock();
if (chSemWaitTimeoutS(&tdsem, time) != RDY_OK)
tdp = NULL;
else
tdp = max_lld_get_transmit_descriptor(macp, size);
chSysUnlock();
while ((time > 0) &&
(tdp = max_lld_get_transmit_descriptor(macp, size)) == NULL) {
chSysLock();
systime_t now = chTimeNow();
if (chSemWaitTimeoutS(&tdsem, time) == RDY_TIMEOUT) {
tdp = NULL;
break;
}
if (time != TIME_INFINITE)
time -= (chTimeNow() - now);
chSysUnlock();
}
return tdp;
}
@ -133,14 +140,18 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(MACDriver *macp,
systime_t time) {
MACReceiveDescriptor *rdp;
chSysLock();
if (chSemWaitTimeoutS(&rdsem, time) != RDY_OK)
rdp = NULL;
else
rdp = max_lld_get_receive_descriptor(macp, szp);
chSysUnlock();
while ((time > 0) &&
(rdp = max_lld_get_receive_descriptor(macp, szp)) == NULL) {
chSysLock();
systime_t now = chTimeNow();
if (chSemWaitTimeoutS(&rdsem, time) == RDY_TIMEOUT) {
rdp = NULL;
break;
}
if (time != TIME_INFINITE)
time -= (chTimeNow() - now);
chSysUnlock();
}
return rdp;
}

View File

@ -45,6 +45,16 @@
*/
#define macGetReceiveBuffer(rdp) mac_lld_get_receive_buffer(rdp)
/**
* @bief Returns the received frames event source.
*
* @param[in] macp pointer to the @p MACDriver object
* @return The pointer to the @p EventSource structure.
*/
#if CH_USE_EVENTS || defined(__DOXYGEN__)
#define macGetReceiveEventSource(macp) (&(macp)->md_rdevent)
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -82,7 +82,10 @@ static void serve_interrupt(void) {
if ((isr & AT91C_EMAC_RCOMP) || (rsr & RSR_BITS)) {
if (rsr & AT91C_EMAC_REC) {
chSysLockFromIsr();
chSemSignalI(&MAC1.md_rdsem);
chSemResetI(&MAC1.md_rdsem, 0);
#if CH_USE_EVENTS
chEvtBroadcast(&MAC1.md_rdevent);
#endif
chSysUnlockFromIsr();
}
AT91C_BASE_EMAC->EMAC_RSR = RSR_BITS;
@ -91,7 +94,7 @@ static void serve_interrupt(void) {
if ((isr & AT91C_EMAC_TCOMP) || (tsr & TSR_BITS)) {
if (tsr & AT91C_EMAC_COMP) {
chSysLockFromIsr();
chSemSignalI(&MAC1.md_tdsem);
chSemResetI(&MAC1.md_tdsem, 0);
chSysUnlockFromIsr();
}
AT91C_BASE_EMAC->EMAC_TSR = TSR_BITS;

View File

@ -100,6 +100,9 @@
typedef struct {
Semaphore md_tdsem; /**< Transmit semaphore.*/
Semaphore md_rdsem; /**< Receive semaphore.*/
#if CH_USE_EVENTS
EventSource md_rdevent; /**< Receive event source.*/
#endif
} MACDriver;
/**

View File

@ -48,6 +48,9 @@
typedef struct {
Semaphore md_tdsem; /**< Transmit semaphore.*/
Semaphore md_rdsem; /**< Receive semaphore.*/
#if CH_USE_EVENTS
EventSource md_rdevent; /**< Receive event source.*/
#endif
} MACDriver;
/**