Ignore:
Timestamp:
Sep 21, 2018, 10:24:15 PM (3 years ago)
Author:
nicolas.van.phan@…
Message:

Add SD card driver in kernel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/drivers/soclib_sdc.c

    r543 r550  
    66///////////////////////////////////////////////////////////////////////////////////
    77
    8 //#include <hard_config.h>
     8// #include <hard_config.h>
    99#include <soclib_sdc.h>
    1010//#include <tty0.h>
    1111//#include <utils.h>
     12#include <hal_kernel_types.h>
     13#include <chdev.h>
     14#include <dev_ioc.h>
     15#include <thread.h>
    1216#include <printk.h>
    1317
     
    334338
    335339////////////////////////
    336 unsigned int _sdc_init()
     340void soclib_sdc_init( chdev_t* chdev )
    337341{
    338342    spi = (struct spi_dev*)SEG_IOC_BASE;
     
    393397    printk("[SDC WARNING] Finish SD card initialization\n\r");
    394398
    395     return 0;
    396 } // end _sdc_init()
    397 
     399    /* Initialize the chdev */
     400    // get extended pointer on SOCLIB_BDV peripheral base address
     401        xptr_t  sdc_xp = chdev->base;
     402
     403    // set driver specific fields
     404    chdev->cmd = &soclib_sdc_cmd;
     405    chdev->isr = &soclib_sdc_isr;
     406
     407} // end soclib_sdc_init()
    398408
    399409/////////////////////////////////////////////////////
    400 unsigned int _sdc_access( unsigned int       use_irq,  // unused
    401                           unsigned int       to_mem,
    402                           unsigned int       lba,
    403                           unsigned long long buf_paddr,
    404                           unsigned int       count )
    405 {
     410void __attribute__ ((noinline)) soclib_sdc_cmd( xptr_t th_xp )
     411{
     412    cxy_t      th_cxy = GET_CXY( th_xp );
     413    thread_t * th_ptr = GET_PTR( th_xp );
     414
     415    // get command arguments and extended pointer on IOC device
     416    uint32_t        cmd_type =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->ioc_cmd.type   ) );
     417    unsigned int    lba      =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->ioc_cmd.lba ) );
     418    xptr_t          buf_xp   = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->ioc_cmd.buf_xp ) );
     419    unsigned int    count    =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->ioc_cmd.count  ) );
     420
    406421    unsigned char args[4];
    407422    unsigned char sdcard_rsp;
     
    410425    unsigned int last = lba + count;
    411426
    412     if ( to_mem )  // read access
     427    if ( cmd_type == IOC_SYNC_READ )  // read access
    413428    {
    414429        for ( ; curr < last ; curr++ )
     
    432447            _sdc_wait_data_block();
    433448
    434             if (spi_get_data(sdcard.spi, buf_paddr, 512 ))
     449            if (spi_get_data(sdcard.spi, buf_xp, 512 ))
    435450            {
    436451                _sdc_disable();
     
    444459            _sdc_disable();
    445460
    446             buf_paddr += 512;
     461            buf_xp += 512;
    447462        }
    448463    }
     
    451466        assert( false, __FUNCTION__, "[SDC ERROR] function _sdc_write() not iplemented yet\n");
    452467    }
    453 
    454     return 0;
    455468}  // _end sdc_access()
    456469
     
    458471// This ISR handles the IRQ generated by a SDC controler
    459472///////////////////////////////////////////////////////////////////////////////
    460 void _sdc_isr( unsigned int irq_type,
    461                unsigned int irq_id,
    462                unsigned int channel )
     473void __attribute__ ((noinline)) soclib_sdc_isr( chdev_t * chdev )
    463474{
    464475    assert( false, __FUNCTION__, "\n[GIET ERROR] _sdc_isr() not implemented\n");
Note: See TracChangeset for help on using the changeset viewer.