/**********************************************************************/
/*                                                                    */
/* File name: app_cfg.c                                               */
/*                                                                    */
/* Since:     2007-02-25                                              */
/*                                                                    */
/* Version:   uip Kernel v1.09                                        */
/*            Copyright (C) 2006..2018 Wang Baojin.                   */
/*                                                                    */
/* Author:    Designed by Wang Baojin(王保进)                         */
/*                                                                    */
/*                                                                    */
/* Purpose:   Task, alarm and counter's definition                    */
/*                                                                    */
/* Distribution: This file is part of uip kernel demo.                */
/*            uip Kernel is free software; you can redistribute it    */
/*            and/or modify it under the terms of the GNU General     */
/*            Public License as published by the Free Software        */
/*            Foundation; either version 2, or (at your option)       */
/*            any later version.                                      */
/*                                                                    */
/*            uip Kernel is distributed in the hope that it will be   */
/*            useful, but WITHOUT ANY WARRANTY; without even the      */
/*            implied warranty of MERCHANTABILITY or FITNESS FOR A    */
/*            PuipICULAR PURPOSE.  See the GNU General Public         */
/*            License for more details.                               */
/*                                                                    */
/*            You should have received a copy of the GNU General      */
/*            Public License along with gpsim; see the file           */
/*            COPYING.txt. If not, write to the Free Software         */
/*            Foundation, 59 Temple Place - Suite 330,                */
/*            Boston, MA 02111-1307, USA.                             */
/*                                                                    */
/*          > A special exception to the GPL can be applied should    */
/*            you wish to distribute a combined work that includes    */
/*            uip Kernel, without being obliged to provide the        */
/*            source code for any proprietary components.             */
/*                                                                    */
/* History:                                                           */
/*   2007/02/25  [WBJ] Create this file.                              */
/*                                                                    */
/**********************************************************************/

#include "uip_kernel_api.h"
#include "demo.h"

/* Counters and Alarm's Definition  */
AlarmBaseType AppAlarmBase[] = 
{
    {
        65535,
        1,
        0,
    },
    
    {
        65535,
        1,
        0,
    }
};

uipCounter AppCounter[] = 
{
    {
        0,                            /* Counter's current value */                  
        0,                                    
        &AppAlarmBase[0],
    },
    
    {
        0,                            /* Counter's current value */                  
        0,                                    
        &AppAlarmBase[1],
    }
};

uipAlarm  AppAlarm[] = 
{
     {
         100,                         /* Alarm value */
         100,                         /* Cycle */
         APP_EVENT_TASK_0,            /* Event */
         &AppCounter[0],              /* Counter */
         0,                           /* CallBack */
         TASK_0_ID,                   /* Task ID */
         uip_ALARM_ON,                /* Alarm state */
         0,                           /* padding byte */
         0,                           /* padding byte */
     },
     
     {
         100,                         /* Alarm value */
         100,                         /* Cycle */
         APP_EVENT_TASK_1,            /* Event */
         &AppCounter[1],              /* Counter */
         0,                           /* CallBack */
         TASK_1_ID,                   /* Task ID */
         uip_ALARM_ON,                /* Alarm state */
         0,                           /* padding byte */
         0,                           /* padding byte */
     },
};

AlarmNumberType AppAlarmNumber = 2;

uipRes AppRes[] = 
{
    {
	   (struct uip_TSK_STRUCT *)0,                     /* Pointer to TCB of task that is using this resource */
       (struct uip_RESOURCE_STRUCT *)0,                /* Link to next resource */
       0,                                              /* Bit value in task priority group
                                                           corresponding to task ready priority */
       RESOURCE_0_CEILING_PRIO,                        /* Resource's mutex ceiling priority */
       0,                                              /* Index value into ready task table 
                                                           corresponding to task ready priority */
       0,                                              /* Bit position in ready table 
                                                           corresponding to task ready priority */
       0,                                              /* Dispatched priority of task that is using this resource */
       0,                                              /* Show the state of resource: 
                                                                           0 not being used; 
                                                                           1 being used      */
       0,                                              /* Padding byte for ARM */
       0,                                              /* Padding byte for ARM */
       0,                                              /* Padding byte for ARM */
	},
};  

ResNumberType AppResNumber = 1;

UIP_CHAR AppMsgBuf[APP_MSG_LENGTH];

uipMsg AppMsg[] = 
{
    {
        MSG_ID_0,                                      /* Message's id */
        0,                                             /* Messages's current state(locked, unlocked, 
                                                          overflow or not etc.) */
        uip_MSG_QUEUED,                                /* Messages's type(unqueued or queued message) */
        0,                                             /* Flags to be set for notifying */
        (UIP_UCHAR_PTR)&AppMsgBuf[0],                  /* Point to buffer stuip address */ 
        (UIP_UCHAR_PTR)0,                              /* Point to buffer address to be writen */ 
        ((UIP_UCHAR_PTR)&AppMsgBuf[0]+sizeof(AppMsgBuf)), /* Point to buffer end address */ 
        (UIP_UCHAR_PTR)0,                              /* Point to buffer address to be read */
        APP_MSG_SIZE,                                  /* Size of messages(bytes) */
        0,                                             /* Event to be set for notifying */
        (VOID *)0,                                     /* Callback routine called when sending message */
        TASK_4_ID,                                     /* The ID of task to be nofified */
        uip_COM_NOTIFICATION_ACTIVATETASK,             /* notification type */    
        0,                                             /* Padding byte for ARM */    
        0,                                             /* Padding byte for ARM */        	
    },	
};

MsgNumberType AppMsgNumber = 1;

/* Task and stack definition */
/* 2012.05.16 增加任务到4个 */
UIP_UINT Task_0_Stack[APP_STACK_SIZE];
UIP_UINT Task_1_Stack[APP_STACK_SIZE];
UIP_UINT Task_2_Stack[APP_STACK_SIZE];
UIP_UINT Task_3_Stack[APP_STACK_SIZE];
UIP_UINT Task_4_Stack[APP_STACK_SIZE];
UIP_UINT Task_App_Idle_Stack[APP_STACK_SIZE];

DeclareTask(TASK_0);
DeclareTask(TASK_1);
DeclareTask(TASK_2);
DeclareTask(TASK_3);
DeclareTask(TASK_4);
DeclareTask(AppIdleTask);

uipTask AppTask[] = 
{
    {	
        TASK_0_ID,                       /* Task's ID */
        READY_STATE | uip_TASK_EXTENDED, /* Taks's execution state */
        TASK_0_READY_PRIO,               /* Task's ready priority */
#ifdef MixPreemption
        TASK_0_DISPATCH_PRIO,            /* Task's dispatched priority */
#else
        0,                               /* padding byte */
#endif
        0,                               /* The occupaited resources list of this task*/
        TASK_0,                          /* Task's entry point */
        &Task_0_Stack[APP_STACK_SIZE-1], /* Task's stack stuiping address */
        APP_STACK_SIZE,                  /* Task's stack size */
        0,                               /* Mask of waited events */
        0,                               /* Mask of setted events */
        0,                               /* Bit value in task priority group
                                            corresponding to task ready priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task ready priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task ready priority */
        0,                               /* Task activated number */
        0,                               /* padding byte */
#ifdef MixPreemption
        0,                               /* Bit value in task priority group
                                            corresponding to task dispatch priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task dispatch priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task dispatch priority */
        0,                               /* padding byte */
        0,                               /* padding byte */
#endif
        0
    },
    
    {
        TASK_1_ID,                       /* Task's ID */
        READY_STATE | uip_TASK_EXTENDED, /* Taks's execution state */
        TASK_1_READY_PRIO,               /* Task's ready priority */
#ifdef MixPreemption
        TASK_1_DISPATCH_PRIO,            /* Task's dispatched priority */
#else
        0,                               /* padding byte */
#endif
        0,                               /* The occupaited resources list of this task*/
        TASK_1,                          /* Task's entry point */
        &Task_1_Stack[APP_STACK_SIZE-1], /* Task's stack stuiping address */
        APP_STACK_SIZE,                  /* Task's stack size */
        0,                               /* Mask of waited events */
        0,                               /* Mask of setted events */
        0,                               /* Bit value in task priority group
                                            corresponding to task ready priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task ready priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task ready priority */
        0,                               /* Task activated number */
        0,                               /* padding byte */
#ifdef MixPreemption
        0,                               /* Bit value in task priority group
                                            corresponding to task dispatch priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task dispatch priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task dispatch priority */
        0,                               /* padding byte */
        0,                               /* padding byte */
#endif
        0
    },

    {
        TASK_2_ID,                       /* Task's ID */
        READY_STATE | uip_TASK_EXTENDED, /* Taks's execution state */
        TASK_2_READY_PRIO,               /* Task's ready priority */
#ifdef MixPreemption
        TASK_2_DISPATCH_PRIO,            /* Task's dispatched priority */
#else
        0,                               /* padding byte */
#endif
        0,                               /* The occupaited resources list of this task*/
        TASK_2,                          /* Task's entry point */
        &Task_2_Stack[APP_STACK_SIZE-1], /* Task's stack stuiping address */
        APP_STACK_SIZE,                  /* Task's stack size */
        0,                               /* Mask of waited events */
        0,                               /* Mask of setted events */
        0,                               /* Bit value in task priority group
                                            corresponding to task ready priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task ready priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task ready priority */
        0,                               /* Task activated number */
        0,                               /* padding byte */
#ifdef MixPreemption
        0,                               /* Bit value in task priority group
                                            corresponding to task dispatch priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task dispatch priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task dispatch priority */
        0,                               /* padding byte */
        0,                               /* padding byte */
#endif
        0
    },

    {
        TASK_3_ID,                       /* Task's ID */
        READY_STATE | uip_TASK_EXTENDED, /* Taks's execution state READY_STATE*/
        TASK_3_READY_PRIO,               /* Task's ready priority */
#ifdef MixPreemption
        TASK_3_DISPATCH_PRIO,            /* Task's dispatched priority */
#else
        0,                               /* padding byte */
#endif
        0,                               /* The occupaited resources list of this task*/
        TASK_3,                          /* Task's entry point */
        &Task_3_Stack[APP_STACK_SIZE-1], /* Task's stack stuiping address */
        APP_STACK_SIZE,                  /* Task's stack size */
        0,                               /* Mask of waited events */
        0,                               /* Mask of setted events */
        0,                               /* Bit value in task priority group
                                            corresponding to task ready priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task ready priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task ready priority */
        0,                               /* Task activated number */
        0,                               /* padding byte */
#ifdef MixPreemption
        0,                               /* Bit value in task priority group
                                            corresponding to task dispatch priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task dispatch priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task dispatch priority */
        0,                               /* padding byte */
        0,                               /* padding byte */
#endif
        0
    },
    
    {
        TASK_4_ID,                       /* Task's ID */
        SUSPENDED_STATE | uip_TASK_EXTENDED, /* Taks's execution state */
        //READY_STATE | uip_TASK_EXTENDED,
        TASK_4_READY_PRIO,               /* Task's ready priority */
#ifdef MixPreemption
        TASK_4_DISPATCH_PRIO,            /* Task's dispatched priority */
#else
        0,                               /* padding byte */
#endif
        0,                               /* The occupaited resources list of this task*/
        TASK_4,                          /* Task's entry point */
        &Task_4_Stack[APP_STACK_SIZE-1], /* Task's stack stuiping address */
        APP_STACK_SIZE,                  /* Task's stack size */
        0,                               /* Mask of waited events */
        0,                               /* Mask of setted events */
        0,                               /* Bit value in task priority group
                                            corresponding to task ready priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task ready priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task ready priority */
        0,                               /* Task activated number */
        0,                               /* padding byte */
#ifdef MixPreemption
        0,                               /* Bit value in task priority group
                                            corresponding to task dispatch priority */
        0,                               /* Index value into ready task table 
                                            corresponding to task dispatch priority */
        0,                               /* Bit position in ready table 
                                            corresponding to task dispatch priority */
        0,                               /* padding byte */
        0,                               /* padding byte */
#endif
        0
    },

    {
        TASK_App_Idle_ID,                       /* Task's ID */
        READY_STATE | uip_TASK_EXTENDED, /* Taks's execution state */
        TASK_App_Idle_READY_PRIO,        /* Task's ready priority */
#ifdef MixPreemption
        TASK_App_Idle_DISPATCH_PRIO,     /* Task's dispatched priority */
#else
        0,                               /* padding byte */
#endif
        0,                               /* The occupaited resources list of this task*/
        AppIdleTask,                   /* Task's entry point */
        &Task_App_Idle_Stack[APP_STACK_SIZE-1], /* Task's stack stuiping address */
        ((APP_STACK_SIZE-1)-2),          /* Task's stack size */
        0,                               /* Mask of waited events */
        0,                               /* Mask of setted events */
        0,                               /* Bit value in task priority group
                                            corresponding to task ready priority */
        0,                               /* Index value into ready task table
                                            corresponding to task ready priority */
        0,                               /* Bit position in ready table
                                            corresponding to task ready priority */
        0,                               /* Task activated number */
        0,                               /* padding byte */
#ifdef MixPreemption
        0,                               /* Bit value in task priority group
                                            corresponding to task dispatch priority */
        0,                               /* Index value into ready task table
                                            corresponding to task dispatch priority */
        0,                               /* Bit position in ready table
                                            corresponding to task dispatch priority */
        0,                               /* padding byte */
        0,                               /* padding byte */
#endif
        0
    }
};

TaskNumberType AppTaskNumber = 6;
//TaskNumberType AppTaskNumber = 5;
/***************************************************************************************/
/*                            End of File : app_cfg.c                                  */
/***************************************************************************************/
