CoOS Demonstrator adapted to mbed Hardware.

Dependencies:   mbed

Committer:
ericebert
Date:
Fri Dec 03 19:45:30 2010 +0000
Revision:
0:57690853989a
Some basic LED-Flashing works in the CoOS-RTOS using Tasks

Who changed what in which revision?

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