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

Subversion Repositories sd_card_controller

[/] [sd_card_controller/] [trunk/] [sw/] [example/] [src/] [sdc_example.c] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 rozpruwacz
/*
2
 * WISHBONE SD Card Controller IP Core
3
 *
4
 * sd_example.c
5
 *
6
 * This file is part of the WISHBONE SD Card
7
 * Controller IP Core project
8 8 rozpruwacz
 * http://opencores.org/project,sd_card_controller
9 3 rozpruwacz
 *
10
 * Description
11
 * Example application using WISHBONE SD Card Controller
12
 * IP Core. The app perform core initialisation,
13
 * mmc/sd card initialisation and then reads one block
14
 * of data from the card.
15
 * This app is using some of code from u-boot project
16
 * (mmc.c and mmc.h)
17
 *
18
 * Author(s):
19
 *     - Marek Czerski, ma.czerski@gmail.com
20
 */
21
/*
22
 *
23
 * Copyright (C) 2013 Authors
24
 *
25
 * This source file may be used and distributed without
26
 * restriction provided that this copyright statement is not
27
 * removed from the file and that any derivative work contains
28
 * the original copyright notice and the associated disclaimer.
29
 *
30
 * This source file is free software; you can redistribute it
31
 * and/or modify it under the terms of the GNU Lesser General
32
 * Public License as published by the Free Software Foundation;
33
 * either version 2.1 of the License, or (at your option) any
34
 * later version.
35
 *
36
 * This source is distributed in the hope that it will be
37
 * useful, but WITHOUT ANY WARRANTY; without even the implied
38
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39
 * PURPOSE. See the GNU Lesser General Public License for more
40
 * details.
41
 *
42
 * You should have received a copy of the GNU Lesser General
43
 * Public License along with this source; if not, download it
44
 * from http://www.opencores.org/lgpl.shtml
45
 */
46
 
47
#include "mmc.h"
48
#include <stdio.h>
49
#include <stdlib.h>
50
 
51
struct mmc * ocsdc_mmc_init(int base_addr, int clk_freq);
52
 
53
#define BLKSIZE 512
54
#define BLKCNT 10
55
 
56
char buff[BLKSIZE*BLKCNT] = {'\0'};
57
 
58
void printHex(const void *lpvbits, const unsigned int n) {
59
    char* data = (char*) lpvbits;
60
    unsigned int i = 0;
61
    char line[17] = {};
62
    printf("%.8X | ", (unsigned int)data);
63
    while ( i < n ) {
64
        line[i%16] = *(data+i);
65
        if ((line[i%16] < 32) || (line[i%16] > 126)) {
66
            line[i%16] = '.';
67
        }
68
        printf("%.2X", (unsigned char)*(data+i));
69
        i++;
70
        if (i%4 == 0) {
71
            if (i%16 == 0) {
72
                if (i < n-1)
73
                    printf(" | %s\n\r%.8X | ", line, (unsigned int)data+i);
74
            } else {
75
                printf(" ");
76
            }
77
        }
78
    }
79
    while (i%16 > 0) {
80
        (i%4 == 0)?printf("   "):printf("  ");
81
        line[i%16] = ' ';
82
        i++;
83
    }
84
    printf(" | %s\n\r", line);
85
}
86
 
87
int main(void) {
88
        printf("Hello World !!!\n\r");
89
 
90
        //init ocsdc driver
91
        struct mmc * drv = ocsdc_mmc_init(0x9e000000, 50000000);
92
        if (!drv) {
93
                printf("ocsdc_mmc_init failed\n\r");
94
                return -1;
95
        }
96
        printf("ocsdc_mmc_init success\n\r");
97
 
98
        drv->has_init = 0;
99
        int err = mmc_init(drv);
100
        if (err != 0 || drv->has_init == 0) {
101
                printf("mmc_init failed\n\r");
102
                return -1;
103
        }
104
        printf("mmc_init success\n\r");
105
 
106
        print_mmcinfo(drv);
107
 
108
        //read 1 block
109
        printf("attempting to read 1 block\n\r");
110
        if (mmc_bread(drv, 0, 1, buff) == 0) {
111
                printf("mmc_bread failed\n\r");
112
                return -1;
113
        }
114
        printf("mmc_bread success\n\r");
115
 
116
        printHex(buff, BLKSIZE);
117
 
118
        return EXIT_SUCCESS;
119
}

powered by: WebSVN 2.1.0

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