OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [usb/] [msd/] [slave/] [current/] [tests/] [usbs_test_ramdisk.c] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      usb_test_ramdisk.c
4
//
5
//      Example application for the USB MSD layer in eCos.
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 2008 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later
16
// version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
//
27
// As a special exception, if other files instantiate templates or use
28
// macros or inline functions from this file, or you compile this file
29
// and link it with other works to produce a work based on this file,
30
// this file does not by itself cause the resulting work to be covered by
31
// the GNU General Public License. However the source code for this file
32
// must still be made available in accordance with section (3) of the GNU
33
// General Public License v2.
34
//
35
// This exception does not invalidate any other reasons why a work based
36
// on this file might be covered by the GNU General Public License.
37
// -------------------------------------------
38
// ####ECOSGPLCOPYRIGHTEND####
39
//===========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    ccoutand
43
// Contributors:
44
// Date:         2010-06-27
45
// Description:  USB Slave Mass Storage example application.
46
//
47
//####DESCRIPTIONEND####
48
//===========================================================================
49
 
50
#include <pkgconf/system.h>
51
#include <pkgconf/hal.h>
52
 
53
#if defined(CYGPKG_FS_FAT)
54
#include <pkgconf/io_fileio.h>
55
#include <pkgconf/fs_fat.h>
56
#endif
57
 
58
#include <pkgconf/io_usb_slave_msd.h>
59
#include <pkgconf/kernel.h>
60
#include <cyg/kernel/kapi.h>
61
#include <cyg/hal/hal_arch.h>
62
#include <cyg/infra/diag.h>
63
#include <cyg/io/usb/usbs_msd_io.h>
64
#include <cyg/io/io.h>
65
#include <cyg/io/devtab.h>
66
#include <cyg/io/disk.h>
67
 
68
#include <stdio.h>
69
#include <stdlib.h>
70
 
71
#if defined(CYGPKG_FS_FAT)
72
#include <cyg/infra/cyg_trac.h>
73
#include <cyg/infra/cyg_ass.h>
74
#include <cyg/infra/testcase.h>
75
#include <unistd.h>
76
#include <dirent.h>
77
#include <errno.h>
78
#include <cyg/fileio/fileio.h>
79
#include <cyg/fs/fatfs.h>
80
#endif
81
 
82
#if defined(CYGBLD_IO_USB_SLAVE_MSD_DEBUG)
83
#define DBG diag_printf
84
#else
85
#define DBG (1) ? (void)0 : diag_printf
86
#endif
87
 
88
// ----------------------------------------------------------------------------
89
// FAT12 file-system FBR, FAT and ROOT directory entries are hardcoded
90
// and later copied over to the RAM disk
91
//
92
 
93
#define USBS_MSD_RAMDISK_BLOCKLEN   512
94
#define USBS_MSD_RAMDISK_NUM_BLOCK   32
95
 
96
// Allocate space for the RAM disk
97
static char ram_disk[ USBS_MSD_RAMDISK_BLOCKLEN * USBS_MSD_RAMDISK_NUM_BLOCK ] __attribute__((aligned(4)));
98
 
99
// FAT12 Boot Record
100
const char fat12_br[] = {
101
   0xEB, 0x3C, 0x90,                               // Field for Bootable Media
102
   0x4D, 0x53, 0x57, 0x49, 0x4E, 0x34, 0x2E, 0x31, // MSWIN4.1
103
   0x00, 0x02,                                     // 512 bytes sector
104
   0x01,                                           // 1 sector per cluster
105
   0x01, 0x00,                                     // 1 reserved sector (including MBR)
106
   0x02,                                           // 2 FATs
107
   0x40, 0x00,                                     // 64 entries
108
   USBS_MSD_RAMDISK_NUM_BLOCK, 0x00,               // Number of sectors is less than 32K: 32 sectors
109
   0xF0,                                           // Removable media
110
   0x01, 0x00,                                     // 1sector per FAT
111
   0x00, 0x00,                                     // Sector per track (not used in LBA)
112
   0x00, 0x00,                                     // Number of Heads (not used in LBA)
113
   0x00, 0x00, 0x00, 0x00,                         // Hidden sector
114
   0x00, 0x00, 0x00, 0x00,                         // Number of sectors is more than 32K
115
   0x00,                                           // Logical drive number
116
   0x00,                                           // Reserved
117
   0x29,                                           // Extended boot signature
118
   0x04, 0x03, 0x02, 0x01,                         // Serial Number
119
   0x65, 0x43, 0x6F, 0x73, 0x20, 0x64, 0x69, 0x73, // VOLUME: eCos disk
120
   0x6B, 0x20, 0x20,
121
   0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20  // FAT12
122
};
123
 
124
// MBR and Volume sector signature
125
const char mbr_signature[] = {
126
   0x55, 0xAA
127
};
128
 
129
// Partition table
130
const char partition_tbl[] = {
131
   // First (FAT12)
132
   0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
133
   0x01, 0x00, 0x00, 0x00, (USBS_MSD_RAMDISK_NUM_BLOCK-1), 0x00, 0x00, 0x00,
134
   // Second
135
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137
   // Third
138
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140
   // Fourth
141
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
143
};
144
 
145
// Root directory (eCos-3.0)
146
const char root_dir[] = {
147
   0x65, 0x43, 0x6F, 0x73, 0x2d, 0x33, 0x2e, 0x30,
148
   0x20, 0x20, 0x20, 0x28, 0x00, 0x00, 0x00, 0x00,
149
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x9e,
150
   0x65, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
151
};
152
 
153
// File-system Allocation Table
154
const char fat[] = {
155
  0xF0, 0xff, 0xff
156
};
157
 
158
// Initialize FAT12
159
static void
160
init_fat12_disk( char *start_addr )
161
{
162
  char * dst = start_addr;
163
 
164
  // Copy partition table
165
  dst = start_addr + 446;
166
  memcpy(dst, partition_tbl, 64);
167
 
168
  // Copy signature
169
  dst = start_addr + (USBS_MSD_RAMDISK_BLOCKLEN - 2 );
170
  memcpy(dst, mbr_signature, 2);
171
 
172
  // Copy FBR
173
  dst = start_addr + USBS_MSD_RAMDISK_BLOCKLEN;
174
  memcpy(dst, fat12_br, 62);
175
 
176
  // Copy signature
177
  dst = start_addr + (( USBS_MSD_RAMDISK_BLOCKLEN * 2 ) - 2 );
178
  memcpy(dst, mbr_signature, 2);
179
 
180
  // Copy FAT0
181
  dst = start_addr + ( USBS_MSD_RAMDISK_BLOCKLEN * 2);
182
  memcpy(dst, fat, 3);
183
 
184
  // Copy FAT1
185
  dst = start_addr + ( USBS_MSD_RAMDISK_BLOCKLEN * 3);
186
  memcpy(dst, fat, 3);
187
 
188
  // Copy Root directory
189
  dst = start_addr + ( USBS_MSD_RAMDISK_BLOCKLEN * 4);
190
  memcpy(dst, root_dir, 32);
191
 
192
}
193
 
194
 
195
// ----------------------------------------------------------------------------
196
// Create a tiny "RAM disk" device
197
//
198
//
199
 
200
#define RAM_DISK_NAME "/dev/ramdisk0/"
201
 
202
typedef struct {
203
    volatile cyg_uint8 *base;
204
    cyg_uint16 size;
205
} ram_disk_info_t;
206
 
207
static cyg_bool ram_disk_init(struct cyg_devtab_entry *tab);
208
 
209
static Cyg_ErrNo ram_disk_bread(disk_channel *chan,
210
                              void         *buf,
211
                              cyg_uint32    len,
212
                              cyg_uint32    block_num);
213
 
214
 
215
static Cyg_ErrNo ram_disk_bwrite(disk_channel *chan,
216
                               const void   *buf,
217
                               cyg_uint32    len,
218
                               cyg_uint32    block_num);
219
 
220
static Cyg_ErrNo ram_disk_get_config(disk_channel *chan,
221
                               cyg_uint32    key,
222
                               const void   *xbuf,
223
                               cyg_uint32   *len);
224
 
225
static Cyg_ErrNo ram_disk_set_config(disk_channel *chan,
226
                               cyg_uint32    key,
227
                               const void   *xbuf,
228
                               cyg_uint32   *len);
229
 
230
static Cyg_ErrNo ram_disk_lookup(struct cyg_devtab_entry **tab,
231
                                struct cyg_devtab_entry  *sub_tab,
232
                                const char               *name);
233
 
234
DISK_FUNS(ram_disk_funs,
235
          ram_disk_bread,
236
          ram_disk_bwrite,
237
          ram_disk_get_config,
238
          ram_disk_set_config
239
);
240
 
241
DISK_CONTROLLER(ram_disk_controller, ram_disk_controller);
242
 
243
#define RAM_DISK_INSTANCE(_number_,_base_,_mbr_supp_,_name_)    \
244
static ram_disk_info_t ram_disk_info##_number_ = {              \
245
    base: (volatile cyg_uint8 *)_base_,                         \
246
};                                                              \
247
DISK_CHANNEL(ram_disk_channel##_number_,                        \
248
             ram_disk_funs,                                     \
249
             ram_disk_info##_number_,                           \
250
             ram_disk_controller,                               \
251
             _mbr_supp_,                                        \
252
             1                                                  \
253
);                                                              \
254
BLOCK_DEVTAB_ENTRY(ram_disk_io##_number_,                       \
255
             _name_,                                            \
256
             0,                                                 \
257
             &cyg_io_disk_devio,                                \
258
             ram_disk_init,                                     \
259
             ram_disk_lookup,                                   \
260
             &ram_disk_channel##_number_                        \
261
);
262
 
263
RAM_DISK_INSTANCE(0, 0, true, RAM_DISK_NAME);
264
 
265
 
266
// ----------------------------------------------------------------------------
267
static void
268
read_data(volatile cyg_uint8  *base,
269
          void                *buf,
270
          cyg_uint32           len)
271
{
272
    cyg_uint8 *dst = (cyg_uint8 *)buf;
273
    cyg_uint8 *src = (cyg_uint8 *)base;
274
    cyg_uint32 i = 0;
275
 
276
    for (i = 0; i < len; i += 1)
277
    {
278
        *dst = *src;
279
        dst = dst + 1; src = src + 1;
280
    }
281
 
282
}
283
 
284
static void
285
write_data(volatile cyg_uint8  *base,
286
           const void          *buf,
287
           cyg_uint16           len)
288
{
289
    cyg_uint8 *dst = (cyg_uint8 *)base;
290
    cyg_uint8 *src = (cyg_uint8 *)buf;
291
    cyg_uint32 i = 0;
292
 
293
    for (i = 0; i < len; i += 1)
294
    {
295
        *dst = *src;
296
         dst = dst + 1; src = src + 1;
297
    }
298
}
299
 
300
// ----------------------------------------------------------------------------
301
static cyg_bool
302
ram_disk_init(struct cyg_devtab_entry *tab)
303
{
304
    disk_channel           *chan = (disk_channel *) tab->priv;
305
    ram_disk_info_t         *info = (ram_disk_info_t *) chan->dev_priv;
306
    cyg_disk_identify_t     ident;
307
 
308
    if (chan->init)
309
        return true;
310
 
311
    info->base = (volatile cyg_uint8 *) &ram_disk[0];
312
    info->size = USBS_MSD_RAMDISK_BLOCKLEN * USBS_MSD_RAMDISK_NUM_BLOCK;
313
 
314
    DBG("RAM DISK ( %p ) init\n", info->base);
315
 
316
    init_fat12_disk( &ram_disk[0] );
317
 
318
    ident.cylinders_num   =  0;
319
    ident.heads_num       =  0;
320
    ident.lba_sectors_num = USBS_MSD_RAMDISK_NUM_BLOCK-2;
321
    ident.phys_block_size = USBS_MSD_RAMDISK_BLOCKLEN;
322
    ident.max_transfer    = USBS_MSD_RAMDISK_BLOCKLEN;
323
 
324
    if (!(chan->callbacks->disk_init)(tab))
325
        return false;
326
 
327
    if (ENOERR != (chan->callbacks->disk_connected)(tab, &ident))
328
        return false;
329
 
330
    return true;
331
}
332
 
333
static Cyg_ErrNo
334
ram_disk_lookup(struct cyg_devtab_entry **tab,
335
               struct cyg_devtab_entry  *sub_tab,
336
               const char *name)
337
{
338
    disk_channel *chan = (disk_channel *) (*tab)->priv;
339
    return (chan->callbacks->disk_lookup)(tab, sub_tab, name);
340
}
341
 
342
static Cyg_ErrNo
343
ram_disk_bread(disk_channel *chan,
344
             void         *buf,
345
             cyg_uint32    len,
346
             cyg_uint32    block_num)
347
{
348
    ram_disk_info_t *info = (ram_disk_info_t *)chan->dev_priv;
349
    volatile cyg_uint8 *src = info->base + USBS_MSD_RAMDISK_BLOCKLEN * block_num;
350
    cyg_uint32 len_byte = len * USBS_MSD_RAMDISK_BLOCKLEN;
351
 
352
    if ( len_byte == 0 )
353
      return EINVAL;
354
 
355
    read_data(src, buf, len_byte);
356
 
357
    return ENOERR;
358
}
359
 
360
static Cyg_ErrNo
361
ram_disk_bwrite(disk_channel *chan,
362
              const void   *buf,
363
              cyg_uint32    len,
364
              cyg_uint32    block_num)
365
{
366
    ram_disk_info_t *info = (ram_disk_info_t *)chan->dev_priv;
367
    volatile cyg_uint8 *dst = info->base + USBS_MSD_RAMDISK_BLOCKLEN * block_num;
368
    cyg_uint32 len_byte = len * USBS_MSD_RAMDISK_BLOCKLEN;
369
 
370
    if ( len_byte == 0 )
371
      return EINVAL;
372
 
373
    write_data(dst, buf, len_byte);
374
 
375
    return ENOERR;
376
}
377
 
378
static Cyg_ErrNo
379
ram_disk_get_config(disk_channel *chan,
380
                   cyg_uint32    key,
381
                   const void   *xbuf,
382
                   cyg_uint32   *len)
383
{
384
    return -EINVAL;
385
}
386
 
387
static Cyg_ErrNo
388
ram_disk_set_config(disk_channel *chan,
389
                   cyg_uint32    key,
390
                   const void   *xbuf,
391
                   cyg_uint32   *len)
392
{
393
    return -EINVAL;
394
}
395
 
396
 
397
// ----------------------------------------------------------------------------
398
// In case FAT file-system package is included, this application will try
399
// to play with the file-system before it is mounted as a mass storage device.
400
// The following code is a copy of the fatfs1.c from the fs/test directory
401
//
402
#if defined(CYGPKG_FS_FAT)
403
 
404
#define SHOW_RESULT( _fn, _res ) \
405
  DBG("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):"");
406
 
407
#define IOSIZE  100
408
 
409
//==========================================================================
410
 
411
void checkcwd( const char *cwd )
412
{
413
    static char cwdbuf[PATH_MAX];
414
    char *ret;
415
 
416
    ret = getcwd( cwdbuf, sizeof(cwdbuf));
417
    if( ret == NULL ) SHOW_RESULT( getcwd, (int)ret );
418
 
419
    if( strcmp( cwdbuf, cwd ) != 0 )
420
    {
421
        DBG( "cwdbuf %s cwd %s\n",cwdbuf, cwd );
422
        CYG_TEST_FAIL( "Current directory mismatch");
423
    }
424
}
425
 
426
//==========================================================================
427
 
428
static void listdir( char *name, int statp, int numexpected, int *numgot )
429
{
430
    int err;
431
    DIR *dirp;
432
    int num=0;
433
 
434
    DBG("<INFO>: reading directory %s\n",name);
435
 
436
    dirp = opendir( name );
437
    if( dirp == NULL ) SHOW_RESULT( opendir, -1 );
438
 
439
    for(;;)
440
    {
441
        struct dirent *entry = readdir( dirp );
442
 
443
        if( entry == NULL )
444
            break;
445
        num++;
446
        DBG("<INFO>: entry %14s",entry->d_name);
447
#ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE
448
        DBG(" d_type %2x", entry->d_type);
449
#endif
450
        if( statp )
451
        {
452
            char fullname[PATH_MAX];
453
            struct stat sbuf;
454
 
455
            if( name[0] )
456
            {
457
                strcpy(fullname, name );
458
                if( !(name[0] == '/' && name[1] == 0 ) )
459
                    strcat(fullname, "/" );
460
            }
461
            else fullname[0] = 0;
462
 
463
            strcat(fullname, entry->d_name );
464
 
465
            err = stat( fullname, &sbuf );
466
            if( err < 0 )
467
            {
468
                if( errno == ENOSYS )
469
                    DBG(" <no status available>");
470
                else SHOW_RESULT( stat, err );
471
            }
472
            else
473
            {
474
                DBG(" [mode %08x ino %08x nlink %d size %ld]",
475
                            sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,(long)sbuf.st_size);
476
            }
477
#ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE
478
            if ((entry->d_type & S_IFMT) != (sbuf.st_mode & S_IFMT))
479
              CYG_TEST_FAIL("File mode's don't match between dirent and stat");
480
#endif
481
        }
482
 
483
        DBG("\n");
484
    }
485
 
486
    err = closedir( dirp );
487
    if( err < 0 ) SHOW_RESULT( stat, err );
488
    if (numexpected >= 0 && num != numexpected)
489
        CYG_TEST_FAIL("Wrong number of dir entries\n");
490
    if ( numgot != NULL )
491
        *numgot = num;
492
}
493
 
494
//==========================================================================
495
 
496
static void createfile( char *name, size_t size )
497
{
498
    char buf[IOSIZE];
499
    int fd;
500
    ssize_t wrote;
501
    int i;
502
    int err;
503
 
504
    DBG("<INFO>: create file %s size %zd \n",name,size);
505
 
506
    err = access( name, F_OK );
507
    if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
508
 
509
    for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256;
510
 
511
    fd = open( name, O_WRONLY|O_CREAT );
512
    if( fd < 0 ) SHOW_RESULT( open, fd );
513
 
514
    while( size > 0 )
515
    {
516
        ssize_t len = size;
517
        if ( len > IOSIZE ) len = IOSIZE;
518
 
519
        wrote = write( fd, buf, len );
520
        if( wrote != len ) SHOW_RESULT( write, (int)wrote );
521
 
522
        size -= wrote;
523
    }
524
 
525
    err = close( fd );
526
    if( err < 0 ) SHOW_RESULT( close, err );
527
}
528
 
529
//==========================================================================
530
 
531
static void checkfile( char *name )
532
{
533
    char buf[IOSIZE];
534
    int fd;
535
    ssize_t done;
536
    int i;
537
    int err;
538
    off_t pos = 0;
539
 
540
    DBG("<INFO>: check file %s\n",name);
541
 
542
    err = access( name, F_OK );
543
    if( err != 0 ) SHOW_RESULT( access, err );
544
 
545
    fd = open( name, O_RDONLY );
546
    if( fd < 0 ) SHOW_RESULT( open, fd );
547
 
548
    for(;;)
549
    {
550
        done = read( fd, buf, IOSIZE );
551
        if( done < 0 ) SHOW_RESULT( read, (int)done );
552
 
553
        if( done == 0 ) break;
554
 
555
        for( i = 0; i < done; i++ )
556
            if( buf[i] != i%256 )
557
            {
558
                DBG("buf[%ld+%d](%02x) != %02x\n",pos,i,buf[i],i%256);
559
                CYG_TEST_FAIL("Data read not equal to data written\n");
560
            }
561
 
562
        pos += done;
563
    }
564
 
565
    err = close( fd );
566
    if( err < 0 ) SHOW_RESULT( close, err );
567
}
568
 
569
//==========================================================================
570
 
571
static void copyfile( char *name2, char *name1 )
572
{
573
 
574
    int err;
575
    char buf[IOSIZE];
576
    int fd1, fd2;
577
    ssize_t done, wrote;
578
 
579
    DBG("<INFO>: copy file %s -> %s\n",name2,name1);
580
 
581
    err = access( name1, F_OK );
582
    if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
583
 
584
    err = access( name2, F_OK );
585
    if( err != 0 ) SHOW_RESULT( access, err );
586
 
587
    fd1 = open( name1, O_WRONLY|O_CREAT );
588
    if( fd1 < 0 ) SHOW_RESULT( open, fd1 );
589
 
590
    fd2 = open( name2, O_RDONLY );
591
    if( fd2 < 0 ) SHOW_RESULT( open, fd2 );
592
 
593
    for(;;)
594
    {
595
        done = read( fd2, buf, IOSIZE );
596
        if( done < 0 ) SHOW_RESULT( read, (int)done );
597
 
598
        if( done == 0 ) break;
599
 
600
        wrote = write( fd1, buf, done );
601
        if( wrote != done ) SHOW_RESULT( write, (int) wrote );
602
 
603
        if( wrote != done ) break;
604
    }
605
 
606
    err = close( fd1 );
607
    if( err < 0 ) SHOW_RESULT( close, err );
608
 
609
    err = close( fd2 );
610
    if( err < 0 ) SHOW_RESULT( close, err );
611
 
612
}
613
 
614
//==========================================================================
615
 
616
static void comparefiles( char *name2, char *name1 )
617
{
618
    int err;
619
    char buf1[IOSIZE];
620
    char buf2[IOSIZE];
621
    int fd1, fd2;
622
    ssize_t done1, done2;
623
    int i;
624
 
625
    DBG("<INFO>: compare files %s == %s\n",name2,name1);
626
 
627
    err = access( name1, F_OK );
628
    if( err != 0 ) SHOW_RESULT( access, err );
629
 
630
    err = access( name1, F_OK );
631
    if( err != 0 ) SHOW_RESULT( access, err );
632
 
633
    fd1 = open( name1, O_RDONLY );
634
    if( fd1 < 0 ) SHOW_RESULT( open, fd1 );
635
 
636
    fd2 = open( name2, O_RDONLY );
637
    if( fd2 < 0 ) SHOW_RESULT( open, fd2 );
638
 
639
    for(;;)
640
    {
641
        done1 = read( fd1, buf1, IOSIZE );
642
        if( done1 < 0 ) SHOW_RESULT( read, (int)done1 );
643
 
644
        done2 = read( fd2, buf2, IOSIZE );
645
        if( done2 < 0 ) SHOW_RESULT( read, (int)done2 );
646
 
647
        if( done1 != done2 )
648
            DBG("Files different sizes\n");
649
 
650
        if( done1 == 0 ) break;
651
 
652
        for( i = 0; i < done1; i++ )
653
            if( buf1[i] != buf2[i] )
654
            {
655
                DBG("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]);
656
                CYG_TEST_FAIL("Data in files not equal\n");
657
            }
658
    }
659
 
660
    err = close( fd1 );
661
    if( err < 0 ) SHOW_RESULT( close, err );
662
 
663
    err = close( fd2 );
664
    if( err < 0 ) SHOW_RESULT( close, err );
665
 
666
}
667
 
668
#endif
669
 
670
 
671
 
672
// ----------------------------------------------------------------------------
673
// Entry point of the test application. If the FAT file-system package is
674
// included, the file-system is mounted and tested before the USB Mass Storage
675
// service is started.
676
//
677
// Once the mass storage device is mounted on the host computer, 2 files
678
// (foo and fee) and one directory (bar) should appear in the device
679
//
680
 
681
int cyg_start(void)
682
{
683
#if defined(CYGPKG_FS_FAT)
684
  int err;
685
  int existingdirents=-1;
686
#endif
687
 
688
  DBG("Start USB MSD application\n\r");
689
 
690
#if defined(CYGPKG_FS_FAT)
691
 
692
  // Mount RAM disk partition 1
693
  err = mount( "/dev/ramdisk0/1", "/", "fatfs" );
694
 
695
  if( err < 0 )
696
     SHOW_RESULT( mount, err );
697
 
698
  err = chdir( "/" );
699
  if( err < 0 )
700
     SHOW_RESULT( chdir, err );
701
 
702
  checkcwd( "/" );
703
 
704
  // Display list of all files/directories from root
705
  listdir( "/", true, -1, &existingdirents );
706
 
707
  // Play around with the file-system, create / copy /
708
  // compare files
709
  createfile( "/foo", 1000 );
710
  checkfile( "foo" );
711
  copyfile( "foo", "fee" );
712
  checkfile( "fee" );
713
  comparefiles( "foo", "/fee" );
714
  DBG("<INFO>: mkdir bar\n");
715
 
716
  // Create new directory
717
  err = mkdir( "/bar", 0 );
718
  if( err < 0 )
719
     SHOW_RESULT( mkdir, err );
720
 
721
  // Display list of all files/directories from root
722
  listdir( "/" , true, existingdirents+3, NULL );
723
 
724
  // Umount file-system
725
  err = umount( "/" );
726
 
727
  if( err < 0 )
728
     SHOW_RESULT( umount, err );
729
 
730
#endif
731
 
732
  // Start Mass Storage Service
733
  usbs_msd_start();
734
 
735
  // Start scheduler
736
  cyg_scheduler_start();
737
 
738
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.