Exemplo n.º 1
0
/**
  * @brief  This function handles DMA channel interrupt request.- PPG adc data ISR
  * @param  None
  * @retval None
  */
__attribute__((externally_visible)) void DMAChannel1_IRQHandler(void) {
	static uint8_t decimation_counter;
	if(DMA_GetITStatus(DMA1_IT_HT1)) {
		DMA_ClearITPendingBit(DMA1_IT_GL1);		//clear all the interrupts
		if(Sensors&PPG_SENSORS)				//PPG enabled
			PPG_LO_Filter(ADC1_Convertion_buff);	//Process lower half
	}
	else if (DMA_GetITStatus(DMA1_IT_TC1)) {
		DMA_ClearITPendingBit(DMA1_IT_GL1);		//clear all the interrupts
		if(Sensors&PPG_SENSORS)				//PPG enabled
			PPG_LO_Filter(&ADC1_Convertion_buff[ADC_BUFF_SIZE/4]);//Transfer complete, process upper half - indexed as 16bit words
	}
	DMA_ClearFlag(DMA1_FLAG_TC1|DMA1_FLAG_HT1);  		//make sure flags are clear
	//Now we process other sensor data - we do this here so as to have all the sensors syncronised with the PPG data
	if(++decimation_counter==PPG_NO_SUBSAMPLES) {		//Each time this is true we will have output some PPG samples
		decimation_counter=0;				//Reset this here
		//Now process each sensor
		if(Sensors&(1<<PRESSURE_HOSE))			//Only pass data once hose is connected
			Add_To_Buffer(*(uint32_t*)(&Reported_Pressure),&Pressures_Buffer);//Pass pressure data via buffer to avoid issues with lag
		if(Sensors&(1<<TEMPERATURE_SENSOR))		//Only pass data is I2C temp sensor is connected
			Add_To_Buffer(*(uint32_t*)(&TMP102_Reported_Temperature),&Temperatures_Buffer);//Pass press data via buffer avoiding lag issue
		if(Sensors&(1<<THERMISTOR_SENSOR))		//Only pass data is I2C temp sensor is connected
			Add_To_Buffer(*(uint32_t*)(&Device_Temperature),&Thermistor_Buffer);//Pass press data via buffer avoiding lag issue
		//More sensors can be added here	
	}
}
Exemplo n.º 2
0
/**
  * @brief  Loads the data from the raw I2C driver into the data buffers as 16 bit integers
  * @param  uint8_t state: takes values 0 or 1 to toggle between sparkfun sensor units
  * @retval None
  */
void Fill_Sample_Buffers(uint8_t state) {	//State should be zero or one to use the two sparkfun sensor buffers
	for(uint8_t n=0;n<3;n++) {
		Add_To_Buffer(*(uint16_t*)&(Rawdata[1+4*state][2*n]),		&(sfe_sensor_buffers[state].accel[n]));
		Add_To_Buffer(Flipedbytes(*(uint16_t*)&(Rawdata[2+4*state][2*n])),&(sfe_sensor_buffers[state].magno[n]));
		Add_To_Buffer(Flipedbytes(*(uint16_t*)&(Rawdata[3+4*state][2*n+2])),&(sfe_sensor_buffers[state].gyro[n]));//+2 as we skip the temperature
	}
	Add_To_Buffer(Flipedbytes(*(uint16_t*)&(Rawdata[3+4*state][0])),&(sfe_sensor_buffers[state].temp));//the temperature from the itg3200
	//Add the LSM330 temperature sensor (this is only 8 bit output)	- other LSM330 sensor data is added directly from callbacks
	if(!state)
		Add_To_Buffer((uint16_t)Rawdata[4][0],&(forehead_buffer.temp));
}
Exemplo n.º 3
0
/**
  * @brief  This function generates a device to base station packet, uses a reverse COBS format that requires working backwards from end of packet
  * @param  Pointer to output buffer, pointer to input data, number of data bytes, device ID on the network, pointer to sequence number (iterates)
  * @retval None
  */
void RN42_generate_packet(uint8_t* data_payload, uint8_t number_bytes, uint8_t device_network_id, uint8_t* sequence_number) {
	const uint8_t header=HEAD;
	Add_To_Buffer(&header,&Usart1_tx_buff);
	Add_To_Buffer(&device_network_id,&Usart1_tx_buff);//Packet header consists of device network id byte and sequence number (for scrolling graph smoothness)
	Add_To_Buffer(sequence_number,&Usart1_tx_buff);//This is similar to HDLC packet format
	uint8_t skip=1;
	for(uint8_t n=0; n<number_bytes; n++) {
		if(data_payload[n]==HEAD) {
			__usart_send_char(skip);	//The send_char routine is used here as it will kick start the interrupt driven usart comms if needs be
			skip=1;
		}
		else {
			skip++;
			__usart_send_char(data_payload[n]);
		}
	}
	__usart_send_char(skip);			//Work backwards from the end of the packet, skipping skip bytes and replacing with HEAD until packet header
	*sequence_number++;				//Incriment this
}