Esempio n. 1
0
int main(void)
{
    MCUSR &= ~(1 << WDRF);
    wdt_disable();

     // led
    SETUPRED();
    SETUPGREEN();
    GREENON();
    REDON();

    uint8_t bootloader_version[5] = "b002";
    eeprom_update_block((void *)&bootloader_version, BOOTLOADER_VERSION_ADDR, 4);

    sd_disk sd;
    _delay_ms(250);

     uint16_t flash = 0;
     if (!sd_init(&sd) && disk_init(&sd)) {
         if (!find_and_load_bootfile(&sd)) {
             flash = 4*3;
         }
     }
     GREENOFF();
     REDOFF();

     for (int i=0; i<flash; i++) {
         REDTOGGLE();
        _delay_ms(250);
      }
    REDOFF();
     __asm__("jmp 0000");
     sd_write_block(0,0);
}
Esempio n. 2
0
File: main.c Progetto: eerimoq/simba
static int test_write_performance(struct harness_t *harness_p)
{
    int i, block, res;
    struct time_t start, stop, diff;
    float seconds;
    unsigned long bytes_per_seconds;
    int number_of_blocks = 32;

    /* Write reference data to given block and verify that it was
       written. */
    for (i = 0; i < membersof(buf); i++) {
        buf[i] = (i & 0xff);
    }

    time_get(&start);

    /* Write to and read from the first five blocks. */
    for (block = 0; block < number_of_blocks; block++) {
        BTASSERT((res = sd_write_block(&sd, block, buf)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);
    }

    time_get(&stop);
    time_diff(&diff, &stop, &start);
    seconds = (diff.seconds + diff.nanoseconds / 1000000000.0f);
    bytes_per_seconds = ((SD_BLOCK_SIZE * number_of_blocks) / seconds);

    std_printf(FSTR("Wrote 32 blocks of %d bytes in %f s (%lu bytes/s).\r\n"),
               SD_BLOCK_SIZE,
               seconds,
               bytes_per_seconds);

    return (0);
}
Esempio n. 3
0
/**
 * def write(self, block, buffer)
 */
static mp_obj_t class_sd_write_block(mp_obj_t self_in,
                                     mp_obj_t block_in,
                                     mp_obj_t buffer_in)
{
    struct class_sd_t *self_p;
    uint32_t block;
    mp_buffer_info_t buffer_info;

    self_p = MP_OBJ_TO_PTR(self_in);
    block = mp_obj_get_int(block_in);
    mp_get_buffer_raise(MP_OBJ_TO_PTR(buffer_in),
                        &buffer_info,
                        MP_BUFFER_READ);

    if (buffer_info.len != SD_BLOCK_SIZE) {
        nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
                                           "bad buffer length"));
    }

    if (sd_write_block(&self_p->drv, block, buffer_info.buf) != SD_BLOCK_SIZE) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
                                                "sd_write_block(%d) failed",
                                                block));
    }

    return (mp_const_none);
}
Esempio n. 4
0
File: main.c Progetto: eerimoq/simba
static int test_read_write(struct harness_t *harness_p)
{
    int i, block, res;

    /* Write to and read from the first five blocks. */
    for (block = 0; block < 5; block++) {
        /* Write reference data to given block and verify that it was
           written. */
        for (i = 0; i < membersof(buf); i++) {
            buf[i] = ((block + i) & 0xff);
        }

        BTASSERT((res = sd_write_block(&sd, block, buf)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);
        memset(buf, 0, sizeof(buf));
        BTASSERT((res = sd_read_block(&sd, buf, block)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);

        for (i = 0; i < membersof(buf); i++) {
            BTASSERT(buf[i] == ((block + i) & 0xff));
        }

        /* Write zeros to given block and verify that it was
           written. */
        for (i = 0; i < membersof(buf); i++) {
            buf[i] = 0;
        }

        memset(buf, 0, sizeof(buf));
        BTASSERT((res = sd_write_block(&sd, block, buf)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);
        memset(buf, -1, sizeof(buf));
        BTASSERT((res = sd_read_block(&sd, buf, block)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);

        for (i = 0; i < membersof(buf); i++) {
            BTASSERT(buf[i] == 0);
        }
    }

    return (0);
}
uint8_t write_message(uint32_t file_number,message *m,uint8_t message_number)//writes message at particular position 
{
	uint32_t address;

	ptr=m;
	temp=*ptr;

	if(!CHECK_MSG_EXIST(file_number,message_number))//checking message location is empty
	{
		address=mat[file_number]->address[message_number];
		return sd_write_block(&sd,address,temp.data); // returns 1 0r 0
	}
	else
		return 0xff; // Error msg exists can not overwrite the message
}
Esempio n. 6
0
DRESULT disk_write (
	BYTE pdrv,			/* Physical drive nmuber to identify the drive */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector address in LBA */
	UINT count			/* Number of sectors to write */
)
{
	DRESULT res;
//	int result;

            sd_write_block (&sdc, sector, buff);
            sd_wait_notbusy (&sdc);
            res = RES_OK;
            return res;
            
            
        /*
	switch (pdrv) {
	case ATA :
		// translate the arguments here

		result = ATA_disk_write(buff, sector, count);

		// translate the reslut code here

		return res;

	case MMC :
		// translate the arguments here

		result = MMC_disk_write(buff, sector, count);

		// translate the reslut code here

		return res;

	case USB :
		// translate the arguments here

		result = USB_disk_write(buff, sector, count);

		// translate the reslut code here

		return res;
	}
        
	return RES_PARERR;*/
}
uint8_t store_fat_mat_to_SD()// stores the Fat and mat in SD at higher address. Need to be called from idle task.
{
	/* Size of FAT to be written into SD sector is 40 bytes only.*/

	uint32_t address,temp;
	uint8_t data[message_size];
	uint16_t i,j,shift=0,x;
	uint16_t next=0;
	uint32_t MAT_START;

	MAT_START=SP_ADD_MAT_START; //Starting address sector where mats will be stored contigiously

	/* Following 3 loops stores the FAT into array */

	for(i=0;i<files;i++) // Stores the address of the files of FAT in array to be written
	{
		for(j=0;j<4;j++)
		{
			address=(root->address[i]) >> shift;
			temp=address & 0xff;
			data[next++]=(uint8_t)temp;
			shift +=8;
		}
		shift=0;
	}

	shift=0;

	for(i=0;i<files;i++) // Stores the numbers of the files of FAT in array to be written
	{
		for(j=0;j<4;j++)
		{
			address=(root->file_number[i]) >> shift;
			temp=address & 0xff;
			data[next++]=(uint8_t)temp;
			shift +=8;
		}
		shift=0;
	}
	shift=0;
	for(i=0;i<4;i++) // Stores the flag_table of the files of FAT in array to be written
	{
		for(j=0;j<4;j++)
		{
			address=(root->flag_table[i]) >> shift;
			temp=address & 0xff;
			data[next++]=(uint8_t)temp;
			shift +=8;
		}
		shift=0;
	}
	
	for(i=next;i<message_size;i++)	// zero paddding
		data[i]=0;

	/* Sector is ready to be written into SD Card At Special address*/

	 address = (SP_ADD_FAT1 << 9 );	 
	 sd_write_block(&sd,address,data); // FAT1 is written
	 sd_delay(15); // SD card is taking rest wait

	 address = (SP_ADD_FAT2 << 9 );	 	
	 sd_write_block(&sd,address,data); // FAT2 is written
	 sd_delay(15); // SD card is taking rest wait
	
	 address = (SP_ADD_FAT3 << 9 );	 
	 sd_write_block(&sd,address,data); // FAT3 is written
	 sd_delay(15); // SD card is taking rest wait

	/* Its time to write MATS into SD Card */
	
	shift=0;
	next=0;
	for(x=0;x<files;x++)
	{
		for(i=0;i<4;i++)
		{
			address= (mat[x]->file_number) >> shift;
			temp= address & 0xff;
			data[next++]= (uint8_t)temp;
			shift += 8;
		} // File Number is written
		shift=0;
		
		data[next++]=(mat[x]->next); // next ptr is done

		for(i=0;i<messages_per_file;i++) // message number is written
		{
			data[next++]= mat[x]->message_number[i];
		}
		
		for(i=0;i<8;i++) // Stores exists flad table
		{	
			for(j=0;j<4;j++)
			{
				address=(mat[x]->exists_flag_table[i]) >> shift;
				temp=address & 0xff;
				data[next++]=(uint8_t)temp;
				shift +=8;
			}
			shift=0;
		}

		shift=0;
		
		for(i=0;i<8;i++) // Stores delete flag table
		{	
			for(j=0;j<4;j++)
			{
				address=(mat[x]->delete_flag_table[i]) >> shift;
				temp=address & 0xff;
				data[next++]=(uint8_t)temp;
				shift +=8;
			}
			shift=0;
		}
		
		shift=0;

		for(i=0;i<messages_per_file;i++) // Stores address of messages
		{	
			for(j=0;j<4;j++)
			{
				address=(mat[x]->address[i]) >> shift;
				temp=address & 0xff;
				data[next++]=(uint8_t)temp;
				shift +=8;
			}
			shift=0;
		}

		for(i=next;i<message_size;i++)
			data[i]=0x0;

		/* MAT for this itration's file is ready to written into SD */ 
		
		address= MAT_START << 9;
		sd_write_block(&sd,address,data);
		sd_delay(15);// Sd is taking rest
		MAT_START++;
		shift=0;
		next=0;
		
	}
	
	return 0;
}