int main(void) { RT_TASK *Main_Task; long msg; if (!(Main_Task = rt_thread_init(nam2num("MNTSK"), 10, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT MAIN TASK\n"); exit(1); } if (!(hard_timer_running = rt_is_hard_timer_running())) { start_rt_timer(0); } barrier = rt_sem_init(nam2num("PREMS"), 4); latency_thread = rt_thread_create(latency_fun, NULL, 0); fast_thread = rt_thread_create(fast_fun, NULL, 0); slow_thread = rt_thread_create(slow_fun, NULL, 0); start = rt_get_time() + nano2count(200000000); rt_sem_wait_barrier(barrier); rt_receive(0, &msg); end = 1; rt_sem_wait_barrier(barrier); rt_thread_join(latency_thread); rt_thread_join(fast_thread); rt_thread_join(slow_thread); if (!hard_timer_running) { stop_rt_timer(); } rt_sem_delete(barrier); rt_thread_delete(Main_Task); return 0; }
int main(void) { RT_TASK *mytask; int smbx, rmbx[NTASKS]; int i, bthread, mthread[NTASKS]; char msg[] = "let's end the game"; mytask = rt_thread_init(nam2num("MAIN"), 2, 0, SCHED_FIFO, 0xF); barrier = rt_sem_init(rt_get_name(0), NTASKS + 1); smbx = rt_msgget(nam2num("SMSG"), 0x666 | IPC_CREAT); for (i = 0; i < NTASKS; i++) { char mname[6] = "RMBX"; mname[4] = i + '0'; mname[5] = 0; rmbx[i] = rt_msgget(nam2num(mname), 0x666 | IPC_CREAT); } rt_set_oneshot_mode(); start_rt_timer(0); bthread = rt_thread_create(bfun, 0, 0x8000); for (i = 0; i < NTASKS; i++) { mthread[i] = rt_thread_create(mfun, (void *)i, 0x8000); } printf("IF NOTHING HAPPENS IS OK, TYPE ENTER TO FINISH.\n"); getchar(); for (i = 0; i < NTASKS; i++) { end = i; rt_msgsnd_nu(rmbx[i], 1, msg, sizeof(msg), 0); rt_thread_join(mthread[i]); } end = NTASKS; rt_msgsnd_nu(smbx, 1, msg, sizeof(msg), 0); rt_thread_join(bthread); for (i = 0; i < NTASKS; i++) { rt_msgctl(rmbx[i], IPC_RMID, NULL); printf("TASK %d, LOOPS: %d.\n", i, cnt[i]); } rt_msgctl(smbx, IPC_RMID, NULL); stop_rt_timer(); rt_sem_delete(barrier); rt_task_delete(mytask); printf("MAIN TASK ENDS.\n"); return 0; }
int main(int argc, char *argv[]) { RT_TASK *task; struct sockaddr_in addr; int i, srvport; if (!(task = rt_task_init(nam2num("TSKCOD"), 0, 0, 0))) { printf("CANNOT INIT TASK CODE\n"); exit(1); } comnode = 0; if (argc == 2 && strstr(argv[1], "ComNode=")) { inet_aton(argv[1] + 8, &addr.sin_addr); comnode = addr.sin_addr.s_addr; } if (!comnode) { inet_aton("127.0.0.1", &addr.sin_addr); comnode = addr.sin_addr.s_addr; } init_module(); for (i = 0; i < NUM_TASKS; i++) { rt_thread_join(thread[i]); } while ((srvport = rt_request_port(comnode)) <= 0) { msleep(100); } RT_sem_signal(comnode, srvport, end_sem); rt_release_port(comnode, srvport); rt_task_delete(task); exit(0); }
int main(void) { int i, indx[NTASKS]; unsigned long mytask_name = nam2num("MASTER"); signal(SIGINT, endme); if (!(mytask = rt_task_init(mytask_name, 1, 0, 0))) { printf("CANNOT INIT TASK %lu\n", mytask_name); exit(1); } printf("MASTER INIT: name = %lu, address = %p.\n", mytask_name, mytask); sem = rt_sem_init(10000, 0); rt_set_oneshot_mode(); // rt_set_periodic_mode(); start_rt_timer(0); for (i = 0; i < ntasks; i++) { indx[i] = i; if (!(task[i] = rt_thread_create(thread_fun, &indx[i], 10000))) { printf("ERROR IN CREATING THREAD %d\n", indx[i]); exit(1); } } for (i = 0; i < ntasks; i++) { while (!rt_get_adr(taskname(i))) { rt_sleep(nano2count(20000000)); } } for (i = 0; i < ntasks; i++) { rt_send(rt_get_adr(taskname(i)), (unsigned long)sem); } for (i = 0; i < ntasks; i++) { rt_sem_wait(sem); } for (i = 0; i < ntasks; i++) { while (rt_get_adr(taskname(i))) { rt_sleep(nano2count(20000000)); } } for (i = 0; i < ntasks; i++) { rt_thread_join(task[i]); } rt_sem_delete(sem); stop_rt_timer(); rt_task_delete(mytask); printf("MASTER %lu %p ENDS\n", mytask_name, mytask); return 0; }
int main (void) { M3EcSystemShm * sys; RT_TASK *task; pthread_t ptsys; int cntr=0; signal(SIGINT, endme); sys = rtai_malloc (nam2num(SHMNAM_M3MKMD),1); if (sys==-1) { printf("Error allocating shared memory\n"); return 0; } int ns=sys->slaves_active; printf("Found %d active M3 EtherCAT slaves\n",ns); if (ns==0) { printf("No slaves available. Exiting...\n"); return 0; } rt_allow_nonroot_hrt(); if (!(task = rt_task_init_schmod(nam2num("M3MAIN"), RT_TASK_PRIORITY, 0, 0, SCHED_FIFO, 0xF))) { rt_shm_free(nam2num(SHMNAM_M3MKMD)); printf("Cannot init the RTAI task %s\n","M3MAIN"); return 0; } hst=rt_thread_create((void*)rt_system_thread, sys, 10000); usleep(100000); //Let start up if (!sys_thread_active) { rt_task_delete(task); rt_shm_free(nam2num(SHMNAM_M3MKMD)); printf("Startup of thread failed.\n",0); return 0; } while(!end) { //SysEcShmPrettyPrint(sys); usleep(250000); } printf("Removing RT thread...\n",0); sys_thread_end=1; rt_thread_join(hst); if (sys_thread_active)printf("Real-time thread did not shutdown correctly\n"); rt_task_delete(task); rt_shm_free(nam2num(SHMNAM_M3MKMD)); return 0; }
int main(void) { long signal_a; long signal_b; t_info a = { .id = 'A', }; t_info b = { .id = 'B', }; finish = 0; rt_set_periodic_mode(); start_rt_timer(nano2count(TICK_TIME)); rt_make_hard_real_time(); a.delay = 0; a.period = nano2count(TICK_TIME); signal_a = rt_thread_create(&signal_func, &a, 500); if (!signal_a) { printf("Can not initialize signal A\n"); return -ENODEV; } b.delay = nano2count(DELAY_TIME); b.period = nano2count(TICK_TIME); signal_b = rt_thread_create(&signal_func, &b, 500); if (!signal_b) { printf("Can not initialize signal B\n"); return -ENODEV; } scanf("%d", &finish); finish = 1; rt_thread_join(signal_a); rt_thread_join(signal_b); pthread_exit(NULL); return 0; }
/* * Shutdown all of the worker threads and free up their resources */ void destroy_render_threads(scenedef * scene) { thr_parms * parms = (thr_parms *) scene->threadparms; rt_thread_t * threads = (rt_thread_t *) scene->threads; int thr; #if defined(MPI) && defined(THR) int row; #endif if (scene->threads != NULL) { /* wake up sleepers and tell them to exit */ rt_thread_barrier(parms[0].runbar, 0); /* wait for all sleepers to exit */ for (thr=1; thr<parms[0].nthr; thr++) rt_thread_join(threads[thr], NULL); /* destroy the thread barrier */ rt_thread_barrier_destroy(parms[0].runbar); free(scene->threads); } if (scene->threadparms != NULL) { /* deallocate thread parameter buffers * NOTE: This has to use the remembered number of threads stored in the * thread parameter area for thread 0, since the one in the scene * may have changed on us. */ for (thr=0; thr < parms[0].nthr; thr++) { if (parms[thr].local_mbox != NULL) free(parms[thr].local_mbox); } #if defined(MPI) && defined(THR) /* destroy and free row barriers for MPI builds */ for (row=0; row<parms[0].numrowbars; row++) { rt_atomic_int_destroy(&parms[0].rowbars[row]); } rt_atomic_int_destroy(parms[0].rowsdone); free(parms[0].rowbars); free(parms[0].rowsdone); #endif free(scene->threadparms); } scene->threads = NULL; scene->threadparms = NULL; }
int main(void) { rt_thread_init(nam2num("MNTSK"), 100, 0, SCHED_FIFO, 0x1); rt_printk("\nTESTING THE SCHEDULER WITH SEMs [%d LOOPs].\n", LOOPS); sem1 = rt_sem_init(nam2num("SEM1"), 0); sem2 = rt_sem_init(nam2num("SEM2"), 0); thread1 = rt_thread_create(task1, NULL, STACK_SIZE); poll(NULL, 0, 100); thread2 = rt_thread_create(task2, NULL, STACK_SIZE); rt_thread_join(thread2); end = 1; rt_sem_signal(sem1); rt_thread_join(thread1); rt_sem_delete(sem1); rt_sem_delete(sem2); rt_task_delete(NULL); rt_printk("END SCHEDULER TEST WITH SEMs.\n\n"); return 0; }
int main(void) { pthread_t thread; unsigned int player, cnt; unsigned long msg; RT_TASK *mytask; MBX *mbx; char data[BUFSIZE]; signal(SIGINT, endme); rt_allow_nonroot_hrt(); if ((player = open("../../../share/linux.au", O_RDONLY)) < 0) { printf("ERROR OPENING SOUND FILE (linux.au)\n"); exit(1); } if (!(mytask = rt_task_init(nam2num("SNDMAS"), 2, 0, 0))) { printf("CANNOT INIT MASTER TASK\n"); exit(1); } mlockall(MCL_CURRENT | MCL_FUTURE); printf("\nINIT MASTER TASK %p\n\n(CTRL-C TO END EVERYTHING)\n", mytask); mbx = rt_typed_named_mbx_init("SNDMBX", 2000, FIFO_Q); rt_set_oneshot_mode(); start_rt_timer(0); thread = rt_thread_create(intr_handler, NULL, 10000); rt_mbx_receive(mbx, &data, 1); while (!end) { lseek(player, 0, SEEK_SET); while(!end && (cnt = read(player, &data, BUFSIZE)) > 0) { rt_mbx_send(mbx, data, cnt); } } rt_rpc(rt_get_adr(nam2num("SOUND")), msg, &msg); while (rt_get_adr(nam2num("SOUND"))) { rt_sleep(nano2count(1000000)); } rt_task_delete(mytask); rt_mbx_delete(mbx); stop_rt_timer(); close(player); printf("\nEND MASTER TASK %p\n", mytask); rt_thread_join(thread); return 0; }
int main(int argc, char *argv[]) { RT_TASK *task; struct sockaddr_in addr; int i, srvport; if (!(task = rt_task_init(nam2num("STRTSK"), 0, 0, 0))) { printf("CANNOT INIT START_TASK TASK\n"); exit(1); } comnode = tasknode = 0; for (i = 0; i < argc; i++) { if (strstr(argv[i], "ComNode=")) { inet_aton(argv[i] + 8, &addr.sin_addr); comnode = addr.sin_addr.s_addr; argv[i] = 0; continue; } if (strstr(argv[i], "TaskNode=")) { inet_aton(argv[i] + 9, &addr.sin_addr); tasknode = addr.sin_addr.s_addr; argv[i] = 0; continue; } } if (!comnode) { inet_aton("127.0.0.1", &addr.sin_addr); comnode = addr.sin_addr.s_addr; } if (!tasknode) { inet_aton("127.0.0.1", &addr.sin_addr); tasknode = addr.sin_addr.s_addr; } rt_grow_and_lock_stack(100000); init_module(); rt_thread_join(thread); while ((srvport = rt_request_hard_port(comnode)) <= 0) { msleep(100); } rt_make_hard_real_time(); RT_sem_signal(comnode, srvport, end_sem); rt_make_soft_real_time(); rt_release_port(comnode, srvport); rt_task_delete(task); exit(0); }
int main(void) { RT_TASK *mytask; RT_MSGQ *smbx; int bthread; char msg[] = "let's end the game"; mytask = rt_thread_init(nam2num("MAIN"), 2, 0, SCHED_FIFO, 0xF); smbx = rt_msgq_init(nam2num("SMSG"), 0, 0); bthread = rt_thread_create(bfun, 0, 0x8000); printf("IF NOTHING HAPPENS IS OK, TYPE ENTER TO FINISH.\n"); getchar(); end = 1; rt_msg_send(smbx, msg, sizeof(msg), 1); rt_thread_join(bthread); rt_task_delete(mytask); printf("MAIN TASK ENDS.\n"); return 0; }
void TestRTAI::stop() { continueRunning = false; rt_thread_join(rtThreadID); // blocks until the real-time thread exits. rt_task_delete(normalTask); }
int main(int argc, char **argv) { #ifdef RTAI RT_TASK *task; RTIME period; #endif int i,j,aa; void *status; /* uint32_t rf_mode_max[4] = {55759,55759,55759,55759}; uint32_t rf_mode_med[4] = {39375,39375,39375,39375}; uint32_t rf_mode_byp[4] = {22991,22991,22991,22991}; */ uint32_t my_rf_mode = RXEN + TXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM + DMAMODE_RX + DMAMODE_TX; uint32_t rf_mode_base = TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM; uint32_t rf_mode[4] = {my_rf_mode,0,0,0}; uint32_t rf_local[4] = {8255000,8255000,8255000,8255000}; // UE zepto //{8254617, 8254617, 8254617, 8254617}; //eNB khalifa //{8255067,8254810,8257340,8257340}; // eNB PETRONAS uint32_t rf_vcocal[4] = {910,910,910,910}; uint32_t rf_vcocal_850[4] = {2015, 2015, 2015, 2015}; uint32_t rf_rxdc[4] = {32896,32896,32896,32896}; uint32_t rxgain[4] = {20,20,20,20}; uint32_t txgain[4] = {20,20,20,20}; uint16_t Nid_cell = 0; uint8_t cooperation_flag=0, transmission_mode=1, abstraction_flag=0; uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2; int c; char do_forms=0; unsigned int fd; unsigned int tcxo = 114; int amp; uint8_t prach_fmt; int N_ZC; char rxg_fname[100]; char txg_fname[100]; char rflo_fname[100]; char rfdc_fname[100]; FILE *rxg_fd=NULL; FILE *txg_fd=NULL; FILE *rflo_fd=NULL; FILE *rfdc_fd=NULL; unsigned int rxg_max[4]={133,133,133,133}, rxg_med[4]={127,127,127,127}, rxg_byp[4]={120,120,120,120}; int tx_max_power=0; char line[1000]; int l; int ret, ant; int ant_offset=0; int error_code; char *itti_dump_file = NULL; const struct option long_options[] = { {"calib-ue-rx", required_argument, NULL, 256}, {"calib-ue-rx-med", required_argument, NULL, 257}, {"calib-ue-rx-byp", required_argument, NULL, 258}, {"debug-ue-prach", no_argument, NULL, 259}, {"no-L2-connect", no_argument, NULL, 260}, {NULL, 0, NULL, 0}}; //mode = normal_txrx; while ((c = getopt_long (argc, argv, "C:K:O:ST:UdF:V",long_options,NULL)) != -1) { switch (c) { case 'V': ouput_vcd = 1; break; case 'd': do_forms=1; break; case 'U': UE_flag = 1; break; case 'C': carrier_freq[0] = atoi(optarg); carrier_freq[1] = atoi(optarg); carrier_freq[2] = atoi(optarg); carrier_freq[3] = atoi(optarg); break; case 'S': fs4_test=1; break; case 'T': tcxo=atoi(optarg); break; case 'K': #if defined(ENABLE_ITTI) itti_dump_file = strdup(optarg); #else printf("-K option is disabled when ENABLE_ITTI is not defined\n"); #endif break; case 'O': #if defined(ENABLE_USE_MME) EPC_MODE_ENABLED = 1; if (optarg == NULL) /* No IP address provided: use localhost */ { memcpy(&EPC_MODE_MME_ADDRESS[0], "127.0.0.1", 10); } else { uint8_t ip_length = strlen(optarg) + 1; memcpy(&EPC_MODE_MME_ADDRESS[0], optarg, ip_length > 16 ? 16 : ip_length); } #else printf("You enabled mme mode without s1ap compiled...\n"); #endif break; case 'F': sprintf(rxg_fname,"%srxg.lime",optarg); rxg_fd = fopen(rxg_fname,"r"); if (rxg_fd) { printf("Loading RX Gain parameters from %s\n",rxg_fname); l=0; while (fgets(line, sizeof(line), rxg_fd)) { if ((strlen(line)==0) || (*line == '#')) continue; //ignore empty or comment lines else { if (l==0) sscanf(line,"%d %d %d %d",&rxg_max[0],&rxg_max[1],&rxg_max[2],&rxg_max[3]); if (l==1) sscanf(line,"%d %d %d %d",&rxg_med[0],&rxg_med[1],&rxg_med[2],&rxg_med[3]); if (l==2) sscanf(line,"%d %d %d %d",&rxg_byp[0],&rxg_byp[1],&rxg_byp[2],&rxg_byp[3]); l++; } } } else printf("%s not found, running with defaults\n",rxg_fname); sprintf(txg_fname,"%stxg.lime",optarg); txg_fd = fopen(txg_fname,"r"); if (txg_fd) { printf("Loading TX Gain parameters from %s\n",txg_fname); l=0; while (fgets(line, sizeof(line), txg_fd)) { if ((strlen(line)==0) || (*line == '#')) { continue; //ignore empty or comment lines } else { if (l==0) sscanf(line,"%d %d %d %d",&txgain[0],&txgain[1],&txgain[2],&txgain[3]); if (l==1) sscanf(line,"%d",&tx_max_power); l++; } } } else printf("%s not found, running with defaults\n",txg_fname); sprintf(rflo_fname,"%srflo.lime",optarg); rflo_fd = fopen(rflo_fname,"r"); if (rflo_fd) { printf("Loading RF LO parameters from %s\n",rflo_fname); fscanf(rflo_fd,"%d %d %d %d",&rf_local[0],&rf_local[1],&rf_local[2],&rf_local[3]); } else printf("%s not found, running with defaults\n",rflo_fname); sprintf(rfdc_fname,"%srfdc.lime",optarg); rfdc_fd = fopen(rfdc_fname,"r"); if (rfdc_fd) { printf("Loading RF DC parameters from %s\n",rfdc_fname); fscanf(rfdc_fd,"%d %d %d %d",&rf_rxdc[0],&rf_rxdc[1],&rf_rxdc[2],&rf_rxdc[3]); } else printf("%s not found, running with defaults\n",rfdc_fname); break; /* case 256: mode = rx_calib_ue; rx_input_level_dBm = atoi(optarg); printf("Running with UE calibration on (LNA max), input level %d dBm\n",rx_input_level_dBm); break; case 257: mode = rx_calib_ue_med; rx_input_level_dBm = atoi(optarg); printf("Running with UE calibration on (LNA med), input level %d dBm\n",rx_input_level_dBm); break; case 258: mode = rx_calib_ue_byp; rx_input_level_dBm = atoi(optarg); printf("Running with UE calibration on (LNA byp), input level %d dBm\n",rx_input_level_dBm); break; case 259: mode = debug_prach; break; case 260: mode = no_L2_connect; break; */ default: break; } } if (UE_flag==1) printf("configuring for UE\n"); else printf("configuring for eNB\n"); //randominit (0); //set_taus_seed (0); // initialize the log (see log.h for details) logInit(); #if defined(ENABLE_ITTI) itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, itti_dump_file); # if defined(ENABLE_USE_MME) if (itti_create_task(TASK_SCTP, sctp_eNB_task, NULL) < 0) { LOG_E(EMU, "Create task failed"); LOG_D(EMU, "Initializing SCTP task interface: FAILED\n"); return -1; } if (itti_create_task(TASK_S1AP, s1ap_eNB_task, NULL) < 0) { LOG_E(EMU, "Create task failed"); LOG_D(EMU, "Initializing S1AP task interface: FAILED\n"); return -1; } # endif if (itti_create_task(TASK_L2L1, l2l1_task, NULL) < 0) { LOG_E(EMU, "Create task failed"); LOG_D(EMU, "Initializing L2L1 task interface: FAILED\n"); return -1; } // Handle signals until all tasks are terminated // itti_wait_tasks_end(); #endif if (ouput_vcd) { if (UE_flag==1) vcd_signal_dumper_init("/tmp/openair_dump_UE.vcd"); else vcd_signal_dumper_init("/tmp/openair_dump_eNB.vcd"); } #ifdef NAS_NETLINK netlink_init(); #endif // to make a graceful exit when ctrl-c is pressed signal(SIGSEGV, signal_handler); signal(SIGINT, signal_handler); #ifndef RTAI check_clock(); #endif g_log->log_component[HW].level = LOG_DEBUG; g_log->log_component[HW].flag = LOG_HIGH; #ifdef OPENAIR2 g_log->log_component[PHY].level = LOG_INFO; #else g_log->log_component[PHY].level = LOG_INFO; #endif g_log->log_component[PHY].flag = LOG_HIGH; g_log->log_component[MAC].level = LOG_INFO; g_log->log_component[MAC].flag = LOG_HIGH; g_log->log_component[RLC].level = LOG_INFO; g_log->log_component[RLC].flag = LOG_HIGH; g_log->log_component[PDCP].level = LOG_INFO; g_log->log_component[PDCP].flag = LOG_HIGH; g_log->log_component[OTG].level = LOG_INFO; g_log->log_component[OTG].flag = LOG_HIGH; g_log->log_component[RRC].level = LOG_INFO; g_log->log_component[RRC].flag = LOG_HIGH; // Initialize card ret = openair0_open(); if ( ret != 0 ) { if (ret == -1) printf("Error opening /dev/openair0"); if (ret == -2) printf("Error mapping bigshm"); if (ret == -3) printf("Error mapping RX or TX buffer"); return(ret); } printf ("Detected %d number of cards, %d number of antennas.\n", openair0_num_detected_cards, openair0_num_antennas[card]); p_exmimo_config = openair0_exmimo_pci[card].exmimo_config_ptr; p_exmimo_id = openair0_exmimo_pci[card].exmimo_id_ptr; printf("Card %d: ExpressMIMO %d, HW Rev %d, SW Rev 0x%d\n", card, p_exmimo_id->board_exmimoversion, p_exmimo_id->board_hwrev, p_exmimo_id->board_swrev); if (p_exmimo_id->board_swrev>=BOARD_SWREV_CNTL2) p_exmimo_config->framing.eNB_flag = 0; else p_exmimo_config->framing.eNB_flag = !UE_flag; p_exmimo_config->framing.tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB; for (ant=0; ant<4; ant++) p_exmimo_config->framing.resampling_factor[ant] = RESAMPLING_FACTOR; /* for (ant=0;ant<max(frame_parms->nb_antennas_tx,frame_parms->nb_antennas_rx);ant++) p_exmimo_config->rf.rf_mode[ant] = rf_mode_base; for (ant=0;ant<frame_parms->nb_antennas_tx;ant++) p_exmimo_config->rf.rf_mode[ant] += (TXEN + DMAMODE_TX); for (ant=0;ant<frame_parms->nb_antennas_rx;ant++) p_exmimo_config->rf.rf_mode[ant] += (RXEN + DMAMODE_RX); for (ant=max(frame_parms->nb_antennas_tx,frame_parms->nb_antennas_rx);ant<4;ant++) { p_exmimo_config->rf.rf_mode[ant] = 0; carrier_freq[ant] = 0; //this turns off all other LIMEs } */ ant_offset = 0; for (ant=0; ant<4; ant++) { if (ant==ant_offset) { //if (1) { p_exmimo_config->rf.rf_mode[ant] = rf_mode_base; //p_exmimo_config->rf.rf_mode[ant] += (TXEN + DMAMODE_TX); p_exmimo_config->rf.rf_mode[ant] += (RXEN + DMAMODE_RX); } else { p_exmimo_config->rf.rf_mode[ant] = 0; carrier_freq[ant] = 0; //this turns off all other LIMEs } } for (ant = 0; ant<4; ant++) { p_exmimo_config->rf.do_autocal[ant] = 1; p_exmimo_config->rf.rf_freq_rx[ant] = carrier_freq[ant]; p_exmimo_config->rf.rf_freq_tx[ant] = carrier_freq[ant]; p_exmimo_config->rf.rx_gain[ant][0] = rxgain[ant]; p_exmimo_config->rf.tx_gain[ant][0] = txgain[ant]; p_exmimo_config->rf.rf_local[ant] = rf_local[ant]; p_exmimo_config->rf.rf_rxdc[ant] = rf_rxdc[ant]; if ((carrier_freq[ant] >= 850000000) && (carrier_freq[ant] <= 865000000)) { p_exmimo_config->rf.rf_vcocal[ant] = rf_vcocal_850[ant]; p_exmimo_config->rf.rffe_band_mode[ant] = DD_TDD; } else if ((carrier_freq[ant] >= 1900000000) && (carrier_freq[ant] <= 2000000000)) { p_exmimo_config->rf.rf_vcocal[ant] = rf_vcocal[ant]; p_exmimo_config->rf.rffe_band_mode[ant] = B19G_TDD; } else { p_exmimo_config->rf.rf_vcocal[ant] = rf_vcocal[ant]; p_exmimo_config->rf.rffe_band_mode[ant] = 0; } p_exmimo_config->rf.rffe_gain_txlow[ant] = 31; p_exmimo_config->rf.rffe_gain_txhigh[ant] = 31; p_exmimo_config->rf.rffe_gain_rxfinal[ant] = 52; p_exmimo_config->rf.rffe_gain_rxlow[ant] = 31; } number_of_cards = openair0_num_detected_cards; /* if (p_exmimo_id->board_exmimoversion==1) //ExpressMIMO1 openair_daq_vars.timing_advance = 138; else //ExpressMIMO2 openair_daq_vars.timing_advance = 0; */ openair0_dump_config(card); printf("EXMIMO_CONFIG: rf_mode 0x %x %x %x %x, [0]: TXRXEn %d, TXLPFEn %d, TXLPF %d, RXLPFEn %d, RXLPF %d, RFBB %d, LNA %d, LNAGain %d, RXLPFMode %d, SWITCH %d, rf_rxdc %d, rf_local %d, rf_vcocal %d\n", p_exmimo_config->rf.rf_mode[0], p_exmimo_config->rf.rf_mode[1], p_exmimo_config->rf.rf_mode[2], p_exmimo_config->rf.rf_mode[3], (p_exmimo_config->rf.rf_mode[0]&3), // RXen+TXen (p_exmimo_config->rf.rf_mode[0]&4)>>2, //TXLPFen (p_exmimo_config->rf.rf_mode[0]&TXLPFMASK)>>3, //TXLPF (p_exmimo_config->rf.rf_mode[0]&128)>>7, //RXLPFen (p_exmimo_config->rf.rf_mode[0]&RXLPFMASK)>>8, //TXLPF (p_exmimo_config->rf.rf_mode[0]&RFBBMASK)>>16, // RFBB mode (p_exmimo_config->rf.rf_mode[0]&LNAMASK)>>12, // RFBB mode (p_exmimo_config->rf.rf_mode[0]&LNAGAINMASK)>>14, // RFBB mode (p_exmimo_config->rf.rf_mode[0]&RXLPFMODEMASK)>>19, // RXLPF mode (p_exmimo_config->framing.tdd_config&TXRXSWITCH_MASK)>>1, // Switch mode p_exmimo_config->rf.rf_rxdc[0], p_exmimo_config->rf.rf_local[0], p_exmimo_config->rf.rf_vcocal[0]); for (ant=0;ant<4;ant++) p_exmimo_config->rf.do_autocal[ant] = 0; #ifdef EMOS error_code = rtf_create(CHANSOUNDER_FIFO_MINOR,CHANSOUNDER_FIFO_SIZE); if (error_code==0) printf("[OPENAIR][SCHED][INIT] Created EMOS FIFO %d\n",CHANSOUNDER_FIFO_MINOR); else if (error_code==ENODEV) printf("[OPENAIR][SCHED][INIT] Problem: EMOS FIFO %d is greater than or equal to RTF_NO\n",CHANSOUNDER_FIFO_MINOR); else if (error_code==ENOMEM) printf("[OPENAIR][SCHED][INIT] Problem: cannot allocate memory for EMOS FIFO %d\n",CHANSOUNDER_FIFO_MINOR); else printf("[OPENAIR][SCHED][INIT] Problem creating EMOS FIFO %d, error_code %d\n",CHANSOUNDER_FIFO_MINOR,error_code); #endif mlockall(MCL_CURRENT | MCL_FUTURE); #ifdef RTAI // make main thread LXRT soft realtime task = rt_task_init_schmod(nam2num("MYTASK"), 9, 0, 0, SCHED_FIFO, 0xF); // start realtime timer and scheduler #ifdef TIMER_ONESHOT_MODE rt_set_oneshot_mode(); start_rt_timer(0); printf("started RTAI timer inoneshot mode\n"); #else rt_set_periodic_mode(); period = start_rt_timer(nano2count(500000)); printf("started RTAI timer with period %llu ns\n",count2nano(period)); #endif printf("Init mutex\n"); //mutex = rt_get_adr(nam2num("MUTEX")); mutex = rt_sem_init(nam2num("MUTEX"), 1); if (mutex==0) { printf("Error init mutex\n"); exit(-1); } else printf("mutex=%p\n",mutex); #endif DAQ_MBOX = (volatile unsigned int *) openair0_exmimo_pci[card].rxcnt_ptr[0]; // this starts the DMA transfers if (UE_flag!=1) openair0_start_rt_acquisition(card); #ifdef XFORMS if (do_forms==1) { fl_initialize (&argc, argv, NULL, 0, 0); form_stats = create_form_stats_form(); if (UE_flag==1) { form_ue[UE_id] = create_lte_phy_scope_ue(); sprintf (title, "LTE DL SCOPE UE"); fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); } else { for(UE_id=0;UE_id<scope_enb_num_ue;UE_id++) { form_enb[UE_id] = create_lte_phy_scope_enb(); sprintf (title, "UE%d LTE UL SCOPE eNB",UE_id+1); fl_show_form (form_enb[UE_id]->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); } } fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats"); if (UE_flag==0) { for (UE_id=0;UE_id<scope_enb_num_ue;UE_id++) { if (otg_enabled) { fl_set_button(form_enb[UE_id]->button_0,1); fl_set_object_label(form_enb[UE_id]->button_0,"DL Traffic ON"); } else { fl_set_button(form_enb[UE_id]->button_0,0); fl_set_object_label(form_enb[UE_id]->button_0,"DL Traffic OFF"); } } } else { if (openair_daq_vars.use_ia_receiver) { fl_set_button(form_ue[UE_id]->button_0,1); fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON"); } else { fl_set_button(form_ue[UE_id]->button_0,0); fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); } } ret = pthread_create(&thread2, NULL, scope_thread, NULL); printf("Scope thread created, ret=%d\n",ret); } #endif #ifdef EMOS ret = pthread_create(&thread3, NULL, emos_thread, NULL); printf("EMOS thread created, ret=%d\n",ret); #endif rt_sleep_ns(10*FRAME_PERIOD); #ifndef RTAI pthread_attr_init (&attr_dlsch_threads); pthread_attr_setstacksize(&attr_dlsch_threads,OPENAIR_THREAD_STACK_SIZE); //attr_dlsch_threads.priority = 1; sched_param_dlsch.sched_priority = sched_get_priority_max(SCHED_FIFO); //OPENAIR_THREAD_PRIORITY; pthread_attr_setschedparam (&attr_dlsch_threads, &sched_param_dlsch); pthread_attr_setschedpolicy (&attr_dlsch_threads, SCHED_FIFO); #endif // start the main thread if (UE_flag == 1) { /* #ifdef RTAI thread1 = rt_thread_create(UE_thread, NULL, 100000000); #else error_code = pthread_create(&thread1, &attr_dlsch_threads, UE_thread, NULL); if (error_code!= 0) { LOG_D(HW,"[lte-softmodem.c] Could not allocate UE_thread, error %d\n",error_code); return(error_code); } else { LOG_D(HW,"[lte-softmodem.c] Allocate UE_thread successful\n"); } #endif #ifdef DLSCH_THREAD init_rx_pdsch_thread(); rt_sleep_ns(FRAME_PERIOD/10); init_dlsch_threads(); #endif printf("UE threads created\n"); */ } else { #ifdef RTAI thread0 = rt_thread_create(eNB_thread, NULL, 100000000); #else error_code = pthread_create(&thread0, &attr_dlsch_threads, eNB_thread, NULL); if (error_code!= 0) { LOG_D(HW,"[lte-softmodem.c] Could not allocate eNB_thread, error %d\n",error_code); return(error_code); } else { LOG_D(HW,"[lte-softmodem.c] Allocate eNB_thread successful\n"); } #endif #ifdef ULSCH_THREAD init_ulsch_threads(); #endif printf("eNB threads created\n"); } // wait for end of program printf("TYPE <CTRL-C> TO TERMINATE\n"); //getchar(); while (oai_exit==0) rt_sleep_ns(FRAME_PERIOD); // stop threads #ifdef XFORMS printf("waiting for XFORMS thread\n"); if (do_forms==1) { pthread_join(thread2,&status); fl_hide_form(form_stats->stats_form); fl_free_form(form_stats->stats_form); if (UE_flag==1) { fl_hide_form(form_ue[UE_id]->lte_phy_scope_ue); fl_free_form(form_ue[UE_id]->lte_phy_scope_ue); } else { for(UE_id=0;UE_id<scope_enb_num_ue;UE_id++) { fl_hide_form(form_enb[UE_id]->lte_phy_scope_enb); fl_free_form(form_enb[UE_id]->lte_phy_scope_enb); } } } #endif printf("stopping MODEM threads\n"); // cleanup if (UE_flag == 1) { /* #ifdef RTAI rt_thread_join(thread1); #else pthread_join(thread1,&status); #endif #ifdef DLSCH_THREAD cleanup_dlsch_threads(); cleanup_rx_pdsch_thread(); #endif */ } else { #ifdef RTAI rt_thread_join(thread0); #else pthread_join(thread0,&status); #endif #ifdef ULSCH_THREAD cleanup_ulsch_threads(); #endif } #ifdef OPENAIR2 //cleanup_pdcp_thread(); #endif #ifdef RTAI stop_rt_timer(); #endif printf("stopping card\n"); openair0_stop(card); printf("closing openair0_lib\n"); openair0_close(); #ifdef EMOS printf("waiting for EMOS thread\n"); pthread_cancel(thread3); pthread_join(thread3,&status); #endif #ifdef EMOS error_code = rtf_destroy(CHANSOUNDER_FIFO_MINOR); printf("[OPENAIR][SCHED][CLEANUP] EMOS FIFO closed, error_code %d\n", error_code); #endif if (ouput_vcd) vcd_signal_dumper_close(); logClean(); return 0; }
int calc_grid_energies_excl_mgrid(float* atoms, float* grideners, long int numplane, long int numcol, long int numpt, long int natoms, float gridspacing, unsigned char* excludepos, int maxnumprocs) { // cionize_params* params, cionize_molecule* molecule, cionize_grid* grid) { int i; enthrparms *parms; rt_thread_t * threads; #if defined(THR) int numprocs; int availprocs = rt_thread_numprocessors(); if (params->maxnumprocs <= availprocs) { numprocs = params->maxnumprocs; } else { numprocs = availprocs; } #else int numprocs = 1; #endif printf("calc_grid_energies_excl_mgrid()\n"); /* DH: setup and compute long-range */ MgridParam mg_prm; MgridSystem mg_sys; Mgrid mg; //MgridLattice *lattice; int j, k; int gridfactor; double h, h_1; int nspacings; double *eh; int ndim; int ii, jj, kk; int im, jm, km; int ilo, jlo, klo; double dx_h, dy_h, dz_h; double xphi[4], yphi[4], zphi[4]; double t, en, c; int koff, jkoff, index; rt_timerhandle timer; float totaltime; memset(&mg_prm, 0, sizeof(mg_prm)); memset(&mg_sys, 0, sizeof(mg_sys)); /* * set mgrid parameters * * make sure origin of mgrid's grid is at ionize's grid origin (0,0,0) * * length is (number of grid spacings) * (grid spacing), * where the number of spacings is one less than number of grid points */ mg_prm.length = (numpt-1) * gridspacing; mg_prm.center.x = 0.5 * mg_prm.length; mg_prm.center.y = 0.5 * mg_prm.length; mg_prm.center.z = 0.5 * mg_prm.length; /* make sure domain and grid are both cubic */ if (numpt != numcol || numcol != numplane) { printf("ERROR: grid must be cubic\n"); return -1; } /* * grid used by mgrid needs spacing h >= 2 * * determine grid factor: (2^gridfactor)*h_ionize = h_mgrid */ gridfactor = 0; //nspacings = numpt - 1; nspacings = numpt; /* add one more spacing so that interpolation loop below will work */ h = gridspacing; while (h < 2.0) { h *= 2; nspacings = ((nspacings & 1) ? nspacings/2 + 1 : nspacings/2); gridfactor++; } mg_prm.nspacings = nspacings; /* have to modify mgrid length */ mg_prm.length += h; mg_prm.center.x = 0.5 * mg_prm.length; mg_prm.center.y = 0.5 * mg_prm.length; mg_prm.center.z = 0.5 * mg_prm.length; h_1 = 1.0/h; mg_prm.cutoff = CUTOFF; mg_prm.boundary = MGRID_NONPERIODIC; /* choice of splitting must be consistent with short-range below */ #if defined(CUBIC_TAYLOR2) mg_prm.approx = MGRID_CUBIC; mg_prm.split = MGRID_TAYLOR2; #elif defined(QUINTIC1_TAYLOR3) mg_prm.approx = MGRID_QUINTIC1; mg_prm.split = MGRID_TAYLOR3; #elif defined(HEPTIC1_TAYLOR4) mg_prm.approx = MGRID_HEPTIC1; mg_prm.split = MGRID_TAYLOR4; /* #elif defined(HERMITE_TAYLOR3) mg_prm.approx = MGRID_HERMITE; mg_prm.split = MGRID_TAYLOR3; */ #endif mg_prm.natoms = natoms; printf("natom = %d\n", mg_prm.natoms); printf("mgrid center = %g %g %g\n", mg_prm.center.x, mg_prm.center.y, mg_prm.center.z); printf("mgrid length = %g\n", mg_prm.length); printf("mgrid nspacings = %d\n", mg_prm.nspacings); /* setup mgrid system */ mg_sys.f_elec = (MD_Dvec *) calloc(mg_prm.natoms, sizeof(MD_Dvec)); mg_sys.pos = (MD_Dvec *) calloc(mg_prm.natoms, sizeof(MD_Dvec)); mg_sys.charge = (double *) calloc(mg_prm.natoms, sizeof(double)); for (i = 0; i < mg_prm.natoms; i++) { mg_sys.pos[i].x = atoms[4*i ]; mg_sys.pos[i].y = atoms[4*i + 1]; mg_sys.pos[i].z = atoms[4*i + 2]; mg_sys.charge[i] = atoms[4*i + 3]; } /* setup mgrid solver and compute */ if (mgrid_param_config(&mg_prm)) { printf("ERROR: mgrid_param_config() failed\n"); return -1; } printf("spacing = %g\n", mg_prm.spacing); if (mgrid_init(&mg)) { printf("ERROR: mgrid_init() failed\n"); return -1; } if (mgrid_setup(&mg, &mg_sys, &mg_prm)) { printf("ERROR: mgrid_setup() failed\n"); return -1; } timer = rt_timer_create(); rt_timer_start(timer); if (mgrid_force(&mg, &mg_sys)) { printf("ERROR: mgrid_force() failed\n"); return -1; } /* DH: end setup and compute long-range */ printf(" using %d processors\n", numprocs); /* allocate array of threads */ threads = (rt_thread_t *) calloc(numprocs * sizeof(rt_thread_t), 1); /* allocate and initialize array of thread parameters */ parms = (enthrparms *) malloc(numprocs * sizeof(enthrparms)); for (i=0; i<numprocs; i++) { parms[i].threadid = i; parms[i].threadcount = numprocs; parms[i].atoms = atoms; parms[i].grideners = grideners; parms[i].numplane = numplane; parms[i].numcol = numcol; parms[i].numpt = numpt; parms[i].natoms = natoms; parms[i].gridspacing = gridspacing; parms[i].excludepos = excludepos; } #if defined(THR) /* spawn child threads to do the work */ for (i=0; i<numprocs; i++) { rt_thread_create(&threads[i], energythread, &parms[i]); } /* join the threads after work is done */ for (i=0; i<numprocs; i++) { rt_thread_join(threads[i], NULL); } #else /* single thread does all of the work */ energythread((void *) &parms[0]); #endif /* DH: tabulate and cleanup long-range */ /* interpolate from mgrid potential lattice */ eh = (double *)(mg.egrid[0].data); /* mgrid's long-range potential lattice */ ndim = mg.egrid[0].ni; /* number of points in each dimension of lattice */ for (kk = 0; kk < numplane; kk++) { for (jj = 0; jj < numcol; jj++) { for (ii = 0; ii < numpt; ii++) { /* distance between atom and corner measured in grid points */ dx_h = (ii*gridspacing) * h_1; dy_h = (jj*gridspacing) * h_1; dz_h = (kk*gridspacing) * h_1; /* find closest mgrid lattice point less than or equal to */ im = ii >> gridfactor; jm = jj >> gridfactor; km = kk >> gridfactor; #if defined(CUBIC_TAYLOR2) ilo = im-1; jlo = jm-1; klo = km-1; /* find t for x dimension and compute xphi */ t = dx_h - ilo; xphi[0] = 0.5 * (1 - t) * (2 - t) * (2 - t); t--; xphi[1] = (1 - t) * (1 + t - 1.5 * t * t); t--; xphi[2] = (1 + t) * (1 - t - 1.5 * t * t); t--; xphi[3] = 0.5 * (1 + t) * (2 + t) * (2 + t); /* find t for y dimension and compute yphi */ t = dy_h - jlo; yphi[0] = 0.5 * (1 - t) * (2 - t) * (2 - t); t--; yphi[1] = (1 - t) * (1 + t - 1.5 * t * t); t--; yphi[2] = (1 + t) * (1 - t - 1.5 * t * t); t--; yphi[3] = 0.5 * (1 + t) * (2 + t) * (2 + t); /* find t for z dimension and compute zphi */ t = dz_h - klo; zphi[0] = 0.5 * (1 - t) * (2 - t) * (2 - t); t--; zphi[1] = (1 - t) * (1 + t - 1.5 * t * t); t--; zphi[2] = (1 + t) * (1 - t - 1.5 * t * t); t--; zphi[3] = 0.5 * (1 + t) * (2 + t) * (2 + t); /* determine 64=4*4*4 eh grid stencil contribution to potential */ en = 0; for (k = 0; k < 4; k++) { koff = (k + klo) * ndim; for (j = 0; j < 4; j++) { jkoff = (koff + (j + jlo)) * ndim; c = yphi[j] * zphi[k]; for (i = 0; i < 4; i++) { index = jkoff + (i + ilo); /* ASSERT(&eh[index] == mgrid_lattice_elem(&(mg.egrid[0]), i+ilo, j+jlo, k+klo)); */ if (&eh[index] != mgrid_lattice_elem(&(mg.egrid[0]), i+ilo, j+jlo, k+klo)) { printf("ndim=%d index=%d i+ilo=%d j+jlo=%d k+klo=%d\n" "ia=%d ib=%d ni=%d\n" "ja=%d jb=%d nj=%d\n" "ka=%d kb=%d nk=%d\n", ndim, index, i+ilo, j+jlo, k+klo, mg.egrid[0].ia, mg.egrid[0].ib, mg.egrid[0].ni, mg.egrid[0].ja, mg.egrid[0].jb, mg.egrid[0].nj, mg.egrid[0].ka, mg.egrid[0].kb, mg.egrid[0].nk ); abort(); } en += eh[index] * xphi[i] * c; } } } /* end CUBIC */ #endif //ENERGY(grid->eners[k*numcol*numpt + j*numpt + i]); grideners[kk*numcol*numpt + jj*numpt + ii] += (float)en; // (float) *((double *)mgrid_lattice_elem(lattice, i, j, k)); //ENERGY((float) *((double *)mgrid_lattice_elem(lattice, i, j, k))); //ENERGY(grid->eners[k*numcol*numpt + j*numpt + i]*560.47254); } } } totaltime = rt_timer_timenow(timer); printf("total time for mgrid: %.1f\n", totaltime); rt_timer_destroy(timer); /* cleanup mgrid */ mgrid_done(&mg); free(mg_sys.f_elec); free(mg_sys.pos); free(mg_sys.charge); /* DH: tabulate and cleanup long-range */ /* free thread parms */ free(parms); free(threads); return 0; }
int main(int argc, char *argv[]) { unsigned long sndnode; long sndport, i, r; RT_TASK *rcvtsk, *sndtsk; struct sockaddr_in addr; static MBX *sndmbx; SERVER = atoi(argv[1]); if (!(rcvtsk = rt_task_init_schmod(nam2num("RCVTSK"), 2, 0, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT RECEIVER TASK\n"); exit(1); } mbx = rt_mbx_init(nam2num("MBX"), 100); athread = rt_thread_create(async_fun, NULL, 10000); sndnode = 0; if (argc == 3 && strstr(argv[2], "SndNode=")) { inet_aton(argv[2] + 8, &addr.sin_addr); sndnode = addr.sin_addr.s_addr; } if (!sndnode) { inet_aton("127.0.0.1", &addr.sin_addr); sndnode = addr.sin_addr.s_addr; } rt_set_oneshot_mode(); start_rt_timer(0); while ((sndport = rt_request_port_mbx(sndnode, mbx)) <= 0 && sndport != -EINVAL); while (!(sndmbx = RT_get_adr(sndnode, sndport, "SNDMBX"))) { rt_sleep(nano2count(100000000)); } sndtsk = RT_get_adr(sndnode, sndport, "SNDTSK"); printf("\nRECEIVER TASK RUNNING\n"); mlockall(MCL_CURRENT | MCL_FUTURE); rt_make_hard_real_time(); while (!end) { r = RT_mbx_receive(sndnode, -sndport, sndmbx, &i, sizeof(long)); rt_printk("RECEIVE %ld %ld\n", r, i); if (SERVER) { rt_sleep(nano2count(100000000)); } else { while (!end && rt_waiting_return(sndnode, sndport)) { rt_sleep(nano2count(1000000)); } if (!end) { unsigned long long retval; long i1, i2; int l1, l2; if (rt_sync_net_rpc(sndnode, -sndport)) { l1 = l2 = sizeof(long); rt_get_net_rpc_ret(mbx, &retval, &i1, &l1, &i2, &l2, 0LL, MBX_RECEIVE); rt_printk("RECEIVER ASYNC MSG: RETVAL = %d, MSG = %ld, LEN = %d.\n", (int)retval, i1, l1); if (i1 < 0) { end = 1; break; } } } } } rt_mbx_delete(mbx); rt_release_port(sndnode, sndport); rt_make_soft_real_time(); rt_thread_join(athread); rt_return(rt_receive(0, &i), i); rt_task_delete(rcvtsk); stop_rt_timer(); printf("\nRECEIVER TASK STOPS\n"); return 0; }
int main(int argc, char* argv[]) { extern int init_cmdclk(void); extern int init_cmdcrn(void); extern int init_dispclk(void); extern int cleanup_cmdclk(void); extern int cleanup_cmdcrn(void); extern int cleanup_dispclk(void); RT_TASK *mytask; hide = FALSE; Pause = FALSE; sem_init(&sync_sem, 0, 0); rt_set_oneshot_mode(); init_cmdclk(); init_cmdcrn(); init_dispclk(); if (!(mytask = rt_task_init(nam2num("MASTER"), 1, 0, 0))) { printf("CANNOT INIT MASTER TASK\n"); exit(1); } printf("\nINIT MASTER TASK %p.\n", mytask); OneUnit = nano2count(ONE_UNIT); start_rt_timer(0); if (!(Read = rt_thread_create(ClockChrono_Read, NULL, 10000))) { printf("ERROR IN CREATING ClockChrono_Read\n"); exit(1); } if (!(Chrono = rt_thread_create(ClockChrono_Chrono, NULL, 10000))) { printf("ERROR IN CREATING ClockChrono_Chrono\n"); exit(1); } if (!(Clock = rt_thread_create(ClockChrono_Clock, NULL, 10000))) { printf("ERROR IN CREATING ClockChrono_Clock\n"); exit(1); } if (!(Write = rt_thread_create(ClockChrono_Write, NULL, 10000))) { printf("ERROR IN CREATING ClockChrono_Write\n"); exit(1); } rt_task_suspend(mytask); while (rt_get_adr(nam2num("READ"))) { rt_sleep(nano2count(1000000)); } while (rt_get_adr(nam2num("CLOCK"))) { rt_sleep(nano2count(1000000)); } while (rt_get_adr(nam2num("CHRONO"))) { rt_sleep(nano2count(1000000)); } while (rt_get_adr(nam2num("WRITE"))) { rt_sleep(nano2count(1000000)); } cleanup_cmdclk(); cleanup_cmdcrn(); cleanup_dispclk(); rt_thread_join(Chrono); rt_thread_join(Clock); rt_thread_join(Read); rt_thread_join(Write); sem_destroy(&sync_sem); rt_task_delete(mytask); printf("\nEND MASTER TASK %p.\n", mytask); return 0; }
void TestRTAI::runTest(double period) { std::cout << "TestRTAI::runTest: Method called!" << std::endl; // Compute the period of the real-time servo loop. rtPeriod_ns = period * 1e9; long long const rtPeriod_us(rtPeriod_ns / 1000); // Allow non-root user to use Linux POSIX soft real-time process management and // memory lock functions. // See: https://www.rtai.org/userfiles/documentation/magma/html/api/group__lxrt.html#ga74 rt_allow_nonroot_hrt(); // Change scheduler of this thread to be RTAI std::cout << "TestRTAI::runTest: Switching to RTAI scheduler..." << std::endl; normalTask = rt_task_init_schmod( nam2num("MY_TASK"), // name NON_REALTIME_PRIORITY, // priority 0, // stack_size 0, // max_msg_size SCHED_FIFO, // scheduling policy 0xF // CPUs allowed ); if (!normalTask) throw std::runtime_error("rt_task_init_schmod failed for non-RT task"); rtThreadState = RT_THREAD_UNDEF; // Spawn the real-time thread. The real-time thread executes call_rtMethod(). std::cout << "TestRTAI::runTest: Spawning RT thread..." << std::endl; rtThreadID = rt_thread_create( (void*)call_rtMethod, // method to call this, // parameters 50000 // stack size ); // Wait up to MAX_START_LATENCY_CYCLES for real-time thread to begin running std::cout << "TestRTAI::runTest: Waiting for RT thread to run..." << std::endl; for (int ii = 0; ii < MAX_START_LATENCY_CYCLES; ii++) { if (rtThreadState == RT_THREAD_RUNNING || rtThreadState == RT_THREAD_ERROR) break; usleep(rtPeriod_us); } if (rtThreadState != RT_THREAD_RUNNING) { std::stringstream ss; ss << "TestRTAI::runTest: ERROR: Real-time thread not running, state is: "; switch (rtThreadState) { case RT_THREAD_UNDEF: ss << "RT_THREAD_UNDEF"; break; case RT_THREAD_INIT: ss << "RT_THREAD_INIT"; break; case RT_THREAD_RUNNING: ss << "RT_THREAD_RUNNING"; break; case RT_THREAD_CLEANUP: ss << "RT_THREAD_CLEANUP"; break; case RT_THREAD_ERROR: ss << "RT_THREAD_ERROR"; break; case RT_THREAD_DONE: ss << "RT_THREAD_DONE"; break; default: ss << "Invalid state: " << rtThreadState; } std::cout << ss.str() << std::endl; usleep(15 * rtPeriod_us); rt_task_delete(normalTask); rt_thread_join(rtThreadID); // blocks until the real-time thread exits. throw std::runtime_error("TestRTAI::runTest: RT thread failed to start"); } std::cout << "TestRTAI::runTest: OK - real-time thread started." << std::endl; }
int main(void) { RTIME tsr, tss, tsm, trpc; RT_TASK *mainbuddy; int i, k, s; unsigned long msg; printf("\n\nWait for it ...\n"); if (!(mainbuddy = rt_thread_init(nam2num("MASTER"), 1000, 0, SCHED_FIFO, 0x1))) { printf("CANNOT INIT TASK %lu\n", nam2num("MASTER")); exit(1); } sem = rt_sem_init(nam2num("SEMAPH"), 1); change = 0; for (i = 0; i < NR_RT_TASKS; i++) { indx[i] = i; if (!(thread[i] = rt_thread_create(thread_fun, indx + i, 0))) { printf("ERROR IN CREATING THREAD %d\n", indx[i]); exit(1); } } do { msleep(50); s = 0; for (i = 0; i < NR_RT_TASKS; i++) { s += hrt[i]; } } while (s != NR_RT_TASKS); mlockall(MCL_CURRENT | MCL_FUTURE); rt_make_hard_real_time(); tsr = rt_get_cpu_time_ns(); for (i = 0; i < LOOPS; i++) { for (k = 0; k < NR_RT_TASKS; k++) { rt_task_resume(mytask[k]); } } tsr = rt_get_cpu_time_ns() - tsr; change = 1; for (k = 0; k < NR_RT_TASKS; k++) { rt_task_resume(mytask[k]); } tss = rt_get_cpu_time_ns(); for (i = 0; i < LOOPS; i++) { for (k = 0; k < NR_RT_TASKS; k++) { rt_sem_signal(sem); } } tss = rt_get_cpu_time_ns() - tss; change = 2; for (k = 0; k < NR_RT_TASKS; k++) { rt_sem_signal(sem); } tsm = rt_get_cpu_time_ns(); for (i = 0; i < LOOPS; i++) { for (k = 0; k < NR_RT_TASKS; k++) { rt_send(mytask[k], 0); } } tsm = rt_get_cpu_time_ns() - tsm; change = 3; for (k = 0; k < NR_RT_TASKS; k++) { rt_send(mytask[k], 0); } trpc = rt_get_cpu_time_ns(); for (i = 0; i < LOOPS; i++) { for (k = 0; k < NR_RT_TASKS; k++) { rt_rpc(mytask[k], 0, &msg); } } trpc = rt_get_cpu_time_ns() - trpc; rt_make_soft_real_time(); printf("\n\nFOR %d TASKS: ", NR_RT_TASKS); printf("TIME %d (ms), SUSP/RES SWITCHES %d, ", (int)(tsr/1000000), 2*NR_RT_TASKS*LOOPS); printf("SWITCH TIME %d (ns)\n", (int)(tsr/(2*NR_RT_TASKS*LOOPS))); printf("\nFOR %d TASKS: ", NR_RT_TASKS); printf("TIME %d (ms), SEM SIG/WAIT SWITCHES %d, ", (int)(tss/1000000), 2*NR_RT_TASKS*LOOPS); printf("SWITCH TIME %d (ns)\n", (int)(tss/(2*NR_RT_TASKS*LOOPS))); printf("\nFOR %d TASKS: ", NR_RT_TASKS); printf("TIME %d (ms), SEND/RCV SWITCHES %d, ", (int)(tsm/1000000), 2*NR_RT_TASKS*LOOPS); printf("SWITCH TIME %d (ns)\n", (int)(tsm/(2*NR_RT_TASKS*LOOPS))); printf("\nFOR %d TASKS: ", NR_RT_TASKS); printf("TIME %d (ms), RPC/RCV-RET SWITCHES %d, ", (int)(tsm/1000000), 2*NR_RT_TASKS*LOOPS); printf("SWITCH TIME %d (ns)\n\n", (int)(trpc/(2*NR_RT_TASKS*LOOPS))); fflush(stdout); end = 1; for (i = 0; i < NR_RT_TASKS; i++) { rt_rpc(mytask[i], 0, &msg); } do { msleep(50); s = 0; for (i = 0; i < NR_RT_TASKS; i++) { s += hrt[i]; } } while (s); rt_sem_delete(sem); rt_task_delete(mainbuddy); for (i = 0; i < NR_RT_TASKS; i++) { rt_thread_join(thread[i]); } return 0; }