CooCox 1.1.4 on mbed with simple blinky example

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers utility.c Source File

utility.c

Go to the documentation of this file.
00001 /**
00002  *******************************************************************************
00003  * @file       utility.c
00004  * @version    V1.1.4    
00005  * @date       2011.04.20
00006  * @brief      Utility management implementation code of CooCox CoOS kernel.    
00007  *******************************************************************************
00008  * @copy
00009  *
00010  * INTERNAL FILE,DON'T PUBLIC.
00011  * 
00012  * <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2>
00013  *******************************************************************************
00014  */ 
00015 
00016 
00017 /*---------------------------- Include ---------------------------------------*/
00018 #include <coocox.h>
00019 
00020 #if CFG_UTILITY_EN > 0
00021 
00022 
00023 /**
00024  *******************************************************************************
00025  * @brief      Convert tick number to time    
00026  * @param[in]  ticks    Specifies the systerm tick numbers that will be converted.   
00027  * @param[out] hour     Hours which converted. 
00028  * @param[out] minute   minutes which converted.
00029  * @param[out] sec      seconds which converted.
00030  * @param[out] millsec  millseconds which converted.
00031  * @retval     None      
00032  *
00033  * @par Description
00034  * @details    This function is called to convert specify ticks to time format.         
00035  *******************************************************************************                
00036  */
00037 #if CFG_TICK_TO_TIME_EN > 0
00038 void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec)
00039 {
00040     U32 totalTime;
00041     
00042     /* Convert ticks to time*/
00043     totalTime = ticks * (1000/CFG_SYSTICK_FREQ);
00044     *millsec  = totalTime%1000;
00045     totalTime = totalTime/1000;
00046     *sec      = totalTime%60;
00047     totalTime = totalTime/60;
00048     *minute   = totalTime%60;
00049     totalTime = totalTime/60;
00050     *hour     = totalTime;      
00051 }
00052 #endif    /* CFG_TICK_TO_TIME_EN    */
00053 
00054 
00055 /**
00056  *******************************************************************************
00057  * @brief      Convert time to tick   
00058  * @param[in]  hour     Specifies the number of hours.
00059  * @param[in]  minute   Specifies the number of minutes.
00060  * @param[in]  sec      Specifies the number of seconds.
00061  * @param[in]  millsec  Specifies the number of millseconds.     
00062  * @param[out] ticks    Tick numbers that converted.  
00063  * @retval     E_INVALID_PARAMETER   Invalid parameter be passed and convert fail.
00064  * @retval     E_OK                  Convert successful.
00065  *
00066  * @par Description
00067  * @details    This function is called to convert specify time to tick number.       
00068  *******************************************************************************
00069  */
00070 #if CFG_TIME_TO_TICK_EN > 0
00071 StatusType  CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks)
00072 {
00073 #if CFG_PAR_CHECKOUT_EN >0
00074     /* Validate arguments to be within range */
00075     if((minute > 59)||(sec > 59)||(millsec > 999))
00076         return E_INVALID_PARAMETER;
00077 #endif
00078 
00079     /* Convert time to ticks */
00080     *ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\
00081               + (millsec*CFG_SYSTICK_FREQ + 500)/1000;
00082     return E_OK;
00083 }
00084 #endif    /* CFG_TIME_TO_TICK_EN  */
00085 
00086 #endif    /* CFG_UTILITY_EN       */