2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 * CC1111 definitions and code fragments for AltOS
27 /* Convert a __data pointer into an __xdata pointer */
28 #define DATA_TO_XDATA(a) ((void __xdata *) ((uint8_t) (a) | 0xff00))
30 /* Code and xdata use the same address space */
31 #define CODE_TO_XDATA(a) ((__xdata void *) ((uint16_t) (a)))
33 /* Pdata lives at the start of xdata */
34 #define PDATA_TO_XDATA(a) ((void __xdata *) ((uint8_t) (a) | 0xf000))
36 /* Stack runs from above the allocated __data space to 0xfe, which avoids
37 * writing to 0xff as that triggers the stack overflow indicator
39 #define AO_STACK_START 0x90
40 #define AO_STACK_END 0xfe
41 #define AO_STACK_SIZE (AO_STACK_END - AO_STACK_START + 1)
43 #define ao_arch_reboot() do { \
44 WDCTL = WDCTL_EN | WDCTL_MODE_WATCHDOG | WDCTL_INT_64; \
45 ao_delay(AO_SEC_TO_TICKS(2)); \
48 #define ao_arch_nop() __asm nop __endasm
49 #define ao_arch_interrupt(n) __interrupt n
51 #define ao_arch_naked_declare __naked
52 #define ao_arch_naked_define __naked
54 /* CC1111-specific drivers */
60 #define AO_ROMCONFIG_VERSION 2
62 extern __code __at (0x00a0) uint16_t ao_romconfig_version;
63 extern __code __at (0x00a2) uint16_t ao_romconfig_check;
64 extern __code __at (0x00a4) uint16_t ao_serial_number;
65 extern __code __at (0x00a6) uint32_t ao_radio_cal;
68 #error Please define HAS_USB
71 #define ao_arch_task_members\
72 uint8_t stack_count; /* amount of saved stack */
74 /* Initialize stack */
75 #define ao_arch_init_stack(task, start) { \
76 uint8_t __xdata *stack = task->stack; \
78 *stack++ = ((uint16_t) start); /* 0 */ \
79 *stack++ = ((uint16_t) start) >> 8; /* 1 */ \
81 /* and the stuff saved by ao_switch */ \
82 *stack++ = 0; /* 2 acc */ \
83 *stack++ = 0x80; /* 3 IE */ \
99 for (t = 0; t < 13; t++) \
101 task->stack_count = 17; \
106 /* Save current context */
108 #define ao_arch_save_regs() \
110 /* Push ACC first, as when restoring the context it must be restored \
111 * last (it is used to set the IE register). */ \
113 /* Store the IE register then enable interrupts. */ \
134 #define ao_arch_save_stack() { \
136 __data uint8_t *stack_ptr; \
137 __xdata uint8_t *save_ptr; \
138 /* Save the current stack */ \
139 stack_len = SP - (AO_STACK_START - 1); \
140 ao_cur_task->stack_count = stack_len; \
141 stack_ptr = (uint8_t __data *) AO_STACK_START; \
142 save_ptr = (uint8_t __xdata *) ao_cur_task->stack; \
144 *save_ptr++ = *stack_ptr++; \
145 while (--stack_len); \
148 #define ao_arch_isr_stack() \
149 /* Empty the stack; might as well let interrupts have the whole thing */ \
150 (SP = AO_STACK_START - 1)
152 #define ao_arch_cpu_idle() (PCON = PCON_IDLE)
154 #define ao_arch_restore_stack() { \
156 __data uint8_t *stack_ptr; \
157 __xdata uint8_t *save_ptr; \
159 /* Restore the old stack */ \
160 stack_len = ao_cur_task->stack_count; \
161 SP = AO_STACK_START - 1 + stack_len; \
163 stack_ptr = (uint8_t __data *) AO_STACK_START; \
164 save_ptr = (uint8_t __xdata *) ao_cur_task->stack; \
166 *stack_ptr++ = *save_ptr++; \
167 while (--stack_len); \
183 /* The next byte of the stack is the IE register. Only the global \
184 enable bit forms part of the task context. Pop off the IE then set \
185 the global enable bit to match that of the stored IE register. */ \
193 /* Finally pop off the ACC, which was the first register saved. */ \
199 #define ao_arch_critical(b) __critical { b }
202 int16_t accel; /* accelerometer */
203 int16_t pres; /* pressure sensor */
204 int16_t temp; /* temperature sensor */
205 int16_t v_batt; /* battery voltage */
206 int16_t sense_d; /* drogue continuity sense */
207 int16_t sense_m; /* main continuity sense */
209 int16_t accel_ref; /* acceleration reference */
213 #define AO_DATA_RING 32
218 ao_p0_isr(void) ao_arch_interrupt(13);
221 ao_p1_isr(void) ao_arch_interrupt(15);
231 ao_button_init(void);
234 ao_button_get(void) __critical;
237 ao_button_clear(void) __critical;
242 _ao_xmemcpy(__xdata void *dst, __xdata void *src, uint8_t count);
244 #define ao_xmemcpy(d,s,c) _ao_xmemcpy(d,s,c)
247 _ao_xmemset(__xdata void *dst, uint8_t value, uint8_t count);
249 #define ao_xmemset(d,v,c) _ao_xmemset(d,v,c)
252 _ao_xmemcmp(__xdata void *a, __xdata void *b, uint8_t count);
254 #define ao_xmemcmp(d,s,c) _ao_xmemcmp((d), (s), (c))
256 struct ao_serial_speed {
261 extern const __code struct ao_serial_speed ao_serial_speeds[];
267 /* Allocate a DMA channel. the 'done' parameter will be set when the
268 * dma is finished and will be used to wakeup any waiters
272 ao_dma_alloc(__xdata uint8_t * done);
274 /* Setup a DMA channel */
276 ao_dma_set_transfer(uint8_t id,
277 void __xdata *srcaddr,
278 void __xdata *dstaddr,
283 /* Start a DMA channel */
285 ao_dma_start(uint8_t id);
287 /* Manually trigger a DMA channel */
289 ao_dma_trigger(uint8_t id);
291 /* Abort a running DMA transfer */
293 ao_dma_abort(uint8_t id);
295 /* DMA interrupt routine */
297 ao_dma_isr(void) ao_arch_interrupt(8);
302 /* The A/D interrupt handler */
304 ao_adc_isr(void) ao_arch_interrupt(1);
308 /* USB interrupt handler */
310 ao_usb_isr(void) ao_arch_interrupt(6);
315 ao_serial0_rx_isr(void) ao_arch_interrupt(2);
318 ao_serial0_tx_isr(void) ao_arch_interrupt(7);
323 ao_serial1_rx_isr(void) ao_arch_interrupt(3);
326 ao_serial1_tx_isr(void) ao_arch_interrupt(14);
329 #endif /* _AO_ARCH_H_ */