|
Altera SoC 的第一个应用程序--点亮LED
[复制链接]
LED_Blink_project.zip
(10.81 KB, 下载次数: 33)
- /*
- * Copyright Altera 2013
- * All Rights Reserved
- * File: hello.c
- *
- */
- #include <sys/mman.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #define MAP_SIZE (0x20000)
- #define MAP_BASE_ADDR (0xFF200000) //lwAxiMaster Base Addr
- #define LED_PIO_BASE (0x10040)
- #define LED_PIO_DATA_OFFSET (0x0)
- void usage(char * executable){
- printf("Usage: %s <munber of blink in dec> <blink period (ms)>\n", executable);
- printf("Ex.): %s 100 250\n",executable);
- }
- int main(int argc, char** argv)
- {
- int fd;
- int i;
- unsigned int *mapped_ptr;
- unsigned long int num_of_blink, blink_period;
- printf("\n\n LED Blink Demo \n\n");
- if (argc != 3){
- usage(argv[0]);
- return -1;
- }
- num_of_blink = strtol(argv[1], NULL, 10);
- blink_period = strtol(argv[2], NULL, 10);
- fd= open("/dev/mem", O_RDWR|O_SYNC);
- if(fd < 0){
- printf(" failed to open /dev/mem\n");
- return -1;
- }
- mapped_ptr = (unsigned int *)mmap(NULL,
- MAP_SIZE,
- PROT_READ|PROT_WRITE,
- MAP_SHARED,
- fd,
- MAP_BASE_ADDR );
- if(mapped_ptr == MAP_FAILED){
- printf("mmap failed\n");
- return -1;
- }
- printf(" blink start \n %d times \n period = %d ms\n", num_of_blink,blink_period);
- for(i=0; i < num_of_blink; i++) {
- mapped_ptr[ (LED_PIO_BASE + LED_PIO_DATA_OFFSET)/sizeof(unsigned int)] = 0xf;
- usleep(1000*blink_period);
- mapped_ptr[(LED_PIO_BASE + LED_PIO_DATA_OFFSET)/sizeof(unsigned int)] = 0x0;
- usleep(1000*blink_period);
- }
- munmap(mapped_ptr, MAP_SIZE);
- close(fd);
- printf("\n done\n\n");
- return 0;
- }
复制代码
|
赞赏
-
2
查看全部赞赏
-
|