Appendix A. Full Modules and Proof

Greeter Module

This is the full greeter module greeting someone over the USB port. Referenced from “Getting Personal with RAM”:

 module greeter ( input clk, // clock input rst, // reset input new_rx, // new RX flag input rx_data[8], // RX data output new_tx, // new TX flag output tx_data[8], // TX data input tx_busy // TX is busy flag ) { // reverse so index 0 is the left most letter const HELLO_TEXT = $reverse("\r\nHello @!\r\n"); const PROMPT_TEXT = $reverse("Please type your name: "); .clk(clk) { .rst(rst) { fsm state = {IDLE, PROMPT, LISTEN, HELLO}; // our state machine } // we need our counters to be large enough to store all the indices of our // text // HELLO_TEXT is 2D so WIDTH[0] gets the first dimension dff hello_count[$clog2(HELLO_TEXT.WIDTH[0])]; dff prompt_count[$clog2(PROMPT_TEXT.WIDTH[0])]; dff name_count[5]; // 5 allows for 2^5 = 32 letters // we need our RAM to have an entry for every value of name_count simple_ram ram (#SIZE(8), #DEPTH($pow(2,name_count.WIDTH))); } always { ram.address = name_count.q; // use name_count as the address ram.write_data = 8hxx; // don't care ram.write_en = 0; // read by default new_tx = 0; // default to no new data tx_data = 8hxx; // don't care case (state.q) { // our FSM // IDLE: Reset everything and wait for a new byte. state.IDLE: hello_count.d = 0; prompt_count.d = 0; name_count.d = 0; if (new_rx) // wait for any letter state.d = state.PROMPT; // PROMPT: Print out name prompt. state.PROMPT: ...

Get Learning FPGAs now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.