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 /* Stack runs from above the allocated __data space to 0xfe, which avoids
31 * writing to 0xff as that triggers the stack overflow indicator
33 #define AO_STACK_START 0x90
34 #define AO_STACK_END 0xfe
35 #define AO_STACK_SIZE (AO_STACK_END - AO_STACK_START + 1)
37 #define ao_arch_reboot() do { \
38 WDCTL = WDCTL_EN | WDCTL_MODE_WATCHDOG | WDCTL_INT_64; \
39 ao_delay(AO_SEC_TO_TICKS(2)); \
42 #define ao_arch_nop() _asm nop _endasm
43 #define ao_arch_interrupt(n) __interrupt n
45 #define ao_arch_naked_declare __naked
46 #define ao_arch_naked_define __naked
48 /* CC1111-specific drivers */
54 #define AO_ROMCONFIG_VERSION 2
56 extern __code __at (0x00a0) uint16_t ao_romconfig_version;
57 extern __code __at (0x00a2) uint16_t ao_romconfig_check;
58 extern __code __at (0x00a4) uint16_t ao_serial_number;
59 extern __code __at (0x00a6) uint32_t ao_radio_cal;
62 #error Please define HAS_USB
65 #define ao_arch_task_members\
66 uint8_t stack_count; /* amount of saved stack */
68 /* Initialize stack */
69 #define ao_arch_init_stack(task, start) { \
70 uint8_t __xdata *stack = task->stack; \
72 *stack++ = ((uint16_t) start); /* 0 */ \
73 *stack++ = ((uint16_t) start) >> 8; /* 1 */ \
75 /* and the stuff saved by ao_switch */ \
76 *stack++ = 0; /* 2 acc */ \
77 *stack++ = 0x80; /* 3 IE */ \
93 for (t = 0; t < 13; t++) \
95 task->stack_count = 17; \
100 /* Save current context */
102 #define ao_arch_save_regs() \
104 /* Push ACC first, as when restoring the context it must be restored \
105 * last (it is used to set the IE register). */ \
107 /* Store the IE register then enable interrupts. */ \
128 #define ao_arch_save_stack() { \
130 __data uint8_t *stack_ptr; \
131 __xdata uint8_t *save_ptr; \
132 /* Save the current stack */ \
133 stack_len = SP - (AO_STACK_START - 1); \
134 ao_cur_task->stack_count = stack_len; \
135 stack_ptr = (uint8_t __data *) AO_STACK_START; \
136 save_ptr = (uint8_t __xdata *) ao_cur_task->stack; \
138 *save_ptr++ = *stack_ptr++; \
139 while (--stack_len); \
142 #define ao_arch_isr_stack() \
143 /* Empty the stack; might as well let interrupts have the whole thing */ \
144 (SP = AO_STACK_START - 1)
146 #define ao_arch_cpu_idle() (PCON = PCON_IDLE)
148 #define ao_arch_restore_stack() { \
150 __data uint8_t *stack_ptr; \
151 __xdata uint8_t *save_ptr; \
153 /* Restore the old stack */ \
154 stack_len = ao_cur_task->stack_count; \
155 SP = AO_STACK_START - 1 + stack_len; \
157 stack_ptr = (uint8_t __data *) AO_STACK_START; \
158 save_ptr = (uint8_t __xdata *) ao_cur_task->stack; \
160 *stack_ptr++ = *save_ptr++; \
161 while (--stack_len); \
177 /* The next byte of the stack is the IE register. Only the global \
178 enable bit forms part of the task context. Pop off the IE then set \
179 the global enable bit to match that of the stored IE register. */ \
187 /* Finally pop off the ACC, which was the first register saved. */ \
193 #define ao_arch_critical(b) __critical { b }
196 uint16_t tick; /* tick when the sample was read */
197 int16_t accel; /* accelerometer */
198 int16_t pres; /* pressure sensor */
199 int16_t temp; /* temperature sensor */
200 int16_t v_batt; /* battery voltage */
201 int16_t sense_d; /* drogue continuity sense */
202 int16_t sense_m; /* main continuity sense */
205 #define AO_ADC_RING 32
207 #endif /* _AO_ARCH_H_ */