MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_dm_device_find

Function rt_dm_device_find

components/drivers/core/dm.c:146–185  ·  view source on GitHub ↗

* @brief This function will return the specified master id and device id of device. * * @param master_id is the master id (0, 255] of device * * @param device_id is the device id [-1, 255] of device, when device_id is -1, * the function will end when find the first device. * * @return the device object or RT_NULL */

Source from the content-addressed store, hash-verified

144 * @return the device object or RT_NULL
145 */
146rt_device_t rt_dm_device_find(int master_id, int device_id)
147{
148 struct rt_device *dev, *ret_dev = RT_NULL;
149 struct rt_object_information *information = RT_NULL;
150
151 if (master_id <= 0 || device_id > 255)
152 {
153 return RT_NULL;
154 }
155
156 information = rt_object_get_information(RT_Object_Class_Device);
157
158 /* parameter check */
159 if (!information)
160 {
161 return RT_NULL;
162 }
163
164 /* which is invoke in interrupt status */
165 RT_DEBUG_NOT_IN_INTERRUPT;
166
167 /* enter critical */
168 rt_enter_critical();
169
170 /* try to find object */
171 rt_list_for_each_entry(dev, &information->object_list, parent.list)
172 {
173 if (master_id == dev->master_id &&
174 (device_id == -1 || device_id == dev->device_id))
175 {
176 ret_dev = dev;
177 break;
178 }
179 }
180
181 /* leave critical */
182 rt_exit_critical();
183
184 return ret_dev;
185}
186
187struct prefix_track
188{

Callers

nothing calls this directly

Calls 3

rt_enter_criticalFunction · 0.50
rt_exit_criticalFunction · 0.50

Tested by

no test coverage detected