Пример #1
0
uint8_t flash_data_set_write(float acc_g_xyz[3], float cal_acc_g_xyz[3], uint8_t event_ID, uint32_t UTC)
{
		uint32_t temp;
		if (buffer_event_count==BUFFER_EVENT_SIZE) return buffer_event_count;// buffer full return immediately  
			
		if (event_ID) {
			is_event_detected = true;
			event_addr[w_buffer_event_ptr] = w_addr_ptr;
			event_type[w_buffer_event_ptr] = event_ID;
			event_utc[w_buffer_event_ptr] = UTC;
		}
		
		if (w_addr_ptr%page_size == 0) flash_page_erase((uint32_t*)w_addr_ptr);// new page, erase before writing
	
		if (acc_g_xyz != NULL) {
			flash_word_write((uint32_t*)w_addr_ptr, w_flash_dummy1++);
		}
		w_addr_ptr+=4;

		if (acc_g_xyz != NULL) {		
			flash_word_write((uint32_t*)w_addr_ptr, w_flash_dummy1++);
		}
		w_addr_ptr+=4;

		if (cal_acc_g_xyz != NULL) {
			temp = (uint32_t) ((float)(cal_acc_g_xyz[0]+16)*100)<<16 | (uint32_t) ((float)(cal_acc_g_xyz[1]+16)*100); 
			flash_word_write((uint32_t*)w_addr_ptr, temp);
		}	
		w_addr_ptr+=4;

		if (cal_acc_g_xyz != NULL) {		
			temp = (uint32_t) ((float)(cal_acc_g_xyz[2]+16)*100); 
			flash_word_write((uint32_t*)w_addr_ptr, temp);
		}
		w_addr_ptr+=4;
	
		if (w_addr_ptr == w_r_addr[w_buffer_event_ptr]+four_page_size) // ring buffering management, round in 4 pase size
			w_addr_ptr = w_r_addr[w_buffer_event_ptr];
//		if (w_addr_ptr%four_page_size == 0)
//			bp++;
		
		if (is_event_detected) 
			count_down_7s_50Hz--;
		if (count_down_7s_50Hz==0) {
			is_event_detected = false;
			count_down_7s_50Hz = 7*50;
			w_buffer_event_ptr++;
			if(w_buffer_event_ptr==BUFFER_EVENT_SIZE) w_buffer_event_ptr = 0;
			w_addr_ptr = w_r_addr[w_buffer_event_ptr];
			buffer_event_count++;
		}
		return buffer_event_count;
}	
Пример #2
0
static void data_storage(uint32_t data[], uint32_t len, uint8_t pgnum)
{
    uint32_t * addr;
    uint8_t    patwr;
    uint32_t   i = 0;
    uint32_t   pg_size;
    uint32_t   pg_num;


    pg_size = NRF_FICR->CODEPAGESIZE;
    pg_num  = pgnum;  

		// There is 4K bytes in one page, datasheet suggest write small packet one time to avoid interrupt BLE operation		
		// Start address:
		addr = (uint32_t *)(pg_size * pg_num);
	
		// Erase page:
		flash_page_erase(addr);
	
		while (i < len)
		{
				patwr = data[i];
		
				flash_word_write(addr, (uint32_t)patwr);
				++addr;
				++i;
		}
}
Пример #3
0
/*--------------------------- check the bootloader of mcu ---------------*/
void mcu_bootloader_check(void)
{    
    if(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) != BOOTLOADER_ADDRESS_DEFAULT)
    {                                                
        read_back_disable();
        flash_word_write((uint32_t*)NRF_UICR_BOOT_START_ADDRESS, BOOTLOADER_ADDRESS_DEFAULT);
        xprintf("switch bootloader to 0xx%, begin to reset.\r\n", BOOTLOADER_ADDRESS_DEFAULT);
        NVIC_SystemReset();
    }
    
    xprintf("system app start work...\r\n");
}
Пример #4
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    uint32_t *addr;
    uint8_t patwr;
    uint8_t patrd;
    uint8_t patold;
    uint32_t i;
    uint32_t pg_size;
    uint32_t pg_num;

    init();
    
    patold  = 0;
    pg_size = NRF_FICR->CODEPAGESIZE;
    pg_num  = NRF_FICR->CODESIZE - 1;    // Use last page in flash

    while (true)
    {
        // Start address:
        addr = (uint32_t *)(pg_size * pg_num);
        // Erase page:
        flash_page_erase(addr);
        i = 0;
        do
        {
            // Read pattern from port 0 (pins0-7), and write it to flash:
            patwr =  nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0);
            if (patold != patwr)
            {
                patold = patwr;
                flash_word_write(++addr, (uint32_t)patwr);
                i += 4;
            }
            // Read pattern from flash and write it to port 1 (pins8-15):
            patrd = (uint8_t)*addr;
            nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, patrd);
        } while (i < pg_size);
    }
}