summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ao.h76
-rw-r--r--src/core/ao_panic.c2
-rw-r--r--src/core/ao_pins.h408
-rw-r--r--src/core/ao_task.c60
4 files changed, 25 insertions, 521 deletions
diff --git a/src/core/ao.h b/src/core/ao.h
index 0f1a24ad..9b0bb545 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -22,21 +22,16 @@
#include <stdio.h>
#include <string.h>
#include <stddef.h>
-#include <ao_arch.h>
#include "ao_pins.h"
+#include <ao_arch.h>
#define TRUE 1
#define FALSE 0
/* Convert a __data pointer into an __xdata pointer */
-#define DATA_TO_XDATA(a) ((void __xdata *) ((uint8_t) (a) | 0xff00))
-
-/* Stack runs from above the allocated __data space to 0xfe, which avoids
- * writing to 0xff as that triggers the stack overflow indicator
- */
-#define AO_STACK_START 0x90
-#define AO_STACK_END 0xfe
-#define AO_STACK_SIZE (AO_STACK_END - AO_STACK_START + 1)
+#ifndef DATA_TO_XDATA
+#define DATA_TO_XDATA(a) (a)
+#endif
/* An AltOS task */
struct ao_task {
@@ -75,7 +70,7 @@ ao_alarm(uint16_t delay);
/* Yield the processor to another task */
void
-ao_yield(void) __naked;
+ao_yield(void) ao_arch_naked_declare;
/* Add a task to the run queue */
void
@@ -136,7 +131,7 @@ ao_timer_set_adc_interval(uint8_t interval) __critical;
/* Timer interrupt */
void
-ao_timer_isr(void) __interrupt 9;
+ao_timer_isr(void) ao_arch_interrupt(9);
/* Initialize the timer */
void
@@ -159,20 +154,8 @@ struct ao_adc {
int16_t sense_m; /* main continuity sense */
};
-#ifndef HAS_ADC
-#error Please define HAS_ADC
-#endif
-
#if HAS_ADC
-#if HAS_ACCEL
-#ifndef HAS_ACCEL_REF
-#error Please define HAS_ACCEL_REF
-#endif
-#else
-#define HAS_ACCEL_REF 0
-#endif
-
/*
* ao_adc.c
*/
@@ -207,7 +190,7 @@ ao_adc_get(__xdata struct ao_adc *packet);
/* The A/D interrupt handler */
void
-ao_adc_isr(void) __interrupt 1;
+ao_adc_isr(void) ao_arch_interrupt(1);
/* Initialize the A/D converter */
void
@@ -299,25 +282,6 @@ void
ao_led_init(uint8_t enable);
/*
- * ao_romconfig.c
- */
-
-#define AO_ROMCONFIG_VERSION 2
-
-extern __code __at (0x00a0) uint16_t ao_romconfig_version;
-extern __code __at (0x00a2) uint16_t ao_romconfig_check;
-extern __code __at (0x00a4) uint16_t ao_serial_number;
-extern __code __at (0x00a6) uint32_t ao_radio_cal;
-
-#ifndef HAS_USB
-#error Please define HAS_USB
-#endif
-
-#if HAS_USB
-extern __code __at (0x00aa) uint8_t ao_usb_descriptors [];
-#endif
-
-/*
* ao_usb.c
*/
@@ -342,7 +306,7 @@ ao_usb_flush(void);
#if HAS_USB
/* USB interrupt handler */
void
-ao_usb_isr(void) __interrupt 6;
+ao_usb_isr(void) ao_arch_interrupt(6);
#endif
/* Enable the USB controller */
@@ -446,7 +410,7 @@ ao_dma_abort(uint8_t id);
/* DMA interrupt routine */
void
-ao_dma_isr(void) __interrupt 8;
+ao_dma_isr(void) ao_arch_interrupt(8);
/*
* ao_mutex.c
@@ -927,10 +891,10 @@ ao_dbg_init(void);
#endif
void
-ao_serial_rx1_isr(void) __interrupt 3;
+ao_serial_rx1_isr(void) ao_arch_interrupt(3);
void
-ao_serial_tx1_isr(void) __interrupt 14;
+ao_serial_tx1_isr(void) ao_arch_interrupt(14);
char
ao_serial_getchar(void) __critical;
@@ -1251,14 +1215,6 @@ struct ao_telemetry_tiny {
char callsign[AO_MAX_CALLSIGN];
};
-/*
- * ao_radio_recv tacks on rssi and status bytes
- */
-
-struct ao_telemetry_raw_recv {
- uint8_t packet[AO_MAX_TELEMETRY + 2];
-};
-
struct ao_telemetry_orig_recv {
struct ao_telemetry_orig telemetry_orig;
int8_t rssi;
@@ -1271,6 +1227,14 @@ struct ao_telemetry_tiny_recv {
uint8_t status;
};
+/*
+ * ao_radio_recv tacks on rssi and status bytes
+ */
+
+struct ao_telemetry_raw_recv {
+ uint8_t packet[AO_MAX_TELEMETRY + 2];
+};
+
/* Set delay between telemetry reports (0 to disable) */
#define AO_TELEMETRY_INTERVAL_PAD AO_MS_TO_TICKS(1000)
@@ -1302,7 +1266,7 @@ extern __xdata uint8_t ao_radio_done;
extern __xdata uint8_t ao_radio_mutex;
void
-ao_radio_general_isr(void) __interrupt 16;
+ao_radio_general_isr(void) ao_arch_interrupt(16);
void
ao_radio_get(uint8_t len);
diff --git a/src/core/ao_panic.c b/src/core/ao_panic.c
index fdada201..cbfdf399 100644
--- a/src/core/ao_panic.c
+++ b/src/core/ao_panic.c
@@ -33,7 +33,7 @@ ao_panic_delay(uint8_t n)
while (n--)
while (--j)
while (--i)
- _asm nop _endasm;
+ ao_arch_nop();
}
void
diff --git a/src/core/ao_pins.h b/src/core/ao_pins.h
deleted file mode 100644
index e1f5459f..00000000
--- a/src/core/ao_pins.h
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * Copyright © 2010 Keith Packard <keithp@keithp.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-#ifndef _AO_PINS_H_
-#define _AO_PINS_H_
-
-#if defined(TELEMETRUM_V_1_0)
- #define HAS_FLIGHT 1
- #define HAS_USB 1
- #define HAS_BEEP 1
- #define HAS_GPS 1
- #define HAS_SERIAL_1 1
- #define HAS_ADC 1
- #define USE_SERIAL_STDIN 0
- #define HAS_EEPROM 1
- #define USE_INTERNAL_FLASH 0
- #define HAS_DBG 1
- #define DBG_ON_P1 1
- #define DBG_ON_P0 0
- #define IGNITE_ON_P2 1
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 0
- #define PACKET_HAS_SLAVE 1
-
- #define HAS_COMPANION 1
- #define COMPANION_CS_ON_P1 1
- #define COMPANION_CS_MASK 0x4 /* CS1 is P1_2 */
- #define COMPANION_CS P1_2
-
- #define AO_LED_RED 1
- #define LEDS_AVAILABLE (AO_LED_RED)
- #define HAS_EXTERNAL_TEMP 0
- #define HAS_ACCEL_REF 0
- #define HAS_ACCEL 1
- #define HAS_IGNITE 1
- #define HAS_MONITOR 0
-#endif
-
-#if defined(TELEMETRUM_V_1_1)
- #define HAS_FLIGHT 1
- #define HAS_USB 1
- #define HAS_BEEP 1
- #define HAS_GPS 1
- #define HAS_SERIAL_1 1
- #define USE_SERIAL_STDIN 0
- #define HAS_ADC 1
- #define HAS_EEPROM 1
- #define USE_INTERNAL_FLASH 0
- #define HAS_DBG 1
- #define DBG_ON_P1 1
- #define DBG_ON_P0 0
- #define IGNITE_ON_P2 1
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 0
- #define PACKET_HAS_SLAVE 1
-
- #define HAS_COMPANION 1
- #define COMPANION_CS_ON_P1 1
- #define COMPANION_CS_MASK 0x4 /* CS1 is P1_2 */
- #define COMPANION_CS P1_2
-
- #define AO_LED_RED 1
- #define LEDS_AVAILABLE (AO_LED_RED)
- #define HAS_EXTERNAL_TEMP 0
- #define HAS_ACCEL_REF 1
- #define SPI_CS_ON_P1 1
- #define SPI_CS_ON_P0 0
- #define M25_CS_MASK 0x02 /* CS0 is P1_1 */
- #define M25_MAX_CHIPS 1
- #define HAS_ACCEL 1
- #define HAS_IGNITE 1
- #define HAS_MONITOR 0
-#endif
-
-#if defined(TELEDONGLE_V_0_2)
- #define HAS_FLIGHT 0
- #define HAS_USB 1
- #define HAS_BEEP 0
- #define HAS_SERIAL_1 0
- #define USE_SERIAL_STDIN 0
- #define HAS_ADC 0
- #define HAS_DBG 1
- #define HAS_EEPROM 0
- #define DBG_ON_P1 1
- #define DBG_ON_P0 0
- #define IGNITE_ON_P2 0
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 1
- #define PACKET_HAS_SLAVE 0
- #define AO_LED_RED 1
- #define AO_LED_GREEN 2
- #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
- #define SPI_CS_ON_P1 1
- #define SPI_CS_ON_P0 0
- #define HAS_IGNITE 0
- #define HAS_MONITOR 1
-#endif
-
-#if defined(TELEMINI_V_1_0)
- #define HAS_FLIGHT 1
- #define HAS_USB 0
- #define HAS_BEEP 0
- #define HAS_GPS 0
- #define HAS_SERIAL_1 0
- #define USE_SERIAL_STDIN 0
- #define HAS_ADC 1
- #define HAS_EEPROM 1
- #define USE_INTERNAL_FLASH 1
- #define HAS_DBG 0
- #define IGNITE_ON_P2 0
- #define IGNITE_ON_P0 1
- #define PACKET_HAS_MASTER 0
- #define PACKET_HAS_SLAVE 1
- #define USE_FAST_ASCENT_LOG 1
-
- #define AO_LED_GREEN 1
- #define AO_LED_RED 2
- #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
- #define HAS_EXTERNAL_TEMP 0
- #define HAS_ACCEL 0
- #define HAS_IGNITE 1
- #define HAS_MONITOR 0
-#endif
-
-#if defined(TELENANO_V_0_1)
- #define HAS_FLIGHT 1
- #define HAS_USB 0
- #define HAS_BEEP 0
- #define HAS_GPS 0
- #define HAS_SERIAL_1 0
- #define USE_SERIAL_STDIN 0
- #define HAS_ADC 1
- #define HAS_EEPROM 1
- #define USE_INTERNAL_FLASH 1
- #define HAS_DBG 0
- #define IGNITE_ON_P2 0
- #define IGNITE_ON_P0 1
- #define PACKET_HAS_MASTER 0
- #define PACKET_HAS_SLAVE 1
-
- #define AO_LED_GREEN 1
- #define AO_LED_RED 2
- #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
- #define HAS_EXTERNAL_TEMP 0
- #define HAS_ACCEL 0
- #define HAS_IGNITE 0
- #define HAS_MONITOR 0
-#endif
-
-#if defined(TELEMETRUM_V_0_1)
- #define HAS_FLIGHT 1
- #define HAS_USB 1
- #define HAS_BEEP 1
- #define HAS_GPS 1
- #define HAS_SERIAL_1 1
- #define USE_SERIAL_STDIN 0
- #define HAS_ADC 1
- #define HAS_DBG 0
- #define HAS_EEPROM 1
- #define USE_INTERNAL_FLASH 0
- #define DBG_ON_P1 0
- #define DBG_ON_P0 1
- #define IGNITE_ON_P2 1
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 0
- #define PACKET_HAS_SLAVE 1
- #define AO_LED_RED 2
- #define AO_LED_GREEN 1
- #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
- #define HAS_EXTERNAL_TEMP 1
- #define HAS_ACCEL_REF 0
- #define SPI_CS_ON_P1 1
- #define SPI_CS_ON_P0 0
- #define HAS_ACCEL 1
- #define HAS_IGNITE 1
- #define HAS_MONITOR 0
-#endif
-
-#if defined(TELEDONGLE_V_0_1)
- #define HAS_FLIGHT 0
- #define HAS_USB 1
- #define HAS_BEEP 0
- #define HAS_SERIAL_1 0
- #define USE_SERIAL_STDIN 0
- #define HAS_ADC 0
- #define HAS_DBG 0
- #define HAS_EEPROM 0
- #define DBG_ON_P1 0
- #define DBG_ON_P0 1
- #define IGNITE_ON_P2 0
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 1
- #define PACKET_HAS_SLAVE 0
- #define AO_LED_RED 2
- #define AO_LED_GREEN 1
- #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
- #define SPI_CS_ON_P1 0
- #define SPI_CS_ON_P0 1
- #define HAS_IGNITE 0
- #define HAS_MONITOR 1
-#endif
-
-#if defined(TIDONGLE)
- #define HAS_FLIGHT 0
- #define HAS_USB 1
- #define HAS_BEEP 0
- #define HAS_SERIAL_1 0
- #define USE_SERIAL_STDIN 0
- #define HAS_ADC 0
- #define HAS_DBG 1
- #define HAS_EEPROM 0
- #define DBG_ON_P1 0
- #define DBG_ON_P0 1
- #define IGNITE_ON_P2 0
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 1
- #define PACKET_HAS_SLAVE 0
- #define AO_LED_RED 2
- #define LEDS_AVAILABLE (AO_LED_RED)
- #define SPI_CS_ON_P1 0
- #define SPI_CS_ON_P0 1
- #define HAS_IGNITE 0
- #define HAS_MONITOR 1
-#endif
-
-#if defined(TELEBT_V_0_0)
- #define HAS_FLIGHT 0
- #define HAS_USB 1
- #define HAS_BEEP 0
- #define HAS_SERIAL_1 1
- #define USE_SERIAL_STDIN 1
- #define HAS_ADC 0
- #define HAS_DBG 1
- #define HAS_EEPROM 0
- #define HAS_BTM 1
- #define DBG_ON_P1 0
- #define DBG_ON_P0 1
- #define IGNITE_ON_P2 0
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 1
- #define PACKET_HAS_SLAVE 0
- #define AO_LED_RED 2
- #define AO_LED_GREEN 1
- #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
- #define SPI_CS_ON_P1 1
- #define SPI_CS_ON_P0 0
- #define HAS_IGNITE 0
- #define BT_LINK_ON_P2 1
- #define BT_LINK_ON_P1 0
- #define BT_LINK_PIN_INDEX 7
- #define BT_LINK_PIN P2_1
- #define HAS_MONITOR 1
-#endif
-
-#if defined(TELEBT_V_0_1)
- #define HAS_FLIGHT 0
- #define HAS_USB 1
- #define HAS_BEEP 1
- #define HAS_SERIAL_1 1
- #define HAS_SERIAL_1_ALT_1 1
- #define HAS_SERIAL_1_ALT_2 0
- #define HAS_SERIAL_1_HW_FLOW 1
- #define USE_SERIAL_STDIN 1
- #define HAS_ADC 0
- #define HAS_DBG 1
- #define HAS_EEPROM 1
- #define USE_INTERNAL_FLASH 0
- #define HAS_BTM 1
- #define DBG_ON_P1 1
- #define DBG_ON_P0 0
- #define IGNITE_ON_P2 0
- #define IGNITE_ON_P0 0
- #define PACKET_HAS_MASTER 1
- #define PACKET_HAS_SLAVE 0
- #define AO_LED_RED 1
- #define AO_LED_GREEN 2
- #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
- #define SPI_CS_ON_P1 1
- #define SPI_CS_ON_P0 0
- #define M25_CS_MASK 0x04 /* CS0 is P1_2 */
- #define M25_MAX_CHIPS 1
- #define HAS_ACCEL 0
- #define HAS_IGNITE 0
- #define BT_LINK_ON_P2 0
- #define BT_LINK_ON_P1 1
- #define BT_LINK_PIN_INDEX 7
- #define BT_LINK_PIN P1_7
- #define HAS_MONITOR 1
-#endif
-
-#if DBG_ON_P1
-
- #define DBG_CLOCK (1 << 4) /* mi0 */
- #define DBG_DATA (1 << 5) /* mo0 */
- #define DBG_RESET_N (1 << 3) /* c0 */
-
- #define DBG_CLOCK_PIN (P1_4)
- #define DBG_DATA_PIN (P1_5)
- #define DBG_RESET_N_PIN (P1_3)
-
- #define DBG_PORT_NUM 1
- #define DBG_PORT P1
- #define DBG_PORT_SEL P1SEL
- #define DBG_PORT_INP P1INP
- #define DBG_PORT_DIR P1DIR
-
-#endif /* DBG_ON_P1 */
-
-#if DBG_ON_P0
-
- #define DBG_CLOCK (1 << 3)
- #define DBG_DATA (1 << 4)
- #define DBG_RESET_N (1 << 5)
-
- #define DBG_CLOCK_PIN (P0_3)
- #define DBG_DATA_PIN (P0_4)
- #define DBG_RESET_N_PIN (P0_5)
-
- #define DBG_PORT_NUM 0
- #define DBG_PORT P0
- #define DBG_PORT_SEL P0SEL
- #define DBG_PORT_INP P0INP
- #define DBG_PORT_DIR P0DIR
-
-#endif /* DBG_ON_P0 */
-
-#if COMPANION_CS_ON_P1
- #define COMPANION_CS_PORT P1
- #define COMPANION_CS_SEL P1SEL
- #define COMPANION_CS_DIR P1DIR
-#endif
-
-#if SPI_CS_ON_P1
- #define SPI_CS_PORT P1
- #define SPI_CS_SEL P1SEL
- #define SPI_CS_DIR P1DIR
-#endif
-
-#if SPI_CS_ON_P0
- #define SPI_CS_PORT P0
- #define SPI_CS_SEL P0SEL
- #define SPI_CS_DIR P0DIR
-#endif
-
-#ifndef IGNITE_ON_P2
-#error Please define IGNITE_ON_P2
-#endif
-
-#ifndef IGNITE_ON_P0
-#error Please define IGNITE_ON_P0
-#endif
-
-#ifndef HAS_SERIAL_1
-#error Please define HAS_SERIAL_1
-#endif
-
-#ifndef USE_SERIAL_STDIN
-#error Please define USE_SERIAL_STDIN
-#endif
-
-#ifndef HAS_ADC
-#error Please define HAS_ADC
-#endif
-
-#ifndef HAS_EEPROM
-#error Please define HAS_EEPROM
-#endif
-
-#if HAS_EEPROM
-#ifndef USE_INTERNAL_FLASH
-#error Please define USE_INTERNAL_FLASH
-#endif
-#endif
-
-#ifndef HAS_DBG
-#error Please define HAS_DBG
-#endif
-
-#ifndef HAS_IGNITE
-#error Please define HAS_IGNITE
-#endif
-
-#ifndef PACKET_HAS_MASTER
-#error Please define PACKET_HAS_MASTER
-#endif
-
-#ifndef PACKET_HAS_SLAVE
-#error Please define PACKET_HAS_SLAVE
-#endif
-
-#ifndef HAS_MONITOR
-#error Please define HAS_MONITOR
-#endif
-#endif /* _AO_PINS_H_ */
diff --git a/src/core/ao_task.c b/src/core/ao_task.c
index f5850fa4..41520476 100644
--- a/src/core/ao_task.c
+++ b/src/core/ao_task.c
@@ -27,7 +27,6 @@ __xdata struct ao_task *__data ao_cur_task;
void
ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant
{
- uint8_t __xdata *stack;
uint8_t task_id;
uint8_t t;
if (ao_num_tasks == AO_NUM_TASKS)
@@ -42,70 +41,19 @@ ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *nam
ao_tasks[ao_num_tasks++] = task;
task->task_id = task_id;
task->name = name;
+ task->wchan = NULL;
/*
* Construct a stack frame so that it will 'return'
* to the start of the task
*/
- stack = task->stack;
-
- *stack++ = ((uint16_t) start); /* 0 */
- *stack++ = ((uint16_t) start) >> 8; /* 1 */
-
- /* and the stuff saved by ao_switch */
- *stack++ = 0; /* 2 acc */
- *stack++ = 0x80; /* 3 IE */
-
- /* 4 DPL
- * 5 DPH
- * 6 B
- * 7 R2
- * 8 R3
- * 9 R4
- * 10 R5
- * 11 R6
- * 12 R7
- * 13 R0
- * 14 R1
- * 15 PSW
- * 16 BP
- */
- for (t = 0; t < 13; t++)
- *stack++ = 0;
-
- task->stack_count = 17;
- task->wchan = NULL;
+ ao_arch_init_stack(task, start);
}
/* Task switching function. This must not use any stack variables */
void
-ao_yield(void) __naked
+ao_yield(void) ao_arch_naked_define
{
-
- /* Save current context */
- _asm
- /* Push ACC first, as when restoring the context it must be restored
- * last (it is used to set the IE register). */
- push ACC
- /* Store the IE register then enable interrupts. */
- push _IEN0
- setb _EA
- push DPL
- push DPH
- push b
- push ar2
- push ar3
- push ar4
- push ar5
- push ar6
- push ar7
- push ar0
- push ar1
- push PSW
- _endasm;
- PSW = 0;
- _asm
- push _bp
- _endasm;
+ ao_arch_save_context();
if (ao_cur_task_index == AO_NO_TASK_INDEX)
ao_cur_task_index = ao_num_tasks-1;