Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
enose.c
Go to the documentation of this file.
1 #include <string.h>
2 
3 #include "modules/enose/enose.h"
4 
5 #include "mcu_periph/i2c.h"
6 #include "mcu_periph/adc.h"
7 #include BOARD_CONFIG
8 
9 
14 
15 #define ENOSE_SLAVE_ADDR 0xAE
16 #define ENOSE_PWM_ADDR 0x06
17 #define ENOSE_DATA_ADDR 0x00
18 #define ENOSE_HEAT_INIT 237
19 
21 static volatile bool_t enose_i2c_done;
22 static struct adc_buf buf_PID;
23 
24 
25 void enose_init( void ) {
26  uint8_t i;
27  for (i=0; i< ENOSE_NB_SENSOR; i++) {
29  enose_val[i] = 0;
30  }
34 
35 #ifdef ADC_CHANNEL_PID
36  adc_buf_channel(ADC_CHANNEL_PID, &buf_PID, ADC_CHANNEL_PID_NB_SAMPLES);
37 #endif
38 }
39 
40 
41 void enose_set_heat(uint8_t no_sensor, uint8_t value) {
42  enose_heat[no_sensor] = value;
44 }
45 
46 
47 #ifndef DOWNLINK_DEVICE
48 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
49 #endif
50 #include "mcu_periph/uart.h"
51 #include "messages.h"
53 
54 void enose_periodic( void ) {
56 
57  if (enose_i2c_done) {
59  const uint8_t msg[] = { ENOSE_PWM_ADDR, enose_heat[0], enose_heat[1], enose_heat[2] };
60  memcpy((void*)i2c0_buf, msg, sizeof(msg));
61  i2c0_transmit(ENOSE_SLAVE_ADDR, sizeof(msg), &enose_i2c_done);
64  }
65  else if (enose_status == ENOSE_IDLE) {
67  const uint8_t msg[] = { ENOSE_DATA_ADDR };
68  memcpy((void*)i2c0_buf, msg, sizeof(msg));
69  i2c0_transmit(ENOSE_SLAVE_ADDR, sizeof(msg), &enose_i2c_done);
71  }
72  else if (enose_status == ENOSE_MEASURING_WR) {
74  i2c0_receive(ENOSE_SLAVE_ADDR, 6, &enose_i2c_done);
76  }
77  else if (enose_status == ENOSE_MEASURING_RD) {
78  uint16_t val = (i2c0_buf[0]<<8) | i2c0_buf[1];
79  if (val < 5000)
80  enose_val[0] = val;
81  val = (i2c0_buf[2]<<8) | i2c0_buf[3];
82  if (val < 5000)
83  enose_val[1] = val;
84  val = (i2c0_buf[4]<<8) | i2c0_buf[5];
85  if (val < 5000)
86  enose_val[2] = val;
88  }
89  }
90  DOWNLINK_SEND_ENOSE_STATUS(DefaultChannel, DefaultDevice,&enose_val[0], &enose_val[1], &enose_val[2], &enose_PID_val, 3, enose_heat);
91 }
unsigned short uint16_t
Definition: types.h:16
void enose_periodic(void)
Definition: enose.c:54
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define ENOSE_SLAVE_ADDR
Definition: enose.c:15
void enose_set_heat(uint8_t no_sensor, uint8_t value)
Definition: enose.c:41
#define ENOSE_HEAT_INIT
Definition: enose.c:18
uint16_t value
ADC1+2 interrupt hander.
Definition: adc_arch.c:577
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:59
static struct adc_buf buf_PID
Definition: enose.c:22
uint16_t enose_val[ENOSE_NB_SENSOR]
Definition: enose.c:12
#define ENOSE_MEASURING_RD
Definition: enose.h:22
uint8_t av_nb_sample
Definition: adc.h:64
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
#define FALSE
Definition: imu_chimu.h:141
void enose_init(void)
Definition: enose.c:25
uint16_t val[TCOUPLE_NB]
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
uint8_t enose_status
Definition: enose.c:10
#define ENOSE_DATA_ADDR
Definition: enose.c:17
static uint8_t enose_conf_requested
Definition: enose.c:20
#define TRUE
Definition: imu_chimu.h:144
#define ENOSE_PWM_ADDR
Definition: enose.c:16
uint16_t enose_PID_val
Definition: enose.c:13
unsigned char uint8_t
Definition: types.h:14
#define ENOSE_NB_SENSOR
Definition: enose.h:13
uint8_t enose_heat[ENOSE_NB_SENSOR]
Definition: enose.c:11
#define ENOSE_IDLE
Definition: enose.h:19
static volatile bool_t enose_i2c_done
Definition: enose.c:21
#define ENOSE_MEASURING_WR
Definition: enose.h:21
Architecture independent I2C (Inter-Integrated Circuit Bus) API.