Kernel modification

emgi2008 wrote on Thursday, November 20, 2008:

Currently I am considering the application of FreeRTOS for a robotics project. The processor of choice would be the ATmega128 which is an 8 bit AVR risc processor.
One of the most vital tasks would be keeping track of the odometry. A black/white disc turns on the motor-axle and this movement is registered by a sensor.
This can be accomplished in several ways:
1: using hardware-counters and read these in using a port but 8 IO lines is a lot on an MCU like this.
2: Connect the motion-sensor directly to an input. This solution would only take uo two IO lines and is hence more attractive, at least to me.

The interval at which the IO lines need to be monitored is almost as high as the kernel tick-rate (500-1000Hz) Writing a task for this seems a bad idea as it would leave no timeslots for other processes to run. Instead, I was considering to run the poll routine as part of the tick-interrupt. Using AVR assembly would consume an extra 20-40 cycles at most.
Altough this overhead is incorporated in each tick-cycle, this seems a more viable solution than writing a dedicated task that should run every 10ms or so. My proposed code is below but I am curious to find about other solutions to this challenge.
Tips about how and where to add (port.c?) this code to FreeRTOS are most welcome also!
in r16,PIND
mov r17,r16
lds r18,pdstore ;temp byte that contains the previous status of PIND

eor r16,r18
bst r16,0
brtc right

left: ;maintain a 16bit unsigned counter
lds r19,leftcnt00
inc r19
sts leftcnt00,r19
brneĀ  right
lds r20,leftcnt01
inc r20
sts leftcnt01,r20

right: ;maintain a 16bit unsigned counter
bst r16,1
brtc ready

lds r19,rightcnt00
inc r19
sts rightcnt00,r19
brneĀ  ready
lds r20,rightcnt01
inc r20
sts rightcnt01,r20

sts pdstore,r17


davedoors wrote on Friday, November 21, 2008:

You can add code into the tick interrupt using the tick hook.

Set configUSE_IDLE_HOOK to 1 in FreeRTOSConfig.h. Then define a function called vApplicationTickHook() into which you put your code. You might have to define this as an assembly function in your case, or a naked C function that has inline assembly code in it.

emgi2008 wrote on Friday, November 21, 2008:

Thanks a tonne!
Assembly programming is not an issue for me but I am having trouble with the ins & outs of WinAVR GCC and I am pretty new to FreeRTOS as well.
I guess that I will find out how to do this sooner or later and learn a lot on the way.

emgi2008 wrote on Friday, November 21, 2008:

You probably meant: configUSE_TICK_HOOK?