Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
servos_4017_hw.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 ENAC
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 
23 #ifndef SERVOS_4017_HW_H
24 #define SERVOS_4017_HW_H
25 
26 #include <inttypes.h>
27 #include "std.h"
28 
29 #include "LPC21xx.h"
30 #include "mcu_periph/sys_time.h"
31 
32 #include BOARD_CONFIG
33 
34 #define SERVOS_TICS_OF_USEC(s) cpu_ticks_of_usec(s)
35 #define ChopServo(x,a,b) Chop(x, a, b)
36 
37 #if defined NB_CHANNELS
38 #define _4017_NB_CHANNELS Chop(NB_CHANNELS,0,10)
39 #else
40 #define _4017_NB_CHANNELS 10
41 #endif
42 
44 #define Actuator4017Set(_i, _v) { servos_values[_i] = SERVOS_TICS_OF_USEC(_v); }
45 
46 extern void actuators_4017_init(void);
47 #define Actuators4017Commit() {}
48 #define Actuators4017Init() actuators_4017_init()
49 
51 
52 #define ACTUATORS_IT TIR_MR1I
53 
54 #ifndef SERVOS_4017_CLOCK_FALLING
55 #define SERVOS_4017_ISR() { \
56  if (servos_4017_idx >= _4017_NB_CHANNELS) { \
57  SetBit(IO1SET, SERVO_RESET_PIN); \
58  servos_4017_idx = 0; \
59  SetBit(IO1CLR, SERVO_RESET_PIN); \
60  } \
61  \
62  /* request clock high on next match */ \
63  T0MR1 += servos_values[servos_4017_idx]; \
64  /* lower clock pin */ \
65  T0EMR &= ~TEMR_EM1; \
66  servos_4017_idx++; \
67  }
68 #else /* SERVOS_4017_CLOCK_FALLING */
69 
70 #define SERVOS_4017_RESET_WIDTH SERVOS_TICS_OF_USEC(1000)
71 #define SERVOS_4017_FIRST_PULSE_WIDTH SERVOS_TICS_OF_USEC(100)
72 
73 #define SERVOS_4017_ISR() { \
74  if (servos_4017_idx == _4017_NB_CHANNELS) { \
75  SetBit(IO1SET, SERVO_RESET_PIN); \
76  /* Start a long 1ms reset, keep clock low */ \
77  T0MR1 += SERVOS_4017_RESET_WIDTH; \
78  servos_4017_idx++; \
79  T0EMR &= ~TEMR_EM1; \
80  } \
81  else if (servos_4017_idx > _4017_NB_CHANNELS) { \
82  /* Clear the reset*/ \
83  SetBit(IO1CLR,SERVO_RESET_PIN); \
84  /* assert clock */ \
85  T0EMR |= TEMR_EM1; \
86  /* Starts a short pulse-like period */ \
87  T0MR1 += SERVOS_4017_FIRST_PULSE_WIDTH; \
88  servos_4017_idx=0; \
89  } \
90  else { \
91  /* request next match */ \
92  T0MR1 += servos_values[servos_4017_idx]; \
93  /* clock low if not last one, last is done with reset */ \
94  if (servos_4017_idx != _4017_NB_CHANNELS-1) { \
95  /* raise clock pin */ \
96  T0EMR |= TEMR_EM1; \
97  } \
98  servos_4017_idx++; \
99  } \
100  }
101 #endif /* SERVOS_4017_CLOCK_ON_RESET */
102 
103 #endif /* SERVOS_4017_HW_H */
unsigned short uint16_t
Definition: types.h:16
void actuators_4017_init(void)
Architecture independent timing functions.
uint16_t servos_values[_4017_NB_CHANNELS]
unsigned char uint8_t
Definition: types.h:14
#define _4017_NB_CHANNELS
uint8_t servos_4017_idx