astroboy astroboy
/
CoOS_LWIP
Quick and dirty CoOS + LWIP ( Webserver )
CoOS/kernel/utility.c@0:94897d537b31, 2011-09-10 (annotated)
- Committer:
- astroboy
- Date:
- Sat Sep 10 22:41:10 2011 +0000
- Revision:
- 0:94897d537b31
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
astroboy | 0:94897d537b31 | 1 | /** |
astroboy | 0:94897d537b31 | 2 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 3 | * @file utility.c |
astroboy | 0:94897d537b31 | 4 | * @version V1.1.4 |
astroboy | 0:94897d537b31 | 5 | * @date 2011.04.20 |
astroboy | 0:94897d537b31 | 6 | * @brief Utility management implementation code of CooCox CoOS kernel. |
astroboy | 0:94897d537b31 | 7 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 8 | * @copy |
astroboy | 0:94897d537b31 | 9 | * |
astroboy | 0:94897d537b31 | 10 | * INTERNAL FILE,DON'T PUBLIC. |
astroboy | 0:94897d537b31 | 11 | * |
astroboy | 0:94897d537b31 | 12 | * <h2><center>© COPYRIGHT 2009 CooCox </center></h2> |
astroboy | 0:94897d537b31 | 13 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 14 | */ |
astroboy | 0:94897d537b31 | 15 | |
astroboy | 0:94897d537b31 | 16 | |
astroboy | 0:94897d537b31 | 17 | /*---------------------------- Include ---------------------------------------*/ |
astroboy | 0:94897d537b31 | 18 | #include <coocox.h> |
astroboy | 0:94897d537b31 | 19 | |
astroboy | 0:94897d537b31 | 20 | #if CFG_UTILITY_EN > 0 |
astroboy | 0:94897d537b31 | 21 | |
astroboy | 0:94897d537b31 | 22 | |
astroboy | 0:94897d537b31 | 23 | /** |
astroboy | 0:94897d537b31 | 24 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 25 | * @brief Convert tick number to time |
astroboy | 0:94897d537b31 | 26 | * @param[in] ticks Specifies the systerm tick numbers that will be converted. |
astroboy | 0:94897d537b31 | 27 | * @param[out] hour Hours which converted. |
astroboy | 0:94897d537b31 | 28 | * @param[out] minute minutes which converted. |
astroboy | 0:94897d537b31 | 29 | * @param[out] sec seconds which converted. |
astroboy | 0:94897d537b31 | 30 | * @param[out] millsec millseconds which converted. |
astroboy | 0:94897d537b31 | 31 | * @retval None |
astroboy | 0:94897d537b31 | 32 | * |
astroboy | 0:94897d537b31 | 33 | * @par Description |
astroboy | 0:94897d537b31 | 34 | * @details This function is called to convert specify ticks to time format. |
astroboy | 0:94897d537b31 | 35 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 36 | */ |
astroboy | 0:94897d537b31 | 37 | #if CFG_TICK_TO_TIME_EN > 0 |
astroboy | 0:94897d537b31 | 38 | void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec) |
astroboy | 0:94897d537b31 | 39 | { |
astroboy | 0:94897d537b31 | 40 | U32 totalTime; |
astroboy | 0:94897d537b31 | 41 | |
astroboy | 0:94897d537b31 | 42 | /* Convert ticks to time*/ |
astroboy | 0:94897d537b31 | 43 | totalTime = ticks * (1000/CFG_SYSTICK_FREQ); |
astroboy | 0:94897d537b31 | 44 | *millsec = totalTime%1000; |
astroboy | 0:94897d537b31 | 45 | totalTime = totalTime/1000; |
astroboy | 0:94897d537b31 | 46 | *sec = totalTime%60; |
astroboy | 0:94897d537b31 | 47 | totalTime = totalTime/60; |
astroboy | 0:94897d537b31 | 48 | *minute = totalTime%60; |
astroboy | 0:94897d537b31 | 49 | totalTime = totalTime/60; |
astroboy | 0:94897d537b31 | 50 | *hour = totalTime; |
astroboy | 0:94897d537b31 | 51 | } |
astroboy | 0:94897d537b31 | 52 | #endif /* CFG_TICK_TO_TIME_EN */ |
astroboy | 0:94897d537b31 | 53 | |
astroboy | 0:94897d537b31 | 54 | |
astroboy | 0:94897d537b31 | 55 | /** |
astroboy | 0:94897d537b31 | 56 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 57 | * @brief Convert time to tick |
astroboy | 0:94897d537b31 | 58 | * @param[in] hour Specifies the number of hours. |
astroboy | 0:94897d537b31 | 59 | * @param[in] minute Specifies the number of minutes. |
astroboy | 0:94897d537b31 | 60 | * @param[in] sec Specifies the number of seconds. |
astroboy | 0:94897d537b31 | 61 | * @param[in] millsec Specifies the number of millseconds. |
astroboy | 0:94897d537b31 | 62 | * @param[out] ticks Tick numbers that converted. |
astroboy | 0:94897d537b31 | 63 | * @retval E_INVALID_PARAMETER Invalid parameter be passed and convert fail. |
astroboy | 0:94897d537b31 | 64 | * @retval E_OK Convert successful. |
astroboy | 0:94897d537b31 | 65 | * |
astroboy | 0:94897d537b31 | 66 | * @par Description |
astroboy | 0:94897d537b31 | 67 | * @details This function is called to convert specify time to tick number. |
astroboy | 0:94897d537b31 | 68 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 69 | */ |
astroboy | 0:94897d537b31 | 70 | #if CFG_TIME_TO_TICK_EN > 0 |
astroboy | 0:94897d537b31 | 71 | StatusType CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks) |
astroboy | 0:94897d537b31 | 72 | { |
astroboy | 0:94897d537b31 | 73 | #if CFG_PAR_CHECKOUT_EN >0 |
astroboy | 0:94897d537b31 | 74 | /* Validate arguments to be within range */ |
astroboy | 0:94897d537b31 | 75 | if((minute > 59)||(sec > 59)||(millsec > 999)) |
astroboy | 0:94897d537b31 | 76 | return E_INVALID_PARAMETER; |
astroboy | 0:94897d537b31 | 77 | #endif |
astroboy | 0:94897d537b31 | 78 | |
astroboy | 0:94897d537b31 | 79 | /* Convert time to ticks */ |
astroboy | 0:94897d537b31 | 80 | *ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\ |
astroboy | 0:94897d537b31 | 81 | + (millsec*CFG_SYSTICK_FREQ + 500)/1000; |
astroboy | 0:94897d537b31 | 82 | return E_OK; |
astroboy | 0:94897d537b31 | 83 | } |
astroboy | 0:94897d537b31 | 84 | #endif /* CFG_TIME_TO_TICK_EN */ |
astroboy | 0:94897d537b31 | 85 | |
astroboy | 0:94897d537b31 | 86 | #endif /* CFG_UTILITY_EN */ |