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

📄 ogrt_proc.c

📁 The OpenGPSRec receiver software runs on the real time operating system RTAI-Linux. It compiles with
💻 C
📖 第 1 页 / 共 2 页
字号:
          break;        case track_riseset:          ch_track_riseset( ch, accum_missed);          break;        case follow_riseset:          ch_follow_riseset_DUMP( ch);          break;        case off:          break;        default:          rt_printk( KERN_INFO "ogr: unkown state Chan[%d].state = %d\n", ch, Chan[ch].state);          break;      }    }   // --- if ( accum_new & test[ch]) ---  } // --- for ( ch=0; ch<NOFCHN; ch++) ---  return;}/* *********************************************************************FUNCTION  polling_GP2021()RETURNS  None.PARAMETERS None.PURPOSE  Called every TICK_PERIOD Nanoseconds, read correlator registers  if TIC / DUMP event occurred.WRITTEN BY  Clifford Kelley********************************************************************* */static void polling_GP2021( void){  INT16 accum_new, accum_missed;  static INT16 nav_count = 0;    // set nav_flag every NNN msec// latch the ACCUM_STATUS_x registers  to_gps( STATUS, 0x0);// did we miss a dump? what channels have data ready?  accum_missed = from_gps( ACCUM_STATUS_B);  accum_new    = from_gps( ACCUM_STATUS_A);  RT_Ctrl->accum_new    = accum_new;  RT_Ctrl->accum_missed = accum_missed;/* * DUMP event? *///  if ( accum_new & 0xfff || accum_missed & 0x2000)  if ( accum_new & 0xfff)  {    handle_DUMP_event( accum_new, accum_missed);    call_ch_funs( accum_new, accum_missed);  }/* * now that the urgent stuff (DUMP event, every 1 msec) has been * treated, we have time for the less pressing stuff (TIC every 0.1) */  if ( accum_missed & 0x2000)  {/* * a TIC event has occurred: update timer, overflow after one week */    RT_Ctrl->tow_tic_count = (RT_Ctrl->tow_tic_count + 1) % 6048000;/* * read out phase of carrier and code NCOs */    handle_TIC_event( accum_new, accum_missed);/* * if in monosat/riseset mode re-sync carrier/code loops of  * slave channels every TIC event */// *** FIXME: what do we do in riseset mode?!? ***    if ( RT_Ctrl->leadch >= 0)      ch_follow_monosat_TIC( RT_Ctrl->leadch);// 1 second has passed    if ( (RT_Ctrl->tow_tic_count % 10) == 0)      RT_Ctrl->sec_flag = 1;// 1 minute has passed    if ( (RT_Ctrl->tow_tic_count % 600) == 0)      RT_Ctrl->min_flag = 1;/* *  check if transition to other modes */    switch( RT_Ctrl->trans)    {    case trans2navigate:      init_navigate();      RT_Ctrl->trans = none;      break;    case trans2monosat:    case trans2riseset:      init_monosatriseset( RT_Ctrl->trans);      RT_Ctrl->trans = none;      break;    default:      break;      }// user pressed '+' / '-' to shift slave code delays?    if ( RT_Ctrl->monosat_slew)      slew_slave_code_delay();    nav_count = (nav_count + 1) % nav_tic;    if ( nav_count == 0)      writefifo_navdata();/* *  finally: write some informational data to  *  ring buffer to be read by gpsplot */    fill_channelinfo_ringbuffer();  }  // --- if ( accum_missed & 0x2000) ---  return;}/* ------------------------------------------------------------------------- *FUNCTION void copy_from_controlstrct( void)RETURNS  nonePARAMETERS  nonePURPOSE  copy fields from struct 'RT_Ctrl' to local variables* ------------------------------------------------------------------------- */void copy_from_controlstrct( void){//  INT16 i;//  thetime          = RT_Ctrl->thetime;//  rms              = RT_Ctrl->rms;  search_min_f             = RT_Ctrl->search_min_f;  search_max_f             = RT_Ctrl->search_max_f;  confirm_above_thresh_max = RT_Ctrl->confirm_above_thresh_max;  if ( !confirm_above_thresh_max)    confirm_above_thresh_max = CONFIRM_ABOVE_THRESH_MAX;  confirm_count_max        = RT_Ctrl->confirm_count_max;  if ( !confirm_count_max)    confirm_count_max      = CONFIRM_COUNT_MAX;  pull_in_count_max        = RT_Ctrl->pull_in_count_max;  if ( !pull_in_count_max)    pull_in_count_max = PULL_IN_COUNT_MAX;  align_count_max          = RT_Ctrl->align_count_max;  if ( !align_count_max)    align_count_max = ALIGN_COUNT_MAX;//  phase_test              = RT_Ctrl->phase_test;  nav_tic                  = RT_Ctrl->nav_tic;  frq_step                 = RT_Ctrl->frq_step;  acq_thresh               = RT_Ctrl->acq_thresh;  code_corr                = RT_Ctrl->code_corr;  pul_cod_c1               = RT_Ctrl->pul_cod_c1;  pul_cod_c3               = RT_Ctrl->pul_cod_c3;  pul_car_c1               = RT_Ctrl->pul_car_c1;  pul_car_c3               = RT_Ctrl->pul_car_c3;  trk_cod_c1               = RT_Ctrl->trk_cod_c1;  trk_cod_c3               = RT_Ctrl->trk_cod_c3;  trk_car_c1               = RT_Ctrl->trk_car_c1;  trk_car_c3               = RT_Ctrl->trk_car_c3;  return;}/* ------------------------------------------------------------------------- *FUNCTION void ogr_routine( int arg)RETURNS  nonePARAMETERS  nonePURPOSE  main routine in real-time process  waits for user process intialization and then  polls GP2021 correlator at predefined intervals* ------------------------------------------------------------------------- */void ogr_routine( int arg){  static INT16 Watch_Cnt = 0;/* *  we wait until the tracking parameters are  *  initalized from user space */  while ( RT_Ctrl->magic != MAGIC_NUMBER)     rt_task_wait_period();//  copy from RT_Ctrl structure to global variables  copy_from_controlstrct();//  initialize navigation mode (default)  init_navigate();  rt_printk( KERN_INFO "ogr: start polling loop ...\n");  while ( RT_Ctrl->rt_polling)   {    rt_task_wait_period();    polling_GP2021();//  call watchdog() every second    Watch_Cnt += 1;    if ( Watch_Cnt > 1000)    {      Watch_Cnt = 0;      watchdog();      RT_Ctrl->user_watch_flag += 1;//  stop if user prg not running for 10 sec      if ( RT_Ctrl->user_watch_flag > WATCHDOG_USER_MAX)      {        rt_printk( KERN_INFO "ogr: user_watch_flag overflowed! (%d)\n",          RT_Ctrl->user_watch_flag);        RT_Ctrl->rt_polling = 0;      }    }  }  rt_printk( KERN_INFO "ogr: left 'while' loop in function ogr_routine().\n");  return;}/* ------------------------------------------------------------------------- *FUNCTION int init_module( void)RETURNS  nonePARAMETERS  nonePURPOSE  initialize RT module, called at /sbin/insmod ogr_rtproc.o* ------------------------------------------------------------------------- */int init_module( void){  int ret;  RTIME tick_period, start;// register our GPS board with Linux  if ( !(ret = registerGPS()))   {    return( ret);  }  switch_off_proto3_LED();//  can we talk to GP2021?  if ( self_test())  {    rt_printk( KERN_INFO "ogr: self_test() failed!\n");    return (-1);  }  rt_printk( KERN_INFO "ogr: self_test() succeeded!\n");/* * allocate shared memory areas */  Chan = (CHANNEL*) rtai_kmalloc( nam2num( SHM_CHANNEL),          sizeof( CHANNEL)*NOFCHN);  if ( !Chan)  {     rt_printk( KERN_INFO "ogr: rtai_kmalloc() of SHM_CHANNEL failed in init_module().\n");    return (-ENOMEM);  }  memset( Chan, 0, sizeof( CHANNEL)*NOFCHN);  RT_Ctrl = (RT_CTRL*) rtai_kmalloc( nam2num( SHM_RT_CTRL),          sizeof( RT_CTRL));  if ( !RT_Ctrl)  {     rt_printk( KERN_INFO "ogr: rtai_kmalloc() of SHM_RT_CTRL failed in init_module().\n");    return (-ENOMEM);  }  memset( RT_Ctrl, 0, sizeof( RT_CTRL));  Chn_RBuf = (CHN_RBUF*) rtai_kmalloc( nam2num( SHM_CHN_RBUF),          sizeof( CHN_RBUF));  if ( !Chn_RBuf)  {     rt_printk( KERN_INFO "ogr: rtai_kmalloc() of SHM_CHN_RBUF failed in init_module().\n");    return (-ENOMEM);  }  memset( Chn_RBuf, 0, sizeof( CHN_RBUF));  Chn_RBuf->ch_head = -1;/* *  FIFO to send nav bits to user space */  ret = rtf_create( FIFO_NAVBIT, FIFOBUFLEN_NAVBIT);  if ( ret < 0)  {    rt_printk( KERN_INFO "ogr: rtf_create(FIFO_NAVBIT,n) failed. Error code %d\n", ret);    return (-ENOMEM);      }/* *  FIFO to I/Q (trailing mode) to user space */  ret = rtf_create( FIFO_IQDUMP, FIFOBUFLEN_INQUAD);  if ( ret < 0)  {    rt_printk( KERN_INFO "ogr: rtf_create(FIFO_IQDUMP,n) failed. Error code %d\n", ret);    return (-ENOMEM);      }  RT_Ctrl->mod_loaded = 0x1234;  RT_Ctrl->rt_polling    = 1;//  rt_printk( "iopl() succeeded!\n");//  return (-1);//  rt_printk( "self_test() successful!\n");// DISCIO discrete output, value is 0// MULTI_FN_IO discrete output, value is 0  io_config( 0x301);//  de-activate test mode  test_control( 0);// MEAS_INT cleared by read of ACCUM_STATUS_B// no increase of drive of ACCUM_INT, MEAS_INT and D0-D15 pins// input level to TTL// interrupt period is 505 us// real input mode from front end// ACCUM_INT and MEAS_INT are disabled  system_setup( 0);//  rt_printk( "system_setup() succeeded!\n");// reset bits, active low  reset_cntl( 0x1fff);  rt_task_init( &thread, ogr_routine, 0, RTAI_STACK_SIZE, 0, 0, 0);  tick_period = start_rt_timer( nano2count( TICK_PERIOD));  start = rt_get_time() + 100 * tick_period;    rt_task_make_periodic( &thread, start, tick_period);  return 0;}/* ------------------------------------------------------------------------- *FUNCTION void cleanup_module( void)RETURNS  nonePARAMETERS  nonePURPOSE  clean up, called at /sbin/rmmod ogr_rtptoc* ------------------------------------------------------------------------- */void cleanup_module( void){//  power down correlators  reset_cntl( 0x1);  stop_rt_timer();    rt_busy_sleep( 10000000);  rt_task_delete( &thread);/* * free shared memory areas */  if ( Chan)    rtai_kfree( nam2num( SHM_CHANNEL));  if ( RT_Ctrl)    rtai_kfree( nam2num( SHM_RT_CTRL));  if ( Chn_RBuf)    rtai_kfree( nam2num( SHM_CHN_RBUF));/* * free FIFOs */  rtf_destroy( FIFO_IQDUMP);  rtf_destroy( FIFO_NAVBIT);#ifdef ISABOARD  release_region( ISABASE, ISA_NR_PORTS);#endif#ifdef PCIBOARD  release_region( PCIBASE, PCI_NR_PORTS);#endif  return;}/* ------------------------------- end of file ---------------------------- */

⌨️ 快捷键说明

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