Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <debug.h> |
| 24 | #include <printf.h> |
| 25 | #include <platform/at91sam7.h> |
| 26 | #include <kernel/thread.h> |
| 27 | #include <stdarg.h> |
| 28 | |
| 29 | void ser_init(void) |
| 30 | { |
| 31 | AT91DBGU *dbgu = AT91DBGU_ADDR; |
| 32 | |
| 33 | // AT91PIO *pio = AT91PIO_ADDR; |
| 34 | // pio->select_a = PIN_DRXD | PIN_DTXD; |
| 35 | // pio->pio_disable = PIN_DRXD | PIN_DTXD; |
| 36 | |
| 37 | dbgu->MR = DBGU_PAR_NONE | DBGU_MODE_NORMAL; |
| 38 | // dbgu->BRGR = 10; //MCK_IN_MHZ / 115200 / 16; |
| 39 | dbgu->BRGR = AT91_MCK_MHZ / 115200 / 16; |
| 40 | dbgu->CR = DBGU_RXEN | DBGU_TXEN; |
| 41 | } |
| 42 | |
| 43 | void ser_putc(unsigned c) |
| 44 | { |
| 45 | AT91DBGU *dbgu = AT91DBGU_ADDR; |
| 46 | if(c == 10) { |
| 47 | while(!(dbgu->SR & DBGU_TXRDY)); |
| 48 | dbgu->THR = 13; |
| 49 | } |
| 50 | while(!(dbgu->SR & DBGU_TXRDY)); |
| 51 | dbgu->THR = c; |
| 52 | } |
| 53 | |
| 54 | void ser_puts(const char *s) |
| 55 | { |
| 56 | AT91DBGU *dbgu = AT91DBGU_ADDR; |
| 57 | while(*s) { |
| 58 | if(*s == 10) { |
| 59 | while(!(dbgu->SR & DBGU_TXRDY)); |
| 60 | dbgu->THR = 13; |
| 61 | } |
| 62 | while(!(dbgu->SR & DBGU_TXRDY)); |
| 63 | dbgu->THR = *s++; |
| 64 | } |
| 65 | } |
| 66 | |
Travis Geiselbrecht | 5eaef67 | 2009-12-03 23:56:23 -0800 | [diff] [blame] | 67 | int dgetc(char *c, bool wait) |
| 68 | { |
| 69 | return -1; |
| 70 | } |
| 71 | |
| 72 | |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 73 | void _dputc(char c) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 74 | { |
| 75 | ser_putc(c); |
| 76 | } |
| 77 | |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 78 | void platform_halt() |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 79 | { |
| 80 | arch_disable_ints(); |
| 81 | for(;;); |
| 82 | } |
| 83 | |