Ignore:
Timestamp:
Jan 31, 2014, 2:37:38 PM (10 years ago)
Author:
cfuguet
Message:

Modification of comments format on SPI-SDCARD driver to respect
GIET-VM format

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branch/giet_vm_ioc_drivers/giet_drivers/sdc_driver.c

    r283 r284  
    1 /**
    2  * \file    : sdc_driver.c
    3  * \date    : 30 August 2012
    4  * \author  : Cesar Fuguet
    5  *
    6  * This file defines the driver of a SD Card device using an SPI controller
    7  */
    8 
     1///////////////////////////////////////////////////////////////////////////////////
     2// File     : sdc_driver.c
     3// Date     : 31/08/2012
     4// Author   : cesar fuguet
     5// Copyright (c) UPMC-LIP6
     6///////////////////////////////////////////////////////////////////////////////////
    97#include <sdc_driver.h>
    108#include <utils.h>
     
    1614static struct spi_dev*   spi;
    1715
    18 /**
    19  * \return  void
    20  *
    21  * \brief   Enable SD Card select signal
    22  */
     16///////////////////////////////////////////////////////////////////////////////
     17//      _sdc_enable()
     18// This function enables SD Card select signal
     19///////////////////////////////////////////////////////////////////////////////
    2320static void _sdc_enable()
    2421{
     
    2623}
    2724
    28 /**
    29  * \return  void
    30  *
    31  * \brief   Disable SD Card select signal
    32  */
     25///////////////////////////////////////////////////////////////////////////////
     26//      _sdc_enable()
     27// This function disables SD Card select signal
     28///////////////////////////////////////////////////////////////////////////////
    3329static void _sdc_disable()
    3430{
     
    3632}
    3733
    38 /**
    39  * \param   tick_count: SD Card clock ticks number
    40  *
    41  * \return  void
    42  *
    43  * \brief   Enable SD Card clock
    44  *          The tick count is byte measured (1 tick, 8 clock)
    45  */
     34///////////////////////////////////////////////////////////////////////////////
     35//      _sdc_gen_tick()
     36// This function writes on the SPI tx register to generate SD card clock ticks
     37// - tick_count: number of ticks to generate (1 tick -> 8 clocks)
     38///////////////////////////////////////////////////////////////////////////////
    4639static void _sdc_gen_tick(unsigned int tick_count)
    4740{
     
    5043}
    5144
    52 /**
    53  * \param   lba : Position where the block device access
    54  *                pointer must be move
    55  *
    56  * \return  void
    57  *
    58  * \brief   Change block device access pointer position
    59  * 
    60  * The block device access pointer is relocated in terms of blocks
    61  */
     45///////////////////////////////////////////////////////////////////////////////
     46//      _sdc_lseek()
     47// This function changes the SD card access pointer position in terms of
     48// blocks
     49// - lba: number of logical block to move the pointer
     50///////////////////////////////////////////////////////////////////////////////
    6251void _sdc_lseek(unsigned int lba)
    6352{
     
    6554}
    6655
    67 /**
    68  * \return  char from the SD card
    69  *
    70  * \brief   Get a byte from the SD Card
    71  */
     56///////////////////////////////////////////////////////////////////////////////
     57//      _sdc_receive_char()
     58// This function gets a byte from the SD card
     59///////////////////////////////////////////////////////////////////////////////
    7260static unsigned char _sdc_receive_char()
    7361{
     
    7765}
    7866
    79 /**
    80  * \return  sdcard response
    81  *
    82  * \brief   Wait for a valid response after the send of a command
    83  *          This function can return if one of the next two conditions are true:
    84  *           1. Bit valid received
    85  *           2. Timeout (not valid bit received after SDCARD_COMMAND_TIMEOUT
    86  *              wait ticks)
    87  */
     67///////////////////////////////////////////////////////////////////////////////
     68//      _sdc_wait_response()
     69// This function returns when a valid response from the SD card is received or
     70// a timeout has been triggered
     71// Returns the SD card response value
     72///////////////////////////////////////////////////////////////////////////////
    8873static unsigned char _sdc_wait_response()
    8974{
     
    10590}
    10691
    107 /**
    108  * \return  void
    109  *
    110  * \brief   Wait data block start marker
    111  */
     92///////////////////////////////////////////////////////////////////////////////
     93//      _sdc_wait_data_block()
     94// This function returns when a data block from the SD card is received (data
     95// block start marker received).
     96// It must be called after a read command
     97///////////////////////////////////////////////////////////////////////////////
    11298static void _sdc_wait_data_block()
    11399{
     
    115101}
    116102
    117 /**
    118  * \param   index   : SD card CMD index
    119  * \param   app     : Type of command, 0 for normal command or 1 for
    120  *                    application specific
    121  * \param   args    : SD card CMD arguments
    122  *
    123  * \return  response first byte
    124  *
    125  * \brief   Send command to the SD card
    126  */
     103///////////////////////////////////////////////////////////////////////////////
     104//      _sdc_send_command()
     105// This function sends a command to the SD card
     106// - index: CMD index
     107// - app: type of command
     108// - args: CMD arguments vector
     109// - crc7: CRC (7 bits) to send
     110///////////////////////////////////////////////////////////////////////////////
    127111static int _sdc_send_command ( int      index,
    128112                               int      app  ,
     
    137121    if (app == SDCARD_ACMD)
    138122    {
    139         spi_put_tx(sdcard.spi, 0x40 | 55         , 0 );/* CMD and START bit */
    140         spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[0]       */
    141         spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[1]       */
    142         spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[2]       */
    143         spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[3]       */
    144         spi_put_tx(sdcard.spi, 0x01 | (crc7 << 1), 0 );/* END bit           */
     123        spi_put_tx(sdcard.spi, 0x40 | 55         , 0 );// CMD and START bit
     124        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[0]
     125        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[1]
     126        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[2]
     127        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[3]
     128        spi_put_tx(sdcard.spi, 0x01 | (crc7 << 1), 0 );// END bit
    145129
    146130        sdcard_rsp = _sdc_wait_response();
     
    165149}
    166150
     151///////////////////////////////////////////////////////////////////////////////
     152//      _sdc_open()
     153// This function initializes the SD card (reset procedure)
     154// - channel: channel index (only channel 0 is supported)
     155// Returns 0 if success, other value if failure
     156///////////////////////////////////////////////////////////////////////////////
    167157static int _sdc_open( unsigned int channel )
    168158{
     
    174164        sdcard.slave_id = channel;
    175165
    176         /*
    177         * Supply SD card ramp up time (min 74 cycles)
    178         */
     166        // supply SD card ramp up time (min 74 cycles)
    179167        _sdc_gen_tick(10);
    180168
    181         /*
    182         * Assert slave select signal
    183         * Send CMD0 (Reset Command)
    184         * Deassert slave select signal
    185         */
     169        // Assert slave select signal
     170        // Send CMD0 (Reset Command)
     171        // Deassert slave select signal
    186172        _sdc_enable();
    187173
     
    199185
    200186        _sdc_disable();
    201         /*
    202          * send CMD8. If card is pre-v2, It will reply with illegal command.
    203          * Otherwise we announce sdhc support.
    204          */
     187
     188        // send CMD8. If card is pre-v2, It will reply with illegal command.
     189        // Otherwise we announce sdhc support.
    205190        _sdc_enable();
    206191        args[0] = 0;
     
    209194        args[3] = 0x01;
    210195        sdcard_rsp = _sdc_send_command(8, SDCARD_CMD, args, 0x63);
    211         if (!SDCARD_CHECK_R1_VALID(sdcard_rsp)) {
     196        if (!SDCARD_CHECK_R1_VALID(sdcard_rsp))
     197    {
    212198                _puts("card CMD8 failed ");
    213199                return sdcard_rsp;
    214200        }
    215         if (!SDCARD_CHECK_R1_ERROR(sdcard_rsp)) {
    216                 /* no error, command accepted. get whole reply */
     201        if (!SDCARD_CHECK_R1_ERROR(sdcard_rsp))
     202    {
     203                // no error, command accepted. get whole reply
    217204                ersp = _sdc_receive_char();
    218205                ersp = (ersp << 8) | _sdc_receive_char();
     
    220207                ersp = (ersp << 8) | _sdc_receive_char();
    221208                if ((ersp & 0xffff) != 0x0101) {
    222                         /* voltage mismatch */
     209                        // voltage mismatch
    223210                        _puts("card CMD8 mismatch: ");
    224211                        _putx(ersp);
     
    227214                _puts("v2 or later ");
    228215                sdcard.sdhc = 1;
    229         } else if ((sdcard_rsp & SDCARD_R1_ILLEGAL_CMD) == 0) {
    230                 /* other error */
     216        }
     217    else if ((sdcard_rsp & SDCARD_R1_ILLEGAL_CMD) == 0)
     218    {
     219                // other error
    231220                _puts("card CMD8 error ");
    232221                return sdcard_rsp;
    233         } else {
     222        }
     223    else
     224    {
    234225                sdcard.sdhc = 0;
    235226        }
    236227        _sdc_disable();
    237         /* send CMD41, enabling the card */
     228
     229        // send CMD41, enabling the card
    238230        _sdc_enable();
    239231        args[0] = sdcard.sdhc ? 0x40: 0;
     
    255247
    256248        _sdc_disable();
    257         if (sdcard_rsp) {
     249        if (sdcard_rsp)
     250    {
    258251                _puts("SD ACMD41 failed ");
    259252                return sdcard_rsp;
    260253        }
    261         if (sdcard.sdhc != 0) {
    262                 /* get the card capacity to see if it's really HC */
     254        if (sdcard.sdhc != 0)
     255    {
     256                // get the card capacity to see if it's really HC
    263257                _sdc_enable();
    264258                args[0] = sdcard.sdhc ? 0x40: 0;
     
    267261                args[3] = 0;
    268262        sdcard_rsp = _sdc_send_command(58, SDCARD_CMD, args, 0x00);
    269                 if (sdcard_rsp) {
     263                if (sdcard_rsp)
     264        {
    270265                        _puts("SD CMD58 failed ");
    271266                        return sdcard_rsp;
     
    275270                ersp = (ersp << 8) | _sdc_receive_char();
    276271                ersp = (ersp << 8) | _sdc_receive_char();
    277                 if (ersp & 0x40000000) {
     272                if (ersp & 0x40000000)
     273        {
    278274                        _puts("SDHC ");
    279                 } else {
     275                } else
     276        {
    280277                        sdcard.sdhc = 0;
    281278                }
     
    286283}
    287284
     285///////////////////////////////////////////////////////////////////////////////
     286//      _sdc_set_block_size()
     287// This function sets the block size in bytes of the SD card
     288// - len: block size in bytes (only 512 bytes supported)
     289// Returns 0 if success, other value if failure
     290///////////////////////////////////////////////////////////////////////////////
    288291static unsigned int _sdc_set_block_size(unsigned int len)
    289292{
     
    292295    register int i;
    293296
    294     /*
    295      * For now, supported block size is 512 bytes
    296      */
     297    // For now, supported block size is 512 bytes
    297298    if (len != 512) return 1;
    298299
    299     /*
    300      * When using high capacity SDCARD, the block_length is not a number of bytes
    301      * but a number of blocks (transfer unit)
    302      */
     300    // When using high capacity SDCARD, the block_length is not a number of bytes
     301    // but a number of blocks (transfer unit)
    303302    if (sdcard.sdhc)
    304303    {
     
    328327}
    329328
     329///////////////////////////////////////////////////////////////////////////////
     330//      _sdc_init()
     331// This function initializes the SPI controller and call sdc_open to
     332// initializes SD card
     333// - channel: channel to initialize (only channel 0 supported)
     334// Returns 0 if success, other value if failure
     335///////////////////////////////////////////////////////////////////////////////
    330336unsigned int _sdc_init( unsigned int channel )
    331337{
    332338    spi = (struct spi_dev*) &seg_ioc_base;
    333339
    334     /**
    335      * Initializing the SPI controller
    336      */
     340    // initializing the SPI controller
    337341    _spi_init (
    338342        spi           ,
     
    344348    );
    345349
    346     /**
    347      * Initializing the SD Card
    348      */
     350    // initializing the SD Card
    349351    unsigned int iter = 0;
    350352    unsigned char sdcard_rsp;
     
    376378    }
    377379
    378     /**
    379      * Set the block length of the SD Card
    380      */
     380    // set the block length of the SD Card
    381381    sdcard_rsp = _sdc_set_block_size(512);
    382382    if (sdcard_rsp)
     
    386386    }
    387387
    388     /**
    389      * Incrementing SDCARD clock frequency for normal function
    390      */
     388    // incrementing SDCARD clock frequency for normal function
    391389    _spi_init (
    392390        spi         ,
    393         10000000    , /**< SPI_clk 10 Mhz */
    394         SYSCLK_FREQ , /**< Sys_clk        */
    395         -1          , /**< Charlen: 8     */
     391        10000000    , // SPI_clk 10 Mhz
     392        SYSCLK_FREQ , // Sys_clk
     393        -1          , // Charlen: 8
    396394        -1          ,
    397395        -1
     
    450448        }
    451449
    452         /*
    453          * Get the CRC16 (comes at the end of the data block)
    454          */
     450        // Get the CRC16 (comes at the end of the data block)
    455451        _sdc_receive_char(); // first byte
    456452        _sdc_receive_char(); // second byte
     
    464460}
    465461
     462///////////////////////////////////////////////////////////////////////////////
     463//     _sdc_write() (not supported for now)
     464// Transfer data from memory buffer to SD card device.
     465// - mode     : BOOT / KERNEL / USER
     466// - lba      : destination first block index on the SD card
     467// - buffer   : base address of the memory buffer (must be word aligned)
     468// - count    : number of blocks to be transfered.
     469// Returns 0 if success, > 0 if error.
     470///////////////////////////////////////////////////////////////////////////////
    466471unsigned int _sdc_write( unsigned int mode,
    467472                         unsigned int lba,
     
    472477}
    473478
     479///////////////////////////////////////////////////////////////////////////////
     480//     _sdc_get_status()
     481// Transfer data from memory buffer to SD card device.
     482// - channel: channel index
     483// - status: this pointer is used to transmit the status value to caller.
     484// Returns 0 if success, > 0 if error.
     485///////////////////////////////////////////////////////////////////////////////
    474486unsigned int _sdc_get_status( unsigned int channel ,
    475487                              unsigned int* status )
    476488{
    477     return BLOCK_DEVICE_IDLE;
    478 }
    479 
     489    *status = BLOCK_DEVICE_IDLE;
     490
     491    return 0;
     492}
     493
     494///////////////////////////////////////////////////////////////////////////////
     495//     _sdc_get_block_size()
     496// Returns the block size in bytes of the SD card
     497///////////////////////////////////////////////////////////////////////////////
    480498unsigned int _sdc_get_block_size()
    481499{
     
    484502}
    485503
    486 
    487 
    488 /*
    489  * vim: tabstop=4 : shiftwidth=4 : expandtab : softtabstop=4
    490  */
     504// Local Variables:
     505// tab-width: 4
     506// c-basic-offset: 4
     507// c-file-offsets:((innamespace . 0)(inline-open . 0))
     508// indent-tabs-mode: nil
     509// End:
     510// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracChangeset for help on using the changeset viewer.