This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Implementing a simple multi threaded environment using CCS and an MSP430 device

Other Parts Discussed in Thread: MSP430F5336

Hi,

I don't have any experience using multi threaded environments.  However, I have a need that may require me to go one.  I have a system using an MSP430F5336 device and need to add in pre-coded drivers for the CC3000.  The drivers are written from the perspective that nothing else is running or needs cpu cycles for extended periods of time (multiple seconds) while waiting for events to occur.  That will not work with my system because there are functions in it that need to be taken care of in a timely fashion (that can't be interrupt driven).  I don't have an OS in my system (or, if you want to call it, I have a very simple OS that I have written myself).

The question is: does anyone know a simple way to implement a multi threaded environment - so as not to have a large impact on my existing system?  Is there another simpler way to go about this?

Thanks,

Brent

  • When you introduce multitasking, extra CPU cores does not appear. Tasks shall give away CPU time for other tasks or shall be interrupted preemptively. Unfortunately you say that other code can't be interrupt-driven so basically you are stuck. You need to redesign at least part of your system. Bad news are that it is very hard to apply multitasking to multitasking-unaware low level, hardware-accessing code without adapting it for cooperative or preemptive multitasking.

  • There are two ways to implement multitasking.

    The common way is to have a supervisor that interrupts a running task, saves all registers and switches the stack, the continues to execute a task that was interrupted the same way previously. Almost all OS versions out there work this way.
    The difference between preemptive or cooperative is just that in a preemptive multitasking, the thread will be interrupted without noticing and without caring for it, while in cooperative multitasking, it has to manually call a function that does the switching.

    The less common way is a nested state machine.

    Main calls different functions in a loop or based on a priority pattern. Each function is a state machine. It looks at its current state, does some work base don it, changes the state information and returns back to main.Next time it is called, it continues the job.
    This is how different ISRs coexist (or at least should): the are called, know what to do and exit when done, to be called later again: Things like sampling ADC data, filling a ringbuffer by incoming UART data, or initializing a hot-plugged SD card can be done in the background by this way. Extending it to non-interrupt driven code gives cooperative multitasking without the need of task (stack) switching etc.

**Attention** This is a public forum