PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
propeller2.h
Go to the documentation of this file.
1 
23 #ifndef _PROPELLER2_H_
24 #define _PROPELLER2_H_
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
41 static __inline__ int coginit(int id, void *image, void *par)
42 {
43  __asm__ volatile (
44  "setcog %[_id]\n\t"
45  "coginit %[_image], %[_par] wr,wc\n\t"
46  "if_c neg %[_image], #1"
47  : /* outputs */
48  [_image] "+r" (image)
49  : /* inputs */
50  [_id] "r" (id),
51  [_par] "r" (par)
52  : /* no clobbered registers */
53  );
54  return (uint32_t)image;
55 }
56 
65 static __inline__ uint32_t getcnt(void)
66 {
67  uint32_t value;
68  __asm__ volatile (
69  "getcnt %[_value]"
70  : /* outputs */
71  [_value] "=r" (value)
72  : /* no inputs */
73  : /* no clobbered registers */
74  );
75  return value;
76 }
77 
87 static __inline__ int getpin(int pin)
88 {
89  uint32_t value;
90  __asm__ volatile (
91  "getp %[_pin] wc\n\t"
92  "mov %[_value], #0\n\t"
93  "rcl %[_value], #1"
94  : /* outputs */
95  [_value] "=r" (value)
96  : /* inputs */
97  [_pin] "r" (pin)
98  : /* no clobbered registers */
99  );
100  return value;
101 }
102 
113 static __inline__ void setpin(int pin, int value)
114 {
115  __asm__ volatile (
116  "rcr %[_value], #1 wc,nr\n\t"
117  "setpc %[_pin]"
118  : /* outputs */
119  "=r" (value)
120  : /* inputs */
121  [_pin]"r" (pin),
122  [_value] "0" (value)
123  : /* no clobbered registers */
124  );
125 }
126 
137 static __inline__ void togglepin(int pin)
138 {
139  __asm__ volatile (
140  "notp %[_pin]"
141  : /* no outputs */
142  : /* inputs */
143  [_pin] "r" (pin)
144  : /* no clobbered registers */
145  );
146 }
147 
155 #define PINA _PINA
157 #define PINB _PINB
159 #define PINC _PINC
161 #define PIND _PIND
163 
170 #define DIRA _DIRA
172 #define DIRB _DIRB
174 #define DIRC _DIRC
176 #define DIRD _DIRD
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif
184 // _PROPELLER2_H_
getcnt
static __inline__ uint32_t getcnt(void)
CNT register accessor.
Definition: propeller2.h:65
getpin
static __inline__ int getpin(int pin)
getpin accessor used to read the state of a pin.
Definition: propeller2.h:87
setpin
static __inline__ void setpin(int pin, int value)
setpin accessor used to write the state of a pin.
Definition: propeller2.h:113
togglepin
static __inline__ void togglepin(int pin)
togglepin accessor used to toggle the state of a pin.
Definition: propeller2.h:137
coginit
static __inline__ int coginit(int id, void *image, void *par)
Start a cog with a parameter.
Definition: propeller2.h:41