|
Beaglebone black中QNX操作系统LED驱动问题
[复制链接]
1芯积分
本帖最后由 传说哥 于 2015-10-19 10:59 编辑
本人购买了Beaglebone black开发板,并从QNX官网下载了针对该板卡的BSP
http://community.qnx.com/sf/wiki ... i/TiAm335Beaglebone,
仿照BSP中led.c文件中int doleds(unsigned char ch)- BSP中led.c文件中的int doleds(unsigned char ch)
- int doleds(unsigned char ch)
- {
- uintptr_t gpio_base;
- uint32_t val;
- // Map device registers
- gpio_base = mmap_device_io(AM335X_GPIO_SIZE, AM335X_GPIO1_BASE);
- if(gpio_base == MAP_DEVICE_FAILED)
- {
- perror("Can't map device I/O");
- return 0;
- }
- // Read GPIO output enable register
- // 0 The corresponding GPIO port is configured as an output.
- // 1 The corresponding GPIO port is configured as an input.
- val = in32(gpio_base + GPIO_OE);
- val &= ~(LED0|LED1|LED2|LED3);
- out32(gpio_base + GPIO_OE, val);
- // Write GPIO data output register
- val = in32(gpio_base + GPIO_DATAOUT);
- val &= ~(LED0|LED1|LED2|LED3);
- val |= (LEDS(ch));
- out32(gpio_base + GPIO_DATAOUT, val);
- munmap_device_io(gpio_base, AM335X_GPIO_SIZE);
- return 1;
- }
复制代码 写了如下代码来驱动LED显示。
结果是报执行到val = in32(gpio_base + GPIO_OE)有误,in32()调用有误。
我对比了自己写的代码和BSP中的代码,感觉自己的代码没有问题,求高手指点问题出在哪里了?
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <stdio.h>
- #include <stddef.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/mman.h>
- #include <hw/inout.h>
- #include "am335x.h"
- #include <sys/iofunc.h>
- #include <sys/dispatch.h>
- #define LED0 (1<<21)
- #define LED1 (1<<22)
- #define LED2 (1<<23)
- #define LED3 (1<<24)
- #define LEDS(n) ((n&0xf)<<21)
- int main(void)
- {
- uintptr_t gpio_base;
- uint32_t val;
- unsigned char ch =10;
- if (ThreadCtl(_NTO_TCTL_IO, 0) == -1) {
- perror("ThreadCtl");
- exit(EXIT_FAILURE);
- }
- // Map device registers
- gpio_base = mmap_device_io(AM335X_GPIO_SIZE, AM335X_GPIO1_BASE);
- if(gpio_base == MAP_DEVICE_FAILED)
- {
- perror("Can't map device I/O");
- return 0;
- }
- // Read GPIO output enable register
- // 0 The corresponding GPIO port is configured as an output.
- // 1 The corresponding GPIO port is configured as an input.
- val = in32(gpio_base + GPIO_OE);
- val &= ~(LED0|LED1|LED2|LED3);
- out32(gpio_base + GPIO_OE, val);
- // Write GPIO data output register
- val = in32(gpio_base + GPIO_DATAOUT);
- val &= ~(LED0|LED1|LED2|LED3);
- val |= (LEDS(ch));
- out32(gpio_base + GPIO_DATAOUT, val);
- munmap_device_io(gpio_base, AM335X_GPIO_SIZE);
- }
复制代码 使用shell命令看运行结果为:
|
|