Beispiel #1
0
ret_code_t fs_init(void)
{
    uint16_t   lowest_index = 0;
    uint16_t   lowest_order = 0xFFFF;
    uint32_t * current_end  = (uint32_t*)FS_PAGE_END_ADDR;
    uint32_t   num_left     = FS_SECTION_VARS_COUNT;

    queue_init();

    /** Assign pages to registered users, beginning with the ones with the lowest
     *  order, which will be assigned pages with the lowest memory address. */
    do
    {
        fs_config_t * p_config;
        for (uint16_t i = 0; i < FS_SECTION_VARS_COUNT; i++)
        {
            p_config = FS_SECTION_VARS_GET(i);

            // Skip the ones which have the end-address already set.
            if (p_config->p_end_addr != NULL)
                continue;

            if (p_config->page_order < lowest_order)
            {
                lowest_order = p_config->page_order;
                lowest_index = i;
            }
        }

        p_config = FS_SECTION_VARS_GET(lowest_index);

        p_config->p_end_addr   = current_end;
        p_config->p_start_addr = p_config->p_end_addr - (p_config->num_pages * FS_PAGE_SIZE_WORDS);

        current_end  = p_config->p_start_addr;
        lowest_order = 0xFFFF;

    } while ( --num_left > 0 );

    m_flags |= FS_FLAG_INIT;

    return NRF_SUCCESS;
}
Beispiel #2
0
// Just for testing out section vars (across many compilers).
void fs_debug_print()
{
    printf("fs start address: 0x%08lx\r\n", (unsigned long)FS_SECTION_VARS_START_ADDR);
    printf("fs end address: 0x%08lx\r\n",   (unsigned long)FS_SECTION_VARS_END_ADDR);
    printf("Num items: 0x%08lx\r\n",        (unsigned long)FS_SECTION_VARS_COUNT);
    printf("===== ITEMS %lu =====\r\n",     (unsigned long)FS_SECTION_VARS_COUNT);

    for(int i = 0; i < FS_SECTION_VARS_COUNT; i++)
    {
        fs_config_t* config = FS_SECTION_VARS_GET(i);
        printf( "Address: 0x%08lx, CB: 0x%08lx\r\n",
                (unsigned long)config, (unsigned long)config->cb );
    }
    printf("\r\n");
}
Beispiel #3
0
fs_ret_t fs_init(void)
{
    uint32_t const   users         = FS_SECTION_VARS_COUNT;
    uint32_t const * p_current_end = FS_PAGE_END_ADDR;
    uint32_t         index_max     = 0x00;
    uint32_t         index_last    = 0xFFFFFFFF;

    if (m_flags & FS_FLAG_INITIALIZED)
    {
        return FS_SUCCESS;
    }

    #if 0
    // Check for configurations with duplicate priority.
    for (uint32_t i = 0; i < users; i++)
    {
        for (uint32_t j = i + 1; j < users; j++)
        {
            fs_config_t const * const p_config_i = FS_SECTION_VARS_GET(i);
            fs_config_t const * const p_config_j = FS_SECTION_VARS_GET(j);

            if (p_config_i->page_order == p_config_j->page_order)
            {
                // Error.
                return FS_ERR_INVALID_CFG;
            }
        }
    }
    #endif

    // Assign pages to registered users, beginning with the ones with the highest
    // priority, which will be assigned pages with the highest memory address.

    for (uint32_t i = 0; i < users; i++)
    {
        uint8_t max_priority  = 0x00;

        for (uint32_t j = 0; j < users; j++)
        {
            fs_config_t * const p_config = FS_SECTION_VARS_GET(j);

            // Skip the one assigned during last iteration.
            if (j == index_last)
            {
                continue;
            }

            if (p_config->priority >= max_priority)
            {
                max_priority = p_config->priority;
                index_max    = j;
            }
        }

        fs_config_t * const p_config = FS_SECTION_VARS_GET(index_max);

        p_config->p_end_addr   = p_current_end;
        p_config->p_start_addr = p_current_end - (p_config->num_pages * FS_PAGE_SIZE_WORDS);

        p_current_end = p_config->p_start_addr;

        index_last = index_max;
    }

    m_flags |= FS_FLAG_INITIALIZED;

    return FS_SUCCESS;
}