RT-Thread RTOS  1.0.0
An open source embedded real-time operating system
Device System

Data Structures

struct  rt_device
struct  rt_device_blk_geometry
struct  rt_device_graphic_info
struct  rt_device_rect_info
struct  rt_device_graphic_ops

Defines

#define RT_DEVICE_FLAG_DEACTIVATE   0x000
#define RT_DEVICE_FLAG_RDONLY   0x001
#define RT_DEVICE_FLAG_WRONLY   0x002
#define RT_DEVICE_FLAG_RDWR   0x003
#define RT_DEVICE_FLAG_REMOVABLE   0x004
#define RT_DEVICE_FLAG_STANDALONE   0x008
#define RT_DEVICE_FLAG_ACTIVATED   0x010
#define RT_DEVICE_FLAG_SUSPENDED   0x020
#define RT_DEVICE_FLAG_STREAM   0x040
#define RT_DEVICE_FLAG_INT_RX   0x100
#define RT_DEVICE_FLAG_DMA_RX   0x200
#define RT_DEVICE_FLAG_INT_TX   0x400
#define RT_DEVICE_FLAG_DMA_TX   0x800
#define RT_DEVICE_OFLAG_CLOSE   0x000
#define RT_DEVICE_OFLAG_RDONLY   0x001
#define RT_DEVICE_OFLAG_WRONLY   0x002
#define RT_DEVICE_OFLAG_RDWR   0x003
#define RT_DEVICE_OFLAG_OPEN   0x008
#define RT_DEVICE_CTRL_RESUME   0x01
#define RT_DEVICE_CTRL_SUSPEND   0x02
#define RT_DEVICE_CTRL_CHAR_STREAM   0x10
#define RT_DEVICE_CTRL_BLK_GETGEOME   0x10
#define RT_DEVICE_CTRL_NETIF_GETMAC   0x10
#define RT_DEVICE_CTRL_MTD_FORMAT   0x10
#define RT_DEVICE_CTRL_RTC_GET_TIME   0x10
#define RT_DEVICE_CTRL_RTC_SET_TIME   0x11
#define RTGRAPHIC_CTRL_RECT_UPDATE   0
#define RTGRAPHIC_PIXEL_POSITION(x, y)   ((x << 16) | y)

Enumerations

enum  rt_device_class_type {
  RT_Device_Class_Char = 0, RT_Device_Class_Block, RT_Device_Class_NetIf, RT_Device_Class_MTD,
  RT_Device_Class_CAN, RT_Device_Class_RTC, RT_Device_Class_Sound, RT_Device_Class_Graphic,
  RT_Device_Class_I2C, RT_Device_Class_USBDevice, RT_Device_Class_USBHost, RT_Device_Class_SPIBUS,
  RT_Device_Class_SPIDevice, RT_Device_Class_SDIO, RT_Device_Class_Unknown
}

Functions

rt_device_t rt_device_find (const char *name)
rt_err_t rt_device_register (rt_device_t dev, const char *name, rt_uint16_t flags)
rt_err_t rt_device_unregister (rt_device_t dev)
rt_err_t rt_device_init_all (void)
rt_err_t rt_device_set_rx_indicate (rt_device_t dev, rt_err_t(*rx_ind)(rt_device_t dev, rt_size_t size))
rt_err_t rt_device_set_tx_complete (rt_device_t dev, rt_err_t(*tx_done)(rt_device_t dev, void *buffer))
rt_err_t rt_device_init (rt_device_t dev)
rt_err_t rt_device_open (rt_device_t dev, rt_uint16_t oflag)
rt_err_t rt_device_close (rt_device_t dev)
rt_size_t rt_device_read (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
rt_size_t rt_device_write (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
rt_err_t rt_device_control (rt_device_t dev, rt_uint8_t cmd, void *arg)

Detailed Description

The Device System is designed as simple and minimum layer to help communication between applications and drivers.

The Device System provide five interfaces to driver:


Define Documentation

#define RT_DEVICE_FLAG_DEACTIVATE   0x000

device flags defitions device is not not initialized

#define RT_DEVICE_FLAG_RDONLY   0x001

read only

#define RT_DEVICE_FLAG_WRONLY   0x002

write only

#define RT_DEVICE_FLAG_RDWR   0x003

read and write

#define RT_DEVICE_FLAG_REMOVABLE   0x004

removable device

#define RT_DEVICE_FLAG_STANDALONE   0x008

standalone device

#define RT_DEVICE_FLAG_ACTIVATED   0x010

device is activated

#define RT_DEVICE_FLAG_SUSPENDED   0x020

device is suspended

#define RT_DEVICE_FLAG_STREAM   0x040

stream mode

#define RT_DEVICE_FLAG_INT_RX   0x100

INT mode on Rx

#define RT_DEVICE_FLAG_DMA_RX   0x200

DMA mode on Rx

#define RT_DEVICE_FLAG_INT_TX   0x400

INT mode on Tx

#define RT_DEVICE_FLAG_DMA_TX   0x800

DMA mode on Tx

#define RT_DEVICE_OFLAG_CLOSE   0x000

device is closed

#define RT_DEVICE_OFLAG_RDONLY   0x001

read only access

#define RT_DEVICE_OFLAG_WRONLY   0x002

write only access

#define RT_DEVICE_OFLAG_RDWR   0x003

read and write

#define RT_DEVICE_OFLAG_OPEN   0x008

device is opened

#define RT_DEVICE_CTRL_RESUME   0x01

general device commands resume device

#define RT_DEVICE_CTRL_SUSPEND   0x02

suspend device

#define RT_DEVICE_CTRL_CHAR_STREAM   0x10

special device commands stream mode on char device

#define RT_DEVICE_CTRL_BLK_GETGEOME   0x10

get geometry information

#define RT_DEVICE_CTRL_NETIF_GETMAC   0x10

get mac address

#define RT_DEVICE_CTRL_MTD_FORMAT   0x10

format a MTD device

#define RT_DEVICE_CTRL_RTC_GET_TIME   0x10

get time

#define RT_DEVICE_CTRL_RTC_SET_TIME   0x11

set time

graphic device control command

#define RTGRAPHIC_PIXEL_POSITION (   x,
 
)    ((x << 16) | y)

build a pixel position according to (x, y) coordinates.


Enumeration Type Documentation

device (I/O) class type

Enumerator:
RT_Device_Class_Char 

character device

RT_Device_Class_Block 

block device

RT_Device_Class_NetIf 

net interface

RT_Device_Class_MTD 

memory device

RT_Device_Class_CAN 

CAN device

RT_Device_Class_RTC 

RTC device

RT_Device_Class_Sound 

Sound device

RT_Device_Class_Graphic 

Graphic device

RT_Device_Class_I2C 

I2C device

RT_Device_Class_USBDevice 

USB slave device

RT_Device_Class_USBHost 

USB host bus

RT_Device_Class_SPIBUS 

SPI bus device

RT_Device_Class_SPIDevice 

SPI device

RT_Device_Class_SDIO 

SDIO bus device

RT_Device_Class_Unknown 

unknown device


Function Documentation

rt_device_t rt_device_find ( const char *  name)

This function finds a device driver by specified name.

Parameters:
namethe device driver's name
Returns:
the registered device driver on successful, or RT_NULL on failure.
rt_err_t rt_device_register ( rt_device_t  dev,
const char *  name,
rt_uint16_t  flags 
)

This function registers a device driver with specified name.

Parameters:
devthe pointer of device driver structure
namethe device driver's name
flagsthe flag of device
Returns:
the error code, RT_EOK on initialization successfully.

This function removes a previously registered device driver

Parameters:
devthe pointer of device driver structure
Returns:
the error code, RT_EOK on successfully.

This function initializes all registered device driver

Returns:
the error code, RT_EOK on successfully.

This function will set the indication callback function when device receives data.

Parameters:
devthe pointer of device driver structure
rx_indthe indication callback function
Returns:
RT_EOK
rt_err_t rt_device_set_tx_complete ( rt_device_t  dev,
rt_err_t(*)(rt_device_t dev, void *buffer)  tx_done 
)

This function will set the indication callback function when device has written data to physical hardware.

Parameters:
devthe pointer of device driver structure
tx_donethe indication callback function
Returns:
RT_EOK

This function will initialize the specified device

Parameters:
devthe pointer of device driver structure
Returns:
the result

This function will open a device

Parameters:
devthe pointer of device driver structure
oflagthe flags for device open
Returns:
the result

This function will close a device

Parameters:
devthe pointer of device driver structure
Returns:
the result
rt_size_t rt_device_read ( rt_device_t  dev,
rt_off_t  pos,
void *  buffer,
rt_size_t  size 
)

This function will read some data from a device.

Parameters:
devthe pointer of device driver structure
posthe position of reading
bufferthe data buffer to save read data
sizethe size of buffer
Returns:
the actually read size on successful, otherwise negative returned.
Note:
since 0.4.0, the unit of size/pos is a block for block device.
rt_size_t rt_device_write ( rt_device_t  dev,
rt_off_t  pos,
const void *  buffer,
rt_size_t  size 
)

This function will write some data to a device.

Parameters:
devthe pointer of device driver structure
posthe position of written
bufferthe data buffer to be written to device
sizethe size of buffer
Returns:
the actually written size on successful, otherwise negative returned.
Note:
since 0.4.0, the unit of size/pos is a block for block device.
rt_err_t rt_device_control ( rt_device_t  dev,
rt_uint8_t  cmd,
void *  arg 
)

This function will perform a variety of control functions on devices.

Parameters:
devthe pointer of device driver structure
cmdthe command sent to device
argthe argument of command
Returns:
the result
 All Data Structures Variables