timerafter() not firing for ~20 seconds

Technical questions regarding the XTC tools and programming with XMOS.
ashleyb
Member
Posts: 14
Joined: Sun Dec 20, 2009 1:08 am

timerafter() not firing for ~20 seconds

Post by ashleyb »

Hi All,
I'm having some fun trying to debug why the polling timer used for reading values from hardware doesn't fire for about 20 seconds, the code is essentially

Code: Select all

	timer t;
	unsigned timeout;
	unsigned receive_poll_period = 100000000;
	uint8_t reg;
	
	t :> timeout;
	
	timeout += receive_poll_period;
	
	while(1)
	{
		select
		{
			case t when timerafter(timeout) :> unsigned fire:
				printhexln(timeout);
				printhexln(fire);
				
				reg = readReg();
				
				printhexln(reg);
				
				//Do Stuff here
				
				timeout += receive_poll_period;
				break;
		}
	}
This results in the following printout

Code: Select all

6C3AFA6D
6C3AFA71
0
7230DB6D
7230DB71
0
7826BC6D
7826BC71
0
7E1C9D6D
7E1C9D71
0
84127E6D
84127E71
0
<<stuck here for ~20 seconds>>
8A085F6D
7F8494
0
8FFE406D
22AA16C
0
95F4216D
3D72D76
0
9BEA026D
58271B4
0
A1DFE36D
72DA462
0
A7D5C46D
8D97310
0
ADCBA56D
A8203B6
0
B3C1866D
C2D767C
0
B9B7676D
DD82396
0
BFAD486D
F8293F0
0
C5A3296D
112BBD0A
0
CB990A6D
12D630DB
0
D18EEB6D
148019F8
0
D784CC6D
162CA079
0
DD7AAD6D
17D68F2A
0
E3708E6D
19819913
0
E9666F6D
1B2E5F64
0
EF5C506D
1CD9CA05
0
F552316D
1E85094A
0
FB48126D
202EBBFF
0
13DF36D
21DD07A0
0
733D46D
23865A46
0
D29B56D
252FADD8
0
131F966D
26DD04B6
0
1915776D
288AED77
0
1F0B586D
2A365A2C
0
2501396D
2BE257CD
0
2AF71A6D
2D904812
0
<<very rapidly advances to here>>
30ECFB6D
30ECFB71
0
36E2DC6D
36E2DC71
0
3CD8BD6D
3CD8BD71
0
42CE9E6D
42CE9E71
0
48C47F6D
48C47F71
0
4EBA606D
4EBA6071
0
54B0416D
54B04171
0
I've tried with both int and unsigned types for the timeout and receive_poll_period, neither changes the behaviour.

It looks to me like a rollover issue with timerafter(). My understanding of timerafter() is that as long as what I am asking for is within (2^31) ticks into the future then it will wait, otherwise it will fire immediately.

I'm using the 11.11.1 tools

Has anybody else experienced this and worked out a solution?

Thanks,

Ashley


User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

Use the "long" type for any time variables, as the time returned is a long. You may be exceeding the maximum of a 32 bit type (long is 64 bits)

EDIT: See Segher's post, this is wrong. I was thinking of Java. Don't know what could be causing that.
Last edited by rp181 on Mon Sep 10, 2012 1:33 pm, edited 2 times in total.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

No. "long int" is 32 bits, just like "int"; and timer values are 32-bit.

See http://www.xmos.com/xs1-data-types.