Skip to content

Instantly share code, notes, and snippets.

@muthmano-dev
Created March 19, 2015 04:10
Show Gist options
  • Save muthmano-dev/c0b7fae3a86ec6870572 to your computer and use it in GitHub Desktop.
Save muthmano-dev/c0b7fae3a86ec6870572 to your computer and use it in GitHub Desktop.
an example C code using PRUSS-C libraries
#include <gpio_v2.h>
#include <soc_AM335x.h>
//#include "blink.h"
#define PRU0_ARM_INTERRUPT 19
#define AM33XX
#define GPIO1 (*(volatile unsigned long *)(0x4804c000)) // The address of the GPIO1
#define GPIO_INSTANCE_ADDRESS (SOC_GPIO_1_REGS)
#define SYSCFG (*(&C4+0x01))
int C4 __attribute__((cregister("MEM",near),peripheral)); //only compatible with v1.1.0B1 +
//add following lines to MEMORY{} in lnk.cmd
//PAGE 2:
// MEM : o = 0x00026000 l = 0x00002000 CREGISTER=4
volatile register unsigned int __R31;
static void blink1(void);
static void blink2(void);
void main(void)
{
/*Intialise OCP Master port for accessing external memories*/
SYSCFG&=0xFFFFFFEF;
/*Start Main Code*/
blink1();
blink2();
/*Exiting procedure*/
__R31 = 35; // Send notification to Host for program completion
__halt(); //only compatible with v2.0.0B1 + for lower verions of Compiler use
//asm(" HALT");
}
/*Blink user led 2,3 twice and stay ON*/
static void blink1(void)
{
unsigned int i;
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 23, GPIO_PIN_LOW);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 24, GPIO_PIN_LOW);
for(i=0;i<0x00a00000;i++);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 23, GPIO_PIN_HIGH);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 24, GPIO_PIN_HIGH);
for(i=0;i<0x00a00000;i++);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 23, GPIO_PIN_LOW);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 24, GPIO_PIN_LOW);
for(i=0;i<0x00a00000;i++);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 23, GPIO_PIN_HIGH);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 24, GPIO_PIN_HIGH);
for(i=0;i<0x00a00000;i++);
}
/*Blink userled 0,1 twice and stay on */
static void blink2(void)
{
unsigned int i;
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 21, GPIO_PIN_LOW);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 22, GPIO_PIN_LOW);
for(i=0;i<0x00a00000;i++);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 21, GPIO_PIN_HIGH);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 22, GPIO_PIN_HIGH);
for(i=0;i<0x00a00000;i++);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 21, GPIO_PIN_LOW);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 22, GPIO_PIN_LOW);
for(i=0;i<0x00a00000;i++);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 21, GPIO_PIN_HIGH);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, 22, GPIO_PIN_HIGH);
for(i=0;i<0x00a00000;i++);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment