diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-27 15:00:08 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-27 15:00:08 +0000 |
commit | 0055ceb084f7b91d039b189c19c257f0fae63ce9 (patch) | |
tree | 195941ce73345f0f33ac1a1ecdfefdb289414456 /os/io | |
parent | 85eea6f1955d3aed6a2c7f2ae38cf48902973edf (diff) | |
download | ChibiOS-0055ceb084f7b91d039b189c19c257f0fae63ce9.tar.gz ChibiOS-0055ceb084f7b91d039b189c19c257f0fae63ce9.tar.bz2 ChibiOS-0055ceb084f7b91d039b189c19c257f0fae63ce9.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1189 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io')
-rw-r--r-- | os/io/mac.c | 45 | ||||
-rw-r--r-- | os/io/mac.h | 10 | ||||
-rw-r--r-- | os/io/platforms/AT91SAM7X/mac_lld.c | 7 | ||||
-rw-r--r-- | os/io/platforms/AT91SAM7X/mac_lld.h | 3 | ||||
-rw-r--r-- | os/io/templates/mac_lld.h | 3 |
5 files changed, 49 insertions, 19 deletions
diff --git a/os/io/mac.c b/os/io/mac.c index af6d556a3..0a2736458 100644 --- a/os/io/mac.c +++ b/os/io/mac.c @@ -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;
}
diff --git a/os/io/mac.h b/os/io/mac.h index b652fe74d..1cb135297 100644 --- a/os/io/mac.h +++ b/os/io/mac.h @@ -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
diff --git a/os/io/platforms/AT91SAM7X/mac_lld.c b/os/io/platforms/AT91SAM7X/mac_lld.c index ebaed4e9c..916a125f0 100644 --- a/os/io/platforms/AT91SAM7X/mac_lld.c +++ b/os/io/platforms/AT91SAM7X/mac_lld.c @@ -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;
diff --git a/os/io/platforms/AT91SAM7X/mac_lld.h b/os/io/platforms/AT91SAM7X/mac_lld.h index a3ba3decd..e038a43d7 100644 --- a/os/io/platforms/AT91SAM7X/mac_lld.h +++ b/os/io/platforms/AT91SAM7X/mac_lld.h @@ -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;
/**
diff --git a/os/io/templates/mac_lld.h b/os/io/templates/mac_lld.h index 3ab322b5c..a01bf845e 100644 --- a/os/io/templates/mac_lld.h +++ b/os/io/templates/mac_lld.h @@ -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;
/**
|