Ignore:
Timestamp:
Oct 1, 2015, 4:20:46 PM (9 years ago)
Author:
alain
Message:

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_common/tty0.c

    r594 r709  
    1212#include <stdarg.h>
    1313#include <tty_driver.h>
     14#include <ctx_handler.h>
    1415#include <utils.h>
    1516#include <kernel_locks.h>
     
    3031spin_lock_t          _tty0_spin_lock  __attribute__((aligned(64)));
    3132
    32 //////////////////////////////////////////////
    33 unsigned int _tty0_write( char*        buffer,
    34                           unsigned int nbytes )
     33/////////////////////////////////////////////////////
     34unsigned int _tty_channel_write( unsigned int channel,
     35                                 char*        buffer,
     36                                 unsigned int nbytes )
    3537{
    3638    unsigned int n;
     
    4042    {
    4143        // test TTY_TX buffer full
    42         if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) ) // buffer full
     44        if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) ) // buffer full
    4345        {
    4446            // retry if full
    4547            for( k = 0 ; k < 10000 ; k++ )
    4648            {
    47                 if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) == 0) break;
     49                if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) == 0) break;
    4850            }
    4951            // return error if full after 10000 retry
     
    5254
    5355        // 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] );
    5658    }
    5759    return 0;
     
    6567    while ( string[n] > 0 ) n++;
    6668
    67     _tty0_write( string, n );
     69    _tty_channel_write( 0, string, n );
    6870}
    6971
     
    8486        val = val >> 4;
    8587    }
    86     _tty0_write( buf, 10 );
     88    _tty_channel_write( 0, buf, 10 );
    8789}
    8890
     
    102104        val = val >> 4;
    103105    }
    104     _tty0_write( buf, 18 );
     106    _tty_channel_write( 0, buf, 18 );
    105107}
    106108
     
    126128        val /= 10;
    127129    }
    128     _tty0_write( &buf[first], 10 - first );
     130    _tty_channel_write( 0, &buf[first], 10 - first );
    129131}
    130132
     
    140142
    141143//////////////////////////////////////////////////////////
    142 static void _kernel_printf( char * format, va_list* args )
     144static void _kernel_printf( unsigned int channel,
     145                            char *       format,
     146                            va_list*     args )
    143147{
    144148
     
    151155        if (i)
    152156        {
    153             if ( _tty0_write( format, i ) ) goto return_error;
     157            if ( _tty_channel_write( channel, format, i ) ) goto return_error;
    154158            format += i;
    155159        }
     
    188192                {
    189193                    val = -val;
    190                     if ( _tty0_write( "-" , 1 ) ) goto return_error;
     194                    if ( _tty_channel_write( channel, "-" , 1 ) ) goto return_error;
    191195                }
    192196                for(i = 0; i < 10; i++)
     
    214218            {
    215219                unsigned int val = va_arg( *args , unsigned int );
    216                 if ( _tty0_write( "0x" , 2 ) ) goto return_error;
     220                if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error;
    217221                for(i = 0; i < 8; i++)
    218222                {
     
    227231            {
    228232                unsigned int val = va_arg( *args , unsigned int );
    229                 if ( _tty0_write( "0x" , 2 ) ) goto return_error;
     233                if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error;
    230234                for(i = 0; i < 8; i++)
    231235                {
     
    240244            {
    241245                unsigned long long val = va_arg( *args , unsigned long long );
    242                 if ( _tty0_write( "0x" , 2 ) ) goto return_error;
     246                if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error;
    243247                for(i = 0; i < 16; i++)
    244248                {
     
    264268        }
    265269
    266         if ( _tty0_write( pbuf, len ) ) goto return_error;
     270        if ( _tty_channel_write( channel, pbuf, len ) ) goto return_error;
    267271       
    268272        goto printf_text;
     
    284288        _putd( lpid );
    285289        _puts("]\n");
    286 
    287290        _exit();
    288291    }
     
    294297    va_list   args;
    295298
     299    // call kernel_printf
    296300    va_start( args , format );
    297     _kernel_printf( format , &args );
     301    _kernel_printf( 0, format , &args );
    298302    va_end( args );
    299303}
     304
    300305////////////////////////////////
    301306void _printf( char* format, ...)
     
    309314    else                   _sqt_lock_acquire( &_tty0_sqt_lock );
    310315
     316    // call kernel_printf
    311317    va_start( args , format );
    312     _kernel_printf( format , &args );
     318    _kernel_printf( 0, format , &args );
    313319    va_end( args );
    314320
     
    318324    _it_restore( &save_sr );
    319325}
     326
     327/////////////////////////////////////
     328void _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
    320348
    321349
Note: See TracChangeset for help on using the changeset viewer.