dit projekt
|
my own small KeRNeL adapted for Arduino
(C) 2012,2013,2014,...,2022
Jens Dalsgaard Nielsen jdn@e s.aa u.dkhttp://www.control.aau.dk/~jdn Section of Automation & Control Aalborg University, Denmark
"THE BEER-WARE LICENSE" (frit efter PHK) jdn@e wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return :-) or if you are real happy then ... single malt will be well received :-) s.aa u.dk
(C) Jens Dalsgaard Nielsen
KRNL is a preemptive realtime kernel here ported for Arduino
See krnl.h for documentation or follow the links below
One note before starting:
In standard version you can only select 1 millisecond in k_start. Otherwise it will not start
All initialization must be carried out after k_init and BEFORE k_start
So no creation of semaphores, tasks, etc when the system is running.
Why ? because we are dealing with embedded systems and once your system is configured it shall just run.
I do also really advise not to use dynamic memory after k_start: no malloc and free when your system is running.
If ... you need to do so please protect memory by a mutex (semaphore + k_wait and k_signal) or just encapsule malloc in DI() and EI(). And never never use and rely on free. You may end up with fragmented memory which on the long run is of no use.
So the advise is to
Use freeRam for testing (part of krnl)
On the 1280/2560 a few more bytes is used due to extended program counter register
KRNL itself uses approx 190B before allocating task/sem/msgQ descriptors
If any call fails (like no more RAM or bad parameters) KRNL will not start but will return an error code in k_start
_i indicates that no lock/unlock(disable/enable) is carried out
https://ceezblog.info/2018/07/10/arduino-timer-pwm-cheat-sheet/
UNO and mega uses timer2 for krnl ticks so avoid using libraries that are using these timers
So look below and observe that UNO timer2 has normally PWM support based on timer2 on pin 3 and 11
On UNO tone do also use timer2 !! so dont use tone hen running timer (or find library newTone)
Arduino UNO (ATmega328p) has three 8bit timers
Arduino Mega has six 8bit timers
Timer5 - is on pin 46, 45, 44
Don’t mess with Timer0 since we need to use millis() or micros() for measuring time
Welcome to the real world :-)
There exist some pitfalls you may encounter, when programming your Arduino and making use of functions or libraries that uses timers.