/*
*********************************************************************************************************
*                                               uC/OS-II
*                                         The Real-Time Kernel
*
*                             (c) Copyright 1998-2005, Micrium, Weston, FL
*                                          All Rights Reserved
*
*
*                                            ARM Sample code
*
* File : APP.C
* By   : Eric Shufro
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                                VARIABLES
*********************************************************************************************************
*/

OS_STK        AppStartTaskStk[APP_TASK_START_STK_SIZE];

/*
*********************************************************************************************************
*                                            FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  void  AppStartTask(void *p_arg);

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx(INT8U rx_data);
#endif

/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.  It is assumed that your code will call
*               main() once you have performed all necessary 68HC12 and C initialization.
* Arguments   : none
*********************************************************************************************************
*/
extern void init_lcd(void);
extern void lcd_print_crlf(char *s);
extern void lcd_clear(void);
extern void page_delay(void);
extern void delay(int);
extern unsigned char line_ctr;
extern unsigned time_to_clear;

void  main (void)
{
    INT8U  err;


    BSP_IntDisAll();                       /* Disable all interrupts until we are ready to accept them */

    init_lcd();                            /* initiallize the LCD IO  */
    lcd_clear();                           /* clear the display  */

    lcd_print_crlf("uCOS-II Demo    ");
    lcd_print_crlf("(c) Micrium 2006");

    lcd_print_crlf("Init OS...      ");
    OSInit();                              /* Initialize "uC/OS-II, The Real-Time Kernel"              */

    lcd_print_crlf("Setup Tasks...  ");
    OSTaskCreateExt(AppStartTask,
                    (void *)0,
                    (OS_STK *)&AppStartTaskStk[APP_TASK_START_STK_SIZE-1],
                    APP_TASK_START_PRIO,
                    APP_TASK_START_PRIO,
                    (OS_STK *)&AppStartTaskStk[0],
                    APP_TASK_START_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 11
    OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif

    lcd_print_crlf("Start OS...     ");
    OSStart();                             /* Start multitasking (i.e. give control to uC/OS-II)       */
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                          STARTUP TASK
*
* Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
*               initialize the ticker only once multitasking has started.
* Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                  used.  The compiler should not generate any code for this statement.
*               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
*                  set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/

static  void  AppStartTask (void *p_arg)
{
   (void)p_arg;

    BSP_Init();                             /* Initialize BSP functions                                */

#if OS_TASK_STAT_EN > 0
    OSStatInit();                           /* Determine CPU capacity                                  */
#endif

#if OS_VIEW_MODULE > 0
    OSView_Init(38400);
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();                       /* Enable Rx Interrupts                                    */
#endif

    LED_Off(0);                             /* Turn OFF all the LEDs                                   */
    while (TRUE) {                          /* Task body, always written as an infinite loop.          */
        LED_On(1);
        LED_Off(2);
        OSTimeDlyHMSM(0, 0, 0, 100);
        LED_Off(1);
        LED_On(2);
        OSTimeDlyHMSM(0, 0, 0, 100);
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx (INT8U rx_data)
{
}
#endif
