• R/O
  • SSH
  • HTTPS

chibios: コミット


コミットメタ情報

リビジョン15939 (tree)
日時2023-01-01 22:28:18
作者gdisirio

ログメッセージ

(メッセージはありません)

変更サマリ

差分

--- branches/hal9_dev/os/common/utils/include/oop_base_object.h (revision 15938)
+++ branches/hal9_dev/os/common/utils/include/oop_base_object.h (revision 15939)
@@ -1,5 +1,5 @@
11 /*
2- ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio
2+ ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio
33
44 Licensed under the Apache License, Version 2.0 (the "License");
55 you may not use this file except in compliance with the License.
--- branches/hal9_dev/os/common/utils/include/oop_referenced_object.h (revision 15938)
+++ branches/hal9_dev/os/common/utils/include/oop_referenced_object.h (revision 15939)
@@ -1,5 +1,5 @@
11 /*
2- ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio
2+ ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio
33
44 Licensed under the Apache License, Version 2.0 (the "License");
55 you may not use this file except in compliance with the License.
@@ -33,6 +33,11 @@
3333 #include "oop_base_object.h"
3434
3535 /**
36+ * @brief Type of a references counter.
37+ */
38+typedef unsigned int oop_object_references_t;
39+
40+/**
3641 * @brief Type of a referenced object class.
3742 */
3843 typedef struct referenced_object referenced_object_c;
@@ -50,7 +55,7 @@
5055 */
5156 #define __referenced_object_data \
5257 __base_object_data \
53- unsigned references;
58+ oop_object_references_t references;
5459
5560
5661 /**
@@ -88,7 +93,7 @@
8893 referenced_object_c *objp = (referenced_object_c *)ip;
8994
9095 __base_object_objinit_impl(ip, vmt);
91- objp->references = 1U;
96+ objp->references = (oop_object_references_t)1;
9297
9398 return ip;
9499 }
@@ -101,9 +106,11 @@
101106 */
102107 CC_FORCE_INLINE
103108 static inline void __referenced_object_dispose_impl(void *ip) {
109+ referenced_object_c *objp = (referenced_object_c *)ip;
104110
105- /* TODO assertion */
106- __base_object_dispose_impl(ip);
111+ osalDbgAssert(objp->references == (oop_object_references_t)0, "not zero");
112+
113+ __base_object_dispose_impl(objp);
107114 }
108115
109116 /**
@@ -118,6 +125,8 @@
118125
119126 objp->references++;
120127
128+ osalDbgAssert(objp->references != (oop_object_references_t)0, "overflow");
129+
121130 return ip;
122131 }
123132
@@ -128,7 +137,7 @@
128137 * @return Remaining references.
129138 */
130139 CC_FORCE_INLINE
131-static inline unsigned __referenced_object_getref_impl(void *ip) {
140+static inline oop_object_references_t __referenced_object_getref_impl(void *ip) {
132141 referenced_object_c *objp = (referenced_object_c *)ip;
133142
134143 return objp->references;
@@ -141,7 +150,7 @@
141150 * @return The number of references left.
142151 */
143152 CC_FORCE_INLINE
144-static inline unsigned __referenced_object_release_impl(void *ip) {
153+static inline oop_object_references_t __referenced_object_release_impl(void *ip) {
145154 referenced_object_c *objp = (referenced_object_c *)ip;
146155
147156 osalDbgAssert(objp->references > 0U, "zero references");
@@ -174,7 +183,7 @@
174183 * @return The number of references left.
175184 */
176185 CC_FORCE_INLINE
177-static inline unsigned roRelease(void *ip) {
186+static inline oop_object_references_t roRelease(void *ip) {
178187 referenced_object_c *objp = (referenced_object_c *)ip;
179188
180189 return objp->vmt->release(ip);
--- branches/hal9_dev/os/common/utils/include/oop_synchronized_object.h (revision 15938)
+++ branches/hal9_dev/os/common/utils/include/oop_synchronized_object.h (revision 15939)
@@ -1,5 +1,5 @@
11 /*
2- ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio
2+ ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio
33
44 Licensed under the Apache License, Version 2.0 (the "License");
55 you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@
2929 #ifndef OOP_SYNCHRONIZED_OBJECT_H
3030 #define OOP_SYNCHRONIZED_OBJECT_H
3131
32-#include "ch.h"
32+#include "osal.h"
3333 #include "oop_referenced_object.h"
3434
3535 /**
@@ -86,7 +86,7 @@
8686 synchronized_object_c *objp = (synchronized_object_c *)ip;
8787
8888 __referenced_object_objinit_impl(ip, vmt);
89- chMtxObjectInit(&objp->mutex);
89+ osalMutexObjectInit(&objp->mutex);
9090
9191 return ip;
9292 }
@@ -114,7 +114,7 @@
114114 static inline void soLock(void *ip) {
115115 synchronized_object_c *objp = (synchronized_object_c *)ip;
116116
117- chMtxLock(&objp->mutex);
117+ osalMutexLock(&objp->mutex);
118118 }
119119
120120 /**
@@ -126,7 +126,7 @@
126126 static inline void soUnlock(void *ip) {
127127 synchronized_object_c *objp = (synchronized_object_c *)ip;
128128
129- chMtxUnlock(&objp->mutex);
129+ osalMutexUnlock(&objp->mutex);
130130 }
131131
132132 #endif /* OOP_SYNCHRONIZED_OBJECT_H */
--- branches/hal9_dev/os/hal/include/hal_base_driver.h (revision 15938)
+++ branches/hal9_dev/os/hal/include/hal_base_driver.h (revision 15939)
@@ -1,5 +1,5 @@
11 /*
2- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
2+ ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio
33
44 Licensed under the Apache License, Version 2.0 (the "License");
55 you may not use this file except in compliance with the License.
@@ -37,14 +37,54 @@
3737 /* Driver constants. */
3838 /*===========================================================================*/
3939
40+/**
41+ * @name Common driver states
42+ * @{
43+ */
44+#define HAL_DRV_STATE_UNINIT 0U
45+#define HAL_DRV_STATE_STOPPED 1U
46+#define HAL_DRV_STATE_READY 2U
47+#define HAL_DRV_STATE_ACTIVE 3U
48+#define HAL_DRV_STATE_ERROR 4U
49+/** @} */
50+
4051 /*===========================================================================*/
4152 /* Driver pre-compile time settings. */
4253 /*===========================================================================*/
4354
55+/**
56+ * @name Common driver configuration options
57+ * @{
58+ */
59+/**
60+ * @brief Enables the mutual exclusion APIs on driver instances.
61+ * @note Disabling this option saves both code and data space.
62+ */
63+#if !defined(HAL_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
64+#define HAL_USE_MUTUAL_EXCLUSION TRUE
65+#endif
66+
67+/**
68+ * @brief Enables the HAL registry for drivers.
69+ * @note Disabling this option saves both code and data space.
70+ */
71+#if !defined(HAL_USE_REGISTRY) || defined(__DOXYGEN__)
72+#define HAL_USE_REGISTRY TRUE
73+#endif
74+/** @} */
75+
4476 /*===========================================================================*/
4577 /* Derived constants and error checks. */
4678 /*===========================================================================*/
4779
80+#if (HAL_USE_MUTUAL_EXCLUSION != TRUE) && (HAL_USE_MUTUAL_EXCLUSION != FALSE)
81+#error "invalid HAL_USE_MUTUAL_EXCLUSION value"
82+#endif
83+
84+#if (HAL_USE_REGISTRY != TRUE) && (HAL_USE_REGISTRY != FALSE)
85+#error "invalid HAL_USE_REGISTRY value"
86+#endif
87+
4888 /*===========================================================================*/
4989 /* Driver data structures and types. */
5090 /*===========================================================================*/
@@ -63,19 +103,27 @@
63103 * @brief @p base_driver_c specific methods.
64104 */
65105 #define __base_driver_methods \
66- __referenced_object_methods \
67- void (*stop)(void *ip); \
68- void (*lock)(void *ip); \
69- void (*unlock)(void *ip);
106+ __referenced_object_methods
70107
108+#if (HAL_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
71109 /**
72110 * @brief @p base_driver_c specific data.
73111 */
74112 #define __base_driver_data \
75113 __referenced_object_data \
114+ /* Driver state.*/ \
76115 hal_driver_state_t state; \
116+ /* Driver owner or NULL.*/ \
117+ void *owner; \
118+ /* Mutual exclusion object.*/ \
77119 mutex_t mutex;
78120
121+#else /* HAL_USE_MUTUAL_EXCLUSION != TRUE */
122+#define __base_driver_data \
123+ __referenced_object_data \
124+ hal_driver_state_t state; \
125+ void *owner;
126+#endif /* HAL_USE_MUTUAL_EXCLUSION != TRUE */
79127
80128 /**
81129 * @brief @p base_driver_c virtual methods table.
@@ -132,6 +180,7 @@
132180 base_driver_c *objp = (base_driver_c *)ip;
133181
134182 __referenced_object_objinit_impl(objp, vmt);
183+ objp->owner = NULL;
135184 osalMutexObjectInit(&objp->mutex);
136185
137186 return ip;
@@ -153,9 +202,76 @@
153202 /** @} */
154203
155204 /**
156- * @brief Object lock.
205+ * @brief Driver close.
206+ * @details Releases a reference to the driver, when the count reaches zero
207+ * then the driver is physically uninitialized.
157208 *
158- * @param[in] ip Pointer to a @p synchronized_object_c structure to be
209+ * @param[in] ip Pointer to a @p base_driver_c structure.
210+ * @return The number of references left.
211+ */
212+CC_FORCE_INLINE
213+static inline oop_object_references_t drvClose(void *ip) {
214+ base_driver_c *objp = (base_driver_c *)ip;
215+
216+ return roRelease(objp);
217+}
218+
219+/**
220+ * @brief Driver state get.
221+ *
222+ * @param[in] ip Pointer to a @p base_driver_c structure.
223+ * @return The driver state.
224+ */
225+CC_FORCE_INLINE
226+static inline hal_driver_state_t drvGetStateX(void *ip) {
227+ base_driver_c *objp = (base_driver_c *)ip;
228+
229+ return objp->state;
230+}
231+
232+/**
233+ * @brief Driver state set.
234+ *
235+ * @param[in] ip Pointer to a @p base_driver_c structure.
236+ * @param[in] state New driver state.
237+ */
238+CC_FORCE_INLINE
239+static inline void drvSetStateX(void *ip, hal_driver_state_t state) {
240+
241+ ((base_driver_c *)ip)->state = state;
242+}
243+
244+/**
245+ * @brief Driver owner get.
246+ *
247+ * @param[in] ip Pointer to a @p base_driver_c structure.
248+ * @return The driver owner.
249+ */
250+CC_FORCE_INLINE
251+static inline void *drvGetOwnerX(void *ip) {
252+ base_driver_c *objp = (base_driver_c *)ip;
253+
254+ return objp->owner;
255+}
256+
257+/**
258+ * @brief Driver owner set.
259+ *
260+ * @param[in] ip Pointer to a @p base_driver_c structure.
261+ * @param[in] owner New driver owner.
262+ */
263+CC_FORCE_INLINE
264+static inline void drvSetOwnerX(void *ip, void *owner) {
265+ base_driver_c *objp = (base_driver_c *)ip;
266+
267+ objp->owner = owner;
268+}
269+
270+#if (HAL_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
271+/**
272+ * @brief Driver lock.
273+ *
274+ * @param[in] ip Pointer to a @p base_driver_c structure to be
159275 * locked.
160276 */
161277 CC_FORCE_INLINE
@@ -166,9 +282,9 @@
166282 }
167283
168284 /**
169- * @brief Object unlock.
285+ * @brief Driver unlock.
170286 *
171- * @param[in] ip Pointer to a @p synchronized_object_c structure to be
287+ * @param[in] ip Pointer to a @p base_driver_c structure to be
172288 * unlocked.
173289 */
174290 CC_FORCE_INLINE
@@ -177,6 +293,7 @@
177293
178294 osalMutexUnlock(&objp->mutex);
179295 }
296+#endif /* HAL_USE_MUTUAL_EXCLUSION == TRUE */
180297
181298 #endif /* HAL_BASE_DRIVER */
182299
旧リポジトリブラウザで表示