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

Subversion Repositories ion

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

Go to most recent revision | 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
    printf("Loading file '/code.bin' onto RAM at address 0x00000000...\n");
46
 
47
 
48
    WRPORT(0,0x17890083);
49
 
50
 
51
        f_mount(0, &Fatfs);              /* Register volume work area (never fails) */
52
 
53
        rc = f_open(&Fil, "CODE.BIN", FA_READ);
54
        if (rc) die(rc);
55
 
56
        for (;;) {
57
                rc = f_read(&Fil, Buff, sizeof Buff, &br);      /* Read a chunk of file */
58
                if (rc || !br) break;                   /* Error or end of file */
59
                for (i = 0; i < br; i++){       /* Type the data */
60
                        target[wr_index] = Buff[i];
61
            wr_index++;
62
        }
63
        if(wr_index > 256*1024) break;
64
        }
65
        if (rc) die(rc);
66
 
67
 
68
        rc = f_close(&Fil);
69
        if (rc) die(rc);
70
 
71
 
72
    printf("Done. Read %u bytes.\n", wr_index);
73
    printf("Transferring control to address 0x00000000\n\n");
74
 
75
    target_fn();
76
 
77
        for (;;) ;
78
}
79
 
80
 
81
 
82
/*---------------------------------------------------------*/
83
/* User Provided Timer Function for FatFs module           */
84
/*---------------------------------------------------------*/
85
 
86
DWORD get_fattime (void)
87
{
88
        return    ((DWORD)(2012 - 1980) << 25)  /* Year = 2012 */
89
                        | ((DWORD)1 << 21)                              /* Month = 1 */
90
                        | ((DWORD)1 << 16)                              /* Day_m = 1*/
91
                        | ((DWORD)0 << 11)                               /* Hour = 0 */
92
                        | ((DWORD)0 << 5)                                /* Min = 0 */
93
                        | ((DWORD)0 >> 1);                               /* Sec = 0 */
94
}

powered by: WebSVN 2.1.0

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