From 45a6b7dc5a1758cb2bc49b0d76effa381043d297 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 19 Aug 2009 13:11:25 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1082 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/io/serial.c | 62 +++++++++++++++++++++++--------------------- os/io/serial.h | 44 +++++++++++-------------------- os/io/templates/serial_lld.c | 11 +++++++- 3 files changed, 58 insertions(+), 59 deletions(-) (limited to 'os/io') diff --git a/os/io/serial.c b/os/io/serial.c index abc099eea..05d258841 100644 --- a/os/io/serial.c +++ b/os/io/serial.c @@ -61,36 +61,10 @@ static size_t read(void *ip, uint8_t *buffer, size_t n) { return chIQRead(&((SerialDriver *)ip)->d2.iqueue, buffer, n); } -static void start(void *ip, const SerialDriverConfig *config) { - SerialDriver *sdp = (SerialDriver *)ip; - - chSysLock(); - sd_lld_start(sdp, config); - chSysUnlock(); -} - -/** - * @brief Stops the driver. - * @Details Any thread waiting on the driver's queues will be awakened with - * the message @p Q_RESET. - * - * @param sd The @p SerialDriver to be stopped. - */ -static void stop(void *ip) { - SerialDriver *sdp = (SerialDriver *)ip; - - chSysLock(); - sd_lld_stop(sdp); - chOQResetI(&sdp->d2.oqueue); - chIQResetI(&sdp->d2.iqueue); - chSchRescheduleS(); - chSysUnlock(); -} - static const struct SerialDriverVMT vmt = { {putwouldblock, getwouldblock, put, get}, {write, read}, - {start, stop} + {} }; /** @@ -112,8 +86,6 @@ static const struct SerialDriverVMT vmt = { */ void sdInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { - chDbgCheck(sdp != NULL, "sdInit"); - sdp->vmt = &vmt; chEvtInit(&sdp->d1.ievent); chEvtInit(&sdp->d1.oevent); @@ -123,6 +95,38 @@ void sdInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { chOQInit(&sdp->d2.oqueue, sdp->d2.ob, SERIAL_BUFFERS_SIZE, onotify); } +/** + * @brief Configures and starts the driver. + * + * @param[in] ip pointer to a @p SerialDriver or derived class + * @param[in] config the architecture-dependent serial driver configuration. + * If this parameter is set to @p NULL then a default + * configuration is used. + */ +void sdStart(SerialDriver *sdp, const SerialDriverConfig *config) { + + chSysLock(); + sd_lld_start(sdp, config); + chSysUnlock(); +} + +/** + * @brief Stops the driver. + * @Details Any thread waiting on the driver's queues will be awakened with + * the message @p Q_RESET. + * + * @param[in] ip pointer to a @p SerialDriver or derived class + */ +void sdStop(SerialDriver *sdp) { + + chSysLock(); + sd_lld_stop(sdp); + chOQResetI(&sdp->d2.oqueue); + chIQResetI(&sdp->d2.iqueue); + chSchRescheduleS(); + chSysUnlock(); +} + /** * @brief Handles incoming data. * @details This function must be called from the input interrupt service diff --git a/os/io/serial.h b/os/io/serial.h index aa18ebe7b..acfb2500f 100644 --- a/os/io/serial.h +++ b/os/io/serial.h @@ -50,22 +50,6 @@ typedef struct _SerialDriver SerialDriver; * @brief @p SerialDriver specific methods. */ struct _serial_driver_methods { - /** - * @brief Configures and starts the driver. - * - * @param[in] ip pointer to a @p SerialDriver or derived class - * @param[in] config The configuration record. - */ - void (*start)(void *ip, const SerialDriverConfig *config); - - /** - * @brief Stops the driver. - * @Details Any thread waiting on the driver's queues will be awakened with - * the message @p Q_RESET. - * - * @param[in] ip pointer to a @p SerialDriver or derived class - */ - void (*stop)(void *ip); }; /** @@ -115,11 +99,13 @@ struct _SerialDriver { #ifdef __cplusplus extern "C" { #endif - void sdInit(SerialDriver *sd, qnotify_t inotify, qnotify_t onotify); - void sdIncomingDataI(SerialDriver *sd, uint8_t b); - msg_t sdRequestDataI(SerialDriver *sd); - void sdAddFlagsI(SerialDriver *sd, sdflags_t mask); - sdflags_t sdGetAndClearFlags(SerialDriver *sd); + void sdInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify); + void sdStart(SerialDriver *sdp, const SerialDriverConfig *config); + void sdStop(SerialDriver *sdp); + void sdIncomingDataI(SerialDriver *sdp, uint8_t b); + msg_t sdRequestDataI(SerialDriver *sdp); + void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask); + sdflags_t sdGetAndClearFlags(SerialDriver *sdp); #ifdef __cplusplus } #endif @@ -131,7 +117,7 @@ extern "C" { * be used to check different channels implementations. * @see chIOPutWouldBlock() */ -#define sdPutWouldBlock(sd) chOQIsFull(&(sd)->d2.oqueue) +#define sdPutWouldBlock(sdp) chOQIsFull(&(sdp)->d2.oqueue) /** * @brief Direct input check on a @p SerialDriver. @@ -140,7 +126,7 @@ extern "C" { * be used to check different channels implementations. * @see chIOGetWouldBlock() */ -#define sdGetWouldBlock(sd) chIQIsEmpty(&(sd)->d2.iqueue) +#define sdGetWouldBlock(sdp) chIQIsEmpty(&(sdp)->d2.iqueue) /** * @brief Direct blocking write to a @p SerialDriver. @@ -149,7 +135,7 @@ extern "C" { * be used to write to different channels implementations. * @see chIOPut() */ -#define sdPut(sd, b) chOQPut(&(sd)->d2.oqueue, b) +#define sdPut(sdp, b) chOQPut(&(sdp)->d2.oqueue, b) /** * @brief Direct blocking write on a @p SerialDriver with timeout @@ -159,7 +145,7 @@ extern "C" { * be used to write to different channels implementations. * @see chIOPutTimeout() */ -#define sdPutTimeout(sd, b, t) chOQPutTimeout(&(sd)->d2.iqueue, b, t) +#define sdPutTimeout(sdp, b, t) chOQPutTimeout(&(sdp)->d2.iqueue, b, t) /** * @brief Direct blocking read from a @p SerialDriver. @@ -168,7 +154,7 @@ extern "C" { * be used to read from different channels implementations. * @see chIOGet() */ -#define sdGet(sd) chIQGet(&(sd)->d2.iqueue) +#define sdGet(sdp) chIQGet(&(sdp)->d2.iqueue) /** * @brief Direct blocking read from a @p SerialDriver with timeout @@ -178,7 +164,7 @@ extern "C" { * be used to read from different channels implementations. * @see chIOGetTimeout() */ -#define sdGetTimeout(sd, t) chIQGetTimeout(&(sd)->d2.iqueue, t) +#define sdGetTimeout(sdp, t) chIQGetTimeout(&(sdp)->d2.iqueue, t) /** * @brief Direct non-blocking write to a @p SerialDriver. @@ -187,7 +173,7 @@ extern "C" { * be used to write from different channels implementations. * @see chIOWrite() */ -#define sdWrite(sd, b, n) chOQWrite(&(sd)->d2.oqueue, b, n) +#define sdWrite(sdp, b, n) chOQWrite(&(sdp)->d2.oqueue, b, n) /** * @brief Direct non-blocking read on a @p SerialDriver. @@ -196,7 +182,7 @@ extern "C" { * be used to read from different channels implementations. * @see chIORead() */ -#define sdRead(sd, b, n) chIQRead(&(sd)->d2.iqueue, b, n) +#define sdRead(sdp, b, n) chIQRead(&(sdp)->d2.iqueue, b, n) #endif /* _SERIAL_H_ */ diff --git a/os/io/templates/serial_lld.c b/os/io/templates/serial_lld.c index 0fbaa3900..d0aabfaa0 100644 --- a/os/io/templates/serial_lld.c +++ b/os/io/templates/serial_lld.c @@ -26,6 +26,10 @@ #include +/** @brief Driver default configuration.*/ +static const SerialDriverConfig default_config = { +}; + /*===========================================================================*/ /* Low Level Driver local functions. */ /*===========================================================================*/ @@ -49,10 +53,15 @@ void sd_lld_init(void) { * @brief Low level serial driver configuration and (re)start. * * @param[in] sdp pointer to a @p SerialDriver object - * @param[in] config the architecture-dependent serial driver configuration + * @param[in] config the architecture-dependent serial driver configuration. + * If this parameter is set to @p NULL then a default + * configuration is used. */ void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) { + if (config == NULL) + config = &default_config; + } /** -- cgit v1.2.3