Ignore:
Timestamp:
Jul 12, 2017, 8:12:41 PM (7 years ago)
Author:
alain
Message:

Redefine the PIC device API.

File:
1 edited

Legend:

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

    r101 r188  
    3838extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
    3939
    40 extern chdev_pic_input_t  chdev_pic_input;   // allocated in kernel_init.c
     40//////////////////////////////////
     41void dev_txt_init( chdev_t * txt )
     42{
     43    // For all TXT channels other than the TXT0 (kernel terminal),
     44    // the PIC chdev must be initialized before the TXT chdev, because
     45    // the TXT chdev initialization requires the routing of an external IRQ
    4146
    42 ////////////////////////////////////
    43 void dev_txt_init( chdev_t * chdev )
    44 {
    45     // the local ICU chdev must be initialized before the TXT chdev, because
    46     // the TXT chdev initialization requires allocation of a WTI from local ICU
    47     xptr_t  icu_xp  = chdev_dir.icu[local_cxy];
    48     assert( (icu_xp != XPTR_NULL) , __FUNCTION__ , "ICU not initialised before TXT" );
     47    xptr_t    pic_xp  = chdev_dir.pic;
     48    uint32_t  channel = txt->channel;
     49    uint32_t  impl    = txt->impl;
    4950
    50     // get implementation and channel index
    51     uint32_t  impl    = chdev->impl;
    52     uint32_t  channel = chdev->channel;
     51    assert( (pic_xp != XPTR_NULL) || (channel == 0) , __FUNCTION__ ,
     52            "PIC not initialised before TXT" );
    5353
    5454    // set chdev name
    55     snprintf( chdev->name , 16 , "txt_%d" , chdev->channel );
     55    snprintf( txt->name , 16 , "txt_%d" , channel );
    5656
    5757    // set fields "cmd", "isr", and call driver init function
    5858    if( impl == IMPL_TXT_TTY )
    5959    {
    60         chdev->cmd = &soclib_tty_cmd;
    61         chdev->isr = &soclib_tty_isr;
    62         soclib_tty_init( chdev );
     60        txt->cmd = &soclib_tty_cmd;
     61        txt->isr = &soclib_tty_isr;
     62        soclib_tty_init( txt );
    6363    }
    6464    else
     
    6767    }
    6868
    69     // get a WTI mailbox from local ICU
    70     uint32_t wti_id = dev_icu_wti_alloc();
     69    // no server thread and no IRQ routing for TXT0
     70    if( channel != 0 )
     71    {
     72        // select a core to execute the TXT server thread
     73        lid_t lid = cluster_select_local_core();
    7174
    72     assert( (wti_id != -1) , __FUNCTION__ , "cannot allocate WTI mailbox" );
     75        // bind TXT IRQ to the selected core
     76        dev_pic_bind_irq( lid , txt );
    7377
    74     // select a core
    75     lid_t lid = cluster_select_local_core();
     78        // enable TXT IRQ
     79        dev_pic_enable_irq( lid , txt );
    7680
    77     // enable WTI IRQ and update WTI interrupt vector
    78     dev_icu_enable_irq( lid , WTI_TYPE , wti_id , chdev );
     81        // create server thread
     82        thread_t * new_thread;
     83        error_t    error;
    7984
    80     // link IOC IRQ to WTI mailbox in PIC component
    81     uint32_t irq_id = chdev_pic_input.txt[channel];
    82     dev_pic_bind_irq( irq_id , local_cxy , wti_id );
     85        error = thread_kernel_create( &new_thread,
     86                                      THREAD_DEV,
     87                                      &chdev_sequencial_server,
     88                                      txt,
     89                                      lid );
    8390
    84     // create server thread
    85     thread_t * new_thread;
    86     error_t    error;
     91        assert( (error == 0) , __FUNCTION__ , "cannot create server thread" );
    8792
    88     error = thread_kernel_create( &new_thread,
    89                                   THREAD_DEV,
    90                                   &chdev_sequencial_server,
    91                                   chdev,
    92                                   lid );
    93     assert( (error == 0) , __FUNCTION__ , "cannot create server thread" );
     93        // set "server" field in chdev descriptor
     94        txt->server = new_thread;
    9495
    95     // set "server" field in chdev descriptor
    96     chdev->server = new_thread;
    97 
    98     // start server thread
    99     thread_unblock( XPTR( local_cxy , new_thread ) , THREAD_BLOCKED_GLOBAL );
     96        // start server thread
     97        thread_unblock( XPTR( local_cxy , new_thread ) , THREAD_BLOCKED_GLOBAL );
     98    }
    10099}
    101100
Note: See TracChangeset for help on using the changeset viewer.