comparison include/prussdrv.h @ 15:901d205d1a3c

Updated to latest PRU library; external PRU file no longer needed. Also catch SIGTERM as well as SIGINT to clean up gracefully.
author andrewm
date Sat, 07 Feb 2015 16:41:56 +0000
parents 8a575ba3ab52
children
comparison
equal deleted inserted replaced
14:06f93bef7dd2 15:901d205d1a3c
1 /* 1 /*
2 * prussdrv.h 2 * prussdrv.h
3 * 3 *
4 * Describes PRUSS userspace driver for Industrial Communications 4 * Describes PRUSS userspace driver for Industrial Communications
5 * 5 *
6 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 6 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
7 * 7 *
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * Redistributions of source code must retain the above copyright 13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 15 *
16 * Redistributions in binary form must reproduce the above copyright 16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the 18 * documentation and/or other materials provided with the
19 * distribution. 19 * distribution.
20 * 20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of 21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived 22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission. 23 * from this software without specific prior written permission.
24 * 24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * 36 *
37 */ 37 */
38 38
39 /* 39 /*
47 47
48 #ifndef _PRUSSDRV_H 48 #ifndef _PRUSSDRV_H
49 #define _PRUSSDRV_H 49 #define _PRUSSDRV_H
50 50
51 #include <sys/types.h> 51 #include <sys/types.h>
52 #include <pthread.h>
53 52
54 #if defined (__cplusplus) 53 #if defined (__cplusplus)
55 extern "C" { 54 extern "C" {
56 #endif 55 #endif
57 56
62 61
63 #define PRUSS0_PRU0_DATARAM 0 62 #define PRUSS0_PRU0_DATARAM 0
64 #define PRUSS0_PRU1_DATARAM 1 63 #define PRUSS0_PRU1_DATARAM 1
65 #define PRUSS0_PRU0_IRAM 2 64 #define PRUSS0_PRU0_IRAM 2
66 #define PRUSS0_PRU1_IRAM 3 65 #define PRUSS0_PRU1_IRAM 3
66
67 #define PRUSS_V1 1 // AM18XX
68 #define PRUSS_V2 2 // AM33XX
67 69
68 //Available in AM33xx series - begin 70 //Available in AM33xx series - begin
69 #define PRUSS0_SHARED_DATARAM 4 71 #define PRUSS0_SHARED_DATARAM 4
70 #define PRUSS0_CFG 5 72 #define PRUSS0_CFG 5
71 #define PRUSS0_UART 6 73 #define PRUSS0_UART 6
82 #define PRU_EVTOUT_4 4 84 #define PRU_EVTOUT_4 4
83 #define PRU_EVTOUT_5 5 85 #define PRU_EVTOUT_5 5
84 #define PRU_EVTOUT_6 6 86 #define PRU_EVTOUT_6 6
85 #define PRU_EVTOUT_7 7 87 #define PRU_EVTOUT_7 7
86 88
87 typedef void *(*prussdrv_function_handler) (void *);
88 typedef struct __sysevt_to_channel_map { 89 typedef struct __sysevt_to_channel_map {
89 short sysevt; 90 short sysevt;
90 short channel; 91 short channel;
91 } tsysevt_to_channel_map; 92 } tsysevt_to_channel_map;
92 typedef struct __channel_to_host_map { 93 typedef struct __channel_to_host_map {
101 //{-1, -1} indicates end of list 102 //{-1, -1} indicates end of list
102 tsysevt_to_channel_map sysevt_to_channel_map[NUM_PRU_SYS_EVTS]; 103 tsysevt_to_channel_map sysevt_to_channel_map[NUM_PRU_SYS_EVTS];
103 //Channel to Host map.Channels -Range: 0..9 HOSTs - Range:0..9 104 //Channel to Host map.Channels -Range: 0..9 HOSTs - Range:0..9
104 //{-1, -1} indicates end of list 105 //{-1, -1} indicates end of list
105 tchannel_to_host_map channel_to_host_map[NUM_PRU_CHANNELS]; 106 tchannel_to_host_map channel_to_host_map[NUM_PRU_CHANNELS];
106 //10-bit mask - Enable Host0-Host9 {Host0/1:PRU0/1, Host2..9 : PRUEVT_OUT0..7) 107 //10-bit mask - Enable Host0-Host9 {Host0/1:PRU0/1, Host2..9 : PRUEVT_OUT0..7}
107 unsigned int host_enable_bitmask; 108 unsigned int host_enable_bitmask;
108 } tpruss_intc_initdata; 109 } tpruss_intc_initdata;
109 110
110 int prussdrv_init(void); 111 int prussdrv_init(void);
111 112
112 int prussdrv_open(unsigned int pru_evtout_num); 113 int prussdrv_open(unsigned int host_interrupt);
114
115 /** Return version of PRU. This must be called after prussdrv_open. */
116 int prussdrv_version();
117
118 /** Return string description of PRU version. */
119 const char* prussdrv_strversion(int version);
113 120
114 int prussdrv_pru_reset(unsigned int prunum); 121 int prussdrv_pru_reset(unsigned int prunum);
115 122
116 int prussdrv_pru_disable(unsigned int prunum); 123 int prussdrv_pru_disable(unsigned int prunum);
117 124
118 int prussdrv_pru_enable(unsigned int prunum); 125 int prussdrv_pru_enable(unsigned int prunum);
126 int prussdrv_pru_enable_at(unsigned int prunum, size_t addr);
119 127
120 int prussdrv_pru_write_memory(unsigned int pru_ram_id, 128 int prussdrv_pru_write_memory(unsigned int pru_ram_id,
121 unsigned int wordoffset, 129 unsigned int wordoffset,
122 unsigned int *memarea, 130 const unsigned int *memarea,
123 unsigned int bytelength); 131 unsigned int bytelength);
124 132
125 int prussdrv_pruintc_init(tpruss_intc_initdata * prussintc_init_data); 133 int prussdrv_pruintc_init(const tpruss_intc_initdata *prussintc_init_data);
134
135 /** Find and return the channel a specified event is mapped to.
136 * Note that this only searches for the first channel mapped and will not
137 * detect error cases where an event is mapped erroneously to multiple
138 * channels.
139 * @return channel-number to which a system event is mapped.
140 * @return -1 for no mapping found
141 */
142 short prussdrv_get_event_to_channel_map( unsigned int eventnum );
143
144 /** Find and return the host interrupt line a specified channel is mapped
145 * to. Note that this only searches for the first host interrupt line
146 * mapped and will not detect error cases where a channel is mapped
147 * erroneously to multiple host interrupt lines.
148 * @return host-interrupt-line to which a channel is mapped.
149 * @return -1 for no mapping found
150 */
151 short prussdrv_get_channel_to_host_map( unsigned int channel );
152
153 /** Find and return the host interrupt line a specified event is mapped
154 * to. This first finds the intermediate channel and then the host.
155 * @return host-interrupt-line to which a system event is mapped.
156 * @return -1 for no mapping found
157 */
158 short prussdrv_get_event_to_host_map( unsigned int eventnum );
126 159
127 int prussdrv_map_l3mem(void **address); 160 int prussdrv_map_l3mem(void **address);
128 161
129 int prussdrv_map_extmem(void **address); 162 int prussdrv_map_extmem(void **address);
130 163
164 unsigned int prussdrv_extmem_size(void);
165
131 int prussdrv_map_prumem(unsigned int pru_ram_id, void **address); 166 int prussdrv_map_prumem(unsigned int pru_ram_id, void **address);
132 167
133 int prussdrv_map_peripheral_io(unsigned int per_id, void **address); 168 int prussdrv_map_peripheral_io(unsigned int per_id, void **address);
134 169
135 unsigned int prussdrv_get_phys_addr(void *address); 170 unsigned int prussdrv_get_phys_addr(const void *address);
136 171
137 void *prussdrv_get_virt_addr(unsigned int phyaddr); 172 void *prussdrv_get_virt_addr(unsigned int phyaddr);
138 173
139 int prussdrv_pru_wait_event(unsigned int pru_evtout_num); 174 /** Wait for the specified host interrupt.
175 * @return the number of times the event has happened. */
176 unsigned int prussdrv_pru_wait_event(unsigned int host_interrupt);
177
178 int prussdrv_pru_event_fd(unsigned int host_interrupt);
140 179
141 int prussdrv_pru_send_event(unsigned int eventnum); 180 int prussdrv_pru_send_event(unsigned int eventnum);
142 181
143 int prussdrv_pru_clear_event(unsigned int eventnum); 182 /** Clear the specified event and re-enable the host interrupt. */
183 int prussdrv_pru_clear_event(unsigned int host_interrupt,
184 unsigned int sysevent);
144 185
145 int prussdrv_pru_send_wait_clear_event(unsigned int send_eventnum, 186 int prussdrv_pru_send_wait_clear_event(unsigned int send_eventnum,
146 unsigned int pru_evtout_num, 187 unsigned int host_interrupt,
147 unsigned int ack_eventnum); 188 unsigned int ack_eventnum);
148 189
149 int prussdrv_exit(void); 190 int prussdrv_exit(void);
150 191
151 int prussdrv_exec_program(int prunum, char *filename); 192 int prussdrv_exec_program(int prunum, const char *filename);
152 193 int prussdrv_exec_program_at(int prunum, const char *filename, size_t addr);
153 int prussdrv_start_irqthread(unsigned int pru_evtout_num, int priority, 194
154 prussdrv_function_handler irqhandler); 195 int prussdrv_exec_code(int prunum, const unsigned int *code, int codelen);
155 196 int prussdrv_exec_code_at(int prunum, const unsigned int *code, int codelen, size_t addr);
197 int prussdrv_load_data(int prunum, const unsigned int *code, int codelen);
198 int prussdrv_load_datafile(int prunum, const char *filename);
156 199
157 #if defined (__cplusplus) 200 #if defined (__cplusplus)
158 } 201 }
159 #endif 202 #endif
160 #endif 203 #endif