Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1477175
  • 博文数量: 108
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-29 09:58
个人简介

兴趣是坚持一件事永不衰竭的动力

文章分类

全部博文(108)

文章存档

2021年(1)

2020年(10)

2019年(19)

2018年(9)

2016年(23)

2015年(43)

2013年(3)

我的朋友

分类: LINUX

2018-11-21 08:56:54

1.在common文件夹下新建cmd_led_test.c
2.修改common/Makefile ,添加一行COBJS-y += cmd_led_test.o ,将cmd_led_test编译进uboot
3.编译
4.下载测试
U-Boot# led on
argc = 2
argv[0] is: led
argv[1] is: on
输入led on,可以发现led被亮了,我使用的是am335x GPIO3_16
U-Boot# led off
argc = 2
argv[0] is: led
argv[1] is: off
输入led off,可以发现led被熄灭

附源码cmd_led_test.c
//======================================

点击(此处)折叠或打开

  1. #define AM335X_GPIO3_BASE 0x481AE000

  2. #define GPIO3_16_PIN 0x00010000

  3. #define GPIO_OE 0x481AE134

  4. #define GPIO_CLEARDATAOUT 0x481AE190

  5. #define GPIO_SETDATAOUT 0x481AE194


  6. #include <common.h>

  7. #include <command.h>


  8. static void led_on(){

  9.     int * gpio_SETDATAOUT = (int *) GPIO_SETDATAOUT ;

  10.     int * gpio_CLEARDATAOUT = (int *) GPIO_CLEARDATAOUT;

  11.     int * gpio_OE = (int *) GPIO_OE;

  12.     

  13.     *gpio_OE = ~GPIO3_16_PIN;

  14.     *gpio_SETDATAOUT = GPIO3_16_PIN;

  15. }

  16. static void led_off(){

  17.     int * gpio_SETDATAOUT = (int *) GPIO_SETDATAOUT ;

  18.     int * gpio_CLEARDATAOUT = (int *) GPIO_CLEARDATAOUT;

  19.     

  20.     int * gpio_OE = (int *) GPIO_OE;

  21.     *gpio_OE = ~GPIO3_16_PIN;

  22.     *gpio_CLEARDATAOUT = GPIO3_16_PIN;

  23.     

  24. }

  25. static int do_led(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])

  26. {

  27.     int i = 0;

  28.         printf("argc = %d\n",argc);

  29.     for( i = 0; i < argc ; i++){

  30.         printf("argv[%d] is: %s\n",i,argv[i]);

  31.     }

  32.     if( argc == 2){

  33.         if( strcmp(argv[1],"on") == 0 ){

  34.             led_on();

  35.         }else{

  36.             led_off();

  37.         }

  38.     }

  39.     return 0;

  40. }



  41. U_BOOT_CMD(

  42.     led, 2, 0, do_led,

  43.     "led - this is a led command, light ON or OFF led2 ,which control by GPIO3_16",

  44.     "- led - this is a led command, light ON or OFF led2 ,which control by GPIO3_16"

  45. );


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