Skip to content

Commit 51d0bb5

Browse files
committed
111.949MHz/1A7A: UART FIFO working
The UART FIFO is now working. This requires some changes to the UART driver, and also how the PS/2 Keyboard interface works. It also has introduced some difficulties in the simulator, the simulator now needs to peek at the input stream in order to simulate the PS/2 and UART input correctly, which is fine for the GUI application, but not so for the CLI application. I may change how the FIFO works again so it is easier to simulate. The problem is whether we read a character first and then trigger a read enabled, or whether we do a read enable then read a character.
1 parent 701558b commit 51d0bb5

File tree

11 files changed

+155
-134
lines changed

11 files changed

+155
-134
lines changed

embed.fth

+8-2
Original file line numberDiff line numberDiff line change
@@ -832,11 +832,17 @@ h: (irq)
832832
ien! ;
833833
[t] (irq) 2/ $C t!
834834
: irq $0040 $4010 ! [-1] timer! 1 ien! ;
835+
836+
\ FIFO: Write Read Enable after Read
835837
h: uart? ( uart-register -- c -1 | 0 : generic UART input functions )
836-
dup @ $0100 and if drop 0x0000 exit then dup $0400 swap ! @ $FF and [-1] ;
838+
dup @ $0100 and if drop 0x0000 exit then dup @ $FF and swap $0400 swap! [-1] ;
839+
\ FIFO: Write Read Enable before Read
840+
\ h: uart? ( uart-register -- c -1 | 0 : generic UART input functions )
841+
\ dup @ $0100 and if drop 0x0000 exit then dup $0400 swap! @ $FF and [-1] ;
842+
837843
: rx? $4000 uart? if [-1] exit then $4002 uart? ; ( -- c -1|0: rx uart/ps2 )
838844
h: uart! ( c uart-register -- )
839-
begin dup @ $1000 and 0= until swap $2000 or swap ! ;
845+
begin dup @ $1000 and 0= until swap $2000 or swap! ;
840846
: tx! dup $4002 uart! ( VGA/VT-100 ) $4000 uart! ( UART ) ;
841847
h: (ok) state@ if cr exit then ." ok" cr ; ( -- : default state aware prompt )
842848
h: preset tib-start #tib cell+ ! 0 in! id zero ; ( -- : reset input )

gui.c

+19-6
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,18 @@ static fifo_t *ps2_rx_fifo = NULL;
851851

852852
/* ====================================== H2 I/O Handling ====================================== */
853853

854-
static uint16_t h2_io_get_gui(const h2_soc_state_t * const soc, const uint16_t addr, bool *debug_on) {
854+
static void fifo_peek(fifo_t *f, fifo_data_t *data) {
855+
assert(f);
856+
assert(data);
857+
assert(sizeof(*data) == sizeof(uint8_t));
858+
*data = 0;
859+
if (fifo_is_empty(f))
860+
return;
861+
fifo_pop(f, data);
862+
fifo_push(f, *data);
863+
}
864+
865+
static uint16_t h2_io_get_gui(h2_soc_state_t * const soc, const uint16_t addr, bool *debug_on) {
855866
assert(soc);
856867
assert(ps2_rx_fifo);
857868
assert(uart_tx_fifo);
@@ -860,13 +871,16 @@ static uint16_t h2_io_get_gui(const h2_soc_state_t * const soc, const uint16_t a
860871
if (debug_on)
861872
*debug_on = false;
862873
switch (addr) {
863-
case iUart:
874+
case iUart: {
875+
fifo_peek(uart_rx_fifo, &soc->uart_getchar_register);
864876
return (fifo_is_empty(uart_tx_fifo) << UART_TX_FIFO_EMPTY_BIT)
865877
| (fifo_is_full(uart_tx_fifo) << UART_TX_FIFO_FULL_BIT)
866878
| (fifo_is_empty(uart_rx_fifo) << UART_RX_FIFO_EMPTY_BIT)
867879
| (fifo_is_full(uart_rx_fifo) << UART_RX_FIFO_FULL_BIT)
868880
| soc->uart_getchar_register;
881+
}
869882
case iVT100:
883+
fifo_peek(ps2_rx_fifo, &soc->ps2_getchar_register);
870884
return (1u << UART_TX_FIFO_EMPTY_BIT)
871885
| (0u << UART_TX_FIFO_FULL_BIT)
872886
| (fifo_is_empty(ps2_rx_fifo) << UART_RX_FIFO_EMPTY_BIT)
@@ -883,7 +897,6 @@ static uint16_t h2_io_get_gui(const h2_soc_state_t * const soc, const uint16_t a
883897
return 0;
884898
}
885899

886-
/**@warning uses variables of static storage duration! */
887900
static void h2_io_set_gui(h2_soc_state_t *soc, const uint16_t addr, const uint16_t value, bool *debug_on) {
888901
assert(soc);
889902
assert(uart_tx_fifo);
@@ -931,9 +944,9 @@ static void h2_io_set_gui(h2_soc_state_t *soc, const uint16_t addr, const uint16
931944
case oMemControl:
932945
{
933946
soc->mem_control = value;
934-
const bool sram_cs = soc->mem_control & SRAM_CHIP_SELECT;
935-
const bool oe = soc->mem_control & FLASH_MEMORY_OE;
936-
const bool we = soc->mem_control & FLASH_MEMORY_WE;
947+
const bool sram_cs = soc->mem_control & SRAM_CHIP_SELECT;
948+
const bool oe = soc->mem_control & FLASH_MEMORY_OE;
949+
const bool we = soc->mem_control & FLASH_MEMORY_WE;
937950
if (sram_cs && !oe && we)
938951
soc->vram[(((uint32_t)(soc->mem_control & FLASH_MASK_ADDR_UPPER_MASK) << 16) | soc->mem_addr_low) >> 1] = soc->mem_dout;
939952
break;

h2.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,9 @@ uint16_t h2_io_memory_read_operation(const h2_soc_state_t * const soc) {
15511551
return 0;
15521552
}
15531553

1554-
static uint16_t h2_io_get_default(const h2_soc_state_t * const soc, const uint16_t addr, bool *debug_on) {
1554+
/* TODO: Fix Input so Read then Read Enable FIFO semantics work
1555+
(this requires peeking at the input stream). */
1556+
static uint16_t h2_io_get_default(h2_soc_state_t * const soc, const uint16_t addr, bool *debug_on) {
15551557
assert(soc);
15561558
debug("IO read addr: %"PRIx16, addr);
15571559
(void)debug_on;

h2.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ typedef struct {
235235
uint16_t uart_tx_baud, uart_rx_baud, uart_control;
236236
} h2_soc_state_t;
237237

238-
typedef uint16_t (*h2_io_get)(const h2_soc_state_t *soc, uint16_t addr, bool *debug_on);
238+
typedef uint16_t (*h2_io_get)(h2_soc_state_t *soc, uint16_t addr, bool *debug_on);
239239
typedef void (*h2_io_set)(h2_soc_state_t *soc, uint16_t addr, uint16_t value, bool *debug_on);
240240
typedef void (*h2_io_update)(h2_soc_state_t *soc);
241241

kbd.vhd

-10
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ architecture rtl of keyboard is
104104
signal kbd_new_edge: std_ulogic := '0';
105105
signal kbd_new: std_ulogic := '0'; -- new ASCII char available
106106
signal kbd_char: std_ulogic_vector(kbd_char_buf'range) := (others => '0'); -- ASCII char
107-
signal kbd_char_o: std_ulogic_vector(kbd_char_buf'range) := (others => '0'); -- ASCII char
108107
begin
109108
kbd_char_buf_new <= kbd_new_c after g.delay;
110109

@@ -128,15 +127,6 @@ begin
128127
rst => rst,
129128
di => kbd_char,
130129
we => kbd_new_edge,
131-
do => kbd_char_o);
132-
133-
char_buf: entity work.reg
134-
generic map(g => g, N => kbd_char'length)
135-
port map(
136-
clk => clk,
137-
rst => rst,
138-
di => kbd_char_o,
139-
we => kbd_char_re,
140130
do => kbd_char_buf);
141131

142132
ps2_proc: process(kbd_new_edge, kbd_new_c, kbd_char_re)

t/ansi.fth

+72-72
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
\ RJH - ANSI TERMINAL TESTS / 2019. TESTED IN GFORTH
2-
\ Based around the definition for 'F' found here:
3-
\ https://www.forth.com/starting-forth/1-forth-stacks-dictionary/
4-
\
5-
\ This file is used to prepare test vectors for the VT-100 terminal emulator,
6-
\ a mini-language is make for drawing text and displaying colors.
7-
\
8-
ONLY FORTH DEFINITIONS DECIMAL
9-
10-
WORDLIST CONSTANT COOL-TEXT ( <_< - way cool )
11-
COOL-TEXT >ORDER DEFINITIONS
12-
VARIABLE COOL-CHARACTER CHAR * COOL-CHARACTER !
13-
: BYE BYE ;
14-
: CR $D EMIT $A EMIT ;
15-
: {{ CR COOL-TEXT >ORDER DUP ;
16-
: >_> CHAR COOL-CHARACTER ! ;
17-
: <_< [CHAR] * COOL-CHARACTER ! ;
18-
: \ POSTPONE \ ;
19-
: .( POSTPONE .( ;
20-
21-
: CSI $1B EMIT [CHAR] [ EMIT ;
22-
: 10U. BASE @ >R DECIMAL 0 <# #S #> TYPE R> BASE ! ;
23-
: ANSI SWAP CSI 10U. EMIT ; ( N C -- )
24-
: AT-XY CSI 10U. $3B EMIT 10U. [CHAR] H EMIT ;
25-
: PAGE 2 [CHAR] J ANSI 1 1 AT-XY ;
26-
: SGR [CHAR] m ANSI ;
27-
28-
: UP [CHAR] A ANSI ;
29-
: DOWN [CHAR] B ANSI ;
30-
: RIGHT [CHAR] C ANSI ;
31-
: LEFT [CHAR] D ANSI ;
32-
33-
0 CONSTANT BLACK 1 CONSTANT RED 2 CONSTANT GREEN 4 CONSTANT BLUE
34-
RED GREEN + CONSTANT YELLOW
35-
GREEN BLUE + CONSTANT CYAN
36-
RED BLUE + CONSTANT MAGENTA
37-
RED GREEN BLUE + + CONSTANT WHITE
38-
: BACKGROUND $A + ;
39-
: COLOR $1E + SGR ;
40-
41-
: BLINKY $5 SGR ;
42-
: UNBLINK $19 SGR ;
43-
: BOLD $1 SGR ;
44-
: NORMAL $16 SGR ;
45-
: REVERSE $7 SGR ;
46-
: ESREVER $1B SGR ;
47-
48-
: DOT COOL-CHARACTER @ EMIT ;
49-
: DOTS 0 DO DOT LOOP ;
50-
: BLIP 1 DOWN DUP RIGHT DOT DUP 2 * LEFT ;
51-
: BAR 1 DOWN DUP RIGHT 5 DOTS DUP 2 * LEFT ;
52-
: F BAR BLIP BAR BLIP BLIP DROP 5 UP ;
53-
: C BAR BLIP BLIP BLIP BAR DROP 5 UP ;
54-
: E DUP F C ;
55-
: I BLIP BLIP BLIP BLIP BLIP DROP 5 UP ;
56-
: O DUP C 4 + I ;
57-
: A DUP F 4 + I ;
58-
: _ 4 DOWN BAR DROP 5 UP ;
59-
: TOP BAR DROP 1 UP ;
60-
: U DUP I DUP _ 4 + I ;
61-
: J DUP _ 4 + I ;
62-
: L DUP I _ ;
63-
: W DUP L DUP 2 + I 4 + I ;
64-
: M DUP I DUP 2 + I DUP 4 + I TOP ;
65-
: - 2 DOWN BAR DROP 3 UP ;
66-
: H DUP I DUP - 4 + I ;
67-
: T DUP TOP 2 + I ;
68-
: D DUP I DROP ;
69-
70-
: | 7 + DUP ;
71-
: }} DROP 6 DOWN PREVIOUS ;
72-
SEAL
1+
\ RJH - ANSI TERMINAL TESTS / 2019. TESTED IN GFORTH
2+
\ Based around the definition for 'F' found here:
3+
\ https://www.forth.com/starting-forth/1-forth-stacks-dictionary/
4+
\
5+
\ This file is used to prepare test vectors for the VT-100 terminal emulator,
6+
\ a mini-language is make for drawing text and displaying colors.
7+
\
8+
ONLY FORTH DEFINITIONS DECIMAL
9+
10+
WORDLIST CONSTANT COOL-TEXT ( <_< - way cool )
11+
COOL-TEXT >ORDER DEFINITIONS
12+
VARIABLE COOL-CHARACTER CHAR * COOL-CHARACTER !
13+
: BYE BYE ;
14+
: CR $D EMIT $A EMIT ;
15+
: {{ CR COOL-TEXT >ORDER DUP ;
16+
: >_> CHAR COOL-CHARACTER ! ;
17+
: <_< [CHAR] * COOL-CHARACTER ! ;
18+
: \ POSTPONE \ ;
19+
: .( POSTPONE .( ;
20+
21+
: CSI $1B EMIT [CHAR] [ EMIT ;
22+
: 10U. BASE @ >R DECIMAL 0 <# #S #> TYPE R> BASE ! ;
23+
: ANSI SWAP CSI 10U. EMIT ; ( N C -- )
24+
: AT-XY CSI 10U. $3B EMIT 10U. [CHAR] H EMIT ;
25+
: PAGE 2 [CHAR] J ANSI 1 1 AT-XY ;
26+
: SGR [CHAR] m ANSI ;
27+
28+
: UP [CHAR] A ANSI ;
29+
: DOWN [CHAR] B ANSI ;
30+
: RIGHT [CHAR] C ANSI ;
31+
: LEFT [CHAR] D ANSI ;
32+
33+
0 CONSTANT BLACK 1 CONSTANT RED 2 CONSTANT GREEN 4 CONSTANT BLUE
34+
RED GREEN + CONSTANT YELLOW
35+
GREEN BLUE + CONSTANT CYAN
36+
RED BLUE + CONSTANT MAGENTA
37+
RED GREEN BLUE + + CONSTANT WHITE
38+
: BACKGROUND $A + ;
39+
: COLOR $1E + SGR ;
40+
41+
: BLINKY $5 SGR ;
42+
: UNBLINK $19 SGR ;
43+
: BOLD $1 SGR ;
44+
: NORMAL $16 SGR ;
45+
: REVERSE $7 SGR ;
46+
: ESREVER $1B SGR ;
47+
48+
: DOT COOL-CHARACTER @ EMIT ;
49+
: DOTS 0 DO DOT LOOP ;
50+
: BLIP 1 DOWN DUP RIGHT DOT DUP 2 * LEFT ;
51+
: BAR 1 DOWN DUP RIGHT 5 DOTS DUP 2 * LEFT ;
52+
: F BAR BLIP BAR BLIP BLIP DROP 5 UP ;
53+
: C BAR BLIP BLIP BLIP BAR DROP 5 UP ;
54+
: E DUP F C ;
55+
: I BLIP BLIP BLIP BLIP BLIP DROP 5 UP ;
56+
: O DUP C 4 + I ;
57+
: A DUP F 4 + I ;
58+
: _ 4 DOWN BAR DROP 5 UP ;
59+
: TOP BAR DROP 1 UP ;
60+
: U DUP I DUP _ 4 + I ;
61+
: J DUP _ 4 + I ;
62+
: L DUP I _ ;
63+
: W DUP L DUP 2 + I 4 + I ;
64+
: M DUP I DUP 2 + I DUP 4 + I TOP ;
65+
: - 2 DOWN BAR DROP 3 UP ;
66+
: H DUP I DUP - 4 + I ;
67+
: T DUP TOP 2 + I ;
68+
: D DUP I DROP ;
69+
70+
: | 7 + DUP ;
71+
: }} DROP 6 DOWN PREVIOUS ;
72+
SEAL

t/eforth.fth

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
\ Test setup code for eForth interpreter on the target
2+
echos
3+
4+
5+
system +order
26
: echos begin key emit switches until ;
37
echos

tb.vhd

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ architecture testing of tb is
3535
constant g: common_generics := (
3636
clock_frequency => 100_000_000,
3737
asynchronous_reset => true,
38-
delay => 0 ns
39-
);
38+
delay => 0 ns);
4039

4140
constant number_of_interrupts: positive := 8;
4241
constant uart_baud: positive := 115200;

top.vhd

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ begin
319319

320320
--- UART ----------------------------------------------------------
321321
uart_fifo_0: work.uart_pkg.uart_top
322-
generic map (g => g, baud => uart_baud, use_fifo => false)
322+
generic map (g => g, baud => uart_baud, use_fifo => true)
323323
port map (
324324
clk => clk,
325325
rst => rst,

0 commit comments

Comments
 (0)