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

master
gdisirio 2012-05-08 17:09:20 +00:00
parent ba6519a2ea
commit d0a2e55ed0
31 changed files with 190 additions and 505 deletions

View File

@ -74,7 +74,7 @@ static bool_t mmc_is_protected(void) {
/* Generic large buffer.*/
uint8_t fbuff[1024];
static FRESULT scan_files(BaseChannel *chp, char *path) {
static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
FRESULT res;
FILINFO fno;
DIR dir;
@ -114,7 +114,7 @@ static FRESULT scan_files(BaseChannel *chp, char *path) {
#define SHELL_WA_SIZE THD_WA_SIZE(1024)
#define TEST_WA_SIZE THD_WA_SIZE(256)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
(void)argv;
@ -128,7 +128,7 @@ static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {THD_STATE_NAMES};
Thread *tp;
@ -148,7 +148,7 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
} while (tp != NULL);
}
static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
@ -165,7 +165,7 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
chThdWait(tp);
}
static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
FRESULT err;
uint32_t clusters;
FATFS *fsp;
@ -201,7 +201,7 @@ static const ShellCommand commands[] = {
};
static const ShellConfig shell_cfg1 = {
(BaseChannel *)&SD1,
(BaseSequentialStream *)&SD1,
commands
};

View File

@ -74,7 +74,7 @@ static bool_t mmc_is_protected(void) {
/* Generic large buffer.*/
uint8_t fbuff[1024];
static FRESULT scan_files(BaseChannel *chp, char *path) {
static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
FRESULT res;
FILINFO fno;
DIR dir;
@ -114,7 +114,7 @@ static FRESULT scan_files(BaseChannel *chp, char *path) {
#define SHELL_WA_SIZE THD_WA_SIZE(1024)
#define TEST_WA_SIZE THD_WA_SIZE(256)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
(void)argv;
@ -128,7 +128,7 @@ static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {THD_STATE_NAMES};
Thread *tp;
@ -148,7 +148,7 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
} while (tp != NULL);
}
static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
@ -165,7 +165,7 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
chThdWait(tp);
}
static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
FRESULT err;
uint32_t clusters;
FATFS *fsp;
@ -201,7 +201,7 @@ static const ShellCommand commands[] = {
};
static const ShellConfig shell_cfg1 = {
(BaseChannel *)&SD1,
(BaseSequentialStream *)&SD1,
commands
};

View File

@ -62,7 +62,7 @@ static bool_t mmc_is_protected(void) {return !palReadPad(IOPORT3, GPIOC_MMCWP);}
/* Generic large buffer.*/
uint8_t fbuff[1024];
static FRESULT scan_files(BaseChannel *chp, char *path) {
static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
FRESULT res;
FILINFO fno;
DIR dir;
@ -102,7 +102,7 @@ static FRESULT scan_files(BaseChannel *chp, char *path) {
#define SHELL_WA_SIZE THD_WA_SIZE(2048)
#define TEST_WA_SIZE THD_WA_SIZE(256)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
(void)argv;
@ -116,7 +116,7 @@ static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {THD_STATE_NAMES};
Thread *tp;
@ -136,7 +136,7 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
} while (tp != NULL);
}
static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
@ -153,7 +153,7 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
chThdWait(tp);
}
static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
FRESULT err;
uint32_t clusters;
FATFS *fsp;
@ -189,7 +189,7 @@ static const ShellCommand commands[] = {
};
static const ShellConfig shell_cfg1 = {
(BaseChannel *)&SD2,
(BaseSequentialStream *)&SD2,
commands
};

View File

@ -141,7 +141,7 @@ static bool_t fs_ready = FALSE;
/* Generic large buffer.*/
uint8_t fbuff[1024];
static FRESULT scan_files(BaseChannel *chp, char *path) {
static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
FRESULT res;
FILINFO fno;
DIR dir;
@ -181,7 +181,7 @@ static FRESULT scan_files(BaseChannel *chp, char *path) {
#define SHELL_WA_SIZE THD_WA_SIZE(2048)
#define TEST_WA_SIZE THD_WA_SIZE(256)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
(void)argv;
@ -195,7 +195,7 @@ static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {THD_STATE_NAMES};
Thread *tp;
@ -215,7 +215,7 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
} while (tp != NULL);
}
static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
@ -232,7 +232,7 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
chThdWait(tp);
}
static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
FRESULT err;
uint32_t clusters;
FATFS *fsp;
@ -268,7 +268,7 @@ static const ShellCommand commands[] = {
};
static const ShellConfig shell_cfg1 = {
(BaseChannel *)&SD1,
(BaseSequentialStream *)&SD1,
commands
};

View File

@ -274,7 +274,7 @@ int main(void) {
x = (int8_t)lis302dlReadRegister(&SPID1, LIS302DL_OUTX);
y = (int8_t)lis302dlReadRegister(&SPID1, LIS302DL_OUTY);
z = (int8_t)lis302dlReadRegister(&SPID1, LIS302DL_OUTZ);
chprintf((BaseChannel *)&SD2, "%d, %d, %d\r\n", x, y, z);
chprintf((BaseSequentialStream *)&SD2, "%d, %d, %d\r\n", x, y, z);
chThdSleepMilliseconds(500);
}
}

View File

@ -29,7 +29,7 @@
#define SHELL_WA_SIZE THD_WA_SIZE(1024)
#define TEST_WA_SIZE THD_WA_SIZE(256)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
(void)argv;
@ -43,7 +43,7 @@ static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {THD_STATE_NAMES};
Thread *tp;
@ -63,7 +63,7 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
} while (tp != NULL);
}
static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
@ -88,7 +88,7 @@ static const ShellCommand commands[] = {
};
static const ShellConfig shell_cfg1 = {
(BaseChannel *)&SD1,
(BaseSequentialStream *)&SD1,
commands
};

View File

@ -71,7 +71,7 @@
*
* @brief @p BaseChannel virtual methods table.
*/
struct tmp_BaseChannelVMT {
struct BaseChannelVMT {
_base_channel_methods
};
@ -86,7 +86,7 @@ typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseChannelVMT *vmt;
_base_channel_data
} tmp_BaseChannel;
} BaseChannel;
/**
* @name Macro Functions (BaseChannel)
@ -98,6 +98,7 @@ typedef struct {
* block.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
*
* @return The output queue status.
* @retval FALSE if the output queue has space and would not block a
* write operation.
@ -114,6 +115,7 @@ typedef struct {
* block.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
*
* @return The input queue status.
* @retval FALSE if the input queue contains data and would not block a
* read operation.
@ -131,6 +133,7 @@ typedef struct {
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @param[in] b the byte value to be written to the channel
*
* @return The operation status.
* @retval Q_OK if the operation succeeded.
* @retval Q_RESET if the channel associated queue (if any) was reset.
@ -166,6 +169,7 @@ typedef struct {
* is not available then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
*
* @return A byte value from the queue.
* @retval Q_RESET if the channel associated queue (if any) has been
* reset.
@ -194,6 +198,21 @@ typedef struct {
*/
#define chnGetTimeout(ip, time) ((ip)->vmt->get(ip, time))
/**
* @brief Channel blocking write.
* @details The function writes data from a buffer to a channel. If the channel
* is not ready to accept data then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @param[out] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred
*
* @return The number of bytes transferred.
*
* @api
*/
#define chnWrite(ip, bp, n) chSequentialStreamWrite(ip, bp, n)
/**
* @brief Channel blocking write with timeout.
* @details The function writes data from a buffer to a channel. If the channel
@ -213,6 +232,21 @@ typedef struct {
*/
#define chnWriteTimeout(ip, bp, n, time) ((ip)->vmt->writet(ip, bp, n, time))
/**
* @brief Channel blocking read.
* @details The function reads data from a channel into a buffer. If the data
* is not available then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @param[in] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred
*
* @return The number of bytes transferred.
*
* @api
*/
#define chnRead(ip, bp, n) chSequentialStreamRead(ip, bp, n)
/**
* @brief Channel blocking read with timeout.
* @details The function reads data from a channel into a buffer. If the data
@ -260,7 +294,7 @@ typedef uint_fast16_t chnflags_t;
/**
* @brief @p BaseAsynchronousChannel specific methods.
*/
#define tmp__base_asynchronous_channel_methods \
#define _base_asynchronous_channel_methods \
_base_channel_methods \
/* Channel read method with timeout specification.*/ \
chnflags_t (*getflags)(void *instance);
@ -268,7 +302,7 @@ typedef uint_fast16_t chnflags_t;
/**
* @brief @p BaseAsynchronousChannel specific data.
*/
#define tmp__base_asynchronous_channel_data \
#define _base_asynchronous_channel_data \
_base_channel_data \
/* I/O condition event source.*/ \
EventSource event; \
@ -280,7 +314,7 @@ typedef uint_fast16_t chnflags_t;
*
* @brief @p BaseAsynchronousChannel virtual methods table.
*/
struct tmp_BaseAsynchronousChannelVMT {
struct BaseAsynchronousChannelVMT {
_base_asynchronous_channel_methods
};
@ -295,7 +329,7 @@ typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseAsynchronousChannelVMT *vmt;
_base_asynchronous_channel_data
} tmp_BaseAsynchronousChannel;
} BaseAsynchronousChannel;
/**
* @name Macro Functions (BaseAsynchronousChannel)

View File

@ -139,7 +139,7 @@ static void usart_deinit(AT91PS_USART u) {
* @param[in] sdp communication channel associated to the USART
*/
static void set_error(SerialDriver *sdp, AT91_REG csr) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (csr & AT91C_US_OVRE)
sts |= SD_OVERRUN_ERROR;
@ -150,7 +150,7 @@ static void set_error(SerialDriver *sdp, AT91_REG csr) {
if (csr & AT91C_US_RXBRK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@ -181,7 +181,7 @@ void sd_lld_serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
u->US_IDR = AT91C_US_TXRDY;
}
else

View File

@ -70,7 +70,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/
static void set_error(uint8_t sra, SerialDriver *sdp) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (sra & (1 << DOR))
sts |= SD_OVERRUN_ERROR;
@ -79,7 +79,7 @@ static void set_error(uint8_t sra, SerialDriver *sdp) {
if (sra & (1 << FE))
sts |= SD_FRAMING_ERROR;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}

View File

@ -101,7 +101,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@ -112,7 +112,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@ -139,12 +139,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->RBR) < Q_OK)
chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@ -160,7 +160,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->IER &= ~IER_THRE;
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@ -186,7 +186,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return;
}
u->THR = b;

View File

@ -101,7 +101,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@ -112,7 +112,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@ -139,12 +139,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->RBR) < Q_OK)
chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@ -160,7 +160,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->IER &= ~IER_THRE;
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@ -186,7 +186,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return;
}
u->THR = b;

View File

@ -106,7 +106,7 @@ static void uart_deinit(UART *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@ -117,7 +117,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@ -145,12 +145,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->UART_LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->UART_RBR) < Q_OK)
chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@ -166,7 +166,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->UART_IER &= ~IER_THRE;
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@ -192,7 +192,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return;
}
u->UART_THR = b;

View File

@ -60,7 +60,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t urctl) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (urctl & OE)
sts |= SD_OVERRUN_ERROR;
@ -71,7 +71,7 @@ static void set_error(SerialDriver *sdp, uint8_t urctl) {
if (urctl & BRK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}

View File

@ -121,7 +121,7 @@ static bool_t connint(SerialDriver *sdp) {
goto abort;
}
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_CONNECTED);
chnAddFlagsI(sdp, CHN_CONNECTED);
chSysUnlockFromIsr();
return TRUE;
}
@ -149,7 +149,7 @@ static bool_t inint(SerialDriver *sdp) {
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:
@ -190,7 +190,7 @@ static bool_t outint(SerialDriver *sdp) {
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:

View File

@ -117,7 +117,7 @@ static void esci_deinit(volatile struct ESCI_tag *escip) {
* @param[in] sr eSCI SR register value
*/
static void set_error(SerialDriver *sdp, uint32_t sr) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (sr & 0x08000000)
sts |= SD_OVERRUN_ERROR;
@ -130,7 +130,7 @@ static void set_error(SerialDriver *sdp, uint32_t sr) {
/* if (sr & 0x00000000)
sts |= SD_BREAK_DETECTED;*/
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@ -156,7 +156,7 @@ static void serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
escip->CR1.B.TIE = 0;
}
else {

View File

@ -140,7 +140,7 @@ static void usart_deinit(USART_TypeDef *u) {
* @param[in] sr USART SR register value
*/
static void set_error(SerialDriver *sdp, uint16_t sr) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (sr & USART_SR_ORE)
sts |= SD_OVERRUN_ERROR;
@ -151,7 +151,7 @@ static void set_error(SerialDriver *sdp, uint16_t sr) {
if (sr & USART_SR_NE)
sts |= SD_NOISE_ERROR;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@ -172,7 +172,7 @@ static void serve_interrupt(SerialDriver *sdp) {
/* Special case, LIN break detection.*/
if (sr & USART_SR_LBD) {
chSysLockFromIsr();
chIOAddFlagsI(sdp, SD_BREAK_DETECTED);
chnAddFlagsI(sdp, SD_BREAK_DETECTED);
chSysUnlockFromIsr();
u->SR &= ~USART_SR_LBD;
}
@ -188,7 +188,7 @@ static void serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
u->CR1 = (cr1 & ~USART_CR1_TXEIE) | USART_CR1_TCIE;
}
else
@ -198,7 +198,7 @@ static void serve_interrupt(SerialDriver *sdp) {
/* Physical transmission end.*/
if (sr & USART_SR_TC) {
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_TRANSMISSION_END);
chnAddFlagsI(sdp, CHN_TRANSMISSION_END);
chSysUnlockFromIsr();
u->CR1 = cr1 & ~USART_CR1_TCIE;
u->SR &= ~USART_SR_TC;

View File

@ -115,7 +115,7 @@ static void notify3(GenericQueue *qp) {
* @notapi
*/
void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) {
ioflags_t sts = 0;
chnflags_t sts = 0;
if (sr & USART_SR_OR)
sts |= SD_OVERRUN_ERROR;
@ -126,7 +126,7 @@ void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) {
if (sr & USART_SR_PE)
sts |= SD_PARITY_ERROR;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}

View File

@ -73,7 +73,7 @@ static ROMCONST SerialConfig default_config = {
/*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t sr) {
ioflags_t sts = 0;
chnflags_t sts = 0;
/* Note, SR register bit definitions are equal for all UARTs so using
the UART1 definitions is fine.*/
@ -86,7 +86,7 @@ static void set_error(SerialDriver *sdp, uint8_t sr) {
if (sr & UART1_SR_PE)
sts |= SD_PARITY_ERROR;
chSysLockFromIsr();
chIOAddFlagsI(sdp, sts);
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}

View File

@ -114,7 +114,7 @@ static bool_t connint(SerialDriver *sdp) {
goto abort;
}
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_CONNECTED);
chnAddFlagsI(sdp, CHN_CONNECTED);
chSysUnlockFromIsr();
return TRUE;
}
@ -143,7 +143,7 @@ static bool_t inint(SerialDriver *sdp) {
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case SOCKET_ERROR:
@ -184,7 +184,7 @@ static bool_t outint(SerialDriver *sdp) {
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case SOCKET_ERROR:

View File

@ -94,8 +94,8 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time);
}
static ioflags_t getflags(void *ip) {
_ch_get_and_clear_flags_impl(ip);
static chnflags_t getflags(void *ip) {
_chn_get_and_clear_flags_impl(ip);
}
static const struct SerialDriverVMT vmt = {
@ -139,7 +139,7 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {
sdp->vmt = &vmt;
chEvtInit(&sdp->event);
sdp->flags = IO_NO_ERROR;
sdp->flags = CHN_NO_ERROR;
sdp->state = SD_STOP;
chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify);
chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify);
@ -215,9 +215,9 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) {
chDbgCheck(sdp != NULL, "sdIncomingDataI");
if (chIQIsEmptyI(&sdp->iqueue))
chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
if (chIQPutI(&sdp->iqueue, b) < Q_OK)
chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
}
/**
@ -243,7 +243,7 @@ msg_t sdRequestDataI(SerialDriver *sdp) {
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK)
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return b;
}

View File

@ -103,7 +103,7 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, time);
}
static ioflags_t getflags(void *ip) {
static chnflags_t getflags(void *ip) {
_ch_get_and_clear_flags_impl(ip);
}
@ -133,7 +133,7 @@ static void inotify(GenericQueue *qp) {
chSysLock();
usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP);
chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE);
chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE);
sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer;
sdup->iqueue.q_counter = n;
while (notempty(&sdup->iqueue.q_waiting))
@ -160,7 +160,7 @@ static void onotify(GenericQueue *qp) {
chSysLock();
usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP);
chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY);
sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer;
sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue);
while (notempty(&sdup->oqueue.q_waiting))
@ -195,7 +195,7 @@ void sduObjectInit(SerialUSBDriver *sdup) {
sdup->vmt = &vmt;
chEvtInit(&sdup->event);
sdup->flags = IO_NO_ERROR;
sdup->flags = CHN_NO_ERROR;
sdup->state = SDU_STOP;
chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify);
chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify);
@ -312,7 +312,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
chSysLockFromIsr();
usbStartTransmitI(usbp, ep);
chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY);
chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY);
sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer;
sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue);
while (notempty(&sdup->oqueue.q_waiting))
@ -348,7 +348,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) {
chSysLockFromIsr();
usbStartReceiveI(usbp, ep);
chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE);
chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE);
sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer;
sdup->iqueue.q_counter = n;
while (notempty(&sdup->iqueue.q_waiting))

View File

@ -123,7 +123,6 @@
#include "chinline.h"
#include "chqueues.h"
#include "chstreams.h"
#include "chioch.h"
#include "chfiles.h"
#include "chdebug.h"

View File

@ -1,370 +0,0 @@
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
2011,2012 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file chioch.h
* @brief I/O channels.
* @details This header defines abstract interfaces useful to access generic
* I/O resources in a standardized way.
*
* @addtogroup io_channels
* @details This module defines an abstract interface for I/O channels by
* extending the @p BaseSequentialStream interface. Note that no code
* is present, I/O channels are just abstract interface like
* structures, you should look at the systems as to a set of abstract
* C++ classes (even if written in C). Specific device drivers can
* use/extend the interface and implement them.<br>
* This system has the advantage to make the access to channels
* independent from the implementation logic.
* @{
*/
#ifndef _CHIOCH_H_
#define _CHIOCH_H_
/**
* @brief @p BaseChannel specific methods.
*/
#define _base_channel_methods \
_base_sequential_stream_methods \
/* Channel output check.*/ \
bool_t (*putwouldblock)(void *instance); \
/* Channel input check.*/ \
bool_t (*getwouldblock)(void *instance); \
/* Channel put method with timeout specification.*/ \
msg_t (*put)(void *instance, uint8_t b, systime_t time); \
/* Channel get method with timeout specification.*/ \
msg_t (*get)(void *instance, systime_t time); \
/* Channel write method with timeout specification.*/ \
size_t (*writet)(void *instance, const uint8_t *bp, \
size_t n, systime_t time); \
/* Channel read method with timeout specification.*/ \
size_t (*readt)(void *instance, uint8_t *bp, size_t n, systime_t time);
/**
* @brief @p BaseChannel specific data.
* @note It is empty because @p BaseChannel is only an interface without
* implementation.
*/
#define _base_channel_data \
_base_sequential_stream_data
/**
* @extends BaseSequentialStreamVMT
*
* @brief @p BaseChannel virtual methods table.
*/
struct BaseChannelVMT {
_base_channel_methods
};
/**
* @extends BaseSequentialStream
*
* @brief Base channel class.
* @details This class represents a generic, byte-wide, I/O channel. This class
* introduces generic I/O primitives with timeout specification.
*/
typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseChannelVMT *vmt;
_base_channel_data
} BaseChannel;
/**
* @name Macro Functions (BaseChannel)
* @{
*/
/**
* @brief Channel output check.
* @details This function verifies if a subsequent put/write operation would
* block.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @return The output queue status.
* @retval FALSE if the output queue has space and would not block a
* write operation.
* @retval TRUE if the output queue is full and would block a write
* operation.
*
* @api
*/
#define chIOPutWouldBlock(ip) ((ip)->vmt->putwouldblock(ip))
/**
* @brief Channel input check.
* @details This function verifies if a subsequent get/read operation would
* block.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @return The input queue status.
* @retval FALSE if the input queue contains data and would not block a
* read operation.
* @retval TRUE if the input queue is empty and would block a read
* operation.
*
* @api
*/
#define chIOGetWouldBlock(ip) ((ip)->vmt->getwouldblock(ip))
/**
* @brief Channel blocking byte write.
* @details This function writes a byte value to a channel. If the channel
* is not ready to accept data then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @param[in] b the byte value to be written to the channel
* @return The operation status.
* @retval Q_OK if the operation succeeded.
* @retval Q_RESET if the channel associated queue (if any) was reset.
*
* @api
*/
#define chIOPut(ip, b) ((ip)->vmt->put(ip, b, TIME_INFINITE))
/**
* @brief Channel blocking byte write with timeout.
* @details This function writes a byte value to a channel. If the channel
* is not ready to accept data then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @param[in] b the byte value to be written to the channel
* @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 The operation status.
* @retval Q_OK if the operation succeeded.
* @retval Q_TIMEOUT if the specified time expired.
* @retval Q_RESET if the channel associated queue (if any) was reset.
*
* @api
*/
#define chIOPutTimeout(ip, b, time) ((ip)->vmt->put(ip, b, time))
/**
* @brief Channel blocking byte read.
* @details This function reads a byte value from a channel. If the data
* is not available then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @return A byte value from the queue.
* @retval Q_RESET if the channel associated queue (if any) has been
* reset.
*
* @api
*/
#define chIOGet(ip) ((ip)->vmt->get(ip, TIME_INFINITE))
/**
* @brief Channel blocking byte read with timeout.
* @details This function reads a byte value from a channel. If the data
* is not available then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @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 byte value from the queue.
* @retval Q_TIMEOUT if the specified time expired.
* @retval Q_RESET if the channel associated queue (if any) has been
* reset.
*
* @api
*/
#define chIOGetTimeout(ip, time) ((ip)->vmt->get(ip, time))
/**
* @brief Channel blocking write with timeout.
* @details The function writes data from a buffer to a channel. If the channel
* is not ready to accept data then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @param[out] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred
* @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 The number of bytes transferred.
*
* @api
*/
#define chIOWriteTimeout(ip, bp, n, time) \
((ip)->vmt->writet(ip, bp, n, time))
/**
* @brief Channel blocking read with timeout.
* @details The function reads data from a channel into a buffer. If the data
* is not available then the calling thread is suspended.
*
* @param[in] ip pointer to a @p BaseChannel or derived class
* @param[in] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred
* @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 The number of bytes transferred.
*
* @api
*/
#define chIOReadTimeout(ip, bp, n, time) \
((ip)->vmt->readt(ip, bp, n, time))
/** @} */
#if CH_USE_EVENTS || defined(__DOXYGEN__)
/**
* @name I/O status flags
* @{
*/
/** @brief No pending conditions.*/
#define IO_NO_ERROR 0
/** @brief Connection happened.*/
#define IO_CONNECTED 1
/** @brief Disconnection happened.*/
#define IO_DISCONNECTED 2
/** @brief Data available in the input queue.*/
#define IO_INPUT_AVAILABLE 4
/** @brief Output queue empty.*/
#define IO_OUTPUT_EMPTY 8
/** @brief Transmission end.*/
#define IO_TRANSMISSION_END 16
/** @} */
/**
* @brief Type of an I/O condition flags mask.
*/
typedef uint_fast16_t ioflags_t;
/**
* @brief @p BaseAsynchronousChannel specific methods.
*/
#define _base_asynchronous_channel_methods \
_base_channel_methods \
/* Channel read method with timeout specification.*/ \
ioflags_t (*getflags)(void *instance);
/**
* @brief @p BaseAsynchronousChannel specific data.
*/
#define _base_asynchronous_channel_data \
_base_channel_data \
/* I/O condition event source.*/ \
EventSource event; \
/* I/O condition flags.*/ \
ioflags_t flags;
/**
* @extends BaseChannelVMT
*
* @brief @p BaseAsynchronousChannel virtual methods table.
*/
struct BaseAsynchronousChannelVMT {
_base_asynchronous_channel_methods
};
/**
* @extends BaseChannel
*
* @brief Base asynchronous channel class.
* @details This class extends @p BaseChannel by adding event sources fields
* for asynchronous I/O for use in an event-driven environment.
*/
typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseAsynchronousChannelVMT *vmt;
_base_asynchronous_channel_data
} BaseAsynchronousChannel;
/**
* @name Macro Functions (BaseAsynchronousChannel)
* @{
*/
/**
* @brief Returns the I/O condition event source.
* @details The event source is broadcasted when an I/O condition happens.
*
* @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
* class
* @return A pointer to an @p EventSource object.
*
* @api
*/
#define chIOGetEventSource(ip) (&((ip)->event))
/**
* @brief Adds status flags to the channel's mask.
* @details This function is usually called from the I/O ISRs in order to
* notify I/O conditions such as data events, errors, signal
* changes etc.
*
* @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
* class
* @param[in] mask condition flags to be added to the mask
*
* @iclass
*/
#define chIOAddFlagsI(ip, mask) { \
(ip)->flags |= (mask); \
chEvtBroadcastI(&(ip)->event); \
}
/**
* @brief Returns and clears the status flags associated to the channel.
*
* @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
* class
* @return The condition flags modified since last time this
* function was invoked.
*
* @api
*/
#define chIOGetAndClearFlags(ip) ((ip)->vmt->getflags(ip))
/** @} */
/**
* @brief Default implementation of the @p getflags virtual method.
*
* @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
* class
* @return The condition flags modified since last time this
* function was invoked.
*
* @notapi
*/
#define _ch_get_and_clear_flags_impl(ip) \
ioflags_t mask; \
chSysLock(); \
mask = ((BaseAsynchronousChannel *)(ip))->flags; \
((BaseAsynchronousChannel *)(ip))->flags = IO_NO_ERROR; \
chSysUnlock(); \
return mask
#endif /* CH_USE_EVENTS */
#endif /* _CHIOCH_H_ */
/** @} */

View File

@ -29,6 +29,11 @@
#define MAX_FILLER 11
#define FLOAT_PRECISION 100000
static void _putc(BaseSequentialStream *chp, char c) {
chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
}
static char *long_to_string_with_divisor(char *p,
long num,
unsigned radix,
@ -83,7 +88,7 @@ static char *ftoa(char *p, double num) {
/**
* @brief System formatted output function.
* @details This function implements a minimal @p printf() like functionality
* with output on a @p BaseChannel.
* with output on a @p BaseSequentialStream.
* The general parameters format is: %[-][width|*][.precision|*][l|L]p.
* The following parameter types (p) are supported:
* - <b>x</b> hexadecimal integer.
@ -98,10 +103,10 @@ static char *ftoa(char *p, double num) {
* - <b>s</b> string.
* .
*
* @param[in] chp pointer to a @p BaseChannel implementing object
* @param[in] chp pointer to a @p BaseSequentialStream implementing object
* @param[in] fmt formatting string
*/
void chprintf(BaseChannel *chp, const char *fmt, ...) {
void chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
va_list ap;
char tmpbuf[MAX_FILLER + 1];
char *p, *s, c, filler;
@ -120,7 +125,7 @@ void chprintf(BaseChannel *chp, const char *fmt, ...) {
return;
}
if (c != '%') {
chIOPut(chp, (uint8_t)c);
_putc(chp, (uint8_t)c);
continue;
}
p = tmpbuf;
@ -235,18 +240,18 @@ unsigned_common:
width = -width;
if (width < 0) {
if (*s == '-' && filler == '0') {
chIOPut(chp, (uint8_t)*s++);
_putc(chp, (uint8_t)*s++);
i--;
}
do
chIOPut(chp, (uint8_t)filler);
_putc(chp, (uint8_t)filler);
while (++width != 0);
}
while (--i >= 0)
chIOPut(chp, (uint8_t)*s++);
_putc(chp, (uint8_t)*s++);
while (width) {
chIOPut(chp, (uint8_t)filler);
_putc(chp, (uint8_t)filler);
width--;
}
}

View File

@ -39,7 +39,7 @@
#ifdef __cplusplus
extern "C" {
#endif
void chprintf(BaseChannel *chp, const char *fmt, ...);
void chprintf(BaseSequentialStream *chp, const char *fmt, ...);
#ifdef __cplusplus
}
#endif

View File

@ -38,6 +38,11 @@
*/
EventSource shell_terminated;
static void _putc(BaseSequentialStream *chp, char c) {
chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
}
static char *_strtok(char *str, const char *delim, char **saveptr) {
char *token;
if (str)
@ -55,12 +60,12 @@ static char *_strtok(char *str, const char *delim, char **saveptr) {
return *token ? token : NULL;
}
static void usage(BaseChannel *chp, char *p) {
static void usage(BaseSequentialStream *chp, char *p) {
chprintf(chp, "Usage: %s\r\n", p);
}
static void list_commands(BaseChannel *chp, const ShellCommand *scp) {
static void list_commands(BaseSequentialStream *chp, const ShellCommand *scp) {
while (scp->sc_name != NULL) {
chprintf(chp, "%s ", scp->sc_name);
@ -68,7 +73,7 @@ static void list_commands(BaseChannel *chp, const ShellCommand *scp) {
}
}
static void cmd_info(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argv;
if (argc > 0) {
@ -100,7 +105,7 @@ static void cmd_info(BaseChannel *chp, int argc, char *argv[]) {
#endif
}
static void cmd_systime(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argv;
if (argc > 0) {
@ -119,7 +124,7 @@ static ShellCommand local_commands[] = {
{NULL, NULL}
};
static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
static bool_t cmdexec(const ShellCommand *scp, BaseSequentialStream *chp,
char *name, int argc, char *argv[]) {
while (scp->sc_name != NULL) {
@ -135,7 +140,7 @@ static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
/**
* @brief Shell thread function.
*
* @param[in] p pointer to a @p BaseChannel object
* @param[in] p pointer to a @p BaseSequentialStream object
* @return Termination reason.
* @retval RDY_OK terminated by command.
* @retval RDY_RESET terminated by reset condition on the I/O channel.
@ -143,7 +148,7 @@ static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
static msg_t shell_thread(void *p) {
int n;
msg_t msg = RDY_OK;
BaseChannel *chp = ((ShellConfig *)p)->sc_channel;
BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
char *args[SHELL_MAX_ARGUMENTS + 1];
@ -245,19 +250,20 @@ Thread *shellCreateStatic(const ShellConfig *scp, void *wsp,
/**
* @brief Reads a whole line from the input channel.
*
* @param[in] chp pointer to a @p BaseChannel object
* @param[in] chp pointer to a @p BaseSequentialStream object
* @param[in] line pointer to the line buffer
* @param[in] size buffer maximum length
* @return The operation status.
* @retval TRUE the channel was reset or CTRL-D pressed.
* @retval FALSE operation successful.
*/
bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
char *p = line;
while (TRUE) {
short c = (short)chIOGet(chp);
if (c < 0)
char c;
if (chSequentialStreamRead(chp, (uint8_t *)&c, 1) == 0)
return TRUE;
if (c == 4) {
chprintf(chp, "^D");
@ -265,9 +271,9 @@ bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
}
if (c == 8) {
if (p != line) {
chIOPut(chp, (uint8_t)c);
chIOPut(chp, 0x20);
chIOPut(chp, (uint8_t)c);
_putc(chp, c);
_putc(chp, 0x20);
_putc(chp, c);
p--;
}
continue;
@ -280,7 +286,7 @@ bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
if (c < 0x20)
continue;
if (p < line + size - 1) {
chIOPut(chp, (uint8_t)c);
_putc(chp, c);
*p++ = (char)c;
}
}

View File

@ -46,7 +46,7 @@
/**
* @brief Command handler function type.
*/
typedef void (*shellcmd_t)(BaseChannel *chp, int argc, char *argv[]);
typedef void (*shellcmd_t)(BaseSequentialStream *chp, int argc, char *argv[]);
/**
* @brief Custom command entry type.
@ -60,7 +60,7 @@ typedef struct {
* @brief Shell descriptor type.
*/
typedef struct {
BaseChannel *sc_channel; /**< @brief I/O channel associated
BaseSequentialStream *sc_channel; /**< @brief I/O channel associated
to the shell. */
const ShellCommand *sc_commands; /**< @brief Shell extra commands
table. */
@ -77,7 +77,7 @@ extern "C" {
Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio);
Thread *shellCreateStatic(const ShellConfig *scp, void *wsp,
size_t size, tprio_t prio);
bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size);
bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size);
#ifdef __cplusplus
}
#endif

View File

@ -171,6 +171,12 @@
lwIP demos (backported to 2.4.1).
- NEW: lwIP related code is not centralized into a single place, no need to
duplicate the code in each application or demo (backported to 2.4.1).
- CHANGE: Removed the chioch.h header from the kernel, now channels interface
is exported by the HAL.
- CHANGE: chprintf() now takes a BaseSequentialStream as parameter instead
of a BaseChannel making it more generic.
- CHANGE: Now the shell requires a BaseSequentialStream instead of a
BaseChannel for communications making it more generic.
- CHANGE: Kernel memory pools now do not check the alignment of the inserted
objects, it is responsibility of the application to insert properly
aligned objects.

View File

@ -85,7 +85,12 @@ void * ROMCONST wa[5] = {test.wa.T0, test.wa.T1, test.wa.T2,
/*
* Console output.
*/
static BaseChannel *chp;
static BaseSequentialStream *chp;
static void _putc(BaseSequentialStream *chp, char c) {
chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
}
/**
* @brief Prints a decimal unsigned number.
@ -96,13 +101,13 @@ void test_printn(uint32_t n) {
char buf[16], *p;
if (!n)
chIOPut(chp, '0');
_putc(chp, '0');
else {
p = buf;
while (n)
*p++ = (n % 10) + '0', n /= 10;
while (p > buf)
chIOPut(chp, *--p);
_putc(chp, *--p);
}
}
@ -114,7 +119,7 @@ void test_printn(uint32_t n) {
void test_print(const char *msgp) {
while (*msgp)
chIOPut(chp, *msgp++);
_putc(chp, *msgp++);
}
/**
@ -125,8 +130,7 @@ void test_print(const char *msgp) {
void test_println(const char *msgp) {
test_print(msgp);
chIOPut(chp, '\r');
chIOPut(chp, '\n');
chSequentialStreamWrite(chp, (const uint8_t *)"\r\n", 1);
}
/*
@ -141,7 +145,7 @@ static void print_tokens(void) {
char *cp = tokens_buffer;
while (cp < tokp)
chIOPut(chp, *cp++);
_putc(chp, *cp++);
}
/**
@ -306,9 +310,8 @@ static void print_line(void) {
unsigned i;
for (i = 0; i < 76; i++)
chIOPut(chp, '-');
chIOPut(chp, '\r');
chIOPut(chp, '\n');
_putc(chp, '-');
chSequentialStreamWrite(chp, (const uint8_t *)"\r\n", 1);
}
/**

View File

@ -113,7 +113,7 @@ bool_t sdc_lld_is_write_protected(SDCDriver *sdcp) {
/**
*
*/
void cmd_sdiotest(BaseChannel *chp, int argc, char *argv[]){
void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
(void)argc;
(void)argv;
uint32_t i = 0;
@ -356,7 +356,7 @@ static const ShellCommand commands[] = {
{NULL, NULL}
};
static const ShellConfig shell_cfg1 = {
(BaseChannel *)&SD2,
(BaseSequentialStream *)&SD2,
commands
};

View File

@ -20,6 +20,12 @@ Within 2.5.x:
* FatFs 0.9x integration.
- USB driver model revision.
X STM32 OTG USB cell support for CL, F2, F4 devices.
X Streaming DAC/I2S driver model and STM32 implementation.
- Unified LPC1xxx HAL.
- LPC11xx and LPC13xx HALs merged in the unified one.
- LPC17xx support.
- NUC120 support.
- STM32F0 support.
- Add USARTs support to the STM32 SPI driver.
- Add option to use another counter instead of the systick counter into the
trace buffer.
@ -31,12 +37,8 @@ X STM32 OTG USB cell support for CL, F2, F4 devices.
to be updated.
- Runtime errors manager in HAL.
- Critical errors manager in HAL (to replace or complement assertions).
- Streaming DAC/I2S driver model and STM32 implementation.
- Add ADC3 support to the STM32 ADC driver.
- Add ADC3 support to the STM32F1xx ADC driver.
- Update C++ wrapper.
- STM32F0 support.
- LPC17xx support.
- NUC120 support.
? Add the RTC service inside the kernel and port, remove from HAL.
Within 2.x.x