Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
servos_4017_hw.h
Go to the documentation of this file.
1 #ifndef SERVOS_4017_HW_H
2 #define SERVOS_4017_HW_H
3 
4 #include <inttypes.h>
5 #include "std.h"
6 
7 #include "LPC21xx.h"
8 #include "mcu_periph/sys_time.h"
9 
10 #include BOARD_CONFIG
11 
12 #define SERVOS_TICS_OF_USEC(s) CPU_TICKS_OF_USEC(s)
13 #define ChopServo(x,a,b) Chop(x, a, b)
14 
15 #if defined NB_CHANNELS
16 #define _4017_NB_CHANNELS Chop(NB_CHANNELS,0,10)
17 #else
18 #define _4017_NB_CHANNELS 10
19 #endif
20 
22 #define Actuator(i) servos_values[i]
23 
24 #define ActuatorsCommit() {}
25 
27 
28 #define ACTUATORS_IT TIR_MR1I
29 
30 #ifndef SERVOS_4017_CLOCK_FALLING
31 #define SERVOS_4017_ISR() { \
32  if (servos_4017_idx >= _4017_NB_CHANNELS) { \
33  SetBit(IO1SET, SERVO_RESET_PIN); \
34  servos_4017_idx = 0; \
35  SetBit(IO1CLR, SERVO_RESET_PIN); \
36  } \
37  \
38  /* request clock high on next match */ \
39  T0MR1 += servos_values[servos_4017_idx]; \
40  /* lower clock pin */ \
41  T0EMR &= ~TEMR_EM1; \
42  servos_4017_idx++; \
43  }
44 #else /* SERVOS_4017_CLOCK_FALLING */
45 
46 #define SERVOS_4017_RESET_WIDTH SERVOS_TICS_OF_USEC(1000)
47 #define SERVOS_4017_FIRST_PULSE_WIDTH SERVOS_TICS_OF_USEC(100)
48 
49 #define SERVOS_4017_ISR() { \
50  if (servos_4017_idx == _4017_NB_CHANNELS) { \
51  SetBit(IO1SET, SERVO_RESET_PIN); \
52  /* Start a long 1ms reset, keep clock low */ \
53  T0MR1 += SERVOS_4017_RESET_WIDTH; \
54  servos_4017_idx++; \
55  T0EMR &= ~TEMR_EM1; \
56  } \
57  else if (servos_4017_idx > _4017_NB_CHANNELS) { \
58  /* Clear the reset*/ \
59  SetBit(IO1CLR,SERVO_RESET_PIN); \
60  /* assert clock */ \
61  T0EMR |= TEMR_EM1; \
62  /* Starts a short pulse-like period */ \
63  T0MR1 += SERVOS_4017_FIRST_PULSE_WIDTH; \
64  servos_4017_idx=0; \
65  } \
66  else { \
67  /* request next match */ \
68  T0MR1 += servos_values[servos_4017_idx]; \
69  /* clock low if not last one, last is done with reset */ \
70  if (servos_4017_idx != _4017_NB_CHANNELS-1) { \
71  /* raise clock pin */ \
72  T0EMR |= TEMR_EM1; \
73  } \
74  servos_4017_idx++; \
75  } \
76  }
77 #endif /* SERVOS_4017_CLOCK_ON_RESET */
78 
79 #endif /* SERVOS_4017_HW_H */
unsigned short uint16_t
Definition: types.h:16
uint8_t servos_4017_idx
Definition: servos_4017_hw.c:6
Architecture independent timing functions.
uint16_t servos_values[_4017_NB_CHANNELS]
Definition: servos_4015_hw.c:8
#define _4017_NB_CHANNELS
unsigned char uint8_t
Definition: types.h:14