#include #include #include #include /* now declare (and allocate space for) some kernel objects, like the edf threads we will use */ cyg_thread thread_s[2]; /* space for EDF thread objects */ char stack[2][4096]; /* space for EDF 4K stacks */ /* now the handles for the threads */ cyg_handle_t simple_threadA, simple_threadB; /* and now variables for the procedure which is the thread */ cyg_thread_entry_t simple_program; /* and now a mutex to protect calls to the C library */ cyg_mutex_t cliblock; /* we install our own startup routine which sets up threads */ void cyg_user_start(void) { printf("With underlying file support (edf.cxx, edf.hxx)\n"); printf("Just running with EDF scheduler in CDL v2.5\n"); printf("Now we have cyg_edf_sched_info type in ktypes.h\n"); printf("+ thread_edf_info prop in Cyg_SchedThread_Implementation of edf.hxx\n"); cyg_mutex_init(&cliblock); cyg_thread_create(4, simple_program, (cyg_addrword_t) 0, "Thread A", (void *) stack[0], 4096, &simple_threadA, &thread_s[0]); cyg_thread_create(5, simple_program, (cyg_addrword_t) 1, "Thread B", (void *) stack[1], 4096, &simple_threadB, &thread_s[1]); printf("Threads are created\n"); cyg_thread_resume(simple_threadA); cyg_thread_resume(simple_threadB); } /* this is a simple program which runs in a thread */ void simple_program(cyg_addrword_t data) { int message = (int) data; int delay; printf("Beginning execution; thread data is %d\n", message); cyg_thread_delay(200); cyg_thread_info info; cyg_handle_t cur_thread; for (;;) { delay = 400 + (rand() % 50); cur_thread = cyg_thread_self(); /* note: printf() must be protected by a call to cyg_mutex_lock() */ cyg_mutex_lock(&cliblock); { printf("Thread %d: and now a delay of %d clock ticks\n", message, delay); cyg_thread_get_info(cur_thread, cyg_thread_get_id( cyg_thread_self() ), &info); printf("ID: %d, name: %10s, ser pri: %d cur pri: %d stack use: %d\n\n", info.id, info.name, info.set_pri, info.cur_pri, info.stack_used); /* printf("Name of the thread is %d\n", cyg_thread_get_id( cyg_thread_self() ));*/ } cyg_mutex_unlock(&cliblock); cyg_thread_delay(delay); } }