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

This commit is contained in:
gdisirio 2009-05-02 20:03:30 +00:00
parent ae4f143cf6
commit 83cafc020d
2 changed files with 70 additions and 100 deletions

View File

@ -30,28 +30,27 @@
static msg_t put(void *instance, uint8_t b, systime_t timeout) { static msg_t put(void *instance, uint8_t b, systime_t timeout) {
return chOQPutTimeout(&((FullDuplexDriver *)instance)->d3.oqueue, b, timeout); return chOQPutTimeout(&((FullDuplexDriver *)instance)->d2.oqueue, b, timeout);
} }
static msg_t get(void *instance, systime_t timeout) { static msg_t get(void *instance, systime_t timeout) {
return chIQGetTimeout(&((FullDuplexDriver *)instance)->d3.iqueue, timeout); return chIQGetTimeout(&((FullDuplexDriver *)instance)->d2.iqueue, timeout);
} }
static size_t write(void *instance, uint8_t *buffer, size_t n) { static size_t write(void *instance, uint8_t *buffer, size_t n) {
return chOQWrite(&((FullDuplexDriver *)instance)->d3.oqueue, buffer, n); return chOQWrite(&((FullDuplexDriver *)instance)->d2.oqueue, buffer, n);
} }
static size_t read(void *instance, uint8_t *buffer, size_t n) { static size_t read(void *instance, uint8_t *buffer, size_t n) {
return chIQRead(&((FullDuplexDriver *)instance)->d3.iqueue, buffer, n); return chIQRead(&((FullDuplexDriver *)instance)->d2.iqueue, buffer, n);
} }
static const struct FullDuplexDriverVMT vmt = { static const struct FullDuplexDriverVMT vmt = {
{put, get}, {put, get},
{write, read}, {write, read},
{},
{} {}
}; };
@ -84,8 +83,8 @@ void chFDDInit(FullDuplexDriver *sd,
chEvtInit(&sd->d1.oevent); chEvtInit(&sd->d1.oevent);
chEvtInit(&sd->d2.sevent); chEvtInit(&sd->d2.sevent);
sd->d2.flags = SD_NO_ERROR; sd->d2.flags = SD_NO_ERROR;
chIQInit(&sd->d3.iqueue, ib, isize, inotify); chIQInit(&sd->d2.iqueue, ib, isize, inotify);
chOQInit(&sd->d3.oqueue, ob, osize, onotify); chOQInit(&sd->d2.oqueue, ob, osize, onotify);
} }
/** /**
@ -98,7 +97,7 @@ void chFDDInit(FullDuplexDriver *sd,
*/ */
void chFDDIncomingDataI(FullDuplexDriver *sd, uint8_t b) { void chFDDIncomingDataI(FullDuplexDriver *sd, uint8_t b) {
if (chIQPutI(&sd->d3.iqueue, b) < Q_OK) if (chIQPutI(&sd->d2.iqueue, b) < Q_OK)
chFDDAddFlagsI(sd, SD_OVERRUN_ERROR); chFDDAddFlagsI(sd, SD_OVERRUN_ERROR);
else else
chEvtBroadcastI(&sd->d1.ievent); chEvtBroadcastI(&sd->d1.ievent);
@ -116,7 +115,7 @@ void chFDDIncomingDataI(FullDuplexDriver *sd, uint8_t b) {
*/ */
msg_t chFDDRequestDataI(FullDuplexDriver *sd) { msg_t chFDDRequestDataI(FullDuplexDriver *sd) {
msg_t b = chOQGetI(&sd->d3.oqueue); msg_t b = chOQGetI(&sd->d2.oqueue);
if (b < Q_OK) if (b < Q_OK)
chEvtBroadcastI(&sd->d1.oevent); chEvtBroadcastI(&sd->d1.oevent);
return b; return b;

View File

@ -47,72 +47,6 @@
/** Serial Driver condition flags type.*/ /** Serial Driver condition flags type.*/
typedef uint8_t dflags_t; typedef uint8_t dflags_t;
/**
* @brief @p GenericSerialDriver specific methods.
*/
struct _generic_serial_driver_methods {
};
/**
* @brief @p GenericSerialDriver specific data.
*/
struct _generic_serial_driver_data {
/**
* Status Change @p EventSource. This event is generated when one or more
* condition flags change.
*/
EventSource sevent;
/**
* I/O driver status flags.
*/
dflags_t flags;
};
/**
* @brief @p GenericSerialDriver virtual methods table.
*/
struct GenericSerialDriverVMT {
/**
* @p BaseChannel class inherited methods.
*/
struct _base_channel_methods m0;
/**
* @p BaseAsynchronousChannel class inherited methods.
*/
struct _base_asynchronous_channel_methods m1;
/**
* @p GenericSerialDriver specific methods.
*/
struct _generic_serial_driver_methods m2;
};
/**
* @extends BaseAsynchronousChannel
*
* @brief Generic serial driver class.
* @details This class extends @p BaseAsynchronousChannel by adding handling for
* serial error events.
*/
typedef struct {
/**
* Virtual Methods Table.
*/
const struct GenericSerialDriverVMT *vmt;
/**
* @p BaseChannel class inherited data.
*/
struct _base_channel_data d0;
/**
* @p BaseAsynchronousChannel class inherited data.
*/
struct _base_asynchronous_channel_data d1;
/**
* @p GenericSerialDriver specific data.
*/
struct _generic_serial_driver_data d2;
} GenericSerialDriver;
/** /**
* @brief @p FullDuplexDriver specific methods. * @brief @p FullDuplexDriver specific methods.
*/ */
@ -133,6 +67,15 @@ struct _full_duplex_driver_data {
* using the queues APIs. * using the queues APIs.
*/ */
OutputQueue oqueue; OutputQueue oqueue;
/**
* Status Change @p EventSource. This event is generated when one or more
* condition flags change.
*/
EventSource sevent;
/**
* I/O driver status flags.
*/
dflags_t flags;
}; };
/** /**
@ -147,14 +90,10 @@ struct FullDuplexDriverVMT {
* @p BaseAsynchronousChannel class inherited methods. * @p BaseAsynchronousChannel class inherited methods.
*/ */
struct _base_asynchronous_channel_methods m1; struct _base_asynchronous_channel_methods m1;
/**
* @p GenericSerialDriver specific methods.
*/
struct _generic_serial_driver_methods m2;
/** /**
* @p FullDuplexDriver specific methods. * @p FullDuplexDriver specific methods.
*/ */
struct _full_duplex_driver_methods m3; struct _full_duplex_driver_methods m2;
}; };
/** /**
@ -177,14 +116,10 @@ typedef struct {
* @p BaseAsynchronousChannel class inherited data. * @p BaseAsynchronousChannel class inherited data.
*/ */
struct _base_asynchronous_channel_data d1; struct _base_asynchronous_channel_data d1;
/**
* @p GenericSerialDriver inherited data.
*/
struct _generic_serial_driver_data d2;
/** /**
* @p FullDuplexDriver specific data. * @p FullDuplexDriver specific data.
*/ */
struct _full_duplex_driver_data d3; struct _full_duplex_driver_data d2;
} FullDuplexDriver; } FullDuplexDriver;
#ifdef __cplusplus #ifdef __cplusplus
@ -201,25 +136,61 @@ extern "C" {
} }
#endif #endif
/** @see chIQRead()*/ /**
#define chFDDRead(sd, b, n) \ * @brief Direct blocking write to a @p FullDuplexDriver.
chIQRead(&(sd)->sd_iqueue, b, n) * @details This function bypasses the indirect access to the channel and
* writes directly on the output queue. This is faster but cannot
* be used to write to different channels implementations.
* @see chIOPut()
*/
#define chFDDPut(sd, b) chOQPut(&(sd)->d2.oqueue, b)
/** @see chOQWrite()*/ /**
#define chFDDWrite(sd, b, n) \ * @brief Direct blocking write on a @p FullDuplexDriver with timeout
chOQWrite(&(sd)->sd_oqueue, b, n) * specification.
* @details This function bypasses the indirect access to the channel and
* writes directly on the output queue. This is faster but cannot
* be used to write to different channels implementations.
* @see chIOPutTimeout()
*/
#define chFDDPutTimeout(sd, b, t) chOQPutTimeout(&(sd)->d2.iqueue, b, t)
/** @see chIQGet()*/ /**
#define chFDDGet(sd) \ * @brief Direct blocking read from a @p FullDuplexDriver.
chIQGet(&(sd)->sd_iqueue) * @details This function bypasses the indirect access to the channel and
* reads directly from the input queue. This is faster but cannot
* be used to read from different channels implementations.
* @see chIOGet()
*/
#define chFDDGet(sd) chIQGet(&(sd)->d2.iqueue)
/** @see chIQGetTimeout()*/ /**
#define chFDDGetTimeout(sd, t) \ * @brief Direct blocking read from a @p FullDuplexDriver with timeout
chIQGetTimeout(&(sd)->sd_iqueue, t) * specification.
* @details This function bypasses the indirect access to the channel and
* reads directly from the input queue. This is faster but cannot
* be used to read from different channels implementations.
* @see chIOGetTimeout()
*/
#define chFDDGetTimeout(sd, t) chIQGetTimeout(&(sd)->d2.iqueue, t)
/** @see chOQPut()*/ /**
#define chFDDPut(sd, b) \ * @brief Direct non-blocking write to a @p FullDuplexDriver.
chOQPut(&(sd)->sd_oqueue, b) * @details This function bypasses the indirect access to the channel and
* writes directly to the output queue. This is faster but cannot
* be used to write from different channels implementations.
* @see chIOWrite()
*/
#define chFDDWrite(sd, b, n) chOQWrite(&(sd)->d2.oqueue, b, n)
/**
* @brief Direct non-blocking read on a @p FullDuplexDriver.
* @details This function bypasses the indirect access to the channel and
* reads directly from the input queue. This is faster but cannot
* be used to read from different channels implementations.
* @see chIORead()
*/
#define chFDDRead(sd, b, n) chIQRead(&(sd)->d2.iqueue, b, n)
#endif /* CH_USE_SERIAL_FULLDUPLEX */ #endif /* CH_USE_SERIAL_FULLDUPLEX */