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

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [sdboot/] [sdboot.c] - Blame information for rev 249

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 246 ja_rd
/*----------------------------------------------------------------------*/
2
/* FatFs sample project for generic microcontrollers (C)ChaN, 2012      */
3
/*----------------------------------------------------------------------*/
4
 
5
#include <stdio.h>
6
#include "../common/fatfs/ff.h"
7
#include "../common/libsoc/src/hw.h"
8
 
9
 
10
FATFS Fatfs;            /* File system object */
11
FIL Fil;                        /* File object */
12
BYTE Buff[128];         /* File read buffer */
13
 
14
 
15
void die (              /* Stop with dying message */
16
        FRESULT rc      /* FatFs return value */
17
)
18
{
19
    switch(rc){
20 248 ja_rd
    case FR_NOT_READY:      printf("Disk absent."); break;
21
    case FR_DISK_ERR:       printf("Low level disk i/o error."); break;
22
    case FR_NO_FILESYSTEM:  printf("No valid filesystem in drive."); break;
23
    case FR_NO_FILE:        printf("File not found."); break;
24
    default:                printf("Failed with rc=%u.", rc); break;
25 246 ja_rd
    }
26
    printf("\n");
27
        for (;;) ;
28
}
29
 
30
 
31
/*-----------------------------------------------------------------------*/
32
/* Program Main                                                          */
33
/*-----------------------------------------------------------------------*/
34
 
35
int main (void)
36
{
37
        FRESULT rc;                             /* Result code */
38
        UINT br, i;
39
    BYTE *target = (BYTE *)0x00000000;
40
    UINT wr_index = 0;
41
    void (*target_fn)(void) = (void *)0x00000000;
42
 
43
 
44
    printf("ION SD loader -- " __DATE__ "\n\n");
45
 
46
 
47
        f_mount(0, &Fatfs);              /* Register volume work area (never fails) */
48
 
49
        rc = f_open(&Fil, "CODE.BIN", FA_READ);
50
        if (rc) die(rc);
51
 
52 249 ja_rd
    printf("Loading file '/code.bin' onto RAM at address 0x00000000...\n");
53
 
54 246 ja_rd
        for (;;) {
55
                rc = f_read(&Fil, Buff, sizeof Buff, &br);      /* Read a chunk of file */
56
                if (rc || !br) break;                   /* Error or end of file */
57
                for (i = 0; i < br; i++){       /* Type the data */
58
                        target[wr_index] = Buff[i];
59
            wr_index++;
60
        }
61
        if(wr_index > 256*1024) break;
62
        }
63
        if (rc) die(rc);
64
 
65
 
66
        rc = f_close(&Fil);
67
        if (rc) die(rc);
68
 
69
 
70
    printf("Done. Read %u bytes.\n", wr_index);
71
    printf("Transferring control to address 0x00000000\n\n");
72
 
73
    target_fn();
74
 
75
        for (;;) ;
76
}
77
 
78
 
79
 
80
/*---------------------------------------------------------*/
81
/* User Provided Timer Function for FatFs module           */
82
/*---------------------------------------------------------*/
83
 
84
DWORD get_fattime (void)
85
{
86
        return    ((DWORD)(2012 - 1980) << 25)  /* Year = 2012 */
87
                        | ((DWORD)1 << 21)                              /* Month = 1 */
88
                        | ((DWORD)1 << 16)                              /* Day_m = 1*/
89
                        | ((DWORD)0 << 11)                               /* Hour = 0 */
90
                        | ((DWORD)0 << 5)                                /* Min = 0 */
91
                        | ((DWORD)0 >> 1);                               /* Sec = 0 */
92
}

powered by: WebSVN 2.1.0

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