示例#1
0
/**
 * @function WavStop
 * @brief stop the WAV playback
 * @param none
 * @return none
 */
void WavStop(void) {
  if(state != WAV_STOPPED) {
    state = WAV_STOPPED;
    TmrStop(WAV_TIMER);       /*disable the callback*/
    f_close(&pFile);
    pOut(0x8000);       /*clear the DAC*/
  }
}
示例#2
0
文件: tmr.c 项目: Griffindog/tiny-DDS
/**
 * @function TmrSetCallback
 * @brief associate a callback function to a given timer
 * @param tmr_t tmr_id: timer id
 * @param *ptrCallback: pointer to a void function(void)
 * @return none
 */
void TmrSetCallback(tmr_t tmr_id, void (*ptrCallback) (void)) {
  switch(tmr_id) {
    case TMR_1:
      TmrStop(TMR_1);
      tmr1PtrCallback = ptrCallback;
      break;
    case TMR_4:
      TmrStop(TMR_4);
      tmr4PtrCallback = ptrCallback;
      break;
    case TMR_5:
      TmrStop(TMR_5);
      tmr5PtrCallback = ptrCallback;
      break;
    default:
      break;
  }
}
示例#3
0
/**
 * @function ARB_Stop
 * @brief stop the arbitrary handler (stop timer, clear current sample #id)
 * @param arb_st *arb: pointer to the arbitrary waveform handler
 * @return none
 */
void ARB_Stop(arb_st *arb) {

  if(arb != NULL) {
    arb->run = 0;
    arb->currentSample = 0;

    /*stop the timer first, then the DDS*/
    TmrStop(ARB_TIMER);
    AD9834_Stop(0);

    /*kill the wav playback if any*/
    if(arb->waveformType == ARB_WAVE_WAV) {
      WavStop();
    }
  }
}
示例#4
0
TestHarness::TestHarness(QWidget *parent)
    : QWidget(parent)
{
    QGroupBox *ecu_box = new QGroupBox("Engine Control Unit");
    QGroupBox *gps_box = new QGroupBox("GPS");
    QGroupBox *imu_box = new QGroupBox("Inertial Measurement Unit");
    QGroupBox *lts_box = new QGroupBox("Lighting System");
    QGroupBox *wls_box = new QGroupBox("Wireless Radio");
    QGroupBox *tmr_box = new QGroupBox("Timer/Logger");

    QGridLayout *ecu_layout = new QGridLayout();
    QGridLayout *gps_layout = new QGridLayout();
    QGridLayout *imu_layout = new QGridLayout();
    QGridLayout *lts_layout = new QGridLayout();
    QGridLayout *wls_layout = new QGridLayout();
    QGridLayout *tmr_layout = new QGridLayout();
    QGridLayout *layout = new QGridLayout();

    // ecu box
    ecu_rpm_label = new QLabel("RPM:");
    ecu_rpm_edit = new QLineEdit("2000");
    ecu_spark_label = new QLabel("Spark Advance:");
    ecu_spark_edit = new QLineEdit("15.0");
    ecu_cranking_label = new QLabel("Cranking:");
    ecu_cranking_edit = new QCheckBox("Yes");
    ecu_map_label = new QLabel("Manifold Air Pres:");
    ecu_map_edit = new QLineEdit("1500.0");
    ecu_mat_label = new QLabel("Manifold Air Temp:");
    ecu_mat_edit = new QLineEdit("15.0");
    ecu_clt_label = new QLabel("Coolant Temp:");
    ecu_clt_edit = new QLineEdit("90.0");
    ecu_tps_label = new QLabel("Throttle Position:");
    ecu_tps_edit = new QLineEdit("50.0");
    ecu_batt_label = new QLabel("Battery:");
    ecu_batt_edit = new QLineEdit("11.9");
    ecu_maf_label = new QLabel("Mass Airflow:");
    ecu_maf_edit = new QLineEdit("900.0");
    ecu_tc_label = new QLabel("Tach Count:");
    ecu_tc_edit = new QLineEdit("100");
    ecu_update_button = new QPushButton("Update");

    ecu_layout->addWidget(ecu_rpm_label, 0, 0);
    ecu_layout->addWidget(ecu_rpm_edit, 0, 1);
    ecu_layout->addWidget(ecu_spark_label, 1, 0);
    ecu_layout->addWidget(ecu_spark_edit, 1, 1);
    ecu_layout->addWidget(ecu_cranking_label, 2, 0);
    ecu_layout->addWidget(ecu_cranking_edit, 2, 1);
    ecu_layout->addWidget(ecu_map_label, 3, 0);
    ecu_layout->addWidget(ecu_map_edit, 3, 1);
    ecu_layout->addWidget(ecu_mat_label, 4, 0);
    ecu_layout->addWidget(ecu_mat_edit, 4, 1);
    ecu_layout->addWidget(ecu_clt_label, 5, 0);
    ecu_layout->addWidget(ecu_clt_edit, 5, 1);
    ecu_layout->addWidget(ecu_tps_label, 6, 0);
    ecu_layout->addWidget(ecu_tps_edit, 6, 1);
    ecu_layout->addWidget(ecu_batt_label, 7, 0);
    ecu_layout->addWidget(ecu_batt_edit, 7, 1);
    ecu_layout->addWidget(ecu_maf_label, 8, 0);
    ecu_layout->addWidget(ecu_maf_edit, 8, 1);
    ecu_layout->addWidget(ecu_tc_label, 9, 0);
    ecu_layout->addWidget(ecu_tc_edit, 9, 1);
    ecu_layout->addWidget(ecu_update_button, 10, 0, 1, 2);
    ecu_layout->setRowStretch(11, 1);

    // gps box
    gps_time_label = new QLabel("UTC Time:");
    gps_colon1_label = new QLabel(":");
    gps_colon2_label = new QLabel(":");
    gps_hrs_edit = new QLineEdit("12");
    gps_mins_edit = new QLineEdit("01");
    gps_secs_edit = new QLineEdit("01.001");
    gps_lat_label = new QLabel("Latitude:");
    gps_deg1_label = new QLabel("deg");
    gps_min1_label = new QLabel("min");
    gps_latdeg_edit = new QLineEdit("35");
    gps_latmin_edit = new QLineEdit("15.653229");
    gps_latdir_edit = new QLineEdit("N");
    gps_long_label = new QLabel("Longitude:");
    gps_deg2_label = new QLabel("deg");
    gps_min2_label = new QLabel("min");
    gps_longdeg_edit = new QLineEdit("120");
    gps_longmin_edit = new QLineEdit("39.2362974");
    gps_longdir_edit = new QLineEdit("W");
    gps_alt_label = new QLabel("Altitude:");
    gps_alt_edit = new QLineEdit("500.0");
    gps_speed_label = new QLabel("Speed:");
    gps_speed_edit = new QLineEdit("25.0");
    gps_heading_label = new QLabel("Heading:");
    gps_heading_edit = new QLineEdit("187.5");
    gps_update_button = new QPushButton("Update");

    gps_layout->addWidget(gps_time_label, 0, 0);
    gps_layout->addWidget(gps_hrs_edit, 0, 1);
    gps_layout->addWidget(gps_colon1_label, 0, 2);
    gps_layout->addWidget(gps_mins_edit, 0, 3);
    gps_layout->addWidget(gps_colon2_label, 0, 4);
    gps_layout->addWidget(gps_secs_edit, 0, 5);
    gps_layout->addWidget(gps_lat_label, 1, 0);
    gps_layout->addWidget(gps_latdeg_edit, 1, 1);
    gps_layout->addWidget(gps_deg1_label, 1, 2);
    gps_layout->addWidget(gps_latmin_edit, 1, 3);
    gps_layout->addWidget(gps_min1_label, 1, 4);
    gps_layout->addWidget(gps_latdir_edit, 1, 5);
    gps_layout->addWidget(gps_long_label, 2, 0);
    gps_layout->addWidget(gps_longdeg_edit, 2, 1);
    gps_layout->addWidget(gps_deg2_label, 2, 2);
    gps_layout->addWidget(gps_longmin_edit, 2, 3);
    gps_layout->addWidget(gps_min2_label, 2, 4);
    gps_layout->addWidget(gps_longdir_edit, 2, 5);
    gps_layout->addWidget(gps_alt_label, 3, 0);
    gps_layout->addWidget(gps_alt_edit, 3, 1, 1, 5);
    gps_layout->addWidget(gps_speed_label, 4, 0);
    gps_layout->addWidget(gps_speed_edit, 4, 1, 1, 5);
    gps_layout->addWidget(gps_heading_label, 5, 0);
    gps_layout->addWidget(gps_heading_edit, 5, 1, 1, 5);
    gps_layout->addWidget(gps_update_button, 6, 0, 1, 6);
    gps_layout->setRowStretch(7, 1);

    // imu box
    imu_ax_label = new QLabel("Accel X:");
    imu_ax_edit = new QLineEdit("0.0");
    imu_ay_label = new QLabel("Accel Y:");
    imu_ay_edit = new QLineEdit("1.0");
    imu_az_label = new QLabel("Accel Z:");
    imu_az_edit = new QLineEdit("0.0");
    imu_gx_label = new QLabel("Gyro X:");
    imu_gx_edit = new QLineEdit("0.0");
    imu_gy_label = new QLabel("Gyro Y:");
    imu_gy_edit = new QLineEdit("0.0");
    imu_gz_label = new QLabel("Gyro Z:");
    imu_gz_edit = new QLineEdit("0.0");
    imu_update_button = new QPushButton("Update");

    imu_layout->addWidget(imu_ax_label, 0, 0);
    imu_layout->addWidget(imu_ax_edit, 0, 1);
    imu_layout->addWidget(imu_ay_label, 1, 0);
    imu_layout->addWidget(imu_ay_edit, 1, 1);
    imu_layout->addWidget(imu_az_label, 2, 0);
    imu_layout->addWidget(imu_az_edit, 2, 1);
    imu_layout->addWidget(imu_gx_label, 3, 0);
    imu_layout->addWidget(imu_gx_edit, 3, 1);
    imu_layout->addWidget(imu_gy_label, 4, 0);
    imu_layout->addWidget(imu_gy_edit, 4, 1);
    imu_layout->addWidget(imu_gz_label, 5, 0);
    imu_layout->addWidget(imu_gz_edit, 5, 1);
    imu_layout->addWidget(imu_update_button, 6, 0, 1, 2);
    imu_layout->setRowStretch(7, 1);

    // lights box
    lts_head_label = new QLabel("Headlights:");
    lts_head_edit = new QCheckBox("On");
    lts_brake_label = new QLabel("Brakelights:");
    lts_brake_edit = new QCheckBox("On");
    lts_left_label = new QLabel("Left Turn Signal:");
    lts_left_edit = new QCheckBox("On");
    lts_right_label = new QLabel("Right Turn Signal:");
    lts_right_edit = new QCheckBox("On");
    lts_hazards_label = new QLabel("Hazards:");
    lts_hazards_edit = new QCheckBox("On");
    lts_update_button = new QPushButton("Update");

    lts_layout->addWidget(lts_head_label, 0, 0);
    lts_layout->addWidget(lts_head_edit, 0, 1);
    lts_layout->addWidget(lts_brake_label, 1, 0);
    lts_layout->addWidget(lts_brake_edit, 1, 1);
    lts_layout->addWidget(lts_left_label, 2, 0);
    lts_layout->addWidget(lts_left_edit, 2, 1);
    lts_layout->addWidget(lts_right_label, 3, 0);
    lts_layout->addWidget(lts_right_edit, 3, 1);
    lts_layout->addWidget(lts_hazards_label, 4, 0);
    lts_layout->addWidget(lts_hazards_edit, 4, 1);
    lts_layout->addWidget(lts_update_button, 5, 0, 1, 2);
    lts_layout->setRowStretch(6, 1);

    // wireless box
    wls_rx_label = new QLabel("Received from the radio:");
    wls_rx_edit = new QTextEdit();
    wls_tx_label = new QLabel("Transmit to the radio:");
    wls_tx_edit = new QTextEdit();
    wls_update_button = new QPushButton("Update");

    wls_layout->addWidget(wls_rx_label, 0, 0);
    wls_layout->addWidget(wls_rx_edit, 1, 0);
    wls_layout->addWidget(wls_tx_label, 2, 0);
    wls_layout->addWidget(wls_tx_edit, 3, 0);
    wls_layout->addWidget(wls_update_button, 4, 0);
    wls_layout->setRowStretch(5, 1);

    // timer box
    tmr_time_display = new QLCDNumber(8);
    tmr_time_display->setSegmentStyle(QLCDNumber::Flat);
    tmr_start_button = new QPushButton("Start Timer");
    tmr_stop_button = new QPushButton("Stop Timer");
    log_start_button = new QPushButton("Start Data Logger");
    log_stop_button = new QPushButton("Stop Data Logger");

    tmr_layout->addWidget(tmr_time_display, 0, 0);
    tmr_layout->addWidget(tmr_start_button, 1, 0);
    tmr_layout->addWidget(tmr_stop_button, 2, 0);
    tmr_layout->addWidget(log_start_button, 3, 0);
    tmr_layout->addWidget(log_stop_button, 4, 0);
    tmr_layout->setRowStretch(5, 1);

    // master layout
    ecu_box->setLayout(ecu_layout);
    gps_box->setLayout(gps_layout);
    imu_box->setLayout(imu_layout);
    lts_box->setLayout(lts_layout);
    wls_box->setLayout(wls_layout);
    tmr_box->setLayout(tmr_layout);
    layout->addWidget(ecu_box, 0, 0);
    layout->addWidget(gps_box, 0, 1);
    layout->addWidget(imu_box, 0, 2);
    layout->addWidget(lts_box, 1, 0);
    layout->addWidget(wls_box, 1, 1);
    layout->addWidget(tmr_box, 1, 2);

    setLayout(layout);
    setWindowTitle("Hardware Interface Test Harness");

    // connect up the ui to internal slots
    connect(tmr_start_button, SIGNAL(clicked()), this, SLOT(TmrStart()));
    connect(tmr_stop_button, SIGNAL(clicked()), this, SLOT(TmrStop()));
    connect(this, SIGNAL(TmrTick(int)), tmr_time_display, SLOT(display(int)));
    connect(ecu_update_button, SIGNAL(clicked()), this, SLOT(UpdateEcu()));
    connect(gps_update_button, SIGNAL(clicked()), this, SLOT(UpdateGps()));
    connect(imu_update_button, SIGNAL(clicked()), this, SLOT(UpdateImu()));
    connect(lts_update_button, SIGNAL(clicked()), this, SLOT(UpdateLts()));
    connect(wls_update_button, SIGNAL(clicked()), this, SLOT(UpdateWls()));

    // done initializing ui, set up some internal stuff
    timer_running = false;
    time = new QTime();
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(TimerTick()));

    // debug
    logger = new DataLogger();
    dashboard = new Dashboard();
    dashboard->show();

    // connect up the test harness to the data logger
    connect(log_start_button, SIGNAL(clicked()), logger, SLOT(LogStart()));
    connect(log_stop_button, SIGNAL(clicked()), logger, SLOT(LogStop()));
    connect(this, SIGNAL(EcuStateChanged(ecustate_t)), logger, SLOT(EcuUpdate(ecustate_t)));
    connect(this, SIGNAL(GpsStateChanged(gpsstate_t)), logger, SLOT(GpsUpdate(gpsstate_t)));
    connect(this, SIGNAL(ImuStateChanged(imustate_t)), logger, SLOT(ImuUpdate(imustate_t)));
    connect(this, SIGNAL(LtsStateChanged(ltsstate_t)), logger, SLOT(LtsUpdate(ltsstate_t)));
    connect(this, SIGNAL(TmrTick(int)), logger, SLOT(TmrUpdate(int)));

    // connect up the test harness to the dashboard
    connect(this, SIGNAL(TmrTick(int)), dashboard, SLOT(TmrUpdate(int)));
    connect(this, SIGNAL(EcuStateChanged(ecustate_t)), dashboard, SLOT(EcuUpdate(ecustate_t)));
    connect(this, SIGNAL(GpsStateChanged(gpsstate_t)), dashboard, SLOT(GpsUpdate(gpsstate_t)));
    connect(this, SIGNAL(ImuStateChanged(imustate_t)), dashboard, SLOT(ImuUpdate(imustate_t)));
    connect(this, SIGNAL(LtsStateChanged(ltsstate_t)), dashboard, SLOT(LtsUpdate(ltsstate_t)));
}
示例#5
0
/**
 * @function TicksSetExternalCallback
 * @brief enable a external function, which will be called every ticks
 * @param void (*function)(void): pointer to the extern function
 * @return none
 */
void TicksSetExternalCallback(void (*function)(void)) {
  TmrStop(TMR_1);
  extFunc = function;
  TmrLaunch(TMR_1);
}
示例#6
0
/**
 * @function TicksSetWatchdog
 * @brief enable a watchdog function
 * @param void (*function)(void): function to execute when reaching a delay
 * @param ticks_t delay: dela, in ms
 * @return none
 */
void TicksSetWatchdog(void (*function)(void), ticks_t delay) {
  TmrStop(TMR_1);
  wdtFunc = function;
  u64wdtTimer = u64AbsoluteTicks + delay;
  TmrLaunch(TMR_1);
}
示例#7
0
/**
 * @function ARB_Pause
 * @brief suspend the arbitrary handler (timer pause)
 * @param arb_st *arb: pointer to the arbitrary waveform handler
 * @return none
 */
void ARB_Pause(arb_st *arb) {
  if(arb != NULL) {
    arb->run = 0;
    TmrStop(ARB_TIMER);
  }
}
示例#8
0
文件: tmr.c 项目: Griffindog/tiny-DDS
/**
 * @function TmrSetFrequency
 * @brief configure a given timer with a desired frequency
 * @param tmr_t tmr_id: timer id
 * @param uint32_t desiredFrequency: desired frequency, in Hz
 * @return int8_t: 0 sucess, otherwise error
 */
int8_t TmrSetFrequency(tmr_t tmr_id, uint32_t desiredFrequency) {

  uint16_t tmrValue = 0xFFFF;
  uint16_t prescale;
  uint32_t cfg;
  int8_t res = -1;

  
    switch(tmr_id) {
    
      case TMR_1:
        if(SetTimerFrequency(TMR_TYPE_A, desiredFrequency, &tmrValue, &prescale) == 0) {
          TmrStop(TMR_1);
          mT1ClearIntFlag();
          ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_1 | T1_INT_SUB_PRIOR_1);
          cfg = T1_SOURCE_INT | T1_IDLE_CON;
          if(prescale == 1) cfg |= T1_PS_1_1;
          else if(prescale == 8) cfg |= T1_PS_1_8;
          else if(prescale == 64) cfg |= T1_PS_1_64;
          else cfg |= T1_PS_1_256;
          OpenTimer1(cfg, tmrValue);
          timer1Configured = 1;
          res = 0;
        }
        break;
        
      case TMR_4:
        if(SetTimerFrequency(TMR_TYPE_B, desiredFrequency, &tmrValue, &prescale) == 0) {
          TmrStop(TMR_4);
          mT4ClearIntFlag();
          ConfigIntTimer4(T4_INT_ON | T4_INT_PRIOR_4 | T4_INT_SUB_PRIOR_1);
          cfg = T4_SOURCE_INT | T4_IDLE_CON;
          if(prescale == 1) cfg |= T4_PS_1_1;
          else if(prescale == 2) cfg |= T4_PS_1_2;
          else if(prescale == 4) cfg |= T4_PS_1_4;
          else if(prescale == 8) cfg |= T4_PS_1_8;
          else if(prescale == 16) cfg |= T4_PS_1_16;
          else if(prescale == 32) cfg |= T4_PS_1_32;
          else if(prescale == 64) cfg |= T4_PS_1_64;
          else cfg |= T4_PS_1_256;
          OpenTimer4(cfg, tmrValue);
          timer4Configured = 1;
          res = 0;
        }
        break;
        
      case TMR_5:
        if(SetTimerFrequency(TMR_TYPE_B, desiredFrequency, &tmrValue, &prescale) == 0) {
          TmrStop(TMR_5);
          mT5ClearIntFlag();
          ConfigIntTimer5(T5_INT_ON | T5_INT_PRIOR_5 | T5_INT_SUB_PRIOR_1);
          cfg = T5_SOURCE_INT | T5_IDLE_CON;
          if(prescale == 1) cfg |= T5_PS_1_1;
          else if(prescale == 2) cfg |= T5_PS_1_2;
          else if(prescale == 4) cfg |= T5_PS_1_4;
          else if(prescale == 8) cfg |= T5_PS_1_8;
          else if(prescale == 16) cfg |= T5_PS_1_16;
          else if(prescale == 32) cfg |= T5_PS_1_32;
          else if(prescale == 64) cfg |= T5_PS_1_64;
          else cfg |= T5_PS_1_256;
          OpenTimer5(cfg, tmrValue);
          timer5Configured = 1;
          res = 0;
        }
        break;
        
      default:
        break;
    }
  return res;
}