rtel wrote on Wednesday, July 27, 2005:
The serial port drivers in the demo are written to test ISR semaphore and queue mechanisms from within an ISR. They work fine but are not written to be optimised solutions. They can be tailored to provide optimised solutions for different applications. For example, depending on the priorities within your system it might not be necessary to switch tasks immediately a character is received.
If you want an example of a more comprehensive and structured sample driver than supports multiple ports then take a look at Demo\Flshlite\serial\serial.c.
As a simple change, using more than one port requires the xComPortHandle to be used to identify which port any operation is to be performed on. This is returned from xSerialPortInit(), and then used as a parameter to the send and receive functions. The code as delivered for the AVR only supports one port so the xComPortHandle is not used.
As a minimal mod:
+ Change the queue definitions from one Rx queue and one Tx queue to an array of Rx queues and an array of Tx queues:
static xQueueHandle xRxedChars[2];
static xQueueHandle xCharsForTx[2];
+ Change xSerialPortInitMinimal() to take a parameter that indicates which port is being initialised - port 0 or port 1. The xSerialPortInit() function prototype can be used if easier than modifying the minimal version.
xSerialPortInitMinimal() then has to of coarse initialise the correct port depending on the new parameters. Also when the queues are initialised you have to initialise the correct queue within the array, eg.
xRxedChars[ PORT ] = xQueueCreate( uxQueueLength, sizeof( portCHAR ) );
Finally the init function returns a handle to the port - which can just be 0 or 1 as an index into the queue arrays.
+ xSerialGetChar() then needs to use the pxPort parameter which is currently ignored. If this is 0 for port 0 and 1 for port 1 then all that needs doing is change xRxedChars to xRxedChars[ pxPort ]. pxPort expected to be a pointer to a struct (as per the flashlite serial driver referenced above) so will probably need casting to use it as an index.
+ xSerialPutChar() as per above, just change xCharsForTx to xCharsForTx[ pxPort ].
+ The interrupt routines have to also you the correct queue within the array.
This perhaps sounds complex but really is not.
Regards.