// lab5_starter.c // Notes for Fur Elise, E155 Lab 5 // Pitch in Hz, duration in ms const int notes[][2] = { {659, 125}, {623, 125}, {659, 125}, {623, 125}, {659, 125}, {494, 125}, {587, 125}, {523, 125}, {440, 250}, {0, 125}, {262, 125}, {330, 125}, {440, 125}, {494, 250}, {0, 125}, {330, 125}, {416, 125}, {494, 125}, {523, 250}, {0, 125}, {330, 125}, {659, 125}, {623, 125}, {659, 125}, {623, 125}, {659, 125}, {494, 125}, {587, 125}, {523, 125}, {440, 250}, {0, 125}, {262, 125}, {330, 125}, {440, 125}, {494, 250}, {0, 125}, {330, 125}, {523, 125}, {494, 125}, {440, 250}, {0, 125}, {494, 125}, {523, 125}, {587, 125}, {659, 375}, {392, 125}, {699, 125}, {659, 125}, {587, 375}, {349, 125}, {659, 125}, {587, 125}, {523, 375}, {330, 125}, {587, 125}, {523, 125}, {494, 250}, {0, 125}, {330, 125}, {659, 125}, {0, 250}, {659, 125}, {1319, 125}, {0, 250}, {623, 125}, {659, 125}, {0, 250}, {623, 125}, {659, 125}, {623, 125}, {659, 125}, {623, 125}, {659, 125}, {494, 125}, {587, 125}, {523, 125}, {440, 250}, {0, 125}, {262, 125}, {330, 125}, {440, 125}, {494, 250}, {0, 125}, {330, 125}, {416, 125}, {494, 125}, {523, 250}, {0, 125}, {330, 125}, {659, 125}, {623, 125}, {659, 125}, {623, 125}, {659, 125}, {494, 125}, {587, 125}, {523, 125}, {440, 250}, {0, 125}, {262, 125}, {330, 125}, {440, 125}, {494, 250}, {0, 125}, {330, 125}, {523, 125}, {494, 125}, {440, 500}, {0, 0}}; #include #include #include #include #include ///////////////////////////////////////////////////////////////////// // Constants ///////////////////////////////////////////////////////////////////// // GPIO FSEL Types #define INPUT 0 #define OUTPUT 1 #define ALT0 4 #define ALT1 5 #define ALT2 6 #define ALT3 7 #define ALT4 3 #define ALT5 2 #define GPFSEL ((volatile unsigned int *) (gpio + 0)) #define GPSET ((volatile unsigned int *) (gpio + 7)) #define GPCLR ((volatile unsigned int *) (gpio + 10)) #define GPLEV ((volatile unsigned int *) (gpio + 13)) #define INPUT 0 #define OUTPUT 1 // Physical addresses #define BCM2836_PERI_BASE 0x3F000000 #define GPIO_BASE (BCM2836_PERI_BASE + 0x200000) #define BLOCK_SIZE (4*1024) // Pointers that will be memory mapped when pioInit() is called volatile unsigned int *gpio; //pointer to base of gpio void pioInit() { int mem_fd; void *reg_map; // /dev/mem is a psuedo-driver for accessing memory in the Linux filesystem if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) { printf("can't open /dev/mem \n"); exit(-1); } reg_map = mmap( NULL, //Address at which to start local mapping (null means don't-care) BLOCK_SIZE, //Size of mapped memory block PROT_READ|PROT_WRITE,// Enable both reading and writing to the mapped memory MAP_SHARED, // This program does not have exclusive access to this memory mem_fd, // Map to /dev/mem GPIO_BASE); // Offset to GPIO peripheral if (reg_map == MAP_FAILED) { printf("gpio mmap error %d\n", (int)reg_map); close(mem_fd); exit(-1); } gpio = (volatile unsigned *)reg_map; }