示例#1
0
ret_code_t fs_erase(fs_config_t const *       p_config,
                    uint32_t          * const p_addr,
                    fs_length_t const         length_words)
{
    if ((m_flags & FS_FLAG_INIT) == 0)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    if (!check_config(p_config))
    {
        return NRF_ERROR_FORBIDDEN;
    }

    /** Check that the address is aligned on a page boundary and the length to erase
     *  is a multiple of the page size. */
    if (((uint32_t)p_addr & (FS_PAGE_SIZE - 1)) ||
        (length_words     & (FS_PAGE_SIZE_WORDS - 1)))
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    // Check that the erase operation is on pages owned by this user (configuration).
    if ((p_addr < p_config->p_start_addr) || ((p_addr + length_words) > p_config->p_end_addr))
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    return cmd_enqueue(p_config, FS_OP_ERASE, p_addr, NULL, length_words);
}
示例#2
0
ret_code_t fs_store(fs_config_t const *       p_config,
                    uint32_t    const *       p_addr,
                    uint32_t    const * const p_data,
                    fs_length_t               length_words)
{
    if ((m_flags & FS_FLAG_INIT) == 0)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    if (!check_config(p_config))
    {
        return NRF_ERROR_FORBIDDEN;
    }

    if (!is_word_aligned(p_addr))
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    // Check that the erase operation is on pages owned by this user (configuration).
    if ((p_addr < p_config->p_start_addr) || ((p_addr + length_words) > p_config->p_end_addr))
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    return cmd_enqueue(p_config, FS_OP_STORE, p_addr, p_data, length_words);
}
示例#3
0
ret_code_t fs_store(fs_config_t const * const p_config,
                    uint32_t    const * const p_dest,
                    uint32_t    const * const p_src,
                    uint16_t                  length_words)
{
    fs_cmd_t cmd;

    if ((m_flags & FS_FLAG_INIT) == 0)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    if (!check_config(p_config))
    {
        return NRF_ERROR_FORBIDDEN;
    }

    if (((uint32_t)p_src  & 0x3) ||
        ((uint32_t)p_dest & 0x3))
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    if ((p_dest < p_config->p_start_addr) || ((p_dest + length_words) > p_config->p_end_addr))
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    cmd.p_config           = p_config;
    cmd.op_code            = FS_OP_STORE;
    cmd.store.p_src        = p_src;
    cmd.store.p_dest       = p_dest;
    cmd.store.length_words = length_words;
    cmd.store.offset       = 0;

    return cmd_enqueue(&cmd);
}
示例#4
0
ret_code_t fs_erase(fs_config_t const * const p_config,
                    uint32_t    const * const p_page_addr,
                    uint16_t                  num_pages)
{

    fs_cmd_t cmd;

    if ((m_flags & FS_FLAG_INIT) == 0)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    if (!check_config(p_config))
    {
        return NRF_ERROR_FORBIDDEN;
    }

    if (((uint32_t)p_page_addr % FS_PAGE_SIZE) != 0)
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    if ((p_page_addr < p_config->p_start_addr) ||
        (p_page_addr + (FS_PAGE_SIZE_WORDS * num_pages) > p_config->p_end_addr))
    {
        return NRF_ERROR_INVALID_DATA;
    }

    cmd.p_config             = p_config;
    cmd.op_code              = FS_OP_ERASE;
    cmd.erase.page           = ((uint32_t)p_page_addr / FS_PAGE_SIZE);
    cmd.erase.pages_erased   = 0;
    cmd.erase.pages_to_erase = num_pages;

    return cmd_enqueue(&cmd);
}