Hello,
I'm trying to test an alarm assigned to a software counter. I have defined an extended task (
IncrCounter_Task ) that runs every 10ms (using a cyclic alarm
IncrCounter_Alarm that expire every 10ms). Inside this task I call the function
IncrementCounter(ToggleLED_Counter);. I have also defined an alarm (
ToggleLED_Alarm) assigned to the SW counter
ToggleLED_Counter. When this alarm expires it raises an event for another task (
ToggleLED_Task). Inside this task a LED connected to pin PB0 is toggled. So in my scenario the
ToggleLED_Counter gets a tick every 10ms. The alarm
ToggleLED_Alarm is configured as a relative to expire every 50 ticks (500ms). The end result is that the LED should blinking with frequency 1Hz.
If I define the alarms to run automatically (
AUTOSTART = TRUE;), the example works as is expected. The problem is if I try to run them in the software with the API
SetRelAlarm(). Then, I think the program loops inside
IncrementCounter() by some reason.
Below you can find the full configuration of tasks, counters and alarms. In attachments I have attached complete examples - working and non-working.
Code: Select all
CPU mySystem {
/******************************************************************************************
*
* Core OS settings
*
******************************************************************************************/
OS myOs {
EE_OPT = "__AVR8_GCC_C99__";
CFLAGS = "-O0 -g";
CFLAGS = "-DF_CPU=16000000L";
STATUS = EXTENDED;
STARTUPHOOK = TRUE;
ERRORHOOK = TRUE;
SHUTDOWNHOOK = FALSE;
PRETASKHOOK = FALSE;
POSTTASKHOOK = FALSE;
USEGETSERVICEID = FALSE;
USEPARAMETERACCESS = TRUE;
USERESSCHEDULER = FALSE;
CPU_DATA = AVR8 {
COMPILER = GCC;
MULTI_STACK = TRUE;
};/* End of CPU_DATA */
MCU_DATA = MEGA {
MODEL = MEGA_328p;
};/* End of MCU_DATA */
/*KERNEL_TYPE = OSEK {
CLASS = ECC1;
};*//* End of KERNEL_TYPE */
};/* End of OS */
/******************************************************************************************
*
* Source files
*
******************************************************************************************/
APPDATA myApp {
APP_SRC = "Source/main.c";
APP_SRC = "Source/tasks.c";
APP_SRC = "Source/LedControl.c";
APP_SRC = "Source/ErrorHandler.c";
};/* End of APPDATA */
/******************************************************************************************
*
* APPLICATION MODES
*
******************************************************************************************/
/******************************************************************************************
*
* TASKS
*
******************************************************************************************/
TASK ToggleLED_Task {
PRIORITY = 10;
ACTIVATION = 1;
AUTOSTART = TRUE{
APPMODE = OSDEFAULTAPPMODE;
};
STACK = PRIVATE{
SIZE = 100;
};
SCHEDULE = FULL;
EVENT = ToggleLED_Event;
};/* End of TASK */
TASK IncrCounter_Task {
PRIORITY = 5;
ACTIVATION = 1;
AUTOSTART = TRUE{
APPMODE = OSDEFAULTAPPMODE;
};
STACK = PRIVATE{
SIZE = 100;
};
SCHEDULE = FULL;
EVENT = IncrCounter_Event;
};/* End of TASK */
/******************************************************************************************
*
* RESOURCES
*
******************************************************************************************/
/******************************************************************************************
*
* COUNTERS
*
******************************************************************************************/
COUNTER SystemCounter {
MINCYCLE = 1;
MAXALLOWEDVALUE = 65535;
TICKSPERBASE = 1;
TYPE = HARDWARE {
DEVICE = "TIMER1_COMPA";
SYSTEM_TIMER = TRUE;
};
SECONDSPERTICK = 0.001;
};
COUNTER ToggleLED_Counter {
MINCYCLE = 1;
MAXALLOWEDVALUE = 1000;
TICKSPERBASE = 1;
TYPE = SOFTWARE;
};
/******************************************************************************************
*
* ALARMS
*
* ****************************************************************************************/
ALARM ToggleLED_Alarm {
COUNTER = ToggleLED_Counter;
ACTION = SETEVENT {
TASK = ToggleLED_Task;
EVENT = ToggleLED_Event;
};
AUTOSTART = FALSE; /*TRUE {
APPMODE = OSDEFAULTAPPMODE;
ALARMTIME = 50;
CYCLETIME = 50;
};*/
};
ALARM IncrCounter_Alarm {
COUNTER = SystemCounter;
ACTION = SETEVENT {
TASK = IncrCounter_Task;
EVENT = IncrCounter_Event;
};
AUTOSTART = FALSE; /*TRUE {
APPMODE = OSDEFAULTAPPMODE;
ALARMTIME = 10;
CYCLETIME = 10;
};*/
};
/******************************************************************************************
*
* EVENTS
*
******************************************************************************************/
EVENT ToggleLED_Event
{
MASK = AUTO;
};
EVENT IncrCounter_Event
{
MASK = AUTO;
};
/******************************************************************************************
*
* MESSAGES
*
******************************************************************************************/
/******************************************************************************************
*
* INTERRUPTS
*
******************************************************************************************/
};
Code: Select all
/* System headers */
#include <ee.h>
#include <avr/io.h>
#include <util/delay.h>
/* User headers */
#include "LedControl.h"
TASK(ToggleLED_Task)
{
SetRelAlarm(ToggleLED_Alarm,50,50);
for(;;)
{
WaitEvent(ToggleLED_Event);
ClearEvent(ToggleLED_Event);
LedCnt_ToggleLed();
}
}
TASK(IncrCounter_Task)
{
SetRelAlarm(IncrCounter_Alarm,10,10);
for(;;)
{
WaitEvent(IncrCounter_Event);
ClearEvent(IncrCounter_Event);
IncrementCounter(ToggleLED_Counter);
}
}
BR
Dimo