|
| 1 | +#include <defs.h> |
| 2 | +#include <stub.h> |
| 3 | +#include <csr.h> |
| 4 | +#include "../include/slip.h" |
| 5 | +#include "../include/uart.h" |
| 6 | +#include "../include/gpio.h" |
| 7 | + |
| 8 | +#define ARRAY_SIZE 100 |
| 9 | + |
| 10 | +// -------------------------------------------------------- |
| 11 | +// Firmware routines |
| 12 | +// -------------------------------------------------------- |
| 13 | + |
| 14 | +/** @brief Configure the IO pins |
| 15 | + */ |
| 16 | +void configure_io() { |
| 17 | + // ======= Useful GPIO mode values ============= |
| 18 | + |
| 19 | + // GPIO_MODE_MGMT_STD_INPUT_NOPULL |
| 20 | + // GPIO_MODE_MGMT_STD_INPUT_PULLDOWN |
| 21 | + // GPIO_MODE_MGMT_STD_INPUT_PULLUP |
| 22 | + // GPIO_MODE_MGMT_STD_OUTPUT |
| 23 | + // GPIO_MODE_MGMT_STD_BIDIRECTIONAL |
| 24 | + // GPIO_MODE_MGMT_STD_ANALOG |
| 25 | + |
| 26 | + // GPIO_MODE_USER_STD_INPUT_NOPULL |
| 27 | + // GPIO_MODE_USER_STD_INPUT_PULLDOWN |
| 28 | + // GPIO_MODE_USER_STD_INPUT_PULLUP |
| 29 | + // GPIO_MODE_USER_STD_OUTPUT |
| 30 | + // GPIO_MODE_USER_STD_BIDIRECTIONAL |
| 31 | + // GPIO_MODE_USER_STD_ANALOG |
| 32 | + |
| 33 | + // ======= set each IO to the desired configuration ============= |
| 34 | + |
| 35 | + // GPIO 0 is turned off to prevent toggling the debug pin; For debug, make this an output and |
| 36 | + // drive it externally to ground. |
| 37 | + |
| 38 | + reg_mprj_io_0 = GPIO_MODE_MGMT_STD_ANALOG; |
| 39 | + |
| 40 | + // Changing configuration for IO[1-4] will interfere with programming flash. if you change them, |
| 41 | + // You may need to hold reset while powering up the board and initiating flash to keep the process |
| 42 | + // configuring these IO from their default values. |
| 43 | + |
| 44 | + // SPI |
| 45 | + reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 46 | + reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 47 | + reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 48 | + reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 49 | + |
| 50 | + // ------------------------------------------- |
| 51 | + |
| 52 | + reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // UART Rx |
| 53 | + reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT; // UART Tx |
| 54 | + reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // Used for reset |
| 55 | + reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 56 | + reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 57 | + reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 58 | + reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 59 | + reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 60 | + reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 61 | + reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 62 | + reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 63 | + reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 64 | + reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 65 | + reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 66 | + |
| 67 | + reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 68 | + reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 69 | + reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 70 | + reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 71 | + reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 72 | + reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 73 | + reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 74 | + reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 75 | + reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; |
| 76 | + reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 77 | + reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 78 | + reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT; // High |
| 79 | + reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT; // Low |
| 80 | + reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT; // High |
| 81 | + reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT; // Controlled by the code |
| 82 | + reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 83 | + reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 84 | + reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 85 | + reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT; |
| 86 | + |
| 87 | + // Initialize UART |
| 88 | + uart_init(); |
| 89 | + |
| 90 | + // Initiate the serial transfer to configure IO |
| 91 | + reg_mprj_xfer = 1; |
| 92 | + while (reg_mprj_xfer == 1) |
| 93 | + ; |
| 94 | +} |
| 95 | + |
| 96 | +/** @brief Delay in microseconds |
| 97 | + * |
| 98 | + * @param d Delay in microseconds. |
| 99 | + */ |
| 100 | +void delay(const int d) { |
| 101 | + /* Configure timer for a single-shot countdown */ |
| 102 | + reg_timer0_config = 0; |
| 103 | + reg_timer0_data = d; |
| 104 | + reg_timer0_config = 1; |
| 105 | + |
| 106 | + // Loop, waiting for value to reach zero |
| 107 | + reg_timer0_update = 1; // latch current value |
| 108 | + while (reg_timer0_value > 0) { reg_timer0_update = 1; } |
| 109 | +} |
| 110 | + |
| 111 | +/** @brief Turn off the LED |
| 112 | + */ |
| 113 | +void led_off() { reg_gpio_out = 1; } |
| 114 | + |
| 115 | +/** @brief Turn on the LED |
| 116 | + */ |
| 117 | +void led_on() { reg_gpio_out = 0; } |
| 118 | + |
| 119 | +/** @brief Entry point |
| 120 | + */ |
| 121 | +void main() { |
| 122 | + // Initialize GPIO |
| 123 | + reg_gpio_mode1 = 1; |
| 124 | + reg_gpio_mode0 = 0; |
| 125 | + reg_gpio_ien = 1; |
| 126 | + reg_gpio_oe = 1; |
| 127 | + |
| 128 | + // Configure IO pins including UART pins |
| 129 | + configure_io(); |
| 130 | + |
| 131 | + // Configure All LA probes as inputs to the cpu |
| 132 | + reg_la0_oenb = reg_la0_iena = 0x00000000; // [31:0] |
| 133 | + reg_la1_oenb = reg_la1_iena = 0x00000000; // [63:32] |
| 134 | + reg_la2_oenb = reg_la2_iena = 0x00000000; // [95:64] |
| 135 | + reg_la3_oenb = reg_la3_iena = 0x00000000; // [127:96] |
| 136 | + |
| 137 | + // write data to la output |
| 138 | + // reg_la0_data = 0x00; |
| 139 | + // reg_la1_data = 0x00; |
| 140 | + // reg_la2_data = 0x00; |
| 141 | + // reg_la3_data = 0x00; |
| 142 | + |
| 143 | + // read data from la input |
| 144 | + // data0 = reg_la0_data; |
| 145 | + // data1 = reg_la1_data; |
| 146 | + // data2 = reg_la2_data; |
| 147 | + // data3 = reg_la3_data; |
| 148 | + |
| 149 | + // Turn off all GPIO outputs |
| 150 | + reg_mprj_datah = 0x00000000; // Set all high pins (32-37) low |
| 151 | + reg_mprj_datal = 0x00000000; // Set all low pins (0-31) low |
| 152 | + |
| 153 | + // Define a static array of items initialized to zero |
| 154 | + static uint8_t zero_array[ARRAY_SIZE] = {0}; |
| 155 | + |
| 156 | + // Main loop - echo received characters and blink LED and |
| 157 | + while (true) { |
| 158 | + // Set all GPIO pins to high |
| 159 | + for (uint32_t i = 0; i <= 37; i++) { gpio_set(i); } |
| 160 | + |
| 161 | + // Wait for 1 second |
| 162 | + delay(10000000); |
| 163 | + } |
| 164 | +} |
0 commit comments