#line 1 "..\\..\\..\\..\\uipkernel\\uip_kernel_time.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_time.c"

  
  
  
  
  
  
  
  
  
  
  
  
 
 
  
  
 
  
  
  
  
 
  
  
  
 
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
StatusType UIP_GetAlarmBase(AlarmType AlarmID, AlarmBaseRefType Info)
{
    uipAlarmPtr        alarmPtr;
    
    if (AlarmID > uipAlarmNumber)
    {
        return (0x03);
    }  
  
    alarmPtr = (uipAlarmPtr)(&uipACBArray[AlarmID]);
    
    Info = (AlarmBaseRefType)(&((alarmPtr -> uipCounterPtr) -> uipCtrBase));
    
    return (0x00);
}  

  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
 
  
 
 
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
StatusType UIP_GetAlarm(AlarmType AlarmID, TickRefType Tick)
{
    unsigned int uipInterruptStateSaved;;
    uipAlarmPtr        alarmPtr;
          
    if (AlarmID > uipAlarmNumber)
    {
        return (0x03);
    }  
    
    alarmPtr = (uipAlarmPtr)(&uipACBArray[AlarmID]);

     
    {uipInterruptStateSaved = uipDisableAllInterrupts();};
    
    if ((alarmPtr -> uipAlarmState) == 0x00)
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
  	    return (0x05);
    } 
  
     
    if ((alarmPtr -> uipAlarmValue) >= ((alarmPtr -> uipCounterPtr) -> uipCtrValue))
    {
    	*Tick = (alarmPtr -> uipAlarmValue) - 
                ((alarmPtr -> uipCounterPtr) -> uipCtrValue);
    }
    else
    {
    	*Tick = (alarmPtr -> uipAlarmValue) + 
    	        ((((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue) - 
    	                                ((alarmPtr -> uipCounterPtr) -> uipCtrValue));
    } 
     
    {uipIntMaskStateRestore(uipInterruptStateSaved);};        

     
    return (0x00);
}  

  
  
  
  
  
  
  
  
  
  
  
  
 
 
 
 
  
  
 
  
 
 
 
 
 
 
 
 
 
 
 
  
  
  
  
 
 
 
 
 
  
  
  
  
  
  
  
  
  
 
  
 
 
  
 
 
 
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
StatusType UIP_SetRelAlarm(AlarmType AlarmID, TickType increment, TickType cycle)
{
    unsigned int uipInterruptStateSaved;;
    uipAlarmPtr        alarmPtr;
          
     
    if (AlarmID > uipAlarmNumber)
    {
        return (0x03);
    }  
    
    alarmPtr = (uipAlarmPtr)(&uipACBArray[AlarmID]);

     
    {uipInterruptStateSaved = uipDisableAllInterrupts();};

         
    if ((alarmPtr -> uipAlarmState) == 0x01)
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
  	    return (0x07);
    } 

         
    if (increment > (((alarmPtr -> uipCounterPtr) 
                                  -> uipCtrBase) -> maxAllowedValue))
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
        return (0x08);
    }
    
         
    if ((cycle!=0) && ((cycle < ((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> minCycle) || 
                  (cycle > ((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue)))
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
        return (0x08);
    }
  
    if (increment > ((((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue) 
                                  - ((alarmPtr -> uipCounterPtr) -> uipCtrValue)))
    {
        alarmPtr -> uipAlarmValue = increment - 
                            ((((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue) - 
                            ((alarmPtr -> uipCounterPtr) -> uipCtrValue)+1);                                  
    }                                           
    else
    {
        alarmPtr -> uipAlarmValue = ((alarmPtr -> uipCounterPtr) -> uipCtrValue) + increment;
    }
    
    alarmPtr -> uipCycle = cycle;

    alarmPtr -> uipAlarmState = 0x01;
    
     
    {uipIntMaskStateRestore(uipInterruptStateSaved);};

    return (0x00);
}  

  
  
  
  
  
  
  
  
  
  
  
  
 
 
 
 
  
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
  
  
  
 
 
 
 
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
StatusType UIP_SetAbsAlarm(AlarmType AlarmID, TickType start, TickType cycle)
{
    unsigned int uipInterruptStateSaved;;
    uipAlarmPtr        alarmPtr;
              
     
    if (AlarmID > uipAlarmNumber)
    {
        return (0x03);
    }  
    
    alarmPtr = (uipAlarmPtr)(&uipACBArray[AlarmID]);

     
    {uipInterruptStateSaved = uipDisableAllInterrupts();};

         
    if ((alarmPtr -> uipAlarmState) == 0x01)
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
  	    return (0x07);
    } 
  
         
    if (start > (((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue))
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
        return (0x08);
    }
  
         
    if ((cycle != 0) && ((cycle < ((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> minCycle) 
         || (cycle > ((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue)))
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
        return (0x08);
    }
  
    alarmPtr -> uipAlarmValue = start;

    alarmPtr -> uipCycle = cycle;

    alarmPtr -> uipAlarmState = 0x01;
    
     
    {uipIntMaskStateRestore(uipInterruptStateSaved);};

    return (0x00);
}  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
 
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
 
StatusType UIP_CancelAlarm(AlarmType AlarmID)
{
    unsigned int uipInterruptStateSaved;;
    uipAlarmPtr        alarmPtr;
              
     
    if (AlarmID > uipAlarmNumber)
    {
        return (0x03);
    }  
    
    alarmPtr = (uipAlarmPtr)(&uipACBArray[AlarmID]);

     
    {uipInterruptStateSaved = uipDisableAllInterrupts();};

    if ((alarmPtr -> uipAlarmState) == 0x00)
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
  	    return (0x05);
    } 
  
    alarmPtr -> uipAlarmState = 0x00;
    
     
    {uipIntMaskStateRestore(uipInterruptStateSaved);};

    return (0x00);
}  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
 
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
 
void uipSystemCounterHandler(void)
{
    UIP_UINT           alarm_index;  
    uipAlarmPtr        alarmPtr;
              
    if(uipSystemCounter.uipCtrValue < (uipSystemCounter.uipCtrBase)->maxAllowedValue)
    {
        uipSystemCounter.uipCtrValue++;
    }
    else 
    {
        uipSystemCounter.uipCtrValue = 0;
    }
    
    for (alarm_index = 0; alarm_index < uipAlarmNumber; alarm_index++)
    {
        alarmPtr = (uipAlarmPtr)(&uipACBArray[alarm_index]);

        if (alarmPtr -> uipAlarmState == 0x01)
        {  
             
             
            if((alarmPtr -> uipCounterPtr) -> uipCtrValue < ((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue)
            {
                (alarmPtr -> uipCounterPtr) -> uipCtrValue++;
            }
            else
            {
                (alarmPtr -> uipCounterPtr) -> uipCtrValue = 0;
            }
             
            if ((alarmPtr -> uipCounterPtr) -> uipCtrValue == alarmPtr -> uipAlarmValue)
            {
                 
                 
				uipAlarmHandler(alarm_index);
            }
        } 
    } 
}  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
 
void uipAlarmHandler(UIP_UINT alarm_index)
{
    uipAlarmPtr        alarmPtr;

    alarmPtr = (uipAlarmPtr)(&uipACBArray[alarm_index]);

     
     
    if (alarmPtr -> uipCycle == 0)
    {
        alarmPtr -> uipAlarmState = 0x00;    	
    }
     
    else
    {
        if ((alarmPtr -> uipCycle) > ((((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue) - 
                                     ((alarmPtr -> uipCounterPtr) -> uipCtrValue)))
        {
            alarmPtr -> uipAlarmValue = (alarmPtr -> uipCycle) - 
                                     ((((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue) - 
                                     ((alarmPtr -> uipCounterPtr) -> uipCtrValue) + 1);                                      
        }  
                                                 
        else
        {
            alarmPtr -> uipAlarmValue = ((alarmPtr -> uipCounterPtr) -> uipCtrValue) + (alarmPtr -> uipCycle);
        }
    }
    
         
    if (alarmPtr -> uipCallBack != 0)
    {
        alarmPtr -> uipCallBack();	
    }

         
    if (alarmPtr -> uipEvent != 0)
    {
        UIP_SetEvent(alarmPtr -> uipAlarmActTaskID, alarmPtr -> uipEvent);
    }
    
         
    else if (alarmPtr -> uipAlarmActTaskID != uipIdleTaskID)
    {
        UIP_ActivateTask(alarmPtr -> uipAlarmActTaskID);
    }
}  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
 
void uipGeneralCounterHandler(AlarmType AlarmID)
{    
    uipAlarmPtr        alarmPtr;

    alarmPtr = (uipAlarmPtr)(&uipACBArray[AlarmID]);

     
     
    if((alarmPtr -> uipCounterPtr) -> uipCtrValue < ((alarmPtr -> uipCounterPtr) -> uipCtrBase) -> maxAllowedValue)
    {
        (alarmPtr -> uipCounterPtr) -> uipCtrValue++;
    }
    else
    {
        (alarmPtr -> uipCounterPtr) -> uipCtrValue = 0;
    }

    if ((AlarmID <= uipAlarmNumber) && ((alarmPtr -> uipAlarmState) == 0x01))
    {  
         
        if ((alarmPtr -> uipCounterPtr) -> uipCtrValue == alarmPtr -> uipAlarmValue)
        {
             
             
			uipAlarmHandler(AlarmID);
        }
    } 
}

  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  
 
StatusType uipGetCtrCurrentValue(AlarmType AlarmID, TickRefType Tick)
{
    unsigned int uipInterruptStateSaved;;
    uipAlarmPtr        alarmPtr;

    if (AlarmID > uipAlarmNumber)
    {
        return (0x03);
    }  
    
    alarmPtr = (uipAlarmPtr)(&uipACBArray[AlarmID]);

     
    {uipInterruptStateSaved = uipDisableAllInterrupts();};

    if ((alarmPtr -> uipAlarmState) == 0x00)
    {
         
        {uipIntMaskStateRestore(uipInterruptStateSaved);};
        
  	    return (0x05);
    } 

    *Tick = (alarmPtr -> uipCounterPtr) -> uipCtrValue;

     
    {uipIntMaskStateRestore(uipInterruptStateSaved);};        

     
    return (0x00);
}  

 
 
 
