| 258 | } |
| 259 | |
| 260 | uc_err set_timer_reload_val(uc_engine *uc, uint32_t id, uint64_t reload_val) { |
| 261 | struct TimerState* timers = &uc->fw->timers; |
| 262 | #ifdef DEBUG_TIMER |
| 263 | printf("[TIMER] set_timer_reload_val(id = %d, reload_val=%ld)\n", id, reload_val); fflush(stdout); |
| 264 | #endif |
| 265 | |
| 266 | if(id >= MAX_TIMERS) { |
| 267 | perror("[TIMER ERROR] set_timer_reload_val: Too high id passed\n"); |
| 268 | exit(-1); |
| 269 | } |
| 270 | |
| 271 | if(reload_val == 0) { |
| 272 | reload_val = MAX_RELOAD_VAL; |
| 273 | } |
| 274 | |
| 275 | struct Timer *tim = &timers->timers[id]; |
| 276 | if(tim->reload_val == reload_val) { |
| 277 | return UC_ERR_OK; |
| 278 | } |
| 279 | |
| 280 | if (tim->is_active) { |
| 281 | // For active timers, we remove and re-insert to maintain fast-path sorting logic |
| 282 | remove_active_timer(uc, tim); |
| 283 | tim->reload_val = reload_val; |
| 284 | tim->ticker_val = reload_val; |
| 285 | insert_active_timer(uc, tim); |
| 286 | } else { |
| 287 | tim->reload_val = reload_val; |
| 288 | tim->ticker_val = reload_val; |
| 289 | } |
| 290 | |
| 291 | return UC_ERR_OK; |
| 292 | } |
| 293 | |
| 294 | uint32_t get_timer_scale(struct FwContext* fw) { |
| 295 | return fw->config.timer_scale; |
no test coverage detected