之前写的乱七八糟一大堆1
作者:互联网
关于调试
利用rt_kprintf()输出有疑问的变量或其他,但是注意, 修改是做下标记 !!
例如:
rt_kprintf("EventGet-eEvent: %x \r\n", eEvent); //... 或 //srb11-24
标记统一,便于后期删改,全局搜索 “//...” 即可!!!
关于命名规则
无论是变量、文件还是函数,都适用。
可跟随编程环境/系统。
例如,使用RT_Thread框架编程,命名均是小写加下划线,
1、大小驼峰
//eg:
struct SmiDevice
{
};
//eg:
uint8_t PidControl = 1;
2、小写加下划线
//eg:
drv_pwm.c
drv_soft_i2c.c
i2c_core.c
i2c_dev.c
//eg: 以下为i2c类的封装
/***************************************************************************************/
stm32_i2c -> rt_i2c_bus_device -> rt_device
-> rt_object(name,type,flag) [rt_list_t list; /**< list node of kernel object */]
/***************************************************************************************/
/* stm32 i2c dirver class */
struct stm32_i2c
{
struct rt_i2c_bit_ops ops;
struct rt_i2c_bus_device i2c2_bus;
};
struct rt_i2c_bit_ops
{
void *data; /* private data for lowlevel routines */
void (*set_sda)(void *data, rt_int32_t state);
void (*set_scl)(void *data, rt_int32_t state);
rt_int32_t (*get_sda)(void *data);
rt_int32_t (*get_scl)(void *data);
void (*udelay)(rt_uint32_t us);
rt_uint32_t delay_us; /* scl and sda line delay */
rt_uint32_t timeout; /* in tick */
};
/*for i2c bus driver*/
struct rt_i2c_bus_device
{
struct rt_device parent;
const struct rt_i2c_bus_device_ops *ops;
rt_uint16_t flags;
rt_uint16_t addr;
struct rt_mutex lock;
rt_uint32_t timeout;
rt_uint32_t retries;
void *priv;
};
/**
* Device structure
*/
struct rt_device
{
struct rt_object parent; /**< inherit from rt_object */
enum rt_device_class_type type; /**< device type */
rt_uint16_t flag; /**< device flag */
rt_uint16_t open_flag; /**< device open flag */
rt_uint8_t ref_count; /**< reference count */
rt_uint8_t device_id; /**< 0 - 255 */
/* device call back */
rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
#ifdef RT_USING_DEVICE_OPS
const struct rt_device_ops *ops;
#else
/* common device interface */
rt_err_t (*init) (rt_device_t dev);
rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
rt_err_t (*close) (rt_device_t dev);
rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
#endif
#if defined(RT_USING_POSIX)
const struct dfs_file_ops *fops;
struct rt_wqueue wait_queue;
#endif
void *user_data; /**< device private data */
};
struct rt_object
{
char name[RT_NAME_MAX]; /**< name of kernel object */
rt_uint8_t type; /**< type of kernel object */
rt_uint8_t flag; /**< flag of kernel object */
#ifdef RT_USING_MODULE
void *module_id; /**< id of application module */
#endif
rt_list_t list; /**< list node of kernel object */
};
typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */
关于 Tab & 空格
针对不同的IED,一个Tab键所包含的字符数是不统一的!
但空格定义是一致的,即一个空格一个字符,
所以,在编程中切记使用空格来进行换行或缩进,保持程序的可读性、完整性;
一般,认为4个空格为一个Tab。
关于RT-ThreadStudio
新建工程后,需要修改一些配置。
1)cubemux 配置
2)keil 中改路径
3)menuconfig 开启 using system default workqueue
RT-Thread Configuration -> RT-Thread Component ->Device Drivers -> 使能
STM32编译时出现类似于:
..\OBJ\KEY.axf: Error: L6218E: Undefined symbol IWDG_WriteAccessCmd (referred from wdg.o).错误原因:
没有将相应的库函数包含进去!!!!!
方法:Project--右键--Manage Project Items--在Groups选择对应文件夹--Files中添加需要的库文件
标签:rt,struct,乱七八糟,object,之前,一大堆,device,i2c,void 来源: https://www.cnblogs.com/programming-debug/p/15959654.html