⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tm_basic.cxx

📁 eCos1.31版
💻 CXX
📖 第 1 页 / 共 5 页
字号:
        cyg_semaphore_peek(&test_semaphores[i], &sem_val);        HAL_CLOCK_READ(&semaphore_ft[i].end);    }    show_times(semaphore_ft, nsemaphores, "Peek semaphore");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nsemaphores;  i++) {        HAL_CLOCK_READ(&semaphore_ft[i].start);        cyg_semaphore_destroy(&test_semaphores[i]);        HAL_CLOCK_READ(&semaphore_ft[i].end);    }    show_times(semaphore_ft, nsemaphores, "Destroy semaphore");    run_semaphore_circuit_test();    end_of_test_group();}voidrun_semaphore_circuit_test(void){    int i;    // Set my priority lower than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 3);    // Set up for full semaphore post/wait test    cyg_semaphore_init(&test_semaphores[0], 0);    cyg_semaphore_init(&synchro, 0);    cyg_thread_create(2,              // Priority - just a number                      semaphore_test,           // entry                      0,               // index                      thread_name("thread", 0),     // Name                      &stacks[0][0],   // Stack                      STACK_SIZE,      // Size                      &semaphore_test_thread_handle,   // Handle                      &semaphore_test_thread    // Thread data structure        );    cyg_thread_resume(semaphore_test_thread_handle);    for (i = 0;  i < nsemaphores;  i++) {        wait_for_tick(); // Wait until the next clock tick to minimize aberations        HAL_CLOCK_READ(&semaphore_ft[i].start);        cyg_semaphore_post(&test_semaphores[0]);        cyg_semaphore_wait(&synchro);    }    cyg_thread_delete(semaphore_test_thread_handle);    show_times(semaphore_ft, nsemaphores, "Post/Wait semaphore");}voidrun_counter_tests(void){    int i;    cyg_tick_count_t val=0;    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        cyg_counter_create(&counters[i], &test_counters[i]);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Create counter");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        val = cyg_counter_current_value(counters[i]);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Get counter value");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        cyg_counter_set_value(counters[i], val);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Set counter value");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        cyg_counter_tick(counters[i]);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Tick counter");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        cyg_counter_delete(counters[i]);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Delete counter");    end_of_test_group();}// Alarm callback functionvoidalarm_cb(cyg_handle_t alarm, cyg_addrword_t val){    // empty call back}// Callback used to test determinancystatic volatile int alarm_cnt;voidalarm_cb2(cyg_handle_t alarm, cyg_addrword_t indx){    if (alarm_cnt == nscheds) return;    sched_ft[alarm_cnt].start = 0;    HAL_CLOCK_READ(&sched_ft[alarm_cnt++].end);    if (alarm_cnt == nscheds) {        cyg_semaphore_post(&synchro);    }}static voidalarm_cb3(cyg_handle_t alarm, cyg_addrword_t indx){    if (alarm_cnt == nscheds) {        cyg_semaphore_post(&synchro);    } else {        sched_ft[alarm_cnt].start = 0;        cyg_thread_resume((cyg_handle_t)indx);    }}// Null thread, used to keep scheduler busyvoidalarm_test(cyg_uint32 id){    while (true) {        cyg_thread_yield();    }}// Thread that suspends itself at the first opportunityvoidalarm_test2(cyg_uint32 id){    cyg_handle_t me = cyg_thread_self();    while (true) {        HAL_CLOCK_READ(&sched_ft[alarm_cnt++].end);        cyg_thread_suspend(me);    }}voidrun_alarm_tests(void){    int i;    cyg_tick_count_t init_val, step_val;    cyg_handle_t rtc_handle;    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ncounters;  i++) {        cyg_counter_create(&counters[i], &test_counters[i]);    }    for (i = 0;  i < nalarms;  i++) {        HAL_CLOCK_READ(&alarm_ft[i].start);        cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]);        HAL_CLOCK_READ(&alarm_ft[i].end);    }    show_times(alarm_ft, nalarms, "Create alarm");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    init_val = 0;  step_val = 0;    for (i = 0;  i < nalarms;  i++) {        HAL_CLOCK_READ(&alarm_ft[i].start);        cyg_alarm_initialize(alarms[i], init_val, step_val);        HAL_CLOCK_READ(&alarm_ft[i].end);    }    show_times(alarm_ft, nalarms, "Initialize alarm");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    init_val = 0;  step_val = 0;    for (i = 0;  i < nalarms;  i++) {        HAL_CLOCK_READ(&alarm_ft[i].start);        cyg_alarm_disable(alarms[i]);        HAL_CLOCK_READ(&alarm_ft[i].end);    }    show_times(alarm_ft, nalarms, "Disable alarm");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    init_val = 0;  step_val = 0;    for (i = 0;  i < nalarms;  i++) {        HAL_CLOCK_READ(&alarm_ft[i].start);        cyg_alarm_enable(alarms[i]);        HAL_CLOCK_READ(&alarm_ft[i].end);    }    show_times(alarm_ft, nalarms, "Enable alarm");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nalarms;  i++) {        HAL_CLOCK_READ(&alarm_ft[i].start);        cyg_alarm_delete(alarms[i]);        HAL_CLOCK_READ(&alarm_ft[i].end);    }    show_times(alarm_ft, nalarms, "Delete alarm");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_counter_create(&counters[0], &test_counters[0]);    cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]);    init_val = 9999;  step_val = 9999;    cyg_alarm_initialize(alarms[0], init_val, step_val);    cyg_alarm_enable(alarms[0]);    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        cyg_counter_tick(counters[0]);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Tick counter [1 alarm]");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_counter_create(&counters[0], &test_counters[0]);    for (i = 0;  i < nalarms;  i++) {        cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[i], &test_alarms[i]);        init_val = 9999;  step_val = 9999;        cyg_alarm_initialize(alarms[i], init_val, step_val);        cyg_alarm_enable(alarms[i]);    }    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        cyg_counter_tick(counters[0]);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Tick counter [many alarms]");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_counter_create(&counters[0], &test_counters[0]);    cyg_alarm_create(counters[0], alarm_cb, 0, &alarms[0], &test_alarms[0]);    init_val = 1;  step_val = 1;    cyg_alarm_initialize(alarms[0], init_val, step_val);    cyg_alarm_enable(alarms[0]);    for (i = 0;  i < ncounters;  i++) {        HAL_CLOCK_READ(&counter_ft[i].start);        cyg_counter_tick(counters[0]);        HAL_CLOCK_READ(&counter_ft[i].end);    }    show_times(counter_ft, ncounters, "Tick & fire counter [1 alarm]");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_counter_create(&counters[0], &test_counters[0]);    for (i = 0;  i < nalarms;  i++) {        cyg_alarm_create(counters[0], alarm_cb, i, &alarms[i], &test_alarms[i]);        init_val = 1;  step_val = 1;        cyg_alarm_initialize(alarms[i], init_val, step_val);        cyg_alarm_enable(alarms[i]);    }    for (i = 0;  i < nalarms;  i++) {        HAL_CLOCK_READ(&alarm_ft[i].start);        cyg_counter_tick(counters[0]);        HAL_CLOCK_READ(&alarm_ft[i].end);    }    for (i = 0;  i < nalarms;  i++) {        cyg_alarm_delete(alarms[i]);    }    show_times(alarm_ft, nalarms, "Tick & fire counters [>1 together]");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_counter_create(&counters[0], &test_counters[0]);    for (i = 0;  i < nalarms;  i++) {        cyg_alarm_create(counters[0], alarm_cb, i, &alarms[i], &test_alarms[i]);        init_val = i+1;  step_val = nalarms+1;        cyg_alarm_initialize(alarms[i], init_val, step_val);        cyg_alarm_enable(alarms[i]);    }    for (i = 0;  i < nalarms;  i++) {        HAL_CLOCK_READ(&alarm_ft[i].start);        cyg_counter_tick(counters[0]);        HAL_CLOCK_READ(&alarm_ft[i].end);    }    for (i = 0;  i < nalarms;  i++) {        cyg_alarm_delete(alarms[i]);    }    show_times(alarm_ft, nalarms, "Tick & fire counters [>1 separately]");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle);    cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]);    init_val = 5;  step_val = 5;  alarm_cnt = 0;    cyg_alarm_initialize(alarms[0], init_val, step_val);    cyg_semaphore_init(&synchro, 0);    cyg_alarm_enable(alarms[0]);    cyg_semaphore_wait(&synchro);    cyg_alarm_disable(alarms[0]);    cyg_alarm_delete(alarms[0]);    show_times(sched_ft, nscheds, "Alarm latency [0 threads]");    // Set my priority higher than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 2);    for (i = 0;  i < 2;  i++) {        cyg_thread_create(10,              // Priority - just a number                          alarm_test,      // entry                          i,               // index                          thread_name("thread", i),     // Name                          &stacks[i][0],   // Stack                          STACK_SIZE,      // Size                          &threads[i],     // Handle                          &test_threads[i] // Thread data structure            );        cyg_thread_resume(threads[i]);    }    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle);    cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]);    init_val = 5;  step_val = 5;  alarm_cnt = 0;    cyg_alarm_initialize(alarms[0], init_val, step_val);    cyg_semaphore_init(&synchro, 0);    cyg_alarm_enable(alarms[0]);    cyg_semaphore_wait(&synchro);    cyg_alarm_disable(alarms[0]);    cyg_alarm_delete(alarms[0]);    show_times(sched_ft, nscheds, "Alarm latency [2 threads]");    for (i = 0;  i < 2;  i++) {        cyg_thread_suspend(threads[i]);        cyg_thread_delete(threads[i]);    }    // Set my priority higher than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 2);    for (i = 0;  i < ntest_threads;  i++) {        cyg_thread_create(10,              // Priority - just a number                          alarm_test,      // entry                          i,               // index                          thread_name("thread", i),     // Name                          &stacks[i][0],   // Stack                          STACK_SIZE,      // Size                          &threads[i],     // Handle                          &test_threads[i] // Thread data structure            );        cyg_thread_resume(threads[i]);    }    wait_for_tick(); // Wait until the next clock tick to minimize aberations    cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle);    cyg_alarm_create(rtc_handle, alarm_cb2, 0, &alarms[0], &test_alarms[0]);    init_val = 5;  step_val = 5;  alarm_cnt = 0;    cyg_alarm_initialize(alarms[0], init_val, step_val);    cyg_semaphore_init(&synchro, 0);    cyg_alarm_enable(alarms[0]);    cyg_semaphore_wait(&synchro);    cyg_alarm_disable(alarms[0]);    cyg_alarm_delete(alarms[0]);    show_times(sched_ft, nscheds, "Alarm latency [many threads]");    for (i = 0;  i < ntest_threads;  i++) {        cyg_thread_suspend(threads[i]);        cyg_thread_delete(threads[i]);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -