Ignore:
Timestamp:
Apr 26, 2017, 2:11:56 PM (7 years ago)
Author:
alain
Message:

Introduce the chdev_t structure in place of the device_t structure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/printk.c

    r1 r5  
    2424#include <hal_types.h>
    2525#include <hal_irqmask.h>
    26 #include <printk.h>
    27 #include <stdarg.h>
     26#include <hal_special.h>
    2827#include <dev_txt.h>
    2928#include <remote_spinlock.h>
    3029#include <cluster.h>
     30#include <printk.h>
    3131
    3232///////////////////////////////////////////////////////////////////////////////////
    33 // This static function is called by printk(), nolock_printk() and user_printk()
     33// This static function is called by kernel_printf() to display a string on the
     34// TXT channel defined by the <channel> argument.
     35// The access mode is defined by the <busy> argument:
     36// - if <busy> is true, it uses the dev_txt_sync_write() function, that takes the
     37//   TXT lock, and call directly the relevant TXT driver, without descheduling.
     38// - if <busy is false, it uses the dev_txt_write() function, that register the
     39//   write buffer in the relevant TXT chdev queue, and uses a descheduling policy.
    3440///////////////////////////////////////////////////////////////////////////////////
     41// @ channel  : TXT channel.
     42// @ busy     : TXT device acces mode.
     43// @ buf      : buffer containing the characters.
     44// @ nc       : number of characters.
     45// return 0 if success / return -1 if TTY0 busy after 10000 retries.
     46///////////////////////////////////////////////////////////////////////////////////
     47static error_t txt_write( uint32_t  channel,
     48                          uint32_t  busy,
     49                          char    * buffer,
     50                          uint32_t  count )
     51{
     52    if( busy ) return dev_txt_sync_write( channel , buffer , count );
     53    else       return dev_txt_write( channel , buffer , count );
     54
     55
     56//////////////////////////////////////////////////////////////////////////////////////
     57// This static function is called by printk() and user_printk() to build
     58// a formated string.
     59//////////////////////////////////////////////////////////////////////////////////////
     60// @ channel   : channel index.
     61// @ busy      : TXT device access mode.
     62// @ format    : printf like format.
     63// @ args      : format arguments.
     64//////////////////////////////////////////////////////////////////////////////////////
    3565static void kernel_printf( uint32_t   channel,
     66                           uint32_t   busy,
    3667                           char     * format,
    3768                           va_list  * args )
     
    4677        if (i)
    4778        {
    48             dev_txt_sync_write( channel, format, i );
     79            txt_write( channel, busy, format, i );
    4980            format += i;
    5081        }
     
    83114                {
    84115                    val = -val;
    85                     dev_txt_sync_write( channel, "-" , 1 );
     116                    txt_write( channel, busy, "-" , 1 );
    86117                }
    87118                for(i = 0; i < 10; i++)
     
    109140            {
    110141                uint32_t val = va_arg( *args , uint32_t );
    111                 dev_txt_sync_write( channel, "0x" , 2 );
     142                txt_write( channel, busy, "0x" , 2 );
    112143                for(i = 0; i < 8; i++)
    113144                {
    114                     buf[7 - i] = HexaTab[val % 16];
     145                    buf[7 - i] = HexaTab[val & 0xF];
    115146                    if (!(val = (val>>4)))  break;
    116147                }
     
    119150                break;
    120151            }
    121             case ('X'):             /* 32 bits hexadecimal unsigned  on 10 char*/
     152            case ('X'):             /* 32 bits hexadecimal unsigned  on 10 char */
    122153            {
    123154                uint32_t val = va_arg( *args , uint32_t );
    124                 dev_txt_sync_write( channel, "0x" , 2 );
     155                txt_write( channel, busy, "0x" , 2 );
    125156                for(i = 0; i < 8; i++)
    126157                {
    127                     buf[7 - i] = HexaTab[val % 16];
     158                    buf[7 - i] = HexaTab[val & 0xF];
    128159                    val = (val>>4);
    129160                }
     
    135166            {
    136167                uint64_t val = va_arg( *args , uint64_t );
    137                 dev_txt_sync_write( channel, "0x" , 2 );
     168                txt_write( channel, busy, "0x" , 2 );
    138169                for(i = 0; i < 16; i++)
    139170                {
    140                     buf[15 - i] = HexaTab[val % 16];
    141                     if (!(val /= 16))  break;
     171                    buf[15 - i] = HexaTab[val & 0xF];
     172                    if (!(val = (val>>4)))  break;
    142173                }
    143174                len =  i + 1;
    144175                pbuf = &buf[15 - i];
     176                break;
     177            }
     178            case ('L'):           /* 64 bits hexadecimal unsigned on 18 char */
     179            {
     180                uint64_t val = va_arg( *args , uint64_t );
     181                txt_write( channel, busy, "0x" , 2 );
     182                for(i = 0; i < 16; i++)
     183                {
     184                    buf[15 - i] = HexaTab[val & 0xF];
     185                    val = (val>>4);
     186                }
     187                len =  16;
     188                pbuf = buf;
    145189                break;
    146190            }
     
    157201            default:
    158202            {
    159                 dev_txt_sync_write( channel ,
    160                                     "\n[PANIC] in kernel_printf() : illegal format\n", 45 );
     203                txt_write( channel , busy,
     204                           "\n[PANIC] in kernel_printf() : illegal format\n", 45 );
    161205            }
    162206        }
    163207
    164         if( pbuf != NULL ) dev_txt_sync_write( channel, pbuf, len );
     208        if( pbuf != NULL ) txt_write( channel, busy, pbuf, len );
    165209       
    166210        goto printf_text;
     
    169213}  // end kernel_printf()
    170214
    171 ///////////////////////////////////////
    172 void nolock_printk( char* format, ...)
    173 {
    174     va_list   args;
     215////////////////////////////////
     216void printk( char * format, ...)
     217{
     218    va_list       args;
    175219
    176220    // call kernel_printf
    177221    va_start( args , format );
    178     kernel_printf( 0, format , &args );
     222    kernel_printf( 0 , 1 , format , &args );
    179223    va_end( args );
    180224}
    181225
    182 ////////////////////////////////
    183 void printk( char* format, ...)
    184 {
    185     va_list       args;
    186     uint32_t  save_sr;
    187 
    188     // disable IRQs
    189     hal_disable_irq( &save_sr );
    190 
    191     // get TXT0 lock
    192     cluster_t * cluster = LOCAL_CLUSTER;
    193     remote_spinlock_lock( XPTR( cluster->io_cxy , &cluster->txt0_lock ) );
     226/////////////////////////////////////
     227void user_printk( char* format, ...)
     228{
     229    va_list   args;
     230
     231    // get calling thread TXT channel TODO
     232    uint32_t channel = 0;
    194233
    195234    // call kernel_printf
    196235    va_start( args , format );
    197     kernel_printf( 0, format , &args );
    198     va_end( args );
    199 
    200     // release TXT0 lock
    201     remote_spinlock_unlock( XPTR( cluster->io_cxy , &cluster->txt0_lock ) );
    202 
    203     // restore IRQs
    204     hal_restore_irq( save_sr );
    205 }
    206 
    207 /////////////////////////////////////
    208 void user_printk( char* format, ...)
    209 {
    210     va_list   args;
    211 
    212     // get calling thread TXT channel TODO
    213     uint32_t channel = 0;
    214 
    215     // call kernel_printf
    216     va_start( args , format );
    217     kernel_printf( channel, format , &args );
     236    kernel_printf( channel, 0 , format , &args );
    218237    va_end( args );
    219238}
    220239
    221 
     240///////////////////////////////////////////
     241inline void assert( bool_t       condition,
     242                    const char * function_name,
     243                    char       * string )
     244{
     245    if( condition == false )
     246    {
     247        printk("\n[PANIC] in %s : %s\n" , function_name , string );
     248        hal_core_sleep();
     249    }
     250}
    222251
    223252// Local Variables:
Note: See TracChangeset for help on using the changeset viewer.