| 1 | /** |
|---|
| 2 | @file |
|---|
| 3 | DHL_Timer.c |
|---|
| 4 | |
|---|
| 5 | @brief |
|---|
| 6 | Timer implementation. |
|---|
| 7 | |
|---|
| 8 | Copyright 2006~2010 Digital STREAM Technology, Inc. |
|---|
| 9 | All Rights Reserved |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | #include "DHL_OSAL.h" |
|---|
| 13 | #include "DHL_DBG.h" |
|---|
| 14 | #include "DHL_Timer.h" |
|---|
| 15 | |
|---|
| 16 | #include "DHL_DBG_Priv.h" |
|---|
| 17 | #include "DHL_OSAL_Config.h" |
|---|
| 18 | |
|---|
| 19 | //#include <stdio.h> |
|---|
| 20 | ////#include <string.h> |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | DHL_MODULE("*TMR", 0); |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | #if COMMENT |
|---|
| 27 | ____Debug____(){} |
|---|
| 28 | #endif |
|---|
| 29 | //------------------------------------------------------------------ |
|---|
| 30 | // Timer Debug Print |
|---|
| 31 | |
|---|
| 32 | //int g_Trace_bDHLTimer = 0; |
|---|
| 33 | // tmprintÀÇ µð¹ö±× ¸Þ½ÃÁö¸¦ °¨Ãâ°æ¿ì 0 |
|---|
| 34 | |
|---|
| 35 | void *g_Trace_TimerHandle; |
|---|
| 36 | // trace ÇϰíÀÚ ÇÏ´Â timer handle. |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #if COMMENT |
|---|
| 41 | ____Config____(){} |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | #define DHL_TIMER_TASK_PRIO TASK_PRI_DRV_TIMER |
|---|
| 46 | #define DHL_TIMER_TASK_STACK 8192 |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | #if COMMENT |
|---|
| 52 | ____Types____(){} |
|---|
| 53 | #endif |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | /* |
|---|
| 57 | ¾Æ·¡ Á¤ÀÇµÈ °ªµéÀº flags ·Î »ç¿ëµÈ´Ù. |
|---|
| 58 | */ |
|---|
| 59 | #define TIMER_FLAG_NeedAck 0x40 |
|---|
| 60 | // °ú°ÅÀÇ bNeedAck °ú µ¿ÀÏÇÑ ¿ªÇÒ. |
|---|
| 61 | |
|---|
| 62 | #define TIMER_FLAG_OldStyleProc 0x80 |
|---|
| 63 | // timer procÀÌ DHL_TIMER_PROC_EX°¡ ¾Æ´Ï¶ó DHL_TIMER_PROC ÀÌ´Ù. |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | // DHL_Timer.h¿¡¼ 8ÀÚ·Î ¸í½Ã |
|---|
| 69 | #define MAX_TIMER_NAME 8 |
|---|
| 70 | |
|---|
| 71 | #define DHL_TIMER_MAGICKEY 0x09110911 |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | /* UINT32 ÆÄ¶ó¹ÌÅ͸¦ ¸î °³ ±îÁö Áö¿øÇÏ´ÂÁö.. |
|---|
| 75 | ±âÁ¸ version 1 ¿¡¼´Â ´Ü Çϳª¸¸ Áö¿øÇß¾úÀ½. |
|---|
| 76 | */ |
|---|
| 77 | #define MAX_NUMBER_OF_TIMER_PARAM 16 |
|---|
| 78 | |
|---|
| 79 | /* ŸÀÌ¸Ó Å½ºÅ© msg queÀÇ µðÆúÆ® Å©±â. ±âÁ¸ version 1 ¿¡¼ÀÇ °ª°ú µ¿ÀÏÇÏ´Ù. |
|---|
| 80 | */ |
|---|
| 81 | #define DEFAULT_MSG_QUE_SIZE 20 |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | typedef struct |
|---|
| 85 | { |
|---|
| 86 | UINT16 nId; // unique id that distinguish to other timer entries. |
|---|
| 87 | |
|---|
| 88 | BOOLEAN used; // TRUE if this timer entry is used (and active) |
|---|
| 89 | |
|---|
| 90 | UINT32 period; // timer period (if periodic timer), or timer delay (if oneshot timer) |
|---|
| 91 | // unit is in TICKs |
|---|
| 92 | |
|---|
| 93 | UINT32 start; // timer start tick. |
|---|
| 94 | // if this is periodic timer, it is reset to NOW at every timer expire. |
|---|
| 95 | |
|---|
| 96 | UINT16 flags; // flags |
|---|
| 97 | |
|---|
| 98 | DHL_TIMER_PROC_EX fn; // timer callback function |
|---|
| 99 | UINT32 params[MAX_NUMBER_OF_TIMER_PARAM]; // user parameters |
|---|
| 100 | |
|---|
| 101 | } DHL_TIMER_ENTRY; |
|---|
| 102 | |
|---|
| 103 | typedef struct DHL_TIMER_t |
|---|
| 104 | { |
|---|
| 105 | UINT32 magic; |
|---|
| 106 | |
|---|
| 107 | char name[MAX_TIMER_NAME+1]; |
|---|
| 108 | |
|---|
| 109 | DHL_TIMER_INIT_PARAM param; |
|---|
| 110 | // user settings parameter for timer init |
|---|
| 111 | |
|---|
| 112 | int nActiveTimer; |
|---|
| 113 | // µî·ÏµÈ Active ŸÀÌ¸Ó °¹¼ö. |
|---|
| 114 | // ÀÌ º¯¼ö´Â ¸ðµç ŽºÅ©¿¡¼ ¼öÁ¤µÇ¹Ç·Î (SetTimer¿¡¼´Â application task, |
|---|
| 115 | // Oneshot ÇØÁ¦µÉ °æ¿ì³ª KillTimer¿¡´Â timer task µî..) µû¶ó¼ lock »óÅ¿¡¼ ¼öÁ¤Çϱ⠹ٶ÷. |
|---|
| 116 | |
|---|
| 117 | int maxActiveIndex; |
|---|
| 118 | // ŸÀÌ¸Ó record¿¡¼ ¹è¿ À妽º °ªÀÇ ÃÖ´ë°ª. |
|---|
| 119 | // Áß°£¿¡ ÀÖ´Â timer¸¦ KillTimer·Î ¾ø¾Ö¸é ¹è¿ °¡¿îµ¥°¡ ºó »óŰ¡ µÇ´Âµ¥, |
|---|
| 120 | // ÀÌ °æ¿ì nActiveTimer¿Í ¹«°üÇÑ °ªÀÌ µÉ ¼ö ÀÖ´Ù. |
|---|
| 121 | // timer routineÀÇ core¿¡¼ ÀÌ °ªÀ» ¾Ë°í ÀÖÀ¸¸é loop ¿À¹öÇìµå¸¦ ¾à°£ ÁÙÀÏ ¼ö ÀÖ´Ù. |
|---|
| 122 | // todo.. |
|---|
| 123 | // ÀÌ °ªÀÌ Ä¿Áö´Â ÄÚµå´Â Àִµ¥, ÁÙ¾îµå´Â ÄÚµå´Â ¾øÀ½. ±¸Çö ÇÊ¿ä.. |
|---|
| 124 | |
|---|
| 125 | DHL_OS_TASK_ID nTaskId; |
|---|
| 126 | // timer service task id. |
|---|
| 127 | |
|---|
| 128 | UINT32 curServicedTimerId; |
|---|
| 129 | // cafrii 060919 add |
|---|
| 130 | // ÇöÀç timer task¿¡¼ ¼ºñ½º ÁßÀÎ timer id. |
|---|
| 131 | // timer task°¡ idle »óÅÂÀÏ °æ¿ì¿¡´Â 0ÀÌ µÈ´Ù. |
|---|
| 132 | |
|---|
| 133 | DHL_OS_MSGQ_ID msgQue; // message queue of timer command |
|---|
| 134 | |
|---|
| 135 | DHL_OS_SEMA_ID semAck; // binary semaphore for returning ACK. |
|---|
| 136 | DHL_OS_SEMA_ID mutexAck; // mutex for guard semAck |
|---|
| 137 | |
|---|
| 138 | struct DHL_TIMER_t *next; |
|---|
| 139 | // for management.. next timer record info.. |
|---|
| 140 | |
|---|
| 141 | int nMaxSlot; |
|---|
| 142 | // maximum number of timer slot info. |
|---|
| 143 | |
|---|
| 144 | int nUserParam; |
|---|
| 145 | // number of user parameter. copied from param->num_user_param. |
|---|
| 146 | // MAX_NUMBER_OF_TIMER_PARAM º¸´Ù Ŭ ¼ö ¾ø´Ù. |
|---|
| 147 | |
|---|
| 148 | int nMaxQueSize; |
|---|
| 149 | // copied from param->msg_que_size. |
|---|
| 150 | |
|---|
| 151 | DHL_TIMER_ENTRY *info; |
|---|
| 152 | // ŸÀÌ¸Ó Á¤º¸ º¯¼ö. |
|---|
| 153 | |
|---|
| 154 | } DHL_TIMER; |
|---|
| 155 | |
|---|
| 156 | /* |
|---|
| 157 | timer command id. |
|---|
| 158 | |
|---|
| 159 | version 2 ¿¡¼´Â timer id ¿Í command id ¸¦ ÅëÇÕÇÏ¿© »ç¿ëÇÑ´Ù. |
|---|
| 160 | ±×¸®°í ¼ýÀÚÀÇ ¹üÀ§µµ 32-bit ¿¡¼ 16-bit·Î Ãà¼ÒÇÏ¿´´Ù. |
|---|
| 161 | */ |
|---|
| 162 | enum TIMER_CMD_ID_t |
|---|
| 163 | { |
|---|
| 164 | eTMR_CMD_BEGIN = 0xfff0, // this is just marker. |
|---|
| 165 | |
|---|
| 166 | //eTMR_CMD_ADD, |
|---|
| 167 | // ÀÌ TIMER_CMD_ID_t ¸í·Éµé ÀÌ¿ÜÀÇ °ªÀº ¸ðµÎ 'ADD'·Î µ¿ÀÛÇÑ´Ù. |
|---|
| 168 | // µû¶ó¼ º°µµÀÇ ADD ¸í·ÉÀ» º¸³¾ Çʿ䰡 ¾ø´Ù. |
|---|
| 169 | |
|---|
| 170 | eTMR_CMD_DELETE, |
|---|
| 171 | // Timer entry Çϳª¸¦ »èÁ¦ÇÑ´Ù. |
|---|
| 172 | // »èÁ¦ÇÒ timer ID´Â userParams[0]À» ÅëÇØ Àü´ÞÇÑ´Ù. |
|---|
| 173 | |
|---|
| 174 | eTMR_CMD_DELETE_ALL, |
|---|
| 175 | // ¸ðµç timer entry »èÁ¦. |
|---|
| 176 | |
|---|
| 177 | eTMR_CMD_SHOW, |
|---|
| 178 | |
|---|
| 179 | eTMR_CMD_QUERY, |
|---|
| 180 | |
|---|
| 181 | eTMR_CMD_SYNC, |
|---|
| 182 | // timer¸¦ ÀÏ¹Ý dpc task·Î »ç¿ëÇϴµ¥, |
|---|
| 183 | // ƯÁ¤ ¸Þ½ÃÁö¸¦ wait ¸ðµå·Î µ¿ÀÛÇØ¾ßÇÑ ÇÏ´Â °æ¿ì |
|---|
| 184 | // ÀÌ timer command¸¦ »ç¿ëÇϸé timer handler¿Í µ¿±âȰ¡ µÇ¾î |
|---|
| 185 | // wait ¸ðµåÀÇ È¿°ú°¡ ³´Ù. |
|---|
| 186 | // app ¿¡¼ Á÷Á¢ semaphore, mutex µîÀ» °ü¸®ÇÏ´Â °ÍÀÌ ¹ø°Å·Î¿ï °æ¿ì |
|---|
| 187 | // °£´ÜÇÏ°Ô ÀÌ ¸í·ÉÀ» Ȱ¿ëÇÏ¸é µÈ´Ù. |
|---|
| 188 | |
|---|
| 189 | eTMR_CMD_SHUTDOWN, |
|---|
| 190 | }; |
|---|
| 191 | |
|---|
| 192 | typedef struct |
|---|
| 193 | { |
|---|
| 194 | UINT16 idTimerOrCmd; |
|---|
| 195 | // Timer ID in 'Add' mode, |
|---|
| 196 | // or Command ID in other mode (delete, show, query, ...) |
|---|
| 197 | // Timer ID should be unique in DHL_TIMER group. |
|---|
| 198 | |
|---|
| 199 | UINT16 flags; |
|---|
| 200 | |
|---|
| 201 | //UINT32 *pResult; // return value is passed to caller |
|---|
| 202 | // synchronous (ack) mode´Â stop (kill timer) ¿¡¼¸¸ »ç¿ëÇϹǷÎ, |
|---|
| 203 | // ÀÌ °ªÀº nPeriodMs º¯¼ö °ø°£À» Ȱ¿ëÇϵµ·Ï ÇÑ´Ù. |
|---|
| 204 | |
|---|
| 205 | UINT32 nPeriodMs; |
|---|
| 206 | // timer expire ÁÖ±â. |
|---|
| 207 | // eTMR_CMD_DELETE ÀÎ °æ¿ì pResult ¿ªÇÒÀ» ÇÑ´Ù. |
|---|
| 208 | |
|---|
| 209 | DHL_TIMER_PROC_EX func; |
|---|
| 210 | UINT32 userParams[MAX_NUMBER_OF_TIMER_PARAM]; // user parameter, passed to timer proc |
|---|
| 211 | // ÀÌ userParamsÀº °¡º¯ ±æÀÌ ¹è¿ÀÌ´Ù. |
|---|
| 212 | // timer group ÃʱâÈ °úÁ¤¿¡¼ ƯÁ¤ size·Î °íÁ¤µÈ´Ù. |
|---|
| 213 | // ÀÌ Çʵ尡 ¸Ç ¸¶Áö¸·¿¡ À§Ä¡ÇØ¾ß ÇÑ´Ù. |
|---|
| 214 | |
|---|
| 215 | } DHL_TIMER_COMMAND; |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | /** |
|---|
| 219 | DHL_TIMER_COMMAND ÀÇ Å©±â´Â °¡º¯ÀÌ´Ù. Á¤È®ÇÑ size´Â nUserParam °ª¿¡ µû¶ó ´Þ¶óÁø´Ù. |
|---|
| 220 | |
|---|
| 221 | SendMessage ÇÒ ¶§ ±×³É ÃÖ´ë Áö¿ø °¹¼öÀÎ MAX_NUMBER_OF_TIMER_PARAM ¸¦ »ç¿ëÇÏÁö ¾Ê´Â ÀÌÀ¯´Â |
|---|
| 222 | ºÒÇÊ¿äÇÑ memcopy overhead¸¦ ÁÙÀ̱â À§ÇÔÀÌ´Ù. |
|---|
| 223 | */ |
|---|
| 224 | #define TIMER_COMMAND_SIZE(num_param) (\ |
|---|
| 225 | sizeof(DHL_TIMER_COMMAND) \ |
|---|
| 226 | - sizeof(UINT32)*MAX_NUMBER_OF_TIMER_PARAM \ |
|---|
| 227 | + sizeof(UINT32)*(num_param) \ |
|---|
| 228 | ) |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | #ifndef min |
|---|
| 232 | #define min(a,b) ((a)<(b)?(a):(b)) |
|---|
| 233 | #endif |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | #if COMMENT |
|---|
| 237 | ____Variables____(){} |
|---|
| 238 | #endif |
|---|
| 239 | |
|---|
| 240 | DHL_TIMER *g_dhl_timer_list; |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | #if COMMENT |
|---|
| 244 | ______Func____(){} |
|---|
| 245 | #endif |
|---|
| 246 | |
|---|
| 247 | // forward declarations |
|---|
| 248 | void dhl_timer_module_init(void); |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | static DHL_RESULT p_timer_check_valid(DHL_TIMER *timer) |
|---|
| 253 | { |
|---|
| 254 | if (timer == NULL || timer->magic != DHL_TIMER_MAGICKEY) { |
|---|
| 255 | printf( "!! invalid timer\n"); |
|---|
| 256 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 257 | } |
|---|
| 258 | if (timer->nTaskId == 0) { |
|---|
| 259 | printf( "!! Timer not initialized!\n"); |
|---|
| 260 | return DHL_FAIL_NOT_INITIALIZED; |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | return DHL_OK; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | #if COMMENT |
|---|
| 268 | ______Method____(){} |
|---|
| 269 | #endif |
|---|
| 270 | |
|---|
| 271 | /* |
|---|
| 272 | add one timer entry |
|---|
| 273 | this function should be called in timer task. |
|---|
| 274 | */ |
|---|
| 275 | static DHL_RESULT p_timer_add_entry(DHL_TIMER *timer, DHL_TIMER_COMMAND *cmd) |
|---|
| 276 | { |
|---|
| 277 | int i; |
|---|
| 278 | int idSelected, idEmpty; |
|---|
| 279 | |
|---|
| 280 | //ASSERT(cmd->idCmd == eTMR_CMD_ADD); |
|---|
| 281 | |
|---|
| 282 | idSelected = -1; |
|---|
| 283 | idEmpty = -1; |
|---|
| 284 | |
|---|
| 285 | // id¸¦ °Ë»öÇϸé¼, µ¿½Ã¿¡ empty slotµµ ã´Â´Ù. |
|---|
| 286 | // ÇØ´ç ID°¡ ÀÌ¹Ì »ç¿ëÁßÀ̶ó¸é °»½Å¸ðµå.. |
|---|
| 287 | for (i=0; i<timer->nMaxSlot; i++) |
|---|
| 288 | { |
|---|
| 289 | if (timer->info[i].used && timer->info[i].nId == cmd->idTimerOrCmd) { |
|---|
| 290 | // ÀÌ¹Ì »ç¿ëÁßÀÌ´Ù.. |
|---|
| 291 | // »õ·Î¿î parameter·Î updateÇϰí ÇÔ¼ö Á¾·á.. |
|---|
| 292 | if (g_Trace_TimerHandle == timer) |
|---|
| 293 | printf( "!! Timer [%d] already active. updated..\n", cmd->idTimerOrCmd); |
|---|
| 294 | idSelected = i; |
|---|
| 295 | break; |
|---|
| 296 | } |
|---|
| 297 | else if (timer->info[i].used == 0) { |
|---|
| 298 | // ºñ¾îÀÖ´Â slotÀ» ã´Â´Ù.. |
|---|
| 299 | if (idEmpty < 0) idEmpty = i; |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | if (idSelected < 0) |
|---|
| 304 | idSelected = idEmpty; |
|---|
| 305 | |
|---|
| 306 | if (idSelected >= 0) |
|---|
| 307 | { |
|---|
| 308 | DHL_TIMER_ENTRY *info = &timer->info[idSelected]; |
|---|
| 309 | if (info->used == FALSE) { |
|---|
| 310 | timer->nActiveTimer++; |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | info->nId = cmd->idTimerOrCmd; |
|---|
| 314 | info->period = cmd->nPeriodMs; |
|---|
| 315 | info->fn = cmd->func; |
|---|
| 316 | for (i=0; i<timer->nUserParam; i++) |
|---|
| 317 | info->params[i] = cmd->userParams[i]; |
|---|
| 318 | info->flags = cmd->flags; |
|---|
| 319 | |
|---|
| 320 | info->start = DHL_OS_GetMsCount(); |
|---|
| 321 | info->used = TRUE; |
|---|
| 322 | |
|---|
| 323 | // maxActiveIndex¸¦ ¾Ë¾ÆµÎ¸é TimerTask¿¡¼ loop¸¦ µ¹¶§ µµ¿òÀÌ µÈ´Ù. |
|---|
| 324 | if (timer->maxActiveIndex < idSelected) |
|---|
| 325 | timer->maxActiveIndex = idSelected; |
|---|
| 326 | |
|---|
| 327 | if (g_Trace_TimerHandle == timer) |
|---|
| 328 | printf( "\t index %d, ID: %d, total %d active\n", idSelected, cmd->idTimerOrCmd, timer->nActiveTimer); |
|---|
| 329 | } |
|---|
| 330 | else { |
|---|
| 331 | if (g_Trace_TimerHandle == timer) |
|---|
| 332 | printf( "!! No more timer slot for ID: %d\n", cmd->idTimerOrCmd); |
|---|
| 333 | // it may be available some time later because oneshot timer will die.. |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | return idSelected >= 0 ? DHL_OK : DHL_FAIL_NOT_AVAILABLE; |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | /* |
|---|
| 340 | delete one timer entry. |
|---|
| 341 | this function should be called in timer task. |
|---|
| 342 | */ |
|---|
| 343 | static DHL_RESULT p_timer_delete_entry(DHL_TIMER *timer, UINT32 nIdTimer) |
|---|
| 344 | { |
|---|
| 345 | int i; |
|---|
| 346 | DHL_RESULT dhr = DHL_FAIL_NOT_FOUND; |
|---|
| 347 | |
|---|
| 348 | //ASSERT(cmd->idTimerOrCmd == eTMR_CMD_DELETE); |
|---|
| 349 | |
|---|
| 350 | if (nIdTimer == (UINT32)-1) { // delete all.. |
|---|
| 351 | if (g_Trace_TimerHandle == timer) |
|---|
| 352 | printf( "delete all timer entry\n"); |
|---|
| 353 | |
|---|
| 354 | memset(&timer->info, 0, timer->nMaxSlot*sizeof(DHL_TIMER_ENTRY)); |
|---|
| 355 | timer->nActiveTimer = 0; |
|---|
| 356 | timer->maxActiveIndex = -1; |
|---|
| 357 | dhr = DHL_OK; |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | for (i=0;i<=timer->maxActiveIndex;i++) |
|---|
| 361 | { |
|---|
| 362 | if ((timer->info[i].used) && (timer->info[i].nId == nIdTimer)) |
|---|
| 363 | { |
|---|
| 364 | memset(&timer->info[i], 0, sizeof(DHL_TIMER_ENTRY)); |
|---|
| 365 | timer->nActiveTimer--; |
|---|
| 366 | |
|---|
| 367 | if (g_Trace_TimerHandle == timer) |
|---|
| 368 | printf( "StopTimer: index: %d, ID: %d\n", i, nIdTimer); |
|---|
| 369 | |
|---|
| 370 | dhr = DHL_OK; |
|---|
| 371 | |
|---|
| 372 | // ¹º°¡ À߸øµÇ¾î¼ °°Àº ID·Î ¿©·¯°³°¡ µî·ÏµÇ¾î ÀÖÀ» ¼öµµ Àֱ⶧¹®¿¡ |
|---|
| 373 | // ¿©±â¼ loop¸¦ ³ª°¡Áö ¾Ê°í ¸ðµç timer record ¸¦ ´Ù °Ë»öÇØº»´Ù. |
|---|
| 374 | } |
|---|
| 375 | } |
|---|
| 376 | return dhr; |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | /* |
|---|
| 380 | show timer info |
|---|
| 381 | */ |
|---|
| 382 | static void p_timer_show(DHL_TIMER *timer, DHL_TIMER_COMMAND *cmd) |
|---|
| 383 | { |
|---|
| 384 | DHL_RESULT dhlResult; |
|---|
| 385 | int i, k; |
|---|
| 386 | char buf[80]; |
|---|
| 387 | |
|---|
| 388 | dhlResult = p_timer_check_valid(timer); |
|---|
| 389 | if (dhlResult) |
|---|
| 390 | return; |
|---|
| 391 | |
|---|
| 392 | DHL_OS_Printf("----- Timer Info 0x%x -----\n", timer); |
|---|
| 393 | |
|---|
| 394 | DHL_OS_Printf(" '%s', priority %d, max %d\n", |
|---|
| 395 | timer->name, timer->param.task_priority, timer->nMaxSlot); |
|---|
| 396 | |
|---|
| 397 | for (i=0; i<=timer->maxActiveIndex; i++) { |
|---|
| 398 | char *fname = NULL; |
|---|
| 399 | if (!timer->info[i].used) continue; |
|---|
| 400 | // dhl_dbg_find_sym_by_addr((UINT32)timer->info[i].fn, &fname); |
|---|
| 401 | for (buf[0]=0, k=0; k<min(4, timer->nUserParam); k++) |
|---|
| 402 | sprintf(buf+strlen(buf), "%lx ", timer->info[i].params[k]); |
|---|
| 403 | DHL_OS_Printf(" (%02d) ID %d, fn %x(%s) arg (%s), %d ms, f%x %s\n", i, |
|---|
| 404 | timer->info[i].nId, |
|---|
| 405 | timer->info[i].fn, fname ? fname : "?", |
|---|
| 406 | buf, //timer->info[i].param, |
|---|
| 407 | timer->info[i].period, |
|---|
| 408 | //timer->info[i].period, |
|---|
| 409 | timer->info[i].flags, |
|---|
| 410 | timer->info[i].flags & eTIMER_FLAG_OneShot ? "oneshot" : |
|---|
| 411 | timer->info[i].flags & eTIMER_FLAG_NowAndContinue ? "n&c" : "interval"); |
|---|
| 412 | } |
|---|
| 413 | DHL_OS_Printf("\n"); |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | void p_timer_call(DHL_TIMER *timer, UINT16 nTimerId, UINT16 flags, |
|---|
| 419 | DHL_TIMER_PROC_EX pFn, UINT32 *userParams) |
|---|
| 420 | { |
|---|
| 421 | // timer callbackÀÌ ºÒ¸®´Â µ¿¾È¿¡´Â ¾î¶² timer id°¡ service ÁßÀÎÁö ±â·ÏÀ» ³²°ÜµÎÀÚ. |
|---|
| 422 | timer->curServicedTimerId = nTimerId; |
|---|
| 423 | |
|---|
| 424 | if (g_Trace_TimerHandle == timer) |
|---|
| 425 | printf( "\n---------- TimerExBegin: %x, ID %d, fn %x, param 0x%x \n", |
|---|
| 426 | timer, nTimerId, pFn, userParams[0]); |
|---|
| 427 | |
|---|
| 428 | if (flags & TIMER_FLAG_OldStyleProc) |
|---|
| 429 | ((DHL_TIMER_PROC)pFn)(nTimerId, userParams[0]); |
|---|
| 430 | else |
|---|
| 431 | pFn(nTimerId, userParams); |
|---|
| 432 | |
|---|
| 433 | if (g_Trace_TimerHandle == timer) |
|---|
| 434 | printf( "---------- TimerExEnd: %x, ID %d \n\n", timer, nTimerId); |
|---|
| 435 | |
|---|
| 436 | timer->curServicedTimerId = 0; |
|---|
| 437 | // timer id 0Àº ¿©±â¼ ó·³ Ưº°ÇÑ Àǹ̷Π»ç¿ëÇϹǷÎ, ÀÏ¹Ý ID·Î´Â reserve ÇØ¾ß ÇÑ´Ù. |
|---|
| 438 | |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | void p_timer_shutdown(DHL_TIMER *timer) |
|---|
| 443 | { |
|---|
| 444 | dprint(2, "timer stop requested..\n"); |
|---|
| 445 | |
|---|
| 446 | // TimerTerminate -> TimerTask shutdown ÀýÂ÷ Áß¿¡´Â race conditionÀ» °í·ÁÇÏÁö ¾Ê´Â´Ù. |
|---|
| 447 | // µû¶ó¼ client´Â shutdown sequence Áß¿¡´Â timer start µîÀÌ È£ÃâµÇÁö ¾Êµµ·Ï ÁÖÀÇÇØ¾ß ÇÑ´Ù. |
|---|
| 448 | |
|---|
| 449 | DHL_OS_DeleteSemaphore(timer->semAck); |
|---|
| 450 | timer->semAck = 0; |
|---|
| 451 | |
|---|
| 452 | DHL_OS_DeleteSemaphore(timer->mutexAck); |
|---|
| 453 | timer->mutexAck = 0; |
|---|
| 454 | |
|---|
| 455 | DHL_OS_DeleteMessageQueue(timer->msgQue); |
|---|
| 456 | timer->msgQue = 0; |
|---|
| 457 | |
|---|
| 458 | dprint(2, "timer task about to shutdown..\n"); |
|---|
| 459 | timer->nTaskId = 0; |
|---|
| 460 | DHL_OS_SelfDeleteTask(); |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | #if COMMENT |
|---|
| 465 | ____Task____() {} |
|---|
| 466 | #endif |
|---|
| 467 | |
|---|
| 468 | /************************************************************************************* |
|---|
| 469 | |
|---|
| 470 | timer task |
|---|
| 471 | |
|---|
| 472 | - Timer Main Task. |
|---|
| 473 | - µî·ÏµÈ Timer¸¦ °ü¸®ÇÑ´Ù. |
|---|
| 474 | |
|---|
| 475 | *************************************************************************************/ |
|---|
| 476 | |
|---|
| 477 | void dhl_timer_task(void* arg) |
|---|
| 478 | { |
|---|
| 479 | int i; |
|---|
| 480 | DHL_RESULT result; |
|---|
| 481 | DHL_TIMER_COMMAND cmd; |
|---|
| 482 | int nMinRemainingTick; |
|---|
| 483 | UINT32 uNow; |
|---|
| 484 | DHL_TIMER *timer = (DHL_TIMER *)arg; |
|---|
| 485 | // printf( "Timer Task Launched, timer %x, %u tick/s\n", timer, _second); |
|---|
| 486 | // printf( "name '%s' max slot %d\n", timer->name, timer->nMaxSlot); |
|---|
| 487 | |
|---|
| 488 | while (TRUE) |
|---|
| 489 | { |
|---|
| 490 | DHL_OS_Delay(10); |
|---|
| 491 | nMinRemainingTick = 0x7fffffff; // signed INT32 valueÀÇ ÃÖ´ë°ª.. |
|---|
| 492 | |
|---|
| 493 | //--------- timer expiration timeout üũ ------------ |
|---|
| 494 | // ÇöÀç °¡Àå °¡±î¿î ½Ã°£ ³»¿¡ expire µÉ timer¸¦ ã´Â´Ù.. |
|---|
| 495 | |
|---|
| 496 | uNow = DHL_OS_GetMsCount(); |
|---|
| 497 | for (i=0; i<=timer->maxActiveIndex; i++) |
|---|
| 498 | { |
|---|
| 499 | int nRemainTick; |
|---|
| 500 | if (timer->info[i].used == 0) continue; |
|---|
| 501 | nRemainTick = (int) (timer->info[i].start + timer->info[i].period - uNow); |
|---|
| 502 | // ÀÌ¹Ì expire µÈ timer¶ó¸é remainÀº negative °ªÀ» °¡Áú °ÍÀÓ.. |
|---|
| 503 | |
|---|
| 504 | if (nMinRemainingTick > nRemainTick) { |
|---|
| 505 | nMinRemainingTick = nRemainTick; // it can be negative!! |
|---|
| 506 | } |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | //--------- wait message with/without timeout ------------ |
|---|
| 510 | |
|---|
| 511 | // ¼³·É, ÀÌ¹Ì expire µÈ timer entry°¡ ÀÖ´Ù°í ÇÏ´õ¶óµµ |
|---|
| 512 | // timer ½ÇÇà ºÎÇϰ¡ ¸¹¾Æ¼ command¸¦ ¾Æ¿¹ ¸ø¹Þ´Â »óȲÀÌ µÇÁö ¾Êµµ·Ï, |
|---|
| 513 | // msgque ´Â ¹Ýµå½Ã ÇѹøÀº üũ¸¦ ¼öÇàÇÏ°í ³ª¼ timer¸¦ ó¸®ÇØ ÁØ´Ù. |
|---|
| 514 | |
|---|
| 515 | if (nMinRemainingTick < 0) nMinRemainingTick = 0; |
|---|
| 516 | |
|---|
| 517 | // ¾ÆÁ÷ ³²Àº ½Ã°£ÀÌ ¸¹±â ¶§¹®¿¡ SleepÀ» ÇÑ´Ù. |
|---|
| 518 | if (nMinRemainingTick < 0x7fffffff) { |
|---|
| 519 | if (g_Trace_TimerHandle == timer) |
|---|
| 520 | dprint(2, "Timer task enter sleep for %d ticks ....\n", nMinRemainingTick); |
|---|
| 521 | |
|---|
| 522 | result = DHL_OS_ReceiveMessage(timer->msgQue, &cmd, nMinRemainingTick); |
|---|
| 523 | } |
|---|
| 524 | else { |
|---|
| 525 | // ó¸®ÇØ¾ß ÇÒ ³²Àº timer°¡ ¾ø´Ù¸é active µÉ¶§±îÁö ¹«ÇÑÁ¤ ±â´Ù¸®±â¸¸ ÇÏ¸é µÈ´Ù. |
|---|
| 526 | // |
|---|
| 527 | if (g_Trace_TimerHandle == timer) |
|---|
| 528 | dprint(2, "Timer task enter sleep until timer set...z.z.z\n"); |
|---|
| 529 | //OS_TakeSemaphore(timer->semWakeUp); |
|---|
| 530 | result = DHL_OS_ReceiveMessage(timer->msgQue, &cmd, DHL_TIMEOUT_FOREVER); |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | //--------- process message if we got new one ------------ |
|---|
| 534 | |
|---|
| 535 | if (result == DHL_OK) // we got command |
|---|
| 536 | { |
|---|
| 537 | // È¿À²ÀûÀÎ dpc ¸í·É ¼öÇàÀ» À§ÇÑ Æ¯º°ÇÑ Ã³¸®. |
|---|
| 538 | if (cmd.idTimerOrCmd < eTMR_CMD_BEGIN && |
|---|
| 539 | cmd.nPeriodMs == 0 && |
|---|
| 540 | (cmd.flags & eTIMER_FLAG_OneShot)) |
|---|
| 541 | { |
|---|
| 542 | // ¹Ù·Î Çѹø ½ÇÇà ÈÄ cancel µÇ´Â °ÍÀ̹ǷÎ, |
|---|
| 543 | // ±»ÀÌ timer entry¿¡ µî·ÏÇÒ Çʿ䰡 ¾ø´Ù. |
|---|
| 544 | |
|---|
| 545 | p_timer_call(timer, cmd.idTimerOrCmd, cmd.flags, cmd.func, cmd.userParams); |
|---|
| 546 | continue; |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | // add / delete / query / shutdown |
|---|
| 550 | |
|---|
| 551 | if (cmd.idTimerOrCmd < eTMR_CMD_BEGIN) { // This is Add command. |
|---|
| 552 | result = p_timer_add_entry(timer, &cmd); |
|---|
| 553 | if (g_Trace_TimerHandle == timer) |
|---|
| 554 | DHL_TIMER_Show(timer); |
|---|
| 555 | |
|---|
| 556 | if (cmd.flags & eTIMER_FLAG_NowAndContinue) |
|---|
| 557 | // µî·Ïµµ ÇÏÁö¸¸, Áö±Ý ¹Ù·Î ´çÀå callµµ ÇØÁÖ¾î¾ß ÇÑ´Ù. |
|---|
| 558 | p_timer_call(timer, cmd.idTimerOrCmd, cmd.flags, cmd.func, cmd.userParams); |
|---|
| 559 | |
|---|
| 560 | } |
|---|
| 561 | else if (cmd.idTimerOrCmd == eTMR_CMD_DELETE) { |
|---|
| 562 | // delete ÀÎ °æ¿ì´Â »èÁ¦ÇÒ timer id°¡ userparam[0]À» ÅëÇØ Àü´Þ µÈ´Ù. |
|---|
| 563 | result = p_timer_delete_entry(timer, cmd.userParams[0]); |
|---|
| 564 | } |
|---|
| 565 | else if (cmd.idTimerOrCmd == eTMR_CMD_DELETE_ALL) { |
|---|
| 566 | result = p_timer_delete_entry(timer, (UINT32)-1); |
|---|
| 567 | } |
|---|
| 568 | else if (cmd.idTimerOrCmd == eTMR_CMD_SYNC) { |
|---|
| 569 | ; // Ưº°È÷ ó¸®ÇÒ °Í ¾øÀ½. ±×³É ¾Æ·¡¿¡¼ ack¸¸ ÁÖ¸é µÊ. |
|---|
| 570 | } |
|---|
| 571 | else if (cmd.idTimerOrCmd == eTMR_CMD_SHOW) { |
|---|
| 572 | p_timer_show(timer, &cmd); |
|---|
| 573 | } |
|---|
| 574 | else if (cmd.idTimerOrCmd == eTMR_CMD_QUERY) { |
|---|
| 575 | // not yet.. |
|---|
| 576 | } |
|---|
| 577 | else if (cmd.idTimerOrCmd == eTMR_CMD_SHUTDOWN) { |
|---|
| 578 | break; |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | // »ç¿ë ¿¹¸¦ º¸¸é TimerStop ¿¡¼¸¸ ack ¸ðµå¸¦ »ç¿ëÇϰí ÀÖÀ¸¹Ç·Î, |
|---|
| 582 | // TimerStop ¿¡¼ »ç¿ëµÇÁö ¾Ê´Â nPeriodMs º¯¼ö °ø°£À» result ¸®ÅÏ ¿ëµµ·Î »ç¿ëÇÑ´Ù. |
|---|
| 583 | if (cmd.idTimerOrCmd == eTMR_CMD_DELETE && (cmd.flags & TIMER_FLAG_NeedAck)) { |
|---|
| 584 | if (cmd.nPeriodMs) |
|---|
| 585 | *(UINT32 *)(cmd.nPeriodMs) = (UINT32)result; |
|---|
| 586 | DHL_OS_GiveSemaphore(timer->semAck); |
|---|
| 587 | } |
|---|
| 588 | if ((cmd.idTimerOrCmd == eTMR_CMD_SYNC) && (cmd.flags & TIMER_FLAG_NeedAck)) { |
|---|
| 589 | DHL_OS_GiveSemaphore(timer->semAck); |
|---|
| 590 | } |
|---|
| 591 | } |
|---|
| 592 | else if (result == DHL_FAIL_TIMEOUT) |
|---|
| 593 | { |
|---|
| 594 | // it is natural.. some timer entry is timed-out. |
|---|
| 595 | } |
|---|
| 596 | else |
|---|
| 597 | { |
|---|
| 598 | DHL_OS_Printf("!! timer rx msg result 0x%x \a\n", result); |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | //-------- timer entry ó¸® --------------- |
|---|
| 602 | |
|---|
| 603 | for (i=0; i<=timer->maxActiveIndex; i++) |
|---|
| 604 | { |
|---|
| 605 | DHL_TIMER_ENTRY *ti = &timer->info[i]; |
|---|
| 606 | |
|---|
| 607 | if (ti->used == FALSE) |
|---|
| 608 | continue; |
|---|
| 609 | |
|---|
| 610 | // ÁöÁ¤ ½Ã°£ÀÌ °æ°úµÇ¾ú´ÂÁö üũ. Timeout µÇ¾úÀ¸¸é TimerÇÔ¼ö ¼öÇà. |
|---|
| 611 | // |
|---|
| 612 | if (DHL_OS_GetMsCount() - ti->start > ti->period) // Timer expired.. |
|---|
| 613 | { |
|---|
| 614 | UINT32 userParams[MAX_NUMBER_OF_TIMER_PARAM]; |
|---|
| 615 | DHL_TIMER_PROC_EX pFn; |
|---|
| 616 | UINT16 id, flags; |
|---|
| 617 | BOOL bOneShot; |
|---|
| 618 | |
|---|
| 619 | // ¾Æ·¡¿¡¼ oneshot ÀÎ °æ¿ì callback Àü¿¡ ¸ÕÀú ti¸¦ clear ½ÃŰ¹Ç·Î, |
|---|
| 620 | // timer call¿¡ ÇÊ¿äÇÑ ¸ðµç ÆÄ¶ó¹ÌÅÍ´Â backup ÇØ µÎ¾î¾ß ÇÑ´Ù. |
|---|
| 621 | pFn = ti->fn; |
|---|
| 622 | id = ti->nId; |
|---|
| 623 | flags = ti->flags; |
|---|
| 624 | memcpy(userParams, ti->params, sizeof(UINT32)*timer->nUserParam); |
|---|
| 625 | bOneShot = (flags & eTIMER_FLAG_OneShot) ? TRUE : FALSE; |
|---|
| 626 | |
|---|
| 627 | if (bOneShot) { // 1ȸ¼º Timer: ÀÌ timer¸¦ off½ÃŲ´Ù. |
|---|
| 628 | memset(ti, 0, sizeof(DHL_TIMER_ENTRY)); |
|---|
| 629 | timer->nActiveTimer--; |
|---|
| 630 | } |
|---|
| 631 | else { // Periodic Timer: tick counter¸¦ ¸®¼Â½ÃŲ´Ù. |
|---|
| 632 | ti->start = DHL_OS_GetMsCount(); |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | p_timer_call(timer, id, flags, pFn, userParams); |
|---|
| 636 | |
|---|
| 637 | if (bOneShot) |
|---|
| 638 | if (g_Trace_TimerHandle == timer) |
|---|
| 639 | printf( "Oneshot timer ID %d killed\n", id); |
|---|
| 640 | } |
|---|
| 641 | |
|---|
| 642 | } // end for (timer DB) |
|---|
| 643 | |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | p_timer_shutdown(timer); |
|---|
| 647 | DHL_OS_SelfDeleteTask(); |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | #if COMMENT |
|---|
| 652 | ____LowLevel_API____(){} |
|---|
| 653 | #endif |
|---|
| 654 | |
|---|
| 655 | DHL_RESULT DHL_TIMER_StartEx(DHL_TMHANDLE handle, UINT32 nIdTimer, UINT32 nPeriodMs, |
|---|
| 656 | DHL_TIMER_PROC_EX func, int numParam, UINT32 *params, UINT16 flags) |
|---|
| 657 | { |
|---|
| 658 | DHL_RESULT dhlResult; |
|---|
| 659 | DHL_TIMER *timer = (DHL_TIMER *)handle; |
|---|
| 660 | DHL_TIMER_COMMAND cmd; |
|---|
| 661 | DHL_OS_TASK_ID tid = DHL_OS_GetTaskID(); |
|---|
| 662 | int i; |
|---|
| 663 | |
|---|
| 664 | if ((dhlResult = p_timer_check_valid(timer))!=0) |
|---|
| 665 | return dhlResult; |
|---|
| 666 | |
|---|
| 667 | if (func == NULL) { |
|---|
| 668 | printf( "!! func is null [%d]!\n", nIdTimer); |
|---|
| 669 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 670 | } |
|---|
| 671 | if (nIdTimer & 0xFFFF0000) { |
|---|
| 672 | printf( "!! timer id should be 16-bits range.\n"); |
|---|
| 673 | DHL_ASSERT(FALSE, ""); |
|---|
| 674 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 675 | } |
|---|
| 676 | if (nIdTimer >= eTMR_CMD_BEGIN || nIdTimer == 0) { |
|---|
| 677 | printf( "!! timer id 0x%x is in reserved range.\n", nIdTimer); |
|---|
| 678 | DHL_ASSERT(FALSE, ""); |
|---|
| 679 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 680 | } |
|---|
| 681 | if (nPeriodMs == 0 && !(flags & eTIMER_FLAG_OneShot)) { |
|---|
| 682 | printf( "!! interval timer should have period.\n"); |
|---|
| 683 | DHL_ASSERT(FALSE, ""); |
|---|
| 684 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 685 | } |
|---|
| 686 | |
|---|
| 687 | // ½ÇÁ¦ parameterÀÇ °¹¼ö´Â Initialize ÇÒ ¶§ ÁöÁ¤Çß´ø ¼öº¸´Ù Å©¸é ¾ÈµÈ´Ù. |
|---|
| 688 | if (numParam > timer->nUserParam) { |
|---|
| 689 | numParam = timer->nUserParam; |
|---|
| 690 | } |
|---|
| 691 | // Initialize ¿¡¼ ÁöÁ¤ÇÑ ¼ýÀÚº¸´Ù ÀûÀº °ÍÀº ±¦ÂúÀ½. 0À¸·Î ä¿öÁü. |
|---|
| 692 | |
|---|
| 693 | dprint(2, "%s: (ID %d, period %d, flags %x, %d params %x %x ..)\n", __FUNCTION__, |
|---|
| 694 | nIdTimer, nPeriodMs, flags, numParam, params[0], params[1]); |
|---|
| 695 | |
|---|
| 696 | memset(&cmd, 0, sizeof(DHL_TIMER_COMMAND)); |
|---|
| 697 | |
|---|
| 698 | // ADDÀÇ °æ¿ì º°µµÀÇ command id¸¦ »ç¿ëÇÏÁö ¾Ê°í, ±×³É timer id¸¦ Àü¼ÛÇÑ´Ù. |
|---|
| 699 | cmd.idTimerOrCmd = nIdTimer; |
|---|
| 700 | cmd.nPeriodMs = nPeriodMs; |
|---|
| 701 | cmd.func = func; |
|---|
| 702 | cmd.flags = flags; |
|---|
| 703 | |
|---|
| 704 | for (i=0; i<numParam; i++) |
|---|
| 705 | cmd.userParams[i] = params[i]; |
|---|
| 706 | |
|---|
| 707 | if (tid != timer->nTaskId) |
|---|
| 708 | { |
|---|
| 709 | // send command asynchronously. |
|---|
| 710 | // if we need return value, then we should use ack. |
|---|
| 711 | // |
|---|
| 712 | // cmd ÀÚü´Â ÃÖ´ë °¹¼öÀÇ user paramÀ» Æ÷ÇÔÇϰí ÀÖÁö¸¸ |
|---|
| 713 | // OSAL ³»ºÎ¿¡¼ ÇÊ¿äÇÑ ¸¸Å¸¸ º¹»ç¸¦ ÇØ °¥ °ÍÀÌ´Ù. |
|---|
| 714 | dhlResult = DHL_OS_SendMessage(timer->msgQue, &cmd, sizeof(cmd)); |
|---|
| 715 | if (dhlResult) { |
|---|
| 716 | // error check.. |
|---|
| 717 | printf( "!! %s send cmd err %x\a\n", __FUNCTION__, dhlResult); |
|---|
| 718 | } |
|---|
| 719 | } |
|---|
| 720 | else |
|---|
| 721 | { |
|---|
| 722 | // current task is THE TIMER task that we can add. |
|---|
| 723 | // so, we can directly modify timer info. |
|---|
| 724 | // |
|---|
| 725 | dhlResult = p_timer_add_entry(timer, &cmd); |
|---|
| 726 | } |
|---|
| 727 | return dhlResult; |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| 730 | DHL_RESULT DHL_TIMER_Start(DHL_TMHANDLE handle, UINT32 nIdTimer, UINT32 nPeriodMs, |
|---|
| 731 | DHL_TIMER_PROC func, UINT32 param, BOOL bOneShot) |
|---|
| 732 | { |
|---|
| 733 | UINT16 flags = \ |
|---|
| 734 | bOneShot == 0 ? eTIMER_FLAG_Continue : \ |
|---|
| 735 | bOneShot == 2 ? eTIMER_FLAG_NowAndContinue : eTIMER_FLAG_OneShot; |
|---|
| 736 | |
|---|
| 737 | flags |= TIMER_FLAG_OldStyleProc; |
|---|
| 738 | return DHL_TIMER_StartEx(handle, nIdTimer, nPeriodMs, |
|---|
| 739 | (DHL_TIMER_PROC_EX) func, 1, ¶m, flags); |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | DHL_RESULT DHL_TIMER_Stop(DHL_TMHANDLE handle, UINT32 nIdTimer) |
|---|
| 743 | { |
|---|
| 744 | DHL_RESULT dhlResult, dhReturnValue = DHL_OK; |
|---|
| 745 | DHL_TIMER *timer = (DHL_TIMER *)handle; |
|---|
| 746 | DHL_TIMER_COMMAND cmd; |
|---|
| 747 | DHL_OS_TASK_ID tid = DHL_OS_GetTaskID(); |
|---|
| 748 | |
|---|
| 749 | if ((dhlResult = p_timer_check_valid(timer))!=0) |
|---|
| 750 | return dhlResult; |
|---|
| 751 | |
|---|
| 752 | // À߸øµÈ timer id ´Â ¾Æ¹«·± ¿µÇâÀ» ³¢Ä¡Áö ¾Ê´Â´Ù. Á¦°Å. |
|---|
| 753 | #if 0 |
|---|
| 754 | if (nIdTimer == 0) { // cafrii 060919 add |
|---|
| 755 | printf( "!! invalid timer id 0\n", nIdTimer); |
|---|
| 756 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 757 | } |
|---|
| 758 | #endif |
|---|
| 759 | |
|---|
| 760 | memset(&cmd, 0, sizeof(DHL_TIMER_COMMAND)); |
|---|
| 761 | |
|---|
| 762 | cmd.idTimerOrCmd = eTMR_CMD_DELETE; |
|---|
| 763 | cmd.userParams[0] = nIdTimer & 0xFFFF; // id´Â 16-bits.. |
|---|
| 764 | |
|---|
| 765 | if (tid != timer->nTaskId) |
|---|
| 766 | { |
|---|
| 767 | int wait_count; |
|---|
| 768 | cmd.flags |= TIMER_FLAG_NeedAck; // we always request ACK when send STOP command. |
|---|
| 769 | cmd.nPeriodMs = (UINT32)&dhReturnValue; |
|---|
| 770 | |
|---|
| 771 | // need ack mechanism.. |
|---|
| 772 | DHL_OS_TakeSemaphore(timer->mutexAck, DHL_TIMEOUT_FOREVER); |
|---|
| 773 | DHL_OS_TakeSemaphore(timer->semAck, 0); // reset to none |
|---|
| 774 | |
|---|
| 775 | dhlResult = DHL_OS_SendMessage(timer->msgQue, &cmd, sizeof(cmd)); |
|---|
| 776 | if (dhlResult) { |
|---|
| 777 | // error check.. |
|---|
| 778 | printf( "!! %s send cmd err %x\a\n", __FUNCTION__, dhlResult); |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | for (wait_count=0 ; wait_count<5; wait_count++) { |
|---|
| 782 | if (wait_count) |
|---|
| 783 | printf( "!! timer not responding.. wait %d..\n", wait_count); |
|---|
| 784 | dhlResult = DHL_OS_TakeSemaphore(timer->semAck, 1000); |
|---|
| 785 | if (dhlResult == DHL_OK) break; |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | dhlResult = dhReturnValue; |
|---|
| 789 | DHL_OS_GiveSemaphore(timer->mutexAck); |
|---|
| 790 | } |
|---|
| 791 | else |
|---|
| 792 | { |
|---|
| 793 | // current task is THE TIMER task that we can add. |
|---|
| 794 | // so, we can directly modify timer info. |
|---|
| 795 | // |
|---|
| 796 | dhlResult = p_timer_delete_entry(timer, nIdTimer); |
|---|
| 797 | } |
|---|
| 798 | return dhlResult; |
|---|
| 799 | } |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | DHL_RESULT DHL_TIMER_Sync(DHL_TMHANDLE handle) |
|---|
| 803 | { |
|---|
| 804 | DHL_RESULT dhlResult, dhReturnValue = DHL_OK; |
|---|
| 805 | DHL_TIMER *timer = (DHL_TIMER *)handle; |
|---|
| 806 | DHL_TIMER_COMMAND cmd; |
|---|
| 807 | DHL_OS_TASK_ID tid = DHL_OS_GetTaskID(); |
|---|
| 808 | |
|---|
| 809 | if ((dhlResult = p_timer_check_valid(timer))!=0) |
|---|
| 810 | return dhlResult; |
|---|
| 811 | |
|---|
| 812 | memset(&cmd, 0, sizeof(DHL_TIMER_COMMAND)); |
|---|
| 813 | |
|---|
| 814 | cmd.idTimerOrCmd = eTMR_CMD_SYNC; |
|---|
| 815 | |
|---|
| 816 | if (tid != timer->nTaskId) |
|---|
| 817 | { |
|---|
| 818 | int wait_count; |
|---|
| 819 | cmd.flags |= TIMER_FLAG_NeedAck; // we need ACK for this command. |
|---|
| 820 | |
|---|
| 821 | // need ack mechanism.. |
|---|
| 822 | DHL_OS_TakeSemaphore(timer->mutexAck, DHL_TIMEOUT_FOREVER); |
|---|
| 823 | DHL_OS_TakeSemaphore(timer->semAck, 0); // reset to none |
|---|
| 824 | |
|---|
| 825 | dhlResult = DHL_OS_SendMessage(timer->msgQue, &cmd, sizeof(cmd)); |
|---|
| 826 | if (dhlResult) { |
|---|
| 827 | // error check.. |
|---|
| 828 | printf( "!! %s send cmd err %x\a\n", __FUNCTION__, dhlResult); |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | for (wait_count=0 ; wait_count<5; wait_count++) { |
|---|
| 832 | if (wait_count) |
|---|
| 833 | printf( "!! timer '%s' not responding.. wait %d..\n", timer->name, wait_count); |
|---|
| 834 | dhlResult = DHL_OS_TakeSemaphore(timer->semAck, 1000); |
|---|
| 835 | if (dhlResult == DHL_OK) break; |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | dhlResult = dhReturnValue; |
|---|
| 839 | DHL_OS_GiveSemaphore(timer->mutexAck); |
|---|
| 840 | } |
|---|
| 841 | else |
|---|
| 842 | { |
|---|
| 843 | DHL_ASSERT(FALSE, "invalid usage\n"); |
|---|
| 844 | } |
|---|
| 845 | return dhlResult; |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | void DHL_TIMER_Show(DHL_TMHANDLE handle) |
|---|
| 849 | { |
|---|
| 850 | DHL_RESULT dhlResult; |
|---|
| 851 | DHL_TIMER *timer; |
|---|
| 852 | DHL_TIMER_COMMAND cmd; |
|---|
| 853 | DHL_OS_TASK_ID tid = DHL_OS_GetTaskID(); |
|---|
| 854 | |
|---|
| 855 | if (handle == 0) |
|---|
| 856 | timer = g_dhl_timer_list; |
|---|
| 857 | else |
|---|
| 858 | timer = (DHL_TIMER *)handle; |
|---|
| 859 | |
|---|
| 860 | while (timer) |
|---|
| 861 | { |
|---|
| 862 | if ((dhlResult = p_timer_check_valid(timer))!=0) |
|---|
| 863 | return; |
|---|
| 864 | |
|---|
| 865 | memset(&cmd, 0, sizeof(DHL_TIMER_COMMAND)); |
|---|
| 866 | cmd.idTimerOrCmd = eTMR_CMD_SHOW; |
|---|
| 867 | // this SHOW command do not use ACK. |
|---|
| 868 | |
|---|
| 869 | if (tid != timer->nTaskId) |
|---|
| 870 | { |
|---|
| 871 | // send command asynchronously.. |
|---|
| 872 | dhlResult = DHL_OS_SendMessage(timer->msgQue, &cmd, sizeof(cmd)); |
|---|
| 873 | if (dhlResult) { |
|---|
| 874 | // error check.. |
|---|
| 875 | printf( "!! %s send cmd err %x\a\n", __FUNCTION__, dhlResult); |
|---|
| 876 | } |
|---|
| 877 | } |
|---|
| 878 | else { |
|---|
| 879 | p_timer_show(timer, &cmd); |
|---|
| 880 | } |
|---|
| 881 | |
|---|
| 882 | if (handle) // show only specified timer. |
|---|
| 883 | break; |
|---|
| 884 | |
|---|
| 885 | if (tid != timer->nTaskId) { |
|---|
| 886 | DHL_OS_Delay(100); |
|---|
| 887 | // wait for timer tasks to print information |
|---|
| 888 | } |
|---|
| 889 | timer = timer->next; |
|---|
| 890 | } |
|---|
| 891 | |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | |
|---|
| 895 | DHL_RESULT DHL_TIMER_Initialize(DHL_TIMER_INIT_PARAM *param, DHL_TMHANDLE *pHandle) |
|---|
| 896 | { |
|---|
| 897 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 898 | int nAllocSize; |
|---|
| 899 | char buf[20]; |
|---|
| 900 | UINT32 mask; |
|---|
| 901 | DHL_TIMER *timer = NULL; |
|---|
| 902 | |
|---|
| 903 | dprint(2, "%s: timer '%s' init, max %d, pri %d, stack %d, #param %d, qsize %d\n", |
|---|
| 904 | __FUNCTION__, param->name, param->max_timer_entry, |
|---|
| 905 | param->task_priority, param->stack_size, |
|---|
| 906 | param->num_user_param, param->msg_que_size); |
|---|
| 907 | |
|---|
| 908 | *pHandle = NULL; // initialize first.. |
|---|
| 909 | |
|---|
| 910 | if (param->max_timer_entry <= 0) |
|---|
| 911 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 912 | |
|---|
| 913 | nAllocSize = sizeof(DHL_TIMER) + 4 + param->max_timer_entry * sizeof(DHL_TIMER_ENTRY) + 4; |
|---|
| 914 | // assign some guard band space between master timer info and timer slot entries. |
|---|
| 915 | |
|---|
| 916 | timer = (DHL_TIMER *) DHL_OS_Malloc(nAllocSize); |
|---|
| 917 | if (timer == NULL) |
|---|
| 918 | return DHL_FAIL_OUT_OF_MEMORY; |
|---|
| 919 | |
|---|
| 920 | memset(timer, 0, nAllocSize); |
|---|
| 921 | |
|---|
| 922 | // name of timers |
|---|
| 923 | strncpy(timer->name, param->name, MAX_TIMER_NAME); |
|---|
| 924 | timer->name[MAX_TIMER_NAME] = 0; |
|---|
| 925 | |
|---|
| 926 | // max timer slots |
|---|
| 927 | timer->nMaxSlot = param->max_timer_entry; |
|---|
| 928 | |
|---|
| 929 | // no active timer now. |
|---|
| 930 | timer->maxActiveIndex = -1; |
|---|
| 931 | |
|---|
| 932 | // timer slots |
|---|
| 933 | timer->info = (DHL_TIMER_ENTRY *) ((UINT8 *)timer + sizeof(DHL_TIMER) + 4); |
|---|
| 934 | |
|---|
| 935 | // num user param |
|---|
| 936 | if (param->num_user_param == 0) |
|---|
| 937 | timer->nUserParam = 1; // for backward compatibility |
|---|
| 938 | else if (param->num_user_param > 0 && param->num_user_param <= MAX_NUMBER_OF_TIMER_PARAM) |
|---|
| 939 | timer->nUserParam = param->num_user_param; |
|---|
| 940 | else { |
|---|
| 941 | printf( "!! num user param %d invalid.\n", param->num_user_param); |
|---|
| 942 | goto label_end; |
|---|
| 943 | } |
|---|
| 944 | |
|---|
| 945 | // message que size |
|---|
| 946 | if (param->msg_que_size == 0) |
|---|
| 947 | timer->nMaxQueSize = DEFAULT_MSG_QUE_SIZE; // for backward compatibility |
|---|
| 948 | else if (param->msg_que_size > 0) |
|---|
| 949 | timer->nMaxQueSize = param->msg_que_size; |
|---|
| 950 | else { |
|---|
| 951 | printf( "!! que size %d invalid.\n", param->msg_que_size); |
|---|
| 952 | goto label_end; |
|---|
| 953 | } |
|---|
| 954 | |
|---|
| 955 | // task´Â ¸Ç ¸¶Áö¸·¿¡ »ý¼ºÇÏ´Â °Ô ÁÁ´Ù. priority °ü·ÃÇÏ¿© ¸ÕÀú ½ÇÇà °¡´É¼ºÀÌ ÀÖÀ¸¹Ç·Î.. |
|---|
| 956 | // |
|---|
| 957 | |
|---|
| 958 | memset(buf, 0, sizeof(buf)); |
|---|
| 959 | strcpy(buf, "TS"); // timer ack sem |
|---|
| 960 | strncpy(buf+2, timer->name, 6); |
|---|
| 961 | timer->semAck = DHL_OS_CreateBinarySemaphore(buf, 0, 0); |
|---|
| 962 | |
|---|
| 963 | if (timer->semAck == 0) { |
|---|
| 964 | printf( "!! Creating sem err\n"); |
|---|
| 965 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 966 | goto label_end; |
|---|
| 967 | } |
|---|
| 968 | |
|---|
| 969 | // param->use_mutex_lock is never used at all. |
|---|
| 970 | |
|---|
| 971 | memset(buf, 0, sizeof(buf)); |
|---|
| 972 | strcpy(buf, "TM"); // timer ack mutex |
|---|
| 973 | strncpy(buf+2, timer->name, 6); |
|---|
| 974 | timer->mutexAck = DHL_OS_CreateMutexSemaphore(buf); |
|---|
| 975 | |
|---|
| 976 | if (timer->mutexAck == 0) { |
|---|
| 977 | printf( "!! Creating mutex err\n"); |
|---|
| 978 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 979 | goto label_end; |
|---|
| 980 | } |
|---|
| 981 | |
|---|
| 982 | memset(buf, 0, sizeof(buf)); |
|---|
| 983 | strcpy(buf, "TQ"); // timer cmd que |
|---|
| 984 | strncpy(buf+2, timer->name, 6); |
|---|
| 985 | #if 0//BRCM |
|---|
| 986 | timer->msgQue = DHL_OS_CreateMessageQueue(buf, 0, |
|---|
| 987 | TIMER_COMMAND_SIZE(timer->nUserParam), TIMER_COMMAND_SIZE(timer->nUserParam)); |
|---|
| 988 | #else |
|---|
| 989 | timer->msgQue = DHL_OS_CreateMessageQueue(buf, 0, |
|---|
| 990 | timer->nMaxQueSize, TIMER_COMMAND_SIZE(timer->nUserParam)); |
|---|
| 991 | #endif |
|---|
| 992 | if (timer->msgQue == 0) { |
|---|
| 993 | printf( "!! Creating msgq err\n"); |
|---|
| 994 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 995 | goto label_end; |
|---|
| 996 | } |
|---|
| 997 | |
|---|
| 998 | timer->magic = DHL_TIMER_MAGICKEY; |
|---|
| 999 | |
|---|
| 1000 | //timer->fnLock = dhl_timer_lock; |
|---|
| 1001 | //timer->fnUnlock = dhl_timer_unclock; |
|---|
| 1002 | |
|---|
| 1003 | timer->param = *param; |
|---|
| 1004 | timer->param.name = timer->name; |
|---|
| 1005 | |
|---|
| 1006 | mask = DHL_OS_DisableInterrupts(); |
|---|
| 1007 | timer->next = g_dhl_timer_list; |
|---|
| 1008 | g_dhl_timer_list = timer; |
|---|
| 1009 | DHL_OS_RestoreInterrupts(mask); |
|---|
| 1010 | |
|---|
| 1011 | //memdump(timer, sizeof(*timer), "timer"); |
|---|
| 1012 | //console_flush(); |
|---|
| 1013 | |
|---|
| 1014 | /* |
|---|
| 1015 | timer task priority°¡ ³ôÀ» °æ¿ì ÀÌ ÇÔ¼ö°¡ Á¾·áµÇÁö Àü¿¡µµ ¹Ù·Î timer task°¡ |
|---|
| 1016 | ½ÇÇà µÉ ¼ö ÀÖÀ½¿¡ À¯ÀÇÇÒ °Í. |
|---|
| 1017 | */ |
|---|
| 1018 | timer->nTaskId = DHL_OS_CreateTask((DHL_OS_TASKFUNCTION) dhl_timer_task, timer->name, |
|---|
| 1019 | param->task_priority, param->stack_size, (UINT32)timer); |
|---|
| 1020 | |
|---|
| 1021 | if (timer->nTaskId == (DHL_OS_TASK_ID) 0) { |
|---|
| 1022 | printf( "!! Creating task err\n"); |
|---|
| 1023 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 1024 | goto label_end; |
|---|
| 1025 | } |
|---|
| 1026 | |
|---|
| 1027 | //dhl_timer_show(0); |
|---|
| 1028 | |
|---|
| 1029 | if (pHandle) |
|---|
| 1030 | *pHandle = (DHL_TMHANDLE) timer; |
|---|
| 1031 | timer = 0; |
|---|
| 1032 | |
|---|
| 1033 | label_end: |
|---|
| 1034 | |
|---|
| 1035 | if (timer) { |
|---|
| 1036 | // clean up! |
|---|
| 1037 | printf( "!! err occurred in timer init. clean up!\n"); |
|---|
| 1038 | |
|---|
| 1039 | if (timer->semAck) |
|---|
| 1040 | DHL_OS_DeleteSemaphore(timer->semAck); |
|---|
| 1041 | if (timer->mutexAck) |
|---|
| 1042 | DHL_OS_DeleteSemaphore(timer->mutexAck); |
|---|
| 1043 | if (timer->msgQue) |
|---|
| 1044 | DHL_OS_DeleteMessageQueue(timer->msgQue); |
|---|
| 1045 | |
|---|
| 1046 | DHL_OS_Free((void**)&timer); |
|---|
| 1047 | } |
|---|
| 1048 | |
|---|
| 1049 | return dhlResult; |
|---|
| 1050 | } |
|---|
| 1051 | |
|---|
| 1052 | |
|---|
| 1053 | /** |
|---|
| 1054 | @todo |
|---|
| 1055 | Task Á¾·á OSAL API°¡ ¾ø´Ù¸é internal ¿ëµµÀÇ functionÀ» ¸¸µé¾î¼ |
|---|
| 1056 | OSAL_Priv.h ¿¡ µî·ÏÇØ ³õ°í »ç¿ëÇÏ¸é µÉ °Í °°À½. |
|---|
| 1057 | |
|---|
| 1058 | */ |
|---|
| 1059 | void DHL_TIMER_Terminate(DHL_TMHANDLE handle) |
|---|
| 1060 | { |
|---|
| 1061 | DHL_RESULT dhlResult; |
|---|
| 1062 | DHL_TIMER *timer = (DHL_TIMER *)handle; |
|---|
| 1063 | UINT32 i; |
|---|
| 1064 | DHL_TIMER_COMMAND cmd; |
|---|
| 1065 | DHL_OS_TASK_ID tid = DHL_OS_GetTaskID(); |
|---|
| 1066 | |
|---|
| 1067 | // TimerTask°¡ ÀÚµ¿À¸·Î Á×À»¶§±îÁö ±â´Ù¸± ½Ã°£.. |
|---|
| 1068 | #define WAIT_TIME 5 // second. |
|---|
| 1069 | #define CHECK_PER_SECOND 5 // times. |
|---|
| 1070 | |
|---|
| 1071 | if ((dhlResult = p_timer_check_valid(timer))!=0) |
|---|
| 1072 | return; |
|---|
| 1073 | |
|---|
| 1074 | if (tid == timer->nTaskId) { |
|---|
| 1075 | printf( "!! %s: cannot shutdown timer in itself\n", __FUNCTION__); |
|---|
| 1076 | return; |
|---|
| 1077 | } |
|---|
| 1078 | |
|---|
| 1079 | memset(&cmd, 0, sizeof(DHL_TIMER_COMMAND)); |
|---|
| 1080 | cmd.idTimerOrCmd = eTMR_CMD_SHUTDOWN; |
|---|
| 1081 | |
|---|
| 1082 | dhlResult = DHL_OS_SendMessage(timer->msgQue, &cmd, sizeof(cmd)); |
|---|
| 1083 | if (dhlResult) { |
|---|
| 1084 | // error check.. |
|---|
| 1085 | printf( "!! %s send cmd err %x\n", __FUNCTION__, dhlResult); |
|---|
| 1086 | } |
|---|
| 1087 | |
|---|
| 1088 | for (i = 0; i < WAIT_TIME*CHECK_PER_SECOND; ++i) { |
|---|
| 1089 | if (timer->nTaskId == 0) { |
|---|
| 1090 | break; |
|---|
| 1091 | } |
|---|
| 1092 | DHL_OS_Delay(1000/CHECK_PER_SECOND); |
|---|
| 1093 | } |
|---|
| 1094 | |
|---|
| 1095 | // ÃæºÐÈ÷ ±â´Ù·È°Ç¸¸, Self Delete°¡ µÇÁö ¾Ê¾ÒÀ» °æ¿ì¿¡´Â °Á¦ Á¾·á½ÃŲ´Ù. |
|---|
| 1096 | // |
|---|
| 1097 | if (timer->nTaskId != 0) |
|---|
| 1098 | { |
|---|
| 1099 | printf( "!! timer shutdown timeout!\n"); |
|---|
| 1100 | #if 0 |
|---|
| 1101 | DHL_ASSERT(dhl_os_delete_task(timer->nTaskId) == DHL_OK, |
|---|
| 1102 | "!! timer task destroy failled.. \n"); |
|---|
| 1103 | #endif |
|---|
| 1104 | } |
|---|
| 1105 | |
|---|
| 1106 | #if 0 // remove. if command not works, something is wrong. |
|---|
| 1107 | // ¿ø·¡ Timer task¿¡¼ »èÁ¦ÇؾßÇÏ´Â °ÍµéÀÌ´Ù. |
|---|
| 1108 | |
|---|
| 1109 | if (timer->semAck) { |
|---|
| 1110 | OS_DeleteSemaphore(timer->semAck); |
|---|
| 1111 | timer->semAck = 0; |
|---|
| 1112 | } |
|---|
| 1113 | if (timer->mutexAck) { |
|---|
| 1114 | OS_DeleteSemaphore(timer->mutexAck); |
|---|
| 1115 | timer->mutexAck = 0; |
|---|
| 1116 | } |
|---|
| 1117 | #endif |
|---|
| 1118 | |
|---|
| 1119 | timer->nTaskId = 0; |
|---|
| 1120 | |
|---|
| 1121 | DHL_OS_Free((void**)&timer); |
|---|
| 1122 | |
|---|
| 1123 | } |
|---|
| 1124 | |
|---|
| 1125 | |
|---|
| 1126 | |
|---|
| 1127 | #if COMMENT |
|---|
| 1128 | ____HighLevel_API____(){} |
|---|
| 1129 | #endif |
|---|
| 1130 | |
|---|
| 1131 | |
|---|
| 1132 | DHL_TMHANDLE g_dhl_timer=NULL; |
|---|
| 1133 | |
|---|
| 1134 | |
|---|
| 1135 | DHL_RESULT DHL_SYS_TimerInit(void) |
|---|
| 1136 | { |
|---|
| 1137 | DHL_TIMER_INIT_PARAM* param; |
|---|
| 1138 | |
|---|
| 1139 | // dhl_timer_module_init(); |
|---|
| 1140 | param = (DHL_TIMER *) DHL_OS_Malloc(sizeof(DHL_TIMER_INIT_PARAM)); |
|---|
| 1141 | |
|---|
| 1142 | if (g_dhl_timer) |
|---|
| 1143 | return DHL_OK; // dhl timer already initialized. |
|---|
| 1144 | |
|---|
| 1145 | memset(param, 0, sizeof(DHL_TIMER_INIT_PARAM)); |
|---|
| 1146 | |
|---|
| 1147 | param->max_timer_entry = DHL_TIMER_MAX_ENTRY; |
|---|
| 1148 | param->name = "DHLTMR"; |
|---|
| 1149 | param->task_priority = DHL_TIMER_TASK_PRIO; |
|---|
| 1150 | param->stack_size = DHL_TIMER_TASK_STACK; |
|---|
| 1151 | param->use_mutex_lock = 0; // we should support ISR!! |
|---|
| 1152 | |
|---|
| 1153 | return DHL_TIMER_Initialize(param, &g_dhl_timer); |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | DHL_RESULT DHL_SYS_StartTimer(UINT32 nIdTimer, UINT32 nPeriodMs, |
|---|
| 1157 | DHL_TIMER_PROC func, UINT32 param, BOOL bOneShot) |
|---|
| 1158 | { |
|---|
| 1159 | return DHL_TIMER_Start(g_dhl_timer, nIdTimer, nPeriodMs, |
|---|
| 1160 | func, param, bOneShot); |
|---|
| 1161 | } |
|---|
| 1162 | |
|---|
| 1163 | DHL_RESULT DHL_SYS_KillTimer(UINT32 nIdTimer) |
|---|
| 1164 | { |
|---|
| 1165 | return DHL_TIMER_Stop(g_dhl_timer, nIdTimer); |
|---|
| 1166 | } |
|---|
| 1167 | |
|---|
| 1168 | void DHL_SYS_ShowTimer(void) |
|---|
| 1169 | { |
|---|
| 1170 | DHL_TIMER_Show(g_dhl_timer); |
|---|
| 1171 | } |
|---|
| 1172 | |
|---|
| 1173 | |
|---|
| 1174 | #if COMMENT |
|---|
| 1175 | ____Symbol____(){} |
|---|
| 1176 | #endif |
|---|
| 1177 | |
|---|
| 1178 | #if DHL_REGISTER_DEUBG_SYMBOLS |
|---|
| 1179 | static DHL_SymbolTable dhl_timer_symbol[] = |
|---|
| 1180 | { |
|---|
| 1181 | //---- functions |
|---|
| 1182 | //DHL_FNC_SYM_ENTRY(DHL_SYS_PrintTimer), |
|---|
| 1183 | //DHL_FNC_SYM_ENTRY(DHL_SYS_KillTimer), |
|---|
| 1184 | |
|---|
| 1185 | //---- variables |
|---|
| 1186 | //DHL_VAR_SYM_ENTRY(g_Trace_bDHLTimer), |
|---|
| 1187 | DHL_VAR_SYM_ENTRY(g_Trace_TimerHandle), |
|---|
| 1188 | |
|---|
| 1189 | }; |
|---|
| 1190 | #endif // DHL_REGISTER_DEBUG_SYMBOL |
|---|
| 1191 | |
|---|
| 1192 | |
|---|
| 1193 | |
|---|
| 1194 | #if COMMENT |
|---|
| 1195 | ____Init____(){} |
|---|
| 1196 | #endif |
|---|
| 1197 | |
|---|
| 1198 | void dhl_timer_module_init(void) |
|---|
| 1199 | { |
|---|
| 1200 | static BOOL s_module_init=FALSE; |
|---|
| 1201 | |
|---|
| 1202 | if (s_module_init) |
|---|
| 1203 | return; |
|---|
| 1204 | |
|---|
| 1205 | #if DHL_REGISTER_DEUBG_SYMBOLS |
|---|
| 1206 | DHL_DBG_RegisterSymbols(dhl_timer_symbol, DHL_NUMSYMBOLS(dhl_timer_symbol)); |
|---|
| 1207 | #endif |
|---|
| 1208 | |
|---|
| 1209 | s_module_init = TRUE; |
|---|
| 1210 | } |
|---|
| 1211 | |
|---|
| 1212 | /* end of file */ |
|---|
| 1213 | |
|---|