Example #1
0
/*
 * sleep_hw_ticks
 * @ticks: Number of hardware ticks for which this task is needed to sleep.
 * This function will busy sleep the current task execution for given number
 * of hardware ticks.
 */
void sleep_hw_ticks(uint64_t ticks)
{
    uint64_t hw_tick;

    /* Wait before reading back from the LCD. */
    hw_tick = current_hardware_tick();
    while ((current_hardware_tick() - hw_tick) < ticks)
    {
        /* Yield current task to execute any high priority task. */
        task_yield();
    }

} /* sleep_hw_ticks */
Example #2
0
/*
 * net_port_random
 * @return: A random 16-bit port number will be returned here.
 * This function will generate a random 16-bit port number and return it's
 * value.
 */
uint16_t net_port_random(void)
{
    /* Return a random port number. */
    return ((uint16_t)(current_hardware_tick() & 0xFFFF));

} /* net_port_random */
Example #3
0
void ctx_sample_task(void *argv)
{
    UNUSED_PARAM(argv);
    uint32_t last_tick;
    uint32_t n = 0;
    uint32_t com = 0;
    uint32_t *ret_time = (uint32_t *)argv;
    MEM_TEST_NODE *mem;
    uint32_t mem_size;
    uint32_t total_allocated;
    uint32_t num_allocated, mem_num;
    MEM_TEST_LIST mem_test_list;

    ret_time[0] = 0;

    num_allocated = 0;
    total_allocated = 0;
    mem_test_list.head =
    mem_test_list.tail = NULL;

    /* Initialize random seed. */
    srand(current_hardware_tick());

    while(1)
    {
        n= n + 1;
        last_tick = current_hardware_tick();
        task_yield();

        if (com > 0x0FFFFFFF)
        {
            com = 0;
            n = 1;
        }

        last_tick = current_hardware_tick() - last_tick;
        if (last_tick < MAX_TIMER_TICKS)
        {
            com += last_tick;
            ret_time[0] = (com / n);
        }

        mem_size = (rand() % MAX_ALLOC) + sizeof(MEM_TEST_NODE);
        mem = (MEM_TEST_NODE *)mem_dynamic_alloc(mem_size);

        if (mem)
        {
            total_allocated += mem_size;
            mem->size = mem_size;
            sll_append(&mem_test_list, mem, OFFSETOF(MEM_TEST_NODE, next));
            num_allocated++;
        }

        while ( (total_allocated > MEM_PER_TASK) || (mem == NULL) )
        {
            mem_num = rand() % num_allocated;
            mem = sll_search_pop(&mem_test_list, pop_n, &mem_num, OFFSETOF(MEM_TEST_NODE, next));

            if (mem)
            {
                total_allocated -= mem->size;
                num_allocated --;
                mem_dynamic_dealloc((uint8_t *)mem);
            }
            else
            {
                break;
            }
        }
    }
}