-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
90 lines (73 loc) · 2.77 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
MIT License
Copyright (c) 2020 - 2022 notweerdmonk
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* @file main.c
* @brief Driver program which demonstrates the use of AVR software UART.
* @author notweerdmonk
*/
#include <uart.h>
#include <defines.h>
#define TRIGGER_DDR DDRB
#define TRIGGER_PORT PORTB
#define TRIGGER_PIN PB4
#define EMIT_TRIGGER
#if defined SIMULATION
#define STRINGIFY(s) #s
#define MCU_NAME(m) STRINGIFY(m)
#define VCD_FILE(m) STRINGIFY(./simulation/)STRINGIFY(m)STRINGIFY(_uart_trace.vcd)
#include </usr/include/simavr/avr/avr_mcu_section.h>
AVR_MCU(16000000, MCU_NAME(DEVICE_NAME));
AVR_MCU_VCD_FILE(VCD_FILE(DEVICE_NAME), 1000);
const struct avr_mmcu_vcd_trace_t _trace[] _MMCU_ = {
{ AVR_MCU_VCD_SYMBOL("TxD"), .mask = (1 << TX_PIN), .what = (void*)&TX_PORT, },
{ AVR_MCU_VCD_SYMBOL("RxD"), .mask = (1 << RX_PIN), .what = (void*)&RX_PORT, },
{ AVR_MCU_VCD_SYMBOL("Trigger"), .mask = (1 << TRIGGER_PIN), .what = (void*)&TRIGGER_PORT, },
};
#endif
char *pattern1 = "UUUU";
char *pattern2 = "AAAAAAAAAAAAAAAA";
char *pattern3 = "aaaaaaaaaaaaaaaa";
char *pattern4 = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
char *teststring = pattern4;
setup_uart(0);
sei();
#if defined EMIT_TRIGGER
/* wait a while */
asm volatile ("ldi r24, 255 \n\t"
"loop1: \n\t"
"ldi r25, 50 \n\t"
"loop2: \n\t"
"dec r25 \n\t"
"brne loop2 \n\t"
"dec r24 \n\t"
"brne loop1 \n\t"
:
:
);
TRIGGER_DDR |= (1 << TRIGGER_PIN);
TRIGGER_PORT |= (1 << TRIGGER_PIN);
#endif
send_str(teststring);
send('\n'); send('\r');
/* loopback */
for(;;send(recv()));
return 0;
}