What is the correct OSTimeTickHook() implementation on a BL5S220 SBC?

Struggling with a very simple timer setup using the OSTimeTickHook() hook to bump a timer. unfortunately, Timer does not budge.

Here’s the code:

#class auto

#define OS_CPU_HOOKS_EN 1

#use UCOS2.LIB

unsigned count = 0 ;
unsigned temp_count = 0 ;
unsigned last_count = 0 ;
unsigned delta_count = 0 ;

void OSTimeTickHook( void ) ;
void main( void ) ;

// Main line.

void main()

OSTaskCreate( OSTimeTickHook, NULL, 512, 0 ) ;

while ( 1 ) {

	costate {

		temp_count = count ;
    	delta_count = temp_count - last_count;

     	printf( "Count = %u Last = %u Delta= %u

", temp_count, last_count, delta_count) ;
last_count = temp_count ;


	} // costate

} // while

} // main



ld		hl, (count)
inc	hl							; increment counter
ld		(count), hl



The first problem here is that you are mixing uCos and costates. You have to pick one or the other for multi tasking to work as far as I know.

Try taking one of the sample uCos programs and adding the hook into that.


Thank you Peter.

I was able to get the code working this morning by adding the OSStart() routine and moving the test code to another routine using OSTaskCreate( Test_Routine_1, NULL, 512, 0 ) ;
The OSTimeTickHook() is being called correctly.

I started out not using the uCos, but found TIMER B was too fast for a general purpose timer. Is there a better way to setup a 1ms timer on this SBC?

In general, are most developers using the uCos OS for multitasking? I’m not even keen on using the costate. Normally, I just setup a timer interrupt (plus input capture, ADC, serial interrupts) and cycle through state tables in the mainline.

Thank you again!

Kind regards,