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] - Diff between revs 3 and 8

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 8
/*
/*
 * WISHBONE SD Card Controller IP Core
 * WISHBONE SD Card Controller IP Core
 *
 *
 * sd_example.c
 * sd_example.c
 *
 *
 * This file is part of the WISHBONE SD Card
 * This file is part of the WISHBONE SD Card
 * Controller IP Core project
 * Controller IP Core project
 * http://www.opencores.org/cores/xxx/
 * http://opencores.org/project,sd_card_controller
 *
 *
 * Description
 * Description
 * Example application using WISHBONE SD Card Controller
 * Example application using WISHBONE SD Card Controller
 * IP Core. The app perform core initialisation,
 * IP Core. The app perform core initialisation,
 * mmc/sd card initialisation and then reads one block
 * mmc/sd card initialisation and then reads one block
 * of data from the card.
 * of data from the card.
 * This app is using some of code from u-boot project
 * This app is using some of code from u-boot project
 * (mmc.c and mmc.h)
 * (mmc.c and mmc.h)
 *
 *
 * Author(s):
 * Author(s):
 *     - Marek Czerski, ma.czerski@gmail.com
 *     - Marek Czerski, ma.czerski@gmail.com
 */
 */
/*
/*
 *
 *
 * Copyright (C) 2013 Authors
 * Copyright (C) 2013 Authors
 *
 *
 * This source file may be used and distributed without
 * This source file may be used and distributed without
 * restriction provided that this copyright statement is not
 * restriction provided that this copyright statement is not
 * removed from the file and that any derivative work contains
 * removed from the file and that any derivative work contains
 * the original copyright notice and the associated disclaimer.
 * the original copyright notice and the associated disclaimer.
 *
 *
 * This source file is free software; you can redistribute it
 * This source file is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General
 * and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation;
 * Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any
 * either version 2.1 of the License, or (at your option) any
 * later version.
 * later version.
 *
 *
 * This source is distributed in the hope that it will be
 * This source is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * details.
 *
 *
 * You should have received a copy of the GNU Lesser General
 * You should have received a copy of the GNU Lesser General
 * Public License along with this source; if not, download it
 * Public License along with this source; if not, download it
 * from http://www.opencores.org/lgpl.shtml
 * from http://www.opencores.org/lgpl.shtml
 */
 */
 
 
#include "mmc.h"
#include "mmc.h"
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
 
 
struct mmc * ocsdc_mmc_init(int base_addr, int clk_freq);
struct mmc * ocsdc_mmc_init(int base_addr, int clk_freq);
 
 
#define BLKSIZE 512
#define BLKSIZE 512
#define BLKCNT 10
#define BLKCNT 10
 
 
char buff[BLKSIZE*BLKCNT] = {'\0'};
char buff[BLKSIZE*BLKCNT] = {'\0'};
 
 
void printHex(const void *lpvbits, const unsigned int n) {
void printHex(const void *lpvbits, const unsigned int n) {
    char* data = (char*) lpvbits;
    char* data = (char*) lpvbits;
    unsigned int i = 0;
    unsigned int i = 0;
    char line[17] = {};
    char line[17] = {};
    printf("%.8X | ", (unsigned int)data);
    printf("%.8X | ", (unsigned int)data);
    while ( i < n ) {
    while ( i < n ) {
        line[i%16] = *(data+i);
        line[i%16] = *(data+i);
        if ((line[i%16] < 32) || (line[i%16] > 126)) {
        if ((line[i%16] < 32) || (line[i%16] > 126)) {
            line[i%16] = '.';
            line[i%16] = '.';
        }
        }
        printf("%.2X", (unsigned char)*(data+i));
        printf("%.2X", (unsigned char)*(data+i));
        i++;
        i++;
        if (i%4 == 0) {
        if (i%4 == 0) {
            if (i%16 == 0) {
            if (i%16 == 0) {
                if (i < n-1)
                if (i < n-1)
                    printf(" | %s\n\r%.8X | ", line, (unsigned int)data+i);
                    printf(" | %s\n\r%.8X | ", line, (unsigned int)data+i);
            } else {
            } else {
                printf(" ");
                printf(" ");
            }
            }
        }
        }
    }
    }
    while (i%16 > 0) {
    while (i%16 > 0) {
        (i%4 == 0)?printf("   "):printf("  ");
        (i%4 == 0)?printf("   "):printf("  ");
        line[i%16] = ' ';
        line[i%16] = ' ';
        i++;
        i++;
    }
    }
    printf(" | %s\n\r", line);
    printf(" | %s\n\r", line);
}
}
 
 
int main(void) {
int main(void) {
        printf("Hello World !!!\n\r");
        printf("Hello World !!!\n\r");
 
 
        //init ocsdc driver
        //init ocsdc driver
        struct mmc * drv = ocsdc_mmc_init(0x9e000000, 50000000);
        struct mmc * drv = ocsdc_mmc_init(0x9e000000, 50000000);
        if (!drv) {
        if (!drv) {
                printf("ocsdc_mmc_init failed\n\r");
                printf("ocsdc_mmc_init failed\n\r");
                return -1;
                return -1;
        }
        }
        printf("ocsdc_mmc_init success\n\r");
        printf("ocsdc_mmc_init success\n\r");
 
 
        drv->has_init = 0;
        drv->has_init = 0;
        int err = mmc_init(drv);
        int err = mmc_init(drv);
        if (err != 0 || drv->has_init == 0) {
        if (err != 0 || drv->has_init == 0) {
                printf("mmc_init failed\n\r");
                printf("mmc_init failed\n\r");
                return -1;
                return -1;
        }
        }
        printf("mmc_init success\n\r");
        printf("mmc_init success\n\r");
 
 
        print_mmcinfo(drv);
        print_mmcinfo(drv);
 
 
        //read 1 block
        //read 1 block
        printf("attempting to read 1 block\n\r");
        printf("attempting to read 1 block\n\r");
        if (mmc_bread(drv, 0, 1, buff) == 0) {
        if (mmc_bread(drv, 0, 1, buff) == 0) {
                printf("mmc_bread failed\n\r");
                printf("mmc_bread failed\n\r");
                return -1;
                return -1;
        }
        }
        printf("mmc_bread success\n\r");
        printf("mmc_bread success\n\r");
 
 
        printHex(buff, BLKSIZE);
        printHex(buff, BLKSIZE);
 
 
        return EXIT_SUCCESS;
        return EXIT_SUCCESS;
}
}
 
 

powered by: WebSVN 2.1.0

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