PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
propeller.h
Go to the documentation of this file.
1 
9 #ifndef _PROPELLER_H_
10 #define _PROPELLER_H_
11 
12 #include "cog.h"
13 #include <stdint.h>
14 #include <string.h>
15 #include <sys/thread.h>
16 
17 #ifdef __PROPELLER2__
18 #include "propeller2.h"
19 #else
20 #include "propeller1.h"
21 #endif
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27 
32 #define HUBDATA __attribute__((section(".hub")))
33 
43 #define HUBTEXT __attribute__((section(".hubtext")))
44 
46 #define CLKFREQ _CLKFREQ
47 
49 #define CLKMODE _CLKMODE
50 
63 #define clkset(mode, frequency) \
64 do { \
65  _CLKFREQ = (frequency); \
66  _CLKMODE = (mode); \
67  __builtin_propeller_clkset(mode); \
68 } while(0)
69 
76 #define cogid() __builtin_propeller_cogid()
77 
94 #define cognew(code, param) coginit(0x8, (code), (param))
95 
100 #define cogstop(a) __builtin_propeller_cogstop((a))
101 
102 /* in xmm mode we need space for a cache for the new xmm cog */
103 /* the code in cogthread.c currently creates a 1K stack with 32 lines of 32 bytes */
104 
108 #ifndef EXTRA_STACK_BYTES
109  #ifdef __PROPELLER_USE_XMM__
110  #define EXTRA_STACK_BYTES (1024 + 128 + 16 + 16 + sizeof(_thread_state_t))
111  #else
112  #define EXTRA_STACK_BYTES (16 + sizeof(_thread_state_t))
113  #endif
114 #endif
115 
119 #ifndef EXTRA_STACK_LONGS
120  #define EXTRA_STACK_LONGS (EXTRA_STACK_BYTES / 4)
121 #endif
122 
139 int cogstart(void (*func)(void *), void *par, void *stack, size_t stacksize);
140 
147 #define locknew() __builtin_propeller_locknew()
148 
155 #define lockret(lockid) __builtin_propeller_lockret((lockid))
156 
163 #define lockset(lockid) __builtin_propeller_lockset((lockid))
164 
170 #define lockclr(lockid) __builtin_propeller_lockclr((lockid))
171 
176 #define waitcnt(a) __builtin_propeller_waitcnt((a),0)
177 
183 #define waitcnt2(a,b) __builtin_propeller_waitcnt((a),(b))
184 
190 #define waitpeq(state, mask) __builtin_propeller_waitpeq((state), (mask))
191 
197 #define waitpne(state, mask) __builtin_propeller_waitpne((state), (mask))
198 
205 #define waitvid(colors, pixels) __builtin_propeller_waitvid((colors), (pixels))
206 
207 /*
208  * Most of these are only used for __PROPELLER_XMM__
209  */
210 #if defined(__PROPELLER_USE_XMM__)
211 
230 static __inline__ void copy_from_xmm(uint32_t *dst, uint32_t *src, int count)
231 {
232  memcpy(dst, src, count*4);
233 }
234 
240 static __inline__ uint32_t rdlong_xmm(uint32_t *addr)
241 {
242  uint32_t value;
243  __asm__ volatile (
244  "xmmio rdlong,%[_value],%[_addr]"
245  : /* outputs */
246  [_value] "=r" (value)
247  : /* inputs */
248  [_addr] "r" (addr)
249  : /* no clobbered registers */
250  );
251  return value;
252 }
253 
259 static __inline__ void wrlong_xmm(uint32_t *addr, uint32_t value)
260 {
261  __asm__ volatile (
262  "xmmio wrlong,%[_value],%[_addr]"
263  : /* no outputs */
264  : /* inputs */
265  [_addr] "r" (addr),
266  [_value] "r" (value)
267  : /* no clobbered registers */
268  );
269 }
270 
275 void kernel_use_lock(uint32_t lockId);
276 
277 #endif
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 
283 #if defined(__PROPELLER_USE_XMM__)
284 
289 #define use_cog_driver(id) extern uint32_t binary_##id##_dat_start[], binary_##id##_dat_end[]
290 
295 #define get_cog_driver(id) \
296  get_cog_driver_xmm( \
297  binary_##id##_dat_start, \
298  binary_##id##_dat_end - binary_##id##_dat_start)
299 
306 #define load_cog_driver(id, param) \
307  load_cog_driver_xmm( \
308  binary_##id##_dat_start, \
309  binary_##id##_dat_end - binary_##id##_dat_start, \
310  (uint32_t *)(param))
311 
312 uint32_t *get_cog_driver_xmm(uint32_t *code, uint32_t codelen);
313 int load_cog_driver_xmm(uint32_t *code, uint32_t codelen, uint32_t *params);
314 
315 #else
316 
321 #define use_cog_driver(id) extern uint32_t binary_##id##_dat_start[]
322 
327 #define get_cog_driver(id) (binary_##id##_dat_start) \
328 
329 
335 #define load_cog_driver(id, param) cognew(binary_##id##_dat_start, (uint32_t *)(param))
336 
337 #endif
338 
339 #endif
340 // _PROPELLER_H_
propeller1.h
Provides Propeller 1 specific functions.
cog.h
Inludes common API definitions for COG programming.
count
long count(int pin, long duration)
Count number of low to high transitions an external input applies to an I/O pin over a certain period...
Definition: count.c:19
propeller2.h
Provides Propeller 2 specific functions.
cogstart
int cogstart(void(*func)(void *), void *par, void *stack, size_t stacksize)
Start a new propeller LMM function/thread in another COG.