Ignore:
Timestamp:
Apr 26, 2017, 2:10:21 PM (5 years ago)
Author:
alain
Message:

Introduce the chdev_t structure in place of device_t.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/drivers/soclib/soclib_tty.c

    r1 r4  
    2323
    2424#include <dev_txt.h>
    25 #include <device.h>
     25#include <chdev.h>
    2626#include <soclib_tty.h>
    2727#include <remote_spinlock.h>
     
    2929#include <hal_special.h>
    3030
    31 /////////////////////////////////////
    32 void soclib_tty_init( xptr_t dev_xp )
     31///////////////////////////////////////
     32void soclib_tty_init( chdev_t * chdev )
    3333{
    34     // get TXT device cluster and local pointer
    35     cxy_t      dev_cxy = GET_CXY( dev_xp );
    36     device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
    37 
    3834    // 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;
    4036
    4137    // get SOCLIB_TTY device cluster and local pointer
     
    4642    hal_remote_sw( XPTR( tty_cxy , tty_ptr + TTY_CONFIG_REG ) , 0 );
    4743
    48 }  // end soclib_tty_init()
    49 
    50 //////////////////////////////////////////////////////////////////
    51 void __attribute__ ((noinline)) soclib_tty_command( xptr_t th_xp )
     44}  // soclib_tty_init()
     45
     46//////////////////////////////////////////////////////////////
     47void __attribute__ ((noinline)) soclib_tty_cmd( xptr_t th_xp )
    5248{
    5349    // get client thread cluster and local pointer
     
    5652
    5753    // 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 ) );
    6056   
    6157    // get TXT device cluster and local pointer
    62     cxy_t      dev_cxy = GET_CXY( dev_xp );
    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 );
    6460
    6561    // get extended pointer on SOCLIB_TTY base segment
     
    7066    uint32_t * tty_ptr = (uint32_t *)GET_PTR( tty_xp );
    7167
     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
    7272    if( type == TXT_READ )              // descheduling strategy for calling thead
    7373    {
    7474        // 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 );
    7676        uint32_t old = hal_remote_lw( config_xp );
    7777        uint32_t new = old | TTY_CONFIG_RX_ENABLE;
     
    8585    {
    8686        // 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 );
    8888        uint32_t old = hal_remote_lw( config_xp );
    8989        uint32_t new = old | TTY_CONFIG_TX_ENABLE;
     
    101101
    102102        // 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 ) );
    105105
    106106        // loop on characters
     
    110110            {
    111111                // 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 ) );
    113113                empty  = ( (status & TTY_STATUS_TX_FULL) == 0 );
    114114
     
    119119
    120120                    // 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 );
    122122                }
    123123            }
     
    125125        }
    126126    }
    127 }  // end soclib_tty_command()
    128 
    129 
    130 ////////////////////////////////////////////////////////////////
    131 void __attribute__ ((noinline)) soclib_tty_isr( device_t * dev )
     127}  // soclib_tty_command()
     128
     129
     130/////////////////////////////////////////////////////////////////
     131void __attribute__ ((noinline)) soclib_tty_isr( chdev_t * chdev )
    132132{
    133133    uint32_t   type;         // command type
     
    138138    uint32_t   i;
    139139
    140 
    141140    // 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 );
    143142    xptr_t client_xp = XLIST_FIRST_ELEMENT( root , thread_t , wait_list );
    144143
     
    148147
    149148    // 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 ) );
    153152
    154153    // 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;
    157159
    158160    if( type == TXT_READ )              // read one single character
    159161    {
    160162        // 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 ) );
    162164
    163165        if( status & TTY_STATUS_RX_FULL )   // TTY_RX full => transfer one byte
    164166        {
    165167            // 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 ) );
    167169
    168170            // write it to command buffer
     
    174176                if( (byte == '\b') || (byte == 0x7F) )
    175177                        {
    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' );
    179181                        }
    180182                else
    181183                {
    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 );
    183185                        }
    184186            }
     
    195197        {
    196198            // 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 ) );
    198200
    199201            if( (status & TTY_STATUS_TX_FULL) == 0 ) // TTY_TX empty => transfer one byte
     
    203205
    204206                // 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 );
    206208            }
    207209            else         // TTY_TX full => update command arguments and exit ISR for retry
    208210            {
    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 );
    212213                return;
    213214            }
     
    218219
    219220    // 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 );
    221222
    222223    // 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 );
    224225
    225226    // 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 );
    227228
    228229    // unblock client thread
    229230    thread_unblock( client_xp , THREAD_BLOCKED_IO );
    230231
    231 }  // end soclib_tty_isr()
    232 
    233 
     232}  // soclib_tty_isr()
     233
     234
Note: See TracChangeset for help on using the changeset viewer.