Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 {
27  uint8_t i;
28  for (i = 0; i < ENOSE_NB_SENSOR; i++) {
30  enose_val[i] = 0;
31  }
35 
36 #ifdef ADC_CHANNEL_PID
37  adc_buf_channel(ADC_CHANNEL_PID, &buf_PID, ADC_CHANNEL_PID_NB_SAMPLES);
38 #endif
39 }
40 
41 
43 {
44  enose_heat[no_sensor] = value;
46 }
47 
48 
49 #include "mcu_periph/uart.h"
50 #include "messages.h"
52 
53 void enose_periodic(void)
54 {
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  } else if (enose_status == ENOSE_IDLE) {
66  const uint8_t msg[] = { ENOSE_DATA_ADDR };
67  memcpy((void *)i2c0_buf, msg, sizeof(msg));
68  i2c0_transmit(ENOSE_SLAVE_ADDR, sizeof(msg), &enose_i2c_done);
70  } else if (enose_status == ENOSE_MEASURING_WR) {
72  i2c0_receive(ENOSE_SLAVE_ADDR, 6, &enose_i2c_done);
74  } else if (enose_status == ENOSE_MEASURING_RD) {
75  uint16_t val = (i2c0_buf[0] << 8) | i2c0_buf[1];
76  if (val < 5000) {
77  enose_val[0] = val;
78  }
79  val = (i2c0_buf[2] << 8) | i2c0_buf[3];
80  if (val < 5000) {
81  enose_val[1] = val;
82  }
83  val = (i2c0_buf[4] << 8) | i2c0_buf[5];
84  if (val < 5000) {
85  enose_val[2] = val;
86  }
88  }
89  }
90  DOWNLINK_SEND_ENOSE_STATUS(DefaultChannel, DefaultDevice, &enose_val[0], &enose_val[1], &enose_val[2], &enose_PID_val,
91  3, enose_heat);
92 }
uint8_t av_nb_sample
Definition: adc.h:57
unsigned short uint16_t
Definition: types.h:16
void enose_periodic(void)
Definition: enose.c:53
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:42
#define ENOSE_HEAT_INIT
Definition: enose.c:18
uint16_t value
Definition: adc_arch.c:586
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:15
uint32_t sum
Definition: adc.h:54
arch independent ADC (Analog to Digital Converter) API
#define FALSE
Definition: std.h:5
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
#define TRUE
Definition: std.h:4
void enose_init(void)
Definition: enose.c:25
uint16_t val[TCOUPLE_NB]
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
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:91
#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:6
uint8_t enose_heat[ENOSE_NB_SENSOR]
Definition: enose.c:11
#define ENOSE_IDLE
Definition: enose.h:12
static volatile bool_t enose_i2c_done
Definition: enose.c:21
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
#define ENOSE_MEASURING_WR
Definition: enose.h:14
Architecture independent I2C (Inter-Integrated Circuit Bus) API.