示例#1
0
INT8U msgQQuery(MSG_Q_ID msgQId, OS_Q_DATA *pdata)
{
    INT8U ret;

	OSSchedLock();
    ret = OSQQuery(msgQId->pEvent, pdata);
	OSSchedUnlock();
    return ret;
}
示例#2
0
int sys_mbox_valid(sys_mbox_t *mbox)
{  
	u8_t ucErr;
	int ret;
	OS_Q_DATA q_data;
	memset(&q_data, 0, sizeof(OS_Q_DATA));
	ucErr = OSQQuery ((*mbox)->pQ,&q_data);
	ret=(ucErr<2 && (q_data.OSNMsgs<q_data.OSQSize))?1:0;
	return ret; 
} 
示例#3
0
/*
* This function gets the number of messages queued to a message queue
*/
extern int32_t msgQNumMsgs
    (
    MSG_Q_ID msgQId /* a pointer to the event control block associated with the desired queue */
    )
{
    OS_Q_DATA msgInfo;

    if (OS_NO_ERR == OSQQuery(msgQId, &msgInfo)) {
        return msgInfo.OSNMsgs;
    }
    return 0;
}
示例#4
0
/*
*******************************************************************************
**
** This function simply queries a message mailqueue without blocking if no
** message is available.
**
*******************************************************************************
*/
RTOS_Message RTOS_MailqueueQuery( RTOS_Mailqueue mailqueue )
{
    OS_Q_DATA mdata;

    if( ! RTOS_MailqueueIsValid( mailqueue ) )
        return( (RTOS_Message)0 );
     
    if( OSQQuery( (OS_EVENT*)mailqueue, &mdata ) != OS_NO_ERR )
        return( (RTOS_Message)0 );

    return( (RTOS_Message) mdata.OSMsg );
}
示例#5
0
INT32U video_encode_audio_sfx(INT16U *PCM_Buf, INT32U cbLen)
{
	INT32S i, index;
	INT32U Temp;
	OS_Q_DATA OSQData; 
	AUDIO_ARGUMENT aud_arg;
	
	aud_arg.Main_Channel = 0;
	    
	if(audio_decode_status(aud_arg) == AUDIO_CODEC_PROCESSING)
	{
		OSQQuery(aud_bg_send_q, &OSQData);
		index = OSQData.OSNMsgs-1;
		if(index<0)
			index = 0;
		
		for(i = 0; i<(cbLen/2) ; i++)
		{
			Temp = (INT16U) pcm_bg_out[index][i];
			Temp +=  PCM_Buf[i];
			PCM_Buf[i] = Temp >> 1;
		}
	}
示例#6
0
void send_task(void* pdata)
{
  INT8U return_code = OS_NO_ERR;
  INT32U  msg = 0;
  OS_Q_DATA queue_data;

  while (1)
  {
    return_code = OSQQuery(msgqueue, &queue_data);
    alt_ucosii_check_return_code(return_code);
    if(queue_data.OSNMsgs < MSG_QUEUE_SIZE) /*Check the number of messages*/
    {                                       /*in the message queue*/
      return_code = OSQPostOpt(msgqueue, (void *)&msg, OS_POST_OPT_BROADCAST);
      alt_ucosii_check_return_code(return_code);
      msg++;
      number_of_messages_sent++;
    }
    else
    {
      OSTimeDlyHMSM(0, 0, 1, 0);
    }
  }
}
示例#7
0
void MainTask(void *arg) {
  ADI_AFE_DEV_HANDLE hDevice;
  int16_t dft_results[DFT_RESULTS_COUNT];
  q15_t dft_results_q15[DFT_RESULTS_COUNT];
  q31_t dft_results_q31[DFT_RESULTS_COUNT];
  q31_t magnitude[DFT_RESULTS_COUNT / 2];
  q15_t phase[DFT_RESULTS_COUNT / 2];
  fixed32_t magnitude_result[DFT_RESULTS_COUNT / 2 - 1];
  fixed32_t phase_result[DFT_RESULTS_COUNT / 2 - 1];
  char msg[MSG_MAXLEN];
  uint8_t err;
  done = 0;
  uint16_t pressure_analog;
  uint32_t pressure;
  nummeasurements = 0;
  uint32_t rtcCount;
  ADI_I2C_RESULT_TYPE i2cResult;

  // Initialize driver.
  rtc_Init();

  // Calibrate.
  rtc_Calibrate();

  // Initialize UART.
  if (uart_Init()) {
    FAIL("ADI_UART_SUCCESS");
  }

  // Initialize I2C.
  i2c_Init(&i2cDevice);
  
  // Initialize flags.
  bRtcAlarmFlag = bRtcInterrupt = bWdtInterrupt = false;

  // Get the current count.
  if (adi_RTC_GetCount(hRTC, &rtcCount)) {
    FAIL("adi_RTC_GetCount failed");
  }

  // Initialize the AFE API.
  if (adi_AFE_Init(&hDevice)) {
    FAIL("adi_AFE_Init");
  }

  // AFE power up.
  if (adi_AFE_PowerUp(hDevice)) {
    FAIL("adi_AFE_PowerUp");
  }

  // Excitation Channel Power-up.
  if (adi_AFE_ExciteChanPowerUp(hDevice)) {
    FAIL("adi_AFE_ExciteChanPowerUp");
  }

  // TIA Channel Calibration.
  if (adi_AFE_TiaChanCal(hDevice)) {
    FAIL("adi_AFE_TiaChanCal");
  }

  // Excitation Channel Calibration (Attenuation Enabled).
  if (adi_AFE_ExciteChanCalAtten(hDevice)) {
    FAIL("adi_AFE_ExciteChanCalAtten");
  }

  // Update FCW in the sequence.
  seq_afe_acmeas2wire[3] = SEQ_MMR_WRITE(REG_AFE_AFE_WG_FCW, FCW);
  // Update sine amplitude in the sequence.
  seq_afe_acmeas2wire[4] =
      SEQ_MMR_WRITE(REG_AFE_AFE_WG_AMPLITUDE, SINE_AMPLITUDE);

  // Recalculate CRC in software for the AC measurement, because we changed.
  // FCW and sine amplitude settings.
  adi_AFE_EnableSoftwareCRC(hDevice, true);

  // Perform the impedance measurement.
  if (adi_AFE_RunSequence(hDevice, seq_afe_acmeas2wire, (uint16_t *)dft_results,
                          DFT_RESULTS_COUNT)) {
    FAIL("Impedance Measurement");
  }

  // Set RTC alarm.
  printf("rtcCount: %d\r\n", rtcCount);
  if (ADI_RTC_SUCCESS != adi_RTC_SetAlarm(hRTC, rtcCount + 120)) {
    FAIL("adi_RTC_SetAlarm failed");
  }

  // Enable RTC alarm.
  if (ADI_RTC_SUCCESS != adi_RTC_EnableAlarm(hRTC, true)) {
    FAIL("adi_RTC_EnableAlarm failed");
  }

  // Read the initial impedance.
  q31_t magnitudecal;
  q15_t phasecal;

  convert_dft_results(dft_results, dft_results_q15, dft_results_q31);
  arm_cmplx_mag_q31(dft_results_q31, &magnitudecal, 2);

  phasecal = arctan(dft_results[1], dft_results[0]);

  printf("raw rcal data: %d, %d\r\n", dft_results[1], dft_results[0]);
  printf("rcal (magnitude, phase) = (%d, %d)\r\n", magnitudecal, phasecal);

  // Create the message queue for communicating between the ISR and this task.
  dft_queue = OSQCreate(&dft_queue_msg[0], DFT_QUEUE_SIZE);

  // Hook into the DFT interrupt.
  if (ADI_AFE_SUCCESS !=
      adi_AFE_RegisterAfeCallback(
          hDevice, ADI_AFE_INT_GROUP_CAPTURE, AFE_DFT_Callback,
          BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN)) {
    FAIL("adi_AFE_RegisterAfeCallback");
  }
  if (ADI_AFE_SUCCESS !=
      adi_AFE_ClearInterruptSource(
          hDevice, ADI_AFE_INT_GROUP_CAPTURE,
          BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN)) {
    FAIL("adi_AFE_ClearInterruptSource (1)");
  }

  packed32_t q_result;
  void *q_result_void;
  OS_Q_DATA q_data;
  uint16_t q_size;
  bool inflated = false;
  while (true) {
    // Wait for the user to press the button.
    printf("MainTask: waiting for button.\n");
    OSSemPend(ux_button_semaphore, 0, &err);
    if (err != OS_ERR_NONE) {
      FAIL("OSSemPend: MainTask");
    }
    
    // TODO: fix bug when pressing button multiple times.
    // Have the pump task inflate the cuff.
    printf("MainTask: button detected. Resuming pump task.\n");
    err = OSTaskResume(TASK_PUMP_PRIO);
    if (err != OS_ERR_NONE) {
      FAIL("OSTaskResume: MainTask (1)");
    }
    
    // Wait a bit.
    printf("MainTask: waiting a bit.\n");
    err = OSTimeDlyHMSM(0, 0, 1, 0);
    if (err != OS_ERR_NONE) {
      FAIL("OSTimeDlyHMSM: MainTask (3)");
    }
    
    // Enable the DFT interrupt.
    printf("MainTask: enabling DFT interrupt.\n");
    if (ADI_AFE_SUCCESS !=
        adi_AFE_EnableInterruptSource(
            hDevice, ADI_AFE_INT_GROUP_CAPTURE,
            BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN, true)) {
      FAIL("adi_AFE_EnableInterruptSource");
    }
    
    PRINT("START\r\n");
    printf("START\r\n");

    while (true) {
      // Wait on the queue to get DFT data from the ISR (~76 Hz).
      //printf("MainTask: pending on DFT queue.\n");
      q_result_void = OSQPend(dft_queue, 0, &err);
      q_result.pointer = q_result_void;
      if (err != OS_ERR_NONE) {
        FAIL("OSQPend: dft_queue");
      }
      OSQQuery(dft_queue, &q_data);
      q_size = q_data.OSNMsgs;
    
      // Right after we get this data, get the transducer's value from the
      // Arduino.
      //printf("MainTask: getting transducer value via I2C.\n");
      i2cResult = adi_I2C_MasterReceive(i2cDevice, I2C_PUMP_SLAVE_ADDRESS, 0x0,
                                        ADI_I2C_8_BIT_DATA_ADDRESS_WIDTH,
                                        i2c_rx, 3, false);
      if (i2cResult != ADI_I2C_SUCCESS) {
        FAIL("adi_I2C_MasterReceive: get pressure from Arduino");
      }

      // Get the analog pressure value from the Arduino.
      if (i2c_rx[0] == ARDUINO_PRESSURE_AVAILABLE
          || i2c_rx[0] == ARDUINO_STILL_INFLATING) {
        pressure_analog = i2c_rx[1] | (i2c_rx[2] << 8);
      } else {
        FAIL("Corrupted or unexpected data from Arduino.");
      }
      
      // Convert the analog value to mmHg.
      pressure = transducer_to_mmhg(pressure_analog);
      //printf("MainTask: got pressure value: %d mmHg.\n", pressure);
      
      // If the pressure is below the threshold, we're done; break the loop.
      if (inflated && pressure < LOWEST_PRESSURE_THRESHOLD_MMHG) {
        PRINT("END\r\n");
        printf("END\r\n");
        inflated = false;
        break;
      } else if (pressure > LOWEST_PRESSURE_THRESHOLD_MMHG * 1.1) {
        inflated = true;
      }

      // Convert DFT results to 1.15 and 1.31 formats.
      dft_results[0] = q_result.parts.magnitude;
      dft_results[1] = q_result.parts.phase;
      convert_dft_results(dft_results, dft_results_q15, dft_results_q31);

      // Compute the magnitude using CMSIS.
      arm_cmplx_mag_q31(dft_results_q31, magnitude, DFT_RESULTS_COUNT / 2);

      // Calculate final magnitude values, calibrated with RCAL.
      fixed32_t magnituderesult;
      magnituderesult = calculate_magnitude(magnitudecal, magnitude[0]);
      q15_t phaseresult;
      phaseresult = arctan(dft_results[1], dft_results[0]);
      fixed32_t phasecalibrated;

      // Calibrate with phase from rcal.
      phasecalibrated = calculate_phase(phasecal, phaseresult);
      
      // TODO: dispatch to another thread?
      //printf("MainTask: sending data via UART.\n");;
      print_PressureMagnitudePhase("", pressure, magnituderesult, phasecalibrated,
                                   q_size);
      nummeasurements++;
    }

    
    // We're done measuring, for now. Disable the DFT interrupts.
    printf("MainTask: disabling DFT interrupts.\n");
    if (ADI_AFE_SUCCESS !=
        adi_AFE_EnableInterruptSource(
            hDevice, ADI_AFE_INT_GROUP_CAPTURE,
            BITM_AFE_AFE_ANALOG_CAPTURE_IEN_DFT_RESULT_READY_IEN, false)) {
      FAIL("adi_AFE_EnableInterruptSource (false)");
    }
    
    // Tell the pump task to deflate the cuff.
    printf("MainTask: resuming pump task to deflate the cuff.\n");
    err = OSTaskResume(TASK_PUMP_PRIO);
    if (err != OS_ERR_NONE) {
      FAIL("OSTaskResume: MainTask (2)");
    }

    // Suspend until the pump finishes deflating. We can then go back to
    // listening for the user input.
    printf("MainTask: suspending to wait for pump task.\n");
    err = OSTaskSuspend(OS_PRIO_SELF);
    if (err != OS_ERR_NONE) {
      FAIL("OSTaskSuspend: MainTask (3)");
    }

    // Tell the UX that we're done for now.
    UX_Disengage();
  }
}