| 375 | } |
| 376 | |
| 377 | uc_err start_timer(uc_engine *uc, uint32_t id) { |
| 378 | struct TimerState* timers = &uc->fw->timers; |
| 379 | if(id >= MAX_TIMERS) { |
| 380 | perror("[TIMER ERROR] start_timer: Too high id passed\n"); |
| 381 | exit(-1); |
| 382 | } else if(!timers->timers[id].in_use) { |
| 383 | perror("[TIMER ERROR] start_timer: Unused timer to be started\n"); |
| 384 | exit(-1); |
| 385 | } else if(timers->timers[id].reload_val == 0) { |
| 386 | perror("[TIMER ERROR] start_timer: Invalid reload value 0\n"); |
| 387 | exit(-1); |
| 388 | } else if(timers->timers[id].reload_val > MAX_RELOAD_VAL) { |
| 389 | perror("[TIMER ERROR] start_timer: Invalid, too large reload value\n"); |
| 390 | exit(-1); |
| 391 | } |
| 392 | |
| 393 | #ifdef DEBUG_TIMER |
| 394 | printf("[TIMER] start_timer(%d)\n", id); |
| 395 | puts("======= Timer state PRE ======= "); |
| 396 | print_timer_state(); |
| 397 | fflush(stdout); |
| 398 | #endif |
| 399 | |
| 400 | struct Timer *tim = &timers->timers[id]; |
| 401 | if (!tim->is_active) { |
| 402 | tim->is_active = 1; |
| 403 | |
| 404 | insert_active_timer(uc, tim); |
| 405 | } |
| 406 | |
| 407 | #ifdef DEBUG_TIMER |
| 408 | puts("======= Timer state POST ======= "); |
| 409 | print_timer_state(); |
| 410 | fflush(stdout); |
| 411 | #endif |
| 412 | |
| 413 | return UC_ERR_OK; |
| 414 | } |
| 415 | |
| 416 | uc_err stop_timer(uc_engine *uc, uint32_t id) { |
| 417 | struct TimerState* timers = &uc->fw->timers; |
no test coverage detected