示例#1
0
文件: p30.c 项目: alcap-org/AlcapDAQ
void writeFlash(uint32_t handle, uint32_t *buffer, uint32_t bufferLength,
		uint32_t startWordAddress) {

	int wc, pp;

	wc = 0;
	pp = 0;

#ifdef PRINT_POINTS        
	printf(".");
	fflush(stdout);
#endif        
	while (wc < bufferLength) {
#ifdef PRINT_POINTS        	
		if (((wc % (32 * 1024)) == 0)) {
			printf(".");
			fflush(stdout);
		}
#endif                      
		writeFlashPage(handle, buffer + (pp * 32),
				startWordAddress + (pp * 32), 32);

		pp++;
		wc += 32;
	} // end of while loop

}
示例#2
0
static inline void tiny85FlashWrites(void) {
    _delay_us(2000); // TODO: why is this here? - it just adds pointless two level deep loops seems like?
    // write page to flash, interrupts will be disabled for > 4.5ms including erase
    
    if (currentAddress % SPM_PAGESIZE) { // when we aren't perfectly aligned to a flash page boundary
        fillFlashWithVectors(); // fill up the rest of the page with 0xFFFF (unprogrammed) bits
    } else {
        writeFlashPage(); // otherwise just write it
    }
}
示例#3
0
// fills the rest of this page with vectors - interrupt vector or tinyvector tables where needed
static void fillFlashWithVectors(void) {
    int16_t i;

    // fill all or remainder of page with 0xFFFF (as if unprogrammed)
    for (i = currentAddress % SPM_PAGESIZE; i < SPM_PAGESIZE; i += 2) {
        writeWordToPageBuffer(0xFFFF); // is where vector tables are sorted out
    }

    writeFlashPage();
}
示例#4
0
void run_task(uint8_t *Task)
{
	switch(Task[2])
	{
		case '0':
		send_string("boot");
		break;
		case '1':
		page_address = Task[9] << 8;
		page_address |= Task[8];
		readFlashPage(page_address, 128);
		send_buff(gBuffer, 128);
		Task[2] = 0;
		break;
		case '2':
		Task[2] = 0;
		break;
		case '3':
		page_address = Task[9] << 8;
		page_address |= Task[8];
		for (uint16_t i = 0; i < SPM_PAGESIZE; i++)
		gBuffer[i] = data_buffer[i + 16];
		writeFlashPage(page_address,SPM_PAGESIZE);
		send_string("page done");
		Task[2] = 0;
		break;
		case '4':
		eraseFlash();
		send_string("erase ok");
		Task[2] = 0;
		break;
		case '5':
		Task[2] = 0;
		break;
		case '6':
		fill_page();
		send_buff(gBuffer, 256);
		Task[2] = 0;
		break;
		case '7':
		blink_led();
		Task[2] = 0;
		break;
		case '8':
		MCUCR |= 1<<IVCE;
		MCUCR = 0<<IVSEL;
		send_string("jump ok");
		jump_to_app();		// Jump to application sector
		Task[2] = 0;
		break;
		default:
		Task[2] = 0;
	}
}
示例#5
0
static void fillFlashWithVectors(void)
{
    int16_t i;

    // fill all or remainder of page starting at CURRENT_ADDRESS with 0xFFs, unless we're
    //   at a special address that needs a vector replaced
    for (i = CURRENT_ADDRESS % SPM_PAGESIZE; i < SPM_PAGESIZE; i += 2)
    {
        writeWordToPageBuffer(0xFFFF);
    }

    writeFlashPage();
}
示例#6
0
// fills the rest of this page with vectors - interrupt vector or tinyvector tables where needed
static void fillFlashWithVectors(void) {
    //int16_t i;
    //
    // fill all or remainder of page with 0xFFFF (as if unprogrammed)
    //for (i = currentAddress % SPM_PAGESIZE; i < SPM_PAGESIZE; i += 2) {
    //    writeWordToPageBuffer(0xFFFF); // is where vector tables are sorted out
    //}

    // TODO: Or more simply:
    do {
        writeWordToPageBuffer(0xFFFF);
    } while (currentAddress % SPM_PAGESIZE);

    writeFlashPage();
}
示例#7
0
static inline void tiny85FlashWrites(void)
{
#if HAVE_CHIP_ERASE
    if(eraseRequested)
    {
        _delay_ms(2);
        cli();
        eraseApplication();
        sei();

#ifdef APPCHECKSUM
        checksum = 0;
#endif
        eraseRequested = 0;
    }
#endif
    if(flashPageLoaded)
    {
        _delay_ms(2);
        // write page to flash, interrupts will be disabled for several milliseconds
        cli();

        if(CURRENT_ADDRESS % SPM_PAGESIZE)
            fillFlashWithVectors();
        else
            writeFlashPage();

        sei();

        flashPageLoaded = 0;
        if(isLastPage)
        {
            // store number of bytes written so rest of flash can be filled later
            writeSize = CURRENT_ADDRESS;
            appWriteComplete = 1;
        }
    }
}