nvboard: change the condition of calling uart->check_tx()
* this can reduce the number of memory access
This commit is contained in:
parent
aedd663a5e
commit
54fe35b910
|
@ -9,7 +9,6 @@ private:
|
|||
Term *term;
|
||||
int state;
|
||||
uint16_t divisor;
|
||||
uint16_t divisor_cnt;
|
||||
uint8_t data;
|
||||
bool need_update_gui;
|
||||
uint8_t *p_tx;
|
||||
|
|
|
@ -38,9 +38,8 @@ void nvboard_update() {
|
|||
if (!is_kb_idle) kb->update_state();
|
||||
|
||||
extern UART* uart;
|
||||
extern bool is_uart_idle;
|
||||
extern uint8_t *uart_tx_ptr;
|
||||
if (!(is_uart_idle && *uart_tx_ptr)) uart->check_tx();
|
||||
extern int16_t uart_divisor_cnt;
|
||||
if ((-- uart_divisor_cnt) < 0) uart->check_tx();
|
||||
|
||||
static uint64_t last = 0;
|
||||
static int cpf = 1; // count per frame
|
||||
|
|
14
src/uart.cpp
14
src/uart.cpp
|
@ -2,17 +2,16 @@
|
|||
#include <uart.h>
|
||||
|
||||
UART* uart = NULL;
|
||||
bool is_uart_idle = true;
|
||||
uint8_t *uart_tx_ptr = NULL;
|
||||
int16_t uart_divisor_cnt = 0;
|
||||
|
||||
UART::UART(SDL_Renderer *rend, int cnt, int init_val, int ct, int x, int y, int w, int h):
|
||||
Component(rend, cnt, init_val, ct),
|
||||
state(0), divisor(16), need_update_gui(false) {
|
||||
term = new Term(rend, x, y, w, h);
|
||||
divisor_cnt = divisor - 1;
|
||||
uart_divisor_cnt = divisor - 1;
|
||||
int len = pin_array[UART_TX].vector_len;
|
||||
assert(len == 0 || len == 1); // either unbound or bound to 1 bit signal
|
||||
uart_tx_ptr = (uint8_t *)pin_array[UART_TX].ptr;
|
||||
p_tx = (uint8_t *)pin_array[UART_TX].ptr;
|
||||
}
|
||||
|
||||
UART::~UART() {
|
||||
|
@ -24,14 +23,12 @@ void UART::update_gui() {
|
|||
}
|
||||
|
||||
void UART::check_tx() {
|
||||
if (divisor_cnt > 0) { divisor_cnt --; return; }
|
||||
divisor_cnt = divisor - 1;
|
||||
uart_divisor_cnt = divisor - 1;
|
||||
|
||||
uint8_t tx = *uart_tx_ptr;
|
||||
uint8_t tx = *p_tx;
|
||||
if (state == 0) { // idle
|
||||
if (!tx) { // start bit
|
||||
data = 0;
|
||||
is_uart_idle = false;
|
||||
state ++;
|
||||
}
|
||||
} else if (state >= 1 && state <= 8) { // data
|
||||
|
@ -41,7 +38,6 @@ void UART::check_tx() {
|
|||
if (tx) {
|
||||
term->feed_ch(data);
|
||||
state = 0;
|
||||
is_uart_idle = true;
|
||||
need_update_gui = true;
|
||||
} // stop bit
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue