Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MPPT.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2009 ENAC, Pascal Brisset, Michel Gorraz
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
25 
26 #include <stdbool.h>
27 #include "MPPT.h"
29 #include "mcu_periph/i2c.h"
30 
31 
32 #define MPPT_SLAVE_ADDR 0x40
33 #define NB_I2C_DATA 8
34 #define MPPT_MODE_ADDR 0xf
35 
37 
53 #ifndef DOWNLINK_DEVICE
54 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
55 #endif
56 #include "mcu_periph/uart.h"
57 #include "messages.h"
59 
64 #define MPPT_STATUS_IDLE 0
65 #define MPPT_STATUS_WRITING 1
66 #define MPPT_STATUS_ASKING 2
67 #define MPPT_STATUS_READING 3
68 
69 
70 static uint8_t data_index = 0xff;
72 
73 void MPPT_init( void ) {
74  MPPT_mode = 0;
76 }
77 
78 
79 static void MPPT_ask( void ) {
80  data_index++;
81  if (data_index >= NB_I2C_DATA) {
82  /* Setting the current value */
83  fbw_current_milliamp = MPPT_data[MPPT_IBAT_INDEX];
84 
86  DOWNLINK_SEND_MPPT(DefaultChannel, DefaultDevice, NB_DATA, MPPT_data);
87  data_index = 0;
88  }
89 
93 }
94 
95 void MPPT_periodic( void ) {
96 
98  switch (MPPT_status) {
99  case MPPT_STATUS_IDLE:
100  /* If free, change mode if needed */
101  if (MPPT_mode) {
103  mppt_trans.buf[1] = 0;
104  mppt_trans.buf[2] = MPPT_mode;
106  MPPT_mode = 0;
108  } else {
109  MPPT_ask();
110  }
111  break;
112 
113  case MPPT_STATUS_WRITING:
115  break;
116 
117  case MPPT_STATUS_ASKING:
118  /* The slave should send 2 bytes */
121  break;
122 
123  case MPPT_STATUS_READING:
124  /* We got 2 bytes */
125  if (data_index < NB_I2C_DATA)
128  break;
129  }
130  }
131 }
FBW ( FlyByWire ) process API.
#define MPPT_MODE_ADDR
Definition: MPPT.c:34
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void MPPT_periodic(void)
Definition: MPPT.c:95
#define MPPT_ITOTAL_INDEX
Definition: MPPT.h:42
#define I2CReceive(_p, _t, _s_addr, _len)
Definition: i2c.h:140
static int16_t MPPT_data[NB_DATA]
Definition: MPPT.c:71
#define MPPT_STATUS_ASKING
Definition: MPPT.c:66
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
#define NB_I2C_DATA
Definition: MPPT.c:33
#define MPPT_IBAT_INDEX
Definition: MPPT.h:40
uint8_t MPPT_mode
Definition: MPPT.c:60
#define MPPT_ICONV_INDEX
Definition: MPPT.h:41
static void MPPT_ask(void)
Definition: MPPT.c:79
signed short int16_t
Definition: types.h:17
enum I2CTransactionStatus status
Definition: i2c.h:47
#define MPPT_SLAVE_ADDR
Definition: MPPT.c:32
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
unsigned char uint8_t
Definition: types.h:14
struct i2c_transaction mppt_trans
Definition: MPPT.c:36
#define NB_DATA
Definition: generic_com.c:38
void MPPT_init(void)
Definition: MPPT.c:73
#define MPPT_STATUS_READING
Definition: MPPT.c:67
#define MPPT_STATUS_WRITING
Definition: MPPT.c:65
static uint8_t MPPT_status
A value different from 0 is a request from this mode.
Definition: MPPT.c:63
#define MPPT_STATUS_IDLE
Definition: MPPT.c:64
static uint8_t data_index
Definition: MPPT.c:70