Changeset 4 for trunk/kernel/drivers/soclib/soclib_tty.c
- Timestamp:
- Apr 26, 2017, 2:10:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/drivers/soclib/soclib_tty.c
r1 r4 23 23 24 24 #include <dev_txt.h> 25 #include < device.h>25 #include <chdev.h> 26 26 #include <soclib_tty.h> 27 27 #include <remote_spinlock.h> … … 29 29 #include <hal_special.h> 30 30 31 ///////////////////////////////////// 32 void soclib_tty_init( xptr_t dev_xp)31 /////////////////////////////////////// 32 void soclib_tty_init( chdev_t * chdev ) 33 33 { 34 // get TXT device cluster and local pointer35 cxy_t dev_cxy = GET_CXY( dev_xp );36 device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );37 38 34 // get extended pointer on TTY-SOCLIB peripheral base address 39 xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );35 xptr_t tty_xp = chdev->base; 40 36 41 37 // get SOCLIB_TTY device cluster and local pointer … … 46 42 hal_remote_sw( XPTR( tty_cxy , tty_ptr + TTY_CONFIG_REG ) , 0 ); 47 43 48 } // endsoclib_tty_init()49 50 ////////////////////////////////////////////////////////////// ////51 void __attribute__ ((noinline)) soclib_tty_c ommand( xptr_t th_xp )44 } // soclib_tty_init() 45 46 ////////////////////////////////////////////////////////////// 47 void __attribute__ ((noinline)) soclib_tty_cmd( xptr_t th_xp ) 52 48 { 53 49 // get client thread cluster and local pointer … … 56 52 57 53 // get command type and extended pointer on TXT device 58 uint32_t type = hal_remote_lw ( XPTR( th_cxy , &th_ptr-> dev.txt.type ) );59 xptr_t dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr-> dev.txt.dev_xp ) );54 uint32_t type = hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.type ) ); 55 xptr_t dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.dev_xp ) ); 60 56 61 57 // get TXT device cluster and local pointer 62 cxy_t 63 device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );58 cxy_t dev_cxy = GET_CXY( dev_xp ); 59 chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); 64 60 65 61 // get extended pointer on SOCLIB_TTY base segment … … 70 66 uint32_t * tty_ptr = (uint32_t *)GET_PTR( tty_xp ); 71 67 68 // get TTY channel index and channel base address 69 uint32_t channel = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->channel ) ); 70 uint32_t * base = tty_ptr + TTY_SPAN * channel; 71 72 72 if( type == TXT_READ ) // descheduling strategy for calling thead 73 73 { 74 74 // unmask RX_IRQ (data transfer will be done by the TTY_RX ISR) 75 xptr_t config_xp = XPTR( tty_cxy , tty_ptr+ TTY_CONFIG_REG );75 xptr_t config_xp = XPTR( tty_cxy , base + TTY_CONFIG_REG ); 76 76 uint32_t old = hal_remote_lw( config_xp ); 77 77 uint32_t new = old | TTY_CONFIG_RX_ENABLE; … … 85 85 { 86 86 // unmask TX_IRQ (data transfer will be done by the TTY_TX ISR) 87 xptr_t config_xp = XPTR( tty_cxy , tty_ptr+ TTY_CONFIG_REG );87 xptr_t config_xp = XPTR( tty_cxy , base + TTY_CONFIG_REG ); 88 88 uint32_t old = hal_remote_lw( config_xp ); 89 89 uint32_t new = old | TTY_CONFIG_TX_ENABLE; … … 101 101 102 102 // get source buffer extended pointer & bytes count 103 uint32_t count = hal_remote_lw ( XPTR( th_cxy , &th_ptr-> dev.txt.count ) );104 xptr_t buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr-> dev.txt.buf_xp ) );103 uint32_t count = hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.count ) ); 104 xptr_t buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.buf_xp ) ); 105 105 106 106 // loop on characters … … 110 110 { 111 111 // get TTY_STATUS_REG 112 status = hal_remote_lw( XPTR( tty_cxy , tty_ptr+ TTY_STATUS_REG ) );112 status = hal_remote_lw( XPTR( tty_cxy , base + TTY_STATUS_REG ) ); 113 113 empty = ( (status & TTY_STATUS_TX_FULL) == 0 ); 114 114 … … 119 119 120 120 // write byte to TTY_WRITE_REG in TTY cluster 121 hal_remote_sb( XPTR( tty_cxy , tty_ptr+ TTY_WRITE_REG ) , byte );121 hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , byte ); 122 122 } 123 123 } … … 125 125 } 126 126 } 127 } // endsoclib_tty_command()128 129 130 //////////////////////////////////////////////////////////////// 131 void __attribute__ ((noinline)) soclib_tty_isr( device_t *dev )127 } // soclib_tty_command() 128 129 130 ///////////////////////////////////////////////////////////////// 131 void __attribute__ ((noinline)) soclib_tty_isr( chdev_t * chdev ) 132 132 { 133 133 uint32_t type; // command type … … 138 138 uint32_t i; 139 139 140 141 140 // get extended pointer on client thread 142 xptr_t root = XPTR( local_cxy , &dev->wait_root );141 xptr_t root = XPTR( local_cxy , &chdev->wait_root ); 143 142 xptr_t client_xp = XLIST_FIRST_ELEMENT( root , thread_t , wait_list ); 144 143 … … 148 147 149 148 // get command arguments 150 type = hal_remote_lw ( XPTR( client_cxy , &client_ptr-> dev.txt.type ) );151 count = hal_remote_lw ( XPTR( client_cxy , &client_ptr-> dev.txt.count ) );152 buf_xp = hal_remote_lwd( XPTR( client_cxy , &client_ptr-> dev.txt.buf_xp ) );149 type = hal_remote_lw ( XPTR( client_cxy , &client_ptr->command.txt.type ) ); 150 count = hal_remote_lw ( XPTR( client_cxy , &client_ptr->command.txt.count ) ); 151 buf_xp = hal_remote_lwd( XPTR( client_cxy , &client_ptr->command.txt.buf_xp ) ); 153 152 154 153 // get SOCLIB_TTY peripheral cluster and local pointer 155 cxy_t tty_cxy = GET_CXY( dev->base ); 156 uint32_t * tty_ptr = (uint32_t *)GET_PTR( dev->base ); 154 cxy_t tty_cxy = GET_CXY( chdev->base ); 155 uint32_t * tty_ptr = (uint32_t *)GET_PTR( chdev->base ); 156 157 // get channel base address 158 uint32_t * base = tty_ptr + TTY_SPAN * chdev->channel; 157 159 158 160 if( type == TXT_READ ) // read one single character 159 161 { 160 162 // get TTY_STATUS_REG 161 status = hal_remote_lw( XPTR( tty_cxy , tty_ptr+ TTY_STATUS_REG ) );163 status = hal_remote_lw( XPTR( tty_cxy , base + TTY_STATUS_REG ) ); 162 164 163 165 if( status & TTY_STATUS_RX_FULL ) // TTY_RX full => transfer one byte 164 166 { 165 167 // get a byte from TTY_READ_REG, and acknowledge RX_IRQ 166 byte = (char)hal_remote_lb( XPTR( tty_cxy , tty_ptr+ TTY_READ_REG ) );168 byte = (char)hal_remote_lb( XPTR( tty_cxy , base + TTY_READ_REG ) ); 167 169 168 170 // write it to command buffer … … 174 176 if( (byte == '\b') || (byte == 0x7F) ) 175 177 { 176 hal_remote_sb( XPTR( tty_cxy , tty_ptr+ TTY_WRITE_REG ) , '\b' );177 hal_remote_sb( XPTR( tty_cxy , tty_ptr+ TTY_WRITE_REG ) , ' ' );178 hal_remote_sb( XPTR( tty_cxy , tty_ptr+ TTY_WRITE_REG ) , '\b' );178 hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , '\b' ); 179 hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , ' ' ); 180 hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , '\b' ); 179 181 } 180 182 else 181 183 { 182 hal_remote_sw( XPTR( tty_cxy , tty_ptr+ TTY_WRITE_REG ) , byte );184 hal_remote_sw( XPTR( tty_cxy , base + TTY_WRITE_REG ) , byte ); 183 185 } 184 186 } … … 195 197 { 196 198 // get TTY_STATUS_REG 197 status = hal_remote_lw( XPTR( tty_cxy , tty_ptr+ TTY_STATUS_REG ) );199 status = hal_remote_lw( XPTR( tty_cxy , base + TTY_STATUS_REG ) ); 198 200 199 201 if( (status & TTY_STATUS_TX_FULL) == 0 ) // TTY_TX empty => transfer one byte … … 203 205 204 206 // write byte to TTY_WRITE_REG, and acknowledge TX_IRQ 205 hal_remote_sb( XPTR( tty_cxy , tty_ptr+ TTY_STATUS_REG ) , byte );207 hal_remote_sb( XPTR( tty_cxy , base + TTY_STATUS_REG ) , byte ); 206 208 } 207 209 else // TTY_TX full => update command arguments and exit ISR for retry 208 210 { 209 // update arguments in command for retry 210 hal_remote_sw ( XPTR( client_cxy , &client_ptr->dev.txt.count ) , count - i ); 211 hal_remote_swd( XPTR( client_cxy , &client_ptr->dev.txt.buf_xp ) , buf_xp + i ); 211 hal_remote_sw ( XPTR( client_cxy , &client_ptr->command.txt.count ), count-i ); 212 hal_remote_swd( XPTR( client_cxy , &client_ptr->command.txt.buf_xp ), buf_xp+i ); 212 213 return; 213 214 } … … 218 219 219 220 // mask both TTY_RX_IRQ and TTY_TX_IRQ 220 hal_remote_sw( XPTR( tty_cxy , tty_ptr+ TTY_CONFIG_REG ) , 0 );221 hal_remote_sw( XPTR( tty_cxy , base + TTY_CONFIG_REG ) , 0 ); 221 222 222 223 // set I/O operation status in command 223 hal_remote_sw( XPTR( client_cxy , &client_ptr-> dev.txt.error ) , 0 );224 hal_remote_sw( XPTR( client_cxy , &client_ptr->command.txt.error ) , 0 ); 224 225 225 226 // unblock server thread 226 thread_unblock( XPTR( local_cxy , & dev->server ) , THREAD_BLOCKED_DEV_ISR );227 thread_unblock( XPTR( local_cxy , &chdev->server ) , THREAD_BLOCKED_DEV_ISR ); 227 228 228 229 // unblock client thread 229 230 thread_unblock( client_xp , THREAD_BLOCKED_IO ); 230 231 231 } // endsoclib_tty_isr()232 233 232 } // soclib_tty_isr() 233 234
Note: See TracChangeset
for help on using the changeset viewer.