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

master
gdisirio 2009-09-24 18:43:09 +00:00
parent 1a62b44848
commit ac7438357d
4 changed files with 99 additions and 30 deletions

View File

@ -30,7 +30,7 @@
/**
* @brief Transmit descriptors counter semaphore.
*/
static Semaphore tdsem;
static Semaphore tdsem, rdsem;
/**
* @brief MAC Driver initialization.
@ -38,6 +38,7 @@ static Semaphore tdsem;
void macInit(void) {
chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemInit(&rdsem, 0);
mac_lld_init();
}
@ -71,6 +72,7 @@ void macStop(void) {
max_lld_stop();
chSemReset(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemReset(&rdsem, 0);
}
/**
@ -80,14 +82,14 @@ void macStop(void) {
* invoking thread is queued until one is freed.
*
* @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* @return A pointer to a @p MACTransmitDescriptor structure or @p NULL if
* the operation timed out or the driver went in stop mode.
*/
MACTransmitDescriptor *macGetTransmitDescriptor(systime_t time) {
MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
MACTransmitDescriptor *tdp;
chSysLock();
@ -109,25 +111,48 @@ MACTransmitDescriptor *macGetTransmitDescriptor(systime_t time) {
*/
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
chSysLock();
mac_lld_release_transmit_descriptor(tdp);
chSysUnlock();
}
/**
* @brief Enqueues data to a @p MACTransmitDescriptor.
*
* @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
* @param buf pointer to the data buffer
* @param size size of the data to be enqueued
* @brief Waits for a received frame.
* @details Stops until a frame is received and buffered. If a frame is
* not immediately available then the invoking thread is queued
* until one is received.
*
* @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* @return A pointer to a @p MACReceiveDescriptor structure or @p NULL if
* the operation timed out, the driver went in stop mode or some
* transient error happened.
*/
void macAddTransmitData(MACTransmitDescriptor *tdp,
uint8_t *buf,
size_t size) {
MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
MACReceiveDescriptor *rdp;
mac_lld_add_transmit_data(tdp, buf, size);
chSysLock();
if (chSemWaitTimeoutS(&rdsem, time) == RDY_OK)
rdp = max_lld_get_receive_descriptor();
else
rdp = NULL;
chSysUnlock();
return rdp;
}
/**
* @brief Releases a receive descriptor.
* @details The descriptor and its buffer is made available for more incoming
* frames.
*
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
*/
void macReleaseTransmitDescriptor(MACReceiveDescriptor *rdp) {
mac_lld_release_receive_descriptor(rdp);
}
/** @} */

View File

@ -29,6 +29,22 @@
#include "mac_lld.h"
/**
* @brief Returns the buffer associated to a @p MACTransmitDescriptor.
*
* @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
* @return The pointer to the transmit buffer.
*/
#define macGetTransmitBuffer(tdp) mac_lld_get_transmit_buffer(tdp)
/**
* @brief Returns the buffer associated to a @p MACReceiveDescriptor.
*
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
* @return The pointer to the receive buffer.
*/
#define macGetReceiveBuffer(rdp) mac_lld_get_receive_buffer(rdp)
#ifdef __cplusplus
extern "C" {
#endif
@ -36,7 +52,7 @@ extern "C" {
void macSetAddress(uint8_t *p);
void macStart(void);
void macStop(void);
MACTransmissionDescriptor *macGetTransmitDescriptor(systime_t time);
MACTransmissionDescriptor *macWaitTransmitDescriptor(systime_t time);
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
void macAddTransmitData(MACTransmitDescriptor *tdp,
uint8_t *buf,

View File

@ -63,7 +63,7 @@ void mac_lld_stop(void) {
}
/**
* @brief Allocates a transmission descriptor.
* @brief Returns a transmission descriptor.
* @details One of the available transmission descriptors is locked and
* returned.
*
@ -86,15 +86,45 @@ void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) {
}
/**
* @brief Enqueues data to a @p MACTransmitDescriptor.
* @brief Returns the buffer associated to a @p MACTransmitDescriptor.
*
* @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
* @param buf pointer to the data buffer
* @param size size of the data to be enqueued
* @return The pointer to the transmit buffer.
*/
void mac_lld_add_transmit_data(MACTransmitDescriptor *tdp,
uint8_t *buf,
size_t size) {
uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp) {
}
/**
* @brief Returns a received frame.
*
* @return A pointer to a @p MACReceiveDescriptor structure or @p NULL if
* the operation timed out, the driver went in stop mode or some
* transient error happened.
*/
MACReceiveDescriptor *max_lld_get_receive_descriptor(void) {
return NULL;
}
/**
* @brief Releases a receive descriptor.
* @details The descriptor and its buffer is made available for more incoming
* frames.
*
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
*/
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) {
}
/**
* @brief Returns the buffer associated to a @p MACTransmitDescriptor.
*
* @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
* @return The pointer to the transmit buffer.
*/
uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp) {
}

View File

@ -59,9 +59,7 @@ extern "C" {
void mac_lld_stop(void);
MACTransmitDescriptor *max_lld_get_transmit_descriptor(void);
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp);
void mac_lld_add_transmit_data(MACTransmitDescriptor *tdp,
uint8_t *buf,
size_t size);
uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp);
#ifdef __cplusplus
}
#endif