ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
Loading...
Searching...
No Matches
neorv32_asc_gpio.c
Go to the documentation of this file.
1/** \file
2 *
3 * \brief Test that ASC can communicate with GPIOs
4 *
5 * Register map is documented at \ref register_map
6 *
7 */
8
9#include <stdbool.h>
10
11#include <neorv32.h>
12
13#include "asc_exception.h"
14#include "ascii_serial_com.h"
17#include "circular_buffer.h"
18#include "millisec_timer.h"
19
20#ifndef NEORV32
21#error ERROR: NEORV32 preprocessor macro is not defined!
22#endif
23
24// Lower 16 bits of GPIO.OUTPUT_LO are writable to the leds
25// GPIO.INPUT_HI is readable for the switches (bits 15 down to 1)
26
27#define BAUD_RATE 19200
28#define UART1_TX_BUFFER_FULL \
29 ((NEORV32_UART1.CTRL & (1 << UART_CTRL_TX_FULL)) != 0)
30
31CEXCEPTION_T e;
32uint16_t nExceptions;
33
34#define nRegs 4
35
36/** \brief Register Map
37 *
38 * ## Register Map
39 *
40 * |Register Number | Description | r/w |
41 * | -------------- |------------ | --- |
42 * | 0 | GPIO output (lower 32 bits) | r/w |
43 * | 1 | GPIO output (upper 32 bits) | r/w |
44 * | 2 | GPIO input (lower 32 bits) | r |
45 * | 3 | GPIO input (upper 32 bits) | r |
46 *
47 * @see register_write_masks
48 *
49 */
50volatile REGTYPE *register_map[nRegs] = {
51 &NEORV32_GPIO.OUTPUT_LO,
52 &NEORV32_GPIO.OUTPUT_HI,
53 &NEORV32_GPIO.INPUT_LO,
54 &NEORV32_GPIO.INPUT_HI,
55};
56
57/** \brief Write masks for \ref register_map
58 *
59 * These define whether the given register in register_map is writable or not
60 *
61 */
62REGTYPE register_write_masks[nRegs] = {
63 0xFFFFFFFF,
64 0xFFFFFFFF,
65 0,
66 0,
67};
68
70
71uint8_t tmp_byte;
72int rx_status;
73
74int main() {
75
76 neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
77
78 if (neorv32_uart1_available() == 0) {
79 neorv32_uart0_print("Error! UART1 not synthesized!\n");
80 return 1;
81 }
82
83 if (neorv32_gpio_available() == 0) {
84 neorv32_uart0_print("Error! GPIO not synthesized!\n");
85 return 1;
86 }
87
88 // capture all exceptions and give debug info via UART
89 // this is not required, but keeps us safe
90 neorv32_rte_setup();
91
92 neorv32_uart0_print("Starting UART1 loopback demo program\n");
93
94 Try {
95 neorv32_uart1_setup(9600, PARITY_NONE, FLOW_CONTROL_NONE);
96
98 nRegs);
99 }
100 Catch(e) { return e; }
101
102 while (1) {
103 Try {
105 // Receive bytes into extraInputBuffer
106 rx_status = neorv32_uart1_getc_safe((char *)&tmp_byte);
107 if (rx_status == 0) { // successfully rx a char
108 circular_buffer_push_back_uint8(&extraInputBuffer, tmp_byte);
109 }
110 }
111 Catch(e) {
112 nExceptions++;
113 neorv32_uart0_printf("Found: %d exceptions\n", nExceptions);
114 }
115 }
116
117 return 0;
118}
#define HANDLE_ASC_COMM_IN_POLLING_LOOP(uart_no)
Polling for ascii_serial_com_device and ascii_serial_com_register_pointers.
#define DECLARE_ASC_DEVICE_W_REGISTER_POINTERS()
Declarations for ascii_serial_com_device and ascii_serial_com_register_pointers.
#define SETUP_ASC_DEVICE_W_REGISTER_POINTERS(register_map, register_write_masks, nRegs)
Setup for ascii_serial_com_device and ascii_serial_com_register_pointers.
ASCII Serial Com Device.
ASCII Serial Com Register Pointers.
void circular_buffer_push_back_uint8(circular_buffer_uint8 *circ_buf, const uint8_t element)
circular buffer push back
Portable millisecond timer.
REGTYPE register_write_masks[nRegs]
Write masks for register_map.
volatile REGTYPE * register_map[nRegs]
Register Map.