uart: add dedicated FPS for TX
This commit is contained in:
parent
54fe35b910
commit
91b82e5687
|
@ -9,6 +9,7 @@
|
|||
#include <SDL_image.h>
|
||||
|
||||
void set_redraw();
|
||||
uint64_t nvboard_get_time();
|
||||
|
||||
void init_render(SDL_Renderer *renderer);
|
||||
SDL_Texture* load_pic_texture(SDL_Renderer *renderer, std::string path);
|
||||
|
|
|
@ -2,25 +2,10 @@
|
|||
#include <keyboard.h>
|
||||
#include <vga.h>
|
||||
#include <uart.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define FPS 60
|
||||
|
||||
static uint64_t boot_time = 0;
|
||||
|
||||
static uint64_t get_time_internal() {
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
uint64_t us = now.tv_sec * 1000000 + now.tv_usec;
|
||||
return us;
|
||||
}
|
||||
|
||||
static uint64_t get_time() {
|
||||
uint64_t now = get_time_internal();
|
||||
return now - boot_time;
|
||||
}
|
||||
|
||||
static SDL_Window *main_window = nullptr;
|
||||
static SDL_Renderer *main_renderer = nullptr;
|
||||
PinNode pin_array[NR_PINS];
|
||||
|
@ -45,7 +30,7 @@ void nvboard_update() {
|
|||
static int cpf = 1; // count per frame
|
||||
static int cnt = 0;
|
||||
if ((-- cnt) < 0) {
|
||||
uint64_t now = get_time();
|
||||
uint64_t now = nvboard_get_time();
|
||||
uint64_t diff = now - last;
|
||||
int cpf_new = ((uint64_t)cpf * 1000000) / ((uint64_t)diff * FPS); // adjust cpf
|
||||
cnt += cpf_new - cpf;
|
||||
|
@ -95,9 +80,11 @@ void nvboard_init(int vga_clk_cycle) {
|
|||
init_components(main_renderer);
|
||||
init_gui(main_renderer);
|
||||
|
||||
void init_nvboard_timer();
|
||||
init_nvboard_timer();
|
||||
|
||||
update_components(main_renderer);
|
||||
|
||||
boot_time = get_time_internal();
|
||||
extern void vga_set_clk_cycle(int cycle);
|
||||
vga_set_clk_cycle(vga_clk_cycle);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#include <nvboard.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static uint64_t boot_time = 0;
|
||||
|
||||
static uint64_t get_time_internal() {
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
uint64_t us = now.tv_sec * 1000000 + now.tv_usec;
|
||||
return us;
|
||||
}
|
||||
|
||||
uint64_t nvboard_get_time() {
|
||||
uint64_t now = get_time_internal();
|
||||
return now - boot_time;
|
||||
}
|
||||
|
||||
void init_nvboard_timer() {
|
||||
boot_time = get_time_internal();
|
||||
}
|
12
src/uart.cpp
12
src/uart.cpp
|
@ -1,6 +1,9 @@
|
|||
#include <nvboard.h>
|
||||
#include <uart.h>
|
||||
|
||||
// There is no need to update TX too frequently
|
||||
#define UART_TX_FPS 5
|
||||
|
||||
UART* uart = NULL;
|
||||
int16_t uart_divisor_cnt = 0;
|
||||
|
||||
|
@ -45,8 +48,13 @@ void UART::check_tx() {
|
|||
|
||||
void UART::update_state() {
|
||||
if (need_update_gui) {
|
||||
need_update_gui = false;
|
||||
update_gui();
|
||||
static uint64_t last = 0;
|
||||
uint64_t now = nvboard_get_time();
|
||||
if (now - last > 1000000 / UART_TX_FPS) {
|
||||
last = now;
|
||||
need_update_gui = false;
|
||||
update_gui();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue