[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 | |
---|
[456] | 20 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 21 | // access functions |
---|
[456] | 22 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 23 | |
---|
| 24 | ///////////////////////////////////////////////////// |
---|
[295] | 25 | unsigned int _tty_get_register( unsigned int channel, |
---|
| 26 | unsigned int index ) |
---|
| 27 | { |
---|
[320] | 28 | unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index; |
---|
[295] | 29 | return _io_extended_read( vaddr ); |
---|
| 30 | } |
---|
| 31 | |
---|
[437] | 32 | ///////////////////////////////////////////// |
---|
[295] | 33 | void _tty_set_register( unsigned int channel, |
---|
| 34 | unsigned int index, |
---|
| 35 | unsigned int value ) |
---|
| 36 | { |
---|
[320] | 37 | unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index; |
---|
[295] | 38 | _io_extended_write( vaddr, value ); |
---|
| 39 | } |
---|
| 40 | |
---|
[456] | 41 | ////////////////////////////////////// |
---|
| 42 | void _tty_init( unsigned int channel ) |
---|
| 43 | { |
---|
| 44 | _tty_rx_full[channel] = 0; |
---|
| 45 | } |
---|
[258] | 46 | |
---|
[437] | 47 | //////////////////////////////////////// |
---|
[295] | 48 | void _tty_rx_isr( unsigned int irq_type, // HWI / WTI |
---|
| 49 | unsigned int irq_id, // index returned by XCU |
---|
| 50 | unsigned int channel ) // TTY channel |
---|
[258] | 51 | { |
---|
[426] | 52 | unsigned int gpid = _get_procid(); |
---|
| 53 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[258] | 54 | |
---|
[297] | 55 | // get TTY status |
---|
| 56 | unsigned int status = _tty_get_register( channel, TTY_STATUS ); |
---|
| 57 | |
---|
| 58 | // check both TTY status and kernel buffer status: |
---|
| 59 | // does nothing if kernel buffer full or tty_buffer empty |
---|
| 60 | if ( ((status & 0x1) == 0) || |
---|
| 61 | (_tty_rx_full[channel] != 0) ) return; |
---|
| 62 | |
---|
| 63 | // reset WTI in XCU if WTI type |
---|
| 64 | if ( irq_type == IRQ_TYPE_WTI ) |
---|
[258] | 65 | { |
---|
[295] | 66 | unsigned int value; |
---|
| 67 | _xcu_get_wti_value( cluster_xy, irq_id, &value ); |
---|
[258] | 68 | } |
---|
| 69 | |
---|
[297] | 70 | // transfer character to kernel buffer and acknowledge TTY IRQ |
---|
| 71 | _tty_rx_buf[channel] = _tty_get_register( channel, TTY_READ ); |
---|
| 72 | |
---|
| 73 | // set kernel buffer status |
---|
| 74 | asm volatile( "sync" ); |
---|
| 75 | _tty_rx_full[channel] = 1; |
---|
| 76 | |
---|
[295] | 77 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlock |
---|
| 78 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 79 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[426] | 80 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
[295] | 81 | _puts("\n[IRQS DEBUG] Processor["); |
---|
| 82 | _putd(x ); |
---|
| 83 | _puts(","); |
---|
| 84 | _putd(y ); |
---|
| 85 | _puts(","); |
---|
| 86 | _putd(lpid ); |
---|
| 87 | _puts("] enters _tty_rx_isr() at cycle "); |
---|
| 88 | _putd(_get_proctime() ); |
---|
| 89 | _puts("\n read byte = "); |
---|
| 90 | _putx(_tty_rx_buf[channel] ); |
---|
| 91 | _puts("\n"); |
---|
| 92 | #endif |
---|
[258] | 93 | |
---|
| 94 | } |
---|
| 95 | |
---|
[437] | 96 | ///////////////////////////////////////// |
---|
[295] | 97 | void _tty_tx_isr( unsigned int irq_type, // HWI / WTI |
---|
| 98 | unsigned int irq_id, // index returned by XCU |
---|
| 99 | unsigned int channel ) // TTY channel |
---|
[258] | 100 | { |
---|
[295] | 101 | _puts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n"); |
---|
| 102 | _exit(); |
---|
[258] | 103 | } |
---|
| 104 | |
---|
| 105 | // Local Variables: |
---|
| 106 | // tab-width: 4 |
---|
| 107 | // c-basic-offset: 4 |
---|
| 108 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 109 | // indent-tabs-mode: nil |
---|
| 110 | // End: |
---|
| 111 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 112 | |
---|