Tool/software: Code Composer Studio
We are trying to use TI RTOS UART code on the CC2640R2 processor to send and receive RS232 data on an external device. The problem is that the device immediately echoes the data as it receives it, and then appends its response. In other words, UART data comes back from that device before we finish the UART_write() command in our code.
There may be more than one way to handle this, but it seems that we must use the nonblocking mode of either the UART_read() or the UART_write() command. Let's say we made the READ nonblocking. That would mean we'd code it like this:
-Start the Read nonblocking
-Start the Write (blocking)
-Handle the Read data when the read finishes
Reading what documentation I can find, it says:
1. Create another task
2. Put the nonblocking read function in that new task
3. Point params->readCallback to that function
4. When the nonblocking read function is called by the hardware interrupt when the read is done, it sets a semaphore that tells the main task that the read data is available
5. The main task then gets the data
I've scanned through E2E and other TI documentation. This should be simple, but I cannot find a simple example. So here are some basic questions. I'm probably not the only person who would like a nice, simple, all in one place example of this to follow in their code.
Some basic, simple questions:
1. How do I create another task and put the nonbocking read function in it?
A. After that readback function is called, what happens to that task?
B. Does it do a return at the end of that readback function? If so, where does it return to?
C. Should the main task delete that task when the read is finished? If so, how?
D. Should the main task then recreate that task every time it wants to do another nonblocking UART Read?
2. The documentation refers to semaphores.
A. How do we create them?
B. How do we make sure that both the main and the newly created readback task access the exact same semaphore? They might create different instances of it and thus not communicate
C. Do we need to recreate the semaphores each time we create the readback task?
3. Some other unanswered questions.
A. The data read back in our case is of undetermined length, and has multiple carriage returns in it. We should be able to terminate the read with a timeout after a reasonable time and get all the data. There is a value called readTimeout that I think we can use. What units is that in? Microseconds, milliseconds, seconds? Why not put that information in the description in the header file?
A simple example of all the above could be in one place in response to this question. It could include an example of how to do everything I asked above. It could help other people searching for answers on how to set up and use UART commands in the nonblocking mode.
Thanks for any help you can give.
Dan Benkman
Innowave