usmart中_m_usmart_dev的理解

 

 

 

首先声明了一个如下类型的结构体类型_m_usmart_dev

  1. struct     _m_usmart_dev
  2. {
  3.     struct _m_usmart_nametab *funs;    //函数名指针
  4.     void (*init)(u8);                //初始化
  5.     u8 (*cmd_rec)(u8*str);            //识别函数名及参数
  6.     void (*exe)(void);                 //执行 
  7.     void (*scan)(void);             //扫描
  8.     u8 fnum;                           //函数数量
  9.     u8 pnum;                        //参数数量
  10.     u8 id;                            //函数id
  11.     u8 sptype;                        //参数显示类型(非字符串参数):0,10进制;1,16进制;
  12.     u16 parmtype;                    //参数的类型
  13.     u8  plentbl[MAX_PARM];          //每个参数的长度暂存表
  14.     u8  parm[PARM_LEN];              //函数的参数
  15.     u8 runtimeflag;                    //0,不统计函数执行时间;1,统计函数执行时间,注意:此功能必须在USMART_ENTIMX_SCAN使能的时候,才有用
  16.     u32 runtime;                    //运行时间,单位:0.1ms,最大延时时间为定时器CNT值的2倍*0.1ms
  17. };

定义了类型为_m_usmart_dev的结构体usmart_dev并将其初始化。即usmart_dev.fun=usmart_nametab //该成员为结构体数组指针变                                                                                              量,将结构体数组usmart_nametab的首地址

                                                               赋给了他

usmart_dev.Init=usmart_init  //该成员为无返回值输入参数为u8类型的函数指针变                                                       量,将函数usmart_init地址赋给它

usmart_dev.cmd_rec=usmart_cmd_rec  //该成员为返回值和输入参数都为u8类型                                                                           的函数指针变量,将函                                                                                                       数usmart_cmd_rec地址赋给它

其他成员就不一一说啦

  1. struct _m_usmart_dev usmart_dev=
  2. {
  3.     usmart_nametab,
  4.     usmart_init,
  5.     usmart_cmd_rec,
  6.     usmart_exe,
  7.     usmart_scan,
  8.     sizeof(usmart_nametab)/sizeof(struct _m_usmart_nametab),//函数数量
  9.     0,          //参数数量
  10.     0,         //函数ID
  11.     1,        //参数显示类型,0,10进制;1,16进制
  12.     0,        //参数类型.bitx:,0,数字;1,字符串        
  13.     0,          //每个参数的长度暂存表,需要MAX_PARM个0初始化
  14.     0,        //函数的参数,需要PARM_LEN个0初始化
  15. };   

 

usmart_nametab 是结构体数组其成员是类型为_m_usmart_nametab的结构体(该结构体成员func为函数指针变量,成员name为指向u8类型的指针变量)

 

  1. struct _m_usmart_nametab //声明结构体类型
  2. {
  3.     void* func;            //函数指针
  4.     const u8* name;        //函数名(查找串)     
  5. };

 

  1. struct _m_usmart_nametab usmart_nametab[]=
  2. {
  3. #if USMART_USE_WRFUNS==1     //如果使能了读写操作
  4.     (void*)read_addr,"u32 read_addr(u32 addr)",
  5.     (void*)write_addr,"void write_addr(u32 addr,u32 val)",     
  6. #endif
  7.     (void*)delay_ms,"void delay_ms(u16 nms)",
  8.     (void*)delay_us,"void delay_us(u32 nus)",    
  9.     (void*)LCD_Clear,"void LCD_Clear(u16 Color)",
  10.     (void*)LCD_Fill,"void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)",
  11.     (void*)LCD_DrawLine,"void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)",
  12.     (void*)LCD_DrawRectangle,"void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)",
  13.     (void*)LCD_Draw_Circle,"void Draw_Circle(u16 x0,u16 y0,u8 r)",
  14.     (void*)LCD_ShowNum,"void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size)",
  15.     (void*)LCD_ShowString,"void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p)",
  16.     (void*)led_set,"void led_set(u8 sta)",
  17.     (void*)test_fun,"void test_fun(void(*ledset)(u8),u8 sta)",                          
  18.     (void*)LCD_ReadPoint,"u16 LCD_ReadPoint(u16 x,u16 y)",
  19. };                    

上面的代码是在定义并初始化usmart_nametab,也就是先定义结构体数组usmart_nametab再赋初值。

其中

usmart_nametab[0]={(void*)read_addr,"u32 read_addr(u32 addr)"}

usmart_nametab[1]={(void*)write_addr,"void write_addr(u32 addr,u32 val)"}

usmart_nametab[2]={(void*)delay_ms,"void delay_ms(u16 nms)"}

...............

与下面的代码是一个意思

  1. struct student //声明结构体
  2. {
  3. int num
  4. char name
  5. }
  6. struct student student1[]= //定义结构体数组并初始化
  7. {
  8. 1,"Li Ming",
  9. 2"Li Ergou",
  10. 3,"Li Yifeng"
  11. }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值