summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-05-23 02:17:51 -0600
committerKeith Packard <keithp@keithp.com>2013-08-25 22:24:01 -0700
commit56911f27376b0fe91a464e369bb8aa1531b3c7dc (patch)
treeb525a8f527917355b758a1812692fd4a84578f7f /src/core
parentcb844328322fd7d9f4dafb58b322257a70b347e6 (diff)
altos: Make TeleMini v2.0 fit
Mash lots of storage locations and code around to shrink stuff down to size Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ao.h2
-rw-r--r--src/core/ao_cmd.c4
-rw-r--r--src/core/ao_int64.c88
-rw-r--r--src/core/ao_int64.h22
-rw-r--r--src/core/ao_kalman.c4
-rw-r--r--src/core/ao_log_telem.c2
-rw-r--r--src/core/ao_sample.h4
-rw-r--r--src/core/ao_task.h3
8 files changed, 67 insertions, 62 deletions
diff --git a/src/core/ao.h b/src/core/ao.h
index caa0ec19..e7320327 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -182,7 +182,7 @@ void
ao_cmd_hex(void);
void
-ao_cmd_decimal(void);
+ao_cmd_decimal(void) __reentrant;
/* Read a single hex nibble off stdin. */
uint8_t
diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c
index 5113548b..4ebaa607 100644
--- a/src/core/ao_cmd.c
+++ b/src/core/ao_cmd.c
@@ -206,9 +206,9 @@ ao_cmd_hex(void)
}
void
-ao_cmd_decimal(void)
+ao_cmd_decimal(void) __reentrant
{
- __pdata uint8_t r = ao_cmd_lex_error;
+ uint8_t r = ao_cmd_lex_error;
ao_cmd_lex_u32 = 0;
ao_cmd_white();
diff --git a/src/core/ao_int64.c b/src/core/ao_int64.c
index 07cdb357..aa23dbe0 100644
--- a/src/core/ao_int64.c
+++ b/src/core/ao_int64.c
@@ -17,8 +17,10 @@
#include <ao_int64.h>
-void ao_plus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
- uint32_t t;
+__pdata ao_int64_t *__data ao_64r, *__data ao_64a, *__data ao_64b;
+
+void ao_plus64(__pdata ao_int64_t *r, __pdata ao_int64_t *a, __pdata ao_int64_t *b) __FATTR {
+ __LOCAL uint32_t t;
r->high = a->high + b->high;
t = a->low + b->low;
@@ -27,9 +29,8 @@ void ao_plus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
r->low = t;
}
-void ao_minus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
- uint32_t t;
-
+void ao_minus64(__pdata ao_int64_t *r, __pdata ao_int64_t *a, __pdata ao_int64_t *b) __FATTR {
+ __LOCAL uint32_t t;
r->high = a->high - b->high;
t = a->low - b->low;
@@ -38,7 +39,7 @@ void ao_minus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
r->low = t;
}
-void ao_rshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d) {
+void ao_rshift64(__pdata ao_int64_t *r, __pdata ao_int64_t *a, uint8_t d) __FATTR {
if (d < 32) {
r->low = a->low >> d;
if (d)
@@ -51,7 +52,7 @@ void ao_rshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d) {
}
}
-void ao_lshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d) {
+void ao_lshift64(__pdata ao_int64_t *r, __pdata ao_int64_t *a, uint8_t d) __FATTR {
if (d < 32) {
r->high = a->high << d;
if (d)
@@ -64,53 +65,49 @@ void ao_lshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d) {
}
}
-static void ao_umul64_32_32(ao_int64_t *r, uint32_t a, uint32_t b)
-{
- uint32_t r1;
- uint32_t r2, r3, r4;
- ao_int64_t s,t,u,v;
- r1 = (uint32_t) (uint16_t) a * (uint16_t) b;
- r2 = (uint32_t) (uint16_t) (a >> 16) * (uint16_t) b;
- r3 = (uint32_t) (uint16_t) a * (uint16_t) (b >> 16);
- r4 = (uint32_t) (uint16_t) (a >> 16) * (uint16_t) (b >> 16);
-
- s.low = r1;
- s.high = r4;
-
- t.high = r2 >> 16;
- t.low = r2 << 16;
- ao_plus64(&u, &s, &t);
-
- v.high = r3 >> 16;
- v.low = r3 << 16;
- ao_plus64(r, &u, &v);
+static void ao_umul64_32_32(__ARG ao_int64_t *r, uint32_t a, uint32_t b) __reentrant {
+ __LOCAL uint32_t s;
+ __LOCAL ao_int64_t t;
+ r->low = (uint32_t) (uint16_t) a * (uint16_t) b;
+ r->high = (uint32_t) (uint16_t) (a >> 16) * (uint16_t) (b >> 16);
+
+ s = (uint32_t) (uint16_t) (a >> 16) * (uint16_t) b;
+
+ t.high = s >> 16;
+ t.low = s << 16;
+ ao_plus64(r, r, &t);
+
+ s = (uint32_t) (uint16_t) a * (uint16_t) (b >> 16);
+
+ t.high = s >> 16;
+ t.low = s << 16;
+ ao_plus64(r, r, &t);
}
-void ao_neg64(ao_int64_t *r, ao_int64_t *a) {
+void ao_neg64(__pdata ao_int64_t *r, __pdata ao_int64_t *a) __FATTR {
r->high = ~a->high;
- r->low = ~a->low;
- if (!++r->low)
+ if (!(r->low = ~a->low + 1))
r->high++;
}
-void ao_mul64_32_32(ao_int64_t *r, int32_t a, int32_t b) {
+void ao_mul64_32_32(__ARG ao_int64_t *r, int32_t a, int32_t b) __FATTR {
uint8_t negative = 0;
if (a < 0) {
a = -a;
- negative = ~0;
+ ++negative;
}
if (b < 0) {
b = -b;
- negative = ~negative;
+ --negative;
}
ao_umul64_32_32(r, a, b);
if (negative)
ao_neg64(r, r);
}
-static void ao_umul64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
- ao_int64_t r2, r3;
+static void ao_umul64(__ARG ao_int64_t *r, __ARG ao_int64_t *a, __ARG ao_int64_t *b) __reentrant {
+ __LOCAL ao_int64_t r2, r3;
ao_umul64_32_32(&r2, a->high, b->low);
ao_umul64_32_32(&r3, a->low, b->high);
@@ -119,38 +116,41 @@ static void ao_umul64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
r->high += r2.low + r3.low;
}
-void ao_mul64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b) {
+static __ARG ao_int64_t ap, bp;
+
+void ao_mul64(__ARG ao_int64_t *r, __ARG ao_int64_t *a, __ARG ao_int64_t *b) __FATTR {
uint8_t negative = 0;
- ao_int64_t ap, bp;
if (ao_int64_negativep(a)) {
ao_neg64(&ap, a);
a = &ap;
- negative = ~0;
+ ++negative;
}
if (ao_int64_negativep(b)) {
ao_neg64(&bp, b);
b = &bp;
- negative = ~negative;
+ --negative;
}
ao_umul64(r, a, b);
if (negative)
ao_neg64(r, r);
}
-void ao_umul64_64_16(ao_int64_t *r, ao_int64_t *a, uint16_t b) {
- uint32_t h = a->high * b;
+static void ao_umul64_64_16(__ARG ao_int64_t *r, __ARG ao_int64_t *a, uint16_t b) __reentrant {
+ __LOCAL uint32_t h;
+
+ h = a->high * b;
ao_umul64_32_32(r, a->low, b);
r->high += h;
}
-void ao_mul64_64_16(ao_int64_t *r, ao_int64_t *a, uint16_t b) {
- ao_int64_t ap;
+void ao_mul64_64_16(__ARG ao_int64_t *r, __ARG ao_int64_t *a, __ARG uint16_t b) __FATTR {
uint8_t negative = 0;
+
if ((int32_t) a->high < 0) {
ao_neg64(&ap, a);
a = &ap;
- negative = ~0;
+ negative++;
} else
ao_umul64_64_16(r, a, b);
if (negative)
diff --git a/src/core/ao_int64.h b/src/core/ao_int64.h
index cf12f0d8..b16db58c 100644
--- a/src/core/ao_int64.h
+++ b/src/core/ao_int64.h
@@ -25,16 +25,18 @@ typedef struct {
uint32_t low;
} ao_int64_t;
-void ao_plus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b);
-void ao_minus64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b);
-void ao_neg64(ao_int64_t *r, ao_int64_t *a);
-void ao_lshift64_16(ao_int64_t *r, uint16_t a, uint8_t d);
-void ao_rshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d);
-void ao_lshift64(ao_int64_t *r, ao_int64_t *a, uint8_t d);
-void ao_mul64_64_64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b);
-void ao_mul64_32_32(ao_int64_t *r, int32_t a, int32_t b);
-void ao_mul64_64_16(ao_int64_t *r, ao_int64_t *a, uint16_t b);
-void ao_mul64(ao_int64_t *r, ao_int64_t *a, ao_int64_t *b);
+#define __FATTR
+#define __ARG __pdata
+#define __LOCAL static __pdata
+
+void ao_plus64(__pdata ao_int64_t *ao_64r, __pdata ao_int64_t *ao_64a, __pdata ao_int64_t *ao_64b) __FATTR;
+void ao_minus64(__pdata ao_int64_t *ao_64r, __pdata ao_int64_t *ao_64a, __pdata ao_int64_t *ao_64b) __FATTR;
+void ao_neg64(__pdata ao_int64_t *ao_64r, __pdata ao_int64_t *ao_64a) __FATTR;
+void ao_rshift64(__pdata ao_int64_t *ao_64r, __pdata ao_int64_t *ao_64a, uint8_t d) __FATTR;
+void ao_lshift64(__pdata ao_int64_t *ao_64r, __pdata ao_int64_t *ao_64a, uint8_t d) __FATTR;
+void ao_mul64_32_32(__ARG ao_int64_t *r, __ARG int32_t a, __ARG int32_t b) __FATTR;
+void ao_mul64_64_16(__ARG ao_int64_t *r, __ARG ao_int64_t *a, __ARG uint16_t b) __FATTR;
+void ao_mul64(__ARG ao_int64_t * __ARG r, __ARG ao_int64_t * __ARG a, __ARG ao_int64_t *__ARG b) __FATTR;
#define ao_int64_init32(r, a) (((r)->high = 0), (r)->low = (a))
#define ao_int64_init64(r, a, b) (((r)->high = (a)), (r)->low = (b))
diff --git a/src/core/ao_kalman.c b/src/core/ao_kalman.c
index 59ffd8b2..762b2c0a 100644
--- a/src/core/ao_kalman.c
+++ b/src/core/ao_kalman.c
@@ -40,9 +40,9 @@ static __pdata int32_t ao_k_accel;
__pdata int16_t ao_height;
__pdata int16_t ao_speed;
__pdata int16_t ao_accel;
-__pdata int16_t ao_max_height;
+__xdata int16_t ao_max_height;
static __pdata int32_t ao_avg_height_scaled;
-__pdata int16_t ao_avg_height;
+__xdata int16_t ao_avg_height;
__pdata int16_t ao_error_h;
__pdata int16_t ao_error_h_sq_avg;
diff --git a/src/core/ao_log_telem.c b/src/core/ao_log_telem.c
index 23ebf7dd..095aca37 100644
--- a/src/core/ao_log_telem.c
+++ b/src/core/ao_log_telem.c
@@ -23,7 +23,7 @@ __code uint8_t ao_log_format = AO_LOG_FORMAT_TELEMETRY;
static __data uint8_t ao_log_monitor_pos;
__pdata enum ao_flight_state ao_flight_state;
-__pdata int16_t ao_max_height; /* max of ao_height */
+__xdata int16_t ao_max_height; /* max of ao_height */
__pdata int16_t sense_d, sense_m;
__pdata uint8_t ao_igniter_present;
diff --git a/src/core/ao_sample.h b/src/core/ao_sample.h
index a2dac979..5bd29536 100644
--- a/src/core/ao_sample.h
+++ b/src/core/ao_sample.h
@@ -136,8 +136,8 @@ uint8_t ao_sample(void);
extern __pdata int16_t ao_height; /* meters */
extern __pdata int16_t ao_speed; /* m/s * 16 */
extern __pdata int16_t ao_accel; /* m/s² * 16 */
-extern __pdata int16_t ao_max_height; /* max of ao_height */
-extern __pdata int16_t ao_avg_height; /* running average of height */
+extern __xdata int16_t ao_max_height; /* max of ao_height */
+extern __xdata int16_t ao_avg_height; /* running average of height */
extern __pdata int16_t ao_error_h;
extern __pdata int16_t ao_error_h_sq_avg;
diff --git a/src/core/ao_task.h b/src/core/ao_task.h
index 1a4b5b6b..e3a311ed 100644
--- a/src/core/ao_task.h
+++ b/src/core/ao_task.h
@@ -45,7 +45,10 @@ struct ao_task {
#endif
};
+#ifndef AO_NUM_TASKS
#define AO_NUM_TASKS 16 /* maximum number of tasks */
+#endif
+
#define AO_NO_TASK 0 /* no task id */
extern __xdata struct ao_task * __xdata ao_tasks[AO_NUM_TASKS];