Пример #1
0
void Task2()
{
  int16_t cnt;
  int8_t val;
uint32_t sector = 0;
nrk_sem_t *radio_sem;


while(1) nrk_wait_until_next_period();
radio_sem= rf_get_sem();
if(radio_sem==NULL) nrk_kprintf( PSTR("radio sem failed!\r\n" ));
  printf( "Task2 PID=%u\r\n",nrk_get_pid());
  cnt=0;


  val=mmc_init();
  if(val!=0 ) {
	printf( "val=%d\r\n",val );
        nrk_kprintf( PSTR("card init failed\r\n") );
        while(1);
        }

  while(1) {
	nrk_sem_pend (radio_sem);
        printf("\nsector %lu\n\r",sector);                // show sector number
        val=mmc_readsector(sector,sectorbuffer);    // read a data sector
        printf( "readsector returned %d\n",val );
        for(cnt=0; cnt<32; cnt++ )
                printf( "%d ",sectorbuffer[cnt] );
        printf( "\n\r" );

        val=sectorbuffer[0];
        val++;
        for(cnt=0; cnt<512; cnt++ )
        {
        sectorbuffer[cnt]=val;
        }

        nrk_kprintf( PSTR("Writting\r\n") );
        val=mmc_writesector(sector,sectorbuffer);    // read a data sector
        printf( "writesector returned %d\n",val );
        printf( "After write:\r\n" );
        val=mmc_readsector(sector,sectorbuffer);    // read a data sector
	nrk_sem_post(radio_sem);
        printf( "readsector returned %d\n",val );
        if(val==0)
        {
         for(cnt=0; cnt<32; cnt++ )
                printf( "%d ",sectorbuffer[cnt] );
        nrk_kprintf( PSTR("\n\r") );
        }
sector++;
//	nrk_led_toggle(RED_LED);
//	printf( "Task2 signed cnt=%d\r\n",cnt );
	nrk_wait_until_next_period();
	cnt--;
	}
}
Пример #2
0
void Task1()
{
uint16_t cnt;
int8_t val;
uint32_t sector = 0;


  printf( "Task1 PID=%d\r\n",nrk_get_pid());
  cnt=0;
  val=mmc_init();
  printf("mmc_init returns %d\n\r", val );
  if(val!=0 ) {
	printf( "card init failed\r\n" );
	while(1);
	}
  
	printf("\nsector %ld\n\r",sector);                // show sector number
        val=mmc_readsector(sector,sectorbuffer);    // read a data sector
       	printf( "readsector returned %d\n",val );
	for(cnt=0; cnt<32; cnt++ )
		printf( "%d ",sectorbuffer[cnt] );
	printf( "\n\r" ); 

	val=sectorbuffer[0];
	val++;
	for(cnt=0; cnt<512; cnt++ )
	{
	sectorbuffer[cnt]=val;
	}

	printf( "Writting\r\n" );
	val=mmc_writesector(sector,sectorbuffer);    // read a data sector
       	printf( "writesector returned %d\n",val );
	printf( "After write:\r\n" );
	val=mmc_readsector(sector,sectorbuffer);    // read a data sector
       	printf( "readsector returned %d\n",val );
       	if(val==0)
	{
	 for(cnt=0; cnt<32; cnt++ )
		printf( "%d ",sectorbuffer[cnt] );
	printf( "\n\r" ); 
	}


  	while(1) {
	nrk_wait_until_next_period();
	}
}
Пример #3
0
void LoadRootDirectory(unsigned char *buffer){

	//read MBR
	mmc_readsector(0);
	
	//read boot record

	//long bootRecordSector=sector_buffer_ptr->mbr.partition1.startSector;

	long bootRecordSector=sector.mbr.partition1.startSector;
	mmc_readsector(bootRecordSector);

	int reservedSectors=sector.bootRecord.reservedSectors;
	int sectorsPerFat=sector.bootRecord.sectorsPerFat;
	maxRootDirectoryEntries=sector.bootRecord.maxRootDirectoryEntries;
	bytesPerSector=sector.bootRecord.bytesPerSector;
	sectorsPerCluster=sector.bootRecord.sectorsPerCluster;

	//get directory table
	dirTableSector=bootRecordSector + reservedSectors + (sectorsPerFat * 2); //+ ((maxRootDirectoryEntries * 32) / bytesPerSector);
	mmc_readsector(dirTableSector);

}
Пример #4
0
//Read one sector from the memory card and dump it to the shell
void
read_sd(void)
{
	char lbastr[5];
	inttostr(lbastr, lba);

	shell_output("Reading SD card: Sector", lbastr);

	uint8_t data[512];

	if (mmc_readsector(lba, data) == 0)	
		hexdump(data, 512);
	else
		shell_output("Failed to read that sector", "");
}
Пример #5
0
void main(){
	unsigned int i,px,py,pz,retval[32];
    uint32_t sector = 0;
    uint8_t sectorbuffer[512];
	printf("MMC mule sez Hello World\n");
	printf("trying mmc_init\n");
	retval[0]=mmc_init();
	printf("\nreturn code is %d\n",retval[0]);

	if (retval[0]==0){
		printf("trying readsector %l\n",sector);
		retval[0]=mmc_readsector(sector,sectorbuffer);    // read a data sector
		printf("return code=%d\n",retval[0]);
		//dump(sectorbuffer,512);                 // dump sector contents
		sector=(0xed)+1+121+121+32;
		printf("trying readsector %lx\n",sector);
		retval[0]=mmc_readsector(sector,sectorbuffer);    // read a data sector
		printf("return code=%d\n",retval[0]);
		dump(sectorbuffer,512);                 // dump sector contents
	}

	printf("\n");
	printf("\nand we're done\n");
}
Пример #6
0
//Read a sector into the sector buffer
uint8_t read_sector_to_buffer(uint32_t lba)
{
	if (buffered_lba != lba) {
		if (mmc_readsector(lba, sectorbuffer) != 0) {
			//We have a read error

			//The buffered sector may be corrupted,
			//so we make sure it's invalidated
			buffered_lba = -1;

			return 1;

		} else { //Successful read
			buffered_lba = lba;
			return 0;
		}
	}
	return 0;
}
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
	if (drv || !count) return RES_PARERR;
	if (SD_STATUS & STA_NOINIT) return RES_NOTRDY;

	if (count > 1)
		return RES_PARERR;

	if (mmc_readsector(sector, buff))
		return RES_PARERR;
	else
		return RES_OK;

}
Пример #8
0
int main(void)
{

	uint32_t i;
	char c;
	char s1[64], s2[64];
	
	uint8_t bufb[512];
	
	init_serial();

	lcd_init();
	
	lcd_printf("Hello World! \n n: %d", 152);

	// init card
	send_str("\ninit mmc card: ");
	c = mmc_init();
	if (c) {
		send_str("failed (");
		send_int(c);
		send_str(")\n");
	} else {
		send_str("success\n");
		
		init_partition(0);
		
		c = 'h';
		
		while (1) {
		
			switch (c) {
				case 'l' :
					ls();
					break;
				
				case 'c' :
					send_str("dir: ");
					receive_str(s1);
					cd(s1);
					break;
					
				case 'r' :
					send_str("rename file: ");
					receive_str(s1);
					send_str("new name: ");
					receive_str(s2);
					rn(s1, s2);
					break;
					
				case 'd' :
					send_str("delete file: ");
					receive_str(s1);
					del(s1);
					break;
					
				case 'p' :
					send_str("file: ");
					receive_str(s1);
					cat(s1);
					break;

				case 't' :
					send_str("name: ");
					receive_str(s1);
					touch(s1);
					break;
					
				case 's' :
					send_str("sector: 0x");
					i = receive_hex();
					if (mmc_readsector(i, bufb)) {
						send_str("error reading sector\n");
					} else {
						dump_sector(bufb);
						send_char('\n');
					}
					break;
				
				case 'h' :
				default :
					send_str("h - help\nl - dir listing\nc - change dir\nd - delete file\np - print file contents\nt - create empty file\ns - dump sector\n");
					break;
			
			}
			
			// prompt
			send_str("> ");
			c = receive_char();
			send_char('\n');
		}
		
	}
	
	while (1) ;
	
	return 0;
}