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
ms2100_arch.h
Go to the documentation of this file.
1 #ifndef MS2100_ARCH_H
2 #define MS2100_ARCH_H
3 
4 #include <stdlib.h> // for abs
5 
6 #include "std.h"
7 #include "LPC21xx.h"
8 #include "interrupt_hw.h"
9 
10 #include "ssp_hw.h"
11 #include BOARD_CONFIG
12 
13 #include "generated/airframe.h"
14 
15 
16 
17 extern volatile uint8_t ms2100_cur_axe;
18 
19 #define Ms2100Select() SetBit(MS2100_SS_IOCLR,MS2100_SS_PIN)
20 #define Ms2100Unselect() SetBit(MS2100_SS_IOSET,MS2100_SS_PIN)
21 
22 #define Ms2100Reset() SetBit(MS2100_RESET_IOCLR,MS2100_RESET_PIN)
23 #define Ms2100Set() SetBit(MS2100_RESET_IOSET,MS2100_RESET_PIN)
24 
25 #define Ms2100OnSpiInt() { \
26  switch (ms2100_status) { \
27  case MS2100_SENDING_REQ: \
28  { \
29  /* read dummy control byte reply */ \
30  uint8_t foo __attribute__ ((unused)) = SSPDR; \
31  ms2100_status = MS2100_WAITING_EOC; \
32  Ms2100Unselect(); \
33  SSP_ClearRti(); \
34  SSP_DisableRti(); \
35  SSP_Disable(); \
36  } \
37  break; \
38  case MS2100_READING_RES: \
39  { \
40  int16_t new_val; \
41  new_val = SSPDR << 8; \
42  new_val += SSPDR; \
43  if (abs(new_val) < 2000) \
44  ms2100_values[ms2100_cur_axe] = new_val; \
45  Ms2100Unselect(); \
46  SSP_ClearRti(); \
47  SSP_DisableRti(); \
48  SSP_Disable(); \
49  ms2100_cur_axe++; \
50  if (ms2100_cur_axe > 2) { \
51  ms2100_cur_axe = 0; \
52  ms2100_status = MS2100_DATA_AVAILABLE; \
53  } \
54  else \
55  ms2100_status = MS2100_IDLE; \
56  } \
57  break; \
58  } \
59  }
60 
61 
62 #define Ms2100SendReq() { \
63  Ms2100Select(); \
64  ms2100_status = MS2100_SENDING_REQ; \
65  Ms2100Set(); \
66  SSP_ClearRti(); \
67  SSP_EnableRti(); \
68  Ms2100Reset(); \
69  uint8_t control_byte = (ms2100_cur_axe+1) << 0 | \
70  MS2100_DIVISOR << 4; \
71  SSP_Send(control_byte); \
72  SSP_Enable(); \
73  }
74 
75 #define Ms2100ReadRes() { \
76  ms2100_status = MS2100_READING_RES; \
77  Ms2100Select(); \
78  /* trigger 2 bytes read */ \
79  SSP_Send(0); \
80  SSP_Send(0); \
81  SSP_Enable(); \
82  SSP_ClearRti(); \
83  SSP_EnableRti(); \
84  }
85 
86 
87 
88 #endif /* MS2100_ARCH_H */
volatile uint8_t ms2100_cur_axe
Definition: ms2100_arch.c:11
unsigned char uint8_t
Definition: types.h:14