#line 1 "..\\..\\..\\..\\uipkernel\\uip_kernel_resource.c"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

#line 1 "..\\..\\..\\..\\uipkernel\\uip_kernel_api.h"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


















 






 





  
#line 90 "..\\..\\..\\..\\uipkernel\\uip_kernel_api.h"






#line 105 "..\\..\\..\\..\\uipkernel\\uip_kernel_api.h"

 
 


 




 


 






 



















 





















                         



 


 


 


 
 


 


  

typedef signed char                 UIP_CHAR;
typedef unsigned char               UIP_UCHAR;
typedef signed char                 UIP_INT8;
typedef unsigned char               UIP_UINT8;
typedef signed short                UIP_INT16;
typedef unsigned short              UIP_UINT16;
typedef signed int                  UIP_INT;
typedef unsigned int                UIP_UINT;
typedef signed long                 UIP_INT32;
typedef unsigned long               UIP_UINT32;


typedef signed char *               UIP_CHAR_PTR;
typedef unsigned char *             UIP_UCHAR_PTR;
typedef signed char *               UIP_INT8_PTR;
typedef unsigned char *             UIP_UINT8_PTR;
typedef signed short *              UIP_INT16_PTR;
typedef unsigned short *            UIP_UINT16_PTR;
typedef signed int *                UIP_INT_PTR;
typedef unsigned int *              UIP_UINT_PTR;
typedef signed long *               UIP_INT32_PTR;
typedef unsigned long *             UIP_UINT32_PTR;
typedef void *                      UIP_VOID_PTR;
 
typedef UIP_INT32                   TaskType;
typedef UIP_INT32_PTR               TaskRefType;
typedef UIP_UCHAR                   TaskStateType;
typedef UIP_UCHAR_PTR               TaskStateRefType;
typedef UIP_UCHAR                   TaskNumberType;                         

typedef UIP_UCHAR                   StatusType;
typedef UIP_UINT                    PointerType;                    

typedef UIP_UCHAR *                 AppDataRef;
typedef UIP_UCHAR                   FlagType;
typedef UIP_UCHAR                   AppModeType;                    

typedef UIP_UINT                    ResourceType;
typedef UIP_UCHAR                   ResNumberType;                          


typedef UIP_UINT                    EventMaskType;
typedef EventMaskType *             EventMaskRefType;

typedef UIP_UCHAR                   AlarmType;
typedef UIP_UCHAR_PTR               AlarmRefType;
typedef UIP_UINT                    TickType;
typedef UIP_UINT_PTR                TickRefType;
typedef UIP_UCHAR                   AlarmNumberType;

typedef UIP_UCHAR                   MsgType;
typedef UIP_UCHAR                   MsgNumberType;                          

 
typedef struct uip_RESOURCE_STRUCT 
{
    struct uip_TSK_STRUCT    
                      *uipTaskPtr;                      
    struct uip_RESOURCE_STRUCT    
                      *uipNextRes;                      
    UIP_UINT          uipResCeilingGrpBit;             
 
    UIP_UCHAR         uipCeilingPrio;                   
    UIP_UCHAR         uipResCeilingGrpArrayIndex;      
 
    UIP_UCHAR         uipResCeilingGrpArrayBit;        
 
    UIP_UCHAR         uipTaskPrio;                      
    UIP_UCHAR         uipLock;                         

 
    UIP_UCHAR         padding_1;                        
    UIP_UCHAR         padding_2;                        
    UIP_UCHAR         padding_3;                        
} uipRes; 

typedef uipRes *                       uipResPtr;

 
 
typedef struct uip_TSK_STRUCT
{
    UIP_UCHAR         uipTaskID;                        
    UIP_UCHAR         uipTaskState;                     
    UIP_UCHAR         uipReadyPrio;                     

    UIP_UCHAR         uipDispatchPrio;                  



    struct uip_RESOURCE_STRUCT  
                      *uipResources;                    
    void              (*uipTaskEntry)(void);            
    UIP_VOID_PTR      uipStackPtr;                      
    UIP_UINT          uipStackSize;                     
    EventMaskType     UIP_WaitEvent;                    
    EventMaskType     UIP_SetEvent;                     
    UIP_UINT          uipRdyPrioGrpBit;                
 
    UIP_UCHAR         uipRdyPrioGrpArrayIndex;         
 
    UIP_UCHAR         uipRdyPrioGrpArrayBit;           
 
    UIP_UCHAR         uipActivatedNumber;               
    UIP_UCHAR         padding_2;                            

    UIP_UINT          uipDispPrioGrpBit;               
 
    UIP_UCHAR         uipDispPrioGrpArrayIndex;        
 
    UIP_UCHAR         uipDispPrioGrpArrayBit;          
 
    UIP_UCHAR         padding_3;                            
    UIP_UCHAR         padding_4;                            

     
    UIP_UINT          IsInited;
} uipTask; 

typedef uipTask *                      uipTaskPtr;

typedef struct uip_ALARMBASE_STRUCT
{
    TickType          maxAllowedValue;                 
 
    TickType          ticksPerBase;                    
 
    TickType          minCycle;                        

 
} AlarmBaseType; 

typedef AlarmBaseType *                AlarmBaseRefType;

 
typedef struct uip_CTR_STRUCT
{
    TickType          uipCtrValue;                       
    TickType          uipTick;
    struct uip_ALARMBASE_STRUCT  
                      *uipCtrBase;
} uipCounter; 

typedef uipCounter *                   uipCounterPtr;

 
typedef struct uip_ALARM_STRUCT
{
    TickType          uipAlarmValue;    
    UIP_UINT          uipCycle;         
    UIP_UINT          uipEvent;
    struct uip_CTR_STRUCT    
                      *uipCounterPtr;       
    void              (*uipCallBack)(void);
    UIP_UCHAR         uipAlarmActTaskID;
    UIP_UCHAR         uipAlarmState;            
    UIP_UCHAR         padding_1;                            
    UIP_UCHAR         padding_2;                            
} uipAlarm;

typedef uipAlarm *                     uipAlarmPtr;

 
typedef struct uip_MSG_STRUCT
{
    UIP_UCHAR         uipMsgId;                          
    UIP_UCHAR         uipMsgStatus;                     
 
    UIP_UCHAR         uipMsgType;                        
    UIP_UCHAR         uipMsgFlag;                        
    UIP_UCHAR_PTR     uipMsgPtr;                          
    UIP_UCHAR_PTR     uipQueueWriteHead;                  
    UIP_UCHAR_PTR     uipQueueEnd;                        
    UIP_UCHAR_PTR     uipQueueReadHead;                  
    UIP_UINT          uipMsgSize;                        
    UIP_UINT          uipMsgEvent;                       
    void              (*uipMsgCallBack)(void);           
    UIP_UCHAR         uipMsgNotifyTaskID;                
    UIP_UCHAR         uipMsgNotifyType;                      
    UIP_UCHAR         padding_2;                             
    UIP_UCHAR         padding_3;                             
} uipMsg; 
 
typedef uipMsg *                       uipMsgPtr;

 
 
typedef struct uip_INT_STRUCT
{
    UIP_UINT32        uipIntId;                          
    UIP_UINT32        uipIntExcepted;                    
    UIP_UINT32        uipIntOutcome;                     
    void              *uipInfo;                          
    UIP_UINT32        (*uipIntCallBack)(struct uip_INT_STRUCT *uipIntContorl);  
                                                        
 
    void              *uipIntReserved;                   
} uipInt; 

typedef uipInt *                       uipIntPtr;

typedef UIP_UINT32 (*uipIntCallBackFunction)(struct uip_INT_STRUCT *uipIntContorl);

 
 
 
 
  
 
StatusType      UIP_GetAlarmBase(AlarmType AlarmID, AlarmBaseRefType Info);

 
 
  
 
StatusType      UIP_GetAlarm(AlarmType AlarmID, TickRefType Tick);

 
 
 
 
 
  
 
StatusType      UIP_SetRelAlarm(AlarmType AlarmID, TickType increment, TickType cycle);

 
 
 
 
 
 
StatusType      UIP_SetAbsAlarm(AlarmType AlarmID, TickType start, TickType cycle);

 
  
 
StatusType      UIP_CancelAlarm(AlarmType AlarmID);

 
  
 
void            uipSystemCounterHandler(void);

 
  
 
void            uipAlarmHandler(UIP_UINT alarm_index);

 
  
 
void            uipGeneralCounterHandler(AlarmType AlarmID);

 
 
 
void            HardFault_Handler(void);
void            UsageFault_Handler(void);
 
  
 
StatusType      uipGetCtrCurrentValue(AlarmType AlarmID, TickRefType Tick);







 
extern UIP_CHAR                              uipLowPowerMode;

 
extern UIP_CHAR                              uipSchedulerLock; 
 
 
extern UIP_UINT                              uipNestedInterrupts;

extern AppModeType                           uipSystemMode;



 
extern UIP_UINT                              uipPrioGroup;



 
extern UIP_UCHAR                             uipPrioGrpArray[(16/8)];

 
extern UIP_UCHAR                             uipLowHalfByteValue[]; 

extern UIP_UCHAR                             uipHighHalfByteValue[];  

 
extern uipTask                               *uipCurrentTaskTCBPtr;


 
extern uipTask                               *uipNextRunningTaskTCBPtr;

extern void                                  *uipSystemStackPtr; 

 
extern UIP_UCHAR                             uipCurrentTaskPriority;                

 
extern UIP_UCHAR                             uipNextRunningTaskPriority;           

 
extern UIP_UCHAR                             uipIdleTaskID;

extern uipTask                               *uipIdleTaskTCBPtr;

extern void                                  uipArmIntHandlerGate(void);

extern UIP_INT32                             uipIntTableID;

extern UIP_UINT32                            uipInSchedulerLoop;


 
void                           uipResetPrioGrpAndArrayBit(void);


 
void                           uipClearPrioGrpAndArrayBit(uipTaskPtr suspendTaskPtr);

 
extern void            uipGetNextTask(void);

 
UIP_UCHAR                      uipGetNextPriority(void);
 
 
void                           uipClearPrioGrpAndArrayBit(uipTaskPtr suspendTaskPtr);

 
 

 

unsigned int            uipDisableAllInterrupts(void);   
        
void                           uipIntMaskStateRestore(unsigned int cpuStateRegister);


 
 
 
  
 
StatusType      UIP_GetResource(ResourceType ID);

 
 
 
  
 
StatusType      UIP_ReleaseResource(ResourceType ID);


 
 
 
  
 
StatusType      UIP_SendMessage(MsgType MsgID, AppDataRef DataRef);

 
 
 
 
  
 
StatusType      UIP_ReceiveMessage(MsgType MsgID, AppDataRef DataRef);

 
 
  
 
StatusType      UIP_GetMessageStatus(MsgType MsgID);

 
 
  
 
FlagType        UIP_ReadFlag(MsgType MsgID);

 
  
 
StatusType      UIP_ResetFlag(MsgType MsgID);

 
 
  
 
StatusType      UIP_StartCOM(void);

 
  
 
StatusType      UIP_CloseCOM(void);

 
 
 
  
 
StatusType      UIP_StopCOM(UIP_UCHAR ShutdownMode);








       
extern uipTaskPtr                            uipTCBArray;  

extern UIP_UCHAR                             uipPriorityToTaskID[16];

extern UIP_UINT                              uipInitTaskStackPtr[16];

extern TaskNumberType                        uipTaskNumber;                               

extern TaskNumberType                        uipTaskIDNumber;                       

       
extern uipResPtr                             uipRCBArray;  

extern ResNumberType                         uipResNumber;                                

 
extern uipAlarmPtr                           uipACBArray;

extern AlarmNumberType                       uipAlarmNumber;                             

extern AlarmType                             uipAlarmID;

 
extern uipMsgPtr                             uipMCBArray;

extern MsgNumberType                         uipMsgNumber;                           

extern uipCounter                            uipSystemCounter;

 
extern AlarmBaseType                         uipSystemAlarmBase;

extern StatusType                            uipCOMInit(void);
 
 
 
 
void            StartOS(AppModeType mode);

 
 
 
void            ShutdownOS(StatusType status);

 
 
 
void            uipTaskInfoInit(uipTaskPtr appTCBArray, TaskNumberType taskNumber);

 
 
 
void            uipResInfoInit(uipResPtr appRCBArray, ResNumberType resNumber);

 
 
 
void            uipMsgInfoInit(uipMsgPtr appMCBArray, MsgNumberType mcbNumber);

 
 
 
void            uipAlarmInfoInit(uipAlarmPtr appACBArray, AlarmNumberType acbNumber);

 
 
 
 
UIP_VOID_PTR    uipTaskStackInit(void *taskEntry, UIP_UINT stackInitialAdress);

 
 
  
 
StatusType      uipTaskInitialize(uipTaskPtr appTCBArray, TaskNumberType tcbNumber);

void            uipKernelInitialize(void);

 
 
  
 
StatusType      uipResInitialize(uipResPtr appRCBArray, ResNumberType rcbNumber);

 
 
  
 
StatusType      uipMsgInitialize(uipMsgPtr appMCBArray, MsgNumberType mcbNumber);

 
 
  
 
StatusType      uipAlarmInitialize(uipAlarmPtr appACBArray, AlarmNumberType acbNumber);


 
 
  
 
void            uipAppInitialize(void);


 
 
 
 
  
 
StatusType      UIP_SetEvent(TaskType TaskID, EventMaskType Mask);

 
 
  
 
StatusType      UIP_ClearEvent(EventMaskType Mask);

 
 
 
 
  
 
StatusType      UIP_GetEvent(TaskType TaskID, EventMaskRefType Mask);

 
 
 
  
 
StatusType      UIP_WaitEvent(EventMaskType Mask);


 
 
 
  
 
StatusType      UIP_ActivateTask(TaskType TaskID);

 
 
 
 
 
StatusType      UIP_TerminateTask(void);

 
 
 
 
 
  
 
StatusType      UIP_ChainTask(TaskType TaskID);

 
 
 
 
  
 
StatusType      UIP_Schedule(void); 

 
 
  
 
StatusType      UIP_GetTaskID(TaskRefType TaskID);

 
 
  
 
StatusType      UIP_GetTaskState(TaskType TaskID, TaskStateRefType State); 

void            uipIRQIntContextSave(void);
void            uipSystemCounterHandler(void);
void            uipIRQIntContextRestore(void);
void            HardFault_Handler(void);

void            uipPreContexSwitch(void);
void            uipPendSVHandler(void);
void            uipInterruptServiceEngine(void);
void            uipInterruptHandlingCallback(void);
 

 






#line 812 "..\\..\\..\\..\\uipkernel\\uip_kernel_api.h"












#line 832 "..\\..\\..\\..\\uipkernel\\uip_kernel_api.h"






 

StatusType      UIP_ActivateTask(TaskType TaskID);
StatusType      UIP_TerminateTask(void);
StatusType      UIP_ChainTask(TaskType TaskID);
StatusType      UIP_Schedule(void); 
StatusType      UIP_GetTaskID(TaskRefType TaskID);
StatusType      UIP_GetTaskState(TaskType TaskID, TaskStateRefType State); 

StatusType      UIP_GetAlarmBase(AlarmType AlarmID, AlarmBaseRefType Info);
StatusType      UIP_GetAlarm(AlarmType AlarmID, TickRefType Tick);
StatusType      UIP_SetRelAlarm(AlarmType AlarmID, TickType increment, TickType cycle);
StatusType      UIP_SetAbsAlarm(AlarmType AlarmID, TickType start, TickType cycle);
StatusType      UIP_CancelAlarm(AlarmType AlarmID);

StatusType      UIP_SetEvent(TaskType TaskID, EventMaskType Mask);
StatusType      UIP_ClearEvent(EventMaskType Mask);
StatusType      UIP_GetEvent(TaskType TaskID, EventMaskRefType Mask);
StatusType      UIP_WaitEvent(EventMaskType Mask);

StatusType      UIP_SendMessage(MsgType MsgID, AppDataRef DataRef);
StatusType      UIP_ReceiveMessage(MsgType MsgID, AppDataRef DataRef);
StatusType      UIP_GetMessageStatus(MsgType MsgID);
FlagType        UIP_ReadFlag(MsgType MsgID);
StatusType      UIP_ResetFlag(MsgType MsgID);
StatusType      UIP_StartCOM(void);
StatusType      UIP_CloseCOM(void);
StatusType      UIP_StopCOM(UIP_UCHAR ShutdownMode);

StatusType      UIP_GetResource(ResourceType ID);
StatusType      UIP_ReleaseResource(ResourceType ID);







 
 
 
#line 45 "..\\..\\..\\..\\uipkernel\\uip_kernel_resource.c"

  
  
  
  
  
  
  
  
  
  
  
  
 
 
  
  
 
 
 
 
 
  
  
 
  
  
 
 
 
 
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
 
 
 
 
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
StatusType UIP_GetResource(ResourceType ResID)
{
    unsigned int uipInterruptStateSaved;;    
    uipResPtr          resourcePtr;
    uipTaskPtr         taskCurrentPtr;                                                      
    
     
    if (uipNestedInterrupts != 0)
    {
         
	  	return (0x02);
    }

     
     
    if (ResID >= uipResNumber)
    {
         
        return (0x03);
    }
        
     
    {uipInterruptStateSaved = uipDisableAllInterrupts();};
    
     
    resourcePtr = (uipResPtr)(&uipRCBArray[ResID]);
     
     
    if ((resourcePtr -> uipLock) == 1)
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};

         
        return (0x01);
    }

    taskCurrentPtr = (uipTask *)uipCurrentTaskTCBPtr;    
    
    
 
    if (uipCurrentTaskPriority < (resourcePtr -> uipCeilingPrio))
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};

         
	  	return (0x01);
    }

     
    resourcePtr -> uipLock = 1;
    resourcePtr -> uipTaskPtr = uipCurrentTaskTCBPtr;             
    resourcePtr -> uipTaskPrio = uipCurrentTaskPriority;             

    resourcePtr -> uipNextRes = taskCurrentPtr -> uipResources;        
    taskCurrentPtr -> uipResources = resourcePtr;

    
 
     
    uipPrioGroup |= (resourcePtr -> uipResCeilingGrpBit);

     
    uipPrioGrpArray[resourcePtr -> uipResCeilingGrpArrayIndex] |= 
                                                resourcePtr -> uipResCeilingGrpArrayBit;
	  
	 
	uipPriorityToTaskID[resourcePtr -> uipCeilingPrio] = taskCurrentPtr->uipTaskID;
	
	uipCurrentTaskPriority = resourcePtr -> uipCeilingPrio;
    
     
    {uipIntMaskStateRestore(uipInterruptStateSaved);};
    
    return (0x00);
}

  
  
  
  
  
  
  
  
  
  
  
  
 
 
  
  
 
  
  
  
  
  
  
  
  
  
  
  
  
  
 
 
 
 
 
  
 
 
 
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
 
  
  
StatusType UIP_ReleaseResource(ResourceType ResID)
{    
    unsigned int uipInterruptStateSaved;;
    uipResPtr          resourcePtr;
    uipTaskPtr         taskCurrentPtr;
    UIP_UCHAR          taskPriority;
    TaskType           taskID;
                                                    
     
     
    if (ResID >= uipResNumber)
    {
         
        return (0x03);
    }
        
     
    {uipInterruptStateSaved = uipDisableAllInterrupts();};
    
     
    resourcePtr = (uipResPtr)(&uipRCBArray[ResID]);
    taskCurrentPtr = (uipTask *)uipCurrentTaskTCBPtr;         

     
         
    if (((resourcePtr -> uipLock) == 0) || ((taskCurrentPtr -> uipResources) != resourcePtr))
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};

         
        return (0x05);
    }

    
 
    if (uipCurrentTaskPriority < (resourcePtr -> uipCeilingPrio))
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};

         
	  	return (0x01);
    }

    taskCurrentPtr -> uipResources = resourcePtr -> uipNextRes;

	uipCurrentTaskPriority = resourcePtr -> uipTaskPrio;

     
    resourcePtr -> uipLock = 0;
    resourcePtr -> uipTaskPtr = 0x00;             
    resourcePtr -> uipTaskPrio = (16-1);             

    
 
     
    uipPrioGrpArray[resourcePtr -> uipResCeilingGrpArrayIndex] &=
                              ~(resourcePtr -> uipResCeilingGrpArrayBit);
    if (uipPrioGrpArray[resourcePtr -> uipResCeilingGrpArrayIndex] == 0x00)
    {
         
        uipPrioGroup &= ~(resourcePtr -> uipResCeilingGrpBit);
    }
    
	 
	uipPriorityToTaskID[resourcePtr -> uipCeilingPrio] = 0x00;  
    
     
    if (uipNestedInterrupts != 0)
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);}

         
	  	return (0x02);
    }

    
              
    taskPriority = uipGetNextPriority(); 

     
    if (taskPriority < uipCurrentTaskPriority)
    {
         
        uipCurrentTaskTCBPtr -> uipTaskState &= 0x80;
        uipCurrentTaskTCBPtr -> uipTaskState |= 0x4; 

         
        taskID = uipPriorityToTaskID[taskPriority];
    
         
        uipNextRunningTaskTCBPtr = (uipTaskPtr)(&uipTCBArray[taskID]); 
        
         
        uipNextRunningTaskPriority = taskPriority;

         
        *((unsigned int *)0xE000ED04) = 0x10000000;
    }     

     
    {uipIntMaskStateRestore(uipInterruptStateSaved);};
    
    return (0x00);
}

 
 
 
