This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

using mmc_spi for olpcl2294 : blocking mutex


Hello,

I' am trying to mount a sdcard using fatfs and the card connected using spi.
The mount() call nevers returns. It seems thaht a mutex lock in mmc_spi_send_init() nevers becomes locked.


in spi.c:

while (!cyg_drv_mutex_lock(&(bus->spi_lock))); <---- doesn't return

With debug option I get :

mmc_spi_disk_lookup(): target name=0
: device name=/dev/mmcdisk0/ dep_name=<null>
: sub name=<Not a string: 0xFAC35279> dep_name=<Not a string: 0xE59FF018>


mmc_spi_send_init(): dev pointer 0x0x81027814, 1
                             : begin pointer 0x81011ff4

regards,
Nicolas FLAVEN

This is my code :

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>

#include <cyg/fileio/fileio.h>
#include <cyg/infra/diag.h>
#include <cyg/io/spi.h>
#include <cyg/io/spi_lpc2xxx.h>

#define MMC_SCS (1 << 7) // P0.7

static void
mmc_cs(int cs)
{
   if (cs)
       diag_printf("CS Up\n");
   else
       diag_printf("CS Down\n");
}



// -------------------------------------------------------------------------

cyg_spi_device *cyg_spi_mmc_dev0;

cyg_spi_lpc2xxx_dev_t mmc_spi_device CYG_SPI_DEVICE_ON_BUS(0) = {
       .spi_device.spi_bus = &cyg_spi_lpc2xxx_bus0.spi_bus,        //
       .spi_cpha = 0,                 // Clock phase
       .spi_cpol = 0,                 // Clock polarity
       .spi_lsbf = 0,                 // LSB first
       .spi_baud = 1000000,           // 1 Mbit/s
       .spi_cs = mmc_cs               // Chip select driver
};

// -------------------------------------------------------------------------


void mmc_write(char fileName[], long nBlocks, long blockSize, unsigned char testChar)
{
char *buf;
int i;
int fd;
ssize_t wrote;


   if ((buf = (char*)malloc(blockSize)) == NULL) {
       diag_printf("[error] memory allocation failed!\n");
       return;
   }

memset(buf, testChar, blockSize);

if ((fd = open(fileName, O_WRONLY|O_CREAT)) < 0){
diag_printf("[error] opening file %s for write failed!\n", fileName);
return;
}


   diag_printf("start writing\n");
   for(i=0;i<nBlocks;i++) {
       diag_printf("off:%d\n",lseek(fd, 0, SEEK_CUR));

wrote = write( fd, buf, blockSize );
if (wrote != blockSize) {
diag_printf("[warning] incomplete write at block %d\n", i);
}
}
diag_printf("end writing");
close(fd);
}


int main()
{
cyg_spi_mmc_dev0 = &mmc_spi_device.spi_device;


cyg_uint32 reg_val;

   int err;
   int i;

diag_printf("MMC spi device test ...\n");

// Test if spi is working
cyg_uint8 Test[] = { 0xAA, 0xAB, 0xFF };
cyg_spi_transaction_begin(cyg_spi_mmc_dev0);
cyg_spi_transaction_transfer(cyg_spi_mmc_dev0, 1, sizeof(Test), Test, NULL, 0);
cyg_spi_transaction_end(cyg_spi_mmc_dev0);


diag_printf("MMC test start ...\n");

if ((mount( "/dev/mmcdisk0/0", "/", "fatfs" )) < 0) {
diag_printf("[error] mounting MMC card!\n");
return 0;
}


mmc_write("test.txt", 5, 1024, 'x');

umount( "/" );

diag_printf("MMC test end\n");

   return 1;
}


-- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]