ChibiOS  21.6.0
hal_i2s.c
Go to the documentation of this file.
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.c
19  * @brief I2S Driver code.
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 /*===========================================================================*/
38 /* Driver local variables and types. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Driver local functions. */
43 /*===========================================================================*/
44 
45 /*===========================================================================*/
46 /* Driver exported functions. */
47 /*===========================================================================*/
48 
49 /**
50  * @brief I2S Driver initialization.
51  * @note This function is implicitly invoked by @p halInit(), there is
52  * no need to explicitly initialize the driver.
53  *
54  * @init
55  */
56 void i2sInit(void) {
57 
58  i2s_lld_init();
59 }
60 
61 /**
62  * @brief Initializes the standard part of a @p I2SDriver structure.
63  *
64  * @param[out] i2sp pointer to the @p I2SDriver object
65  *
66  * @init
67  */
68 void i2sObjectInit(I2SDriver *i2sp) {
69 
70  i2sp->state = I2S_STOP;
71  i2sp->config = NULL;
72 }
73 
74 /**
75  * @brief Configures and activates the I2S peripheral.
76  *
77  * @param[in] i2sp pointer to the @p I2SDriver object
78  * @param[in] config pointer to the @p I2SConfig object
79  *
80  * @api
81  */
82 void i2sStart(I2SDriver *i2sp, const I2SConfig *config) {
83 
84  osalDbgCheck((i2sp != NULL) && (config != NULL));
85 
86  osalSysLock();
87  osalDbgAssert((i2sp->state == I2S_STOP) || (i2sp->state == I2S_READY),
88  "invalid state");
89  i2sp->config = config;
90  i2s_lld_start(i2sp);
91  i2sp->state = I2S_READY;
92  osalSysUnlock();
93 }
94 
95 /**
96  * @brief Deactivates the I2S peripheral.
97  *
98  * @param[in] i2sp pointer to the @p I2SDriver object
99  *
100  * @api
101  */
102 void i2sStop(I2SDriver *i2sp) {
103 
104  osalDbgCheck(i2sp != NULL);
105 
106  osalSysLock();
107 
108  osalDbgAssert((i2sp->state == I2S_STOP) || (i2sp->state == I2S_READY),
109  "invalid state");
110 
111  i2s_lld_stop(i2sp);
112  i2sp->config = NULL;
113  i2sp->state = I2S_STOP;
114 
115  osalSysUnlock();
116 }
117 
118 /**
119  * @brief Starts a I2S data exchange.
120  *
121  * @param[in] i2sp pointer to the @p I2SDriver object
122  *
123  * @api
124  */
126 
127  osalDbgCheck(i2sp != NULL);
128 
129  osalSysLock();
130  osalDbgAssert(i2sp->state == I2S_READY, "not ready");
131  i2sStartExchangeI(i2sp);
132  osalSysUnlock();
133 }
134 
135 /**
136  * @brief Stops the ongoing data exchange.
137  * @details The ongoing data exchange, if any, is stopped, if the driver
138  * was not active the function does nothing.
139  *
140  * @param[in] i2sp pointer to the @p I2SDriver object
141  *
142  * @api
143  */
145 
146  osalDbgCheck((i2sp != NULL));
147 
148  osalSysLock();
149  osalDbgAssert((i2sp->state == I2S_READY) ||
150  (i2sp->state == I2S_ACTIVE) ||
151  (i2sp->state == I2S_COMPLETE),
152  "invalid state");
153  i2sStopExchangeI(i2sp);
154  osalSysUnlock();
155 }
156 
157 #endif /* HAL_USE_I2S == TRUE */
158 
159 /** @} */
i2sStop
void i2sStop(I2SDriver *i2sp)
Deactivates the I2S peripheral.
Definition: hal_i2s.c:102
hal_i2s_driver::state
i2sstate_t state
Driver state.
Definition: hal_i2s.h:93
I2S_COMPLETE
@ I2S_COMPLETE
Definition: hal_i2s.h:62
I2S_READY
@ I2S_READY
Definition: hal_i2s.h:60
i2sStartExchange
void i2sStartExchange(I2SDriver *i2sp)
Starts a I2S data exchange.
Definition: hal_i2s.c:125
hal.h
HAL subsystem header.
I2S_STOP
@ I2S_STOP
Definition: hal_i2s.h:59
i2sObjectInit
void i2sObjectInit(I2SDriver *i2sp)
Initializes the standard part of a I2SDriver structure.
Definition: hal_i2s.c:68
osalSysUnlock
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition: osal.h:611
hal_i2s_driver
Structure representing an I2S driver.
Definition: hal_i2s.h:89
i2sStopExchangeI
#define i2sStopExchangeI(i2sp)
Stops the ongoing data exchange.
Definition: hal_i2s.h:172
hal_i2s_config
Driver configuration structure.
Definition: hal_i2s.h:105
i2sStart
void i2sStart(I2SDriver *i2sp, const I2SConfig *config)
Configures and activates the I2S peripheral.
Definition: hal_i2s.c:82
i2sStopExchange
void i2sStopExchange(I2SDriver *i2sp)
Stops the ongoing data exchange.
Definition: hal_i2s.c:144
osalDbgCheck
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:284
i2sStartExchangeI
#define i2sStartExchangeI(i2sp)
Starts a I2S data exchange.
Definition: hal_i2s.h:158
osalSysLock
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition: osal.h:601
osalDbgAssert
#define osalDbgAssert(c, remark)
Condition assertion.
Definition: osal.h:264
i2s_lld_start
void i2s_lld_start(I2SDriver *i2sp)
Configures and activates the I2S peripheral.
Definition: hal_i2s_lld.c:77
i2s_lld_init
void i2s_lld_init(void)
Low level I2S driver initialization.
Definition: hal_i2s_lld.c:63
hal_i2s_driver::config
const I2SConfig * config
Current configuration data.
Definition: hal_i2s.h:97
I2S_ACTIVE
@ I2S_ACTIVE
Definition: hal_i2s.h:61
i2sInit
void i2sInit(void)
I2S Driver initialization.
Definition: hal_i2s.c:56
i2s_lld_stop
void i2s_lld_stop(I2SDriver *i2sp)
Deactivates the I2S peripheral.
Definition: hal_i2s_lld.c:97