Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Kernel modification

Posted by emgi2008 on 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!
;PD0=odo-left
;PD1-odo-right
begin:
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

ready:
sts pdstore,r17
rts

Regards,
emgi

RE: Kernel modification

Posted by Dave on 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.

RE: Kernel modification

Posted by emgi2008 on 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.

RE: Kernel modification

Posted by emgi2008 on November 21, 2008
You probably meant: configUSE_TICK_HOOK?


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS