* @brief This function will initialize the specified device. * * @param dev is the pointer of device driver structure. * * @return the result, RT_EOK on successfully. */
| 184 | * @return the result, RT_EOK on successfully. |
| 185 | */ |
| 186 | rt_err_t rt_device_init(rt_device_t dev) |
| 187 | { |
| 188 | rt_err_t result = RT_EOK; |
| 189 | |
| 190 | RT_ASSERT(dev != RT_NULL); |
| 191 | |
| 192 | /* get device_init handler */ |
| 193 | if (device_init != RT_NULL) |
| 194 | { |
| 195 | if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) |
| 196 | { |
| 197 | result = device_init(dev); |
| 198 | if (result != RT_EOK) |
| 199 | { |
| 200 | LOG_E("To initialize device:%.*s failed. The error code is %d", |
| 201 | RT_NAME_MAX, dev->parent.name, result); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | dev->flag |= RT_DEVICE_FLAG_ACTIVATED; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | return result; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @brief This function will open a device. |
no outgoing calls