Hi
Here is an example of using the timer:
#define OWN_TASK MY_TASK
#define INITIALISATION 0
#define ACTIVE 1
#define E_TIMER_SEND_SERIAL 1
#define SEND_LENGTH 20
#define PAUSE_DELAY_TIME (DELAY_LIMIT)(0.1*SEC)
void fnMyTask(TTASKTABLE *ptrTaskTable) // Task configured to run once at start up and then sleep
{
static unsigned char ucSerialInput[RX_BUFFER_SIZE]; // static buffer for collecting UART data
static int iSerialRxLenth = 0; // length of collected UART data
static int iTaskState = INITIALISATION;
static QUEUE_HANDLE SerialPortID;
QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID; // queue ID for task input
unsigned char ucInputMessage[RX_BUFFER_SIZE]; // reserve space for receiving messages
if (INITIALISATION == iTaskState) { // configure interfaces on initialisation
SerialPortID = fnConfigureAndOpenUART();
iTaskState = ACTIVE;
}
while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) { // check input queue
switch ( ucInputMessage[ MSG_SOURCE_TASK ] ) { // switch depending on message source
case TIMER_EVENT: // timer event
if (E_TIMER_SEND_SERIAL == ucInputMessage[ MSG_TIMER_EVENT ]) { // pause between characters, send data
fnWrite(SerialPortID, ucSerialInput, iSerialRxLenth); // transmit available buffer
iSerialRxLenth = 0; // reset UART message length counter
}
break;
}
}
while (fnRead(SerialPortID, &ucSerialInput[iSerialRxLenth++], 1) != 0) { // collect serial port data
if (iSerialRxLenth >= SEND_LENGTH) {
fnWrite(SerialPortID, ucSerialInput, iSerialRxLenth); // transmit full buffer
iSerialRxLenth = 0; // reset UART message length counter
uTaskerStopTimer(OWN_TASK); // stop pause monitor timer
}
else {
uTaskerMonoTimer( OWN_TASK, PAUSE_DELAY_TIME, E_TIMER_SEND_SERIAL );// start monitor timer
}
}
}
Each time a characters is received (in character mode) it is saved to a local buffer (ucSerialInput). A timer is started (100ms, with timeout event E_TIMER_SEND_SERIAL) on each character (retriggerable mono-stable). If SEND_LENGTH characters are received, they are sent to the serial port and the pause timer stopped.
If less that SEND_LENGTH characters have been received and the pause monitor timer fires, the timer event causes the available characters to be send.
The result is that if lots of serial data is arriving quickly it will be send in 'packets' of SEND_LENGTH. If there is a pause between characters of more than 100ms, the available number of bytes will be sent after this time.
Regards
Mark