diff options
author | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
commit | dc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch) | |
tree | 4ccb8fa5886b66fa9d480edef74236c27f035e16 /lib/chibios/os/hal/templates |
Diffstat (limited to 'lib/chibios/os/hal/templates')
57 files changed, 11972 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/templates/board/board.c b/lib/chibios/os/hal/templates/board/board.c new file mode 100644 index 000000000..123dfb1ce --- /dev/null +++ b/lib/chibios/os/hal/templates/board/board.c | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #include "hal.h" | ||
18 | |||
19 | /** | ||
20 | * @brief Board-specific initialization code. | ||
21 | * @note You can add your board-specific code here. | ||
22 | */ | ||
23 | void boardInit(void) { | ||
24 | } | ||
diff --git a/lib/chibios/os/hal/templates/board/board.h b/lib/chibios/os/hal/templates/board/board.h new file mode 100644 index 000000000..9aeba7c8f --- /dev/null +++ b/lib/chibios/os/hal/templates/board/board.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef BOARD_H | ||
18 | #define BOARD_H | ||
19 | |||
20 | /* | ||
21 | * Setup for a generic board. | ||
22 | */ | ||
23 | |||
24 | /* | ||
25 | * Board identifier. | ||
26 | */ | ||
27 | #define BOARD_GENERIC | ||
28 | #define BOARD_NAME "Generic Board" | ||
29 | |||
30 | #if !defined(_FROM_ASM_) | ||
31 | #ifdef __cplusplus | ||
32 | extern "C" { | ||
33 | #endif | ||
34 | void boardInit(void); | ||
35 | #ifdef __cplusplus | ||
36 | } | ||
37 | #endif | ||
38 | #endif /* _FROM_ASM_ */ | ||
39 | |||
40 | #endif /* BOARD_H */ | ||
diff --git a/lib/chibios/os/hal/templates/board/board.mk b/lib/chibios/os/hal/templates/board/board.mk new file mode 100644 index 000000000..27724a903 --- /dev/null +++ b/lib/chibios/os/hal/templates/board/board.mk | |||
@@ -0,0 +1,5 @@ | |||
1 | # List of all the board related files. | ||
2 | BOARDSRC = $(CHIBIOS)/os/hal/templates/board/board.c | ||
3 | |||
4 | # Required include directories | ||
5 | BOARDINC = $(CHIBIOS)/os/hal/templates/board | ||
diff --git a/lib/chibios/os/hal/templates/hal_adc_lld.c b/lib/chibios/os/hal/templates/hal_adc_lld.c new file mode 100644 index 000000000..a2b2511c3 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_adc_lld.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_adc_lld.c | ||
19 | * @brief PLATFORM ADC subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup ADC | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_ADC == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @brief ADC1 driver identifier. | ||
39 | */ | ||
40 | #if (PLATFORM_ADC_USE_ADC1 == TRUE) || defined(__DOXYGEN__) | ||
41 | ADCDriver ADCD1; | ||
42 | #endif | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver local variables and types. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* Driver local functions. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Driver interrupt handlers. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver exported functions. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief Low level ADC driver initialization. | ||
62 | * | ||
63 | * @notapi | ||
64 | */ | ||
65 | void adc_lld_init(void) { | ||
66 | |||
67 | #if PLATFORM_ADC_USE_ADC1 == TRUE | ||
68 | /* Driver initialization.*/ | ||
69 | adcObjectInit(&ADCD1); | ||
70 | #endif | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * @brief Configures and activates the ADC peripheral. | ||
75 | * | ||
76 | * @param[in] adcp pointer to the @p ADCDriver object | ||
77 | * | ||
78 | * @notapi | ||
79 | */ | ||
80 | void adc_lld_start(ADCDriver *adcp) { | ||
81 | |||
82 | if (adcp->state == ADC_STOP) { | ||
83 | /* Enables the peripheral.*/ | ||
84 | #if PLATFORM_ADC_USE_ADC1 == TRUE | ||
85 | if (&ADCD1 == adcp) { | ||
86 | |||
87 | } | ||
88 | #endif | ||
89 | } | ||
90 | /* Configures the peripheral.*/ | ||
91 | |||
92 | } | ||
93 | |||
94 | /** | ||
95 | * @brief Deactivates the ADC peripheral. | ||
96 | * | ||
97 | * @param[in] adcp pointer to the @p ADCDriver object | ||
98 | * | ||
99 | * @notapi | ||
100 | */ | ||
101 | void adc_lld_stop(ADCDriver *adcp) { | ||
102 | |||
103 | if (adcp->state == ADC_READY) { | ||
104 | /* Resets the peripheral.*/ | ||
105 | |||
106 | /* Disables the peripheral.*/ | ||
107 | #if PLATFORM_ADC_USE_ADC1 == TRUE | ||
108 | if (&ADCD1 == adcp) { | ||
109 | |||
110 | } | ||
111 | #endif | ||
112 | } | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * @brief Starts an ADC conversion. | ||
117 | * | ||
118 | * @param[in] adcp pointer to the @p ADCDriver object | ||
119 | * | ||
120 | * @notapi | ||
121 | */ | ||
122 | void adc_lld_start_conversion(ADCDriver *adcp) { | ||
123 | |||
124 | (void)adcp; | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * @brief Stops an ongoing conversion. | ||
129 | * | ||
130 | * @param[in] adcp pointer to the @p ADCDriver object | ||
131 | * | ||
132 | * @notapi | ||
133 | */ | ||
134 | void adc_lld_stop_conversion(ADCDriver *adcp) { | ||
135 | |||
136 | (void)adcp; | ||
137 | } | ||
138 | |||
139 | #endif /* HAL_USE_ADC == TRUE */ | ||
140 | |||
141 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_adc_lld.h b/lib/chibios/os/hal/templates/hal_adc_lld.h new file mode 100644 index 000000000..056824e47 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_adc_lld.h | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_adc_lld.h | ||
19 | * @brief PLATFORM ADC subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup ADC | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_ADC_LLD_H | ||
26 | #define HAL_ADC_LLD_H | ||
27 | |||
28 | #if (HAL_USE_ADC == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Driver pre-compile time settings. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /** | ||
39 | * @name PLATFORM configuration options | ||
40 | * @{ | ||
41 | */ | ||
42 | /** | ||
43 | * @brief ADC1 driver enable switch. | ||
44 | * @details If set to @p TRUE the support for ADC1 is included. | ||
45 | * @note The default is @p FALSE. | ||
46 | */ | ||
47 | #if !defined(PLATFORM_ADC_USE_ADC1) || defined(__DOXYGEN__) | ||
48 | #define PLATFORM_ADC_USE_ADC1 FALSE | ||
49 | #endif | ||
50 | /** @} */ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Derived constants and error checks. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver data structures and types. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief ADC sample data type. | ||
62 | */ | ||
63 | typedef uint16_t adcsample_t; | ||
64 | |||
65 | /** | ||
66 | * @brief Channels number in a conversion group. | ||
67 | */ | ||
68 | typedef uint16_t adc_channels_num_t; | ||
69 | |||
70 | /** | ||
71 | * @brief Possible ADC failure causes. | ||
72 | * @note Error codes are architecture dependent and should not relied | ||
73 | * upon. | ||
74 | */ | ||
75 | typedef enum { | ||
76 | ADC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */ | ||
77 | ADC_ERR_OVERFLOW = 1, /**< ADC overflow condition. */ | ||
78 | ADC_ERR_AWD = 2 /**< Analog watchdog triggered. */ | ||
79 | } adcerror_t; | ||
80 | |||
81 | /*===========================================================================*/ | ||
82 | /* Driver macros. */ | ||
83 | /*===========================================================================*/ | ||
84 | |||
85 | /** | ||
86 | * @brief Low level fields of the ADC driver structure. | ||
87 | */ | ||
88 | #define adc_lld_driver_fields \ | ||
89 | /* Dummy field, it is not needed.*/ \ | ||
90 | uint32_t dummy | ||
91 | |||
92 | /** | ||
93 | * @brief Low level fields of the ADC configuration structure. | ||
94 | */ | ||
95 | #define adc_lld_config_fields \ | ||
96 | /* Dummy configuration, it is not needed.*/ \ | ||
97 | uint32_t dummy | ||
98 | |||
99 | /** | ||
100 | * @brief Low level fields of the ADC configuration structure. | ||
101 | */ | ||
102 | #define adc_lld_configuration_group_fields \ | ||
103 | /* Dummy configuration, it is not needed.*/ \ | ||
104 | uint32_t dummy | ||
105 | |||
106 | /*===========================================================================*/ | ||
107 | /* External declarations. */ | ||
108 | /*===========================================================================*/ | ||
109 | |||
110 | #if (PLATFORM_ADC_USE_ADC1 == TRUE) && !defined(__DOXYGEN__) | ||
111 | extern ADCDriver ADCD1; | ||
112 | #endif | ||
113 | |||
114 | #ifdef __cplusplus | ||
115 | extern "C" { | ||
116 | #endif | ||
117 | void adc_lld_init(void); | ||
118 | void adc_lld_start(ADCDriver *adcp); | ||
119 | void adc_lld_stop(ADCDriver *adcp); | ||
120 | void adc_lld_start_conversion(ADCDriver *adcp); | ||
121 | void adc_lld_stop_conversion(ADCDriver *adcp); | ||
122 | #ifdef __cplusplus | ||
123 | } | ||
124 | #endif | ||
125 | |||
126 | #endif /* HAL_USE_ADC == TRUE */ | ||
127 | |||
128 | #endif /* HAL_ADC_LLD_H */ | ||
129 | |||
130 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_can_lld.c b/lib/chibios/os/hal/templates/hal_can_lld.c new file mode 100644 index 000000000..971f904ac --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_can_lld.c | |||
@@ -0,0 +1,257 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_can_lld.c | ||
19 | * @brief PLATFORM CAN subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup CAN | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @brief CAN1 driver identifier. | ||
39 | */ | ||
40 | #if (PLATFORM_CAN_USE_CAN1 == TRUE) || defined(__DOXYGEN__) | ||
41 | CANDriver CAND1; | ||
42 | #endif | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver local variables and types. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* Driver local functions. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Driver interrupt handlers. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver exported functions. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief Low level CAN driver initialization. | ||
62 | * | ||
63 | * @notapi | ||
64 | */ | ||
65 | void can_lld_init(void) { | ||
66 | |||
67 | #if PLATFORM_CAN_USE_CAN1 == TRUE | ||
68 | /* Driver initialization.*/ | ||
69 | canObjectInit(&CAND1); | ||
70 | #endif | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * @brief Configures and activates the CAN peripheral. | ||
75 | * | ||
76 | * @param[in] canp pointer to the @p CANDriver object | ||
77 | * | ||
78 | * @notapi | ||
79 | */ | ||
80 | void can_lld_start(CANDriver *canp) { | ||
81 | |||
82 | if (canp->state == CAN_STOP) { | ||
83 | /* Enables the peripheral.*/ | ||
84 | #if PLATFORM_CAN_USE_CAN1 == TRUE | ||
85 | if (&CAND1 == canp) { | ||
86 | |||
87 | } | ||
88 | #endif | ||
89 | } | ||
90 | /* Configures the peripheral.*/ | ||
91 | |||
92 | } | ||
93 | |||
94 | /** | ||
95 | * @brief Deactivates the CAN peripheral. | ||
96 | * | ||
97 | * @param[in] canp pointer to the @p CANDriver object | ||
98 | * | ||
99 | * @notapi | ||
100 | */ | ||
101 | void can_lld_stop(CANDriver *canp) { | ||
102 | |||
103 | if (canp->state == CAN_READY) { | ||
104 | /* Resets the peripheral.*/ | ||
105 | |||
106 | /* Disables the peripheral.*/ | ||
107 | #if PLATFORM_CAN_USE_CAN1 == TRUE | ||
108 | if (&CAND1 == canp) { | ||
109 | |||
110 | } | ||
111 | #endif | ||
112 | } | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * @brief Determines whether a frame can be transmitted. | ||
117 | * | ||
118 | * @param[in] canp pointer to the @p CANDriver object | ||
119 | * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox | ||
120 | * | ||
121 | * @return The queue space availability. | ||
122 | * @retval false no space in the transmit queue. | ||
123 | * @retval true transmit slot available. | ||
124 | * | ||
125 | * @notapi | ||
126 | */ | ||
127 | bool can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox) { | ||
128 | |||
129 | (void)canp; | ||
130 | |||
131 | switch (mailbox) { | ||
132 | case CAN_ANY_MAILBOX: | ||
133 | return false; | ||
134 | case 1: | ||
135 | return false; | ||
136 | case 2: | ||
137 | return false; | ||
138 | case 3: | ||
139 | return false; | ||
140 | default: | ||
141 | return false; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * @brief Inserts a frame into the transmit queue. | ||
147 | * | ||
148 | * @param[in] canp pointer to the @p CANDriver object | ||
149 | * @param[in] ctfp pointer to the CAN frame to be transmitted | ||
150 | * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox | ||
151 | * | ||
152 | * @notapi | ||
153 | */ | ||
154 | void can_lld_transmit(CANDriver *canp, | ||
155 | canmbx_t mailbox, | ||
156 | const CANTxFrame *ctfp) { | ||
157 | |||
158 | (void)canp; | ||
159 | (void)mailbox; | ||
160 | (void)ctfp; | ||
161 | |||
162 | } | ||
163 | |||
164 | /** | ||
165 | * @brief Determines whether a frame has been received. | ||
166 | * | ||
167 | * @param[in] canp pointer to the @p CANDriver object | ||
168 | * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox | ||
169 | * | ||
170 | * @return The queue space availability. | ||
171 | * @retval false no space in the transmit queue. | ||
172 | * @retval true transmit slot available. | ||
173 | * | ||
174 | * @notapi | ||
175 | */ | ||
176 | bool can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) { | ||
177 | |||
178 | (void)canp; | ||
179 | (void)mailbox; | ||
180 | |||
181 | switch (mailbox) { | ||
182 | case CAN_ANY_MAILBOX: | ||
183 | return false; | ||
184 | case 1: | ||
185 | return false; | ||
186 | case 2: | ||
187 | return false; | ||
188 | default: | ||
189 | return false; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * @brief Receives a frame from the input queue. | ||
195 | * | ||
196 | * @param[in] canp pointer to the @p CANDriver object | ||
197 | * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox | ||
198 | * @param[out] crfp pointer to the buffer where the CAN frame is copied | ||
199 | * | ||
200 | * @notapi | ||
201 | */ | ||
202 | void can_lld_receive(CANDriver *canp, | ||
203 | canmbx_t mailbox, | ||
204 | CANRxFrame *crfp) { | ||
205 | |||
206 | (void)canp; | ||
207 | (void)mailbox; | ||
208 | (void)crfp; | ||
209 | |||
210 | } | ||
211 | |||
212 | /** | ||
213 | * @brief Tries to abort an ongoing transmission. | ||
214 | * | ||
215 | * @param[in] canp pointer to the @p CANDriver object | ||
216 | * @param[in] mailbox mailbox number | ||
217 | * | ||
218 | * @notapi | ||
219 | */ | ||
220 | void can_lld_abort(CANDriver *canp, | ||
221 | canmbx_t mailbox) { | ||
222 | |||
223 | (void)canp; | ||
224 | (void)mailbox; | ||
225 | } | ||
226 | |||
227 | #if (CAN_USE_SLEEP_MODE == TRUE) || defined(__DOXYGEN__) | ||
228 | /** | ||
229 | * @brief Enters the sleep mode. | ||
230 | * | ||
231 | * @param[in] canp pointer to the @p CANDriver object | ||
232 | * | ||
233 | * @notapi | ||
234 | */ | ||
235 | void can_lld_sleep(CANDriver *canp) { | ||
236 | |||
237 | (void)canp; | ||
238 | |||
239 | } | ||
240 | |||
241 | /** | ||
242 | * @brief Enforces leaving the sleep mode. | ||
243 | * | ||
244 | * @param[in] canp pointer to the @p CANDriver object | ||
245 | * | ||
246 | * @notapi | ||
247 | */ | ||
248 | void can_lld_wakeup(CANDriver *canp) { | ||
249 | |||
250 | (void)canp; | ||
251 | |||
252 | } | ||
253 | #endif /* CAN_USE_SLEEP_MOD == TRUEE */ | ||
254 | |||
255 | #endif /* HAL_USE_CAN == TRUE */ | ||
256 | |||
257 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_can_lld.h b/lib/chibios/os/hal/templates/hal_can_lld.h new file mode 100644 index 000000000..624c7bf24 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_can_lld.h | |||
@@ -0,0 +1,275 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_can_lld.h | ||
19 | * @brief PLATFORM CAN subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup CAN | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_CAN_LLD_H | ||
26 | #define HAL_CAN_LLD_H | ||
27 | |||
28 | #if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @brief Number of transmit mailboxes. | ||
36 | */ | ||
37 | #define CAN_TX_MAILBOXES 1 | ||
38 | |||
39 | /** | ||
40 | * @brief Number of receive mailboxes. | ||
41 | */ | ||
42 | #define CAN_RX_MAILBOXES 1 | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver pre-compile time settings. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /** | ||
49 | * @name PLATFORM configuration options | ||
50 | * @{ | ||
51 | */ | ||
52 | /** | ||
53 | * @brief CAN1 driver enable switch. | ||
54 | * @details If set to @p TRUE the support for CAN1 is included. | ||
55 | * @note The default is @p FALSE. | ||
56 | */ | ||
57 | #if !defined(PLATFORM_CAN_USE_CAN1) || defined(__DOXYGEN__) | ||
58 | #define PLATFORM_CAN_USE_CAN1 FALSE | ||
59 | #endif | ||
60 | /** @} */ | ||
61 | |||
62 | /*===========================================================================*/ | ||
63 | /* Derived constants and error checks. */ | ||
64 | /*===========================================================================*/ | ||
65 | |||
66 | /*===========================================================================*/ | ||
67 | /* Driver data structures and types. */ | ||
68 | /*===========================================================================*/ | ||
69 | |||
70 | /** | ||
71 | * @brief Type of a structure representing an CAN driver. | ||
72 | */ | ||
73 | typedef struct CANDriver CANDriver; | ||
74 | |||
75 | /** | ||
76 | * @brief Type of a transmission mailbox index. | ||
77 | */ | ||
78 | typedef uint32_t canmbx_t; | ||
79 | |||
80 | #if defined(CAN_ENFORCE_USE_CALLBACKS) || defined(__DOXYGEN__) | ||
81 | /** | ||
82 | * @brief Type of a CAN notification callback. | ||
83 | * | ||
84 | * @param[in] canp pointer to the @p CANDriver object triggering the | ||
85 | * callback | ||
86 | * @param[in] flags flags associated to the mailbox callback | ||
87 | */ | ||
88 | typedef void (*can_callback_t)(CANDriver *canp, uint32_t flags); | ||
89 | #endif | ||
90 | |||
91 | /** | ||
92 | * @brief CAN transmission frame. | ||
93 | * @note Accessing the frame data as word16 or word32 is not portable because | ||
94 | * machine data endianness, it can be still useful for a quick filling. | ||
95 | */ | ||
96 | typedef struct { | ||
97 | /*lint -save -e46 [6.1] Standard types are fine too.*/ | ||
98 | uint8_t DLC:4; /**< @brief Data length. */ | ||
99 | uint8_t RTR:1; /**< @brief Frame type. */ | ||
100 | uint8_t IDE:1; /**< @brief Identifier type. */ | ||
101 | union { | ||
102 | uint32_t SID:11; /**< @brief Standard identifier.*/ | ||
103 | uint32_t EID:29; /**< @brief Extended identifier.*/ | ||
104 | uint32_t _align1; | ||
105 | }; | ||
106 | /*lint -restore*/ | ||
107 | union { | ||
108 | uint8_t data8[8]; /**< @brief Frame data. */ | ||
109 | uint16_t data16[4]; /**< @brief Frame data. */ | ||
110 | uint32_t data32[2]; /**< @brief Frame data. */ | ||
111 | }; | ||
112 | } CANTxFrame; | ||
113 | |||
114 | /** | ||
115 | * @brief CAN received frame. | ||
116 | * @note Accessing the frame data as word16 or word32 is not portable because | ||
117 | * machine data endianness, it can be still useful for a quick filling. | ||
118 | */ | ||
119 | typedef struct { | ||
120 | /*lint -save -e46 [6.1] Standard types are fine too.*/ | ||
121 | uint8_t FMI; /**< @brief Filter id. */ | ||
122 | uint16_t TIME; /**< @brief Time stamp. */ | ||
123 | uint8_t DLC:4; /**< @brief Data length. */ | ||
124 | uint8_t RTR:1; /**< @brief Frame type. */ | ||
125 | uint8_t IDE:1; /**< @brief Identifier type. */ | ||
126 | union { | ||
127 | uint32_t SID:11; /**< @brief Standard identifier.*/ | ||
128 | uint32_t EID:29; /**< @brief Extended identifier.*/ | ||
129 | uint32_t _align1; | ||
130 | }; | ||
131 | /*lint -restore*/ | ||
132 | union { | ||
133 | uint8_t data8[8]; /**< @brief Frame data. */ | ||
134 | uint16_t data16[4]; /**< @brief Frame data. */ | ||
135 | uint32_t data32[2]; /**< @brief Frame data. */ | ||
136 | }; | ||
137 | } CANRxFrame; | ||
138 | |||
139 | /** | ||
140 | * @brief Driver configuration structure. | ||
141 | */ | ||
142 | typedef struct { | ||
143 | /* End of the mandatory fields.*/ | ||
144 | uint32_t dummy; | ||
145 | } CANConfig; | ||
146 | |||
147 | /** | ||
148 | * @brief Structure representing an CAN driver. | ||
149 | */ | ||
150 | struct CANDriver { | ||
151 | /** | ||
152 | * @brief Driver state. | ||
153 | */ | ||
154 | canstate_t state; | ||
155 | /** | ||
156 | * @brief Current configuration data. | ||
157 | */ | ||
158 | const CANConfig *config; | ||
159 | /** | ||
160 | * @brief Transmission threads queue. | ||
161 | */ | ||
162 | threads_queue_t txqueue; | ||
163 | /** | ||
164 | * @brief Receive threads queue. | ||
165 | */ | ||
166 | threads_queue_t rxqueue; | ||
167 | #if (CAN_ENFORCE_USE_CALLBACKS == FALSE) || defined (__DOXYGEN__) | ||
168 | /** | ||
169 | * @brief One or more frames become available. | ||
170 | * @note After broadcasting this event it will not be broadcasted again | ||
171 | * until the received frames queue has been completely emptied. It | ||
172 | * is <b>not</b> broadcasted for each received frame. It is | ||
173 | * responsibility of the application to empty the queue by | ||
174 | * repeatedly invoking @p chReceive() when listening to this event. | ||
175 | * This behavior minimizes the interrupt served by the system | ||
176 | * because CAN traffic. | ||
177 | * @note The flags associated to the listeners will indicate which | ||
178 | * receive mailboxes become non-empty. | ||
179 | */ | ||
180 | event_source_t rxfull_event; | ||
181 | /** | ||
182 | * @brief One or more transmission mailbox become available. | ||
183 | * @note The flags associated to the listeners will indicate which | ||
184 | * transmit mailboxes become empty. | ||
185 | */ | ||
186 | event_source_t txempty_event; | ||
187 | /** | ||
188 | * @brief A CAN bus error happened. | ||
189 | * @note The flags associated to the listeners will indicate the | ||
190 | * error(s) that have occurred. | ||
191 | */ | ||
192 | event_source_t error_event; | ||
193 | #if (CAN_USE_SLEEP_MODE == TRUE) || defined (__DOXYGEN__) | ||
194 | /** | ||
195 | * @brief Entering sleep state event. | ||
196 | */ | ||
197 | event_source_t sleep_event; | ||
198 | /** | ||
199 | * @brief Exiting sleep state event. | ||
200 | */ | ||
201 | event_source_t wakeup_event; | ||
202 | #endif | ||
203 | #else /* CAN_ENFORCE_USE_CALLBACKS == TRUE */ | ||
204 | /** | ||
205 | * @brief One or more frames become available. | ||
206 | * @note After calling this function it will not be called again | ||
207 | * until the received frames queue has been completely emptied. It | ||
208 | * is <b>not</b> called for each received frame. It is | ||
209 | * responsibility of the application to empty the queue by | ||
210 | * repeatedly invoking @p chTryReceiveI(). | ||
211 | * This behavior minimizes the interrupt served by the system | ||
212 | * because CAN traffic. | ||
213 | */ | ||
214 | can_callback_t rxfull_cb; | ||
215 | /** | ||
216 | * @brief One or more transmission mailbox become available. | ||
217 | * @note The flags associated to the callback will indicate which | ||
218 | * transmit mailboxes become empty. | ||
219 | */ | ||
220 | can_callback_t txempty_cb; | ||
221 | /** | ||
222 | * @brief A CAN bus error happened. | ||
223 | */ | ||
224 | can_callback_t error_cb; | ||
225 | #if (CAN_USE_SLEEP_MODE == TRUE) || defined (__DOXYGEN__) | ||
226 | /** | ||
227 | * @brief Exiting sleep state. | ||
228 | */ | ||
229 | can_callback_t wakeup_cb; | ||
230 | #endif | ||
231 | #endif | ||
232 | /* End of the mandatory fields.*/ | ||
233 | }; | ||
234 | |||
235 | /*===========================================================================*/ | ||
236 | /* Driver macros. */ | ||
237 | /*===========================================================================*/ | ||
238 | |||
239 | /*===========================================================================*/ | ||
240 | /* External declarations. */ | ||
241 | /*===========================================================================*/ | ||
242 | |||
243 | #if (PLATFORM_CAN_USE_CAN1 == TRUE) && !defined(__DOXYGEN__) | ||
244 | extern CANDriver CAND1; | ||
245 | #endif | ||
246 | |||
247 | #ifdef __cplusplus | ||
248 | extern "C" { | ||
249 | #endif | ||
250 | void can_lld_init(void); | ||
251 | void can_lld_start(CANDriver *canp); | ||
252 | void can_lld_stop(CANDriver *canp); | ||
253 | bool can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox); | ||
254 | void can_lld_transmit(CANDriver *canp, | ||
255 | canmbx_t mailbox, | ||
256 | const CANTxFrame *ctfp); | ||
257 | bool can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox); | ||
258 | void can_lld_receive(CANDriver *canp, | ||
259 | canmbx_t mailbox, | ||
260 | CANRxFrame *crfp); | ||
261 | void can_lld_abort(CANDriver *canp, | ||
262 | canmbx_t mailbox); | ||
263 | #if CAN_USE_SLEEP_MODE == TRUE | ||
264 | void can_lld_sleep(CANDriver *canp); | ||
265 | void can_lld_wakeup(CANDriver *canp); | ||
266 | #endif | ||
267 | #ifdef __cplusplus | ||
268 | } | ||
269 | #endif | ||
270 | |||
271 | #endif /* HAL_USE_CAN == TRUE */ | ||
272 | |||
273 | #endif /* HAL_CAN_LLD_H */ | ||
274 | |||
275 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_crypto_lld.c b/lib/chibios/os/hal/templates/hal_crypto_lld.c new file mode 100644 index 000000000..b4f5c9909 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_crypto_lld.c | |||
@@ -0,0 +1,1346 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_crypto_lld.c | ||
19 | * @brief PLATFORM cryptographic subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup CRYPTO | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_CRY == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** @brief CRY1 driver identifier.*/ | ||
38 | #if PLATFORM_CRY_USE_CRY1 || defined(__DOXYGEN__) | ||
39 | CRYDriver CRYD1; | ||
40 | #endif | ||
41 | |||
42 | /*===========================================================================*/ | ||
43 | /* Driver local variables and types. */ | ||
44 | /*===========================================================================*/ | ||
45 | |||
46 | /*===========================================================================*/ | ||
47 | /* Driver local functions. */ | ||
48 | /*===========================================================================*/ | ||
49 | |||
50 | /*===========================================================================*/ | ||
51 | /* Driver interrupt handlers. */ | ||
52 | /*===========================================================================*/ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Driver exported functions. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /** | ||
59 | * @brief Low level crypto driver initialization. | ||
60 | * | ||
61 | * @notapi | ||
62 | */ | ||
63 | void cry_lld_init(void) { | ||
64 | |||
65 | } | ||
66 | |||
67 | /** | ||
68 | * @brief Configures and activates the crypto peripheral. | ||
69 | * | ||
70 | * @param[in] cryp pointer to the @p CRYDriver object | ||
71 | * | ||
72 | * @notapi | ||
73 | */ | ||
74 | void cry_lld_start(CRYDriver *cryp) { | ||
75 | |||
76 | if (cryp->state == CRY_STOP) { | ||
77 | |||
78 | } | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * @brief Deactivates the crypto peripheral. | ||
83 | * | ||
84 | * @param[in] cryp pointer to the @p CRYDriver object | ||
85 | * | ||
86 | * @notapi | ||
87 | */ | ||
88 | void cry_lld_stop(CRYDriver *cryp) { | ||
89 | |||
90 | if (cryp->state == CRY_READY) { | ||
91 | |||
92 | } | ||
93 | } | ||
94 | |||
95 | #if (CRY_LLD_SUPPORTS_AES == TRUE) || defined(__DOXYGEN__) | ||
96 | /** | ||
97 | * @brief Initializes the AES transient key. | ||
98 | * @note It is the underlying implementation to decide which key sizes are | ||
99 | * allowable. | ||
100 | * | ||
101 | * @param[in] cryp pointer to the @p CRYDriver object | ||
102 | * @param[in] size key size in bytes | ||
103 | * @param[in] keyp pointer to the key data | ||
104 | * @return The operation status. | ||
105 | * @retval CRY_NOERROR if the operation succeeded. | ||
106 | * @retval CRY_ERR_INV_ALGO if the algorithm is unsupported. | ||
107 | * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid for | ||
108 | * the specified algorithm. | ||
109 | * | ||
110 | * @notapi | ||
111 | */ | ||
112 | cryerror_t cry_lld_aes_loadkey(CRYDriver *cryp, | ||
113 | size_t size, | ||
114 | const uint8_t *keyp) { | ||
115 | |||
116 | (void)cryp; | ||
117 | (void)size; | ||
118 | (void)keyp; | ||
119 | |||
120 | return CRY_ERR_INV_ALGO; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * @brief Encryption of a single block using AES. | ||
125 | * @note The implementation of this function must guarantee that it can | ||
126 | * be called from any context. | ||
127 | * | ||
128 | * @param[in] cryp pointer to the @p CRYDriver object | ||
129 | * @param[in] key_id the key to be used for the operation, zero is | ||
130 | * the transient key, other values are keys stored | ||
131 | * in an unspecified way | ||
132 | * @param[in] in buffer containing the input plaintext | ||
133 | * @param[out] out buffer for the output ciphertext | ||
134 | * @return The operation status. | ||
135 | * @retval CRY_NOERROR if the operation succeeded. | ||
136 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
137 | * device instance. | ||
138 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
139 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
140 | * or refers to an empty key slot. | ||
141 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
142 | * dependent. | ||
143 | * | ||
144 | * @notapi | ||
145 | */ | ||
146 | cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, | ||
147 | crykey_t key_id, | ||
148 | const uint8_t *in, | ||
149 | uint8_t *out) { | ||
150 | |||
151 | (void)cryp; | ||
152 | (void)key_id; | ||
153 | (void)in; | ||
154 | (void)out; | ||
155 | |||
156 | return CRY_ERR_INV_ALGO; | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | * @brief Decryption of a single block using AES. | ||
161 | * @note The implementation of this function must guarantee that it can | ||
162 | * be called from any context. | ||
163 | * | ||
164 | * @param[in] cryp pointer to the @p CRYDriver object | ||
165 | * @param[in] key_id the key to be used for the operation, zero is | ||
166 | * the transient key, other values are keys stored | ||
167 | * in an unspecified way | ||
168 | * @param[in] in buffer containing the input ciphertext | ||
169 | * @param[out] out buffer for the output plaintext | ||
170 | * @return The operation status. | ||
171 | * @retval CRY_NOERROR if the operation succeeded. | ||
172 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
173 | * device instance. | ||
174 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
175 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
176 | * or refers to an empty key slot. | ||
177 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
178 | * dependent. | ||
179 | * | ||
180 | * @notapi | ||
181 | */ | ||
182 | cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, | ||
183 | crykey_t key_id, | ||
184 | const uint8_t *in, | ||
185 | uint8_t *out) { | ||
186 | |||
187 | (void)cryp; | ||
188 | (void)key_id; | ||
189 | (void)in; | ||
190 | (void)out; | ||
191 | |||
192 | return CRY_ERR_INV_ALGO; | ||
193 | } | ||
194 | #endif | ||
195 | |||
196 | #if (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || defined(__DOXYGEN__) | ||
197 | /** | ||
198 | * @brief Encryption operation using AES-ECB. | ||
199 | * @note The function operates on data buffers whose length is a multiple | ||
200 | * of an AES block, this means that padding must be done by the | ||
201 | * caller. | ||
202 | * | ||
203 | * @param[in] cryp pointer to the @p CRYDriver object | ||
204 | * @param[in] key_id the key to be used for the operation, zero is | ||
205 | * the transient key, other values are keys stored | ||
206 | * in an unspecified way | ||
207 | * @param[in] size size of both buffers, this number must be a | ||
208 | * multiple of 16 | ||
209 | * @param[in] in buffer containing the input plaintext | ||
210 | * @param[out] out buffer for the output ciphertext | ||
211 | * @return The operation status. | ||
212 | * @retval CRY_NOERROR if the operation succeeded. | ||
213 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
214 | * device instance. | ||
215 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
216 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
217 | * or refers to an empty key slot. | ||
218 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
219 | * dependent. | ||
220 | * | ||
221 | * @notapi | ||
222 | */ | ||
223 | cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, | ||
224 | crykey_t key_id, | ||
225 | size_t size, | ||
226 | const uint8_t *in, | ||
227 | uint8_t *out) { | ||
228 | |||
229 | (void)cryp; | ||
230 | (void)key_id; | ||
231 | (void)size; | ||
232 | (void)in; | ||
233 | (void)out; | ||
234 | |||
235 | return CRY_ERR_INV_ALGO; | ||
236 | } | ||
237 | |||
238 | /** | ||
239 | * @brief Decryption operation using AES-ECB. | ||
240 | * @note The function operates on data buffers whose length is a multiple | ||
241 | * of an AES block, this means that padding must be done by the | ||
242 | * caller. | ||
243 | * | ||
244 | * @param[in] cryp pointer to the @p CRYDriver object | ||
245 | * @param[in] key_id the key to be used for the operation, zero is | ||
246 | * the transient key, other values are keys stored | ||
247 | * in an unspecified way | ||
248 | * @param[in] size size of both buffers, this number must be a | ||
249 | * multiple of 16 | ||
250 | * @param[in] in buffer containing the input plaintext | ||
251 | * @param[out] out buffer for the output ciphertext | ||
252 | * @return The operation status. | ||
253 | * @retval CRY_NOERROR if the operation succeeded. | ||
254 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
255 | * device instance. | ||
256 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
257 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
258 | * or refers to an empty key slot. | ||
259 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
260 | * dependent. | ||
261 | * | ||
262 | * @notapi | ||
263 | */ | ||
264 | cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, | ||
265 | crykey_t key_id, | ||
266 | size_t size, | ||
267 | const uint8_t *in, | ||
268 | uint8_t *out) { | ||
269 | |||
270 | (void)cryp; | ||
271 | (void)key_id; | ||
272 | (void)size; | ||
273 | (void)in; | ||
274 | (void)out; | ||
275 | |||
276 | return CRY_ERR_INV_ALGO; | ||
277 | } | ||
278 | #endif | ||
279 | |||
280 | #if (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || defined(__DOXYGEN__) | ||
281 | /** | ||
282 | * @brief Encryption operation using AES-CBC. | ||
283 | * @note The function operates on data buffers whose length is a multiple | ||
284 | * of an AES block, this means that padding must be done by the | ||
285 | * caller. | ||
286 | * | ||
287 | * @param[in] cryp pointer to the @p CRYDriver object | ||
288 | * @param[in] key_id the key to be used for the operation, zero is | ||
289 | * the transient key, other values are keys stored | ||
290 | * in an unspecified way | ||
291 | * @param[in] size size of both buffers, this number must be a | ||
292 | * multiple of 16 | ||
293 | * @param[in] in buffer containing the input plaintext | ||
294 | * @param[out] out buffer for the output ciphertext | ||
295 | * @param[in] iv 128 bits initial vector | ||
296 | * @return The operation status. | ||
297 | * @retval CRY_NOERROR if the operation succeeded. | ||
298 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
299 | * device instance. | ||
300 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
301 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
302 | * or refers to an empty key slot. | ||
303 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
304 | * dependent. | ||
305 | * | ||
306 | * @notapi | ||
307 | */ | ||
308 | cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, | ||
309 | crykey_t key_id, | ||
310 | size_t size, | ||
311 | const uint8_t *in, | ||
312 | uint8_t *out, | ||
313 | const uint8_t *iv) { | ||
314 | |||
315 | (void)cryp; | ||
316 | (void)key_id; | ||
317 | (void)size; | ||
318 | (void)in; | ||
319 | (void)out; | ||
320 | (void)iv; | ||
321 | |||
322 | return CRY_ERR_INV_ALGO; | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * @brief Decryption operation using AES-CBC. | ||
327 | * @note The function operates on data buffers whose length is a multiple | ||
328 | * of an AES block, this means that padding must be done by the | ||
329 | * caller. | ||
330 | * | ||
331 | * @param[in] cryp pointer to the @p CRYDriver object | ||
332 | * @param[in] key_id the key to be used for the operation, zero is | ||
333 | * the transient key, other values are keys stored | ||
334 | * in an unspecified way | ||
335 | * @param[in] size size of both buffers, this number must be a | ||
336 | * multiple of 16 | ||
337 | * @param[in] in buffer containing the input plaintext | ||
338 | * @param[out] out buffer for the output ciphertext | ||
339 | * @param[in] iv 128 bits initial vector | ||
340 | * @return The operation status. | ||
341 | * @retval CRY_NOERROR if the operation succeeded. | ||
342 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
343 | * device instance. | ||
344 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
345 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
346 | * or refers to an empty key slot. | ||
347 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
348 | * dependent. | ||
349 | * | ||
350 | * @notapi | ||
351 | */ | ||
352 | cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, | ||
353 | crykey_t key_id, | ||
354 | size_t size, | ||
355 | const uint8_t *in, | ||
356 | uint8_t *out, | ||
357 | const uint8_t *iv) { | ||
358 | |||
359 | (void)cryp; | ||
360 | (void)key_id; | ||
361 | (void)size; | ||
362 | (void)in; | ||
363 | (void)out; | ||
364 | (void)iv; | ||
365 | |||
366 | return CRY_ERR_INV_ALGO; | ||
367 | } | ||
368 | #endif | ||
369 | |||
370 | #if (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || defined(__DOXYGEN__) | ||
371 | /** | ||
372 | * @brief Encryption operation using AES-CFB. | ||
373 | * @note This is a stream cipher, there are no size restrictions. | ||
374 | * | ||
375 | * @param[in] cryp pointer to the @p CRYDriver object | ||
376 | * @param[in] key_id the key to be used for the operation, zero is | ||
377 | * the transient key, other values are keys stored | ||
378 | * in an unspecified way | ||
379 | * @param[in] size size of both buffers | ||
380 | * @param[in] in buffer containing the input plaintext | ||
381 | * @param[out] out buffer for the output ciphertext | ||
382 | * @param[in] iv 128 bits initial vector | ||
383 | * @return The operation status. | ||
384 | * @retval CRY_NOERROR if the operation succeeded. | ||
385 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
386 | * device instance. | ||
387 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
388 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
389 | * or refers to an empty key slot. | ||
390 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
391 | * dependent. | ||
392 | * | ||
393 | * @notapi | ||
394 | */ | ||
395 | cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, | ||
396 | crykey_t key_id, | ||
397 | size_t size, | ||
398 | const uint8_t *in, | ||
399 | uint8_t *out, | ||
400 | const uint8_t *iv) { | ||
401 | |||
402 | (void)cryp; | ||
403 | (void)key_id; | ||
404 | (void)size; | ||
405 | (void)in; | ||
406 | (void)out; | ||
407 | (void)iv; | ||
408 | |||
409 | return CRY_ERR_INV_ALGO; | ||
410 | } | ||
411 | |||
412 | /** | ||
413 | * @brief Decryption operation using AES-CFB. | ||
414 | * @note This is a stream cipher, there are no size restrictions. | ||
415 | * | ||
416 | * @param[in] cryp pointer to the @p CRYDriver object | ||
417 | * @param[in] key_id the key to be used for the operation, zero is | ||
418 | * the transient key, other values are keys stored | ||
419 | * in an unspecified way | ||
420 | * @param[in] size size of both buffers | ||
421 | * @param[in] in buffer containing the input plaintext | ||
422 | * @param[out] out buffer for the output ciphertext | ||
423 | * @param[in] iv 128 bits initial vector | ||
424 | * @return The operation status. | ||
425 | * @retval CRY_NOERROR if the operation succeeded. | ||
426 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
427 | * device instance. | ||
428 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
429 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
430 | * or refers to an empty key slot. | ||
431 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
432 | * dependent. | ||
433 | * | ||
434 | * @notapi | ||
435 | */ | ||
436 | cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, | ||
437 | crykey_t key_id, | ||
438 | size_t size, | ||
439 | const uint8_t *in, | ||
440 | uint8_t *out, | ||
441 | const uint8_t *iv) { | ||
442 | |||
443 | (void)cryp; | ||
444 | (void)key_id; | ||
445 | (void)size; | ||
446 | (void)in; | ||
447 | (void)out; | ||
448 | (void)iv; | ||
449 | |||
450 | return CRY_ERR_INV_ALGO; | ||
451 | } | ||
452 | #endif | ||
453 | |||
454 | #if (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || defined(__DOXYGEN__) | ||
455 | /** | ||
456 | * @brief Encryption operation using AES-CTR. | ||
457 | * @note This is a stream cipher, there are no size restrictions. | ||
458 | * | ||
459 | * @param[in] cryp pointer to the @p CRYDriver object | ||
460 | * @param[in] key_id the key to be used for the operation, zero is | ||
461 | * the transient key, other values are keys stored | ||
462 | * in an unspecified way | ||
463 | * @param[in] size size of both buffers | ||
464 | * @param[in] in buffer containing the input plaintext | ||
465 | * @param[out] out buffer for the output ciphertext | ||
466 | * @param[in] iv 128 bits initial vector + counter, it contains | ||
467 | * a 96 bits IV and a 32 bits counter | ||
468 | * @return The operation status. | ||
469 | * @retval CRY_NOERROR if the operation succeeded. | ||
470 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
471 | * device instance. | ||
472 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
473 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
474 | * or refers to an empty key slot. | ||
475 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
476 | * dependent. | ||
477 | * | ||
478 | * @notapi | ||
479 | */ | ||
480 | cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, | ||
481 | crykey_t key_id, | ||
482 | size_t size, | ||
483 | const uint8_t *in, | ||
484 | uint8_t *out, | ||
485 | const uint8_t *iv) { | ||
486 | |||
487 | (void)cryp; | ||
488 | (void)key_id; | ||
489 | (void)size; | ||
490 | (void)in; | ||
491 | (void)out; | ||
492 | (void)iv; | ||
493 | |||
494 | return CRY_ERR_INV_ALGO; | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * @brief Decryption operation using AES-CTR. | ||
499 | * @note This is a stream cipher, there are no size restrictions. | ||
500 | * | ||
501 | * @param[in] cryp pointer to the @p CRYDriver object | ||
502 | * @param[in] key_id the key to be used for the operation, zero is | ||
503 | * the transient key, other values are keys stored | ||
504 | * in an unspecified way | ||
505 | * @param[in] size size of both buffers | ||
506 | * @param[in] in buffer containing the input ciphertext | ||
507 | * @param[out] out buffer for the output plaintext | ||
508 | * @param[in] iv 128 bits initial vector + counter, it contains | ||
509 | * a 96 bits IV and a 32 bits counter | ||
510 | * @return The operation status. | ||
511 | * @retval CRY_NOERROR if the operation succeeded. | ||
512 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
513 | * device instance. | ||
514 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
515 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
516 | * or refers to an empty key slot. | ||
517 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
518 | * dependent. | ||
519 | * | ||
520 | * @notapi | ||
521 | */ | ||
522 | cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, | ||
523 | crykey_t key_id, | ||
524 | size_t size, | ||
525 | const uint8_t *in, | ||
526 | uint8_t *out, | ||
527 | const uint8_t *iv) { | ||
528 | |||
529 | (void)cryp; | ||
530 | (void)key_id; | ||
531 | (void)size; | ||
532 | (void)in; | ||
533 | (void)out; | ||
534 | (void)iv; | ||
535 | |||
536 | return CRY_ERR_INV_ALGO; | ||
537 | } | ||
538 | #endif | ||
539 | |||
540 | #if (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || defined(__DOXYGEN__) | ||
541 | /** | ||
542 | * @brief Encryption operation using AES-GCM. | ||
543 | * @note This is a stream cipher, there are no size restrictions. | ||
544 | * | ||
545 | * @param[in] cryp pointer to the @p CRYDriver object | ||
546 | * @param[in] key_id the key to be used for the operation, zero is | ||
547 | * the transient key, other values are keys stored | ||
548 | * in an unspecified way | ||
549 | * @param[in] auth_size size of the data buffer to be authenticated | ||
550 | * @param[in] auth_in buffer containing the data to be authenticated | ||
551 | * @param[in] text_size size of the text buffer | ||
552 | * @param[in] text_in buffer containing the input plaintext | ||
553 | * @param[out] text_out buffer for the output ciphertext | ||
554 | * @param[in] iv 128 bits input vector | ||
555 | * @param[in] tag_size size of the authentication tag, this number | ||
556 | * must be between 1 and 16 | ||
557 | * @param[out] tag_out buffer for the generated authentication tag | ||
558 | * @return The operation status. | ||
559 | * @retval CRY_NOERROR if the operation succeeded. | ||
560 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
561 | * device instance. | ||
562 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
563 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
564 | * or refers to an empty key slot. | ||
565 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
566 | * dependent. | ||
567 | * | ||
568 | * @notapi | ||
569 | */ | ||
570 | cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, | ||
571 | crykey_t key_id, | ||
572 | size_t auth_size, | ||
573 | const uint8_t *auth_in, | ||
574 | size_t text_size, | ||
575 | const uint8_t *text_in, | ||
576 | uint8_t *text_out, | ||
577 | const uint8_t *iv, | ||
578 | size_t tag_size, | ||
579 | uint8_t *tag_out) { | ||
580 | |||
581 | (void)cryp; | ||
582 | (void)key_id; | ||
583 | (void)auth_size; | ||
584 | (void)auth_in; | ||
585 | (void)text_size; | ||
586 | (void)text_in; | ||
587 | (void)text_out; | ||
588 | (void)iv; | ||
589 | (void)tag_size; | ||
590 | (void)tag_out; | ||
591 | |||
592 | return CRY_ERR_INV_ALGO; | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * @brief Decryption operation using AES-GCM. | ||
597 | * @note This is a stream cipher, there are no size restrictions. | ||
598 | * | ||
599 | * @param[in] cryp pointer to the @p CRYDriver object | ||
600 | * @param[in] key_id the key to be used for the operation, zero is | ||
601 | * the transient key, other values are keys stored | ||
602 | * in an unspecified way | ||
603 | * @param[in] auth_size size of the data buffer to be authenticated | ||
604 | * @param[in] auth_in buffer containing the data to be authenticated | ||
605 | * @param[in] text_size size of the text buffer | ||
606 | * @param[in] text_in buffer containing the input plaintext | ||
607 | * @param[out] text_out buffer for the output ciphertext | ||
608 | * @param[in] iv 128 bits input vector | ||
609 | * @param[in] tag_size size of the authentication tag, this number | ||
610 | * must be between 1 and 16 | ||
611 | * @param[in] tag_in buffer for the generated authentication tag | ||
612 | * @return The operation status. | ||
613 | * @retval CRY_NOERROR if the operation succeeded. | ||
614 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
615 | * device instance. | ||
616 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
617 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
618 | * or refers to an empty key slot. | ||
619 | * @retval CRY_ERR_AUTH_FAILED authentication failed | ||
620 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
621 | * dependent. | ||
622 | * | ||
623 | * @notapi | ||
624 | */ | ||
625 | cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, | ||
626 | crykey_t key_id, | ||
627 | size_t auth_size, | ||
628 | const uint8_t *auth_in, | ||
629 | size_t text_size, | ||
630 | const uint8_t *text_in, | ||
631 | uint8_t *text_out, | ||
632 | const uint8_t *iv, | ||
633 | size_t tag_size, | ||
634 | const uint8_t *tag_in) { | ||
635 | |||
636 | (void)cryp; | ||
637 | (void)key_id; | ||
638 | (void)auth_size; | ||
639 | (void)auth_in; | ||
640 | (void)text_size; | ||
641 | (void)text_in; | ||
642 | (void)text_out; | ||
643 | (void)iv; | ||
644 | (void)tag_size; | ||
645 | (void)tag_in; | ||
646 | |||
647 | return CRY_ERR_INV_ALGO; | ||
648 | } | ||
649 | #endif | ||
650 | |||
651 | #if (CRY_LLD_SUPPORTS_DES == TRUE) || defined(__DOXYGEN__) | ||
652 | /** | ||
653 | * @brief Initializes the DES transient key. | ||
654 | * @note It is the underlying implementation to decide which key sizes are | ||
655 | * allowable. | ||
656 | * | ||
657 | * @param[in] cryp pointer to the @p CRYDriver object | ||
658 | * @param[in] size key size in bytes | ||
659 | * @param[in] keyp pointer to the key data | ||
660 | * @return The operation status. | ||
661 | * @retval CRY_NOERROR if the operation succeeded. | ||
662 | * @retval CRY_ERR_INV_ALGO if the algorithm is unsupported. | ||
663 | * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid for | ||
664 | * the specified algorithm. | ||
665 | * | ||
666 | * @notapi | ||
667 | */ | ||
668 | cryerror_t cry_lld_des_loadkey(CRYDriver *cryp, | ||
669 | size_t size, | ||
670 | const uint8_t *keyp) { | ||
671 | |||
672 | (void)cryp; | ||
673 | (void)size; | ||
674 | (void)keyp; | ||
675 | |||
676 | return CRY_ERR_INV_ALGO; | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * @brief Encryption of a single block using (T)DES. | ||
681 | * @note The implementation of this function must guarantee that it can | ||
682 | * be called from any context. | ||
683 | * | ||
684 | * @param[in] cryp pointer to the @p CRYDriver object | ||
685 | * @param[in] key_id the key to be used for the operation, zero is | ||
686 | * the transient key, other values are keys stored | ||
687 | * in an unspecified way | ||
688 | * @param[in] in buffer containing the input plaintext | ||
689 | * @param[out] out buffer for the output ciphertext | ||
690 | * @return The operation status. | ||
691 | * @retval CRY_NOERROR if the operation succeeded. | ||
692 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
693 | * device instance. | ||
694 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
695 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
696 | * or refers to an empty key slot. | ||
697 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
698 | * dependent. | ||
699 | * | ||
700 | * @notapi | ||
701 | */ | ||
702 | cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, | ||
703 | crykey_t key_id, | ||
704 | const uint8_t *in, | ||
705 | uint8_t *out) { | ||
706 | |||
707 | (void)cryp; | ||
708 | (void)key_id; | ||
709 | (void)in; | ||
710 | (void)out; | ||
711 | |||
712 | return CRY_ERR_INV_ALGO; | ||
713 | } | ||
714 | |||
715 | /** | ||
716 | * @brief Decryption of a single block using (T)DES. | ||
717 | * @note The implementation of this function must guarantee that it can | ||
718 | * be called from any context. | ||
719 | * | ||
720 | * | ||
721 | * @param[in] cryp pointer to the @p CRYDriver object | ||
722 | * @param[in] key_id the key to be used for the operation, zero is | ||
723 | * the transient key, other values are keys stored | ||
724 | * in an unspecified way | ||
725 | * @param[in] in buffer containing the input ciphertext | ||
726 | * @param[out] out buffer for the output plaintext | ||
727 | * @return The operation status. | ||
728 | * @retval CRY_NOERROR if the operation succeeded. | ||
729 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
730 | * device instance. | ||
731 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
732 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
733 | * or refers to an empty key slot. | ||
734 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
735 | * dependent. | ||
736 | * | ||
737 | * @notapi | ||
738 | */ | ||
739 | cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, | ||
740 | crykey_t key_id, | ||
741 | const uint8_t *in, | ||
742 | uint8_t *out) { | ||
743 | |||
744 | (void)cryp; | ||
745 | (void)key_id; | ||
746 | (void)in; | ||
747 | (void)out; | ||
748 | |||
749 | return CRY_ERR_INV_ALGO; | ||
750 | } | ||
751 | #endif | ||
752 | |||
753 | #if (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || defined(__DOXYGEN__) | ||
754 | /** | ||
755 | * @brief Encryption operation using (T)DES-ECB. | ||
756 | * @note The function operates on data buffers whose length is a multiple | ||
757 | * of an DES block, this means that padding must be done by the | ||
758 | * caller. | ||
759 | * | ||
760 | * @param[in] cryp pointer to the @p CRYDriver object | ||
761 | * @param[in] key_id the key to be used for the operation, zero is | ||
762 | * the transient key, other values are keys stored | ||
763 | * in an unspecified way | ||
764 | * @param[in] size size of the plaintext buffer, this number must | ||
765 | * be a multiple of 8 | ||
766 | * @param[in] in buffer containing the input plaintext | ||
767 | * @param[out] out buffer for the output ciphertext | ||
768 | * @return The operation status. | ||
769 | * @retval CRY_NOERROR if the operation succeeded. | ||
770 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
771 | * device instance. | ||
772 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
773 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
774 | * or refers to an empty key slot. | ||
775 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
776 | * dependent. | ||
777 | * | ||
778 | * @notapi | ||
779 | */ | ||
780 | cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, | ||
781 | crykey_t key_id, | ||
782 | size_t size, | ||
783 | const uint8_t *in, | ||
784 | uint8_t *out) { | ||
785 | |||
786 | (void)cryp; | ||
787 | (void)key_id; | ||
788 | (void)size; | ||
789 | (void)in; | ||
790 | (void)out; | ||
791 | |||
792 | return CRY_ERR_INV_ALGO; | ||
793 | } | ||
794 | |||
795 | /** | ||
796 | * @brief Decryption operation using (T)DES-ECB. | ||
797 | * @note The function operates on data buffers whose length is a multiple | ||
798 | * of an DES block, this means that padding must be done by the | ||
799 | * caller. | ||
800 | * | ||
801 | * @param[in] cryp pointer to the @p CRYDriver object | ||
802 | * @param[in] key_id the key to be used for the operation, zero is | ||
803 | * the transient key, other values are keys stored | ||
804 | * in an unspecified way | ||
805 | * @param[in] size size of the plaintext buffer, this number must | ||
806 | * be a multiple of 8 | ||
807 | * @param[in] in buffer containing the input ciphertext | ||
808 | * @param[out] out buffer for the output plaintext | ||
809 | * @return T he operation status. | ||
810 | * @retval CRY_NOERROR if the operation succeeded. | ||
811 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
812 | * device instance. | ||
813 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
814 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
815 | * or refers to an empty key slot. | ||
816 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
817 | * dependent. | ||
818 | * | ||
819 | * @notapi | ||
820 | */ | ||
821 | cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, | ||
822 | crykey_t key_id, | ||
823 | size_t size, | ||
824 | const uint8_t *in, | ||
825 | uint8_t *out) { | ||
826 | |||
827 | (void)cryp; | ||
828 | (void)key_id; | ||
829 | (void)size; | ||
830 | (void)in; | ||
831 | (void)out; | ||
832 | |||
833 | return CRY_ERR_INV_ALGO; | ||
834 | } | ||
835 | #endif | ||
836 | |||
837 | #if (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || defined(__DOXYGEN__) | ||
838 | /** | ||
839 | * @brief Encryption operation using (T)DES-CBC. | ||
840 | * @note The function operates on data buffers whose length is a multiple | ||
841 | * of an DES block, this means that padding must be done by the | ||
842 | * caller. | ||
843 | * | ||
844 | * @param[in] cryp pointer to the @p CRYDriver object | ||
845 | * @param[in] key_id the key to be used for the operation, zero is | ||
846 | * the transient key, other values are keys stored | ||
847 | * in an unspecified way | ||
848 | * @param[in] size size of the plaintext buffer, this number must | ||
849 | * be a multiple of 8 | ||
850 | * @param[in] in buffer containing the input plaintext | ||
851 | * @param[out] out buffer for the output ciphertext | ||
852 | * @param[in] iv 64 bits input vector | ||
853 | * @return The operation status. | ||
854 | * @retval CRY_NOERROR if the operation succeeded. | ||
855 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
856 | * device instance. | ||
857 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
858 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
859 | * or refers to an empty key slot. | ||
860 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
861 | * dependent. | ||
862 | * | ||
863 | * @notapi | ||
864 | */ | ||
865 | cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, | ||
866 | crykey_t key_id, | ||
867 | size_t size, | ||
868 | const uint8_t *in, | ||
869 | uint8_t *out, | ||
870 | const uint8_t *iv) { | ||
871 | |||
872 | (void)cryp; | ||
873 | (void)key_id; | ||
874 | (void)size; | ||
875 | (void)in; | ||
876 | (void)out; | ||
877 | (void)iv; | ||
878 | |||
879 | return CRY_ERR_INV_ALGO; | ||
880 | } | ||
881 | |||
882 | /** | ||
883 | * @brief Decryption operation using (T)DES-CBC. | ||
884 | * @note The function operates on data buffers whose length is a multiple | ||
885 | * of an DES block, this means that padding must be done by the | ||
886 | * caller. | ||
887 | * | ||
888 | * @param[in] cryp pointer to the @p CRYDriver object | ||
889 | * @param[in] key_id the key to be used for the operation, zero is | ||
890 | * the transient key, other values are keys stored | ||
891 | * in an unspecified way | ||
892 | * @param[in] size size of the plaintext buffer, this number must | ||
893 | * be a multiple of 8 | ||
894 | * @param[in] in buffer containing the input ciphertext | ||
895 | * @param[out] out buffer for the output plaintext | ||
896 | * @param[in] iv 64 bits input vector | ||
897 | * @return The operation status. | ||
898 | * @retval CRY_NOERROR if the operation succeeded. | ||
899 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
900 | * device instance. | ||
901 | * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. | ||
902 | * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid | ||
903 | * or refers to an empty key slot. | ||
904 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
905 | * dependent. | ||
906 | * | ||
907 | * @notapi | ||
908 | */ | ||
909 | cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, | ||
910 | crykey_t key_id, | ||
911 | size_t size, | ||
912 | const uint8_t *in, | ||
913 | uint8_t *out, | ||
914 | const uint8_t *iv) { | ||
915 | |||
916 | (void)cryp; | ||
917 | (void)key_id; | ||
918 | (void)size; | ||
919 | (void)in; | ||
920 | (void)out; | ||
921 | (void)iv; | ||
922 | |||
923 | return CRY_ERR_INV_ALGO; | ||
924 | } | ||
925 | #endif | ||
926 | |||
927 | #if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) | ||
928 | /** | ||
929 | * @brief Hash initialization using SHA1. | ||
930 | * @note Use of this algorithm is not recommended because proven weak. | ||
931 | * | ||
932 | * @param[in] cryp pointer to the @p CRYDriver object | ||
933 | * @param[out] sha1ctxp pointer to a SHA1 context to be initialized | ||
934 | * @retval CRY_NOERROR if the operation succeeded. | ||
935 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
936 | * device instance. | ||
937 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
938 | * dependent. | ||
939 | * | ||
940 | * @notapi | ||
941 | */ | ||
942 | cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp) { | ||
943 | |||
944 | (void)cryp; | ||
945 | (void)sha1ctxp; | ||
946 | |||
947 | return CRY_ERR_INV_ALGO; | ||
948 | } | ||
949 | |||
950 | /** | ||
951 | * @brief Hash update using SHA1. | ||
952 | * @note Use of this algorithm is not recommended because proven weak. | ||
953 | * | ||
954 | * @param[in] cryp pointer to the @p CRYDriver object | ||
955 | * @param[in] sha1ctxp pointer to a SHA1 context | ||
956 | * @param[in] size size of input buffer | ||
957 | * @param[in] in buffer containing the input text | ||
958 | * @return The operation status. | ||
959 | * @retval CRY_NOERROR if the operation succeeded. | ||
960 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
961 | * device instance. | ||
962 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
963 | * dependent. | ||
964 | * | ||
965 | * @notapi | ||
966 | */ | ||
967 | cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, | ||
968 | size_t size, const uint8_t *in) { | ||
969 | |||
970 | (void)cryp; | ||
971 | (void)sha1ctxp; | ||
972 | (void)size; | ||
973 | (void)in; | ||
974 | |||
975 | return CRY_ERR_INV_ALGO; | ||
976 | } | ||
977 | |||
978 | /** | ||
979 | * @brief Hash finalization using SHA1. | ||
980 | * @note Use of this algorithm is not recommended because proven weak. | ||
981 | * | ||
982 | * @param[in] cryp pointer to the @p CRYDriver object | ||
983 | * @param[in] sha1ctxp pointer to a SHA1 context | ||
984 | * @param[out] out 160 bits output buffer | ||
985 | * @return The operation status. | ||
986 | * @retval CRY_NOERROR if the operation succeeded. | ||
987 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
988 | * device instance. | ||
989 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
990 | * dependent. | ||
991 | * | ||
992 | * @notapi | ||
993 | */ | ||
994 | cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, | ||
995 | uint8_t *out) { | ||
996 | |||
997 | (void)cryp; | ||
998 | (void)sha1ctxp; | ||
999 | (void)out; | ||
1000 | |||
1001 | return CRY_ERR_INV_ALGO; | ||
1002 | } | ||
1003 | #endif | ||
1004 | |||
1005 | #if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
1006 | /** | ||
1007 | * @brief Hash initialization using SHA256. | ||
1008 | * | ||
1009 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1010 | * @param[out] sha256ctxp pointer to a SHA256 context to be initialized | ||
1011 | * @retval CRY_NOERROR if the operation succeeded. | ||
1012 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1013 | * device instance. | ||
1014 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1015 | * dependent. | ||
1016 | * | ||
1017 | * @notapi | ||
1018 | */ | ||
1019 | cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp) { | ||
1020 | |||
1021 | (void)cryp; | ||
1022 | (void)sha256ctxp; | ||
1023 | |||
1024 | return CRY_ERR_INV_ALGO; | ||
1025 | } | ||
1026 | |||
1027 | /** | ||
1028 | * @brief Hash update using SHA256. | ||
1029 | * | ||
1030 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1031 | * @param[in] sha256ctxp pointer to a SHA256 context | ||
1032 | * @param[in] size size of input buffer | ||
1033 | * @param[in] in buffer containing the input text | ||
1034 | * @return The operation status. | ||
1035 | * @retval CRY_NOERROR if the operation succeeded. | ||
1036 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1037 | * device instance. | ||
1038 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1039 | * dependent. | ||
1040 | * | ||
1041 | * @notapi | ||
1042 | */ | ||
1043 | cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, | ||
1044 | size_t size, const uint8_t *in) { | ||
1045 | |||
1046 | (void)cryp; | ||
1047 | (void)sha256ctxp; | ||
1048 | (void)size; | ||
1049 | (void)in; | ||
1050 | |||
1051 | return CRY_ERR_INV_ALGO; | ||
1052 | } | ||
1053 | |||
1054 | /** | ||
1055 | * @brief Hash finalization using SHA256. | ||
1056 | * | ||
1057 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1058 | * @param[in] sha256ctxp pointer to a SHA256 context | ||
1059 | * @param[out] out 256 bits output buffer | ||
1060 | * @return The operation status. | ||
1061 | * @retval CRY_NOERROR if the operation succeeded. | ||
1062 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1063 | * device instance. | ||
1064 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1065 | * dependent. | ||
1066 | * | ||
1067 | * @notapi | ||
1068 | */ | ||
1069 | cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, | ||
1070 | uint8_t *out) { | ||
1071 | |||
1072 | (void)cryp; | ||
1073 | (void)sha256ctxp; | ||
1074 | (void)out; | ||
1075 | |||
1076 | return CRY_ERR_INV_ALGO; | ||
1077 | } | ||
1078 | #endif | ||
1079 | |||
1080 | #if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
1081 | /** | ||
1082 | * @brief Hash initialization using SHA512. | ||
1083 | * | ||
1084 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1085 | * @param[out] sha512ctxp pointer to a SHA512 context to be initialized | ||
1086 | * @retval CRY_NOERROR if the operation succeeded. | ||
1087 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1088 | * device instance. | ||
1089 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1090 | * dependent. | ||
1091 | * | ||
1092 | * @notapi | ||
1093 | */ | ||
1094 | cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp) { | ||
1095 | |||
1096 | (void)cryp; | ||
1097 | (void)sha512ctxp; | ||
1098 | |||
1099 | return CRY_ERR_INV_ALGO; | ||
1100 | } | ||
1101 | |||
1102 | /** | ||
1103 | * @brief Hash update using SHA512. | ||
1104 | * | ||
1105 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1106 | * @param[in] sha512ctxp pointer to a SHA512 context | ||
1107 | * @param[in] size size of input buffer | ||
1108 | * @param[in] in buffer containing the input text | ||
1109 | * @return The operation status. | ||
1110 | * @retval CRY_NOERROR if the operation succeeded. | ||
1111 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1112 | * device instance. | ||
1113 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1114 | * dependent. | ||
1115 | * | ||
1116 | * @notapi | ||
1117 | */ | ||
1118 | cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, | ||
1119 | size_t size, const uint8_t *in) { | ||
1120 | |||
1121 | (void)cryp; | ||
1122 | (void)sha512ctxp; | ||
1123 | (void)size; | ||
1124 | (void)in; | ||
1125 | |||
1126 | return CRY_ERR_INV_ALGO; | ||
1127 | } | ||
1128 | |||
1129 | /** | ||
1130 | * @brief Hash finalization using SHA512. | ||
1131 | * | ||
1132 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1133 | * @param[in] sha512ctxp pointer to a SHA512 context | ||
1134 | * @param[out] out 512 bits output buffer | ||
1135 | * @return The operation status. | ||
1136 | * @retval CRY_NOERROR if the operation succeeded. | ||
1137 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1138 | * device instance. | ||
1139 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1140 | * dependent. | ||
1141 | * | ||
1142 | * @notapi | ||
1143 | */ | ||
1144 | cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, | ||
1145 | uint8_t *out) { | ||
1146 | |||
1147 | (void)cryp; | ||
1148 | (void)sha512ctxp; | ||
1149 | (void)out; | ||
1150 | |||
1151 | return CRY_ERR_INV_ALGO; | ||
1152 | } | ||
1153 | #endif | ||
1154 | |||
1155 | #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
1156 | /** | ||
1157 | * @brief Initializes the HMAC transient key. | ||
1158 | * @note It is the underlying implementation to decide which key sizes are | ||
1159 | * allowable. | ||
1160 | * | ||
1161 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1162 | * @param[in] size key size in bytes | ||
1163 | * @param[in] keyp pointer to the key data | ||
1164 | * @return The operation status. | ||
1165 | * @retval CRY_NOERROR if the operation succeeded. | ||
1166 | * @retval CRY_ERR_INV_ALGO if the algorithm is unsupported. | ||
1167 | * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid for | ||
1168 | * the specified algorithm. | ||
1169 | * | ||
1170 | * @notapi | ||
1171 | */ | ||
1172 | cryerror_t cry_lld_hmac_loadkey(CRYDriver *cryp, | ||
1173 | size_t size, | ||
1174 | const uint8_t *keyp) { | ||
1175 | |||
1176 | (void)cryp; | ||
1177 | (void)size; | ||
1178 | (void)keyp; | ||
1179 | |||
1180 | return CRY_ERR_INV_ALGO; | ||
1181 | } | ||
1182 | |||
1183 | /** | ||
1184 | * @brief Hash initialization using HMAC_SHA256. | ||
1185 | * | ||
1186 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1187 | * @param[out] hmacsha256ctxp pointer to a HMAC_SHA256 context to be | ||
1188 | * initialized | ||
1189 | * @return The operation status. | ||
1190 | * @retval CRY_NOERROR if the operation succeeded. | ||
1191 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1192 | * device instance. | ||
1193 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1194 | * dependent. | ||
1195 | * | ||
1196 | * @notapi | ||
1197 | */ | ||
1198 | cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, | ||
1199 | HMACSHA256Context *hmacsha256ctxp) { | ||
1200 | |||
1201 | (void)cryp; | ||
1202 | (void)hmacsha256ctxp; | ||
1203 | |||
1204 | return CRY_ERR_INV_ALGO; | ||
1205 | } | ||
1206 | |||
1207 | /** | ||
1208 | * @brief Hash update using HMAC. | ||
1209 | * | ||
1210 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1211 | * @param[in] hmacsha256ctxp pointer to a HMAC_SHA256 context | ||
1212 | * @param[in] size size of input buffer | ||
1213 | * @param[in] in buffer containing the input text | ||
1214 | * @return The operation status. | ||
1215 | * @retval CRY_NOERROR if the operation succeeded. | ||
1216 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1217 | * device instance. | ||
1218 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1219 | * dependent. | ||
1220 | * | ||
1221 | * @notapi | ||
1222 | */ | ||
1223 | cryerror_t cry_lld_HMACSHA256_update(CRYDriver *cryp, | ||
1224 | HMACSHA256Context *hmacsha256ctxp, | ||
1225 | size_t size, | ||
1226 | const uint8_t *in) { | ||
1227 | |||
1228 | (void)cryp; | ||
1229 | (void)hmacsha256ctxp; | ||
1230 | (void)size; | ||
1231 | (void)in; | ||
1232 | |||
1233 | return CRY_ERR_INV_ALGO; | ||
1234 | } | ||
1235 | |||
1236 | /** | ||
1237 | * @brief Hash finalization using HMAC. | ||
1238 | * | ||
1239 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1240 | * @param[in] hmacsha256ctxp pointer to a HMAC_SHA256 context | ||
1241 | * @param[out] out 256 bits output buffer | ||
1242 | * @return The operation status. | ||
1243 | * @retval CRY_NOERROR if the operation succeeded. | ||
1244 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1245 | * device instance. | ||
1246 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1247 | * dependent. | ||
1248 | * | ||
1249 | * @notapi | ||
1250 | */ | ||
1251 | cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, | ||
1252 | HMACSHA256Context *hmacsha256ctxp, | ||
1253 | uint8_t *out) { | ||
1254 | |||
1255 | (void)cryp; | ||
1256 | (void)hmacsha256ctxp; | ||
1257 | (void)out; | ||
1258 | |||
1259 | return CRY_ERR_INV_ALGO; | ||
1260 | } | ||
1261 | #endif | ||
1262 | |||
1263 | #if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
1264 | /** | ||
1265 | * @brief Hash initialization using HMAC_SHA512. | ||
1266 | * | ||
1267 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1268 | * @param[out] hmacsha512ctxp pointer to a HMAC_SHA512 context to be | ||
1269 | * initialized | ||
1270 | * @return The operation status. | ||
1271 | * @retval CRY_NOERROR if the operation succeeded. | ||
1272 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1273 | * device instance. | ||
1274 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1275 | * dependent. | ||
1276 | * | ||
1277 | * @notapi | ||
1278 | */ | ||
1279 | cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, | ||
1280 | HMACSHA512Context *hmacsha512ctxp) { | ||
1281 | |||
1282 | (void)cryp; | ||
1283 | (void)hmacsha512ctxp; | ||
1284 | |||
1285 | return CRY_ERR_INV_ALGO; | ||
1286 | } | ||
1287 | |||
1288 | /** | ||
1289 | * @brief Hash update using HMAC. | ||
1290 | * | ||
1291 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1292 | * @param[in] hmacsha512ctxp pointer to a HMAC_SHA512 context | ||
1293 | * @param[in] size size of input buffer | ||
1294 | * @param[in] in buffer containing the input text | ||
1295 | * @return The operation status. | ||
1296 | * @retval CRY_NOERROR if the operation succeeded. | ||
1297 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1298 | * device instance. | ||
1299 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1300 | * dependent. | ||
1301 | * | ||
1302 | * @notapi | ||
1303 | */ | ||
1304 | cryerror_t cry_lld_HMACSHA512_update(CRYDriver *cryp, | ||
1305 | HMACSHA512Context *hmacsha512ctxp, | ||
1306 | size_t size, | ||
1307 | const uint8_t *in) { | ||
1308 | |||
1309 | (void)cryp; | ||
1310 | (void)hmacsha512ctxp; | ||
1311 | (void)size; | ||
1312 | (void)in; | ||
1313 | |||
1314 | return CRY_ERR_INV_ALGO; | ||
1315 | } | ||
1316 | |||
1317 | /** | ||
1318 | * @brief Hash finalization using HMAC. | ||
1319 | * | ||
1320 | * @param[in] cryp pointer to the @p CRYDriver object | ||
1321 | * @param[in] hmacsha512ctxp pointer to a HMAC_SHA512 context | ||
1322 | * @param[out] out 512 bits output buffer | ||
1323 | * @return The operation status. | ||
1324 | * @retval CRY_NOERROR if the operation succeeded. | ||
1325 | * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this | ||
1326 | * device instance. | ||
1327 | * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation | ||
1328 | * dependent. | ||
1329 | * | ||
1330 | * @notapi | ||
1331 | */ | ||
1332 | cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, | ||
1333 | HMACSHA512Context *hmacsha512ctxp, | ||
1334 | uint8_t *out) { | ||
1335 | |||
1336 | (void)cryp; | ||
1337 | (void)hmacsha512ctxp; | ||
1338 | (void)out; | ||
1339 | |||
1340 | return CRY_ERR_INV_ALGO; | ||
1341 | } | ||
1342 | #endif | ||
1343 | |||
1344 | #endif /* HAL_USE_CRY == TRUE */ | ||
1345 | |||
1346 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_crypto_lld.h b/lib/chibios/os/hal/templates/hal_crypto_lld.h new file mode 100644 index 000000000..8b1842c1f --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_crypto_lld.h | |||
@@ -0,0 +1,376 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_crypto_lld.h | ||
19 | * @brief PLATFORM cryptographic subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup CRYPTO | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_CRYPTO_LLD_H | ||
26 | #define HAL_CRYPTO_LLD_H | ||
27 | |||
28 | #if (HAL_USE_CRY == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @name Driver capability switches | ||
36 | * @{ | ||
37 | */ | ||
38 | #define CRY_LLD_SUPPORTS_AES TRUE | ||
39 | #define CRY_LLD_SUPPORTS_AES_ECB TRUE | ||
40 | #define CRY_LLD_SUPPORTS_AES_CBC TRUE | ||
41 | #define CRY_LLD_SUPPORTS_AES_CFB TRUE | ||
42 | #define CRY_LLD_SUPPORTS_AES_CTR TRUE | ||
43 | #define CRY_LLD_SUPPORTS_AES_GCM TRUE | ||
44 | #define CRY_LLD_SUPPORTS_DES TRUE | ||
45 | #define CRY_LLD_SUPPORTS_DES_ECB TRUE | ||
46 | #define CRY_LLD_SUPPORTS_DES_CBC TRUE | ||
47 | #define CRY_LLD_SUPPORTS_SHA1 TRUE | ||
48 | #define CRY_LLD_SUPPORTS_SHA256 TRUE | ||
49 | #define CRY_LLD_SUPPORTS_SHA512 TRUE | ||
50 | #define CRY_LLD_SUPPORTS_HMAC_SHA256 TRUE | ||
51 | #define CRY_LLD_SUPPORTS_HMAC_SHA512 TRUE | ||
52 | /** @} */ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Driver pre-compile time settings. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /** | ||
59 | * @name PLATFORM configuration options | ||
60 | * @{ | ||
61 | */ | ||
62 | /** | ||
63 | * @brief CRY1 driver enable switch. | ||
64 | * @details If set to @p TRUE the support for CRY1 is included. | ||
65 | * @note The default is @p FALSE. | ||
66 | */ | ||
67 | #if !defined(PLATFORM_CRY_USE_CRY1) || defined(__DOXYGEN__) | ||
68 | #define PLATFORM_CRY_USE_CRY1 FALSE | ||
69 | #endif | ||
70 | /** @} */ | ||
71 | |||
72 | /*===========================================================================*/ | ||
73 | /* Derived constants and error checks. */ | ||
74 | /*===========================================================================*/ | ||
75 | |||
76 | /*===========================================================================*/ | ||
77 | /* Driver data structures and types. */ | ||
78 | /*===========================================================================*/ | ||
79 | |||
80 | /** | ||
81 | * @brief CRY key identifier type. | ||
82 | */ | ||
83 | typedef uint32_t crykey_t; | ||
84 | |||
85 | /** | ||
86 | * @brief Type of a structure representing an CRY driver. | ||
87 | */ | ||
88 | typedef struct CRYDriver CRYDriver; | ||
89 | |||
90 | /** | ||
91 | * @brief Driver configuration structure. | ||
92 | * @note It could be empty on some architectures. | ||
93 | */ | ||
94 | typedef struct { | ||
95 | uint32_t dummy; | ||
96 | } CRYConfig; | ||
97 | |||
98 | /** | ||
99 | * @brief Structure representing an CRY driver. | ||
100 | */ | ||
101 | struct CRYDriver { | ||
102 | /** | ||
103 | * @brief Driver state. | ||
104 | */ | ||
105 | crystate_t state; | ||
106 | /** | ||
107 | * @brief Current configuration data. | ||
108 | */ | ||
109 | const CRYConfig *config; | ||
110 | #if defined(CRY_DRIVER_EXT_FIELDS) | ||
111 | CRY_DRIVER_EXT_FIELDS | ||
112 | #endif | ||
113 | /* End of the mandatory fields.*/ | ||
114 | }; | ||
115 | |||
116 | #if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) | ||
117 | /** | ||
118 | * @brief Type of a SHA1 context. | ||
119 | */ | ||
120 | typedef struct { | ||
121 | uint32_t dummy; | ||
122 | } SHA1Context; | ||
123 | #endif | ||
124 | |||
125 | #if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
126 | /** | ||
127 | * @brief Type of a SHA256 context. | ||
128 | */ | ||
129 | typedef struct { | ||
130 | uint32_t dummy; | ||
131 | } SHA256Context; | ||
132 | #endif | ||
133 | |||
134 | #if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
135 | /** | ||
136 | * @brief Type of a SHA512 context. | ||
137 | */ | ||
138 | typedef struct { | ||
139 | uint32_t dummy; | ||
140 | } SHA512Context; | ||
141 | #endif | ||
142 | |||
143 | #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
144 | /** | ||
145 | * @brief Type of a HMAC_SHA256 context. | ||
146 | */ | ||
147 | typedef struct { | ||
148 | uint32_t dummy; | ||
149 | } HMACSHA256Context; | ||
150 | #endif | ||
151 | |||
152 | #if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
153 | /** | ||
154 | * @brief Type of a HMAC_SHA512 context. | ||
155 | */ | ||
156 | typedef struct { | ||
157 | uint32_t dummy; | ||
158 | } HMACSHA512Context; | ||
159 | #endif | ||
160 | |||
161 | /*===========================================================================*/ | ||
162 | /* Driver macros. */ | ||
163 | /*===========================================================================*/ | ||
164 | |||
165 | /*===========================================================================*/ | ||
166 | /* External declarations. */ | ||
167 | /*===========================================================================*/ | ||
168 | |||
169 | #if (PLATFORM_CRY_USE_CRY1 == TRUE) && !defined(__DOXYGEN__) | ||
170 | extern CRYDriver CRYD1; | ||
171 | #endif | ||
172 | |||
173 | #ifdef __cplusplus | ||
174 | extern "C" { | ||
175 | #endif | ||
176 | void cry_lld_init(void); | ||
177 | void cry_lld_start(CRYDriver *cryp); | ||
178 | void cry_lld_stop(CRYDriver *cryp); | ||
179 | #if (CRY_LLD_SUPPORTS_AES == TRUE) || \ | ||
180 | (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || \ | ||
181 | (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || \ | ||
182 | (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || \ | ||
183 | (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || \ | ||
184 | (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || \ | ||
185 | defined(__DOXYGEN__) | ||
186 | cryerror_t cry_lld_aes_loadkey(CRYDriver *cryp, | ||
187 | size_t size, | ||
188 | const uint8_t *keyp); | ||
189 | #endif | ||
190 | #if (CRY_LLD_SUPPORTS_AES == TRUE) || defined(__DOXYGEN__) | ||
191 | cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, | ||
192 | crykey_t key_id, | ||
193 | const uint8_t *in, | ||
194 | uint8_t *out); | ||
195 | cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, | ||
196 | crykey_t key_id, | ||
197 | const uint8_t *in, | ||
198 | uint8_t *out); | ||
199 | #endif | ||
200 | #if (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || defined(__DOXYGEN__) | ||
201 | cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, | ||
202 | crykey_t key_id, | ||
203 | size_t size, | ||
204 | const uint8_t *in, | ||
205 | uint8_t *out); | ||
206 | cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, | ||
207 | crykey_t key_id, | ||
208 | size_t size, | ||
209 | const uint8_t *in, | ||
210 | uint8_t *out); | ||
211 | #endif | ||
212 | #if (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || defined(__DOXYGEN__) | ||
213 | cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, | ||
214 | crykey_t key_id, | ||
215 | size_t size, | ||
216 | const uint8_t *in, | ||
217 | uint8_t *out, | ||
218 | const uint8_t *iv); | ||
219 | cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, | ||
220 | crykey_t key_id, | ||
221 | size_t size, | ||
222 | const uint8_t *in, | ||
223 | uint8_t *out, | ||
224 | const uint8_t *iv); | ||
225 | #endif | ||
226 | #if (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || defined(__DOXYGEN__) | ||
227 | cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, | ||
228 | crykey_t key_id, | ||
229 | size_t size, | ||
230 | const uint8_t *in, | ||
231 | uint8_t *out, | ||
232 | const uint8_t *iv); | ||
233 | cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, | ||
234 | crykey_t key_id, | ||
235 | size_t size, | ||
236 | const uint8_t *in, | ||
237 | uint8_t *out, | ||
238 | const uint8_t *iv); | ||
239 | #endif | ||
240 | #if (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || defined(__DOXYGEN__) | ||
241 | cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, | ||
242 | crykey_t key_id, | ||
243 | size_t size, | ||
244 | const uint8_t *in, | ||
245 | uint8_t *out, | ||
246 | const uint8_t *iv); | ||
247 | cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, | ||
248 | crykey_t key_id, | ||
249 | size_t size, | ||
250 | const uint8_t *in, | ||
251 | uint8_t *out, | ||
252 | const uint8_t *iv); | ||
253 | #endif | ||
254 | #if (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || defined(__DOXYGEN__) | ||
255 | cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, | ||
256 | crykey_t key_id, | ||
257 | size_t auth_size, | ||
258 | const uint8_t *auth_in, | ||
259 | size_t text_size, | ||
260 | const uint8_t *text_in, | ||
261 | uint8_t *text_out, | ||
262 | const uint8_t *iv, | ||
263 | size_t tag_size, | ||
264 | uint8_t *tag_out); | ||
265 | cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, | ||
266 | crykey_t key_id, | ||
267 | size_t auth_size, | ||
268 | const uint8_t *auth_in, | ||
269 | size_t text_size, | ||
270 | const uint8_t *text_in, | ||
271 | uint8_t *text_out, | ||
272 | const uint8_t *iv, | ||
273 | size_t tag_size, | ||
274 | const uint8_t *tag_in); | ||
275 | #endif | ||
276 | #if (CRY_LLD_SUPPORTS_DES == TRUE) || \ | ||
277 | (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || \ | ||
278 | (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || \ | ||
279 | defined(__DOXYGEN__) | ||
280 | cryerror_t cry_lld_des_loadkey(CRYDriver *cryp, | ||
281 | size_t size, | ||
282 | const uint8_t *keyp); | ||
283 | #endif | ||
284 | #if (CRY_LLD_SUPPORTS_DES == TRUE) || defined(__DOXYGEN__) | ||
285 | cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, | ||
286 | crykey_t key_id, | ||
287 | const uint8_t *in, | ||
288 | uint8_t *out); | ||
289 | cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, | ||
290 | crykey_t key_id, | ||
291 | const uint8_t *in, | ||
292 | uint8_t *out); | ||
293 | #endif | ||
294 | #if (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || defined(__DOXYGEN__) | ||
295 | cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, | ||
296 | crykey_t key_id, | ||
297 | size_t size, | ||
298 | const uint8_t *in, | ||
299 | uint8_t *out); | ||
300 | cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, | ||
301 | crykey_t key_id, | ||
302 | size_t size, | ||
303 | const uint8_t *in, | ||
304 | uint8_t *out); | ||
305 | #endif | ||
306 | #if (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || defined(__DOXYGEN__) | ||
307 | cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, | ||
308 | crykey_t key_id, | ||
309 | size_t size, | ||
310 | const uint8_t *in, | ||
311 | uint8_t *out, | ||
312 | const uint8_t *iv); | ||
313 | cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, | ||
314 | crykey_t key_id, | ||
315 | size_t size, | ||
316 | const uint8_t *in, | ||
317 | uint8_t *out, | ||
318 | const uint8_t *iv); | ||
319 | #endif | ||
320 | #if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) | ||
321 | cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp); | ||
322 | cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, | ||
323 | size_t size, const uint8_t *in); | ||
324 | cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, | ||
325 | uint8_t *out); | ||
326 | #endif | ||
327 | #if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
328 | cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp); | ||
329 | cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, | ||
330 | size_t size, const uint8_t *in); | ||
331 | cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, | ||
332 | uint8_t *out); | ||
333 | #endif | ||
334 | #if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
335 | cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp); | ||
336 | cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, | ||
337 | size_t size, const uint8_t *in); | ||
338 | cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, | ||
339 | uint8_t *out); | ||
340 | #endif | ||
341 | #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || \ | ||
342 | (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || \ | ||
343 | defined(__DOXYGEN__) | ||
344 | cryerror_t cry_lld_hmac_loadkey(CRYDriver *cryp, | ||
345 | size_t size, | ||
346 | const uint8_t *keyp); | ||
347 | #endif | ||
348 | #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
349 | cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, | ||
350 | HMACSHA256Context *hmacsha256ctxp); | ||
351 | cryerror_t cry_lld_HMACSHA256_update(CRYDriver *cryp, | ||
352 | HMACSHA256Context *hmacsha256ctxp, | ||
353 | size_t size, const uint8_t *in); | ||
354 | cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, | ||
355 | HMACSHA256Context *hmacsha256ctxp, | ||
356 | uint8_t *out); | ||
357 | #endif | ||
358 | #if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
359 | cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, | ||
360 | HMACSHA512Context *hmacsha512ctxp); | ||
361 | cryerror_t cry_lld_HMACSHA512_update(CRYDriver *cryp, | ||
362 | HMACSHA512Context *hmacsha512ctxp, | ||
363 | size_t size, const uint8_t *in); | ||
364 | cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, | ||
365 | HMACSHA512Context *hmacsha512ctxp, | ||
366 | uint8_t *out); | ||
367 | #endif | ||
368 | #ifdef __cplusplus | ||
369 | } | ||
370 | #endif | ||
371 | |||
372 | #endif /* HAL_USE_CRY == TRUE */ | ||
373 | |||
374 | #endif /* HAL_CRYPTO_LLD_H */ | ||
375 | |||
376 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_dac_lld.c b/lib/chibios/os/hal/templates/hal_dac_lld.c new file mode 100644 index 000000000..13f325b56 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_dac_lld.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_dac_lld.c | ||
19 | * @brief PLATFORM DAC subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup DAC | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_DAC == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** @brief DAC1 driver identifier.*/ | ||
38 | #if (PLATFORM_DAC_USE_DAC1 == TRUE) || defined(__DOXYGEN__) | ||
39 | DACDriver DACD1; | ||
40 | #endif | ||
41 | |||
42 | /*===========================================================================*/ | ||
43 | /* Driver local variables. */ | ||
44 | /*===========================================================================*/ | ||
45 | |||
46 | /*===========================================================================*/ | ||
47 | /* Driver local functions. */ | ||
48 | /*===========================================================================*/ | ||
49 | |||
50 | /*===========================================================================*/ | ||
51 | /* Driver interrupt handlers. */ | ||
52 | /*===========================================================================*/ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Driver exported functions. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /** | ||
59 | * @brief Low level DAC driver initialization. | ||
60 | * | ||
61 | * @notapi | ||
62 | */ | ||
63 | void dac_lld_init(void) { | ||
64 | |||
65 | #if PLATFORM_DAC_USE_DAC1 == TRUE | ||
66 | dacObjectInit(&DACD1); | ||
67 | #endif | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * @brief Configures and activates the DAC peripheral. | ||
72 | * | ||
73 | * @param[in] dacp pointer to the @p DACDriver object | ||
74 | * | ||
75 | * @notapi | ||
76 | */ | ||
77 | void dac_lld_start(DACDriver *dacp) { | ||
78 | |||
79 | /* If the driver is in DAC_STOP state then a full initialization is | ||
80 | required.*/ | ||
81 | if (dacp->state == DAC_STOP) { | ||
82 | /* Enabling the clock source.*/ | ||
83 | #if PLATFORM_DAC_USE_DAC1 == TRUE | ||
84 | if (&DACD1 == dacp) { | ||
85 | |||
86 | } | ||
87 | #endif | ||
88 | } | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * @brief Deactivates the DAC peripheral. | ||
93 | * | ||
94 | * @param[in] dacp pointer to the @p DACDriver object | ||
95 | * | ||
96 | * @notapi | ||
97 | */ | ||
98 | void dac_lld_stop(DACDriver *dacp) { | ||
99 | |||
100 | /* If in ready state then disables the DAC clock.*/ | ||
101 | if (dacp->state == DAC_READY) { | ||
102 | |||
103 | #if PLATFORM_DAC_USE_DAC1 == TRUE | ||
104 | if (&DACD1 == dacp) { | ||
105 | |||
106 | } | ||
107 | #endif | ||
108 | } | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * @brief Outputs a value directly on a DAC channel. | ||
113 | * | ||
114 | * @param[in] dacp pointer to the @p DACDriver object | ||
115 | * @param[in] channel DAC channel number | ||
116 | * @param[in] sample value to be output | ||
117 | * | ||
118 | * @api | ||
119 | */ | ||
120 | void dac_lld_put_channel(DACDriver *dacp, | ||
121 | dacchannel_t channel, | ||
122 | dacsample_t sample) { | ||
123 | |||
124 | (void)dacp; | ||
125 | (void)channel; | ||
126 | (void)sample; | ||
127 | } | ||
128 | |||
129 | /** | ||
130 | * @brief Starts a DAC conversion. | ||
131 | * @details Starts an asynchronous conversion operation. | ||
132 | * @note In @p DAC_DHRM_8BIT_RIGHT mode the parameters passed to the | ||
133 | * callback are wrong because two samples are packed in a single | ||
134 | * dacsample_t element. This will not be corrected, do not rely | ||
135 | * on those parameters. | ||
136 | * @note In @p DAC_DHRM_8BIT_RIGHT_DUAL mode two samples are treated | ||
137 | * as a single 16 bits sample and packed into a single dacsample_t | ||
138 | * element. The num_channels must be set to one in the group | ||
139 | * conversion configuration structure. | ||
140 | * | ||
141 | * @param[in] dacp pointer to the @p DACDriver object | ||
142 | * | ||
143 | * @notapi | ||
144 | */ | ||
145 | void dac_lld_start_conversion(DACDriver *dacp) { | ||
146 | |||
147 | (void)dacp; | ||
148 | } | ||
149 | |||
150 | /** | ||
151 | * @brief Stops an ongoing conversion. | ||
152 | * @details This function stops the currently ongoing conversion and returns | ||
153 | * the driver in the @p DAC_READY state. If there was no conversion | ||
154 | * being processed then the function does nothing. | ||
155 | * | ||
156 | * @param[in] dacp pointer to the @p DACDriver object | ||
157 | * | ||
158 | * @iclass | ||
159 | */ | ||
160 | void dac_lld_stop_conversion(DACDriver *dacp) { | ||
161 | |||
162 | (void)dacp; | ||
163 | } | ||
164 | |||
165 | #endif /* HAL_USE_DAC == TRUE */ | ||
166 | |||
167 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_dac_lld.h b/lib/chibios/os/hal/templates/hal_dac_lld.h new file mode 100644 index 000000000..7bfccda7a --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_dac_lld.h | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_dac_lld.h | ||
19 | * @brief PLATFORM DAC subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup DAC | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_DAC_LLD_H | ||
26 | #define HAL_DAC_LLD_H | ||
27 | |||
28 | #if (HAL_USE_DAC == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @brief Maximum number of DAC channels per unit. | ||
36 | */ | ||
37 | #define DAC_MAX_CHANNELS 2 | ||
38 | |||
39 | /*===========================================================================*/ | ||
40 | /* Driver pre-compile time settings. */ | ||
41 | /*===========================================================================*/ | ||
42 | |||
43 | /** | ||
44 | * @name Configuration options | ||
45 | * @{ | ||
46 | */ | ||
47 | /** | ||
48 | * @brief DAC1 CH1 driver enable switch. | ||
49 | * @details If set to @p TRUE the support for DAC1 channel 1 is included. | ||
50 | * @note The default is @p FALSE. | ||
51 | */ | ||
52 | #if !defined(PLATFORM_DAC_USE_DAC1) || defined(__DOXYGEN__) | ||
53 | #define PLATFORM_DAC_USE_DAC1 FALSE | ||
54 | #endif | ||
55 | /** @} */ | ||
56 | |||
57 | /*===========================================================================*/ | ||
58 | /* Derived constants and error checks. */ | ||
59 | /*===========================================================================*/ | ||
60 | |||
61 | /*===========================================================================*/ | ||
62 | /* Driver data structures and types. */ | ||
63 | /*===========================================================================*/ | ||
64 | |||
65 | /** | ||
66 | * @brief Type of a DAC channel index. | ||
67 | */ | ||
68 | typedef uint32_t dacchannel_t; | ||
69 | |||
70 | /** | ||
71 | * @brief Type representing a DAC sample. | ||
72 | */ | ||
73 | typedef uint16_t dacsample_t; | ||
74 | |||
75 | /** | ||
76 | * @brief Possible DAC failure causes. | ||
77 | * @note Error codes are architecture dependent and should not relied | ||
78 | * upon. | ||
79 | */ | ||
80 | typedef enum { | ||
81 | DAC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */ | ||
82 | DAC_ERR_UNDERFLOW = 1 /**< DAC overflow condition. */ | ||
83 | } dacerror_t; | ||
84 | |||
85 | /*===========================================================================*/ | ||
86 | /* Driver macros. */ | ||
87 | /*===========================================================================*/ | ||
88 | |||
89 | /** | ||
90 | * @brief Low level fields of the DAC driver structure. | ||
91 | */ | ||
92 | #define dac_lld_driver_fields \ | ||
93 | /* Dummy field, it is not needed.*/ \ | ||
94 | uint32_t dummy | ||
95 | |||
96 | /** | ||
97 | * @brief Low level fields of the DAC configuration structure. | ||
98 | */ | ||
99 | #define dac_lld_config_fields \ | ||
100 | /* Dummy configuration, it is not needed.*/ \ | ||
101 | uint32_t dummy | ||
102 | |||
103 | /** | ||
104 | * @brief Low level fields of the DAC group configuration structure. | ||
105 | */ | ||
106 | #define dac_lld_conversion_group_fields \ | ||
107 | /* Dummy configuration, it is not needed.*/ \ | ||
108 | uint32_t dummy | ||
109 | |||
110 | /*===========================================================================*/ | ||
111 | /* External declarations. */ | ||
112 | /*===========================================================================*/ | ||
113 | |||
114 | #if (PLATFORM_DAC_USE_DAC1 == TRUE) && !defined(__DOXYGEN__) | ||
115 | extern DACDriver DACD1; | ||
116 | #endif | ||
117 | |||
118 | #ifdef __cplusplus | ||
119 | extern "C" { | ||
120 | #endif | ||
121 | void dac_lld_init(void); | ||
122 | void dac_lld_start(DACDriver *dacp); | ||
123 | void dac_lld_stop(DACDriver *dacp); | ||
124 | void dac_lld_put_channel(DACDriver *dacp, | ||
125 | dacchannel_t channel, | ||
126 | dacsample_t sample); | ||
127 | void dac_lld_start_conversion(DACDriver *dacp); | ||
128 | void dac_lld_stop_conversion(DACDriver *dacp); | ||
129 | #ifdef __cplusplus | ||
130 | } | ||
131 | #endif | ||
132 | |||
133 | #endif /* HAL_USE_DAC == TRUE */ | ||
134 | |||
135 | #endif /* HAL_DAC_LLD_H */ | ||
136 | |||
137 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_efl_lld.c b/lib/chibios/os/hal/templates/hal_efl_lld.c new file mode 100644 index 000000000..6ec053e54 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_efl_lld.c | |||
@@ -0,0 +1,365 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_efl_lld.c | ||
19 | * @brief PLATFORM Embedded Flash subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup HAL_EFL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_EFL == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @brief EFL1 driver identifier. | ||
39 | */ | ||
40 | #if (PLATFORM_EFL_USE_EFL1 == TRUE) || defined(__DOXYGEN__) | ||
41 | EFlashDriver EFLD1; | ||
42 | #endif | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver local variables and types. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | static const flash_descriptor_t efl_lld_descriptor = { | ||
49 | .attributes = FLASH_ATTR_ERASED_IS_ONE | | ||
50 | FLASH_ATTR_MEMORY_MAPPED | | ||
51 | FLASH_ATTR_ECC_CAPABLE | | ||
52 | FLASH_ATTR_ECC_ZERO_LINE_CAPABLE, | ||
53 | .page_size = 0, | ||
54 | .sectors_count = 0, | ||
55 | .sectors = NULL, | ||
56 | .sectors_size = 0, | ||
57 | .address = (uint8_t *)0, | ||
58 | .size = 0 | ||
59 | }; | ||
60 | |||
61 | /*===========================================================================*/ | ||
62 | /* Driver local functions. */ | ||
63 | /*===========================================================================*/ | ||
64 | |||
65 | /*===========================================================================*/ | ||
66 | /* Driver interrupt handlers. */ | ||
67 | /*===========================================================================*/ | ||
68 | |||
69 | /*===========================================================================*/ | ||
70 | /* Driver exported functions. */ | ||
71 | /*===========================================================================*/ | ||
72 | |||
73 | /** | ||
74 | * @brief Low level Embedded Flash driver initialization. | ||
75 | * | ||
76 | * @notapi | ||
77 | */ | ||
78 | void efl_lld_init(void) { | ||
79 | |||
80 | #if PLATFORM_EFL_USE_EFL1 == TRUE | ||
81 | /* Driver initialization.*/ | ||
82 | eflObjectInit(&EFLD1); | ||
83 | #endif | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * @brief Configures and activates the Embedded Flash peripheral. | ||
88 | * | ||
89 | * @param[in] eflp pointer to a @p EFlashDriver structure | ||
90 | * | ||
91 | * @notapi | ||
92 | */ | ||
93 | void efl_lld_start(EFlashDriver *eflp) { | ||
94 | |||
95 | if (eflp->state == FLASH_STOP) { | ||
96 | /* Enables the peripheral.*/ | ||
97 | #if PLATFORM_EFL_USE_EFL1 == TRUE | ||
98 | if (&EFLD1 == eflp) { | ||
99 | |||
100 | } | ||
101 | #endif | ||
102 | } | ||
103 | /* Configures the peripheral.*/ | ||
104 | |||
105 | } | ||
106 | |||
107 | /** | ||
108 | * @brief Deactivates the Embedded Flash peripheral. | ||
109 | * | ||
110 | * @param[in] eflp pointer to a @p EFlashDriver structure | ||
111 | * | ||
112 | * @notapi | ||
113 | */ | ||
114 | void efl_lld_stop(EFlashDriver *eflp) { | ||
115 | |||
116 | if (eflp->state == FLASH_READY) { | ||
117 | /* Resets the peripheral.*/ | ||
118 | |||
119 | /* Disables the peripheral.*/ | ||
120 | #if PLATFORM_EFL_USE_EFL1 == TRUE | ||
121 | if (&EFLD1 == eflp) { | ||
122 | |||
123 | } | ||
124 | #endif | ||
125 | } | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * @brief Gets the flash descriptor structure. | ||
130 | * | ||
131 | * @param[in] instance pointer to a @p EFlashDriver instance | ||
132 | * @return A flash device descriptor. | ||
133 | * | ||
134 | * @notapi | ||
135 | */ | ||
136 | const flash_descriptor_t *efl_lld_get_descriptor(void *instance) { | ||
137 | |||
138 | (void)instance; | ||
139 | |||
140 | return &efl_lld_descriptor; | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * @brief Read operation. | ||
145 | * | ||
146 | * @param[in] instance pointer to a @p EFlashDriver instance | ||
147 | * @param[in] offset flash offset | ||
148 | * @param[in] n number of bytes to be read | ||
149 | * @param[out] rp pointer to the data buffer | ||
150 | * @return An error code. | ||
151 | * @retval FLASH_NO_ERROR if there is no erase operation in progress. | ||
152 | * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. | ||
153 | * @retval FLASH_ERROR_READ if the read operation failed. | ||
154 | * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. | ||
155 | * | ||
156 | * @notapi | ||
157 | */ | ||
158 | flash_error_t efl_lld_read(void *instance, flash_offset_t offset, | ||
159 | size_t n, uint8_t *rp) { | ||
160 | EFlashDriver *devp = (EFlashDriver *)instance; | ||
161 | flash_error_t err = FLASH_NO_ERROR; | ||
162 | |||
163 | osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U)); | ||
164 | osalDbgCheck(((size_t)offset + n) <= (size_t)efl_lld_descriptor.size); | ||
165 | osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), | ||
166 | "invalid state"); | ||
167 | |||
168 | /* No reading while erasing.*/ | ||
169 | if (devp->state == FLASH_ERASE) { | ||
170 | return FLASH_BUSY_ERASING; | ||
171 | } | ||
172 | |||
173 | /* FLASH_READY state while the operation is performed.*/ | ||
174 | devp->state = FLASH_READ; | ||
175 | |||
176 | /* IMPLEMENT */ | ||
177 | |||
178 | /* Ready state again.*/ | ||
179 | devp->state = FLASH_READY; | ||
180 | |||
181 | return err; | ||
182 | |||
183 | } | ||
184 | |||
185 | /** | ||
186 | * @brief Program operation. | ||
187 | * @note The device supports ECC, it is only possible to write erased | ||
188 | * pages once except when writing all zeroes. | ||
189 | * | ||
190 | * @param[in] instance pointer to a @p EFlashDriver instance | ||
191 | * @param[in] offset flash offset | ||
192 | * @param[in] n number of bytes to be programmed | ||
193 | * @param[in] pp pointer to the data buffer | ||
194 | * @return An error code. | ||
195 | * @retval FLASH_NO_ERROR if there is no erase operation in progress. | ||
196 | * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. | ||
197 | * @retval FLASH_ERROR_PROGRAM if the program operation failed. | ||
198 | * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. | ||
199 | * | ||
200 | * @notapi | ||
201 | */ | ||
202 | flash_error_t efl_lld_program(void *instance, flash_offset_t offset, | ||
203 | size_t n, const uint8_t *pp) { | ||
204 | EFlashDriver *devp = (EFlashDriver *)instance; | ||
205 | flash_error_t err = FLASH_NO_ERROR; | ||
206 | |||
207 | osalDbgCheck((instance != NULL) && (pp != NULL) && (n > 0U)); | ||
208 | osalDbgCheck(((size_t)offset + n) <= (size_t)efl_lld_descriptor.size); | ||
209 | |||
210 | osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), | ||
211 | "invalid state"); | ||
212 | |||
213 | /* No programming while erasing.*/ | ||
214 | if (devp->state == FLASH_ERASE) { | ||
215 | return FLASH_BUSY_ERASING; | ||
216 | } | ||
217 | |||
218 | /* FLASH_PGM state while the operation is performed.*/ | ||
219 | devp->state = FLASH_PGM; | ||
220 | |||
221 | /* IMPLEMENT */ | ||
222 | |||
223 | /* Ready state again.*/ | ||
224 | devp->state = FLASH_READY; | ||
225 | |||
226 | return err; | ||
227 | } | ||
228 | |||
229 | /** | ||
230 | * @brief Starts a whole-device erase operation. | ||
231 | * @note This function only erases bank 2 if it is present. Bank 1 is not | ||
232 | * touched because it is where the program is running on. | ||
233 | * Pages on bank 1 can be individually erased. | ||
234 | * | ||
235 | * @param[in] instance pointer to a @p EFlashDriver instance | ||
236 | * @return An error code. | ||
237 | * @retval FLASH_NO_ERROR if there is no erase operation in progress. | ||
238 | * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. | ||
239 | * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. | ||
240 | * | ||
241 | * @notapi | ||
242 | */ | ||
243 | flash_error_t efl_lld_start_erase_all(void *instance) { | ||
244 | EFlashDriver *devp = (EFlashDriver *)instance; | ||
245 | |||
246 | osalDbgCheck(instance != NULL); | ||
247 | osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), | ||
248 | "invalid state"); | ||
249 | |||
250 | /* No erasing while erasing.*/ | ||
251 | if (devp->state == FLASH_ERASE) { | ||
252 | return FLASH_BUSY_ERASING; | ||
253 | } | ||
254 | |||
255 | /* FLASH_PGM state while the operation is performed.*/ | ||
256 | devp->state = FLASH_ERASE; | ||
257 | |||
258 | /* IMPLEMENT */ | ||
259 | |||
260 | return FLASH_NO_ERROR; | ||
261 | } | ||
262 | |||
263 | /** | ||
264 | * @brief Starts an sector erase operation. | ||
265 | * | ||
266 | * @param[in] instance pointer to a @p EFlashDriver instance | ||
267 | * @param[in] sector sector to be erased | ||
268 | * @return An error code. | ||
269 | * @retval FLASH_NO_ERROR if there is no erase operation in progress. | ||
270 | * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. | ||
271 | * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. | ||
272 | * | ||
273 | * @notapi | ||
274 | */ | ||
275 | flash_error_t efl_lld_start_erase_sector(void *instance, | ||
276 | flash_sector_t sector) { | ||
277 | EFlashDriver *devp = (EFlashDriver *)instance; | ||
278 | |||
279 | osalDbgCheck(instance != NULL); | ||
280 | osalDbgCheck(sector < efl_lld_descriptor.sectors_count); | ||
281 | osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), | ||
282 | "invalid state"); | ||
283 | |||
284 | /* No erasing while erasing.*/ | ||
285 | if (devp->state == FLASH_ERASE) { | ||
286 | return FLASH_BUSY_ERASING; | ||
287 | } | ||
288 | |||
289 | /* FLASH_PGM state while the operation is performed.*/ | ||
290 | devp->state = FLASH_ERASE; | ||
291 | |||
292 | /* IMPLEMENT */ | ||
293 | |||
294 | return FLASH_NO_ERROR; | ||
295 | } | ||
296 | |||
297 | /** | ||
298 | * @brief Queries the driver for erase operation progress. | ||
299 | * | ||
300 | * @param[in] instance pointer to a @p EFlashDriver instance | ||
301 | * @param[out] msec recommended time, in milliseconds, that | ||
302 | * should be spent before calling this | ||
303 | * function again, can be @p NULL | ||
304 | * @return An error code. | ||
305 | * @retval FLASH_NO_ERROR if there is no erase operation in progress. | ||
306 | * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. | ||
307 | * @retval FLASH_ERROR_ERASE if the erase operation failed. | ||
308 | * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. | ||
309 | * | ||
310 | * @api | ||
311 | */ | ||
312 | flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec) { | ||
313 | EFlashDriver *devp = (EFlashDriver *)instance; | ||
314 | flash_error_t err = FLASH_NO_ERROR; | ||
315 | |||
316 | (void)msec; | ||
317 | |||
318 | /* If there is an erase in progress then the device must be checked.*/ | ||
319 | if (devp->state == FLASH_ERASE) { | ||
320 | |||
321 | /* IMPLEMENT */ | ||
322 | |||
323 | } | ||
324 | |||
325 | return err; | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * @brief Returns the erase state of a sector. | ||
330 | * | ||
331 | * @param[in] instance pointer to a @p EFlashDriver instance | ||
332 | * @param[in] sector sector to be verified | ||
333 | * @return An error code. | ||
334 | * @retval FLASH_NO_ERROR if the sector is erased. | ||
335 | * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. | ||
336 | * @retval FLASH_ERROR_VERIFY if the verify operation failed. | ||
337 | * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. | ||
338 | * | ||
339 | * @notapi | ||
340 | */ | ||
341 | flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector) { | ||
342 | EFlashDriver *devp = (EFlashDriver *)instance; | ||
343 | flash_error_t err = FLASH_NO_ERROR; | ||
344 | |||
345 | osalDbgCheck(instance != NULL); | ||
346 | osalDbgCheck(sector < efl_lld_descriptor.sectors_count); | ||
347 | osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), | ||
348 | "invalid state"); | ||
349 | |||
350 | /* No verifying while erasing.*/ | ||
351 | if (devp->state == FLASH_ERASE) { | ||
352 | return FLASH_BUSY_ERASING; | ||
353 | } | ||
354 | |||
355 | /* IMPLEMENT */ | ||
356 | |||
357 | /* Ready state again.*/ | ||
358 | devp->state = FLASH_READY; | ||
359 | |||
360 | return err; | ||
361 | } | ||
362 | |||
363 | #endif /* HAL_USE_EFL == TRUE */ | ||
364 | |||
365 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_efl_lld.h b/lib/chibios/os/hal/templates/hal_efl_lld.h new file mode 100644 index 000000000..07cc95ea1 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_efl_lld.h | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_efl_lld.h | ||
19 | * @brief PLATFORM Embedded Flash subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup HAL_EFL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_EFL_LLD_H | ||
26 | #define HAL_EFL_LLD_H | ||
27 | |||
28 | #if (HAL_USE_EFL == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Driver pre-compile time settings. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /** | ||
39 | * @name PLATFORM configuration options | ||
40 | * @{ | ||
41 | */ | ||
42 | /** | ||
43 | * @brief EFL1 driver enable switch. | ||
44 | * @details If set to @p TRUE the support for EFL1 is included. | ||
45 | * @note The default is @p FALSE. | ||
46 | */ | ||
47 | #if !defined(PLATFORM_EFL_USE_EFL1) || defined(__DOXYGEN__) | ||
48 | #define PLATFORM_EFL_USE_EFL1 FALSE | ||
49 | #endif | ||
50 | /** @} */ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Derived constants and error checks. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver data structures and types. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /*===========================================================================*/ | ||
61 | /* Driver macros. */ | ||
62 | /*===========================================================================*/ | ||
63 | |||
64 | /** | ||
65 | * @brief Low level fields of the embedded flash driver structure. | ||
66 | */ | ||
67 | #define efl_lld_driver_fields \ | ||
68 | /* Dummy field, it is not needed.*/ \ | ||
69 | uint32_t dummy | ||
70 | |||
71 | /** | ||
72 | * @brief Low level fields of the embedded flash configuration structure. | ||
73 | */ | ||
74 | #define efl_lld_config_fields \ | ||
75 | /* Dummy configuration, it is not needed.*/ \ | ||
76 | uint32_t dummy | ||
77 | |||
78 | /*===========================================================================*/ | ||
79 | /* External declarations. */ | ||
80 | /*===========================================================================*/ | ||
81 | |||
82 | #if (PLATFORM_EFL_USE_EFL1 == TRUE) && !defined(__DOXYGEN__) | ||
83 | extern EFlashDriver EFLD1; | ||
84 | #endif | ||
85 | |||
86 | #ifdef __cplusplus | ||
87 | extern "C" { | ||
88 | #endif | ||
89 | void efl_lld_init(void); | ||
90 | void efl_lld_start(EFlashDriver *eflp); | ||
91 | void efl_lld_stop(EFlashDriver *eflp); | ||
92 | const flash_descriptor_t *efl_lld_get_descriptor(void *instance); | ||
93 | flash_error_t efl_lld_read(void *instance, flash_offset_t offset, | ||
94 | size_t n, uint8_t *rp); | ||
95 | flash_error_t efl_lld_program(void *instance, flash_offset_t offset, | ||
96 | size_t n, const uint8_t *pp); | ||
97 | flash_error_t efl_lld_start_erase_all(void *instance); | ||
98 | flash_error_t efl_lld_start_erase_sector(void *instance, | ||
99 | flash_sector_t sector); | ||
100 | flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec); | ||
101 | flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector); | ||
102 | #ifdef __cplusplus | ||
103 | } | ||
104 | #endif | ||
105 | |||
106 | #endif /* HAL_USE_EFL == TRUE */ | ||
107 | |||
108 | #endif /* HAL_EFL_LLD_H */ | ||
109 | |||
110 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_gpt_lld.c b/lib/chibios/os/hal/templates/hal_gpt_lld.c new file mode 100644 index 000000000..327e0eb7c --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_gpt_lld.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_gpt_lld.c | ||
19 | * @brief PLATFORM GPT subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup GPT | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_GPT == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @brief GPTD1 driver identifier. | ||
39 | */ | ||
40 | #if (PLATFORM_GPT_USE_GPT1 == TRUE) || defined(__DOXYGEN__) | ||
41 | GPTDriver GPTD1; | ||
42 | #endif | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver local variables and types. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* Driver local functions. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Driver interrupt handlers. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver exported functions. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief Low level GPT driver initialization. | ||
62 | * | ||
63 | * @notapi | ||
64 | */ | ||
65 | void gpt_lld_init(void) { | ||
66 | |||
67 | #if PLATFORM_GPT_USE_GPT1 == TRUE | ||
68 | /* Driver initialization.*/ | ||
69 | gptObjectInit(&GPTD1); | ||
70 | #endif | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * @brief Configures and activates the GPT peripheral. | ||
75 | * | ||
76 | * @param[in] gptp pointer to the @p GPTDriver object | ||
77 | * | ||
78 | * @notapi | ||
79 | */ | ||
80 | void gpt_lld_start(GPTDriver *gptp) { | ||
81 | |||
82 | if (gptp->state == GPT_STOP) { | ||
83 | /* Enables the peripheral.*/ | ||
84 | #if PLATFORM_GPT_USE_GPT1 == TRUE | ||
85 | if (&GPTD1 == gptp) { | ||
86 | |||
87 | } | ||
88 | #endif | ||
89 | } | ||
90 | /* Configures the peripheral.*/ | ||
91 | |||
92 | } | ||
93 | |||
94 | /** | ||
95 | * @brief Deactivates the GPT peripheral. | ||
96 | * | ||
97 | * @param[in] gptp pointer to the @p GPTDriver object | ||
98 | * | ||
99 | * @notapi | ||
100 | */ | ||
101 | void gpt_lld_stop(GPTDriver *gptp) { | ||
102 | |||
103 | if (gptp->state == GPT_READY) { | ||
104 | /* Resets the peripheral.*/ | ||
105 | |||
106 | /* Disables the peripheral.*/ | ||
107 | #if PLATFORM_GPT_USE_GPT1 == TRUE | ||
108 | if (&GPTD1 == gptp) { | ||
109 | |||
110 | } | ||
111 | #endif | ||
112 | } | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * @brief Starts the timer in continuous mode. | ||
117 | * | ||
118 | * @param[in] gptp pointer to the @p GPTDriver object | ||
119 | * @param[in] interval period in ticks | ||
120 | * | ||
121 | * @notapi | ||
122 | */ | ||
123 | void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval) { | ||
124 | |||
125 | (void)gptp; | ||
126 | (void)interval; | ||
127 | |||
128 | } | ||
129 | |||
130 | /** | ||
131 | * @brief Stops the timer. | ||
132 | * | ||
133 | * @param[in] gptp pointer to the @p GPTDriver object | ||
134 | * | ||
135 | * @notapi | ||
136 | */ | ||
137 | void gpt_lld_stop_timer(GPTDriver *gptp) { | ||
138 | |||
139 | (void)gptp; | ||
140 | |||
141 | } | ||
142 | |||
143 | /** | ||
144 | * @brief Starts the timer in one shot mode and waits for completion. | ||
145 | * @details This function specifically polls the timer waiting for completion | ||
146 | * in order to not have extra delays caused by interrupt servicing, | ||
147 | * this function is only recommended for short delays. | ||
148 | * | ||
149 | * @param[in] gptp pointer to the @p GPTDriver object | ||
150 | * @param[in] interval time interval in ticks | ||
151 | * | ||
152 | * @notapi | ||
153 | */ | ||
154 | void gpt_lld_polled_delay(GPTDriver *gptp, gptcnt_t interval) { | ||
155 | |||
156 | (void)gptp; | ||
157 | (void)interval; | ||
158 | |||
159 | } | ||
160 | |||
161 | #endif /* HAL_USE_GPT == TRUE */ | ||
162 | |||
163 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_gpt_lld.h b/lib/chibios/os/hal/templates/hal_gpt_lld.h new file mode 100644 index 000000000..468dfd0cc --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_gpt_lld.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_gpt_lld.h | ||
19 | * @brief PLATFORM GPT subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup GPT | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_GPT_LLD_H | ||
26 | #define HAL_GPT_LLD_H | ||
27 | |||
28 | #if (HAL_USE_GPT == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Driver pre-compile time settings. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /** | ||
39 | * @name PLATFORM configuration options | ||
40 | * @{ | ||
41 | */ | ||
42 | /** | ||
43 | * @brief GPTD1 driver enable switch. | ||
44 | * @details If set to @p TRUE the support for GPTD1 is included. | ||
45 | * @note The default is @p FALSE. | ||
46 | */ | ||
47 | #if !defined(PLATFORM_GPT_USE_GPT1) || defined(__DOXYGEN__) | ||
48 | #define PLATFORM_GPT_USE_GPT1 FALSE | ||
49 | #endif | ||
50 | /** @} */ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Derived constants and error checks. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver data structures and types. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief GPT frequency type. | ||
62 | */ | ||
63 | typedef uint32_t gptfreq_t; | ||
64 | |||
65 | /** | ||
66 | * @brief GPT counter type. | ||
67 | */ | ||
68 | typedef uint16_t gptcnt_t; | ||
69 | |||
70 | /** | ||
71 | * @brief Driver configuration structure. | ||
72 | * @note It could be empty on some architectures. | ||
73 | */ | ||
74 | typedef struct { | ||
75 | /** | ||
76 | * @brief Timer clock in Hz. | ||
77 | * @note The low level can use assertions in order to catch invalid | ||
78 | * frequency specifications. | ||
79 | */ | ||
80 | gptfreq_t frequency; | ||
81 | /** | ||
82 | * @brief Timer callback pointer. | ||
83 | * @note This callback is invoked on GPT counter events. | ||
84 | */ | ||
85 | gptcallback_t callback; | ||
86 | /* End of the mandatory fields.*/ | ||
87 | } GPTConfig; | ||
88 | |||
89 | /** | ||
90 | * @brief Structure representing a GPT driver. | ||
91 | */ | ||
92 | struct GPTDriver { | ||
93 | /** | ||
94 | * @brief Driver state. | ||
95 | */ | ||
96 | gptstate_t state; | ||
97 | /** | ||
98 | * @brief Current configuration data. | ||
99 | */ | ||
100 | const GPTConfig *config; | ||
101 | #if defined(GPT_DRIVER_EXT_FIELDS) | ||
102 | GPT_DRIVER_EXT_FIELDS | ||
103 | #endif | ||
104 | /* End of the mandatory fields.*/ | ||
105 | }; | ||
106 | |||
107 | /*===========================================================================*/ | ||
108 | /* Driver macros. */ | ||
109 | /*===========================================================================*/ | ||
110 | |||
111 | /** | ||
112 | * @brief Changes the interval of GPT peripheral. | ||
113 | * @details This function changes the interval of a running GPT unit. | ||
114 | * @pre The GPT unit must have been activated using @p gptStart(). | ||
115 | * @pre The GPT unit must have been running in continuous mode using | ||
116 | * @p gptStartContinuous(). | ||
117 | * @post The GPT unit interval is changed to the new value. | ||
118 | * @note The function has effect at the next cycle start. | ||
119 | * | ||
120 | * @param[in] gptp pointer to a @p GPTDriver object | ||
121 | * @param[in] interval new cycle time in timer ticks | ||
122 | * @notapi | ||
123 | */ | ||
124 | #define gpt_lld_change_interval(gptp, interval) { \ | ||
125 | (void)gptp; \ | ||
126 | (void)interval; \ | ||
127 | } | ||
128 | |||
129 | /*===========================================================================*/ | ||
130 | /* External declarations. */ | ||
131 | /*===========================================================================*/ | ||
132 | |||
133 | #if (PLATFORM_GPT_USE_GPT1 == TRUE) && !defined(__DOXYGEN__) | ||
134 | extern GPTDriver GPTD1; | ||
135 | #endif | ||
136 | |||
137 | #ifdef __cplusplus | ||
138 | extern "C" { | ||
139 | #endif | ||
140 | void gpt_lld_init(void); | ||
141 | void gpt_lld_start(GPTDriver *gptp); | ||
142 | void gpt_lld_stop(GPTDriver *gptp); | ||
143 | void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval); | ||
144 | void gpt_lld_stop_timer(GPTDriver *gptp); | ||
145 | void gpt_lld_polled_delay(GPTDriver *gptp, gptcnt_t interval); | ||
146 | #ifdef __cplusplus | ||
147 | } | ||
148 | #endif | ||
149 | |||
150 | #endif /* HAL_USE_GPT == TRUE */ | ||
151 | |||
152 | #endif /* HAL_GPT_LLD_H */ | ||
153 | |||
154 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_i2c_lld.c b/lib/chibios/os/hal/templates/hal_i2c_lld.c new file mode 100644 index 000000000..e2552b949 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_i2c_lld.c | |||
@@ -0,0 +1,187 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_i2c_lld.c | ||
19 | * @brief PLATFORM I2C subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup I2C | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @brief I2C1 driver identifier. | ||
39 | */ | ||
40 | #if (PLATFORM_I2C_USE_I2C1 == TRUE) || defined(__DOXYGEN__) | ||
41 | I2CDriver I2CD1; | ||
42 | #endif | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver local variables and types. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* Driver local functions. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Driver interrupt handlers. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver exported functions. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief Low level I2C driver initialization. | ||
62 | * | ||
63 | * @notapi | ||
64 | */ | ||
65 | void i2c_lld_init(void) { | ||
66 | |||
67 | #if PLATFORM_I2C_USE_I2C1 == TRUE | ||
68 | i2cObjectInit(&I2CD1); | ||
69 | #endif | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * @brief Configures and activates the I2C peripheral. | ||
74 | * | ||
75 | * @param[in] i2cp pointer to the @p I2CDriver object | ||
76 | * | ||
77 | * @notapi | ||
78 | */ | ||
79 | void i2c_lld_start(I2CDriver *i2cp) { | ||
80 | |||
81 | if (i2cp->state == I2C_STOP) { | ||
82 | /* Enables the peripheral.*/ | ||
83 | #if PLATFORM_I2C_USE_I2C1 == TRUE | ||
84 | if (&I2CD1 == i2cp) { | ||
85 | |||
86 | } | ||
87 | #endif | ||
88 | } | ||
89 | |||
90 | } | ||
91 | |||
92 | /** | ||
93 | * @brief Deactivates the I2C peripheral. | ||
94 | * | ||
95 | * @param[in] i2cp pointer to the @p I2CDriver object | ||
96 | * | ||
97 | * @notapi | ||
98 | */ | ||
99 | void i2c_lld_stop(I2CDriver *i2cp) { | ||
100 | |||
101 | if (i2cp->state != I2C_STOP) { | ||
102 | |||
103 | /* Disables the peripheral.*/ | ||
104 | #if PLATFORM_I2C_USE_I2C1 == TRUE | ||
105 | if (&I2CD1 == i2cp) { | ||
106 | |||
107 | } | ||
108 | #endif | ||
109 | } | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * @brief Receives data via the I2C bus as master. | ||
114 | * | ||
115 | * @param[in] i2cp pointer to the @p I2CDriver object | ||
116 | * @param[in] addr slave device address | ||
117 | * @param[out] rxbuf pointer to the receive buffer | ||
118 | * @param[in] rxbytes number of bytes to be received | ||
119 | * @param[in] timeout the number of ticks before the operation timeouts, | ||
120 | * the following special values are allowed: | ||
121 | * - @a TIME_INFINITE no timeout. | ||
122 | * . | ||
123 | * @return The operation status. | ||
124 | * @retval MSG_OK if the function succeeded. | ||
125 | * @retval MSG_RESET if one or more I2C errors occurred, the errors can | ||
126 | * be retrieved using @p i2cGetErrors(). | ||
127 | * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a | ||
128 | * timeout the driver must be stopped and restarted | ||
129 | * because the bus is in an uncertain state</b>. | ||
130 | * | ||
131 | * @notapi | ||
132 | */ | ||
133 | msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr, | ||
134 | uint8_t *rxbuf, size_t rxbytes, | ||
135 | sysinterval_t timeout) { | ||
136 | |||
137 | (void)i2cp; | ||
138 | (void)addr; | ||
139 | (void)rxbuf; | ||
140 | (void)rxbytes; | ||
141 | (void)timeout; | ||
142 | |||
143 | return MSG_OK; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * @brief Transmits data via the I2C bus as master. | ||
148 | * | ||
149 | * @param[in] i2cp pointer to the @p I2CDriver object | ||
150 | * @param[in] addr slave device address | ||
151 | * @param[in] txbuf pointer to the transmit buffer | ||
152 | * @param[in] txbytes number of bytes to be transmitted | ||
153 | * @param[out] rxbuf pointer to the receive buffer | ||
154 | * @param[in] rxbytes number of bytes to be received | ||
155 | * @param[in] timeout the number of ticks before the operation timeouts, | ||
156 | * the following special values are allowed: | ||
157 | * - @a TIME_INFINITE no timeout. | ||
158 | * . | ||
159 | * @return The operation status. | ||
160 | * @retval MSG_OK if the function succeeded. | ||
161 | * @retval MSG_RESET if one or more I2C errors occurred, the errors can | ||
162 | * be retrieved using @p i2cGetErrors(). | ||
163 | * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a | ||
164 | * timeout the driver must be stopped and restarted | ||
165 | * because the bus is in an uncertain state</b>. | ||
166 | * | ||
167 | * @notapi | ||
168 | */ | ||
169 | msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr, | ||
170 | const uint8_t *txbuf, size_t txbytes, | ||
171 | uint8_t *rxbuf, size_t rxbytes, | ||
172 | sysinterval_t timeout) { | ||
173 | |||
174 | (void)i2cp; | ||
175 | (void)addr; | ||
176 | (void)txbuf; | ||
177 | (void)txbytes; | ||
178 | (void)rxbuf; | ||
179 | (void)rxbytes; | ||
180 | (void)timeout; | ||
181 | |||
182 | return MSG_OK; | ||
183 | } | ||
184 | |||
185 | #endif /* HAL_USE_I2C == TRUE */ | ||
186 | |||
187 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_i2c_lld.h b/lib/chibios/os/hal/templates/hal_i2c_lld.h new file mode 100644 index 000000000..30eec6a17 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_i2c_lld.h | |||
@@ -0,0 +1,152 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_i2c_lld.h | ||
19 | * @brief PLATFORM I2C subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup I2C | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_I2C_LLD_H | ||
26 | #define HAL_I2C_LLD_H | ||
27 | |||
28 | #if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Driver pre-compile time settings. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /** | ||
39 | * @name PLATFORM configuration options | ||
40 | * @{ | ||
41 | */ | ||
42 | /** | ||
43 | * @brief I2C1 driver enable switch. | ||
44 | * @details If set to @p TRUE the support for I2C1 is included. | ||
45 | * @note The default is @p FALSE. | ||
46 | */ | ||
47 | #if !defined(PLATFORM_I2C_USE_I2C1) || defined(__DOXYGEN__) | ||
48 | #define PLATFORM_I2C_USE_I2C1 FALSE | ||
49 | #endif | ||
50 | /** @} */ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Derived constants and error checks. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver data structures and types. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief Type representing an I2C address. | ||
62 | */ | ||
63 | typedef uint16_t i2caddr_t; | ||
64 | |||
65 | /** | ||
66 | * @brief Type of I2C Driver condition flags. | ||
67 | */ | ||
68 | typedef uint32_t i2cflags_t; | ||
69 | |||
70 | /** | ||
71 | * @brief Type of I2C driver configuration structure. | ||
72 | * @note Implementations may extend this structure to contain more, | ||
73 | * architecture dependent, fields. | ||
74 | */ | ||
75 | typedef struct { | ||
76 | /* End of the mandatory fields.*/ | ||
77 | uint32_t dummy; | ||
78 | } I2CConfig; | ||
79 | |||
80 | /** | ||
81 | * @brief Type of a structure representing an I2C driver. | ||
82 | */ | ||
83 | typedef struct I2CDriver I2CDriver; | ||
84 | |||
85 | /** | ||
86 | * @brief Structure representing an I2C driver. | ||
87 | */ | ||
88 | struct I2CDriver { | ||
89 | /** | ||
90 | * @brief Driver state. | ||
91 | */ | ||
92 | i2cstate_t state; | ||
93 | /** | ||
94 | * @brief Current configuration data. | ||
95 | */ | ||
96 | const I2CConfig *config; | ||
97 | /** | ||
98 | * @brief Error flags. | ||
99 | */ | ||
100 | i2cflags_t errors; | ||
101 | #if (I2C_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) | ||
102 | mutex_t mutex; | ||
103 | #endif | ||
104 | #if defined(I2C_DRIVER_EXT_FIELDS) | ||
105 | I2C_DRIVER_EXT_FIELDS | ||
106 | #endif | ||
107 | /* End of the mandatory fields.*/ | ||
108 | }; | ||
109 | |||
110 | /*===========================================================================*/ | ||
111 | /* Driver macros. */ | ||
112 | /*===========================================================================*/ | ||
113 | |||
114 | /** | ||
115 | * @brief Get errors from I2C driver. | ||
116 | * | ||
117 | * @param[in] i2cp pointer to the @p I2CDriver object | ||
118 | * | ||
119 | * @notapi | ||
120 | */ | ||
121 | #define i2c_lld_get_errors(i2cp) ((i2cp)->errors) | ||
122 | |||
123 | /*===========================================================================*/ | ||
124 | /* External declarations. */ | ||
125 | /*===========================================================================*/ | ||
126 | |||
127 | #if (PLATFORM_I2C_USE_I2C1 == TRUE) && !defined(__DOXYGEN__) | ||
128 | extern I2CDriver I2CD1; | ||
129 | #endif | ||
130 | |||
131 | #ifdef __cplusplus | ||
132 | extern "C" { | ||
133 | #endif | ||
134 | void i2c_lld_init(void); | ||
135 | void i2c_lld_start(I2CDriver *i2cp); | ||
136 | void i2c_lld_stop(I2CDriver *i2cp); | ||
137 | msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr, | ||
138 | const uint8_t *txbuf, size_t txbytes, | ||
139 | uint8_t *rxbuf, size_t rxbytes, | ||
140 | sysinterval_t timeout); | ||
141 | msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr, | ||
142 | uint8_t *rxbuf, size_t rxbytes, | ||
143 | sysinterval_t timeout); | ||
144 | #ifdef __cplusplus | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | #endif /* HAL_USE_I2C == TRUE */ | ||
149 | |||
150 | #endif /* HAL_I2C_LLD_H */ | ||
151 | |||
152 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_i2s_lld.c b/lib/chibios/os/hal/templates/hal_i2s_lld.c new file mode 100644 index 000000000..1ee525c2b --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_i2s_lld.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_i2s_lld.c | ||
19 | * @brief PLATFORM I2S subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup I2S | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_I2S == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** @brief I2S2 driver identifier.*/ | ||
38 | #if (PLATFORM_I2S_USE_I2S1 == TRUE) || defined(__DOXYGEN__) | ||
39 | I2SDriver I2SD1; | ||
40 | #endif | ||
41 | |||
42 | /*===========================================================================*/ | ||
43 | /* Driver local variables and types. */ | ||
44 | /*===========================================================================*/ | ||
45 | |||
46 | /*===========================================================================*/ | ||
47 | /* Driver local functions. */ | ||
48 | /*===========================================================================*/ | ||
49 | |||
50 | /*===========================================================================*/ | ||
51 | /* Driver interrupt handlers. */ | ||
52 | /*===========================================================================*/ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Driver exported functions. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /** | ||
59 | * @brief Low level I2S driver initialization. | ||
60 | * | ||
61 | * @notapi | ||
62 | */ | ||
63 | void i2s_lld_init(void) { | ||
64 | |||
65 | #if PLATFORM_I2S_USE_I2S1 | ||
66 | i2sObjectInit(&I2SD1); | ||
67 | #endif | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * @brief Configures and activates the I2S peripheral. | ||
72 | * | ||
73 | * @param[in] i2sp pointer to the @p I2SDriver object | ||
74 | * | ||
75 | * @notapi | ||
76 | */ | ||
77 | void i2s_lld_start(I2SDriver *i2sp) { | ||
78 | |||
79 | /* If in stopped state then enables the SPI and DMA clocks.*/ | ||
80 | if (i2sp->state == I2S_STOP) { | ||
81 | |||
82 | #if PLATFORM_I2S_USE_I2S1 | ||
83 | if (&I2SD1 == i2sp) { | ||
84 | |||
85 | } | ||
86 | #endif | ||
87 | } | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * @brief Deactivates the I2S peripheral. | ||
92 | * | ||
93 | * @param[in] i2sp pointer to the @p I2SDriver object | ||
94 | * | ||
95 | * @notapi | ||
96 | */ | ||
97 | void i2s_lld_stop(I2SDriver *i2sp) { | ||
98 | |||
99 | /* If in ready state then disables the SPI clock.*/ | ||
100 | if (i2sp->state == I2S_READY) { | ||
101 | #if PLATFORM_I2S_USE_I2S1 | ||
102 | if (&I2SD1 == i2sp) { | ||
103 | |||
104 | } | ||
105 | #endif | ||
106 | } | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * @brief Starts a I2S data exchange. | ||
111 | * | ||
112 | * @param[in] i2sp pointer to the @p I2SDriver object | ||
113 | * | ||
114 | * @notapi | ||
115 | */ | ||
116 | void i2s_lld_start_exchange(I2SDriver *i2sp) { | ||
117 | |||
118 | (void)i2sp; | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * @brief Stops the ongoing data exchange. | ||
123 | * @details The ongoing data exchange, if any, is stopped, if the driver | ||
124 | * was not active the function does nothing. | ||
125 | * | ||
126 | * @param[in] i2sp pointer to the @p I2SDriver object | ||
127 | * | ||
128 | * @notapi | ||
129 | */ | ||
130 | void i2s_lld_stop_exchange(I2SDriver *i2sp) { | ||
131 | |||
132 | (void)i2sp; | ||
133 | } | ||
134 | |||
135 | #endif /* HAL_USE_I2S */ | ||
136 | |||
137 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_i2s_lld.h b/lib/chibios/os/hal/templates/hal_i2s_lld.h new file mode 100644 index 000000000..6167ef26d --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_i2s_lld.h | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_i2s_lld.h | ||
19 | * @brief PLATFORM I2S subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup I2S | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_I2S_LLD_H | ||
26 | #define HAL_I2S_LLD_H | ||
27 | |||
28 | #if (HAL_USE_I2S == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Driver pre-compile time settings. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /** | ||
39 | * @name PLATFORM configuration options | ||
40 | * @{ | ||
41 | */ | ||
42 | /** | ||
43 | * @brief I2SD1 driver enable switch. | ||
44 | * @details If set to @p TRUE the support for I2S1 is included. | ||
45 | * @note The default is @p FALSE. | ||
46 | */ | ||
47 | #if !defined(PLATFORM_I2S_USE_I2S1) || defined(__DOXYGEN__) | ||
48 | #define PLATFORM_I2S_USE_I2S1 FALSE | ||
49 | #endif | ||
50 | /** @} */ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Derived constants and error checks. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver data structures and types. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /*===========================================================================*/ | ||
61 | /* Driver macros. */ | ||
62 | /*===========================================================================*/ | ||
63 | |||
64 | /** | ||
65 | * @brief Low level fields of the I2S driver structure. | ||
66 | */ | ||
67 | #define i2s_lld_driver_fields \ | ||
68 | /* Dummy field, it is not needed.*/ \ | ||
69 | uint32_t dummy | ||
70 | |||
71 | /** | ||
72 | * @brief Low level fields of the I2S configuration structure. | ||
73 | */ | ||
74 | #define i2s_lld_config_fields \ | ||
75 | /* Dummy configuration, it is not needed.*/ \ | ||
76 | uint32_t dummy | ||
77 | |||
78 | /*===========================================================================*/ | ||
79 | /* External declarations. */ | ||
80 | /*===========================================================================*/ | ||
81 | |||
82 | #if (PLATFORM_I2S_USE_I2S1 == TRUE) && !defined(__DOXYGEN__) | ||
83 | extern I2SDriver I2SD1; | ||
84 | #endif | ||
85 | |||
86 | #ifdef __cplusplus | ||
87 | extern "C" { | ||
88 | #endif | ||
89 | void i2s_lld_init(void); | ||
90 | void i2s_lld_start(I2SDriver *i2sp); | ||
91 | void i2s_lld_stop(I2SDriver *i2sp); | ||
92 | void i2s_lld_start_exchange(I2SDriver *i2sp); | ||
93 | void i2s_lld_stop_exchange(I2SDriver *i2sp); | ||
94 | #ifdef __cplusplus | ||
95 | } | ||
96 | #endif | ||
97 | |||
98 | #endif /* HAL_USE_I2S == TRUE */ | ||
99 | |||
100 | #endif /* HAL_I2S_LLD_H */ | ||
101 | |||
102 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_icu_lld.c b/lib/chibios/os/hal/templates/hal_icu_lld.c new file mode 100644 index 000000000..bdf7349b9 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_icu_lld.c | |||
@@ -0,0 +1,187 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_icu_lld.c | ||
19 | * @brief PLATFORM ADC subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup ICU | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_ICU == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @brief ICUD1 driver identifier. | ||
39 | * @note The driver ICUD1 allocates the complex timer TIM1 when enabled. | ||
40 | */ | ||
41 | #if (PLATFORM_ICU_USE_ICU1 == TRUE) || defined(__DOXYGEN__) | ||
42 | ICUDriver ICUD1; | ||
43 | #endif | ||
44 | |||
45 | /*===========================================================================*/ | ||
46 | /* Driver local variables and types. */ | ||
47 | /*===========================================================================*/ | ||
48 | |||
49 | /*===========================================================================*/ | ||
50 | /* Driver local functions. */ | ||
51 | /*===========================================================================*/ | ||
52 | |||
53 | /*===========================================================================*/ | ||
54 | /* Driver interrupt handlers. */ | ||
55 | /*===========================================================================*/ | ||
56 | |||
57 | /*===========================================================================*/ | ||
58 | /* Driver exported functions. */ | ||
59 | /*===========================================================================*/ | ||
60 | |||
61 | /** | ||
62 | * @brief Low level ICU driver initialization. | ||
63 | * | ||
64 | * @notapi | ||
65 | */ | ||
66 | void icu_lld_init(void) { | ||
67 | |||
68 | #if PLATFORM_ICU_USE_ICU1 == TRUE | ||
69 | /* Driver initialization.*/ | ||
70 | icuObjectInit(&ICUD1); | ||
71 | #endif | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * @brief Configures and activates the ICU peripheral. | ||
76 | * | ||
77 | * @param[in] icup pointer to the @p ICUDriver object | ||
78 | * | ||
79 | * @notapi | ||
80 | */ | ||
81 | void icu_lld_start(ICUDriver *icup) { | ||
82 | |||
83 | if (icup->state == ICU_STOP) { | ||
84 | /* Clock activation and timer reset.*/ | ||
85 | #if PLATFORM_ICU_USE_ICU1 == TRUE | ||
86 | if (&ICUD1 == icup) { | ||
87 | |||
88 | } | ||
89 | #endif | ||
90 | } | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * @brief Deactivates the ICU peripheral. | ||
95 | * | ||
96 | * @param[in] icup pointer to the @p ICUDriver object | ||
97 | * | ||
98 | * @notapi | ||
99 | */ | ||
100 | void icu_lld_stop(ICUDriver *icup) { | ||
101 | |||
102 | if (icup->state == ICU_READY) { | ||
103 | /* Clock deactivation.*/ | ||
104 | #if PLATFORM_ICU_USE_ICU1 == TRUE | ||
105 | if (&ICUD1 == icup) { | ||
106 | |||
107 | } | ||
108 | #endif | ||
109 | } | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * @brief Starts the input capture. | ||
114 | * | ||
115 | * @param[in] icup pointer to the @p ICUDriver object | ||
116 | * | ||
117 | * @notapi | ||
118 | */ | ||
119 | void icu_lld_start_capture(ICUDriver *icup) { | ||
120 | |||
121 | (void)icup; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * @brief Waits for a completed capture. | ||
126 | * @note The operation is performed in polled mode. | ||
127 | * @note In order to use this function notifications must be disabled. | ||
128 | * | ||
129 | * @param[in] icup pointer to the @p ICUDriver object | ||
130 | * @return The capture status. | ||
131 | * @retval false if the capture is successful. | ||
132 | * @retval true if a timer overflow occurred. | ||
133 | * | ||
134 | * @notapi | ||
135 | */ | ||
136 | bool icu_lld_wait_capture(ICUDriver *icup) { | ||
137 | |||
138 | (void)icup; | ||
139 | |||
140 | return false; | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * @brief Stops the input capture. | ||
145 | * | ||
146 | * @param[in] icup pointer to the @p ICUDriver object | ||
147 | * | ||
148 | * @notapi | ||
149 | */ | ||
150 | void icu_lld_stop_capture(ICUDriver *icup) { | ||
151 | |||
152 | (void)icup; | ||
153 | } | ||
154 | |||
155 | /** | ||
156 | * @brief Enables notifications. | ||
157 | * @pre The ICU unit must have been activated using @p icuStart() and the | ||
158 | * capture started using @p icuStartCapture(). | ||
159 | * @note If the notification is already enabled then the call has no effect. | ||
160 | * | ||
161 | * @param[in] icup pointer to the @p ICUDriver object | ||
162 | * | ||
163 | * @api | ||
164 | */ | ||
165 | void icu_lld_enable_notifications(ICUDriver *icup) { | ||
166 | |||
167 | (void)icup; | ||
168 | } | ||
169 | |||
170 | /** | ||
171 | * @brief Disables notifications. | ||
172 | * @pre The ICU unit must have been activated using @p icuStart() and the | ||
173 | * capture started using @p icuStartCapture(). | ||
174 | * @note If the notification is already disabled then the call has no effect. | ||
175 | * | ||
176 | * @param[in] icup pointer to the @p ICUDriver object | ||
177 | * | ||
178 | * @api | ||
179 | */ | ||
180 | void icu_lld_disable_notifications(ICUDriver *icup) { | ||
181 | |||
182 | (void)icup; | ||
183 | } | ||
184 | |||
185 | #endif /* HAL_USE_ICU == TRUE */ | ||
186 | |||
187 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_icu_lld.h b/lib/chibios/os/hal/templates/hal_icu_lld.h new file mode 100644 index 000000000..9c39e6b8a --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_icu_lld.h | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_icu_lld.h | ||
19 | * @brief PLATFORM ICU subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup ICU | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_ICU_LLD_H | ||
26 | #define HAL_ICU_LLD_H | ||
27 | |||
28 | #if (HAL_USE_ICU == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Driver pre-compile time settings. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /** | ||
39 | * @name PLATFORM configuration options | ||
40 | * @{ | ||
41 | */ | ||
42 | /** | ||
43 | * @brief ICUD1 driver enable switch. | ||
44 | * @details If set to @p TRUE the support for ICUD1 is included. | ||
45 | * @note The default is @p FALSE. | ||
46 | */ | ||
47 | #if !defined(PLATFORM_ICU_USE_ICU1) || defined(__DOXYGEN__) | ||
48 | #define PLATFORM_ICU_USE_ICU1 FALSE | ||
49 | #endif | ||
50 | /** @} */ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Derived constants and error checks. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver data structures and types. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /** | ||
61 | * @brief ICU driver mode. | ||
62 | */ | ||
63 | typedef enum { | ||
64 | ICU_INPUT_ACTIVE_HIGH = 0, /**< Trigger on rising edge. */ | ||
65 | ICU_INPUT_ACTIVE_LOW = 1 /**< Trigger on falling edge. */ | ||
66 | } icumode_t; | ||
67 | |||
68 | /** | ||
69 | * @brief ICU frequency type. | ||
70 | */ | ||
71 | typedef uint32_t icufreq_t; | ||
72 | |||
73 | /** | ||
74 | * @brief ICU counter type. | ||
75 | */ | ||
76 | typedef uint32_t icucnt_t; | ||
77 | |||
78 | /** | ||
79 | * @brief Driver configuration structure. | ||
80 | * @note It could be empty on some architectures. | ||
81 | */ | ||
82 | typedef struct { | ||
83 | /** | ||
84 | * @brief Driver mode. | ||
85 | */ | ||
86 | icumode_t mode; | ||
87 | /** | ||
88 | * @brief Timer clock in Hz. | ||
89 | * @note The low level can use assertions in order to catch invalid | ||
90 | * frequency specifications. | ||
91 | */ | ||
92 | icufreq_t frequency; | ||
93 | /** | ||
94 | * @brief Callback for pulse width measurement. | ||
95 | */ | ||
96 | icucallback_t width_cb; | ||
97 | /** | ||
98 | * @brief Callback for cycle period measurement. | ||
99 | */ | ||
100 | icucallback_t period_cb; | ||
101 | /** | ||
102 | * @brief Callback for timer overflow. | ||
103 | */ | ||
104 | icucallback_t overflow_cb; | ||
105 | /* End of the mandatory fields.*/ | ||
106 | } ICUConfig; | ||
107 | |||
108 | /** | ||
109 | * @brief Structure representing an ICU driver. | ||
110 | */ | ||
111 | struct ICUDriver { | ||
112 | /** | ||
113 | * @brief Driver state. | ||
114 | */ | ||
115 | icustate_t state; | ||
116 | /** | ||
117 | * @brief Current configuration data. | ||
118 | */ | ||
119 | const ICUConfig *config; | ||
120 | #if defined(ICU_DRIVER_EXT_FIELDS) | ||
121 | ICU_DRIVER_EXT_FIELDS | ||
122 | #endif | ||
123 | /* End of the mandatory fields.*/ | ||
124 | }; | ||
125 | |||
126 | /*===========================================================================*/ | ||
127 | /* Driver macros. */ | ||
128 | /*===========================================================================*/ | ||
129 | |||
130 | /** | ||
131 | * @brief Returns the width of the latest pulse. | ||
132 | * @details The pulse width is defined as number of ticks between the start | ||
133 | * edge and the stop edge. | ||
134 | * | ||
135 | * @param[in] icup pointer to the @p ICUDriver object | ||
136 | * @return The number of ticks. | ||
137 | * | ||
138 | * @notapi | ||
139 | */ | ||
140 | #define icu_lld_get_width(icup) 0 | ||
141 | |||
142 | /** | ||
143 | * @brief Returns the width of the latest cycle. | ||
144 | * @details The cycle width is defined as number of ticks between a start | ||
145 | * edge and the next start edge. | ||
146 | * | ||
147 | * @param[in] icup pointer to the @p ICUDriver object | ||
148 | * @return The number of ticks. | ||
149 | * | ||
150 | * @notapi | ||
151 | */ | ||
152 | #define icu_lld_get_period(icup) 0 | ||
153 | |||
154 | /** | ||
155 | * @brief Check on notifications status. | ||
156 | * | ||
157 | * @param[in] icup pointer to the @p ICUDriver object | ||
158 | * @return The notifications status. | ||
159 | * @retval false if notifications are not enabled. | ||
160 | * @retval true if notifications are enabled. | ||
161 | * | ||
162 | * @notapi | ||
163 | */ | ||
164 | #define icu_lld_are_notifications_enabled(icup) false | ||
165 | |||
166 | /*===========================================================================*/ | ||
167 | /* External declarations. */ | ||
168 | /*===========================================================================*/ | ||
169 | |||
170 | #if (PLATFORM_ICU_USE_ICU1 == TRUE) && !defined(__DOXYGEN__) | ||
171 | extern ICUDriver ICUD1; | ||
172 | #endif | ||
173 | |||
174 | #ifdef __cplusplus | ||
175 | extern "C" { | ||
176 | #endif | ||
177 | void icu_lld_init(void); | ||
178 | void icu_lld_start(ICUDriver *icup); | ||
179 | void icu_lld_stop(ICUDriver *icup); | ||
180 | void icu_lld_start_capture(ICUDriver *icup); | ||
181 | bool icu_lld_wait_capture(ICUDriver *icup); | ||
182 | void icu_lld_stop_capture(ICUDriver *icup); | ||
183 | void icu_lld_enable_notifications(ICUDriver *icup); | ||
184 | void icu_lld_disable_notifications(ICUDriver *icup); | ||
185 | #ifdef __cplusplus | ||
186 | } | ||
187 | #endif | ||
188 | |||
189 | #endif /* HAL_USE_ICU == TRUE */ | ||
190 | |||
191 | #endif /* HAL_ICU_LLD_H */ | ||
192 | |||
193 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_lld.c b/lib/chibios/os/hal/templates/hal_lld.c new file mode 100644 index 000000000..d71c16ac6 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_lld.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_lld.c | ||
19 | * @brief PLATFORM HAL subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup HAL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | /*===========================================================================*/ | ||
28 | /* Driver local definitions. */ | ||
29 | /*===========================================================================*/ | ||
30 | |||
31 | /*===========================================================================*/ | ||
32 | /* Driver exported variables. */ | ||
33 | /*===========================================================================*/ | ||
34 | |||
35 | /*===========================================================================*/ | ||
36 | /* Driver local variables and types. */ | ||
37 | /*===========================================================================*/ | ||
38 | |||
39 | /*===========================================================================*/ | ||
40 | /* Driver local functions. */ | ||
41 | /*===========================================================================*/ | ||
42 | |||
43 | /*===========================================================================*/ | ||
44 | /* Driver interrupt handlers. */ | ||
45 | /*===========================================================================*/ | ||
46 | |||
47 | /*===========================================================================*/ | ||
48 | /* Driver exported functions. */ | ||
49 | /*===========================================================================*/ | ||
50 | |||
51 | /** | ||
52 | * @brief Low level HAL driver initialization. | ||
53 | * | ||
54 | * @notapi | ||
55 | */ | ||
56 | void hal_lld_init(void) { | ||
57 | |||
58 | } | ||
59 | |||
60 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_lld.h b/lib/chibios/os/hal/templates/hal_lld.h new file mode 100644 index 000000000..e30cbd169 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_lld.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_lld.h | ||
19 | * @brief PLATFORM HAL subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup HAL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef _HAL_LLD_H_ | ||
26 | #define _HAL_LLD_H_ | ||
27 | |||
28 | /*===========================================================================*/ | ||
29 | /* Driver constants. */ | ||
30 | /*===========================================================================*/ | ||
31 | |||
32 | /** | ||
33 | * @name Platform identification macros | ||
34 | * @{ | ||
35 | */ | ||
36 | #define PLATFORM_NAME "templates" | ||
37 | /** @} */ | ||
38 | |||
39 | /*===========================================================================*/ | ||
40 | /* Driver pre-compile time settings. */ | ||
41 | /*===========================================================================*/ | ||
42 | |||
43 | /** | ||
44 | * @name PLATFORM configuration options | ||
45 | * @{ | ||
46 | */ | ||
47 | /** @} */ | ||
48 | |||
49 | /*===========================================================================*/ | ||
50 | /* Derived constants and error checks. */ | ||
51 | /*===========================================================================*/ | ||
52 | |||
53 | /* | ||
54 | * Configuration-related checks. | ||
55 | */ | ||
56 | #if !defined(PLATFORM_MCUCONF) | ||
57 | #error "Using a wrong mcuconf.h file, PLATFORM_MCUCONF not defined" | ||
58 | #endif | ||
59 | |||
60 | /*===========================================================================*/ | ||
61 | /* Driver data structures and types. */ | ||
62 | /*===========================================================================*/ | ||
63 | |||
64 | /*===========================================================================*/ | ||
65 | /* Driver macros. */ | ||
66 | /*===========================================================================*/ | ||
67 | |||
68 | /*===========================================================================*/ | ||
69 | /* External declarations. */ | ||
70 | /*===========================================================================*/ | ||
71 | |||
72 | #ifdef __cplusplus | ||
73 | extern "C" { | ||
74 | #endif | ||
75 | void hal_lld_init(void); | ||
76 | #ifdef __cplusplus | ||
77 | } | ||
78 | #endif | ||
79 | |||
80 | #endif /* _HAL_LLD_H_ */ | ||
81 | |||
82 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_mac_lld.c b/lib/chibios/os/hal/templates/hal_mac_lld.c new file mode 100644 index 000000000..5f9fb5292 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_mac_lld.c | |||
@@ -0,0 +1,313 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_mac_lld.c | ||
19 | * @brief PLATFORM MAC subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup MAC | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include <string.h> | ||
26 | |||
27 | #include "hal.h" | ||
28 | |||
29 | #if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__) | ||
30 | |||
31 | #include "hal_mii.h" | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver local definitions. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /*===========================================================================*/ | ||
38 | /* Driver exported variables. */ | ||
39 | /*===========================================================================*/ | ||
40 | |||
41 | /** | ||
42 | * @brief MAC1 driver identifier. | ||
43 | */ | ||
44 | #if (PLATFORM_MAC_USE_MAC1 == TRUE) || defined(__DOXYGEN__) | ||
45 | MACDriver ETHD1; | ||
46 | #endif | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* Driver local variables and types. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Driver local functions. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /*===========================================================================*/ | ||
57 | /* Driver interrupt handlers. */ | ||
58 | /*===========================================================================*/ | ||
59 | |||
60 | /*===========================================================================*/ | ||
61 | /* Driver exported functions. */ | ||
62 | /*===========================================================================*/ | ||
63 | |||
64 | /** | ||
65 | * @brief Low level MAC initialization. | ||
66 | * | ||
67 | * @notapi | ||
68 | */ | ||
69 | void mac_lld_init(void) { | ||
70 | |||
71 | #if PLATFORM_MAC_USE_MAC1 == TRUE | ||
72 | /* Driver initialization.*/ | ||
73 | macObjectInit(&MACD1); | ||
74 | #endif | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * @brief Configures and activates the MAC peripheral. | ||
79 | * | ||
80 | * @param[in] macp pointer to the @p MACDriver object | ||
81 | * | ||
82 | * @notapi | ||
83 | */ | ||
84 | void mac_lld_start(MACDriver *macp) { | ||
85 | |||
86 | if (macp->state == MAC_STOP) { | ||
87 | /* Enables the peripheral.*/ | ||
88 | #if PLATFORM_MAC_USE_MAC1 == TRUE | ||
89 | if (&MACD1 == macp) { | ||
90 | |||
91 | } | ||
92 | #endif | ||
93 | } | ||
94 | /* Configures the peripheral.*/ | ||
95 | |||
96 | } | ||
97 | |||
98 | /** | ||
99 | * @brief Deactivates the MAC peripheral. | ||
100 | * | ||
101 | * @param[in] macp pointer to the @p MACDriver object | ||
102 | * | ||
103 | * @notapi | ||
104 | */ | ||
105 | void mac_lld_stop(MACDriver *macp) { | ||
106 | |||
107 | if (macp->state != MAC_STOP) { | ||
108 | /* Resets the peripheral.*/ | ||
109 | |||
110 | /* Disables the peripheral.*/ | ||
111 | #if PLATFORM_MAC_USE_MAC1 == TRUE | ||
112 | if (&MACD1 == macp) { | ||
113 | |||
114 | } | ||
115 | #endif | ||
116 | } | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * @brief Returns a transmission descriptor. | ||
121 | * @details One of the available transmission descriptors is locked and | ||
122 | * returned. | ||
123 | * | ||
124 | * @param[in] macp pointer to the @p MACDriver object | ||
125 | * @param[out] tdp pointer to a @p MACTransmitDescriptor structure | ||
126 | * @return The operation status. | ||
127 | * @retval MSG_OK the descriptor has been obtained. | ||
128 | * @retval MSG_TIMEOUT descriptor not available. | ||
129 | * | ||
130 | * @notapi | ||
131 | */ | ||
132 | msg_t mac_lld_get_transmit_descriptor(MACDriver *macp, | ||
133 | MACTransmitDescriptor *tdp) { | ||
134 | |||
135 | (void)macp; | ||
136 | (void)tdp; | ||
137 | |||
138 | return MSG_OK; | ||
139 | } | ||
140 | |||
141 | /** | ||
142 | * @brief Releases a transmit descriptor and starts the transmission of the | ||
143 | * enqueued data as a single frame. | ||
144 | * | ||
145 | * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure | ||
146 | * | ||
147 | * @notapi | ||
148 | */ | ||
149 | void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) { | ||
150 | |||
151 | (void)tdp; | ||
152 | |||
153 | } | ||
154 | |||
155 | /** | ||
156 | * @brief Returns a receive descriptor. | ||
157 | * | ||
158 | * @param[in] macp pointer to the @p MACDriver object | ||
159 | * @param[out] rdp pointer to a @p MACReceiveDescriptor structure | ||
160 | * @return The operation status. | ||
161 | * @retval MSG_OK the descriptor has been obtained. | ||
162 | * @retval MSG_TIMEOUT descriptor not available. | ||
163 | * | ||
164 | * @notapi | ||
165 | */ | ||
166 | msg_t mac_lld_get_receive_descriptor(MACDriver *macp, | ||
167 | MACReceiveDescriptor *rdp) { | ||
168 | |||
169 | (void)macp; | ||
170 | (void)rdp; | ||
171 | |||
172 | return MSG_OK; | ||
173 | } | ||
174 | |||
175 | /** | ||
176 | * @brief Releases a receive descriptor. | ||
177 | * @details The descriptor and its buffer are made available for more incoming | ||
178 | * frames. | ||
179 | * | ||
180 | * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure | ||
181 | * | ||
182 | * @notapi | ||
183 | */ | ||
184 | void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) { | ||
185 | |||
186 | (void)rdp; | ||
187 | |||
188 | } | ||
189 | |||
190 | /** | ||
191 | * @brief Updates and returns the link status. | ||
192 | * | ||
193 | * @param[in] macp pointer to the @p MACDriver object | ||
194 | * @return The link status. | ||
195 | * @retval true if the link is active. | ||
196 | * @retval false if the link is down. | ||
197 | * | ||
198 | * @notapi | ||
199 | */ | ||
200 | bool mac_lld_poll_link_status(MACDriver *macp) { | ||
201 | |||
202 | (void)macp; | ||
203 | |||
204 | return false; | ||
205 | } | ||
206 | |||
207 | /** | ||
208 | * @brief Writes to a transmit descriptor's stream. | ||
209 | * | ||
210 | * @param[in] tdp pointer to a @p MACTransmitDescriptor structure | ||
211 | * @param[in] buf pointer to the buffer containing the data to be | ||
212 | * written | ||
213 | * @param[in] size number of bytes to be written | ||
214 | * @return The number of bytes written into the descriptor's | ||
215 | * stream, this value can be less than the amount | ||
216 | * specified in the parameter @p size if the maximum | ||
217 | * frame size is reached. | ||
218 | * | ||
219 | * @notapi | ||
220 | */ | ||
221 | size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp, | ||
222 | uint8_t *buf, | ||
223 | size_t size) { | ||
224 | |||
225 | (void)tdp; | ||
226 | (void)buf; | ||
227 | |||
228 | return size; | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * @brief Reads from a receive descriptor's stream. | ||
233 | * | ||
234 | * @param[in] rdp pointer to a @p MACReceiveDescriptor structure | ||
235 | * @param[in] buf pointer to the buffer that will receive the read data | ||
236 | * @param[in] size number of bytes to be read | ||
237 | * @return The number of bytes read from the descriptor's | ||
238 | * stream, this value can be less than the amount | ||
239 | * specified in the parameter @p size if there are | ||
240 | * no more bytes to read. | ||
241 | * | ||
242 | * @notapi | ||
243 | */ | ||
244 | size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp, | ||
245 | uint8_t *buf, | ||
246 | size_t size) { | ||
247 | |||
248 | (void)rdp; | ||
249 | (void)buf; | ||
250 | |||
251 | return size; | ||
252 | } | ||
253 | |||
254 | #if (MAC_USE_ZERO_COPY == TRUE) || defined(__DOXYGEN__) | ||
255 | /** | ||
256 | * @brief Returns a pointer to the next transmit buffer in the descriptor | ||
257 | * chain. | ||
258 | * @note The API guarantees that enough buffers can be requested to fill | ||
259 | * a whole frame. | ||
260 | * | ||
261 | * @param[in] tdp pointer to a @p MACTransmitDescriptor structure | ||
262 | * @param[in] size size of the requested buffer. Specify the frame size | ||
263 | * on the first call then scale the value down subtracting | ||
264 | * the amount of data already copied into the previous | ||
265 | * buffers. | ||
266 | * @param[out] sizep pointer to variable receiving the buffer size, it is | ||
267 | * zero when the last buffer has already been returned. | ||
268 | * Note that a returned size lower than the amount | ||
269 | * requested means that more buffers must be requested | ||
270 | * in order to fill the frame data entirely. | ||
271 | * @return Pointer to the returned buffer. | ||
272 | * @retval NULL if the buffer chain has been entirely scanned. | ||
273 | * | ||
274 | * @notapi | ||
275 | */ | ||
276 | uint8_t *mac_lld_get_next_transmit_buffer(MACTransmitDescriptor *tdp, | ||
277 | size_t size, | ||
278 | size_t *sizep) { | ||
279 | |||
280 | (void)tdp; | ||
281 | (void)size; | ||
282 | (void)sizep; | ||
283 | |||
284 | return NULL; | ||
285 | } | ||
286 | |||
287 | /** | ||
288 | * @brief Returns a pointer to the next receive buffer in the descriptor | ||
289 | * chain. | ||
290 | * @note The API guarantees that the descriptor chain contains a whole | ||
291 | * frame. | ||
292 | * | ||
293 | * @param[in] rdp pointer to a @p MACReceiveDescriptor structure | ||
294 | * @param[out] sizep pointer to variable receiving the buffer size, it is | ||
295 | * zero when the last buffer has already been returned. | ||
296 | * @return Pointer to the returned buffer. | ||
297 | * @retval NULL if the buffer chain has been entirely scanned. | ||
298 | * | ||
299 | * @notapi | ||
300 | */ | ||
301 | const uint8_t *mac_lld_get_next_receive_buffer(MACReceiveDescriptor *rdp, | ||
302 | size_t *sizep) { | ||
303 | |||
304 | (void)rdp; | ||
305 | (void)sizep; | ||
306 | |||
307 | return NULL; | ||
308 | } | ||
309 | #endif /* MAC_USE_ZERO_COPY == TRUE */ | ||
310 | |||
311 | #endif /* HAL_USE_MAC == TRUE */ | ||
312 | |||
313 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_mac_lld.h b/lib/chibios/os/hal/templates/hal_mac_lld.h new file mode 100644 index 000000000..c49a377db --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_mac_lld.h | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_mac_lld.h | ||
19 | * @brief PLATFORM MAC subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup MAC | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_MAC_LLD_H | ||
26 | #define HAL_MAC_LLD_H | ||
27 | |||
28 | #if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @brief This implementation supports the zero-copy mode API. | ||
36 | */ | ||
37 | #define MAC_SUPPORTS_ZERO_COPY TRUE | ||
38 | |||
39 | /*===========================================================================*/ | ||
40 | /* Driver pre-compile time settings. */ | ||
41 | /*===========================================================================*/ | ||
42 | |||
43 | /** | ||
44 | * @name PLATFORM configuration options | ||
45 | * @{ | ||
46 | */ | ||
47 | /** | ||
48 | * @brief MAC driver enable switch. | ||
49 | * @details If set to @p TRUE the support for MAC1 is included. | ||
50 | * @note The default is @p FALSE. | ||
51 | */ | ||
52 | #if !defined(PLATFORM_MAC_USE_MAC1) || defined(__DOXYGEN__) | ||
53 | #define PLATFORM_MAC_USE_MAC1 FALSE | ||
54 | #endif | ||
55 | /** @} */ | ||
56 | |||
57 | /*===========================================================================*/ | ||
58 | /* Derived constants and error checks. */ | ||
59 | /*===========================================================================*/ | ||
60 | |||
61 | /*===========================================================================*/ | ||
62 | /* Driver data structures and types. */ | ||
63 | /*===========================================================================*/ | ||
64 | |||
65 | /** | ||
66 | * @brief Driver configuration structure. | ||
67 | */ | ||
68 | typedef struct { | ||
69 | /** | ||
70 | * @brief MAC address. | ||
71 | */ | ||
72 | uint8_t *mac_address; | ||
73 | /* End of the mandatory fields.*/ | ||
74 | } MACConfig; | ||
75 | |||
76 | /** | ||
77 | * @brief Structure representing a MAC driver. | ||
78 | */ | ||
79 | struct MACDriver { | ||
80 | /** | ||
81 | * @brief Driver state. | ||
82 | */ | ||
83 | macstate_t state; | ||
84 | /** | ||
85 | * @brief Current configuration data. | ||
86 | */ | ||
87 | const MACConfig *config; | ||
88 | /** | ||
89 | * @brief Transmit semaphore. | ||
90 | */ | ||
91 | threads_queue_t tdqueue; | ||
92 | /** | ||
93 | * @brief Receive semaphore. | ||
94 | */ | ||
95 | threads_queue_t rdqueue; | ||
96 | #if (MAC_USE_EVENTS == TRUE) || defined(__DOXYGEN__) | ||
97 | /** | ||
98 | * @brief Receive event. | ||
99 | */ | ||
100 | event_source_t rdevent; | ||
101 | #endif | ||
102 | /* End of the mandatory fields.*/ | ||
103 | }; | ||
104 | |||
105 | /** | ||
106 | * @brief Structure representing a transmit descriptor. | ||
107 | */ | ||
108 | typedef struct { | ||
109 | /** | ||
110 | * @brief Current write offset. | ||
111 | */ | ||
112 | size_t offset; | ||
113 | /** | ||
114 | * @brief Available space size. | ||
115 | */ | ||
116 | size_t size; | ||
117 | /* End of the mandatory fields.*/ | ||
118 | } MACTransmitDescriptor; | ||
119 | |||
120 | /** | ||
121 | * @brief Structure representing a receive descriptor. | ||
122 | */ | ||
123 | typedef struct { | ||
124 | /** | ||
125 | * @brief Current read offset. | ||
126 | */ | ||
127 | size_t offset; | ||
128 | /** | ||
129 | * @brief Available data size. | ||
130 | */ | ||
131 | size_t size; | ||
132 | /* End of the mandatory fields.*/ | ||
133 | } MACReceiveDescriptor; | ||
134 | |||
135 | /*===========================================================================*/ | ||
136 | /* Driver macros. */ | ||
137 | /*===========================================================================*/ | ||
138 | |||
139 | /*===========================================================================*/ | ||
140 | /* External declarations. */ | ||
141 | /*===========================================================================*/ | ||
142 | |||
143 | #if (PLATFORM_MAC_USE_MAC1 == TRUE) && !defined(__DOXYGEN__) | ||
144 | extern MACDriver ETHD1; | ||
145 | #endif | ||
146 | |||
147 | #ifdef __cplusplus | ||
148 | extern "C" { | ||
149 | #endif | ||
150 | void mac_lld_init(void); | ||
151 | void mac_lld_start(MACDriver *macp); | ||
152 | void mac_lld_stop(MACDriver *macp); | ||
153 | msg_t mac_lld_get_transmit_descriptor(MACDriver *macp, | ||
154 | MACTransmitDescriptor *tdp); | ||
155 | void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp); | ||
156 | msg_t mac_lld_get_receive_descriptor(MACDriver *macp, | ||
157 | MACReceiveDescriptor *rdp); | ||
158 | void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp); | ||
159 | bool mac_lld_poll_link_status(MACDriver *macp); | ||
160 | size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp, | ||
161 | uint8_t *buf, | ||
162 | size_t size); | ||
163 | size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp, | ||
164 | uint8_t *buf, | ||
165 | size_t size); | ||
166 | #if MAC_USE_ZERO_COPY == TRUE | ||
167 | uint8_t *mac_lld_get_next_transmit_buffer(MACTransmitDescriptor *tdp, | ||
168 | size_t size, | ||
169 | size_t *sizep); | ||
170 | const uint8_t *mac_lld_get_next_receive_buffer(MACReceiveDescriptor *rdp, | ||
171 | size_t *sizep); | ||
172 | #endif | ||
173 | #ifdef __cplusplus | ||
174 | } | ||
175 | #endif | ||
176 | |||
177 | #endif /* HAL_USE_MAC == TRUE */ | ||
178 | |||
179 | #endif /* HAL_MAC_LLD_H */ | ||
180 | |||
181 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_pal_lld.c b/lib/chibios/os/hal/templates/hal_pal_lld.c new file mode 100644 index 000000000..00d1aca97 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_pal_lld.c | |||
@@ -0,0 +1,85 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_pal_lld.c | ||
19 | * @brief PLATFORM PAL subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup PAL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /*===========================================================================*/ | ||
38 | /* Driver local variables and types. */ | ||
39 | /*===========================================================================*/ | ||
40 | |||
41 | /*===========================================================================*/ | ||
42 | /* Driver local functions. */ | ||
43 | /*===========================================================================*/ | ||
44 | |||
45 | /*===========================================================================*/ | ||
46 | /* Driver interrupt handlers. */ | ||
47 | /*===========================================================================*/ | ||
48 | |||
49 | /*===========================================================================*/ | ||
50 | /* Driver exported functions. */ | ||
51 | /*===========================================================================*/ | ||
52 | |||
53 | /** | ||
54 | * @brief STM32 I/O ports configuration. | ||
55 | * | ||
56 | * @notapi | ||
57 | */ | ||
58 | void _pal_lld_init(void) { | ||
59 | |||
60 | } | ||
61 | |||
62 | /** | ||
63 | * @brief Pads mode setup. | ||
64 | * @details This function programs a pads group belonging to the same port | ||
65 | * with the specified mode. | ||
66 | * | ||
67 | * @param[in] port the port identifier | ||
68 | * @param[in] mask the group mask | ||
69 | * @param[in] mode the mode | ||
70 | * | ||
71 | * @notapi | ||
72 | */ | ||
73 | void _pal_lld_setgroupmode(ioportid_t port, | ||
74 | ioportmask_t mask, | ||
75 | iomode_t mode) { | ||
76 | |||
77 | (void)port; | ||
78 | (void)mask; | ||
79 | (void)mode; | ||
80 | |||
81 | } | ||
82 | |||
83 | #endif /* HAL_USE_PAL == TRUE */ | ||
84 | |||
85 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_pal_lld.h b/lib/chibios/os/hal/templates/hal_pal_lld.h new file mode 100644 index 000000000..2a6284a77 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_pal_lld.h | |||
@@ -0,0 +1,444 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_pal_lld.h | ||
19 | * @brief PLATFORM PAL subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup PAL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_PAL_LLD_H | ||
26 | #define HAL_PAL_LLD_H | ||
27 | |||
28 | #if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Unsupported modes and specific modes */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /* Specifies palInit() without parameter, required until all platforms will | ||
35 | be updated to the new style.*/ | ||
36 | #define PAL_NEW_INIT | ||
37 | |||
38 | /*===========================================================================*/ | ||
39 | /* I/O Ports Types and constants. */ | ||
40 | /*===========================================================================*/ | ||
41 | |||
42 | /** | ||
43 | * @name Port related definitions | ||
44 | * @{ | ||
45 | */ | ||
46 | /** | ||
47 | * @brief Width, in bits, of an I/O port. | ||
48 | */ | ||
49 | #define PAL_IOPORTS_WIDTH 16U | ||
50 | |||
51 | /** | ||
52 | * @brief Whole port mask. | ||
53 | * @details This macro specifies all the valid bits into a port. | ||
54 | */ | ||
55 | #define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFU) | ||
56 | /** @} */ | ||
57 | |||
58 | /** | ||
59 | * @name Line handling macros | ||
60 | * @{ | ||
61 | */ | ||
62 | /** | ||
63 | * @brief Forms a line identifier. | ||
64 | * @details A port/pad pair are encoded into an @p ioline_t type. The encoding | ||
65 | * of this type is platform-dependent. | ||
66 | */ | ||
67 | #define PAL_LINE(port, pad) \ | ||
68 | ((ioline_t)((uint32_t)(port)) | ((uint32_t)(pad))) | ||
69 | |||
70 | /** | ||
71 | * @brief Decodes a port identifier from a line identifier. | ||
72 | */ | ||
73 | #define PAL_PORT(line) \ | ||
74 | ((stm32_gpio_t *)(((uint32_t)(line)) & 0xFFFFFFF0U)) | ||
75 | |||
76 | /** | ||
77 | * @brief Decodes a pad identifier from a line identifier. | ||
78 | */ | ||
79 | #define PAL_PAD(line) \ | ||
80 | ((uint32_t)((uint32_t)(line) & 0x0000000FU)) | ||
81 | |||
82 | /** | ||
83 | * @brief Value identifying an invalid line. | ||
84 | */ | ||
85 | #define PAL_NOLINE 0U | ||
86 | /** @} */ | ||
87 | |||
88 | /** | ||
89 | * @brief Generic I/O ports static initializer. | ||
90 | * @details An instance of this structure must be passed to @p palInit() at | ||
91 | * system startup time in order to initialized the digital I/O | ||
92 | * subsystem. This represents only the initial setup, specific pads | ||
93 | * or whole ports can be reprogrammed at later time. | ||
94 | * @note Implementations may extend this structure to contain more, | ||
95 | * architecture dependent, fields. | ||
96 | */ | ||
97 | typedef struct { | ||
98 | |||
99 | } PALConfig; | ||
100 | |||
101 | /** | ||
102 | * @brief Digital I/O port sized unsigned type. | ||
103 | */ | ||
104 | typedef uint32_t ioportmask_t; | ||
105 | |||
106 | /** | ||
107 | * @brief Digital I/O modes. | ||
108 | */ | ||
109 | typedef uint32_t iomode_t; | ||
110 | |||
111 | /** | ||
112 | * @brief Type of an I/O line. | ||
113 | */ | ||
114 | typedef uint32_t ioline_t; | ||
115 | |||
116 | /** | ||
117 | * @brief Port Identifier. | ||
118 | * @details This type can be a scalar or some kind of pointer, do not make | ||
119 | * any assumption about it, use the provided macros when populating | ||
120 | * variables of this type. | ||
121 | */ | ||
122 | typedef uint32_t ioportid_t; | ||
123 | |||
124 | /** | ||
125 | * @brief Type of an pad identifier. | ||
126 | */ | ||
127 | typedef uint32_t iopadid_t; | ||
128 | |||
129 | /*===========================================================================*/ | ||
130 | /* I/O Ports Identifiers. */ | ||
131 | /*===========================================================================*/ | ||
132 | |||
133 | /** | ||
134 | * @brief First I/O port identifier. | ||
135 | * @details Low level drivers can define multiple ports, it is suggested to | ||
136 | * use this naming convention. | ||
137 | */ | ||
138 | #define IOPORT1 0 | ||
139 | |||
140 | /*===========================================================================*/ | ||
141 | /* Implementation, some of the following macros could be implemented as */ | ||
142 | /* functions, if so please put them in pal_lld.c. */ | ||
143 | /*===========================================================================*/ | ||
144 | |||
145 | /** | ||
146 | * @brief Low level PAL subsystem initialization. | ||
147 | * | ||
148 | * @notapi | ||
149 | */ | ||
150 | #define pal_lld_init() _pal_lld_init() | ||
151 | |||
152 | /** | ||
153 | * @brief Reads the physical I/O port states. | ||
154 | * | ||
155 | * @param[in] port port identifier | ||
156 | * @return The port bits. | ||
157 | * | ||
158 | * @notapi | ||
159 | */ | ||
160 | #define pal_lld_readport(port) 0U | ||
161 | |||
162 | /** | ||
163 | * @brief Reads the output latch. | ||
164 | * @details The purpose of this function is to read back the latched output | ||
165 | * value. | ||
166 | * | ||
167 | * @param[in] port port identifier | ||
168 | * @return The latched logical states. | ||
169 | * | ||
170 | * @notapi | ||
171 | */ | ||
172 | #define pal_lld_readlatch(port) 0U | ||
173 | |||
174 | /** | ||
175 | * @brief Writes a bits mask on a I/O port. | ||
176 | * | ||
177 | * @param[in] port port identifier | ||
178 | * @param[in] bits bits to be written on the specified port | ||
179 | * | ||
180 | * @notapi | ||
181 | */ | ||
182 | #define pal_lld_writeport(port, bits) \ | ||
183 | do { \ | ||
184 | (void)port; \ | ||
185 | (void)bits; \ | ||
186 | } while (false) | ||
187 | |||
188 | /** | ||
189 | * @brief Sets a bits mask on a I/O port. | ||
190 | * @note The @ref PAL provides a default software implementation of this | ||
191 | * functionality, implement this function if can optimize it by using | ||
192 | * special hardware functionalities or special coding. | ||
193 | * | ||
194 | * @param[in] port port identifier | ||
195 | * @param[in] bits bits to be ORed on the specified port | ||
196 | * | ||
197 | * @notapi | ||
198 | */ | ||
199 | #define pal_lld_setport(port, bits) \ | ||
200 | do { \ | ||
201 | (void)port; \ | ||
202 | (void)bits; \ | ||
203 | } while (false) | ||
204 | |||
205 | /** | ||
206 | * @brief Clears a bits mask on a I/O port. | ||
207 | * @note The @ref PAL provides a default software implementation of this | ||
208 | * functionality, implement this function if can optimize it by using | ||
209 | * special hardware functionalities or special coding. | ||
210 | * | ||
211 | * @param[in] port port identifier | ||
212 | * @param[in] bits bits to be cleared on the specified port | ||
213 | * | ||
214 | * @notapi | ||
215 | */ | ||
216 | #define pal_lld_clearport(port, bits) \ | ||
217 | do { \ | ||
218 | (void)port; \ | ||
219 | (void)bits; \ | ||
220 | } while (false) | ||
221 | |||
222 | /** | ||
223 | * @brief Toggles a bits mask on a I/O port. | ||
224 | * @note The @ref PAL provides a default software implementation of this | ||
225 | * functionality, implement this function if can optimize it by using | ||
226 | * special hardware functionalities or special coding. | ||
227 | * | ||
228 | * @param[in] port port identifier | ||
229 | * @param[in] bits bits to be XORed on the specified port | ||
230 | * | ||
231 | * @notapi | ||
232 | */ | ||
233 | #define pal_lld_toggleport(port, bits) \ | ||
234 | do { \ | ||
235 | (void)port; \ | ||
236 | (void)bits; \ | ||
237 | } while (false) | ||
238 | |||
239 | /** | ||
240 | * @brief Reads a group of bits. | ||
241 | * @note The @ref PAL provides a default software implementation of this | ||
242 | * functionality, implement this function if can optimize it by using | ||
243 | * special hardware functionalities or special coding. | ||
244 | * | ||
245 | * @param[in] port port identifier | ||
246 | * @param[in] mask group mask | ||
247 | * @param[in] offset group bit offset within the port | ||
248 | * @return The group logical states. | ||
249 | * | ||
250 | * @notapi | ||
251 | */ | ||
252 | #define pal_lld_readgroup(port, mask, offset) 0U | ||
253 | |||
254 | /** | ||
255 | * @brief Writes a group of bits. | ||
256 | * @note The @ref PAL provides a default software implementation of this | ||
257 | * functionality, implement this function if can optimize it by using | ||
258 | * special hardware functionalities or special coding. | ||
259 | * | ||
260 | * @param[in] port port identifier | ||
261 | * @param[in] mask group mask | ||
262 | * @param[in] offset group bit offset within the port | ||
263 | * @param[in] bits bits to be written. Values exceeding the group width | ||
264 | * are masked. | ||
265 | * | ||
266 | * @notapi | ||
267 | */ | ||
268 | #define pal_lld_writegroup(port, mask, offset, bits) \ | ||
269 | do { \ | ||
270 | (void)port; \ | ||
271 | (void)mask; \ | ||
272 | (void)offset; \ | ||
273 | (void)bits; \ | ||
274 | } while (false) | ||
275 | |||
276 | /** | ||
277 | * @brief Pads group mode setup. | ||
278 | * @details This function programs a pads group belonging to the same port | ||
279 | * with the specified mode. | ||
280 | * @note Programming an unknown or unsupported mode is silently ignored. | ||
281 | * | ||
282 | * @param[in] port port identifier | ||
283 | * @param[in] mask group mask | ||
284 | * @param[in] offset group bit offset within the port | ||
285 | * @param[in] mode group mode | ||
286 | * | ||
287 | * @notapi | ||
288 | */ | ||
289 | #define pal_lld_setgroupmode(port, mask, offset, mode) \ | ||
290 | _pal_lld_setgroupmode(port, mask << offset, mode) | ||
291 | |||
292 | /** | ||
293 | * @brief Reads a logical state from an I/O pad. | ||
294 | * @note The @ref PAL provides a default software implementation of this | ||
295 | * functionality, implement this function if can optimize it by using | ||
296 | * special hardware functionalities or special coding. | ||
297 | * | ||
298 | * @param[in] port port identifier | ||
299 | * @param[in] pad pad number within the port | ||
300 | * @return The logical state. | ||
301 | * @retval PAL_LOW low logical state. | ||
302 | * @retval PAL_HIGH high logical state. | ||
303 | * | ||
304 | * @notapi | ||
305 | */ | ||
306 | #define pal_lld_readpad(port, pad) PAL_LOW | ||
307 | |||
308 | /** | ||
309 | * @brief Writes a logical state on an output pad. | ||
310 | * @note This function is not meant to be invoked directly by the | ||
311 | * application code. | ||
312 | * @note The @ref PAL provides a default software implementation of this | ||
313 | * functionality, implement this function if can optimize it by using | ||
314 | * special hardware functionalities or special coding. | ||
315 | * | ||
316 | * @param[in] port port identifier | ||
317 | * @param[in] pad pad number within the port | ||
318 | * @param[in] bit logical value, the value must be @p PAL_LOW or | ||
319 | * @p PAL_HIGH | ||
320 | * | ||
321 | * @notapi | ||
322 | */ | ||
323 | #define pal_lld_writepad(port, pad, bit) \ | ||
324 | do { \ | ||
325 | (void)port; \ | ||
326 | (void)pad; \ | ||
327 | (void)bit; \ | ||
328 | } while (false) | ||
329 | |||
330 | /** | ||
331 | * @brief Sets a pad logical state to @p PAL_HIGH. | ||
332 | * @note The @ref PAL provides a default software implementation of this | ||
333 | * functionality, implement this function if can optimize it by using | ||
334 | * special hardware functionalities or special coding. | ||
335 | * | ||
336 | * @param[in] port port identifier | ||
337 | * @param[in] pad pad number within the port | ||
338 | * | ||
339 | * @notapi | ||
340 | */ | ||
341 | #define pal_lld_setpad(port, pad) \ | ||
342 | do { \ | ||
343 | (void)port; \ | ||
344 | (void)pad; \ | ||
345 | } while (false) | ||
346 | |||
347 | /** | ||
348 | * @brief Clears a pad logical state to @p PAL_LOW. | ||
349 | * @note The @ref PAL provides a default software implementation of this | ||
350 | * functionality, implement this function if can optimize it by using | ||
351 | * special hardware functionalities or special coding. | ||
352 | * | ||
353 | * @param[in] port port identifier | ||
354 | * @param[in] pad pad number within the port | ||
355 | * | ||
356 | * @notapi | ||
357 | */ | ||
358 | #define pal_lld_clearpad(port, pad) \ | ||
359 | do { \ | ||
360 | (void)port; \ | ||
361 | (void)pad; \ | ||
362 | } while (false) | ||
363 | |||
364 | /** | ||
365 | * @brief Toggles a pad logical state. | ||
366 | * @note The @ref PAL provides a default software implementation of this | ||
367 | * functionality, implement this function if can optimize it by using | ||
368 | * special hardware functionalities or special coding. | ||
369 | * | ||
370 | * @param[in] port port identifier | ||
371 | * @param[in] pad pad number within the port | ||
372 | * | ||
373 | * @notapi | ||
374 | */ | ||
375 | #define pal_lld_togglepad(port, pad) \ | ||
376 | do { \ | ||
377 | (void)port; \ | ||
378 | (void)pad; \ | ||
379 | } while (false) | ||
380 | |||
381 | /** | ||
382 | * @brief Pad mode setup. | ||
383 | * @details This function programs a pad with the specified mode. | ||
384 | * @note The @ref PAL provides a default software implementation of this | ||
385 | * functionality, implement this function if can optimize it by using | ||
386 | * special hardware functionalities or special coding. | ||
387 | * @note Programming an unknown or unsupported mode is silently ignored. | ||
388 | * | ||
389 | * @param[in] port port identifier | ||
390 | * @param[in] pad pad number within the port | ||
391 | * @param[in] mode pad mode | ||
392 | * | ||
393 | * @notapi | ||
394 | */ | ||
395 | #define pal_lld_setpadmode(port, pad, mode) \ | ||
396 | do { \ | ||
397 | (void)port; \ | ||
398 | (void)pad; \ | ||
399 | (void)mode; \ | ||
400 | } while (false) | ||
401 | |||
402 | /** | ||
403 | * @brief Returns a PAL event structure associated to a pad. | ||
404 | * | ||
405 | * @param[in] port port identifier | ||
406 | * @param[in] pad pad number within the port | ||
407 | * | ||
408 | * @notapi | ||
409 | */ | ||
410 | #define pal_lld_get_pad_event(port, pad) \ | ||
411 | &_pal_events[0]; (void)(port); (void)pad | ||
412 | |||
413 | /** | ||
414 | * @brief Returns a PAL event structure associated to a line. | ||
415 | * | ||
416 | * @param[in] line line identifier | ||
417 | * | ||
418 | * @notapi | ||
419 | */ | ||
420 | #define pal_lld_get_line_event(line) \ | ||
421 | &_pal_events[0]; (void)line | ||
422 | |||
423 | #if !defined(__DOXYGEN__) | ||
424 | #if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) | ||
425 | extern palevent_t _pal_events[1]; | ||
426 | #endif | ||
427 | #endif | ||
428 | |||
429 | #ifdef __cplusplus | ||
430 | extern "C" { | ||
431 | #endif | ||
432 | void _pal_lld_init(void); | ||
433 | void _pal_lld_setgroupmode(ioportid_t port, | ||
434 | ioportmask_t mask, | ||
435 | iomode_t mode); | ||
436 | #ifdef __cplusplus | ||
437 | } | ||
438 | #endif | ||
439 | |||
440 | #endif /* HAL_USE_PAL == TRUE */ | ||
441 | |||
442 | #endif /* HAL_PAL_LLD_H */ | ||
443 | |||
444 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_pwm_lld.c b/lib/chibios/os/hal/templates/hal_pwm_lld.c new file mode 100644 index 000000000..301163fa2 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_pwm_lld.c | |||
@@ -0,0 +1,220 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_pwm_lld.c | ||
19 | * @brief PLATFORM PWM subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup PWM | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | /*===========================================================================*/ | ||
34 | /* Driver exported variables. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @brief PWMD1 driver identifier. | ||
39 | * @note The driver PWMD1 allocates the complex timer TIM1 when enabled. | ||
40 | */ | ||
41 | #if (PLATFORM_PWM_USE_PWM1 == TRUE) || defined(__DOXYGEN__) | ||
42 | PWMDriver PWMD1; | ||
43 | #endif | ||
44 | |||
45 | /*===========================================================================*/ | ||
46 | /* Driver local variables and types. */ | ||
47 | /*===========================================================================*/ | ||
48 | |||
49 | /*===========================================================================*/ | ||
50 | /* Driver local functions. */ | ||
51 | /*===========================================================================*/ | ||
52 | |||
53 | /*===========================================================================*/ | ||
54 | /* Driver interrupt handlers. */ | ||
55 | /*===========================================================================*/ | ||
56 | |||
57 | /*===========================================================================*/ | ||
58 | /* Driver exported functions. */ | ||
59 | /*===========================================================================*/ | ||
60 | |||
61 | /** | ||
62 | * @brief Low level PWM driver initialization. | ||
63 | * | ||
64 | * @notapi | ||
65 | */ | ||
66 | void pwm_lld_init(void) { | ||
67 | |||
68 | #if PLATFORM_PWM_USE_PWM1 == TRUE | ||
69 | /* Driver initialization.*/ | ||
70 | pwmObjectInit(&PWMD1); | ||
71 | #endif | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * @brief Configures and activates the PWM peripheral. | ||
76 | * @note Starting a driver that is already in the @p PWM_READY state | ||
77 | * disables all the active channels. | ||
78 | * | ||
79 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
80 | * | ||
81 | * @notapi | ||
82 | */ | ||
83 | void pwm_lld_start(PWMDriver *pwmp) { | ||
84 | |||
85 | if (pwmp->state == PWM_STOP) { | ||
86 | /* Clock activation and timer reset.*/ | ||
87 | #if PLATFORM_PWM_USE_PWM1 == TRUE | ||
88 | if (&PWMD1 == pwmp) { | ||
89 | |||
90 | } | ||
91 | #endif | ||
92 | } | ||
93 | } | ||
94 | |||
95 | /** | ||
96 | * @brief Deactivates the PWM peripheral. | ||
97 | * | ||
98 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
99 | * | ||
100 | * @notapi | ||
101 | */ | ||
102 | void pwm_lld_stop(PWMDriver *pwmp) { | ||
103 | |||
104 | /* If in ready state then disables the PWM clock.*/ | ||
105 | if (pwmp->state == PWM_READY) { | ||
106 | #if PLATFORM_PWM_USE_PWM1 == TRUE | ||
107 | if (&PWMD1 == pwmp) { | ||
108 | |||
109 | } | ||
110 | #endif | ||
111 | } | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * @brief Enables a PWM channel. | ||
116 | * @pre The PWM unit must have been activated using @p pwmStart(). | ||
117 | * @post The channel is active using the specified configuration. | ||
118 | * @note The function has effect at the next cycle start. | ||
119 | * @note Channel notification is not enabled. | ||
120 | * | ||
121 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
122 | * @param[in] channel PWM channel identifier (0...channels-1) | ||
123 | * @param[in] width PWM pulse width as clock pulses number | ||
124 | * | ||
125 | * @notapi | ||
126 | */ | ||
127 | void pwm_lld_enable_channel(PWMDriver *pwmp, | ||
128 | pwmchannel_t channel, | ||
129 | pwmcnt_t width) { | ||
130 | |||
131 | (void)pwmp; | ||
132 | (void)channel; | ||
133 | (void)width; | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * @brief Disables a PWM channel and its notification. | ||
138 | * @pre The PWM unit must have been activated using @p pwmStart(). | ||
139 | * @post The channel is disabled and its output line returned to the | ||
140 | * idle state. | ||
141 | * @note The function has effect at the next cycle start. | ||
142 | * | ||
143 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
144 | * @param[in] channel PWM channel identifier (0...channels-1) | ||
145 | * | ||
146 | * @notapi | ||
147 | */ | ||
148 | void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel) { | ||
149 | |||
150 | (void)pwmp; | ||
151 | (void)channel; | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * @brief Enables the periodic activation edge notification. | ||
156 | * @pre The PWM unit must have been activated using @p pwmStart(). | ||
157 | * @note If the notification is already enabled then the call has no effect. | ||
158 | * | ||
159 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
160 | * | ||
161 | * @notapi | ||
162 | */ | ||
163 | void pwm_lld_enable_periodic_notification(PWMDriver *pwmp) { | ||
164 | |||
165 | (void)pwmp; | ||
166 | } | ||
167 | |||
168 | /** | ||
169 | * @brief Disables the periodic activation edge notification. | ||
170 | * @pre The PWM unit must have been activated using @p pwmStart(). | ||
171 | * @note If the notification is already disabled then the call has no effect. | ||
172 | * | ||
173 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
174 | * | ||
175 | * @notapi | ||
176 | */ | ||
177 | void pwm_lld_disable_periodic_notification(PWMDriver *pwmp) { | ||
178 | |||
179 | (void)pwmp; | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * @brief Enables a channel de-activation edge notification. | ||
184 | * @pre The PWM unit must have been activated using @p pwmStart(). | ||
185 | * @pre The channel must have been activated using @p pwmEnableChannel(). | ||
186 | * @note If the notification is already enabled then the call has no effect. | ||
187 | * | ||
188 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
189 | * @param[in] channel PWM channel identifier (0...channels-1) | ||
190 | * | ||
191 | * @notapi | ||
192 | */ | ||
193 | void pwm_lld_enable_channel_notification(PWMDriver *pwmp, | ||
194 | pwmchannel_t channel) { | ||
195 | |||
196 | (void)pwmp; | ||
197 | (void)channel; | ||
198 | } | ||
199 | |||
200 | /** | ||
201 | * @brief Disables a channel de-activation edge notification. | ||
202 | * @pre The PWM unit must have been activated using @p pwmStart(). | ||
203 | * @pre The channel must have been activated using @p pwmEnableChannel(). | ||
204 | * @note If the notification is already disabled then the call has no effect. | ||
205 | * | ||
206 | * @param[in] pwmp pointer to a @p PWMDriver object | ||
207 | * @param[in] channel PWM channel identifier (0...channels-1) | ||
208 | * | ||
209 | * @notapi | ||
210 | */ | ||
211 | void pwm_lld_disable_channel_notification(PWMDriver *pwmp, | ||
212 | pwmchannel_t channel) { | ||
213 | |||
214 | (void)pwmp; | ||
215 | (void)channel; | ||
216 | } | ||
217 | |||
218 | #endif /* HAL_USE_PWM == TRUE */ | ||
219 | |||
220 | /** @} */ | ||
diff --git a/lib/chibios/os/hal/templates/hal_pwm_lld.h b/lib/chibios/os/hal/templates/hal_pwm_lld.h new file mode 100644 index 000000000..625dd5755 --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_pwm_lld.h | |||
@@ -0,0 +1,215 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_pwm_lld.h | ||
19 | * @brief PLATFORM PWM subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup PWM | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_PWM_LLD_H | ||
26 | #define HAL_PWM_LLD_H | ||
27 | |||
28 | #if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @brief Number of PWM channels per PWM driver. | ||
36 | */ | ||
37 | #define PWM_CHANNELS 4 | ||
38 | |||
39 | /*===========================================================================*/ | ||
40 | /* Driver pre-compile time settings. */ | ||
41 | /*===========================================================================*/ | ||
42 | |||
43 | /** | ||
44 | * @name PLATFORM configuration options | ||
45 | * @{ | ||
46 | */ | ||
47 | /** | ||
48 | * @brief PWMD1 driver enable switch. | ||
49 | * @details If set to @p TRUE the support for PWM1 is included. | ||
50 | * @note The default is @p FALSE. | ||
51 | */ | ||
52 | #if !defined(PLATFORM_PWM_USE_PWM1) || defined(__DOXYGEN__) | ||
53 | #define PLATFORM_PWM_USE_PWM1 FALSE | ||
54 | #endif | ||
55 | /** @} */ | ||
56 | |||
57 | /*===========================================================================*/ | ||
58 | /* Configuration checks. */ | ||
59 | /*===========================================================================*/ | ||
60 | |||
61 | /*===========================================================================*/ | ||
62 | /* Driver data structures and types. */ | ||