How do I make better use of ETPU_function parameters from inside a subordinate C function?

ETPU_function parameters don't just pertain to the code in the ETPU_function body; they are relevant to everything that happens in the thread. It would be undesirable to pass these parameters around, and very difficult to get a globally-valid reference.

This item describes a way to use a matched set of ETPU_function parameters and a special global pointer to get access to the parameters in a C function.


I want to assign an ETPU_function to more than one channel. Will all channels share static variables in common?

Each channel, when it runs a shared ETPU_function, can have its own function frame based at its own CPBA setting. This allocation contains parameters and local static variables.


How do I access the angle clock?

The angle clock hardware allows microcode to watch the turning of a gear, and act at angles or rotations.

The TPR register, type register_tpr is specified as a structure:


How do I use eTPU semaphores?

The short answer: assign a number from 0 to 3 to channel.SMPR, and loop until channel.SMPR tests true. Perform the sensitive work to be protected by the semaphore, and assign -1 to channel.SMPR.

Alternatively, use these macros in eTPUC_common.h:


Does eTPU_C support signed divide?

No. Signed divide is not supported at this time.


I've performed an MDU division in my code. How can I access the remainder?

Access the MACH register directly:

Result = Value1 / Value2;  
Remainder = mach;

The host and eTPU are performing read-modify-writes but the eTPU is overwriting the host's update. Is this a bug?

I'm having problems when the host and eTPU are using variables in the same PRAM word. Both are performing read-modify-write sequences on their own words, but the eTPU is overwriting the host's update. Is this a bug?

No, but it will require you to use semaphores to arbitrate access to the PRAM location.


How can I recover the the contents of the Capture registers after ERT_A/B have been written over by programming a match?


chan = chan;

The compiler will not optimize this out, as there are side effects.

Recovering the Capture register values

When a thread starts, ERT_A/B are loaded with the values of the Capture registers. This code reloads those values after using ERT_A/B for other purposes.


I need to place variables manually. How can I do this?

You can place variables in their declaration:

type identifier @ address;

Simply append an @ symbol and a valid address. Since eTPU_C can calculate constant expressions at compile time, you can use relative addresses:


How do I access parameters coherently?

Add the following declarations to your program:

Syndicate content