SHDesigns: Embedded Systems Design, Consulting and Developer Resources Page hits:


CoExec is a simple task switcher for use with the Dynamic C compiler.

This exec is not designed to compete with uCOS or other higher level execs. Initially, it was written to help users port code to Softools C. Recent versions of Dynamic C and their costate/cofunction code has proven too unreliable. The costates just did not work as intended due to compiler bugs. SHDesigns was forced to port CoExec to DC from Softools in order to get a project finished and reliable.

Note: this library does not support DC 10.x or the 4000 and 5000 series processors. Due to lack of support from ZW, support for these processors is not planned.

A discussion topic has been set up on the SHDesigns rabbit board:

CoExec has been used by SHDesigns for porting programs written for the Z-World DC compiler to Softools. It does not emulate the DC costate and cofunc model. It does provide similar functionality. It has worked reliably in several SHDesigns projects and has been used successfully by other users.

Real task switching: No hidden codata structures and non ANSI syntax.

CoExec provides real tasks instead of costates. This eliminates much of the task "churning" of the DC model. Each task has its own stack. This isolates stack problems between tasks. Delays, i.e. waitMS(), are implemented in the exec so the task does not have to repeatedly call the same function just to wait for a delay time. The task is marked with a wake up time and needs no processing until the time has elapsed.

CoExec uses ANSI C syntax so it can be easily portable. In fact, once a Dynamic C program uses CoExec, task switching can be ported to Softools ANSI C easily by just linking in the Softools CoExec lib.

The library emulates the yield, waitfordone, wfd, waitfor, cofunc and scofunc syntax of DC. In fact most of this is just #defined as an empty string as the exec handles these issues. Any function can be called from a task and then call a wait function. There is no need to make all functions "cofunc". This is due to the simple stack-based task switching. No need for the compiler to build a table to save state information. Most library cofunction calls should work with CoExec, however,using non-cofunctions and adding the needed exec wait calls is much more efficient.

Multiple threads each with their own stack and private data.

Each tread can be passed a parameter when it is created. This allows the same thread to be run more than once concurrently. Each thread would use the parameter to access different shared variables. An example is a web proxy task. Multiple copies of the task are run, each is passed a structure with its own socket structure. So if 4 tasks are run, then 4 connections can be processed at the same time, each with its own socket and state information.

It also reduces root memory. Each task can have up to a 4096-byte stack allocated from xmem RAM. With DC and costates, all costates share one 4k stack and use root tables to manage task switching. Also, DC task-switching copies data on and off the stack to do task switching. It is slow, unreliable, and completely undocumented on how it works. CoExec includes a stack check function to verify stack usage at run time.

CoExec does fast task switching. Usually about 6us on a 44mHz CPU. It can perform a task switch without disabling interrupts. So it does not interfere with the serial ports or interrupt processing. Tasks can be aborted, restarted, paused, or run from another task.

Additional Features:

It also supports Events. Tasks can wait on an event signaled from another task. Semaphores can also be used externally (example given.)

There is some support for preemptive tasking. However, the DC debugger does not play well with task switching from interrupts. Preemption can be used stand-alone with no problems. CoExec uses cooperative task switching and is efficient and will work fine with no need for preemption in most cases..

A sample application is included. It demonstrates most of the features of the exec and shows how the tasks operate. The full source and sample projects are now available.

Licensing:

CoExec is free for personal use with no support.The documatation and samples should be sufficient for users to implement the library as part of their code.

For commercial applications or paid-support, SHDesigns asks for a $50 donation to the project to help cover the cost of support. There are no per-product or per-unit licensing fees. A donation is not required for use of the library, mainly to encourage SHDesigns to continue support of the library. A donation can be sent via the online store via credit card or PayPal: HERE.

The code is free for users to use in their applications. They may modify it as they need. They may not distribute modified sources except to their own users (prevents SHDesigns from having to support foreign code.)

Feel free to download the library, documentaion and sample application. If you use it commercially, then consider making a donation.

The Documentation can be viewed here:

The lib, include file, documentation and sample project can be downloaded here:

Additional Information: Rabbit Libraries Home Page - SHDesigns Home Page