Hi, thanks for your last reply. And it do helps me. But I'm a newer in embeded system programming, and our teacher ask us to blink LED by using exact LED address, he also told me that we will use I2C in the furture but not now. The attached code is provided by him. And I think I should get this address to conduct this experiment. Please help me with it, or told me how to change these code.
Thank you!
#include <linux/ioport.h> #include <asm/uaccess.h> // 문제가 있을 경우 asm-arm으로 변경 #include <linux/module.h> #include <linux/fs.h> #include <asm/io.h> // 문제가 있을 경우 asm-arm으로 변경 // 문제가 있을 경우 linux/init.h, linux/version.h 추가 #define LED_MAJOR 239 #define LED_NAME "LED" #define LED_MODULE_VERSION "LED IO PORT V0.1" #define LED_ADDRESS 0x12400000 // 0x0c000016 으로 고칠 것 #define LED_CS (*((volatile unsigned char *)(mem_base))) static void *mem_base; unsigned long mem_addr, mem_len; static int led_clear(void) { LED_CS = 0xFF; return 0; } int led_open(struct inode *minode, struct file *mfile) { return 0; } int led_release(struct inode *minode, struct file *mfile) { return 0; } ssize_t led_write_byte(struct file *inode, const char *gdata, size_t length, loff_t *off_what) { unsigned char c; get_user(c, (unsigned char *)gdata); LED_CS = c; // 문제가 있을 경우 outw(c, LED_CS); 로 변경 return length; } static struct file_operations led_fops = { .owner = THIS_MODULE, .write = led_write_byte, .open = led_open, .release = led_release, }; int led_init(void) { int result; result = register_chrdev(LED_MAJOR, LED_NAME, &led_fops); if(result < 0) { printk(KERN_WARNING "can't get any major number.\n"); return result; } mem_addr = LED_ADDRESS; mem_len = 0x1000; mem_base = ioremap_nocache(mem_addr, mem_len); if( !mem_base) { printk("Error mapping LED memory\n"); release_mem_region(mem_addr, mem_len); return -EBUSY; } printk("init module, LED major number : %d\n", LED_MAJOR); return 0; } void led_exit(void) { led_clear(); if (unregister_chrdev(LED_MAJOR, LED_NAME)) printk(KERN_WARNING"%s driver cleanup failed.\n", LED_NAME); iounmap(mem_base); } MODULE_LICENSE("GPL"); module_init(led_init); module_exit(led_exit);
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(int argc, char **argv) { int dev; char buff; if(argc <= 1) { printf("please input the parameter! ex)./test 0xa1\n"); return -1; } dev = open("/dev/LED", O_WRONLY); if (dev != -1) { if(argv[1][0] == '0' && (argv[1][1] == 'x' || argv[1][1] == 'X')) buff = (unsigned char)strtol(&argv[1][2], NULL, 16); else buff = atoi(argv[1]); write(dev, &buff, 1); close(dev); } else { printf( "Device Open ERROR!\n"); exit(-1); } return(0); }