Changeset 782 for soft


Ignore:
Timestamp:
Feb 7, 2016, 8:23:41 PM (8 years ago)
Author:
alain
Message:

1) Introduce the string library.
2) Introduce a heap in the shell application.

Location:
soft/giet_vm/applications
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/mjpeg/mjpeg.c

    r772 r782  
    2626#include <malloc.h>
    2727#include <stdlib.h>
     28#include <string.h>
    2829#include "mjpeg.h"
    2930#include <mapping_info.h>     // for coprocessor types and modes
  • soft/giet_vm/applications/shell/shell.c

    r775 r782  
    11///////////////////////////////////////////////////////////////////////////////////////
    2 // File   : shell.c   
    3 // Date   : july 2015
    4 // author : Clément Guérin
     2// File    : shell.c   
     3// Date    : july 2015
     4// authors : Clément Guérin and Alain Greiner
    55///////////////////////////////////////////////////////////////////////////////////////
    6 // Simple shell for GIET_VM.
     6// Simple shell for the GIET_VM.
    77///////////////////////////////////////////////////////////////////////////////////////
    88
     
    1010#include "stdlib.h"
    1111#include "malloc.h"
     12#include "string.h"
    1213
    1314#define BUF_SIZE    (256)        // buffer for one command
    1415#define MAX_ARGS    (32)         // max number of arguments in a command
     16#define FIFO_SIZE   (1024)       // FIFO depth for recursive ls
    1517
    1618
     
    4749}
    4850
     51
    4952/////////////////////////////////////////
    5053static void cmd_ls(int argc, char** argv)
    5154{
    52     int            fd;
    53     int            rec;
    54     char*          pathname;
    55     fat_dirent_t   entry;
    56 
     55    fat_dirent_t    entry;
     56    unsigned int    recursive;
     57    char*           paths[FIFO_SIZE];
     58    unsigned int    ptr = 0;
     59    unsigned int    ptw = 0;
     60
     61    // analyse arguments
    5762    if (argc == 2)
    5863    {
    59         rec = 0;
    60         pathname = argv[1];
     64        // allocate a buffer for root directory
     65        // pathname, and push it in FIFO
     66        paths[ptw] = malloc( strlen(argv[1]) );
     67        strcpy( paths[ptw] , argv[1] );
     68
     69giet_tty_printf("\n@@@ arg = %s / path = %s\n", argv[1] , paths[ptw] );
     70
     71        ptw = (ptw + 1) % FIFO_SIZE;
     72
     73        // not recursive
     74        recursive = 0;
    6175    }
    6276    else if ( (argc == 3) && (strcmp( argv[1] , "-r" ) == 0) )
    6377    {
    64         rec = 1;
    65         pathname = argv[2];
    66 
    67         giet_tty_printf("  error : recursive mode not supported yet\n");
    68         return;
     78        // allocate a buffer for root directory
     79        // pathname, and push it in FIFO
     80        paths[ptw] = malloc( strlen(argv[2]) );
     81        strcpy( paths[ptw] , argv[2] );
     82        ptw = (ptw + 1) % FIFO_SIZE;
     83
     84        // recursive
     85        recursive = 1;
    6986    }
    7087    else
     
    7491    }
    7592
    76     fd  = giet_fat_opendir( pathname );
    77 
    78     if (fd < 0)
    79     {
    80         giet_tty_printf("  error : cannot open %s / err = %d)\n", argv[1], fd);
    81         return;
    82     }
    83 
    84     while (giet_fat_readdir(fd, &entry) == 0)
    85     {
    86         if (entry.is_dir) giet_tty_printf("dir ");
    87         else              giet_tty_printf("file");
    88 
    89         giet_tty_printf(" | size = %d \t| cluster = %x \t| %s\n",
    90                         entry.size, entry.cluster, entry.name );
    91     }
    92 
    93     giet_fat_closedir(fd);
    94 }
     93    // loop on registered directories
     94    do
     95    {
     96        // open directory
     97        int fd  = giet_fat_opendir( paths[ptr] );
     98        if (fd < 0)
     99        {
     100            giet_tty_printf("  error : cannot open %s\n", paths[ptr] );
     101            return;
     102        }
     103
     104        // display directory pathname
     105        giet_tty_printf("*** %s ***\n", paths[ptr] );
     106
     107        // loop on directory entries
     108        while (giet_fat_readdir(fd, &entry) == 0)
     109        {
     110            // display entry
     111            if ( entry.is_dir ) giet_tty_printf("dir ");
     112            else                giet_tty_printf("file");
     113            giet_tty_printf(" | size = %d \t| cluster = %x \t| %s\n",
     114                            entry.size, entry.cluster, entry.name );
     115
     116            // allocate a buffer for subdirectory pathname
     117            // and push it in FIFO if required
     118            if ( entry.is_dir && recursive &&
     119                 ( strcmp( entry.name , "." ) != 0 ) &&
     120                 ( strcmp( entry.name , ".." ) != 0 ) )
     121            {
     122                // check FIFO full
     123                if ( ((ptr - ptw) % FIFO_SIZE) == 1 )
     124                {
     125                    giet_tty_printf("   sorry, not enough memory for recursive ls\n");
     126                    return;
     127                }
     128
     129                unsigned int length = strlen(paths[ptr]) + strlen(entry.name) + 2;
     130                paths[ptw] = malloc( length );
     131                if ( strcmp( paths[ptr] , "/" ) == 0 )
     132                {
     133                    snprintf( paths[ptw] , length , "/%s" , entry.name );
     134                }
     135                else
     136                {
     137                    snprintf( paths[ptw] , length , "%s/%s" , paths[ptr] , entry.name );
     138                }
     139                ptw = (ptw + 1) % FIFO_SIZE;   
     140            }
     141        }  // end loop on entries
     142
     143        // close directory
     144        giet_fat_closedir(fd);
     145
     146        // release the directory pathname buffer
     147        // and pop it from FIFO
     148        free( paths[ptr] );
     149        ptr = (ptr + 1) % FIFO_SIZE;
     150
     151    } while ( ptr != ptw );
     152
     153}  // end cmd_ls()
    95154
    96155////////////////////////////////////////////
     
    504563    giet_tty_alloc( 0 );
    505564    giet_tty_printf( "~~~ shell ~~~\n\n" );
     565
     566    // heap initialisation
     567    unsigned int x_id;                          // x cluster coordinate
     568    unsigned int y_id;                          // y cluster coordinate
     569    unsigned int p_id;                          // local processor index
     570    giet_proc_xyp( &x_id , &y_id , &p_id );
     571    heap_init( x_id , y_id );
    506572
    507573    // display first prompt
  • soft/giet_vm/applications/shell/shell.py

    r768 r782  
    3232
    3333    heap_base  = 0x60000000
    34     heap_size  = 0x00001000     # 4 Kbytes
     34    heap_size  = 0x00040000     # 256 Kbytes
    3535
    3636    mmap_base  = 0x70000000
     
    5757                     local = False, big = True )
    5858
    59     # heap vseg (unused)           
     59    # heap vseg            
    6060    mapping.addVseg( vspace, 'shell_heap', heap_base, heap_size,
    6161                     'C_WU', vtype = 'BUFFER', x = xmap , y = ymap , pseg = 'RAM',
  • soft/giet_vm/applications/transpose/transpose.c

    r778 r782  
    3939#include "stdio.h"
    4040#include "stdlib.h"
     41#include "string.h"
    4142#include "user_barrier.h"
    4243#include "malloc.h"
Note: See TracChangeset for help on using the changeset viewer.