I recently needed to rework a lot of code provided by XMOS - since I wnated to reuse parts of it.
While digging through the code I noticed some specifics of XC that makes code analysis really hard:
You have a lot of methods that start or use threads, that simpy pass a bunch of Ports and Channels around and it is really hard to understand what is going on for several reasons:
- There are allways a number of Ports that fulfill a certain function: like RX/TX for UART - they are passed as single function arguments - so it is hard to understand what Ports define a functional block.
- Normally two channel ends are in completely different source files and decoding the protocol that is spoken over the channel is quite hard to understand.
Define functional blocks of Ports as a struct. So that you got for example a UART_Ports - struct. Or does this reduce flexibility too much?
Redefine Channels e.g. with a typedef or similar to make sure which protocol is used - you can then implement the reader and writer routines for a Channel in a single source file. So that you see: This function is using a UART-Communication-Channel. Theoretically a Channel would be a great example for a classical object (as in C++) - but C++ would probably eat up too much precious RAM.
Or did I just not understand reading XC code well enough?