Propeller Device Specific Functions and Registers  v0.5
Provides low level access to Propeller microcontroller functions and registers.
propeller.h
Go to the documentation of this file.
1 
9 #ifndef _PROPELLER_H_
10 #define _PROPELLER_H_
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 #include "cog.h"
18 #include <stdint.h>
19 #include <string.h>
20 
25 #define HUBDATA __attribute__((section(".hub")))
26 
36 #define HUBTEXT __attribute__((section(".hubtext")))
37 
39 #define PAR _PAR
40 
41 #define CNT _CNT
42 
43 #define INA _INA
44 
45 #define INB _INB
46 
47 #define OUTA _OUTA
48 
49 #define OUTB _OUTB
50 
51 #define DIRA _DIRA
52 
53 #define DIRB _DIRB
54 
55 #define CTRA _CTRA
56 
57 #define CTRB _CTRB
58 
59 #define FRQA _FRQA
60 
61 #define FRQB _FRQB
62 
63 #define PHSA _PHSA
64 
65 #define PHSB _PHSB
66 
67 #define VCFG _VCFG
68 
69 #define VSCL _VSCL
70 
72 #define CLKFREQ _CLKFREQ
73 
75 #define CLKMODE _CLKMODE
76 
89 #define clkset(mode, frequency) \
90 do { \
91  _CLKFREQ = (frequency); \
92  _CLKMODE = (mode); \
93  __builtin_propeller_clkset(mode); \
94 } while(0)
95 
102 #define cogid() __builtin_propeller_cogid()
103 
126 #define coginit(id, code, param) __builtin_propeller_coginit( \
127  (((uint32_t)(param) << 16) & 0xfffc0000) \
128  |(((uint32_t)(code) << 2) & 0x0003fff0) \
129  |(((id) ) & 0x0000000f) )
130 
147 #define cognew(code, param) coginit(0x8, (code), (param))
148 
153 #define cogstop(a) __builtin_propeller_cogstop((a))
154 
171 int cogstart(void (*func)(void *), void *par, void *stack, size_t stacksize);
172 
177 #define locknew() __builtin_propeller_locknew()
178 
183 #define lockret(lockid) __builtin_propeller_lockret((lockid))
184 
190 #define lockset(lockid) __builtin_propeller_lockset((lockid))
191 
196 #define lockclr(lockid) __builtin_propeller_lockclr((lockid))
197 
202 #define waitcnt(a) __builtin_propeller_waitcnt((a),0)
203 
209 #define waitcnt2(a,b) __builtin_propeller_waitcnt((a),(b))
210 
216 #define waitpeq(state, mask) __builtin_propeller_waitpeq((state), (mask))
217 
223 #define waitpne(state, mask) __builtin_propeller_waitpne((state), (mask))
224 
231 #define waitvid(colors, pixels) __builtin_propeller_waitvid((colors), (pixels))
232 
233 /*
234  * Most of these are only used for __PROPELLER_XMM__
235  */
236 #if defined(__PROPELLER_USE_XMM__)
237 
256 static __inline__ void copy_from_xmm(uint32_t *dst, uint32_t *src, int count)
257 {
258  memcpy(dst, src, count*4);
259 }
260 
266 static __inline__ uint32_t rdlong_xmm(uint32_t *addr)
267 {
268  uint32_t value;
269  __asm__ volatile (
270  "xmmio rdlong,%[_value],%[_addr]"
271  : /* outputs */
272  [_value] "=r" (value)
273  : /* inputs */
274  [_addr] "r" (addr)
275  : /* no clobbered registers */
276  );
277  return value;
278 }
279 
285 static __inline__ void wrlong_xmm(uint32_t *addr, uint32_t value)
286 {
287  __asm__ volatile (
288  "xmmio wrlong,%[_value],%[_addr]"
289  : /* no outputs */
290  : /* inputs */
291  [_addr] "r" (addr),
292  [_value] "r" (value)
293  : /* no clobbered registers */
294  );
295 }
296 
301 void kernel_use_lock(uint32_t lockId);
302 
303 #endif
304 
305 #if defined(__PROPELLER_USE_XMM__)
306 
311 #define use_cog_driver(id) extern uint32_t binary_##id##_dat_start[], binary_##id##_dat_end[]
312 
317 #define get_cog_driver(id) \
318  get_cog_driver_xmm( \
319  binary_##id##_dat_start, \
320  binary_##id##_dat_end - binary_##id##_dat_start)
321 
328 #define load_cog_driver(id, param) \
329  load_cog_driver_xmm( \
330  binary_##id##_dat_start, \
331  binary_##id##_dat_end - binary_##id##_dat_start, \
332  (uint32_t *)(param))
333 
334 uint32_t *get_cog_driver_xmm(uint32_t *code, uint32_t codelen);
335 int load_cog_driver_xmm(uint32_t *code, uint32_t codelen, uint32_t *params);
336 
337 #else
338 
343 #define use_cog_driver(id) extern uint32_t binary_##id##_dat_start[]
344 
349 #define get_cog_driver(id) (binary_##id##_dat_start) \
350 
351 
357 #define load_cog_driver(id, param) cognew(binary_##id##_dat_start, (uint32_t *)(param))
358 
359 #endif
360 
361 #ifdef __cplusplus
362 }
363 #endif
364 
365 #endif
366 // _PROPELLER_H_