ChibiOS/HAL 9.0.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 */
56void i2sInit(void) {
57
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 */
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 * @return The operation status.
80 *
81 * @api
82 */
83msg_t i2sStart(I2SDriver *i2sp, const I2SConfig *config) {
84 msg_t msg;
85
86 osalDbgCheck((i2sp != NULL) && (config != NULL));
87
89 osalDbgAssert((i2sp->state == I2S_STOP) || (i2sp->state == I2S_READY),
90 "invalid state");
91
92 i2sp->config = config;
93
94#if defined(I2S_LLD_ENHANCED_API)
95 msg = i2s_lld_start(i2sp);
96 if (msg == HAL_RET_SUCCESS) {
97 i2sp->state = I2S_READY;
98 }
99 else {
100 i2sp->state = I2S_STOP;
101 }
102#else
103 i2s_lld_start(i2sp);
104 i2sp->state = I2S_READY;
105 msg = HAL_RET_SUCCESS;
106#endif
107
109
110 return msg;
111}
112
113/**
114 * @brief Deactivates the I2S peripheral.
115 *
116 * @param[in] i2sp pointer to the @p I2SDriver object
117 *
118 * @api
119 */
120void i2sStop(I2SDriver *i2sp) {
121
122 osalDbgCheck(i2sp != NULL);
123
124 osalSysLock();
125
126 osalDbgAssert((i2sp->state == I2S_STOP) || (i2sp->state == I2S_READY),
127 "invalid state");
128
129 i2s_lld_stop(i2sp);
130 i2sp->config = NULL;
131 i2sp->state = I2S_STOP;
132
134}
135
136/**
137 * @brief Starts a I2S data exchange.
138 *
139 * @param[in] i2sp pointer to the @p I2SDriver object
140 *
141 * @api
142 */
144
145 osalDbgCheck(i2sp != NULL);
146
147 osalSysLock();
148 osalDbgAssert(i2sp->state == I2S_READY, "not ready");
149 i2sStartExchangeI(i2sp);
151}
152
153/**
154 * @brief Stops the ongoing data exchange.
155 * @details The ongoing data exchange, if any, is stopped, if the driver
156 * was not active the function does nothing.
157 *
158 * @param[in] i2sp pointer to the @p I2SDriver object
159 *
160 * @api
161 */
163
164 osalDbgCheck((i2sp != NULL));
165
166 osalSysLock();
167 osalDbgAssert((i2sp->state == I2S_READY) ||
168 (i2sp->state == I2S_ACTIVE) ||
169 (i2sp->state == I2S_COMPLETE),
170 "invalid state");
171 i2sStopExchangeI(i2sp);
173}
174
175#endif /* HAL_USE_I2S == TRUE */
176
177/** @} */
#define HAL_RET_SUCCESS
Definition hal.h:93
#define i2sStopExchangeI(i2sp)
Stops the ongoing data exchange.
Definition hal_i2s.h:172
void i2sInit(void)
I2S Driver initialization.
Definition hal_i2s.c:56
void i2s_lld_stop(I2SDriver *i2sp)
Deactivates the I2S peripheral.
Definition hal_i2s_lld.c:97
struct hal_i2s_config I2SConfig
Type of a structure representing an I2S driver configuration.
Definition hal_i2s.h:73
void i2s_lld_init(void)
Low level I2S driver initialization.
Definition hal_i2s_lld.c:63
void i2sStopExchange(I2SDriver *i2sp)
Stops the ongoing data exchange.
Definition hal_i2s.c:162
#define i2sStartExchangeI(i2sp)
Starts a I2S data exchange.
Definition hal_i2s.h:158
void i2sObjectInit(I2SDriver *i2sp)
Initializes the standard part of a I2SDriver structure.
Definition hal_i2s.c:68
void i2sStartExchange(I2SDriver *i2sp)
Starts a I2S data exchange.
Definition hal_i2s.c:143
struct hal_i2s_driver I2SDriver
Type of a structure representing an I2S driver.
Definition hal_i2s.h:68
msg_t i2sStart(I2SDriver *i2sp, const I2SConfig *config)
Configures and activates the I2S peripheral.
Definition hal_i2s.c:83
void i2s_lld_start(I2SDriver *i2sp)
Configures and activates the I2S peripheral.
Definition hal_i2s_lld.c:77
void i2sStop(I2SDriver *i2sp)
Deactivates the I2S peripheral.
Definition hal_i2s.c:120
@ I2S_STOP
Definition hal_i2s.h:59
@ I2S_ACTIVE
Definition hal_i2s.h:61
@ I2S_READY
Definition hal_i2s.h:60
@ I2S_COMPLETE
Definition hal_i2s.h:62
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition osal.h:601
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition osal.h:611
int32_t msg_t
Type of a message.
Definition osal.h:159
#define osalDbgAssert(c, remark)
Condition assertion.
Definition osal.h:264
#define osalDbgCheck(c)
Function parameters check.
Definition osal.h:284
HAL subsystem header.
i2sstate_t state
Driver state.
Definition hal_i2s.h:93
const I2SConfig * config
Current configuration data.
Definition hal_i2s.h:97