Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #define RPI_SYSTIMER_BASE 0x20003000UL
- /* The base address of the GPIO peripheral (ARM Physical Address) */
- #define GPIO_BASE 0x20200000UL
- // define used GPIO pin
- #define LED_GPFSEL GPIO_GPFSEL1
- #define LED_GPFBIT 18
- #define LED_GPSET GPIO_GPSET0
- #define LED_GPCLR GPIO_GPCLR0
- #define LED_GPIO_BIT 16
- #define GPIO_GPFSEL0 0
- #define GPIO_GPFSEL1 1
- #define GPIO_GPFSEL2 2
- #define GPIO_GPFSEL3 3
- #define GPIO_GPFSEL4 4
- #define GPIO_GPFSEL5 5
- #define GPIO_GPSET0 7
- #define GPIO_GPSET1 8
- #define GPIO_GPCLR0 10
- #define GPIO_GPCLR1 11
- #define GPIO_GPLEV0 13
- #define GPIO_GPLEV1 14
- #define GPIO_GPEDS0 16
- #define GPIO_GPEDS1 17
- #define GPIO_GPREN0 19
- #define GPIO_GPREN1 20
- #define GPIO_GPFEN0 22
- #define GPIO_GPFEN1 23
- #define GPIO_GPHEN0 25
- #define GPIO_GPHEN1 26
- #define GPIO_GPLEN0 28
- #define GPIO_GPLEN1 29
- #define GPIO_GPAREN0 31
- #define GPIO_GPAREN1 32
- #define GPIO_GPAFEN0 34
- #define GPIO_GPAFEN1 35
- #define GPIO_GPPUD 37
- #define GPIO_GPPUDCLK0 38
- #define GPIO_GPPUDCLK1 39
- typedef struct {
- volatile uint32_t control_status;
- volatile uint32_t counter_lo;
- volatile uint32_t counter_hi;
- volatile uint32_t compare0;
- volatile uint32_t compare1;
- volatile uint32_t compare2;
- volatile uint32_t compare3;
- } rpi_sys_timer_t;
- void RPI_WaitMicroSeconds( uint32_t us );
- static rpi_sys_timer_t* rpiSystemTimer = (rpi_sys_timer_t*)RPI_SYSTIMER_BASE;
- /** GPIO Register set */
- volatile unsigned int* gpio;
- /** Main function - we'll never return from here */
- int main(void)
- {
- /* Assign the address of the GPIO peripheral (Using ARM Physical Address) */
- gpio = (unsigned int*)GPIO_BASE;
- /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO
- peripheral register to enable GPIO16 as an output */
- gpio[LED_GPFSEL] |= (1 << LED_GPFBIT);
- /* Never exit as there is no OS to exit to! */
- while(1)
- {
- RPI_WaitMicroSeconds( 500000 );
- /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off
- for plus models )*/
- gpio[LED_GPCLR] = (1 << LED_GPIO_BIT);
- RPI_WaitMicroSeconds( 500000 );
- /* Set the LED GPIO pin high ( Turn OK LED off for original Pi, and on
- for plus models )*/
- gpio[LED_GPSET] = (1 << LED_GPIO_BIT);
- }
- }
- void RPI_WaitMicroSeconds( uint32_t us )
- {
- volatile uint32_t ts = rpiSystemTimer->counter_lo;
- while( ( rpiSystemTimer->counter_lo - ts ) < us )
- {
- /* Wait */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement