Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Compact Flash Card

Altera_Forum
Honored Contributor II
1,009 Views

Hi ecos community, 

 

I have a Nios dev board (Stratix edition) running an eCos application that logs data onto a Compact Flash card. 

 

My application runs well, but I am trying to improve it in the way it deals with the Compact Flash card. 

 

I would like my application to be able to get info on the CF card, ie card size, card maker, free space etc. I suspect the CF driver does not support this at present, but if it does I would like to know how. 

 

Also, the CF driver supports interrupt driven card insertion functionality for card initialization, but on my board this does not work, as far as I can tell no interrupt is generated when a card is inserted. If anyone has experience in this area I would like to hear about it. 

 

More detail follows... 

 

From the API the following code should allow access to CF info: 

 

error = cyg_io_lookup("/dev/cfa/1",&cf_handle); // get handle to CF 

error = cyg_io_get_config(&cf_handle,0,xbuf,&len); 

 

but the function alt_avalon_cf_get_config in altera_avalon_cf.c is just an empty stub, however the line of execution never appears to reach this code. 

 

Is there anyone else out there using CF cards? 

 

Peter
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
274 Views

There was a mistake in the second line of code, the correct code is below: 

 

error = cyg_io_lookup("/dev/cfa/1",&cf_handle); // get handle to CF 

error = cyg_io_get_config(cf_handle,0,xbuf,&len); // call for info, if any
0 Kudos
Altera_Forum
Honored Contributor II
274 Views

The following code fragments are a first attempt at providing access to CF information. The alt_avalon_cf_get_config stub is filled out and eCos cleaned and rebuilt. 

 

// fill out stub in altera_avalon_cf.c 

// Altera Avalon compact flash driver 

 

 

alt_avalon_cf_get_config(disk_channel *chan,  

cyg_uint32 key, 

const void *xbuf, //cyg_disk_info_t; 

cyg_uint32 *len) 

 

cyg_disk_info_t *info = chan->info; // info is a pointer 

cyg_disk_info_t *buf = (cyg_disk_info_t *) xbuf; 

 

cyg_disk_identify_t *ident = &chan->info->ident; 

 

Cyg_ErrNo res = ENOERR; 

 

D("alt_avalon_cf_get_config\n"); 

if (!chan->init) 

return -EINVAL; 

if (*len < sizeof(cyg_disk_info_t)) 

return -EINVAL; 

 

*buf = *info; 

*len = sizeof(cyg_disk_info_t); 

 

//D((" serial = &#39;%s&#39;\n", ident->serial));  

//D((" firmware rev = &#39;%s&#39;\n", ident->firmware_rev));  

D(" model num = &#39;%s&#39;\n", ident->model_num);  

D(" block_size = %d\n", info->block_size); 

D(" blocks_num = %d\n", info->blocks_num); 

 

return res; 

 

 

Here is a code fragment to access the info. In this case 

the block size, number of blocks and CF model string. 

 

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

// code to access CF info 

// use API call &#39;cyg_io_get_config&#39; 

 

// information on the CF card 

cyg_disk_info_t cf_info; 

 

char cf_model[20]; 

 

// later on... 

 

{ // get CF card info 

cyg_io_handle_t cf_handle; 

void *xbuf = (void *)&cf_info; //cyg_disk_info_t 

Cyg_ErrNo error; 

 

cyg_uint32 len = sizeof(cyg_disk_info_t); 

 

error = cyg_io_lookup("/dev/cfa/1", &cf_handle); 

if(error!=0) printf("lookup error:%i\n",error); 

 

else  

{  

error = cyg_io_get_config(cf_handle,0,xbuf,&len); // 

printf("cf get_config error: %i %i\n",error,-EINVAL); // should get -EINVAL 

 

//cf_info_ptr = *(cyg_disk_info_t *)xbuf; 

// get useful info 

block_size = cf_info.block_size; 

blocks_num = cf_info.blocks_num; 

strncpy(cf_model,cf_info.ident.model_num,16); 

printf("block size:%i num_blocks:%i %s\n" 

,cf_info.block_size,cf_info.blocks_num,cf_model); 

 

 

Looks like I get to answer my own questions.
0 Kudos
Reply