ChibiOS/HAL  7.0.3
hal_sio.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_sio.c
19  * @brief SIO Driver code.
20  *
21  * @addtogroup SIO
22  * @{
23  */
24 
25 #include "hal.h"
26 
27 #if (HAL_USE_SIO == 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 SIO 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 sioInit(void) {
57 
58  sio_lld_init();
59 }
60 
61 /**
62  * @brief Initializes the standard part of a @p SIODriver structure.
63  *
64  * @param[out] siop pointer to the @p SIODriver object
65  *
66  * @init
67  */
68 void sioObjectInit(SIODriver *siop) {
69 
70  siop->state = SIO_STOP;
71  siop->config = NULL;
72 
73  /* Optional, user-defined initializer.*/
74 #if defined(SIO_DRIVER_EXT_INIT_HOOK)
75  SIO_DRIVER_EXT_INIT_HOOK(siop);
76 #endif
77 }
78 
79 /**
80  * @brief Configures and activates the SIO peripheral.
81  *
82  * @param[in] siop pointer to the @p SIODriver object
83  * @param[in] config pointer to the @p SIOConfig object
84  *
85  * @api
86  */
87 void sioStart(SIODriver *siop, const SIOConfig *config) {
88 
89  osalDbgCheck((siop != NULL) && (config != NULL));
90 
91  osalSysLock();
92  osalDbgAssert((siop->state == SIO_STOP) || (siop->state == SIO_READY),
93  "invalid state");
94 
95  siop->config = config;
96  sio_lld_start(siop);
97  siop->state = SIO_READY;
98  osalSysUnlock();
99 }
100 
101 /**
102  * @brief Deactivates the SIO peripheral.
103  *
104  * @param[in] siop pointer to the @p SIODriver object
105  *
106  * @api
107  */
108 void sioStop(SIODriver *siop) {
109 
110  osalDbgCheck(siop != NULL);
111 
112  osalSysLock();
113 
114  osalDbgAssert((siop->state == SIO_STOP) || (siop->state == SIO_READY),
115  "invalid state");
116 
117  sio_lld_stop(siop);
118  siop->config = NULL;
119  siop->state = SIO_STOP;
120 
121  osalSysUnlock();
122 }
123 
124 #endif /* HAL_USE_SIO == TRUE */
125 
126 /** @} */
void sio_lld_init(void)
Low level SIO driver initialization.
Definition: hal_sio_lld.c:65
void sioObjectInit(SIODriver *siop)
Initializes the standard part of a SIODriver structure.
Definition: hal_sio.c:68
Structure representing a SIO driver.
Definition: hal_sio_lld.h:115
HAL subsystem header.
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition: osal.h:540
const SIOConfig * config
Current configuration data.
Definition: hal_sio_lld.h:123
void sioInit(void)
SIO Driver initialization.
Definition: hal_sio.c:56
siostate_t state
Driver state.
Definition: hal_sio_lld.h:119
void sio_lld_stop(SIODriver *siop)
Deactivates the SIO peripheral.
Definition: hal_sio_lld.c:101
void sio_lld_start(SIODriver *siop)
Configures and activates the SIO peripheral.
Definition: hal_sio_lld.c:80
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:278
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition: osal.h:530
void sioStop(SIODriver *siop)
Deactivates the SIO peripheral.
Definition: hal_sio.c:108
#define osalDbgAssert(c, remark)
Condition assertion.
Definition: osal.h:258
Driver configuration structure.
Definition: hal_sio_lld.h:86
void sioStart(SIODriver *siop, const SIOConfig *config)
Configures and activates the SIO peripheral.
Definition: hal_sio.c:87