source: soft/giet_vm/applications/shell/main.c @ 589

Last change on this file since 589 was 589, checked in by alain, 9 years ago

Modify all applications to support two new rules:
1) introduce a local Makefile for each application.
2) change "application.elf" name to "application/appli.elf" name in the application.py" file.
Introduce the shell application.

File size: 4.8 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////////
2// File   : main.c   (for shell application)
3// Date   : february 2014
4// author : Alain Greiner
5///////////////////////////////////////////////////////////////////////////////////////
6// This single thread application plays with files to test the FAT32.
7///////////////////////////////////////////////////////////////////////////////////////
8
9#include "stdio.h"
10#include "malloc.h"
11
12#define NLINES   256
13#define NPIXELS  256
14
15unsigned char buf[NLINES*NPIXELS];
16
17//////////////////////////////////////////
18__attribute__ ((constructor)) void main()
19//////////////////////////////////////////
20{
21    giet_shr_printf("\n[SHELL] Enter at cycle %d\n", giet_proctime() );
22
23    /////////////// diplay disk content
24    giet_shr_printf("\n#############################################################");
25    giet_fat_list( "/" );
26    giet_fat_list( "/misc" );
27    giet_fat_list( "/home" );
28    giet_shr_printf("#############################################################\n");
29
30    /////////////// open lena_256.raw
31    int fd_lena = giet_fat_open( "/misc/lena_256.raw" , O_RDONLY );
32    if (fd_lena < 0 ) 
33    {
34        giet_exit("cannot open file lena_256.raw");
35    }
36    else
37    {
38        giet_shr_printf("\n[SHELL] open lena_256.raw\n");
39    }
40
41    /////////////// open copy.raw
42    int fd_copy = giet_fat_open( "/home/copy.raw" , O_CREATE );
43    if (fd_copy < 0 )
44    {
45        giet_exit("cannot open file copy.raw");
46    }
47    else
48    {
49        giet_shr_printf("\n[SHELL] open copy.raw\n");
50    }
51
52    //////////////// load lena_256.raw
53    if ( giet_fat_lseek( fd_lena , 0 , SEEK_SET ) )
54    {
55        giet_exit("cannot seek lena_256.raw");
56    }
57
58    if ( giet_fat_read( fd_lena , buf , NLINES*NPIXELS ) != NLINES*NPIXELS )
59    {
60        giet_exit("cannot read lena_256.raw");
61    }
62    else
63    {
64        giet_shr_printf("\n[SHELL] lena_256.raw loaded from device\n");
65    }
66
67    ////////////// store copy.raw
68    if ( giet_fat_lseek( fd_copy , 0 , SEEK_SET ) )
69    {
70        giet_exit("cannot seek copy.raw");
71    }
72
73    if ( giet_fat_write( fd_copy , buf , NLINES*NPIXELS ) != NLINES*NPIXELS )
74    {
75        giet_exit("cannot write copy.raw");
76    }
77    else
78    {
79        giet_shr_printf("\n[SHELL] copy.raw stored to device\n");
80    }
81
82    ///////////// close lena_256.raw
83    if ( giet_fat_close( fd_lena ) )
84    {
85        giet_exit("cannot close lena_256.raw");
86    }
87    else 
88    {
89        giet_shr_printf("\n[SHELL] lena_256.raw closed\n");
90    }
91
92    ///////////// close copy.raw
93    if ( giet_fat_close( fd_copy ) )
94    {
95        giet_exit("cannot close copy.raw");
96    }
97    else 
98    {
99        giet_shr_printf("\n[SHELL] copy.raw closed\n");
100    }
101
102    ////////////// display disk content
103    giet_shr_printf("\n#############################################################");
104    giet_fat_list( "/" );
105    giet_fat_list( "/misc" );
106    giet_fat_list( "/home" );
107    giet_shr_printf("#############################################################\n");
108
109    ///////////// rename copy.raw
110    if ( giet_fat_rename( "/home/copy.raw" , "/misc/copy_lena.raw" ) )
111    {
112        giet_exit("cannot rename /home/copy.raw");
113    }
114    else 
115    {
116        giet_shr_printf("\n[SHELL] /home/copy.raw renamed to /misc/copy_lena.raw\n");
117    }
118   
119    ////////////// display disk content
120    giet_shr_printf("\n#############################################################");
121    giet_fat_list( "/" );
122    giet_fat_list( "/misc" );
123    giet_fat_list( "/home" );
124    giet_shr_printf("#############################################################\n");
125
126    ///////////// remove home
127    if ( giet_fat_remove( "/home" , 1 ) )
128    {
129        giet_exit("cannot remove /home");
130    }
131    else 
132    {
133        giet_shr_printf("\n[SHELL] /home removed from file system\n");
134    }
135   
136    ////////////// display disk content
137    giet_shr_printf("\n#############################################################");
138    giet_fat_list( "/" );
139    giet_fat_list( "/misc" );
140    giet_shr_printf("#############################################################\n");
141
142    //////////// create new_home
143    if ( giet_fat_mkdir( "/new_home" ) )
144    {
145        giet_exit("cannot create /new_home");
146    }
147    else 
148    {
149        giet_shr_printf("\n[SHELL] /new_home created in file system\n");
150    }
151   
152    ////////////// display disk content
153    giet_shr_printf("\n#############################################################");
154    giet_fat_list( "/" );
155    giet_fat_list( "/misc" );
156    giet_fat_list( "/new_home" );
157    giet_shr_printf("#############################################################\n");
158
159    giet_exit("Completed");
160
161} // end main()
162
163// Local Variables:
164// tab-width: 3
165// c-basic-offset:
166// c-file-offsets:((innamespace . 0)(inline-open . 0))
167// indent-tabs-mode: nil
168// End:
169
170// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
171
172
173
Note: See TracBrowser for help on using the repository browser.