amiga_boottest
annotate src/serial.c @ 4:995d42b33974
serial output
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 23 Feb 2018 13:29:37 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@4 | 1 #include "hwregs.h" |
nuclear@4 | 2 #include "serial.h" |
nuclear@4 | 3 |
nuclear@4 | 4 #define CLK 3546895 |
nuclear@4 | 5 #define BVAL(b) (CLK / (b) - 1) |
nuclear@4 | 6 |
nuclear@4 | 7 static inline uint16_t baudval(int baud) |
nuclear@4 | 8 { |
nuclear@4 | 9 switch(baud) { |
nuclear@4 | 10 case 110: return BVAL(110); |
nuclear@4 | 11 case 300: return BVAL(300); |
nuclear@4 | 12 case 600: return BVAL(600); |
nuclear@4 | 13 case 1200: return BVAL(1200); |
nuclear@4 | 14 case 2400: return BVAL(2400); |
nuclear@4 | 15 case 4800: return BVAL(4800); |
nuclear@4 | 16 case 9600: return BVAL(9600); |
nuclear@4 | 17 case 14400: return BVAL(14400); |
nuclear@4 | 18 case 19200: return BVAL(19200); |
nuclear@4 | 19 case 38400: return BVAL(38400); |
nuclear@4 | 20 case 57600: return BVAL(57600); |
nuclear@4 | 21 case 115200: return BVAL(115200); |
nuclear@4 | 22 default: |
nuclear@4 | 23 break; |
nuclear@4 | 24 } |
nuclear@4 | 25 return BVAL(baud); |
nuclear@4 | 26 } |
nuclear@4 | 27 |
nuclear@4 | 28 void ser_init(int baud) |
nuclear@4 | 29 { |
nuclear@4 | 30 REG_SERPER = baudval(baud) & 0x7fff; |
nuclear@4 | 31 } |
nuclear@4 | 32 |
nuclear@4 | 33 /* |
nuclear@4 | 34 void ser_putchar(int c) |
nuclear@4 | 35 { |
nuclear@4 | 36 REG_SERDAT = ((uint16_t)c & 0xff) | 0x100; |
nuclear@4 | 37 } |
nuclear@4 | 38 */ |
nuclear@4 | 39 |
nuclear@4 | 40 void ser_print(const char *s) |
nuclear@4 | 41 { |
nuclear@4 | 42 while(*s) { |
nuclear@4 | 43 if(*s == '\n') { |
nuclear@4 | 44 ser_putchar('\r'); |
nuclear@4 | 45 } |
nuclear@4 | 46 ser_putchar(*s++); |
nuclear@4 | 47 } |
nuclear@4 | 48 } |