libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
pruss_add.c
Go to the documentation of this file.
1 
16 #include "stdio.h"
17 #include "string.h"
18 #include "libpruio/pruio.h" // the library (for pinmuxing)
19 #include "libpruio/pruio_pins.h" // CPU balls human readable
20 #include "libpruio/pruio_prussdrv.h" // user space part of uio_pruss
21 
22 
50 {
51  const uint32 PRUcode[] = {
52  0x240000e0,
53  0xf104e081,
54  0x30830002,
55  0x00e2e1e1,
56  0xe1002081,
57  0x1004041f,
58  0x2a000000,
59  0x21000100 };
60 
61  if(0 >= prussdrv_pru_write_memory(IRam, 0, PRUcode, sizeof(PRUcode)))
62  {printf("failed loading instructions\n"); return -1;}
63  return 0;
64 }
65 
66 
68 int main(int argc, char **argv)
69 {
70  pruIo *io = pruio_new(PRUIO_ACT_PRU1, 0, 0, 0);
71  do {
73 //
74 // Check init success
75 //
76  if(io->Errr) {
77  printf("initialisation failed (%s)\n", io->Errr); break;}
78 
79  if(io->PruNo) { // we use the other PRU
80  pru_num = 0;
84  else {
85  pru_num = 1;
89 //
90 // Now prepare the other PRU
91 //
92  if(prussdrv_open(PRU_EVTOUT_0)) { // note: libpruio uses PRU_EVTOUT_5
93  printf("prussdrv_open failed\n"); break;}
94  //Note: no prussdrv_pruintc_init(), libpruio did it already
95 
97 //
98 // Pass parameters to PRU
99 //
100  uint32 *dram;
101  prussdrv_map_prumem(pru_dram, (void *) &dram); // get dram pointer
102  dram[1] = 23; // start value
103  dram[2] = 7; // value to add
104  dram[3] = 67; // loop count (max 16 bit = 65536)
105  dram[4] = pru_intr + 16; // the interrupt we're waiting for
106 //
107 // Execute
108 //
109  printf("instructions loaded, starting PRU-%d\n", pru_num);
110  prussdrv_pru_enable(pru_num); // start
111  prussdrv_pru_wait_event(PRU_EVTOUT_0); // wait until finished
112  prussdrv_pru_clear_event(PRU_EVTOUT_0, pru_intr); // clear interrupt (optional, useful when starting again)
113 //
114 // Check result
115 //
116  if(dram[0] == (dram[1] + (dram[2] * dram[3])))
117  {printf("Test OK %d == %d + (%d * %d)\n", dram[0], dram[1], dram[2], dram[3]);}
118  else
119  {printf("Test failed: %d != %d + (%d * %d)\n", dram[0], dram[1], dram[2], dram[3]);}
120 
121  prussdrv_pru_disable(pru_num); // disable PRU
122  // note: no prussdrv_exit(), libpruio does it in the destructor
123  } while (0);
124 
125  pruio_destroy(io); /* destroy driver structure */
126  return 0;
127 }
VAR io
create new driver UDT
Definition: 1.bas:18
unsigned int uint32
32 bit unsigned integer data type.
Definition: pruio.h:41
int int32
32 bit signed integer data type.
Definition: pruio.h:38
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo().
@ PRUIO_ACT_PRU1
Activate PRU-1 (= default, instead of PRU-0).
Definition: pruio.h:518
#define PRU1_ARM_INTERRUPT
System event PRU-1 -> ARM.
Definition: pruio_intc.h:19
#define PRUSS0_PRU0_IRAM
ID for PRU-0 instruction ram.
Definition: pruio_intc.h:70
#define PRUSS0_PRU1_DRAM
ID for PRU-1 data ram.
Definition: pruio_intc.h:69
#define PRU_EVTOUT_0
ID for host interrupt 0.
Definition: pruio_intc.h:79
#define PRU0_ARM_INTERRUPT
System event PRU-0 -> ARM.
Definition: pruio_intc.h:18
#define PRUSS0_PRU1_IRAM
ID for PRU-1 instruction ram.
Definition: pruio_intc.h:71
#define PRUSS0_PRU0_DRAM
ID for PRU-0 data ram.
Definition: pruio_intc.h:68
int32 prussdrv_pru_disable(uint32 prunum)
See prussdrv_pru_disable(BYVAL_AS_UInt32 PruId)
#define prussdrv_pru_enable(N)
Macro for variadic parameter list.
void prussdrv_pru_clear_event(uint32 host_interrupt, uint32 sysevent)
See prussdrv_pru_clear_event(BYVAL_AS_UInt32 Irq, BYVAL_AS_UInt32 Event)
uint32 prussdrv_pru_wait_event(uint32 host_interrupt)
See prussdrv_pru_wait_event(BYVAL_AS_UInt32 Irq)
int32 prussdrv_open(uint32 host_interrupt)
See prussdrv_open(BYVAL_AS_UInt32 Irq)
int32 prussdrv_pru_write_memory(uint32 pru_ram_id, uint32 wordoffset, const uint32 *memarea, uint32 bytelength)
See prussdrv_pru_write_memory(BYVAL_AS_UInt32 RamId, BYVAL_AS_UInt32 Offs, BYVAL_AS_CONST_UInt32_PTR ...
int32 prussdrv_map_prumem(uint32 pru_ram_id, void **address)
See prussdrv_map_prumem(BYVAL_AS_UInt32 RamId, BYVAL_AS_ANY_PTR_PTR Addr)
UInt32 pru_intr
ID of its interrupt.
Definition: pruss_add.bas:67
UInt32_PTR dram
a pointer to PRU data ram
Definition: pruss_add.bas:97
UInt32 pru_num
which pru to use
Definition: pruss_add.bas:64
UInt32 pru_iram
ID of its instruction ram.
Definition: pruss_add.bas:65
UInt32 pru_dram
ID of its data ram.
Definition: pruss_add.bas:66
int main(int argc, char **argv)
The main function.
Definition: pruss_add.c:68
int32 load_firmware(uint32 IRam)
load firmware to PRU
Definition: pruss_add.c:49
Wrapper structure for PruIo.
Definition: pruio.h:550