Wiki

Clone wiki

ArdOS / config

Configuring ArdOS

To minimize memory usage, ArdOS has been written to be highly configurable. Almost everything in ArdOS can be turned on or off in the ArdOSConfig.h file. You can also change advanced settings like what type of scheduler to use, and how much time tasks at each priority level gets.

Of course if memory and execution time is not at a premium (haha), you can use all the default values in ArdOSConfig.h.

ArdOS is written primarily for use within the Atmel Studio (formerly known as Atmel AVR Studio) suite and some features are incompatible with the Arduino IDE. These are primarily the pinMode, digitalWrite, digitalRead, analogWrite and analogRead routines provided by ArdOS. If you are using ArdOS within the Arduino IDE environment, see below on how to disable these features.

It is recommended that you open ArdOSConfig.h and read the code in conjunction with this document.

Setting the CPU Type

Before using ArdOS you should set the CPU type using the OSCPU_TYPE setting. Valid values are:

  • AT168
  • AT328
  • AT1280
  • AT2560

The default value as shipped is AT328, which will allow you to use ArdOS on the Arduino Uno.

Setting the number of tasks

ArdOS does not support dynamic allocation of memory, and for this reason the number of tasks to be created must be declared ahead of time. To do so, set the OSTASK_COUNT parameter to the number of tasks you intend to create.

You can set OSTASK_COUNT to a number larger than the number of tasks you will have, at the expense of valuable memory, particularly data memory.

OSMAX_TASKS is automatically set to OSTASK_COUNT+1 to cater for the idle task. Do not modify this.

Choosing components to turn on and off.

  • Turning off pre-emption

If you want to use ArdOS as a co-operative multitasker, you can set the OS_PREEMPTIVE flag to 0.

  • Turning off the sleep function

If you don't intend to use the OSSleep() function, you can set the OSUSE_SLEEP flag to 0.

  • Turning off semaphores

If you don't intend to use semaphores to coordinate your tasks, you can set the OSUSE_SEMA flag to 0.

  • Turning off queues

If you don't use queues in your application to pass messages between tasks, you can set OSUSE_QUES to 0.

  • Turning off GPIO

If your application only uses analog inputs and outputs, you can turn off GPIO support by setting USEGPIO to 0

  • Turning off Arduino style digital I/O ArdOS provides you with very fast and compact I/O routines, but these can be difficult to understand and use. For this reason ArdOS provides Arduino style pinMode, digitalWrite and digitalRead functions. To save memory, or if you are using ArdOS within the Arduino IDE, turn these off by setting USEARDGPIO to 0. Note that to use Arduino style digital I/O, USEGPIO must be set to 1.

  • Turning off analog inputs If your application uses only digital inputs, you can turn off analog input support by setting USEADC to 0.

  • Turning off Arduino style analog inputs The native analog input routines provided by ArdOS are much more compact than those provided by Arduino, but for convenience an Arduino style analogRead function is provided. To save memory, or if you are using ArdOS within the Arduino IDE, set USEARDADC to 0. To use Arudino style analog inputs, USEADC must be set to 1.

  • Turning off analog outputs If your application only uses digital outputs, you can turn off PWM support by setting USEPWM to 0.

  • Turning off Arduino style analog output The native PWM routines provided with ArdOS are much more compact than the analogWrite routine provided with Arduino. If you wish to save memory or use ArdOS within the Arduino IDE environment, turn off Arduino style writeAnalog services, set USEARDPWM to 0. To use Arduino style analog output, USEPWM must be set to 1.

  • Turning off support for individual analog output pins Arduino provides analog output on pins 5, 6, 10, 11 and 12. Each pin requires a small amount of code to support it, and to save memory you can turn off the respective PINxPWM (where x is the pin number) by setting it to 0. For example, to turn off support for PWM on pin 5, set PIN5PWM to 0.

Note: The current implementation of ArdOS does not support analog output on pin 12. This is because the timer hardware registers that are used to generate PWM on pin 12 are also used by the ArdOS master clock. This limitation may be removed in future releases.

Advanced Configuration Options

There are several parameters that you can set to fine-tune how ArdOS operates.

  • Choosing a scheduler type The OSSCHED_TYPE controls the type of scheduling that ArdOS will use. The possible values are:

    • OS_PRIORITY: Use a fixed priority scheduler. As long as a task with a higher priority is able to run, it will always have control of the microcontroller. Use this for time-critical applications. Priorities are inverse to their priority numbers allocated when OSCreateTask is called. If you have n tasks, task 0 will have the highest priority while task n-1 will have the lowest.

    • OS_RR: Use a prioritized round-robin scheduler. Every task is given a chance to run in turn, starting from task 0, then 1, up to n-1, then task 0 again. Each task is given a time quantum controlled by OSMIN_QUANTUM and OSMAX_QUANTUM. The highest priority task (denoted by the lowest priority number, usually 0) will run for OSMAX_QUANTUM milliseconds, while the lowest priority task (denoted by the highest priority number, usually n-1 if you have n tasks) gets OSMIN_QUANTUM milliseconds. Tasks with intermediate priorities will get an intermediate amount of running time inversely proportional to their priority number, in steps of OSQUANTUM_FACTOR.

    • OS_RMS: Use rate-monotonic scheduling for periodic tasks. Tasks are prioritized according to their periods. Use this when you have tasks that must run in fixed periods. This scheduler is currently unimplemented.

    • OS_EDF: Use earliest-deadline-first scheduling for periodic tasks. Use this when you have tasks that must run in fixed periods. Priority is given to tasks who are approaching the end of their periods so that they can complete within the allocated period. This scheduler is currently unimplemented.

  • Configuring the Round-Robin Scheduler: As mentioned previously, you can use OSMIN_QUANTUM and OSMAX_QUANTUM to control the amount of microcontroller time allocated to each priority level.

    • OSMIN_QUANTUM: The time quantum in milliseconds allocated to the lowest priority task. This is generally the task with priority number n-1 for n tasks.

    • OSMAX_QUANTUM: The time quantum in milliseconds allocated to the highest priority task. This is generally the task with priority number 0.

      • OSMAX_PRIOLEVEL: The largest priority number used, denoting the lowest priority process. If you intend to have N processes, this is normally N-1.
    • OSQUANTUM_FACTOR: For tasks with priority numbers 1 to n-2, they will be allocated time quantum that are multiples of this factor lesser than the time allocated to the highest priority task. Do not modify this.


Go home

Building ArdOS Applications

ArdOS I/O Access Calls

ArdOS Library Calls

Updated