[4407ee6] | 1 | /** |
---|
| 2 | * @file printk-support.c |
---|
| 3 | * |
---|
| 4 | * @ingroup tms570 |
---|
| 5 | * |
---|
| 6 | * @brief definitions of serial line for debugging. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> |
---|
| 11 | * |
---|
| 12 | * Google Summer of Code 2014 at |
---|
| 13 | * Czech Technical University in Prague |
---|
| 14 | * Zikova 1903/4 |
---|
| 15 | * 166 36 Praha 6 |
---|
| 16 | * Czech Republic |
---|
| 17 | * |
---|
| 18 | * Based on LPC24xx and LPC1768 BSP |
---|
| 19 | * by embedded brains GmbH and others |
---|
| 20 | * |
---|
| 21 | * The license and distribution terms for this file may be |
---|
| 22 | * found in the file LICENSE in this distribution or at |
---|
| 23 | * http://www.rtems.org/license/LICENSE. |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <rtems/bspIo.h> |
---|
[5ca634e9] | 27 | #include <rtems/sysinit.h> |
---|
[4407ee6] | 28 | #include <stdint.h> |
---|
| 29 | #include <bsp/tms570-sci.h> |
---|
| 30 | #include <bsp/tms570-sci-driver.h> |
---|
| 31 | |
---|
[5ca634e9] | 32 | #define TMS570_CONSOLE (&driver_context_table[0]) |
---|
[4407ee6] | 33 | |
---|
| 34 | /** |
---|
| 35 | * @brief Puts chars into peripheral |
---|
| 36 | * |
---|
| 37 | * debug functions always use serial dev 0 peripheral |
---|
| 38 | * |
---|
| 39 | * @retval Void |
---|
| 40 | */ |
---|
[5ca634e9] | 41 | static void tms570_debug_console_putc(char ch) |
---|
[4407ee6] | 42 | { |
---|
[5ca634e9] | 43 | tms570_sci_context *ctx = TMS570_CONSOLE; |
---|
| 44 | volatile tms570_sci_t *regs = ctx->regs; |
---|
[4407ee6] | 45 | rtems_interrupt_level level; |
---|
| 46 | |
---|
| 47 | rtems_interrupt_disable(level); |
---|
[5ca634e9] | 48 | while ( ( regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) { |
---|
| 49 | rtems_interrupt_flash(level); |
---|
| 50 | } |
---|
| 51 | regs->TD = ch; |
---|
| 52 | while ( ( regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0) { |
---|
[4407ee6] | 53 | rtems_interrupt_flash(level); |
---|
| 54 | } |
---|
| 55 | rtems_interrupt_enable(level); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * @brief debug console output |
---|
| 60 | * |
---|
| 61 | * debug functions always use serial dev 0 peripheral |
---|
| 62 | * |
---|
| 63 | * @retval Void |
---|
| 64 | */ |
---|
[5ca634e9] | 65 | static void tms570_debug_console_out(char c) |
---|
[4407ee6] | 66 | { |
---|
| 67 | if ( c == '\n' ) { |
---|
[5ca634e9] | 68 | tms570_debug_console_putc('\r'); |
---|
[4407ee6] | 69 | } |
---|
[5ca634e9] | 70 | |
---|
| 71 | tms570_debug_console_putc(c); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | static void tms570_debug_console_init(void) |
---|
| 75 | { |
---|
| 76 | tms570_sci_context *ctx = TMS570_CONSOLE; |
---|
| 77 | struct termios term; |
---|
| 78 | |
---|
| 79 | tms570_sci_initialize(ctx); |
---|
| 80 | memset(&term, 0, sizeof(term)); |
---|
| 81 | term.c_cflag = B115200; |
---|
| 82 | tms570_sci_set_attributes(&ctx->base, &term); |
---|
| 83 | BSP_output_char = tms570_debug_console_out; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | static void tms570_debug_console_early_init(char c) |
---|
| 87 | { |
---|
| 88 | tms570_debug_console_init(); |
---|
| 89 | tms570_debug_console_out(c); |
---|
[4407ee6] | 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * @brief debug console input |
---|
| 94 | * |
---|
| 95 | * debug functions always use serial dev 0 peripheral |
---|
| 96 | * |
---|
| 97 | * @retval x Read char |
---|
| 98 | * @retval -1 No input character available |
---|
| 99 | */ |
---|
[5ca634e9] | 100 | static int tms570_debug_console_in( void ) |
---|
[4407ee6] | 101 | { |
---|
[5ca634e9] | 102 | tms570_sci_context *ctx = TMS570_CONSOLE; |
---|
| 103 | volatile tms570_sci_t *regs = ctx->regs; |
---|
| 104 | rtems_interrupt_level level; |
---|
| 105 | int c; |
---|
| 106 | |
---|
| 107 | rtems_interrupt_disable(level); |
---|
| 108 | |
---|
| 109 | if ( regs->FLR & TMS570_SCI_FLR_RXRDY ) { |
---|
| 110 | c = (unsigned char) regs->RD; |
---|
[4407ee6] | 111 | } else { |
---|
[5ca634e9] | 112 | c = -1; |
---|
[4407ee6] | 113 | } |
---|
[5ca634e9] | 114 | |
---|
| 115 | rtems_interrupt_enable(level); |
---|
| 116 | |
---|
| 117 | return c; |
---|
[4407ee6] | 118 | } |
---|
| 119 | |
---|
[5ca634e9] | 120 | BSP_output_char_function_type BSP_output_char = |
---|
| 121 | tms570_debug_console_early_init; |
---|
| 122 | |
---|
| 123 | BSP_polling_getchar_function_type BSP_poll_char = tms570_debug_console_in; |
---|
| 124 | |
---|
| 125 | RTEMS_SYSINIT_ITEM( |
---|
| 126 | tms570_debug_console_init, |
---|
| 127 | RTEMS_SYSINIT_BSP_START, |
---|
| 128 | RTEMS_SYSINIT_ORDER_LAST |
---|
| 129 | ); |
---|