#include <regf276e.h>
#include <cxfuncs.h>
#define T4_Trap 0x24
unsigned char ucLed1TaskSlot, ucLed2TaskSlot;
unsigned int uiTimerReload;
void Setup(void)
{
// Timer Setup
uiTimerReload = 0xE140; // @64 Mhz we want the timer to fire every 1ms
T4IC = 0x0030; // T4 Interrupt Reserved and set elsewhere
T4 = uiTimerReload;
T4CON = 0x0040;
T4IE = 0;
// Leds Direction Registers
_putbit(1,DP3,9);
_putbit(1,DP3,15);
// Serial Comms
_bfld(DP3,0x0C00,0x0400);
_putbit(1,P3,10);
S0CON = 0x8011;
S0BG = 0x0067; // baud rate 19200
S0TBIR =1;
}
_interrupt(T4_Trap) _using (T4_RB) void T4_vector(void)
{
K_OS_Tick_Update();
//S0TBUF = 'W';
T4 = uiTimerReload + T4;
K_OS_Intrp_Exit();
}
void LED1Task(void)
{
while (1)
{
_putbit(0,P3,9);
}
}
void SerialPrint(char *line)
{
while(*line)
{
while (!S0TBIR) {}
S0TBIR =0;
S0TBUF = *line;
line++;
}
}
void main ()
{
unsigned char status;
Setup();
_putbit(1,P3,9);
_putbit(1,P3,15);
SerialPrint("Setup Completed\n");
K_OS_Init();
SerialPrint("OS Initialized\n"); // OS Initialized
status = K_Task_Create(0, &ucLed1TaskSlot, LED1Task, 128);
status &= K_Task_Start(ucLed1TaskSlot);
if (status == K_OK)
{
SerialPrint("OS Started\n"); // OS Started;
T4IE = 1; // Timer Interrupt enabled
K_OS_Start();
}
else
{
_putbit(0,P3,15);
}
}