avr-os
avr-os copied to clipboard
Can't execute sample code on Mega2560
Hi @chrismoos
I facing a problem when running sample code on Mega2560, which it's works on Uno.
Sample Code:
#include "Arduino.h"
#include <Wire.h>
#include "LiquidCrystal/LiquidCrystal_I2C.h"
#include <util/delay.h>
extern "C" {
#include "avros/os.h"
}
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
spinlock_t mutex;
void kernel_task(void *arg) {
while(1) {
spinlock_acquire(&mutex);
lcd.setCursor(0, 0);
lcd.print("kernel: " + String((long)os_get_uptime()));
spinlock_release(&mutex);
os_sleep(1000);
}
}
void user_task(void *arg) {
int x = 0;
while(1) {
spinlock_acquire(&mutex);
lcd.setCursor(0, 1);
lcd.print("user_task: " + String(x++));
spinlock_release(&mutex);
os_sleep(2000);
}
}
void setup() {
lcd.begin(16, 2);
lcd.print("...");
os_init();
}
void loop() {
spinlock_init(&mutex);
os_schedule_task(kernel_task, NULL, 0);
os_schedule_task(user_task, NULL, 1);
os_loop();
}
This is the result when running on Mega2560, it is stucking after calling os_init()
But same code run on Uno, it is works...
Thanks.
Chalos
@chalos Any updates? My sample project doesn't work on a Funduino board (Mega 2560) when running from current master
branch.
@chalos @kneth how are you running it? Arduino IDE?
Yes, I am using Arduino IDE 1.6.
@kneth Different devices have different preprocessor definitions defined and the Arduino IDE doesn't use the Makefiles that set these.
For example in devices/arduino/mega2560
these are defined:
TARGET_OS_TASK_STACK_SIZE := 512
TARGET_OS_TICK_INTERVAL_MS := 10
TARGET_OS_MAX_TASKS := 18
You can try manually adding #define
for these either in the Arduino global CFLAGS
or in the actual avr source files.
@chrismoos I'll give it a shot and report back.