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
i2c_abuse_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Christophe De Wagter
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
35 #include "i2c_abuse_test.h"
36 #include "led.h"
37 #include "mcu_periph/i2c.h"
38 
41 
44 
45 void init_i2c_abuse_test(void) {
46  //LED_INIT(DEMO_MODULE_LED);
47  //LED_OFF(DEMO_MODULE_LED);
48 
50  i2c_test1.slave_addr = 0x3C;
51 
53  i2c_abuse_test_bitrate = 10000;
54 
56 
57 }
58 
60 {
61 
62  i2c_test1.slave_addr = 0x3C;
63  i2c_test1.len_w = 0;
64  i2c_test1.len_r = 0;
65 
66  switch (_init)
67  {
68  case 1:
70  i2c_test1.buf[0] = 0x00; // set to rate to 50Hz
71  i2c_test1.buf[1] = 0x00 | (0x06 << 2);
72  i2c_test1.buf[2] = 0x01<<5;
73  i2c_test1.buf[3] = 0x00;
74  i2c_test1.len_w = 4;
75  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
76  break;
77  case 2:
79  i2c_test1.buf[0] = 0x01; // set to gain to 1 Gauss
80  i2c_test1.buf[1] = 0x01<<5;
81  i2c_test1.len_w = 2;
82  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
83  break;
84  case 3:
86  i2c_test1.buf[0] = 0x00; // set to continuous mode
87  i2c_test1.len_w = 1;
88  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
89  break;
90  case 4:
92  i2c_test1.len_r = 1;
93  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
94  break;
95  case 5:
97  i2c_test1.len_r = 2;
98  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
99  break;
100  case 6:
102  i2c_test1.len_r = 3;
103  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
104  break;
105  case 7:
107  i2c_test1.len_r = 4;
108  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
109  break;
110  case 8:
112  i2c_test1.len_r = 5;
113  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
114  break;
115  case 9:
116  // bad addr
117  i2c_test1.slave_addr = 0x3C + 2;
119  i2c_test1.len_w = 1;
120  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
121  break;
122  case 10:
123  // 2 consecutive
125  i2c_test1.buf[0] = 0x00; // set to continuous mode
126  i2c_test1.len_w = 1;
127  i2c_submit(&I2C_ABUSE_PORT,&i2c_test1);
128  break;
129  case 11:
130  i2c_test1.slave_addr = 0x3C;
132  i2c_test1.len_r = 1;
133  i2c_test1.len_w = 1;
134  i2c_test1.buf[0] = 0x03;
135  i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
136  break;
137  case 12:
138  i2c_test1.slave_addr = 0x3C;
140  i2c_test1.len_r = 2;
141  i2c_test1.len_w = 1;
142  i2c_test1.buf[0] = 0x03;
143  i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
144  break;
145  case 13:
146  i2c_test1.slave_addr = 0x3C;
148  i2c_test1.len_r = 3;
149  i2c_test1.len_w = 1;
150  i2c_test1.buf[0] = 0x03;
151  i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
152  break;
153  case 14:
154  i2c_test1.slave_addr = 0x3C;
156  i2c_test1.len_r = 4;
157  i2c_test1.len_w = 1;
158  i2c_test1.buf[0] = 0x03;
159  i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
160  break;
161  case 15:
162  i2c_test1.slave_addr = 0x3C;
164  i2c_test1.len_r = 4;
165  i2c_test1.len_w = 2;
166  i2c_test1.buf[0] = 0x03;
167  i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
168  break;
169  default:
170  i2c_test1.slave_addr = 0x3C;
172  i2c_test1.len_r = 5;
173  i2c_test1.len_w = 1;
174  i2c_test1.buf[0] = 0x03;
175  i2c_submit(&I2C_ABUSE_PORT, &i2c_test1);
176  }
177 }
178 
179 
181 {
182  if (i2c_idle(&I2C_ABUSE_PORT))
183  {
184  LED_ON(5); // green = idle
185  LED_OFF(4);
186  }
187  else
188  {
189  LED_ON(4); // red = busy
190  LED_OFF(5);
191  }
192 
193  // Wait for I2C transaction object to be released by the I2C driver before changing anything
195  {
197  {
198  //i2c_test2.slave_addr = 0x90;
200  i2c_test2.slave_addr = 0x92;
201  i2c_test2.len_r = 2;
202  i2c_submit(&I2C_ABUSE_PORT,&i2c_test2);
203  }
204  }
205 
206 
208  {
209  if (i2c_abuse_test_counter < 16)
210  {
212  }
213  else
214  {
215  // wait until ready:
216  if (i2c_idle(&I2C_ABUSE_PORT))
217  {
219 
220  i2c_setbitrate(&I2C_ABUSE_PORT, i2c_abuse_test_bitrate);
221 
222  i2c_abuse_test_bitrate += 17000;
223  if (i2c_abuse_test_bitrate > 410000)
224  {
225  i2c_abuse_test_bitrate -= 410000;
226  }
227  }
228  }
229 
230  if (i2c_abuse_test_counter < 16)
231  {
232  RunOnceEvery(100,LED_TOGGLE(I2C_ABUSE_LED));
234  }
235  }
236 }
237 
239 }
240 
241 
242 
static void i2c_abuse_send_transaction(uint8_t _init)
struct i2c_transaction i2c_test1
bool_t i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Definition: i2c_arch.c:333
Total I2C Abuse:
struct i2c_transaction i2c_test2
void periodic_50Hz_i2c_abuse_test(void)
#define LED_ON(i)
Definition: led_hw.h:28
void init_i2c_abuse_test(void)
void i2c_setbitrate(struct i2c_periph *p, int bitrate)
Definition: i2c_arch.c:366
uint8_t slave_addr
Definition: i2c.h:79
volatile uint8_t i2c_abuse_test_counter
void event_i2c_abuse_test(void)
unsigned long uint32_t
Definition: types.h:18
enum I2CTransactionStatus status
Definition: i2c.h:83
#define LED_TOGGLE(i)
Definition: led_hw.h:30
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
uint8_t len_w
Definition: i2c.h:81
uint16_t len_r
Definition: i2c.h:80
unsigned char uint8_t
Definition: types.h:14
Definition: i2c.h:45
enum I2CTransactionType type
Definition: i2c.h:78
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
Definition: i2c.h:46
volatile uint32_t i2c_abuse_test_bitrate
bool_t i2c_idle(struct i2c_periph *p)
Definition: i2c_arch.c:329
Architecture independent I2C (Inter-Integrated Circuit Bus) API.