Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1222239
  • 博文数量: 105
  • 博客积分: 127
  • 博客等级: 入伍新兵
  • 技术积分: 962
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-29 15:22
文章分类

全部博文(105)

文章存档

2021年(1)

2019年(3)

2018年(1)

2017年(11)

2016年(47)

2015年(32)

2014年(4)

2012年(6)

我的朋友

分类: 嵌入式

2015-07-01 11:23:41

uoobt 中需要用到i2c 去与CPLD 进行通信。试过程中,由于CPLD那边的程序还是刚写,就想用I2C 命令去配合初步调试,等通过命令能读取到SLAVE地址,再在uboot中程序操作与CPLD进行功能通信。

平台:imx6dl

Uboot2009.8

       uboot 的命令行下,i2c dev 0后显示的是

          I2C sub-system

          speed [speed] - show or set I2C bus speed  

          i2c bus [muxtype:muxaddr:muxchannel] - add a new bus reached over muxes  

          i2c dev [dev] - show or set current I2C bus  

          i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device  

          i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)  

          i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)  

          i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)  

          i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum  

          i2c probe - show devices on the I2C bus  

          i2c reset - re-init the I2C Controller  

          i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device    

          i2c sdram chip - print SDRAM configuration information

 

这就是告诉你,你所输入的命令不支持。尼玛,freescale 就喜欢干这种事,做到一半,剩下的不管。你还不能说他没做,因为他确实做了,只是没有做好而已。接着又试了一下 i2c probe 发现能找到 i2c channel 2 的芯片地址。这个时候我就顺便把所有的I2C命令在这上面都试了一下。好在其他要用到的命令是支持的。

问题来了,这个i2c dev 没有办法去切换通道,还是没有办法与CPLD通信。跟了一下代码,发现了是没实现


点击(此处)折叠或打开

  1. unsigned int i2c_get_bus_num(void);
  2. int i2c_set_bus_num(unsigned int bus);
  3. 如果要支持这个I2C dev 命令,还需要配置一些其他的宏定义
  4.         #define CONFIG_I2C_MULTI_BUS // 多总线
  5.         #define CONFIG_I2C_MUX 1 //需要打开,好像是因为管脚复用的原因
  6.         #define CONFIG_SYS_MAX_I2C_BUS 2 //表示总线有三个(由于实现是我自己做的,我是从0开始计算的)
  7. 另外还得修改mxc_i2c.c 这里面的相关函数,I2C read ,write 等。因为他只是做了一个通道,需要配合上面的i2c_set_bus_num 来实现通道的可切换,比较简单,只是将操作寄存器基地址与通道数绑定。在实现上面的过程中,发现了一个宏定义U_BOOT_CMD


  1. U_BOOT_CMD(
  2.          i2c, 6, 1, do_i2c,
  3.          "I2C sub-system",
  4.          "speed [speed] - show or set I2C bus speed\n"
  5. #if defined(CONFIG_I2C_MUX)
  6.          "i2c bus [muxtype:muxaddr:muxchannel] - add a new bus reached over muxes\n"
  7. #endif /* CONFIG_I2C_MUX */
  8. #if defined(CONFIG_I2C_MULTI_BUS)
  9.          "i2c dev [dev] - show or set current I2C bus\n"
  10. #endif /* CONFIG_I2C_MULTI_BUS */
  11.          "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
  12.          "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
  13.          "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
  14.          "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
  15.          "i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
  16.          "i2c probe - show devices on the I2C bus\n"
  17.          "i2c reset - re-init the I2C Controller\n"
  18.          "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device"
  19. #if defined(CONFIG_CMD_SDRAM)
  20.          "\n"
  21.          "i2c sdram chip - print SDRAM configuration information"
  22. #endif
  23. );


看起来很牛逼的样子。U_BOOT_CMD应该是一个宏。Include/command.h中找到了其定义

点击(此处)折叠或打开

  1. #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
  2. cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
  3.  #define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))
  4.  
  5. cmd_tbl_t 最终的定义如下:
  6. struct cmd_tbl_s {
  7.          char *name; /* Command Name */
  8.          int maxargs; /* maximum number of arguments */
  9.          int repeatable; /* autorepeat allowed? */
  10.                                                /* Implementation function */
  11.          int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
  12.          char *usage; /* Usage message (short) */
  13. #ifdef CONFIG_SYS_LONGHELP
  14.          char *help; /* Help message (long) */
  15. #endif
  16. #ifdef CONFIG_AUTO_COMPLETE
  17.          /* do auto completion on the arguments */
  18.          int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);
  19. #endif
  20. };

以上面的I2C为例

i2c, 6, 1, do_i2c,"I2C sub-system",

name : i2c //命令名字

maxargs: 6 //最大参数

repeatable: 1 // 自动重复执行

cmd : do_i2c // 要实现的函数

usage: I2C sub-system

help: 帮助信息

但这个宏是在什么时候调用的呢?其实应该说这个结构体。

参考链接:

存在一个_u_boot_cmd 段里面,然后find_cmd可以遍历到,且最终调用。

了解这个后,在uboot中添加一个新的命令,就显得格外简单。例如添加一个新的命令,来记录自己的板号,公司等信息。

Cmd_test.c 这个文件就是一个添加新命令的例子。

阅读(5181) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~