I have updated the ChibiOS/RT library to version 2.2.8.
This library is a simple way to use the ChibiOS/RT RTOS on 328 and Mega Arduinos.
I have added a function to determine the amount of unused stack space for each thread and an example, chStackUse, to demonstrate analysis of thread stack use.
Which seems to work without me knowing what they do at all..
If it is necessary to run an rtos on this small chip is another question -- clocks in at about 2.8kB though, could probably be made smaller by disabling some features from the kernel.
Hmz.. This really brings me back. Don't remember so much from school anymore, but we did make our own (don't remember if it was preemptive or co-op) OS on floppys.. Those were the times. Should have had MCUs though.
If anyone cares, here are the changes required to board.c and chcore.c. Do note I've not extensively verified this works but everything I've tested passed without issue; though admittedly barely extends beyond simple scheduling. I'll also point out, all of the changes have been wrapped for conditional compilation against the atmega8 (atmega8-16pu).
board.c file:
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,2011 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
---
A special exception to the GPL can be applied should you wish to distribute
a combined work that includes ChibiOS/RT, without being obliged to provide
the source code for any proprietary components. See the file exception.txt
for full details of how and when the exception can be applied.
*/
#include "ch.h"
#include "hal.h"
#if defined( __AVR_ATmega8__ )
CH_IRQ_HANDLER(TIMER1_COMPA_vect) {
#else
CH_IRQ_HANDLER(TIMER0_COMPA_vect) {
#endif
CH_IRQ_PROLOGUE();
chSysLockFromIsr();
chSysTimerHandlerI();
chSysUnlockFromIsr();
CH_IRQ_EPILOGUE();
}
/*
* Board-specific initialization code.
*/
void boardInit(void) {
#if defined( __AVR_ATmega8__)
// Timer 1 for atmega8 w/ IRQ for compare
TCNT0 = 0 ;
OCR1A = 128 ;
TCCR0 |= (1<<CS00) ; // No pre-scaling
TIMSK |= (1 << OCIE1A) ;
#else
/*
* Timer 0 setup.
*/
OCR0A = 128;
TIMSK0 |= (1 << OCIE0A); /* IRQ on compare. */
#endif
}
And the part I changed at the end of chcore.c:
/**
* @brief Start a thread by invoking its work function.
* @details If the work function returns @p chThdExit() is automatically
* invoked.
*/
void _port_thread_start(void) {
asm volatile ("sei");
asm volatile ("movw r24, r4");
asm volatile ("movw r30, r2");
asm volatile ("icall");
#if defined( __AVR_ATmega8__ )
asm volatile ("rcall chThdExit");
#else
asm volatile ("call chThdExit");
#endif
}
/** @} */
I looked at the change log. It doesn't look like there are a lot of changes which will directly effect the AVR port.
This may miss an item here or there, but it should be representative of the real beef in this version.
NEW: Implemented new makefile system for ARM GCC ports, now objects,
listings and output files are generated into a "build" directory and not
together with sources, also implemented a simplified output log mode.
Now makefiles and load script files are requirements and trigger a
rebuild if touched.
NEW: Added a new hook THREAD_CONTEXT_SWITCH_HOOK() that allows to insert
code just before a context switch. For example this hook could be used
in oder to implement advanced power management schemes.
NEW: Improved Event Flags subsystems in the kernel.
NEW: Added a macro THD_STATE_NAMES to chthreads.h. This macro is an
initializer for string arrays containing thread state names.
NEW: Added a new debug option CH_DBG_SYSTEM_STATE_CHECK that ensures the
correct API call protocol. If an API is invoked out of the correct context
then the kernel panics with a debug message.
NEW: PAL driver for AVR.
NEW: Updated AVR demos to use the new PAL driver.
So its not really clear, what, if anything, it really means for the AVR port. Especially if you're using fat16lib's port.
Just the same, I'll happily upgrade when the port is available. I too look forward to it.