Пример #1
0
int
flash_program_buf(volatile flash_t *addr, flash_t *data, int len,
                  unsigned long block_mask, int buffer_size)
{
    unsigned int offset = (unsigned int) addr;
    cyg_uint8 *buf = (cyg_uint8 *) data;

    // This helps speed up the programming
    static cyg_uint8 tmp[4096];

    offset -= (unsigned int) cyg_dev_flash_synth_base;

    while (len > 0) {
        int i;
        int write_size = MIN(len, sizeof(tmp));
        // Writing to NOR flash only sets bits from 1 to 0, not vice-versa
        cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
                          CYG_HAL_SYS_SEEK_SET);
        cyg_hal_sys_read(cyg_dev_flash_synth_flashfd, tmp, write_size);
        for (i = 0; i < write_size; i++)
            tmp[i] = tmp[i] & buf[i];
        cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
                          CYG_HAL_SYS_SEEK_SET);
        cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, tmp, write_size);
        // Process next chunk
        buf += write_size;
        offset += write_size;
        len -= write_size;        
    }
    
    return FLASH_ERR_OK;
}
Пример #2
0
int
flash_program_buf(volatile flash_t *addr, flash_t *data, int len,
                  unsigned long block_mask, int buffer_size)
{
  
    int offset = (int)addr;
    offset -= (int)cyg_dev_flash_synth_base;

    cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset, CYG_HAL_SYS_SEEK_SET);
    cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, data, len);
  
    return FLASH_ERR_OK;
}
Пример #3
0
static Cyg_ErrNo 
synth_disk_read(disk_channel *chan, 
                void         *buf,
                cyg_uint32    len,
                cyg_uint32    block_num)
{
    synth_disk_info_t *synth_info = (synth_disk_info_t *)chan->dev_priv;

#ifdef DEBUG
    diag_printf("synth disk read block %d\n", block_num);
#endif
    
    if (synth_info->filefd >= 0)
    {
        cyg_hal_sys_lseek(synth_info->filefd, 
                          block_num * chan->info->block_size,
                          CYG_HAL_SYS_SEEK_SET);
        cyg_hal_sys_read(synth_info->filefd, buf, len*512);
        return ENOERR;
    }
    return -EIO; 
}
Пример #4
0
int flash_erase_block(volatile flash_t *block, unsigned int block_size)
{
    int i;
    int offset = (int)block;
    offset -= (int)cyg_dev_flash_synth_base;

    cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
                      CYG_HAL_SYS_SEEK_SET);
  
    if (!empty_inited) {
        memset(empty, 0xff, sizeof(empty));
        empty_inited = true;
    }

    CYG_ASSERT(sizeof(empty) < block_size,
               "Eckk! Can't work with such small blocks");
    CYG_ASSERT((block_size % sizeof(empty)) == 0,
               "Eckk! Can't work with that odd size block");

    for (i=0; (i * sizeof(empty)) < block_size; i++) {
        cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, empty, sizeof(empty));
    }
    return FLASH_ERR_OK;
}