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
lisa_test_sc18is600.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
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 #include <stm32/gpio.h>
25 #include <stm32/flash.h>
26 #include <stm32/misc.h>
27 
28 #include BOARD_CONFIG
29 #include "mcu.h"
30 #include "mcu_periph/sys_time.h"
32 #include "peripherals/sc18is600.h"
33 #include "led.h"
34 
35 static inline void main_init( void );
36 static inline void main_periodic_task( void );
37 static inline void main_event_task( void );
38 
39 static inline void main_spi2_init(void);
40 
41 int main(void) {
42  main_init();
43 
44  while(1) {
48  }
49 
50  return 0;
51 }
52 
53 
54 static inline void main_init( void ) {
55  mcu_init();
59 }
60 
61 static inline void main_periodic_task( void ) {
62  // LED_TOGGLE(6);
63  RunOnceEvery(10,
64  {
65  DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
66  LED_PERIODIC();
67  });
68 
69  static uint8_t foo=0;
70  switch (foo) {
71  case 2:
72  /* set I2C clock to 400khz */
74  break;
75  case 3:
76  /* read it back, just to check */
78  break;
79  case 4:
80  /* set gyro range to 2000deg/s : write 0x03 to register at addr 0x16 */
81  sc18is600.priv_tx_buf[3] = 0x16;
82  sc18is600.priv_tx_buf[4] = 0x03;
83  sc18is600_transmit(0xD0, 2);
84  break;
85  case 5:
86  /* reads 8 bytes from address 0x1b */
87  sc18is600.priv_tx_buf[4] = 0x1b;
88  sc18is600_tranceive(0xD0, 1, 8);
89  break;
90  }
91 
92  if (foo< 5) foo++;
93 
94 }
95 
96 static inline void main_event_task( void ) {
97 
98 }
99 
100 
101 static inline void main_spi2_init( void ) {
102 
103  /* set mag ss as output and assert it (on PC12) ------------------------------*/
104  /* set mag reset as output and assert it (on PC13) ------------------------------*/
105  /* set eeprom ss as output and assert it (on PC14) ------------------------------*/
106  GPIOC->BSRR = GPIO_Pin_12;
107  GPIOC->BSRR = GPIO_Pin_13;
108  GPIOC->BSRR = GPIO_Pin_14;
109 
110  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
111  GPIO_InitTypeDef GPIO_InitStructure;
112  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13|GPIO_Pin_14;
113  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
114  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
115  GPIO_Init(GPIOC, &GPIO_InitStructure);
116 
117 }
118 
void sc18is600_transmit(uint8_t addr, uint8_t len)
uint8_t priv_tx_buf[SC18IS600_BUF_LEN]
Definition: sc18i600.h:36
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
void sc18is600_write_to_register(uint8_t addr, uint8_t value)
Architecture independent timing functions.
static void main_spi2_init(void)
uint16_t foo
Definition: main_demo5.c:54
static void main_init(void)
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:35
static bool_t sys_time_check_and_ack_timer(tid_t id)
Definition: sys_time.h:90
void sc18is600_init(void)
Definition: sc18i600.c:5
struct Sc18Is600 sc18is600
Definition: sc18i600.c:3
#define LED_PERIODIC()
Definition: led_hw.h:8
arch independent mcu ( Micro Controller Unit ) utilities
static void main_event_task(void)
int main(void)
#define Sc18Is600_I2CClock
Definition: sc18i600.h:9
unsigned char uint8_t
Definition: types.h:14
void sc18is600_read_from_register(uint8_t addr)
void sc18is600_tranceive(uint8_t addr, uint8_t len_tx, uint8_t len_rx)
arch independent LED (Light Emitting Diodes) API
static void main_periodic_task(void)
void mcu_init(void)
Definition: mcu.c:57