Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (5 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_txt.c

    r406 r407  
    2727#include <hal_drivers.h>
    2828#include <thread.h>
     29#include <chdev.h>
    2930#include <rpc.h>
    3031#include <printk.h>
     
    3637
    3738extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
     39
     40#if CONFIG_READ_DEBUG
     41extern uint32_t enter_txt_read;
     42extern uint32_t exit_txt_read;
     43#endif
    3844
    3945//////////////////////////////////
     
    4753    uint32_t  channel = txt->channel;
    4854    uint32_t  impl    = txt->impl;
     55    bool_t    is_rx   = txt->is_rx;
    4956
    5057    assert( (pic_xp != XPTR_NULL) || (channel == 0) , __FUNCTION__ ,
     
    5259
    5360    // set chdev name
    54     snprintf( txt->name , 16 , "txt_%d" , channel );
     61    if( is_rx ) snprintf( txt->name , 16 , "txt%d_rx" , channel );
     62    else        snprintf( txt->name , 16 , "txt%d_tx" , channel );
    5563
    5664    // call driver init function
     
    6169    if( channel != 0 && impl != IMPL_TXT_RS2 )
    6270    {
    63         // select a core to execute the TXT server thread
     71        // select a core to execute the server thread
    6472        lid_t lid = cluster_select_local_core();
    6573
    66         // bind TXT IRQ to the selected core
     74        // bind IRQ to the selected core
    6775        dev_pic_bind_irq( lid , txt );
    6876
    69         // enable TXT IRQ
     77        // enable IRQ
    7078        dev_pic_enable_irq( lid , XPTR( local_cxy , txt ) );
    7179
     
    99107                               uint32_t   count )
    100108{
     109    xptr_t     dev_xp;
    101110    thread_t * this = CURRENT_THREAD;
    102111
    103     txt_dmsg("\n[DMSG] in %s : thread %x in process %x enters\n",
    104                  __FUNCTION__ , this->trdid , this->process->pid );
     112txt_dmsg("\n[DBG] %s : core[%x,%d] (thread %s) enters / cycle %d\n",
     113__FUNCTION__, local_cxy, this->core->lid, thread_type_str(this->type), hal_time_stamp() );
    105114
    106115    // check channel argument
     
    108117
    109118    // get extended pointer on remote TXT chdev descriptor
    110     xptr_t  dev_xp = chdev_dir.txt[channel];
     119    if( type == TXT_WRITE )  dev_xp = chdev_dir.txt_tx[channel];
     120    else                     dev_xp = chdev_dir.txt_rx[channel];
    111121
    112122    assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined TXT chdev descriptor" );
     
    121131    // block client thread on THREAD_BLOCKED_IO and deschedule.
    122132    // it is re-activated by the ISR signaling IO operation completion.
    123     chdev_register_command( dev_xp , this );
     133    chdev_register_command( dev_xp );
    124134
    125     txt_dmsg("\n[DMSG] in %s : thread %x in process %x completes / error = %d\n",
    126              __FUNCTION__ , this->trdid , this->process->pid , this->txt_cmd.error );
     135txt_dmsg("\n[DBG] %s : core[%x,%d] (thread %s) exit / cycle %d\n",
     136__FUNCTION__, local_cxy, this->core->lid, thread_type_str(this->type), hal_time_stamp() );
    127137
    128138    // return I/O operation status from calling thread descriptor
     
    135145                       uint32_t   count )
    136146{
    137     return dev_txt_access( TXT_WRITE , channel , buffer , count );
     147    error_t error = dev_txt_access( TXT_WRITE , channel , buffer , count );
     148    return error;
    138149}
    139150
     
    142153                      char     * buffer )
    143154{
    144     return dev_txt_access( TXT_READ , channel , buffer , 1 );
     155
     156#if CONFIG_READ_DEBUG
     157enter_txt_read = hal_time_stamp();
     158#endif
     159
     160    error_t error = dev_txt_access( TXT_READ , channel , buffer , 1 );
     161
     162#if CONFIG_READ_DEBUG
     163exit_txt_read = hal_time_stamp();
     164#endif
     165
     166    return error;
     167
    145168}
    146169
    147 ///////////////////////////////////////////////
    148 error_t dev_txt_sync_write( uint32_t   channel,
    149                             char     * buffer,
     170//////////////////////////////////////////////
     171error_t dev_txt_sync_write( char     * buffer,
    150172                            uint32_t   count )
    151173{
    152     // get pointer on calling thread
    153     thread_t * this = CURRENT_THREAD;
     174    // get extended pointer on TXT[0] chdev
     175    xptr_t  dev_xp = chdev_dir.txt_tx[0];
    154176
    155     // get extended pointer on TXT[0] chdev
    156     xptr_t  dev_xp = chdev_dir.txt[channel];
     177    assert( (dev_xp != XPTR_NULL) , __FUNCTION__ ,
     178    "undefined TXT0 chdev descriptor" );
    157179
    158     assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined TXT0 chdev descriptor" );
    159 
    160     // register command in calling thread descriptor
    161     this->txt_cmd.dev_xp  = dev_xp;
    162     this->txt_cmd.type    = TXT_SYNC_WRITE;
    163     this->txt_cmd.buf_xp  = XPTR( local_cxy , buffer );
    164     this->txt_cmd.count   = count;
     180    // get TXTO chdev cluster and local pointer
     181    cxy_t    dev_cxy  = GET_CXY( dev_xp );
     182    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
    165183
    166184    // get driver command function
    167     cxy_t       dev_cxy = GET_CXY( dev_xp );
    168     chdev_t   * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
    169     dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->cmd ) );
     185    dev_aux_t * aux = (dev_aux_t *)hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->aux ) );
     186
     187    // build arguments structure
     188    txt_aux_t  args;
     189    args.dev_xp = dev_xp;
     190    args.buffer = buffer;
     191    args.count  = count;
    170192
    171193    // call driver function
    172     cmd( XPTR( local_cxy , this ) );
     194    aux( &args );
    173195
    174     // return I/O operation status from calling thread descriptor
    175     return this->txt_cmd.error;
     196    return 0;
    176197}
    177198
Note: See TracChangeset for help on using the changeset viewer.