aboutsummaryrefslogtreecommitdiffstats
path: root/os/io/mac.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-09-27 15:00:08 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-09-27 15:00:08 +0000
commit0055ceb084f7b91d039b189c19c257f0fae63ce9 (patch)
tree195941ce73345f0f33ac1a1ecdfefdb289414456 /os/io/mac.c
parent85eea6f1955d3aed6a2c7f2ae38cf48902973edf (diff)
downloadChibiOS-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/mac.c')
-rw-r--r--os/io/mac.c45
1 files changed, 28 insertions, 17 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;
}