|
@@ -5,6 +5,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -29,11 +32,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -113,6 +121,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -132,6 +144,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -205,6 +220,10 @@ asm(" .section .version\n"
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+#ifndef UART
|
|
|
|
+#define UART 0
|
|
|
|
+#endif
|
|
|
|
+
|
|
#if 0
|
|
#if 0
|
|
|
|
|
|
|
|
|
|
@@ -310,6 +329,37 @@ void appStart() __attribute__ ((naked));
|
|
#define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
|
|
#define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * Handle devices with up to 4 uarts (eg m1280.) Rather inelegantly.
|
|
|
|
+ * Note that mega8 still needs special handling, because ubrr is handled
|
|
|
|
+ * differently.
|
|
|
|
+ */
|
|
|
|
+#if UART == 0
|
|
|
|
+# define UART_SRA UCSR0A
|
|
|
|
+# define UART_SRB UCSR0B
|
|
|
|
+# define UART_SRC UCSR0C
|
|
|
|
+# define UART_SRL UBRR0L
|
|
|
|
+# define UART_UDR UDR0
|
|
|
|
+#elif UART == 1
|
|
|
|
+# define UART_SRA UCSR1A
|
|
|
|
+# define UART_SRB UCSR1B
|
|
|
|
+# define UART_SRC UCSR1C
|
|
|
|
+# define UART_SRL UBRR1L
|
|
|
|
+# define UART_UDR UDR1
|
|
|
|
+#elif UART == 2
|
|
|
|
+# define UART_SRA UCSR2A
|
|
|
|
+# define UART_SRB UCSR2B
|
|
|
|
+# define UART_SRC UCSR2C
|
|
|
|
+# define UART_SRL UBRR2L
|
|
|
|
+# define UART_UDR UDR2
|
|
|
|
+#elif UART == 3
|
|
|
|
+# define UART_SRA UCSR3A
|
|
|
|
+# define UART_SRB UCSR3B
|
|
|
|
+# define UART_SRC UCSR3C
|
|
|
|
+# define UART_SRL UBRR3L
|
|
|
|
+# define UART_UDR UDR3
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
|
|
int main(void) {
|
|
int main(void) {
|
|
uint8_t ch;
|
|
uint8_t ch;
|
|
@@ -353,10 +403,10 @@ int main(void) {
|
|
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);
|
|
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);
|
|
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
|
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
|
#else
|
|
#else
|
|
- UCSR0A = _BV(U2X0);
|
|
+ UART_SRA = _BV(U2X0);
|
|
- UCSR0B = _BV(RXEN0) | _BV(TXEN0);
|
|
+ UART_SRB = _BV(RXEN0) | _BV(TXEN0);
|
|
- UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
|
|
+ UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
|
|
- UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
|
+ UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -556,8 +606,8 @@ int main(void) {
|
|
|
|
|
|
void putch(char ch) {
|
|
void putch(char ch) {
|
|
#ifndef SOFT_UART
|
|
#ifndef SOFT_UART
|
|
- while (!(UCSR0A & _BV(UDRE0)));
|
|
+ while (!(UART_SRA & _BV(UDRE0)));
|
|
- UDR0 = ch;
|
|
+ UART_UDR = ch;
|
|
#else
|
|
#else
|
|
__asm__ __volatile__ (
|
|
__asm__ __volatile__ (
|
|
" com %[ch]\n"
|
|
" com %[ch]\n"
|
|
@@ -620,9 +670,9 @@ uint8_t getch(void) {
|
|
"r25"
|
|
"r25"
|
|
);
|
|
);
|
|
#else
|
|
#else
|
|
- while(!(UCSR0A & _BV(RXC0)))
|
|
+ while(!(UART_SRA & _BV(RXC0)))
|
|
;
|
|
;
|
|
- if (!(UCSR0A & _BV(FE0))) {
|
|
+ if (!(UART_SRA & _BV(FE0))) {
|
|
|
|
|
|
* A Framing Error indicates (probably) that something is talking
|
|
* A Framing Error indicates (probably) that something is talking
|
|
* to us at the wrong bit rate. Assume that this is because it
|
|
* to us at the wrong bit rate. Assume that this is because it
|
|
@@ -634,7 +684,7 @@ uint8_t getch(void) {
|
|
watchdogReset();
|
|
watchdogReset();
|
|
}
|
|
}
|
|
|
|
|
|
- ch = UDR0;
|
|
+ ch = UART_UDR;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef LED_DATA_FLASH
|
|
#ifdef LED_DATA_FLASH
|