diff --git a/PSE-firmware b/PSE-firmware index d087767..bf08fc6 160000 --- a/PSE-firmware +++ b/PSE-firmware @@ -1 +1 @@ -Subproject commit d0877672a3653eeed5fe7b65185ec45d93943f26 +Subproject commit bf08fc69ff21c28482ade1eca086867e619b7fea diff --git a/main.c b/main.c index aa9d9de..e61d4bf 100644 --- a/main.c +++ b/main.c @@ -79,7 +79,7 @@ int main(int argc, char** argv){ exit(-1); } - window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, LCD_WIDTH, LCD_HEIGHT, SDL_WINDOW_SHOWN ); + window = SDL_CreateWindow("PSE emulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, LCD_WIDTH, LCD_HEIGHT, SDL_WINDOW_SHOWN ); if(window == NULL){ printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); } diff --git a/stm32f1xx_hal.c b/stm32f1xx_hal.c index 342fb11..683c76e 100644 --- a/stm32f1xx_hal.c +++ b/stm32f1xx_hal.c @@ -35,19 +35,23 @@ static void* tim_handler(void* arg){ struct timespec start, current; clock_gettime(CLOCK_MONOTONIC, &start); - while(htim->started){ - uint64_t delay_ps = (uint64_t) 15625 * (htim->presc+1) * (htim->period+1); - printf("delay : %lu\n", delay_ps); + uint64_t delay_ps = (uint64_t) 15625 * (htim->presc+1) * (htim->period+1); + int exec_counter = 0; + + while(htim->started){ clock_gettime(CLOCK_MONOTONIC, ¤t); uint64_t time = (uint64_t) 1000000000 * (current.tv_sec - start.tv_sec) + (current.tv_nsec - start.tv_nsec); - if(delay_ps / 1000 > time) - usleep((delay_ps / 1000 - time) / 1000); - else printf("oups"); - - clock_gettime(CLOCK_MONOTONIC, &start); - - HAL_TIM_PeriodElapsedCallback(htim); + + unsigned int nb_exec = time * 1000 / delay_ps; + int backlog = nb_exec - exec_counter; + while(backlog > 0){ + if(backlog > 10) + printf("timer simulation lagging behind (%d ticks)\n", backlog); + HAL_TIM_PeriodElapsedCallback(htim); + exec_counter++; + backlog = nb_exec - exec_counter; + } } return NULL; }