Exemple #1
0
// Lua: adc.force_init_mode(x)
static int adc_init107( lua_State *L )
{
    uint8_t byte107 = luaL_checkinteger (L, 1);

    uint32 init_sector = flash_safe_get_sec_num () - 4;

    // Note 32bit alignment so we can safely cast to uint32 for the flash api
    char init_data[SPI_FLASH_SEC_SIZE] __attribute__((aligned(4)));

    if (SPI_FLASH_RESULT_OK != flash_safe_read (
                init_sector * SPI_FLASH_SEC_SIZE,
                (uint32 *)init_data, sizeof(init_data)))
        return luaL_error(L, "flash read error");

    // If it's already the correct value, we don't need to force it
    if (init_data[107] == byte107)
    {
        lua_pushboolean (L, false);
        return 1;
    }

    // Nope, it differs, we need to rewrite it
    init_data[107] = byte107;
    if (SPI_FLASH_RESULT_OK != flash_safe_erase_sector (init_sector))
        return luaL_error(L, "flash erase error");

    if (SPI_FLASH_RESULT_OK != flash_safe_write (
                init_sector * SPI_FLASH_SEC_SIZE,
                (uint32 *)init_data, sizeof(init_data)))
        return luaL_error(L, "flash write error");

    lua_pushboolean (L, true);
    return 1;
}
Exemple #2
0
bool flash_init_data_default(void)
{
    /* Can't copy directly from flash (which is where the default data lives)
     * due to it being unmapped during the write, so bounce via ram buffer. */
    uint8_t init_data[128];
    os_memcpy (init_data, flash_init_data, 128);

    // FLASH SEC - 4
    // Dangerous, here are dinosaur infested!!!!!
    // Reboot required!!!
    // It will init system data to default!
    bool result = false;
#if defined(FLASH_SAFE_API)
    if (SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_safe_get_sec_num() - 4)))
    {
        if (SPI_FLASH_RESULT_OK == flash_safe_write((flash_safe_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)init_data, 128))
        {
            result = true;
        }
    }
#else
    if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 4)))
    {
        if (SPI_FLASH_RESULT_OK == spi_flash_write((flash_rom_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)init_data, 128))
        {
            result = true;
        }
    }
#endif // defined(FLASH_SAFE_API)
    return result;
}
bool flash_init_data_default(void)
{
    // FLASH SEC - 4
    // Dangerous, here are dinosaur infested!!!!!
    // Reboot required!!!
    // It will init system data to default!
    bool result = false;
#if defined(FLASH_SAFE_API)
    if (SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_safe_get_sec_num() - 4)))
    {
        if (SPI_FLASH_RESULT_OK == flash_safe_write((flash_safe_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)flash_init_data, 128))
        {
            result = true;
        }
    }
#else
    if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 4)))
    {
        if (SPI_FLASH_RESULT_OK == spi_flash_write((flash_rom_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)flash_init_data, 128))
        {
            result = true;
        }
    }
#endif // defined(FLASH_SAFE_API)
    return result;
}
Exemple #4
0
static int
flash_char_write(struct inode *inode, struct file *filp,
		 const char *buf, int count)
{
	int wlen;
	struct flashpartition *part = (struct flashpartition *)filp->private_data;

	FDEBUG(printk("flash_char_write\n"));
	wlen = flash_safe_write(part,
				(unsigned char *)part->start + filp->f_pos,
				(unsigned char *)buf, count);

	/* advance file position pointer */

	if(wlen >= 0)
		filp->f_pos += wlen;

	return wlen;
}
Exemple #5
0
static s32_t my_spiffs_write(u32_t addr, u32_t size, u8_t *src) {
	flash_safe_write(addr, src, size);
	return SPIFFS_OK;
}