Changeset 709 for soft/giet_vm/giet_common/tty0.c
- Timestamp:
- Oct 1, 2015, 4:20:46 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_common/tty0.c
r594 r709 12 12 #include <stdarg.h> 13 13 #include <tty_driver.h> 14 #include <ctx_handler.h> 14 15 #include <utils.h> 15 16 #include <kernel_locks.h> … … 30 31 spin_lock_t _tty0_spin_lock __attribute__((aligned(64))); 31 32 32 ////////////////////////////////////////////// 33 unsigned int _tty0_write( char* buffer, 34 unsigned int nbytes ) 33 ///////////////////////////////////////////////////// 34 unsigned int _tty_channel_write( unsigned int channel, 35 char* buffer, 36 unsigned int nbytes ) 35 37 { 36 38 unsigned int n; … … 40 42 { 41 43 // test TTY_TX buffer full 42 if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) ) // buffer full44 if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) ) // buffer full 43 45 { 44 46 // retry if full 45 47 for( k = 0 ; k < 10000 ; k++ ) 46 48 { 47 if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) == 0) break;49 if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) == 0) break; 48 50 } 49 51 // return error if full after 10000 retry … … 52 54 53 55 // write one byte 54 if (buffer[n] == '\n') _tty_set_register( 0, TTY_WRITE, (unsigned int)'\r' );55 _tty_set_register( 0, TTY_WRITE, (unsigned int)buffer[n] );56 if (buffer[n] == '\n') _tty_set_register( channel, TTY_WRITE, (unsigned int)'\r' ); 57 _tty_set_register( channel, TTY_WRITE, (unsigned int)buffer[n] ); 56 58 } 57 59 return 0; … … 65 67 while ( string[n] > 0 ) n++; 66 68 67 _tty 0_write(string, n );69 _tty_channel_write( 0, string, n ); 68 70 } 69 71 … … 84 86 val = val >> 4; 85 87 } 86 _tty 0_write(buf, 10 );88 _tty_channel_write( 0, buf, 10 ); 87 89 } 88 90 … … 102 104 val = val >> 4; 103 105 } 104 _tty 0_write(buf, 18 );106 _tty_channel_write( 0, buf, 18 ); 105 107 } 106 108 … … 126 128 val /= 10; 127 129 } 128 _tty 0_write(&buf[first], 10 - first );130 _tty_channel_write( 0, &buf[first], 10 - first ); 129 131 } 130 132 … … 140 142 141 143 ////////////////////////////////////////////////////////// 142 static void _kernel_printf( char * format, va_list* args ) 144 static void _kernel_printf( unsigned int channel, 145 char * format, 146 va_list* args ) 143 147 { 144 148 … … 151 155 if (i) 152 156 { 153 if ( _tty 0_write(format, i ) ) goto return_error;157 if ( _tty_channel_write( channel, format, i ) ) goto return_error; 154 158 format += i; 155 159 } … … 188 192 { 189 193 val = -val; 190 if ( _tty 0_write("-" , 1 ) ) goto return_error;194 if ( _tty_channel_write( channel, "-" , 1 ) ) goto return_error; 191 195 } 192 196 for(i = 0; i < 10; i++) … … 214 218 { 215 219 unsigned int val = va_arg( *args , unsigned int ); 216 if ( _tty 0_write("0x" , 2 ) ) goto return_error;220 if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error; 217 221 for(i = 0; i < 8; i++) 218 222 { … … 227 231 { 228 232 unsigned int val = va_arg( *args , unsigned int ); 229 if ( _tty 0_write("0x" , 2 ) ) goto return_error;233 if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error; 230 234 for(i = 0; i < 8; i++) 231 235 { … … 240 244 { 241 245 unsigned long long val = va_arg( *args , unsigned long long ); 242 if ( _tty 0_write("0x" , 2 ) ) goto return_error;246 if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error; 243 247 for(i = 0; i < 16; i++) 244 248 { … … 264 268 } 265 269 266 if ( _tty 0_write(pbuf, len ) ) goto return_error;270 if ( _tty_channel_write( channel, pbuf, len ) ) goto return_error; 267 271 268 272 goto printf_text; … … 284 288 _putd( lpid ); 285 289 _puts("]\n"); 286 287 290 _exit(); 288 291 } … … 294 297 va_list args; 295 298 299 // call kernel_printf 296 300 va_start( args , format ); 297 _kernel_printf( format , &args );301 _kernel_printf( 0, format , &args ); 298 302 va_end( args ); 299 303 } 304 300 305 //////////////////////////////// 301 306 void _printf( char* format, ...) … … 309 314 else _sqt_lock_acquire( &_tty0_sqt_lock ); 310 315 316 // call kernel_printf 311 317 va_start( args , format ); 312 _kernel_printf( format , &args );318 _kernel_printf( 0, format , &args ); 313 319 va_end( args ); 314 320 … … 318 324 _it_restore( &save_sr ); 319 325 } 326 327 ///////////////////////////////////// 328 void _user_printf( char* format, ...) 329 { 330 va_list args; 331 332 // get calling thread TYY channel 333 unsigned int channel = _get_context_slot( CTX_TTY_ID ); 334 if( channel >= NB_TTY_CHANNELS ) 335 { 336 _puts("\n[GIET ERROR] in _user_printf() : no TTY allocated for thread "); 337 _putx( _get_thread_trdid() ); 338 _puts("\n"); 339 _exit(); 340 } 341 342 // call kernel_printf 343 va_start( args , format ); 344 _kernel_printf( channel, format , &args ); 345 va_end( args ); 346 } 347 320 348 321 349
Note: See TracChangeset
for help on using the changeset viewer.