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