Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces 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
46{
47 //LED_INIT(DEMO_MODULE_LED);
48 //LED_OFF(DEMO_MODULE_LED);
49
51 i2c_test1.slave_addr = 0x3C;
52
55
57
58}
59
61{
62
63 i2c_test1.slave_addr = 0x3C;
64 i2c_test1.len_w = 0;
65 i2c_test1.len_r = 0;
66
67 switch (_init) {
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;
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;
83 break;
84 case 3:
86 i2c_test1.buf[0] = 0x00; // set to continuous mode
87 i2c_test1.len_w = 1;
89 break;
90 case 4:
92 i2c_test1.len_r = 1;
94 break;
95 case 5:
97 i2c_test1.len_r = 2;
99 break;
100 case 6:
102 i2c_test1.len_r = 3;
104 break;
105 case 7:
107 i2c_test1.len_r = 4;
109 break;
110 case 8:
112 i2c_test1.len_r = 5;
114 break;
115 case 9:
116 // bad addr
117 i2c_test1.slave_addr = 0x3C + 2;
119 i2c_test1.len_w = 1;
121 break;
122 case 10:
123 // 2 consecutive
125 i2c_test1.buf[0] = 0x00; // set to continuous mode
126 i2c_test1.len_w = 1;
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;
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;
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;
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;
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;
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;
176 }
177}
178
179
181{
182 if (i2c_idle(&I2C_ABUSE_PORT)) {
183 LED_ON(5); // green = idle
184 LED_OFF(4);
185 } else {
186 LED_ON(4); // red = busy
187 LED_OFF(5);
188 }
189
190 // Wait for I2C transaction object to be released by the I2C driver before changing anything
193 //i2c_test2.slave_addr = 0x90;
195 i2c_test2.slave_addr = 0x92;
196 i2c_test2.len_r = 2;
198 }
199 }
200
201
203 if (i2c_abuse_test_counter < 16) {
205 } else {
206 // wait until ready:
207 if (i2c_idle(&I2C_ABUSE_PORT)) {
209
211
212 i2c_abuse_test_bitrate += 17000;
213 if (i2c_abuse_test_bitrate > 410000) {
214 i2c_abuse_test_bitrate -= 410000;
215 }
216 }
217 }
218
219 if (i2c_abuse_test_counter < 16) {
222 }
223 }
224}
225
227{
228}
229
230
231
#define LED_ON(i)
Definition led_hw.h:51
#define LED_OFF(i)
Definition led_hw.h:52
#define LED_TOGGLE(i)
Definition led_hw.h:53
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:122
uint16_t len_r
Number of bytes to read/receive.
Definition i2c.h:110
enum I2CTransactionType type
Transaction type.
Definition i2c.h:98
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:126
uint8_t slave_addr
Slave address.
Definition i2c.h:104
uint8_t len_w
Number of bytes to write/transmit.
Definition i2c.h:116
static bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
Definition i2c.h:266
static bool i2c_idle(struct i2c_periph *p)
Check if I2C bus is idle.
Definition i2c.h:256
static void i2c_setbitrate(struct i2c_periph *p, int bitrate)
Set I2C bitrate.
Definition i2c.h:274
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:57
@ I2CTransFailed
transaction failed
Definition i2c.h:58
@ I2CTransRx
receive only transaction
Definition i2c.h:48
@ I2CTransTx
transmit only transaction
Definition i2c.h:47
@ I2CTransTxRx
transmit and receive transaction
Definition i2c.h:49
I2C transaction structure.
Definition i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
void init_i2c_abuse_test(void)
void periodic_50Hz_i2c_abuse_test(void)
volatile uint32_t i2c_abuse_test_bitrate
struct i2c_transaction i2c_test1
void event_i2c_abuse_test(void)
static void i2c_abuse_send_transaction(uint8_t _init)
struct i2c_transaction i2c_test2
volatile uint8_t i2c_abuse_test_counter
Total I2C Abuse:
arch independent LED (Light Emitting Diodes) API
uint16_t foo
Definition main_demo5.c:58
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.