Blame view

Project/os/hal/platforms/AT91SAM7/ext_lld.h 7.26 KB
Imanol-Mikel Barba Sabariego authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
    ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
                 2011,2012 Giovanni Di Sirio.

    This file is part of ChibiOS/RT.

    ChibiOS/RT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    ChibiOS/RT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

                                      ---

    A special exception to the GPL can be applied should you wish to distribute
    a combined work that includes ChibiOS/RT, without being obliged to provide
    the source code for any proprietary components. See the file exception.txt
    for full details of how and when the exception can be applied.
*/

/**
 * @file    AT91SAM7/ext_lld.h
 * @brief   AT91SAM7 EXT subsystem low level driver header.
 *
 * @addtogroup EXT
 * @{
 */

#ifndef _EXT_LLD_H_
#define _EXT_LLD_H_

#if HAL_USE_EXT || defined(__DOXYGEN__)

/*===========================================================================*/
/* Driver constants.                                                         */
/*===========================================================================*/

/**
 * @brief    Pointer to the SAM7 AIC register block.
 */
#define SAM7_EXT_AIC    ((AT91PS_AIC *)AT91C_BASE_AIC)

/**
 * @brief    Number of channels within one ext driver.
 */
#define    EXT_MAX_CHANNELS            32

/**
 * @brief    Mask of priority bits in interrupt mode register.
 */
#define SAM7_EXT_PRIORITY_MASK        0x00000007

/**
 * @brief    Shifter for priority bits in interrupt mode register.
 */
#define SAM7_EXT_PRIORITY_SHIFTER    0

/**
 * @brief    Shifter for mode bits in interrupt mode register.
 */
#define SAM7_EXT_MODE_SHIFTER        5

/*
 * On the SAM7 architecture, a single channel can only be enables or disabled
 * Hence, undefine the other channel mode constants
 */
#ifdef EXT_CH_MODE_RISING_EDGE
#undef EXT_CH_MODE_RISING_EDGE
#endif

#ifdef EXT_CH_MODE_FALLING_EDGE
#undef EXT_CH_MODE_FALLING_EDGE
#endif

#ifdef EXT_CH_MODE_BOTH_EDGES
#undef EXT_CH_MODE_BOTH_EDGES
#endif

/**
 * @name    EXT channels mode
 * @{
 */
#define EXT_CH_MODE_ENABLED            1        /**< @brief Channel is enabled. */
/** @} */

/**
 * @name    EXT drivers mode
 * @{
 */
/**
 * @brief   Mask for modes.
 */
#define SAM7_EXT_MODE_MASK            AT91C_AIC_SRCTYPE
/**
 * @brief   Falling edge callback.
 */
#define SAM7_EXT_MODE_FALLING_EDGE    AT91C_AIC_SRCTYPE_EXT_NEGATIVE_EDGE
/**
 * @brief   Rising edge callback.
 */
#define SAM7_EXT_MODE_RISING_EDGE    AT91C_AIC_SRCTYPE_POSITIVE_EDGE
/**
 * @brief   High-level callback.
 */
#define SAM7_EXT_MODE_HIGH_LEVEL    AT91C_AIC_SRCTYPE_HIGH_LEVEL
/**
 * @brief   Low-level callback.
 */
#define SAM7_EXT_MODE_LOW_LEVEL        AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL
/** @} */

/**
 * @name    EXT drivers priorities
 * @{
 */
#define SAM7_EXT_PRIOR_HIGHEST        AT91C_AIC_PRIOR_HIGHEST
#define SAM7_EXT_PRIOR_LOWEST        AT91C_AIC_PRIOR_LOWEST
/** @} */

/*===========================================================================*/
/* Driver pre-compile time settings.                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Derived constants and error checks.                                       */
/*===========================================================================*/

/*===========================================================================*/
/* Driver data structures and types.                                         */
/*===========================================================================*/

/**
 * @brief   EXT channel identifier.
 */
typedef uint32_t expchannel_t;

/**
 * @brief   Type of an EXT generic notification callback.
 *
 * @param[in] extp      pointer to the @p EXPDriver object triggering the
 *                      callback
 */
typedef void (*extcallback_t)(EXTDriver *extp, expchannel_t channel);

/**
 * @brief   Channel configuration structure.
 */
typedef struct {
  /**
   * @brief Channel mode.
   */
  uint32_t              mode;
  /**
   * @brief Channel callback.
   * @details  In the STM32 implementation a @p NULL callback pointer is
   *           valid and configures the channel as an event sources instead
   *           of an interrupt source.
   */
  extcallback_t         cb;
} EXTChannelConfig;

/**
 * @brief   Driver configuration structure.
 * @note    It could be empty on some architectures.
 */
typedef struct {
  /**
   * @brief Channel configurations.
   */
  EXTChannelConfig      channels[EXT_MAX_CHANNELS];
  /* End of the mandatory fields.*/

  /**
   * @brief interrupt mode.
   */
  uint32_t              mode;

  /**
   * @brief interrupt priority.
   */
  uint32_t                priority;
} EXTConfig;

/**
 * @brief   Structure representing an EXT driver.
 */
struct EXTDriver {
  /**
   * @brief Driver state.
   */
  extstate_t                state;
  /**
   * @brief Current configuration data.
   */
  const EXTConfig           *config;
  /* End of the mandatory fields.*/
  /**
   * @brief Pointer to the corresponding PIO registers block.
   */
  AT91PS_PIO                pio;
  /**
   * @brief peripheral ID of the corresponding PIO block.
   */
  uint32_t                    pid;
};

/*===========================================================================*/
/* Driver macros.                                                            */
/*===========================================================================*/

/**
 * @brief    Computes the content for the interrupt source mode register.
 */
#define SAM7_computeSMR(mode, prio) (                                       \
    ((mode & SAM7_EXT_MODE_MASK) << SAM7_EXT_MODE_SHIFTER) |                \
    ((prio & SAM7_EXT_PRIORITY_MASK) << SAM7_EXT_PRIORITY_SHIFTER)          \
)

/*===========================================================================*/
/* External declarations.                                                    */
/*===========================================================================*/

#if !defined(__DOXYGEN__)
extern EXTDriver EXTDA;
#if (SAM7_PLATFORM == SAM7X128) || (SAM7_PLATFORM == SAM7X256) ||           \
    (SAM7_PLATFORM == SAM7X512)
extern EXTDriver EXTDB;
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif
  void ext_lld_init(void);
  void ext_lld_start(EXTDriver *extp);
  void ext_lld_stop(EXTDriver *extp);
  void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel);
  void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel);
#ifdef __cplusplus
}
#endif

#endif /* HAL_USE_EXT */

#endif /* _EXT_LLD_H_ */

/** @} */