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_pulse_counter.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 6
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 * | 4 | Pulse counter count | r |
47 * | 5 | Pulse counter CSR* | r/w |
48 *
49 * Pulse counter CSR:
50 *
51 * Bit 0: enable
52 * Bit 1: reset
53 *
54 * @see register_write_masks
55 *
56 */
57volatile REGTYPE *register_map[nRegs] = {
58 &NEORV32_GPIO.OUTPUT_LO,
59 &NEORV32_GPIO.OUTPUT_HI,
60 &NEORV32_GPIO.INPUT_LO,
61 &NEORV32_GPIO.INPUT_HI,
62 0x71000000,
63 0x71000004,
64};
65
66/** \brief Write masks for \ref register_map
67 *
68 * These define whether the given register in register_map is writable or not
69 *
70 */
71REGTYPE register_write_masks[nRegs] = {
72 0xFFFFFFFF, 0xFFFFFFFF, 0, 0, 0, 0x3,
73};
74
76
77uint8_t tmp_byte;
78int rx_status;
79
80int main() {
81
82 neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
83
84 if (neorv32_uart1_available() == 0) {
85 neorv32_uart0_print("Error! UART1 not synthesized!\n");
86 return 1;
87 }
88
89 if (neorv32_gpio_available() == 0) {
90 neorv32_uart0_print("Error! GPIO not synthesized!\n");
91 return 1;
92 }
93
94 // capture all exceptions and give debug info via UART
95 // this is not required, but keeps us safe
96 neorv32_rte_setup();
97
98 neorv32_uart0_print("Starting ASCII-Serial-Com WB Pulse Counter Program\n");
99
100 Try {
101 neorv32_uart1_setup(9600, PARITY_NONE, FLOW_CONTROL_NONE);
102
104 nRegs);
105 }
106 Catch(e) { return e; }
107
108 while (1) {
109 Try {
111 // Receive bytes into extraInputBuffer
112 rx_status = neorv32_uart1_getc_safe((char *)&tmp_byte);
113 if (rx_status == 0) { // successfully rx a char
114 circular_buffer_push_back_uint8(&extraInputBuffer, tmp_byte);
115 }
116 }
117 Catch(e) {
118 nExceptions++;
119 neorv32_uart0_printf("Found: %d exceptions\n", nExceptions);
120 }
121 }
122
123 return 0;
124}
#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.