blob: b82849ab98a0c3cd31a0c29dd7c34bd5f7baec33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
/*!
* @file apm32f0xx_cec.c
*
* @brief This file contains all the functions for the CEC peripheral
*
* @version V1.0.3
*
* @date 2022-09-20
*
* @attention
*
* Copyright (C) 2020-2022 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
*
* The program is only for reference, which is distributed in the hope
* that it will be useful and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
* and limitations under the License.
*/
/* Includes */
#include "apm32f0xx_cec.h"
#include "apm32f0xx_rcm.h"
/** @addtogroup APM32F0xx_StdPeriphDriver
@{
*/
/** @addtogroup CEC_Driver
@{
*/
/** @defgroup CEC_Macros Macros
@{
*/
/**@} end of group CEC_Macros */
/** @defgroup CEC_Enumerations Enumerations
@{
*/
/**@} end of group CEC_Enumerations */
/** @defgroup CEC_Structures Structures
@{
*/
/**@} end of group CEC_Structures */
/** @defgroup CEC_Variables Variables
@{
*/
/**@} end of group CEC_Variables */
/** @defgroup CEC_Functions Functions
@{
*/
/*!
* @brief Reset CEC peripheral registers to their default values.
*
* @param None
*
* @retval None
*/
void CEC_Reset(void)
{
RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_CEC);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_CEC);
}
/*!
* @brief Configs the CEC peripheral according to the specified parameters
* in the cecConfig.
*
* @param cecConfig: pointer to an CEC_Config_T structure that is used to
* the configuration information for the specified CEC peripheral.
*
* @retval None
*
* @note The CEC parameters must be configured before enabling the CEC peripheral.
*/
void CEC_Config(CEC_Config_T* cecConfig)
{
CEC->CFG_B.SFTCFG = cecConfig->signalFreeTime;
CEC->CFG_B.RXTCFG = cecConfig->RxTolerance;
CEC->CFG_B.RXSBRERR = cecConfig->stopReception;
CEC->CFG_B.GEBRERR = cecConfig->bitRisingError;
CEC->CFG_B.GELBPERR = cecConfig->longPeriodError;
CEC->CFG_B.AEBGIB = cecConfig->broadcastrNoGen;
CEC->CFG_B.SFTOB = cecConfig->signalFreeTimeOption;
}
/*!
* @brief Fills each CEC_InitStruct member with its default value.
*
* @param cecConfig: pointer to a CEC_InitTypeDef structure which will
* be initialized.
*
* @retval None
*/
void CEC_ConfigStructInit(CEC_Config_T* cecConfig)
{
cecConfig->signalFreeTime = CEC_SINGANL_FREETIME_STANDARD;
cecConfig->RxTolerance = CEC_RX_TOLERANCE_STANDARD;
cecConfig->stopReception = CEC_STOP_RECEPTION_OFF;
cecConfig->bitRisingError = CEC_BIT_RISING_ERR_OFF;
cecConfig->longPeriodError = CEC_LONG_PERIOD_ERR_OFF;
cecConfig->broadcastrNoGen = CEC_BROADCAST_NO_ERR_OFF;
cecConfig->signalFreeTimeOption = CEC_SIGNAL_FREETIME_OPTION_OFF;
}
/*!
* @brief Enables the CEC peripheral.
*
* @param None
*
* @retval None
*/
void CEC_Enable(void)
{
CEC->CTRL_B.CECEN = SET;
}
/*!
* @brief Disables the CEC peripheral.
*
* @param None
*
* @retval None
*/
void CEC_Disable(void)
{
CEC->CTRL_B.CECEN = RESET;
}
/*!
* @brief Enables the CEC Listen Mode.
*
* @param None
*
* @retval None
*/
void CEC_EnableListenMode(void)
{
CEC->CFG_B.LMODSEL = SET;
}
/*!
* @brief Disables the CEC Listen Mode.
*
* @param None
*
* @retval None
*/
void CEC_DisableListenMode(void)
{
CEC->CFG_B.LMODSEL = RESET;
}
/*!
* @brief Defines the Own Address of the CEC device.
*
* @param ownAddress: The CEC own address.
*
* @retval None
*/
void CEC_ConfigOwnAddress(uint8_t ownAddress)
{
CEC->CFG_B.OACFG |= (1 << ownAddress);
}
/*!
* @brief Clears the Own Address of the CEC device.
*
* @param CEC_OwnAddress: The CEC own address.
*
* @retval None
*/
void CEC_ClearQwnAddress(void)
{
CEC->CFG = 0x00;
}
/*!
* @brief Transmits single data through the CEC peripheral.
*
* @param Data: the data to transmit.
*
* @retval None
*/
void CEC_TxData(uint8_t Data)
{
CEC->TXDATA = Data;
}
/*!
* @brief Returns the most recent received data by the CEC peripheral.
*
* @param None
*
* @retval The received data.
*/
uint8_t CEC_RxData(void)
{
return (uint8_t)(CEC->RXDATA);
}
/*!
* @brief Starts a new message.
*
* @param None
*
* @retval None
*/
void CEC_StartNewMessage(void)
{
CEC->CTRL_B.TXSM = SET;
}
/*!
* @brief Transmits message with an EOM bit.
*
* @param None
*
* @retval None
*/
void CEC_CompleteMessage(void)
{
CEC->CTRL_B.TXEM = SET;
}
/*!
* @brief Enables the selected CEC interrupts.
*
* @param flag: specifies the CEC interrupt source to be enabled.
* This parameter can be any combination of the following values:
* @arg CEC_INT_RXBR Rx-Byte Received
* @arg CEC_INT_RXEND End Of Reception
* @arg CEC_INT_RXOVR Rx Overrun.
* @arg CEC_INT_BRE Rx Bit Rising Error
* @arg CEC_INT_SBPE Rx Short period Error
* @arg CEC_INT_LBPE Rx Long period Error
* @arg CEC_INT_RXACKE Rx-Missing Acknowledge
* @arg CEC_INT_ARBLST Arbitration Lost
* @arg CEC_INT_TXBR Tx-Byte Request.
* @arg CEC_INT_TXEND End of Transmission
* @arg CEC_INT_TXUDR Tx-Buffer Underrun.
* @arg CEC_INT_TXERR Tx Error.
* @arg CEC_INT_TXACKE Tx Missing acknowledge Error
*
* @retval None
*/
void CEC_EnableInterrupt(uint32_t interrupt)
{
CEC->INTEN |= (uint32_t)interrupt;
}
/*!
* @brief Disables the selected CEC interrupts.
*
* @param flag: specifies the CEC interrupt source to be enabled.
* This parameter can be any combination of the following values:
* @arg CEC_INT_RXBR Rx-Byte Received
* @arg CEC_INT_RXEND End Of Reception
* @arg CEC_INT_RXOVR Rx Overrun.
* @arg CEC_INT_BRE Rx Bit Rising Error
* @arg CEC_INT_SBPE Rx Short period Error
* @arg CEC_INT_LBPE Rx Long period Error
* @arg CEC_INT_RXACKE Rx-Missing Acknowledge
* @arg CEC_INT_ARBLST Arbitration Lost
* @arg CEC_INT_TXBR Tx-Byte Request.
* @arg CEC_INT_TXEND End of Transmission
* @arg CEC_INT_TXUDR Tx-Buffer Underrun.
* @arg CEC_INT_TXERR Tx Error.
* @arg CEC_INT_TXACKE Tx Missing acknowledge Error
*
* @retval None
*/
void CEC_DisableInterrupt(uint32_t interrupt)
{
CEC->INTEN &= ~(uint32_t)interrupt;
}
/*!
* @brief Read the CEC flag status.
*
* @param flag: specifies the CEC interrupt source to be enabled.
* This parameter can be any combination of the following values:
* @arg CEC_FLAG_RXBR Rx-Byte Received
* @arg CEC_FLAG_RXEND End Of Reception
* @arg CEC_FLAG_RXOVR Rx Overrun.
* @arg CEC_FLAG_BRE Rx Bit Rising Error
* @arg CEC_FLAG_SBPE Rx Short period Error
* @arg CEC_FLAG_LBPE Rx Long period Error
* @arg CEC_FLAG_RXACKE Rx-Missing Acknowledge
* @arg CEC_FLAG_ARBLST Arbitration Lost
* @arg CEC_FLAG_TXBR Tx-Byte Request.
* @arg CEC_FLAG_TXEND End of Transmission
* @arg CEC_FLAG_TXUDR Tx-Buffer Underrun.
* @arg CEC_FLAG_TXERR Tx Error.
* @arg CEC_FLAG_TXACKE Tx Missing acknowledge Error
*
* @retval The new state of CEC_FLAG (SET or RESET)
*/
uint8_t CEC_ReadStatusFlag(uint32_t flag)
{
uint32_t status;
status = (uint32_t)(CEC->STS & flag);
if (status == flag)
{
return SET;
}
return RESET;
}
/*!
* @brief Clears the CEC's pending flags.
*
* @param flag: specifies the flag to clear.
* This parameter can be any combination of the following values:
* @arg CEC_FLAG_RXBR Rx-Byte Received
* @arg CEC_FLAG_RXEND End Of Reception
* @arg CEC_FLAG_RXOVR Rx Overrun.
* @arg CEC_FLAG_BRE Rx Bit Rising Error
* @arg CEC_FLAG_SBPE Rx Short period Error
* @arg CEC_FLAG_LBPE Rx Long period Error
* @arg CEC_FLAG_RXACKE Rx-Missing Acknowledge
* @arg CEC_FLAG_ARBLST Arbitration Lost
* @arg CEC_FLAG_TXBR Tx-Byte Request.
* @arg CEC_FLAG_TXEND End of Transmission
* @arg CEC_FLAG_TXUDR Tx-Buffer Underrun.
* @arg CEC_FLAG_TXERR Tx Error.
* @arg CEC_FLAG_TXACKE Tx Missing acknowledge Error
*
* @retval None
*/
void CEC_ClearStatusFlag(uint32_t flag)
{
CEC->STS = flag;
}
/*!
* @brief Checks whether the specified CEC interrupt has occurred or not.
*
* @param flag: specifies the CEC interrupt source to check.
* This parameter can be one of the following values:
* @arg CEC_INT_RXBR Rx-Byte Received
* @arg CEC_INT_RXEND End Of Reception
* @arg CEC_INT_RXOVR Rx Overrun.
* @arg CEC_INT_BRE Rx Bit Rising Error
* @arg CEC_INT_SBPE Rx Short period Error
* @arg CEC_INT_LBPE Rx Long period Error
* @arg CEC_INT_RXACKE Rx-Missing Acknowledge
* @arg CEC_INT_ARBLST Arbitration Lost
* @arg CEC_INT_TXBR Tx-Byte Request.
* @arg CEC_INT_TXEND End of Transmission
* @arg CEC_INT_TXUDR Tx-Buffer Underrun.
* @arg CEC_INT_TXERR Tx Error.
* @arg CEC_INT_TXACKE Tx Missing acknowledge Error
*
* @retval The new state of Flag (SET or RESET).
*/
uint8_t CEC_ReadIntFlag(uint16_t flag)
{
uint32_t intEnable;
uint32_t intStatus;
intEnable = (CEC->INTEN & flag);
intStatus = (CEC->STS & flag);
if ((intStatus != (uint32_t)RESET) && intEnable)
{
return SET;
}
else
{
return RESET;
}
}
/*!
* @brief Clears the CEC's interrupt flag.
*
* @param flag: specifies the CEC interrupt flag to clear.
* This parameter can be any combination of the following values:
* @arg CEC_INT_RXBR Rx-Byte Received
* @arg CEC_INT_RXEND End Of Reception
* @arg CEC_INT_RXOVR Rx Overrun.
* @arg CEC_INT_BRE Rx Bit Rising Error
* @arg CEC_INT_SBPE Rx Short period Error
* @arg CEC_INT_LBPE Rx Long period Error
* @arg CEC_INT_RXACKE Rx-Missing Acknowledge
* @arg CEC_INT_ARBLST Arbitration Lost
* @arg CEC_INT_TXBR Tx-Byte Request.
* @arg CEC_INT_TXEND End of Transmission
* @arg CEC_INT_TXUDR Tx-Buffer Underrun.
* @arg CEC_INT_TXERR Tx Error.
* @arg CEC_INT_TXACKE Tx Missing acknowledge Error
*
* @retval None
*/
void CEC_ClearIntFlag(uint16_t flag)
{
CEC->STS = flag;
}
/**@} end of group CEC_Functions */
/**@} end of group CEC_Driver */
/**@} end of group APM32F0xx_StdPeriphDriver */
|