[258] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : tty_driver.c |
---|
| 3 | // Date : 23/05/2013 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | |
---|
| 8 | #include <giet_config.h> |
---|
[437] | 9 | #include <hard_config.h> |
---|
[258] | 10 | #include <tty_driver.h> |
---|
[295] | 11 | #include <xcu_driver.h> |
---|
[258] | 12 | #include <ctx_handler.h> |
---|
| 13 | #include <utils.h> |
---|
[456] | 14 | #include <tty0.h> |
---|
[258] | 15 | |
---|
[320] | 16 | #if !defined(SEG_TTY_BASE) |
---|
| 17 | # error: You must define SEG_TTY_BASE in the hard_config.h file |
---|
| 18 | #endif |
---|
| 19 | |
---|
[258] | 20 | #if !defined(NB_TTY_CHANNELS) |
---|
| 21 | # error: You must define NB_TTY_CHANNELS in the hard_config.h file |
---|
| 22 | #endif |
---|
| 23 | |
---|
[456] | 24 | #if (NB_TTY_CHANNELS == 0) |
---|
| 25 | # error: The NB_TTY_CHANNELS in the hard_config.h file cannot be 0 |
---|
[350] | 26 | #endif |
---|
| 27 | |
---|
[456] | 28 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 29 | // global variables |
---|
| 30 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 31 | |
---|
[456] | 32 | simple_lock_t _tty_tx_lock[NB_TTY_CHANNELS] __attribute__((aligned(64))); |
---|
[295] | 33 | |
---|
[456] | 34 | unsigned int _tty_rx_buf[NB_TTY_CHANNELS]; |
---|
| 35 | unsigned int _tty_rx_full[NB_TTY_CHANNELS]; |
---|
[350] | 36 | |
---|
[456] | 37 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 38 | // access functions |
---|
[456] | 39 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 40 | |
---|
| 41 | ///////////////////////////////////////////////////// |
---|
[295] | 42 | unsigned int _tty_get_register( unsigned int channel, |
---|
| 43 | unsigned int index ) |
---|
| 44 | { |
---|
[320] | 45 | unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index; |
---|
[295] | 46 | return _io_extended_read( vaddr ); |
---|
| 47 | } |
---|
| 48 | |
---|
[437] | 49 | ///////////////////////////////////////////// |
---|
[295] | 50 | void _tty_set_register( unsigned int channel, |
---|
| 51 | unsigned int index, |
---|
| 52 | unsigned int value ) |
---|
| 53 | { |
---|
[320] | 54 | unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index; |
---|
[295] | 55 | _io_extended_write( vaddr, value ); |
---|
| 56 | } |
---|
| 57 | |
---|
[456] | 58 | ////////////////////////////////////// |
---|
| 59 | void _tty_init( unsigned int channel ) |
---|
| 60 | { |
---|
| 61 | _tty_rx_full[channel] = 0; |
---|
| 62 | } |
---|
[258] | 63 | |
---|
[437] | 64 | //////////////////////////////////////// |
---|
[295] | 65 | void _tty_rx_isr( unsigned int irq_type, // HWI / WTI |
---|
| 66 | unsigned int irq_id, // index returned by XCU |
---|
| 67 | unsigned int channel ) // TTY channel |
---|
[258] | 68 | { |
---|
[426] | 69 | unsigned int gpid = _get_procid(); |
---|
| 70 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[258] | 71 | |
---|
[297] | 72 | // get TTY status |
---|
| 73 | unsigned int status = _tty_get_register( channel, TTY_STATUS ); |
---|
| 74 | |
---|
| 75 | // check both TTY status and kernel buffer status: |
---|
| 76 | // does nothing if kernel buffer full or tty_buffer empty |
---|
| 77 | if ( ((status & 0x1) == 0) || |
---|
| 78 | (_tty_rx_full[channel] != 0) ) return; |
---|
| 79 | |
---|
| 80 | // reset WTI in XCU if WTI type |
---|
| 81 | if ( irq_type == IRQ_TYPE_WTI ) |
---|
[258] | 82 | { |
---|
[295] | 83 | unsigned int value; |
---|
| 84 | _xcu_get_wti_value( cluster_xy, irq_id, &value ); |
---|
[258] | 85 | } |
---|
| 86 | |
---|
[297] | 87 | // transfer character to kernel buffer and acknowledge TTY IRQ |
---|
| 88 | _tty_rx_buf[channel] = _tty_get_register( channel, TTY_READ ); |
---|
| 89 | |
---|
| 90 | // set kernel buffer status |
---|
| 91 | asm volatile( "sync" ); |
---|
| 92 | _tty_rx_full[channel] = 1; |
---|
| 93 | |
---|
[295] | 94 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlock |
---|
| 95 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 96 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[426] | 97 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
[295] | 98 | _puts("\n[IRQS DEBUG] Processor["); |
---|
| 99 | _putd(x ); |
---|
| 100 | _puts(","); |
---|
| 101 | _putd(y ); |
---|
| 102 | _puts(","); |
---|
| 103 | _putd(lpid ); |
---|
| 104 | _puts("] enters _tty_rx_isr() at cycle "); |
---|
| 105 | _putd(_get_proctime() ); |
---|
| 106 | _puts("\n read byte = "); |
---|
| 107 | _putx(_tty_rx_buf[channel] ); |
---|
| 108 | _puts("\n"); |
---|
| 109 | #endif |
---|
[258] | 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
[437] | 113 | ///////////////////////////////////////// |
---|
[295] | 114 | void _tty_tx_isr( unsigned int irq_type, // HWI / WTI |
---|
| 115 | unsigned int irq_id, // index returned by XCU |
---|
| 116 | unsigned int channel ) // TTY channel |
---|
[258] | 117 | { |
---|
[295] | 118 | _puts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n"); |
---|
| 119 | _exit(); |
---|
[258] | 120 | } |
---|
| 121 | |
---|
| 122 | // Local Variables: |
---|
| 123 | // tab-width: 4 |
---|
| 124 | // c-basic-offset: 4 |
---|
| 125 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 126 | // indent-tabs-mode: nil |
---|
| 127 | // End: |
---|
| 128 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 129 | |
---|