From: SourceForge.net <no...@so...> - 2012-09-06 07:57:53
|
Bugs item #3565231, was opened at 2012-09-06 00:57 Message generated for change (Tracker Item Submitted) made by msbroadf You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=3565231&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: common target code generation Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: michael (msbroadf) Assigned to: Nobody/Anonymous (nobody) Summary: Passing in uint32_t and multiplying doesnt work Initial Comment: Code (does not work): ------ volatile uint32_t currentAlarm = 0xFFFFFFFF; volatile uint8_t ticksPerMs; void schedulerInit() { ticksPerMs = rtcFrequency / 1000.0; } int16_t schedulerAddTask(void(*task)(), uint32_t periodMs) __critical { uint8_t i; int16_t id = -1; __bit added = FALSE; uint32_t alarm = currentAlarm; uint32_t currentTime; currentTime = rtcGetCurrentTime(); for (i = 0; i < MAX_TASKS; i++) { if (!added && !tasks[i].task) { tasks[i].alarm = currentTime + (periodMs * ticksPerMs); tasks[i].task = task; id = i; printf("ADDED=%lu, %lu, %u, %lu\r\n", currentTime, periodMs, ticksPerMs, tasks[i].alarm); added = TRUE; } if (tasks[i].task && tasks[i].alarm < alarm) alarm = tasks[i].alarm; } if (added && alarm != currentAlarm) { currentAlarm = alarm; rtcWriteAlarm(currentAlarm); } return id; } Output: -------- ADDED=45, 2000, 20, 20045 ADDED=20048, 2000, 20, 40048 Code: (works, after changing periodMs to float from uint32_t) ------------- volatile uint32_t currentAlarm = 0xFFFFFFFF; volatile uint8_t ticksPerMs; void schedulerInit() { ticksPerMs = rtcFrequency / 1000.0; } /** * Add a task to be processed * * Returns the task id or -1 if the task manager cannot handle any more simultaneous tasks */ int16_t schedulerAddTask(void(*task)(), float periodMs) __critical { uint8_t i; int16_t id = -1; __bit added = FALSE; uint32_t alarm = currentAlarm; uint32_t currentTime; currentTime = rtcGetCurrentTime(); for (i = 0; i < MAX_TASKS; i++) { if (!added && !tasks[i].task) { tasks[i].alarm = currentTime + (periodMs * ticksPerMs); tasks[i].task = task; id = i; printf("ADDED=%lu, %lu, %u, %lu\r\n", currentTime, (uint32_t)periodMs, ticksPerMs, tasks[i].alarm); added = TRUE; } if (tasks[i].task && tasks[i].alarm < alarm) alarm = tasks[i].alarm; } if (added && alarm != currentAlarm) { currentAlarm = alarm; rtcWriteAlarm(currentAlarm); } return id; } Output: ADDED=45, 2000, 20, 40045 ADDED=40048, 2000, 20, 80048 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=3565231&group_id=599 |