To use OSA in your application you need to do the following:
Create a project using IDE. In addition to all your project files add the file osa.c to your project (it contains all system variables and function prototypes);
In your project folder create the file
OSAcfg.h. This file is used to specify OSA compilation parameters (like number of tasks, timer type etc). In the simplest case this file can be empty. You can use the program
OSAcfg_Tool to create/modify this file;
Insert the line "include <osa.h>" into all files that will use OSA services;
Add two "Include search paths" to project options:
the path to
OSAcfg.h for your current project
the path to osa.h;
At the beginning of function main() insert a call to the
OS_Init() service;
At the end of function main() insert a call to the
OS_Run() service;
To add the osa.c file click right button in Workspace window, and select the "Add file…"
Include-paths are set through project options: menu "Project/Build options/Project…", tab "Directories".
void main (void)
{
OS_Init();
...
OS_Task_Define(Task_Buttons);
OS_Task_Define(Task_LEDs);
OS_Task_Define(Task_LCD);
...
OS_Task_Create(Task_Buttons);
OS_Task_Create(Task_LEDs);
OS_Task_Create(Task_LCD);
}
Set the library path: menu "Project/Build options/Progect…", tab "Directories", combo "Library Search Path". Enter the path for library files (e.g. c:\mcc18\lib).
In the project options window select the tab "MPLAB C18", category "Optimization" and check off the "Procedural absraction"
Don't forget to add the linker script file: right mouse button on "Linker Script" folder in "Workspace" window and select the .lkr file for your controller (see "MCC18\lkr")
void main (void)
{
OS_Init();
...
OS_Task_Define(Task_Buttons);
OS_Task_Define(Task_LEDs);
OS_Task_Define(Task_LCD);
...
OS_Task_Create(Task_Buttons);
OS_Task_Create(Task_LEDs);
OS_Task_Create(Task_LCD);
}
To add the osa.c file select menu "Project/Add File To Project…"
Include-path arre set througth menu "Project/Edit Search Paths…". In dialog box there are two path lists: Source Files and Header Files. We need the "Header files". Press "green plus" icon to add include-paths.
The linker must be informed about functions that will be used as tasks:
#pragma funcall main Task_Buttons // Tell linker that function will be
// called indirectly
void Task_Buttons (void)
{
...
}
to add the osa.c file into project do right-click in Workspace window (AVR GCC) on "Source Files" folder and select "Add Existing Source File(s)…"
include-path are set througth menu "Project/Configuration options", tab "Include Directories"
To add the osa.c file select menu "Project/Add files…"
include-path are set througth menu "Project/Options", category "C/C++ compiler", tab "preprocessor", field "Additional include directories"
Than in tab "Optimization" check off "Cross call"
to add the osa.c file into project do right-click in Workspace window on the "Source" folder and select "Add Files To Folder…"
include-path are set througth menu "Project/Options", category "C compiler", tab "preprocessor", field "Additional include directories"
to add the osa.c file select menu "Project/Add Item…"
include-path are set througth menu "Project/Properties", folder "Application Optios", sub-folder "Directories"