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

Function device_test

examples/test/device_test.c:471–510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469}
470
471int device_test(const char * device_name)
472{
473 rt_device_t device = RT_NULL;
474
475 // step 1:find device
476 device = rt_device_find(device_name);
477 if( device == RT_NULL)
478 {
479 rt_kprintf("device %s: not found!\r\n", device_name);
480 return -RT_ERROR;
481 }
482
483 // step 2:init device
484 if (!(device->flag & RT_DEVICE_FLAG_ACTIVATED))
485 {
486 rt_err_t result;
487 result = rt_device_init(device);
488 if (result != RT_EOK)
489 {
490 rt_kprintf("To initialize device:%s failed. The error code is %d\r\n",
491 device->parent.name, result);
492 return result;
493 }
494 else
495 {
496 device->flag |= RT_DEVICE_FLAG_ACTIVATED;
497 }
498 }
499
500 // step 3: device test
501 switch( device->type )
502 {
503 case RT_Device_Class_Block :
504 rt_kprintf("block device!\r\n");
505 return _block_device_test(device);
506 default:
507 rt_kprintf("unkown device type : %02X",device->type);
508 return -RT_ERROR;
509 }
510}
511
512#ifdef RT_USING_FINSH
513#include <finsh.h>

Callers 1

device_test.cFile · 0.85

Calls 4

rt_device_findFunction · 0.85
rt_kprintfFunction · 0.85
rt_device_initFunction · 0.85
_block_device_testFunction · 0.85

Tested by

no test coverage detected