• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (c) Huawei Technologies Co., Ltd. 2013-2018. All rights reserved.
3  * Description: Basic definitions
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  * 1. Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
9  * of conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  * --------------------------------------------------------------------------- */
26 
27 /**
28  * @defgroup kernel Kernel
29  * @defgroup los_base Basic definitions
30  * @ingroup kernel
31  */
32 
33 #ifndef _LOS_BASE_H
34 #define _LOS_BASE_H
35 
36 #include "los_printf.h"
37 #include "los_list.h"
38 #include "los_errno.h"
39 #ifdef __cplusplus
40 #if __cplusplus
41 extern "C" {
42 #endif /* __cplusplus */
43 #endif /* __cplusplus */
44 
45 #define SIZE(a) (a)
46 
47 #define LOS_ASSERT_COND(expression)
48 
49 /**
50  * @ingroup los_base
51  * Define the timeout interval as LOS_NO_WAIT.
52  */
53 #define LOS_NO_WAIT                      0
54 
55 /**
56  * @ingroup los_base
57  * Define the timeout interval as LOS_WAIT_FOREVER.
58  */
59 #define LOS_WAIT_FOREVER                 0xFFFFFFFF
60 
61 /**
62  * @ingroup los_base
63  * Align the beginning of the object with the base address addr,
64  * with boundary bytes being the smallest unit of alignment.
65  */
66 #ifndef ALIGN
67 #define ALIGN(addr, boundary)        LOS_Align(addr, boundary)
68 #endif
69 /**
70  * @ingroup los_base
71  * Align the tail of the object with the base address addr, with size bytes being the smallest unit of alignment.
72  */
73 #define TRUNCATE(addr, size)         ((addr) & ~((size)-1))
74 
75 /**
76  * @ingroup los_base
77  * Read a UINT8 value from addr and stroed in value.
78  */
79 #define READ_UINT8(value, addr)      ((value) = *((volatile UINT8 *)(addr)))
80 /**
81  * @ingroup los_base
82  * Read a UINT16 value from addr and stroed in addr.
83  */
84 #define READ_UINT16(value, addr)     ((value) = *((volatile UINT16 *)(addr)))
85 /**
86  * @ingroup los_base
87  * Read a UINT32 value from addr and stroed in value.
88  */
89 #define READ_UINT32(value, addr)     ((value) = *((volatile UINT32 *)(addr)))
90 /**
91  * @ingroup los_base
92  * Read a UINT64 value from addr and stroed in value.
93  */
94 #define READ_UINT64(value, addr)     ((value) = *((volatile UINT64 *)(addr)))
95 
96 /**
97  * @ingroup los_base
98  * Get a UINT8 value from addr.
99  */
100 #define GET_UINT8(addr)                (*((volatile UINT8 *)(addr)))
101 /**
102  * @ingroup los_base
103  * Get a UINT16 value from addr.
104  */
105 #define GET_UINT16(addr)               (*((volatile UINT16 *)(addr)))
106 /**
107  * @ingroup los_base
108  * Get a UINT32 value from addr.
109  */
110 #define GET_UINT32(addr)               (*((volatile UINT32 *)(addr)))
111 /**
112  * @ingroup los_base
113  * Get a UINT64 value from addr.
114  */
115 #define GET_UINT64(addr)               (*((volatile UINT64 *)(addr)))
116 
117 /**
118  * @ingroup los_base
119  * Write a UINT8 value to addr.
120  */
121 #define WRITE_UINT8(value, addr)     (*((volatile UINT8 *)(addr)) = (value))
122 /**
123  * @ingroup los_base
124  * Write a UINT16 value to addr.
125  */
126 #define WRITE_UINT16(value, addr)    (*((volatile UINT16 *)(addr)) = (value))
127 /**
128  * @ingroup los_base
129  * Write a UINT32 value to addr.
130  */
131 #define WRITE_UINT32(value, addr)    (*((volatile UINT32 *)(addr)) = (value))
132 /**
133  * @ingroup los_base
134  * Write a UINT64 addr to addr.
135  */
136 #define WRITE_UINT64(value, addr) (*((volatile UINT64 *)(addr)) = (value))
137 
138 #if PRINT_LEVEL < LOS_ERR_LEVEL
139 #define LOS_ASSERT(judge)
140 #else
141 #define LOS_ASSERT(judge)                                                          \
142     do {                                                                           \
143         if ((judge) == 0) {                                                        \
144             (VOID)LOS_IntLock();                                                   \
145             PRINT_ERR("ASSERT ERROR! %s, %d\n", __FUNCTION__, __LINE__);           \
146             while (1) { }                                                          \
147         }                                                                          \
148     } while (0)
149 #endif
150 
151 /**
152  * @ingroup los_base
153  * @brief Align the value (addr) by some bytes (boundary) you specify.
154  *
155  * @par Description:
156  * This API is used to align the value (addr) by some bytes (boundary) you specify.
157  *
158  * @attention
159  * <ul>
160  * <li>the value of boundary usually is 4,8,16,32.</li>
161  * </ul>
162  *
163  * @param addr     [IN]  The variable what you want to align.
164  * @param boundary [IN]  The align size what you want to align.
165  *
166  * @retval #UINT32 The variable what have been aligned.
167  * @par Dependency:
168  * <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
169  * @see
170  */
171 extern UINT32 LOS_Align(UINT32 addr, UINT32 boundary);
172 
173 /**
174  * @ingroup los_base
175  * @brief Sleep the current task.
176  *
177  * @par Description:
178  * This API is used to delay the execution of the current task. The task is able to be scheduled
179  * after it is delayed for a specified number of Ticks.
180  *
181  * @attention
182  * <ul>
183  * <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li>
184  * <li>If 0 is passed in and the task scheduling is not locked,
185  * execute the next task in the queue of tasks with the priority of the current task.
186  * If no ready task with the priority of the current task is available,
187  * the task scheduling will not occur, and the current task continues to be executed.</li>
188  * <li>The parameter passed in can not be equal to LOS_WAIT_FOREVER(0xFFFFFFFF).
189  * If that happens, the task will not sleep 0xFFFFFFFF milliseconds or sleep forever but sleep 0xFFFFFFFF Ticks.</li>
190  * </ul>
191  *
192  * @param mSecs [IN] Type #UINT32 Number of MS for which the task is delayed.
193  *
194  * @retval None
195  * @par Dependency:
196  * <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
197  * @see None
198  */
199 extern VOID LOS_Msleep(UINT32 mSecs);
200 
201 /**
202  * @ingroup los_base
203  * @brief System kernel initialization function.
204  *
205  * @par Description:
206  * This API is used to start liteOS .
207  *
208  * @attention
209  * <ul>
210  * <li>None.</li>
211  * </ul>
212  *
213  * @param: None.
214  *
215  * @retval #LOS_OK                                  0:LiteOS start success.
216  *
217  * @par Dependency:
218  * <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
219  * @see
220  */
221 extern UINT32 LOS_Start(VOID);
222 
223 /**
224  * @ingroup los_base
225  * @brief System kernel initialization function.
226  *
227  * @par Description:
228  * This API is used to Initialize kernel ,configure all system modules.
229  *
230  * @attention
231  * <ul>
232  * <li>None.</li>
233  * </ul>
234  *
235  * @param: None.
236  *
237  * @retval #LOS_OK                                  0:System kernel initialization success.
238  *
239  * @par Dependency:
240  * <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
241  * @see
242  */
243 extern UINT32 LOS_KernelInit(VOID);
244 
245 #ifdef __cplusplus
246 #if __cplusplus
247 }
248 #endif /* __cplusplus */
249 #endif /* __cplusplus */
250 
251 #endif /* _LOS_BASE_H */
252