Exemplo n.º 1
0
uint32_t pstorage_register(pstorage_module_param_t * p_module_param,
                           pstorage_handle_t       * p_block_id)
{
    uint16_t page_count;
    uint32_t total_size;

    VERIFY_MODULE_INITIALIZED();
    NULL_PARAM_CHECK(p_module_param);
    NULL_PARAM_CHECK(p_block_id);
    NULL_PARAM_CHECK(p_module_param->cb);
    BLOCK_SIZE_CHECK(p_module_param->block_size);    
    BLOCK_COUNT_CHECK(p_module_param->block_count, p_module_param->block_size);

    // Block size should be a multiple of word size.
    if (!((p_module_param->block_size % sizeof(uint32_t)) == 0))
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    if (m_next_app_instance == PSTORAGE_MAX_APPLICATIONS)
    {
        return NRF_ERROR_NO_MEM;
    }

    p_block_id->module_id = m_next_app_instance;
    p_block_id->block_id  = m_next_page_addr;

    m_app_table[m_next_app_instance].base_id     = p_block_id->block_id;
    m_app_table[m_next_app_instance].cb          = p_module_param->cb;
    m_app_table[m_next_app_instance].block_size  = p_module_param->block_size;
    m_app_table[m_next_app_instance].block_count = p_module_param->block_count;

    // Calculate number of flash pages allocated for the device.
    page_count = 0;
    total_size = p_module_param->block_size * p_module_param->block_count;
    do
    {
        page_count++;
        if (total_size > PSTORAGE_FLASH_PAGE_SIZE)
        {
            total_size -= PSTORAGE_FLASH_PAGE_SIZE;
        }
        else
        {
            total_size = 0;
        }
        m_next_page_addr += PSTORAGE_FLASH_PAGE_SIZE;
    }
    while (total_size > 0);

    m_app_table[m_next_app_instance].num_of_pages = page_count;
    m_next_app_instance++;

    return NRF_SUCCESS;
}
Exemplo n.º 2
0
uint32_t pstorage_register(pstorage_module_param_t * p_module_param,
                           pstorage_handle_t       * p_block_id)
{


    VERIFY_MODULE_INITIALIZED();
    NULL_PARAM_CHECK(p_module_param);
    NULL_PARAM_CHECK(p_block_id);
    NULL_PARAM_CHECK(p_module_param->cb);
    BLOCK_SIZE_CHECK(p_module_param->block_size);
    BLOCK_COUNT_CHECK(p_module_param->block_count, p_module_param->block_size);

#ifndef SUPPORT_MODULES_LARGER_THAN_PAGE
    MODULE_SIZE_CHECK(((uint16_t)(p_module_param->block_size)*(p_module_param->block_count)));
#endif


    if (m_next_app_instance == PSTORAGE_MAX_APPLICATIONS)
    {
        return NRF_ERROR_NO_MEM;
    }

    p_block_id->module_id                        = m_next_app_instance;
    p_block_id->block_id                         = m_next_page_addr;

    m_app_table[m_next_app_instance].base_id     = p_block_id->block_id;
    m_app_table[m_next_app_instance].cb          = p_module_param->cb;
    m_app_table[m_next_app_instance].block_size  = p_module_param->block_size;
    m_app_table[m_next_app_instance].block_count = p_module_param->block_count;

    // Calculate number of flash pages allocated for the device.


#ifdef SUPPORT_MODULES_LARGER_THAN_PAGE
    uint16_t page_count = 0;
    uint32_t total_size;
    total_size = p_module_param->block_size * p_module_param->block_count;
    do
    {
        page_count++;

        if (total_size > PSTORAGE_FLASH_PAGE_SIZE)
        {
            total_size -= PSTORAGE_FLASH_PAGE_SIZE;
        }
        else
        {
            total_size = 0;
        }

        m_next_page_addr += PSTORAGE_FLASH_PAGE_SIZE;

    } while (total_size >= PSTORAGE_FLASH_PAGE_SIZE);
    m_app_table[m_next_app_instance].no_of_pages = page_count;
#else
    m_app_table[m_next_app_instance].no_of_pages = 1;
    m_next_page_addr += PSTORAGE_FLASH_PAGE_SIZE;
#endif
    m_next_app_instance++;

    return NRF_SUCCESS;
}