Whilst trying to get the hang of the XMOS tools I have been playing with a simple pin toggling loop using the port timer. The code is shown below.
First up I use XTA to tell me the execution time of the loop in the toggle_pin thread. For this I have the xta pragma shown in the code and an xta script like so:
Code: Select all
analyze loop toggle_loop
set required - 200 ns
print summary
Code: Select all
Route(0) loop: toggle_loop
Pass with 2 unknowns, Num Paths: 1, Slack: 12.5 ns, Required: 200.0 ns, Worst: 187.5 ns, Min Core Frequency: 375 MHz
Anyway it looks as if my pin toggling loop is only good for 187ns per transition.
Next I move on to the simulator. Notice that in the code I have a PERIOD defined as 15. This gives a output on the simulator of the pin toggling every 150ns.
So there it is. The simulator is saying I can run the code about 20% faster than the timing analyser.
Why is that?
Code: Select all
#include <platform.h>
//#define PERIOD 20 // 200ns OK
#define PERIOD 15 // 150ns OK
//#define PERIOD 14 // 100ns FAIL
port p = PORT_UART_TX;
int x = 0;
int y;
void do_some_stuff()
{
x = ~x;
}
void toggle_pin()
{
int t;
p <: 0 @ t; // Timestamped output, 0 goes to p, port clock goes to t
t += PERIOD;
while (1)
{
#pragma xta endpoint "toggle_loop"
p @ t <: x ; // Timed output x goes to p at time t.
do_some_stuff();
t += PERIOD;
}
}
void waste_thread(){}
int main()
{
par
{
on stdcore[0]: toggle_pin();
on stdcore[0]: waste_thread();
on stdcore[0]: waste_thread();
on stdcore[0]: waste_thread();
on stdcore[0]: waste_thread();
}
return (0);
}