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
riscv
neorv32
neorv32_blink_led.c
Go to the documentation of this file.
1
// #################################################################################################
2
// # << NEORV32 - Blinking LED Demo Program >> # #
3
// *********************************************************************************************
4
// # # BSD 3-Clause License # # # # Copyright (c) 2021, Stephan Nolting. All
5
// rights reserved. # # # # Redistribution
6
// and use in source and binary forms, with or without modification, are # #
7
// permitted provided that the following conditions are met: # # # # 1.
8
// Redistributions of source code must retain the above copyright notice, this
9
// list of # # conditions and the following disclaimer. # # # # 2.
10
// Redistributions in binary form must reproduce the above copyright notice,
11
// this list of # # conditions and the following disclaimer in the
12
// documentation and/or other materials # # provided with the
13
// distribution. # #
14
// # # 3. Neither the name of the copyright holder nor the names of its
15
// contributors may be used to # # endorse or promote products derived from
16
// this software without specific prior written # # permission. # # # #
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
// AND ANY EXPRESS # # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
// THE IMPLIED WARRANTIES OF # # MERCHANTABILITY AND FITNESS FOR A
20
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # # COPYRIGHT
21
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
// SPECIAL, # # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
// LIMITED TO, PROCUREMENT OF SUBSTITUTE # # GOODS OR SERVICES; LOSS OF USE,
24
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED # # AND ON ANY
25
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
// (INCLUDING # # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
// OF THIS SOFTWARE, EVEN IF ADVISED # # OF THE POSSIBILITY OF SUCH DAMAGE. #
28
// #
29
// *********************************************************************************************
30
// # # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan
31
// Nolting #
32
// #################################################################################################
33
34
/**********************************************************************/
/**
35
* @file
36
*blink_led/main.c
37
* @author
38
*Stephan
39
*Nolting
40
* @brief
41
*Simple
42
*blinking
43
*LED
44
*demo
45
*program
46
*using
47
*the
48
*lowest
49
*8
50
*bits
51
*of
52
*the
53
*GPIO.output
54
*port.
55
**************************************************************************/
56
57
#include <neorv32.h>
58
59
/**********************************************************************/
/**
60
* @name
61
*User
62
*configuration
63
**************************************************************************/
64
/**@{*/
65
/** UART BAUD rate */
66
#define BAUD_RATE 19200
67
/**@}*/
68
69
/**********************************************************************/
/**
70
* C
71
*function
72
*to
73
*blink
74
*LEDs
75
**************************************************************************/
76
void
blink_led_c
(
void
);
77
78
/**********************************************************************/
/**
79
* Main
80
*function;
81
*shows
82
*an
83
*incrementing
84
*8-bit
85
*counter
86
*on
87
*GPIO.output(7:0).
88
*
89
* @note
90
*This
91
*program
92
*requires
93
*the
94
*GPIO
95
*controller
96
*to be
97
*synthesized
98
*(the
99
*UART
100
*is
101
*optional).
102
*
103
* @return
104
*0 if
105
*execution
106
*was
107
*successful
108
**************************************************************************/
109
int
main
() {
110
111
// init UART (primary UART = UART0; if no id number is specified the primary
112
// UART is used) at default baud rate, no parity bits, ho hw flow control
113
neorv32_uart0_setup(
BAUD_RATE
, PARITY_NONE, FLOW_CONTROL_NONE);
114
115
// check if GPIO unit is implemented at all
116
if
(neorv32_gpio_available() == 0) {
117
neorv32_uart0_print(
"Error! No GPIO unit synthesized!\n"
);
118
return
1;
// nope, no GPIO unit synthesized
119
}
120
121
// capture all exceptions and give debug info via UART
122
// this is not required, but keeps us safe
123
neorv32_rte_setup();
124
125
// say hello
126
neorv32_uart0_print(
"Blinking LED demo program\n"
);
127
128
blink_led_c
();
129
130
return
0;
131
}
132
133
/**********************************************************************/
/**
134
* C-version
135
*of
136
*blinky
137
*LED
138
*counter
139
**************************************************************************/
140
void
blink_led_c
(
void
) {
141
142
neorv32_gpio_port_set(0);
// clear gpio output
143
144
int
cnt = 0;
145
146
while
(1) {
147
neorv32_gpio_port_set(cnt++ &
148
0xFF);
// increment counter and mask for lowest 8 bit
149
neorv32_cpu_delay_ms(200);
// wait 200ms using busy wait
150
}
151
}
blink_led_c
void blink_led_c(void)
Definition
neorv32_blink_led.c:140
BAUD_RATE
#define BAUD_RATE
Definition
neorv32_blink_led.c:66
main
int main()
Definition
neorv32_blink_led.c:109
Generated by
1.10.0