libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
pruss_add.bas
Go to the documentation of this file.
1 
14 
15 #include ONCE "BBB/pruio.bi" ' the library (for pinmuxing)
16 #include ONCE "BBB/pruio_pins.bi" ' CPU balls human readable
17 #include ONCE "BBB/pruio_prussdrv.bi" ' user space part of uio_pruss
18 
19 
20 
46 FUNCTION load_firmware(BYVAL IRam AS UInt32) AS Int32
47  DIM AS CONST UInt32 PRUcode(...) = { _
48  &h240000E0 _
49  , &hF104E081 _
50  , &h30830002 _
51  , &h00E2E1E1 _
52  , &hE1002081 _
53  , &h1004041F _
54  , &h2A000000 _
55  , &h21000100 }
56  VAR l = (UBOUND(PRUcode) + 1) * SIZEOF(PRUcode)
57  RETURN 0 >= prussdrv_pru_write_memory(IRam, 0, @PRUcode(0), l)
58 END FUNCTION
59 
60 
61 VAR io = NEW PruIo(PRUIO_ACT_PRU1)
62 DO
63  DIM AS UInt32 _
64  pru_num _
65  , pru_iram _
66  , pru_dram _
67  , pru_intr
68 '
69 ' Check init success
70 '
71  IF io->Errr THEN _
72  ?"initialisation failed (" & *io->Errr & ")" : EXIT DO
73 
74  IF io->PruNo THEN ' we use the other PRU
75  pru_num = 0
76  pru_iram = PRUSS0_PRU0_IRAM
77  pru_dram = PRUSS0_PRU0_DRAM
78  pru_intr = PRU0_ARM_INTERRUPT
79  ELSE
80  pru_num = 1
81  pru_iram = PRUSS0_PRU1_IRAM
82  pru_dram = PRUSS0_PRU1_DRAM
83  pru_intr = PRU0_ARM_INTERRUPT ' libpruio uses PRU1_ARM_INTERRUPT!
84  END IF
85 '
86 ' Now prepare the other PRU
87 '
88  IF prussdrv_open(PRU_EVTOUT_0) THEN _ ' note: libpruio uses PRU_EVTOUT_5
89  ?"prussdrv_open failed" : EXIT DO
90  ' Note: no prussdrv_pruintc_init(), libpruio did it already
91 
92  IF load_firmware(pru_iram) < 0 THEN _
93  ?"failed loading PRUSS instructions" : EXIT DO
94 '
95 ' Pass parameters to PRU
96 '
97  DIM AS UInt32 PTR dram
98  prussdrv_map_prumem(pru_dram, CAST(ANY PTR, @dram)) ' get dram pointer
99  dram[1] = 23 ' start value
100  dram[2] = 7 ' value to add
101  dram[3] = 67 ' loop count (max 16 bit = 65536)
102  dram[4] = pru_intr + 16 ' the interrupt we're waiting for
103 '
104 ' Execute
105 '
106  ?"instructions loaded, starting PRU-" & pru_num
107  prussdrv_pru_enable(pru_num) ' start
108  prussdrv_pru_wait_event(PRU_EVTOUT_0) ' wait until finished
109  prussdrv_pru_clear_event(PRU_EVTOUT_0, pru_intr) ' clear interrupt (optional, useful when starting again)
110 '
111 ' Check result
112 '
113  IF dram[0] = (dram[1] + (dram[2] * dram[3])) THEN
114  ?"Test OK " & dram[0] & " = " & dram[1] & " + (" & dram[2] & " * " & dram[3] & ")"
115  ELSE
116  ?"Test failed " & dram[0] & " <> " & dram[1] & " + (" & dram[2] & " * " & dram[3] & ")"
117  END IF
118 
119  prussdrv_pru_disable(pru_num) ' disable PRU
120  ' note: no prussdrv_exit(), libpruio does it in the destructor
121 LOOP UNTIL 1
122 
123 DELETE io ' destroy driver structure
124 
125 '' help Doxygen to document the main code
126 '&/** The main function. */
127 '&int main() {PruIo::PruIo(); PruIo::~PruIo();}
128