ChibiOS/RT 2.2.8 RTOS update

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.

The download is ChibiOS20120117.zip at Google Code Archive - Long-term storage for Google Code Project Hosting..

Had a look at this OS today. I could compile the first example without problems. I'm looking forward to do more tests in the next few days. Thank you.

Cool, just what I was looking for. Do you have any idea what the values should be in board.c for Atmega8a?

OCR0A = 128;
TIMSK0  |= (1 << OCIE0A);

Gives me compilation error. And I'm somewhat uncertain about TIMER0_COMPA_vect: warning: 'TIMER0_COMPA_vect' appears to be a misspelled signal handler

Worked on my Mega so compared some datasheets and replaced it with the following:

TIMER1_COMPA_vect
...
OCR1A = 128;
TIMSK  |= (1 << OCIE1A);

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 :slight_smile: -- 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
}

/** @} */

Looks like ChibiOS was updated on 2/5 to v2.4.0.

How hard was it to port the 2.2.8 version?

I will look at 2.4. It has a lot of new stuff for ARM but AVR may not be hard to port to Arduino.

Looking forward to it :slight_smile:

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.