I am developing a time critical firmware using RTOS. My operations take 240 uS to execute (80MHz TM4C123 MCU). I am trying to reduce its time. Your wisdom and expertise is needed. My software architecture may need drastic improvement.
I have noticed from using logic analyzer that the time it takes from posting a semaphore to unpending the task takes about 30 uS. Is there a way to speed it up? Are there alternatives to using the semaphore pend and post method?
Also, SPI_transfer() takes about 29 uS to run (SPI clock = 20MHz). Is there a way to reduce that? The actual hardware SPI transfer takes only about 5uS for one 4-byte transfer (SPI clock = 20 MHz). What is the algorithm used in SPI_transfer? Does it rely on interrupt or DMA?
The execution graph (Debug Tool) in CCS shows a lot of semaphore post/pend operations during the execution of my code. I don't think my code is doing that. I am wonder what are the sources of those semaphore operations.
In a nut shell, my operations include an incoming IRQ (HWI), four SPI_transfer() calls, with two pairs of SPI_open and SPI_close, two levels of semaphore post/unpend. I need to reduce the overall time down to around 100uS. The flow looks like this :
IRQ arrives
HWI
semaphore_post(Task1_sem)
task1 unpends and runs
SPI_open()
SPI_transfer() // read 4 bytes
SPI_close()
semaphore_post(Task2_sem)
task1 pend
task2 unpends and runs
SPI_open()
SPI_transfer() // write 4 bytes
SPI_close()
task2 pend
wait for next IRQ