mirror of https://github.com/rusefi/ChibiOS.git
Now the serial driver subsystem is a descendant class of a BaseChannel.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@936 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
fcd90e0bc8
commit
81507dcbe7
|
@ -51,12 +51,12 @@ void chFDDInit(FullDuplexDriver *sd,
|
|||
chDbgCheck((sd != NULL) && (ib != NULL) && (ob != NULL) &&
|
||||
(isize > 0) && (osize > 0), "chFDDInit");
|
||||
|
||||
chIQInit(&sd->sd_iqueue, ib, isize, inotify);
|
||||
chEvtInit(&sd->sd_ievent);
|
||||
chOQInit(&sd->sd_oqueue, ob, osize, onotify);
|
||||
chEvtInit(&sd->sd_oevent);
|
||||
chEvtInit(&sd->sd_sevent);
|
||||
sd->sd_flags = SD_NO_ERROR;
|
||||
chEvtInit(&sd->d1.ievent);
|
||||
chEvtInit(&sd->d1.oevent);
|
||||
chEvtInit(&sd->d2.sevent);
|
||||
sd->d2.flags = SD_NO_ERROR;
|
||||
chIQInit(&sd->d3.iqueue, ib, isize, inotify);
|
||||
chOQInit(&sd->d3.oqueue, ob, osize, onotify);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,10 +69,10 @@ void chFDDInit(FullDuplexDriver *sd,
|
|||
*/
|
||||
void chFDDIncomingDataI(FullDuplexDriver *sd, uint8_t b) {
|
||||
|
||||
if (chIQPutI(&sd->sd_iqueue, b) < Q_OK)
|
||||
if (chIQPutI(&sd->d3.iqueue, b) < Q_OK)
|
||||
chFDDAddFlagsI(sd, SD_OVERRUN_ERROR);
|
||||
else
|
||||
chEvtBroadcastI(&sd->sd_ievent);
|
||||
chEvtBroadcastI(&sd->d1.ievent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,9 +87,9 @@ void chFDDIncomingDataI(FullDuplexDriver *sd, uint8_t b) {
|
|||
*/
|
||||
msg_t chFDDRequestDataI(FullDuplexDriver *sd) {
|
||||
|
||||
msg_t b = chOQGetI(&sd->sd_oqueue);
|
||||
msg_t b = chOQGetI(&sd->d3.oqueue);
|
||||
if (b < Q_OK)
|
||||
chEvtBroadcastI(&sd->sd_oevent);
|
||||
chEvtBroadcastI(&sd->d1.oevent);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -103,8 +103,8 @@ msg_t chFDDRequestDataI(FullDuplexDriver *sd) {
|
|||
*/
|
||||
void chFDDAddFlagsI(FullDuplexDriver *sd, dflags_t mask) {
|
||||
|
||||
sd->sd_flags |= mask;
|
||||
chEvtBroadcastI(&sd->sd_sevent);
|
||||
sd->d2.flags |= mask;
|
||||
chEvtBroadcastI(&sd->d2.sevent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,8 +117,8 @@ void chFDDAddFlagsI(FullDuplexDriver *sd, dflags_t mask) {
|
|||
dflags_t chFDDGetAndClearFlags(FullDuplexDriver *sd) {
|
||||
dflags_t mask;
|
||||
|
||||
mask = sd->sd_flags;
|
||||
sd->sd_flags = SD_NO_ERROR;
|
||||
mask = sd->d2.flags;
|
||||
sd->d2.flags = SD_NO_ERROR;
|
||||
return mask;
|
||||
}
|
||||
#endif /* CH_USE_SERIAL_FULLDUPLEX */
|
||||
|
|
|
@ -78,7 +78,7 @@ typedef struct {
|
|||
* @retval Q_OK if the operation succeeded.
|
||||
* @retval Q_RESET if the channel associated queue (if any) was reset.
|
||||
*/
|
||||
#define chIOPut(ip, b) ((ip)->vmt.m0->put(ip, b, TIME_INFINITE))
|
||||
#define chIOPut(ip, b) ((ip)->vmt->m0.put(ip, b, TIME_INFINITE))
|
||||
|
||||
/**
|
||||
* @brief Channel blocking byte write with timeout.
|
||||
|
@ -97,7 +97,7 @@ typedef struct {
|
|||
* @retval Q_TIMEOUT if the specified time expired.
|
||||
* @retval Q_RESET if the channel associated queue (if any) was reset.
|
||||
*/
|
||||
#define chIOPutTimeout(ip, b, timeout) ((ip)->vmt.m0->put(ip, b, timeout))
|
||||
#define chIOPutTimeout(ip, b, timeout) ((ip)->vmt->m0.put(ip, b, timeout))
|
||||
|
||||
/**
|
||||
* @brief Channel blocking byte read.
|
||||
|
@ -108,7 +108,7 @@ typedef struct {
|
|||
* @return A byte value from the queue or:
|
||||
* @retval Q_RESET if the channel associated queue (if any) was reset.
|
||||
*/
|
||||
#define chIOGet(ip) ((ip)->vmt.m0->put(ip, TIME_INFINITE))
|
||||
#define chIOGet(ip) ((ip)->vmt->m0.put(ip, TIME_INFINITE))
|
||||
|
||||
/**
|
||||
* @brief Channel blocking byte read with timeout.
|
||||
|
@ -125,7 +125,7 @@ typedef struct {
|
|||
* @retval Q_TIMEOUT if the specified time expired.
|
||||
* @retval Q_RESET if the channel associated queue (if any) was reset.
|
||||
*/
|
||||
#define chIOGetTimeout(ip, timeout) ((ip)->vmt.m0->put(ip, timeout))
|
||||
#define chIOGetTimeout(ip, timeout) ((ip)->vmt->m0.put(ip, timeout))
|
||||
|
||||
#if CH_USE_EVENTS
|
||||
/**
|
||||
|
@ -192,7 +192,7 @@ typedef struct {
|
|||
* @param[in] n the maximum amount of data to be transferred
|
||||
* @return The number of bytes transferred.
|
||||
*/
|
||||
#define chIOWrite(ip, bp, n) ((ip)->vmt.m1->write(ip, bp, n))
|
||||
#define chIOWrite(ip, bp, n) ((ip)->vmt->m1.write(ip, bp, n))
|
||||
|
||||
/**
|
||||
* @brief Channel non-blocking read.
|
||||
|
@ -205,7 +205,7 @@ typedef struct {
|
|||
* @param[in] n the maximum amount of data to be transferred
|
||||
* @return The number of bytes transferred.
|
||||
*/
|
||||
#define chIORead(ip, bp, n) ((ip)->vmt.m1->read(ip, bp, n))
|
||||
#define chIORead(ip, bp, n) ((ip)->vmt->m1.read(ip, bp, n))
|
||||
|
||||
#endif /* CH_USE_EVENTS */
|
||||
|
||||
|
|
|
@ -128,12 +128,12 @@ struct _full_duplex_driver_data {
|
|||
* Input queue, incoming data can be read from this input queue by
|
||||
* using the queues APIs.
|
||||
*/
|
||||
InputQueue sd_iqueue;
|
||||
InputQueue iqueue;
|
||||
/**
|
||||
* Output queue, outgoing data can be written to this output queue by
|
||||
* using the queues APIs.
|
||||
*/
|
||||
OutputQueue sd_oqueue;
|
||||
OutputQueue oqueue;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -169,7 +169,7 @@ typedef struct {
|
|||
/**
|
||||
* Virtual Methods Table.
|
||||
*/
|
||||
struct _generic_serial_driver_vmt *vmt;
|
||||
struct _full_duplex_driver_vmt *vmt;
|
||||
/**
|
||||
* @p BaseChannel class inherited data.
|
||||
*/
|
||||
|
@ -186,33 +186,6 @@ typedef struct {
|
|||
* @p FullDuplexDriver specific data.
|
||||
*/
|
||||
struct _full_duplex_driver_data d3;
|
||||
} FullDuplexDriver_;
|
||||
|
||||
/**
|
||||
* @brief Full Duplex Serial Driver main structure.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
/** Input queue. Incoming data can be read from this queue by using the
|
||||
* queues APIs.*/
|
||||
InputQueue sd_iqueue;
|
||||
/** Data Available @p EventSource. This event is generated when some incoming
|
||||
* data is inserted in the Input @p Queue.*/
|
||||
EventSource sd_ievent;
|
||||
|
||||
/** Output queue. Outgoing data can be written to this Output @p Queue by
|
||||
* using the queues APIs.*/
|
||||
OutputQueue sd_oqueue;
|
||||
/** Data Transmitted @p EventSource. This event is generated when the
|
||||
* Output @p Queue is empty.*/
|
||||
EventSource sd_oevent;
|
||||
|
||||
/** I/O driver status flags. This field should not be read directly but
|
||||
* the @p chFDDGetAndClearFlags() funtion should be used instead.*/
|
||||
dflags_t sd_flags;
|
||||
/** Status Change @p EventSource. This event is generated when a
|
||||
* condition flag was changed.*/
|
||||
EventSource sd_sevent;
|
||||
} FullDuplexDriver;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
18
test/test.c
18
test/test.c
|
@ -70,27 +70,27 @@ void test_printn(uint32_t n) {
|
|||
char buf[16], *p;
|
||||
|
||||
if (!n)
|
||||
chFDDPut(comp, '0');
|
||||
chIOPut(comp, '0');
|
||||
else {
|
||||
p = buf;
|
||||
while (n)
|
||||
*p++ = (n % 10) + '0', n /= 10;
|
||||
while (p > buf)
|
||||
chFDDPut(comp, *--p);
|
||||
chIOPut(comp, *--p);
|
||||
}
|
||||
}
|
||||
|
||||
void test_print(char *msgp) {
|
||||
|
||||
while (*msgp)
|
||||
chFDDPut(comp, *msgp++);
|
||||
chIOPut(comp, *msgp++);
|
||||
}
|
||||
|
||||
void test_println(char *msgp) {
|
||||
|
||||
test_print(msgp);
|
||||
chFDDPut(comp, '\r');
|
||||
chFDDPut(comp, '\n');
|
||||
chIOPut(comp, '\r');
|
||||
chIOPut(comp, '\n');
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -105,7 +105,7 @@ static void print_tokens(void) {
|
|||
char *cp = tokens_buffer;
|
||||
|
||||
while (cp < tokp)
|
||||
chFDDPut(comp, *cp++);
|
||||
chIOPut(comp, *cp++);
|
||||
}
|
||||
|
||||
void test_emit_token(char token) {
|
||||
|
@ -232,9 +232,9 @@ static void print_line(void) {
|
|||
unsigned i;
|
||||
|
||||
for (i = 0; i < 76; i++)
|
||||
chFDDPut(comp, '-');
|
||||
chFDDPut(comp, '\r');
|
||||
chFDDPut(comp, '\n');
|
||||
chIOPut(comp, '-');
|
||||
chIOPut(comp, '\r');
|
||||
chIOPut(comp, '\n');
|
||||
}
|
||||
|
||||
msg_t TestThread(void *p) {
|
||||
|
|
Loading…
Reference in New Issue