void abtastung1(cyg_addrword_t arg){ while(1){ ezs_watch_wcet(2000); cyg_thread_suspend(cyg_thread_self()); cyg_uint32 tmp = ezs_watch_stop(&messer); } }
// A little test thread. void thread(cyg_addrword_t arg){ uint8_t counter = 0; while(1) { printf("Hallo!\r\n"); ezs_sb16_play_sample(&sb16, counter++); cyg_thread_suspend(cyg_thread_self()); } }
void analyse(cyg_addrword_t arg){ while(1){ cyg_uint32 tmp = ezs_watch_stop(&messer2); if(tmp > 20000) printf("Thread3 periode: %d\r\n", tmp); ezs_watch_wcet(3500); ezs_watch_start(&messer2); cyg_thread_suspend(cyg_thread_self()); } }
void abtastung2(cyg_addrword_t arg){ while(1){ cyg_uint32 tmp = ezs_watch_stop(&messer1); if(tmp > 20000) printf("Thread2 periode: %d\r\n", tmp); ezs_watch_wcet(2000); ezs_watch_start(&messer1); cyg_thread_suspend(cyg_thread_self()); } }
static void entry1( cyg_addrword_t data ) { cyg_handle_t self; CHECK( 333 == (int)data ); self = cyg_thread_self(); CHECK( self == pt1 ); cyg_thread_suspend(pt1); cyg_thread_exit(); // no guarantee this will be called }
static int e_thread_suspend(lua_State *L) { lua_State *L1; lua_ecos_state_t *state; L1 = (lua_State *) *((cyg_addrword_t *) check_user_data(L, 1, E_THREAD)); state = (lua_ecos_state_t *) lua_getuserspace(L1); cyg_thread_suspend(state->thread->handle); return 0; }
static void entry0( cyg_addrword_t data ) { CHECK( 222 == (int)data ); cyg_thread_suspend(pt1); cyg_thread_resume(pt1); cyg_thread_delay(1); cyg_thread_resume(pt1); cyg_thread_delay(1); CYG_TEST_PASS_FINISH("Kernel C API Thread 1 OK"); }
void run_test_timeslice(int nthread) { int i,j; cyg_uint32 cpu_total[CYGNUM_KERNEL_CPU_MAX]; cyg_uint32 cpu_threads[CYGNUM_KERNEL_CPU_MAX]; cyg_uint32 thread_total[NTHREADS_MAX]; CYG_TEST_INFO( "Timeslice Test: Check timeslicing works"); // Init flags. for (i = 0; i < nthread; i++) for( j = 0; j < ncpus; j++ ) slicerun[i][j] = 0; // Set my priority higher than any I plan to create cyg_thread_set_priority(cyg_thread_self(), 2); for (i = 0; i < nthread; i++) { cyg_thread_create(10, // Priority - just a number test_thread_timeslice, // entry i, // index "test_thread", // Name &stacks[i][0], // Stack STACK_SIZE, // Size &threads[i], // Handle &test_threads[i] // Thread data structure ); cyg_thread_resume( threads[i]); } // Just wait a while, until the threads have all run for a bit. cyg_thread_delay( CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS*100 ); // Suspend all the threads for (i = 0; i < nthread; i++) { cyg_thread_suspend(threads[i]); } // And check that a thread ran on each CPU, and that each thread // ran. diag_printf(" Thread "); for( j = 0; j < ncpus; j++ ) { cpu_total[j] = 0; cpu_threads[j] = 0; // " %11d" __123456789ab" diag_printf(" CPU %2d",j); } // " %11d" __123456789ab" diag_printf(" Total\n"); for (i = 0; i < nthread; i++) { thread_total[i] = 0; diag_printf(" %2d ",i); for( j = 0; j < ncpus; j++ ) { thread_total[i] += slicerun[i][j]; cpu_total[j] += slicerun[i][j]; if( slicerun[i][j] > 0 ) cpu_threads[j]++; diag_printf(" %11d",slicerun[i][j]); } diag_printf(" %11d\n",thread_total[i]); if( thread_total[i] == 0 ) failed++; } diag_printf(" Total "); for( j = 0; j < ncpus; j++ ) diag_printf(" %11d",cpu_total[j]); diag_printf("\n"); diag_printf("Threads "); for( j = 0; j < ncpus; j++ ) { diag_printf(" %11d",cpu_threads[j]); if( cpu_threads[j] < 2 ) failed++; } diag_printf("\n"); // Delete all the threads for (i = 0; i < nthread; i++) { cyg_thread_delete(threads[i]); } CYG_TEST_INFO( "Timeslice Test: done"); }
void LinkLocal_ip_Task(cyg_addrword_t arg) { int prob_conut, retry_count; uint32 LinkLocalIP; int get_conflict; //get arp reply to conflict our IP LinkLocal_set_state( NO_USE ); while(1){ cyg_semaphore_init(&linklocal_sem, 0); cyg_semaphore_wait(&linklocal_sem); init_LinkLocal(); if(rendezvous_TaskHdl != 0) { cyg_thread_suspend(rendezvous_TaskHdl); } prob_conut = 0; retry_count = 0; while(1){ switch( LinkLocal_get_current_state() ){ case PROBE: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 0 ); LinkLocalIP = SetLinkLocalIP(Lanface, 0 ); //ZOTIPS break; case RETRY: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 1 ); LinkLocalIP = SetLinkLocalIP(Lanface, 1 ); //ZOTIPS break; case ANNOUNCE: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 0 ); //ZOTIPS set_netif_ip(WLanface); LinkLocalIP = SetLinkLocalIP(Lanface, 0 ); //ZOTIPS set_netif_ip(Lanface); //ZOTIPS break; } //ZOTIPS LinkLocal_IP_Query(LinkLocalIP, WLanface); LinkLocal_IP_Query(LinkLocalIP, Lanface); //ZOTIPS get_conflict = cyg_semaphore_timed_wait(&linklocal_conflict, cyg_current_time() +(900/MSPTICK)); switch( LinkLocal_get_current_state() ){ case PROBE: if( get_conflict ) { LinkLocal_set_state( RETRY ); ppause(1000); } else prob_conut++; if( prob_conut == 3) { ppause(900); LinkLocal_set_state( ANNOUNCE ); } break; case RETRY: if( get_conflict ) { retry_count++; } else{ LinkLocal_set_state( PROBE ); prob_conut = 1; } ppause(1000); if( retry_count == 15) { ppause(900); LinkLocal_set_state( ANNOUNCE ); } break; case ANNOUNCE: if(get_conflict) ppause(1000); //ZOTIPS LinkLocal_IP_Query(LinkLocalIP, WLanface); LinkLocal_IP_Query(LinkLocalIP, Lanface); //ZOTIPS WriteToEEPROM(&EEPROM_Data); LinkLocal_set_state( IDLE ); break; } if( LinkLocal_get_current_state() == IDLE) break; } if( rendezvous_TaskHdl == 0) cyg_semaphore_post( &rendezvous_sem); else { cyg_thread_resume(rendezvous_TaskHdl); Need_Rendezous_Reload = 1; } cyg_semaphore_post(&DhcpWaitLinklocal_sem); } }
void controller( cyg_addrword_t id ) { cyg_priority_t pri; int i; cyg_mutex_init( &worker_mutex ); cyg_cond_init( &worker_cv, &worker_mutex ); // 1 thread, it is running, it calls BREAKME(); // +++ Thread status returned: // +++ 1 thread, running, is the current one breakme(); // Create N more threads; they are all suspended after creation. Adjust // the priorities of all the threads to lower than the controlling thread. // Make them all be distinct priorities as far as possible. BREAKME(); // +++ 1 thread, running, + N suspended ones of different prios. for( i = 1; i < THREADS; i++ ) { pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE; cyg_thread_create(pri, worker, (cyg_addrword_t)i, "worker", (void *)(&thread_stack[i]), STACKSIZE, &thread_handle[i], &thread[i]); } breakme(); // Adjust the priorities of all the threads to lower than the controlling // thread. Make them all be THE SAME priority. BREAKME(); // +++ 1 thread, running, + N suspended ones of same prio. for( i = 1; i < THREADS; i++ ) { cyg_thread_set_priority( thread_handle[i], WORKER_PRI ); } breakme(); // Release all the N threads, BREAKME(); // +++ 1 thread, running, + N ready ones of same prio. for( i = 1; i < THREADS; i++ ) { cyg_thread_resume( thread_handle[i] ); } breakme(); // Adjust the priorities of all the threads, lower than the controlling // thread. Make them all be distinct priorities as far as possible. // BREAKME(); // +++ 1 thread, running, + N ready ones of different prios. for( i = 1; i < THREADS; i++ ) { pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE; cyg_thread_set_priority( thread_handle[i], pri ); } breakme(); // Command all the N threads to sleep; switch my own priority to lower // than theirs so that they all run and sleep, then I get back in and // BREAKME(); // +++ 1 thread, running, + N sleeping ones of different prios. worker_state = WORKER_STATE_WAIT; cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO ); breakme(); // Make them all be THE SAME priority; BREAKME(); // +++ 1 thread, running, + N sleeping ones of same prio. for( i = 1; i < THREADS; i++ ) { cyg_thread_set_priority( thread_handle[i], WORKER_PRI ); } breakme(); // Wake them all up, they'll loop once and sleep again; I get in and // BREAKME(); // +++ 1 thread, running, + N sleeping ones of same prio. cyg_cond_broadcast( &worker_cv ); breakme(); // Adjust the priorities of all the threads, higher than the controlling // thread. Make them all be distinct priorities as far as possible. // BREAKME(); // +++ 1 thread, running, + N sleeping ones of different prios. for( i = 1; i < THREADS; i++ ) { pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE; cyg_thread_set_priority( thread_handle[i], pri ); } breakme(); // Wake them all up, they'll loop once and sleep again; I get in and // BREAKME(); // +++ 1 thread, running, + N sleeping ones of different prios. cyg_cond_broadcast( &worker_cv ); breakme(); // Set them all the same prio, set me to the same prio, BREAKME(); // +++ 1 running, + N sleeping, *all* the same prio. for( i = 0; i < THREADS; i++ ) { cyg_thread_set_priority( thread_handle[i], WORKER_PRI ); } breakme(); // Wake them all up, they'll loop once and sleep again; I get in and // BREAKME(); repeatedly until they have all slept again. // +++ 1 running, + some sleeping, some ready, *all* the same prio. cyg_cond_broadcast( &worker_cv ); // cyg_thread_yield(); do { breakme(); } while( workers_asleep != THREADS-1 ); breakme(); // Suspend some of the threads, BREAKME(); // +++ 1 running, + some sleeping, some suspended, *all* the same prio. for( i = 1; i < THREADS; i++ ) { // suspend every 3rd thread if( 0 == (i % 3) ) cyg_thread_suspend( thread_handle[i] ); } breakme(); // Change the prios all different, change my prio to highest , BREAKME(); // +++ 1 running, + some sleeping, some suspended, different prios. cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_HI ); for( i = 1; i < THREADS; i++ ) { pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE; cyg_thread_set_priority( thread_handle[i], pri ); } breakme(); // Wake up all the threads, BREAKME(); // +++ 1 running, + some ready, some suspended/ready, different prios. cyg_cond_broadcast( &worker_cv ); breakme(); // Change my prio to lowest, let all the threads run, BREAKME(). // +++ 1 running + some sleeping, some suspended/ready, different prios. cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO ); breakme(); // Resume all the threads, BREAKME(); // +++ 1 running, + N ready, different prios. for( i = 1; i < THREADS; i++ ) { cyg_thread_resume( thread_handle[i] ); } breakme(); // Command some of the N threads to call BREAKME(); themselves (then sleep // again). Change my prio to low, so that they all get to run and hit the // breakpoint. // +++ A different one running every time, others in a mixture of // ready and sleeping states. worker_state = WORKER_STATE_BREAK; cyg_cond_broadcast( &worker_cv ); cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO ); breakme(); // Command all the threads to exit; switch my own priority to lower // than theirs so that they all run and exit, then I get back in and // BREAKME(); // +++ 1 thread, running, + N dormant ones. worker_state = WORKER_STATE_EXIT; cyg_cond_broadcast( &worker_cv ); breakme(); #if 0 // Cannot do this yet... // Destroy some of the N threads to invalidate their IDs. Re-create them // with new IDs, so that we get IDs 1,2,4,6,8,11,12,13,14,15 in use instead // of 1,2,3,4,5,6,7,8,9, if you see what I mean. Do all the above again. // Loop forever, or whatever... #endif breakme(); CYG_TEST_PASS_FINISH("GDB Thread test OK"); }
//=========================================================================== // WRITER THREAD //=========================================================================== void can0_thread(cyg_addrword_t data) { cyg_io_handle_t hCAN0; cyg_uint8 i; cyg_uint32 len; cyg_uint32 rx_bufsize; cyg_can_buf_info_t tx_buf_info; cyg_can_event rx_event; cyg_can_message tx_msg = { 0x000, // CAN identifier {0x00, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7}, // 8 data bytes CYGNUM_CAN_ID_STD, // standard frame CYGNUM_CAN_FRAME_DATA, // data frame 2, // data length code }; if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0)) { CYG_TEST_FAIL_FINISH("Error opening /dev/can0"); } len = sizeof(tx_buf_info); if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&tx_buf_info, &len)) { CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0"); } // // Before we can write the CAN messages, we need to know the buffer size of the // receiver. The receiver will tell us this buffer size with one single CAN // message // len = sizeof(rx_event); if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len)) { CYG_TEST_FAIL_FINISH("Error reading from /dev/can0"); } // // we expect a RX event here - we treat any other flag as an error // if (!(rx_event.flags & CYGNUM_CAN_EVENT_RX) || (rx_event.flags & !CYGNUM_CAN_EVENT_RX)) { CYG_TEST_FAIL_FINISH("Unexpected RX event for /dev/can0"); } rx_bufsize = *((cyg_uint32 *)rx_event.msg.data); // // now we send exactly one CAN message more than there is space in the receive buffer // this should cause an RX ovverun in receive buffer // diag_printf("/dev/can0: Sending %d CAN messages\n", rx_bufsize); for (i = 0; i <= rx_bufsize; ++i) { // // we store the message number as CAN id and in first data byte so // a receiver can check this later // tx_msg.id = 0x000 + i; tx_msg.data[0] = i; len = sizeof(tx_msg); if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len)) { CYG_TEST_FAIL_FINISH("Error writing to /dev/can0"); } else { print_can_msg(&tx_msg, ""); } } // for (i = 0; i <= rx_bufsize; ++i) cyg_thread_suspend(cyg_thread_self()); }
// A little test thread. void keythread(cyg_addrword_t arg){ while(1) { printf("Keycode: %d\r\n", g_keycode); cyg_thread_suspend(cyg_thread_self()); } }
void darstellung(cyg_addrword_t arg){ while(1){ ezs_watch_wcet(8000); cyg_thread_suspend(cyg_thread_self()); } }