diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/Makefile | 15 | ||||
| -rw-r--r-- | src/test/ao_aprs_test.c | 16 | ||||
| -rw-r--r-- | src/test/ao_flight_test.c | 4 | ||||
| -rw-r--r-- | src/test/ao_lisp_os.h | 59 | ||||
| -rw-r--r-- | src/test/ao_lisp_test.c | 134 | ||||
| -rw-r--r-- | src/test/hanoi.lisp | 155 | 
6 files changed, 379 insertions, 4 deletions
| diff --git a/src/test/Makefile b/src/test/Makefile index 02e1d22b..a22abe46 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -1,16 +1,16 @@ -vpath % ..:../kernel:../drivers:../util:../micropeak:../aes:../product +vpath % ..:../kernel:../drivers:../util:../micropeak:../aes:../product:../lisp  PROGS=ao_flight_test ao_flight_test_baro ao_flight_test_accel ao_flight_test_noisy_accel ao_flight_test_mm \  	ao_flight_test_metrum \  	ao_gps_test ao_gps_test_skytraq ao_gps_test_ublox ao_convert_test ao_convert_pa_test ao_fec_test \  	ao_aprs_test ao_micropeak_test ao_fat_test ao_aes_test ao_int64_test \ -	ao_ms5607_convert_test ao_quaternion_test +	ao_ms5607_convert_test ao_quaternion_test ao_lisp_test  INCS=ao_kalman.h ao_ms5607.h ao_log.h ao_data.h altitude-pa.h altitude.h ao_quaternion.h  KALMAN=make-kalman  -CFLAGS=-I.. -I. -I../kernel -I../drivers -I../micropeak -I../product -O0 -g -Wall +CFLAGS=-I.. -I. -I../kernel -I../drivers -I../micropeak -I../product -I../lisp -O0 -g -Wall -DAO_LISP_TEST -no-pie  all: $(PROGS) ao_aprs_data.wav @@ -88,3 +88,12 @@ ao_ms5607_convert_test: ao_ms5607_convert_test.c ao_ms5607_convert_8051.c ao_int  ao_quaternion_test: ao_quaternion_test.c ao_quaternion.h  	cc $(CFLAGS) -o $@ ao_quaternion_test.c -lm +AO_LISP_OBJS = ao_lisp_test.o ao_lisp_mem.o  ao_lisp_cons.o ao_lisp_string.o \ +	ao_lisp_atom.o ao_lisp_int.o ao_lisp_eval.o ao_lisp_poly.o \ +	ao_lisp_builtin.o ao_lisp_read.o ao_lisp_rep.o ao_lisp_frame.o \ +	ao_lisp_lambda.o ao_lisp_error.o ao_lisp_save.o ao_lisp_stack.o + +ao_lisp_test: $(AO_LISP_OBJS) +	cc $(CFLAGS) -o $@ $(AO_LISP_OBJS) + +$(AO_LISP_OBJS): ao_lisp.h ao_lisp_const.h ao_lisp_os.h diff --git a/src/test/ao_aprs_test.c b/src/test/ao_aprs_test.c index 3852668a..941bf954 100644 --- a/src/test/ao_aprs_test.c +++ b/src/test/ao_aprs_test.c @@ -60,6 +60,20 @@ ao_aprs_bit(uint8_t bit)  void  ao_radio_send_aprs(ao_radio_fill_func fill); +static void +aprs_bit_debug(uint8_t tx_bit) +{ +	fprintf (stderr, "bit %d\n", tx_bit); +} + +static void +aprs_byte_debug(uint8_t tx_byte) +{ +	fprintf(stderr, "byte %02x\n", tx_byte); +} +#define APRS_BIT_DEBUG(x) aprs_bit_debug(x) +#define APRS_BYTE_DEBUG(y) aprs_byte_debug(y) +  #include <ao_aprs.c>  /* @@ -103,7 +117,7 @@ audio_gap(int secs)  // This is where we go after reset.  int main(int argc, char **argv)  { -    audio_gap(1); +//    audio_gap(1);      ao_gps_data.latitude = (45.0 + 28.25 / 60.0) * 10000000;      ao_gps_data.longitude = (-(122 + 44.2649 / 60.0)) * 10000000; diff --git a/src/test/ao_flight_test.c b/src/test/ao_flight_test.c index bd7f2ff8..25ddb48f 100644 --- a/src/test/ao_flight_test.c +++ b/src/test/ao_flight_test.c @@ -58,6 +58,7 @@ int ao_gps_new;  #define HAS_HMC5883 		1  #define HAS_BEEP		1  #define AO_CONFIG_MAX_SIZE	1024 +#define AO_MMA655X_INVERT	0  struct ao_adc {  	int16_t			sense[AO_ADC_NUM_SENSE]; @@ -71,6 +72,7 @@ struct ao_adc {  #define AO_ADC_NUM_SENSE	2  #define HAS_MS5607		1  #define HAS_MMA655X		1 +#define AO_MMA655X_INVERT	1  #define HAS_BEEP		1  #define AO_CONFIG_MAX_SIZE	1024 @@ -373,6 +375,8 @@ uint16_t	prev_tick;  #define AO_PYRO_2	2  #define AO_PYRO_3	3 +#define PYRO_DBG	1 +  static void  ao_pyro_pin_set(uint8_t pin, uint8_t value)  { diff --git a/src/test/ao_lisp_os.h b/src/test/ao_lisp_os.h new file mode 100644 index 00000000..9ff2e1fe --- /dev/null +++ b/src/test/ao_lisp_os.h @@ -0,0 +1,59 @@ +/* + * Copyright © 2016 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_LISP_OS_H_ +#define _AO_LISP_OS_H_ + +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define AO_LISP_POOL_TOTAL	3072 +#define AO_LISP_SAVE		1 +#define DBG_MEM_STATS		1 + +extern int ao_lisp_getc(void); + +static inline void +ao_lisp_os_flush() { +	fflush(stdout); +} + +static inline void +ao_lisp_abort(void) +{ +	abort(); +} + +static inline void +ao_lisp_os_led(int led) +{ +	printf("leds set to 0x%x\n", led); +} + +static inline void +ao_lisp_os_delay(int delay) +{ +	if (!delay) +		return; +	struct timespec ts = { +		.tv_sec = delay / 1000, +		.tv_nsec = (delay % 1000) * 1000000, +	}; +	nanosleep(&ts, NULL); +} +#endif diff --git a/src/test/ao_lisp_test.c b/src/test/ao_lisp_test.c new file mode 100644 index 00000000..68e3a202 --- /dev/null +++ b/src/test/ao_lisp_test.c @@ -0,0 +1,134 @@ +/* + * Copyright © 2016 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, either version 2 of the License, or + * (at your option) any later version. + * + * 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. + */ + +#include "ao_lisp.h" +#include <stdio.h> + +static FILE *ao_lisp_file; +static int newline = 1; + +static char save_file[] = "lisp.image"; + +int +ao_lisp_os_save(void) +{ +	FILE	*save = fopen(save_file, "w"); + +	if (!save) { +		perror(save_file); +		return 0; +	} +	fwrite(ao_lisp_pool, 1, AO_LISP_POOL_TOTAL, save); +	fclose(save); +	return 1; +} + +int +ao_lisp_os_restore_save(struct ao_lisp_os_save *save, int offset) +{ +	FILE	*restore = fopen(save_file, "r"); +	size_t	ret; + +	if (!restore) { +		perror(save_file); +		return 0; +	} +	fseek(restore, offset, SEEK_SET); +	ret = fread(save, sizeof (struct ao_lisp_os_save), 1, restore); +	fclose(restore); +	if (ret != 1) +		return 0; +	return 1; +} + +int +ao_lisp_os_restore(void) +{ +	FILE	*restore = fopen(save_file, "r"); +	size_t	ret; + +	if (!restore) { +		perror(save_file); +		return 0; +	} +	ret = fread(ao_lisp_pool, 1, AO_LISP_POOL_TOTAL, restore); +	fclose(restore); +	if (ret != AO_LISP_POOL_TOTAL) +		return 0; +	return 1; +} + +int +ao_lisp_getc(void) +{ +	int c; + +	if (ao_lisp_file) +		return getc(ao_lisp_file); + +	if (newline) { +		printf("> "); +		newline = 0; +	} +	c = getchar(); +	if (c == '\n') +		newline = 1; +	return c; +} + +int +main (int argc, char **argv) +{ +	while (*++argv) { +		ao_lisp_file = fopen(*argv, "r"); +		if (!ao_lisp_file) { +			perror(*argv); +			exit(1); +		} +		ao_lisp_read_eval_print(); +		fclose(ao_lisp_file); +		ao_lisp_file = NULL; +	} +	ao_lisp_read_eval_print(); + +	printf ("collects: full: %d incremental %d\n", +		ao_lisp_collects[AO_LISP_COLLECT_FULL], +		ao_lisp_collects[AO_LISP_COLLECT_INCREMENTAL]); + +	printf ("freed: full %d incremental %d\n", +		ao_lisp_freed[AO_LISP_COLLECT_FULL], +		ao_lisp_freed[AO_LISP_COLLECT_INCREMENTAL]); + +	printf("loops: full %d incremental %d\n", +		ao_lisp_loops[AO_LISP_COLLECT_FULL], +		ao_lisp_loops[AO_LISP_COLLECT_INCREMENTAL]); + +	printf("loops per collect: full %f incremental %f\n", +	       (double) ao_lisp_loops[AO_LISP_COLLECT_FULL] / +	       (double) ao_lisp_collects[AO_LISP_COLLECT_FULL], +	       (double) ao_lisp_loops[AO_LISP_COLLECT_INCREMENTAL] / +	       (double) ao_lisp_collects[AO_LISP_COLLECT_INCREMENTAL]); + +	printf("freed per collect: full %f incremental %f\n", +	       (double) ao_lisp_freed[AO_LISP_COLLECT_FULL] / +	       (double) ao_lisp_collects[AO_LISP_COLLECT_FULL], +	       (double) ao_lisp_freed[AO_LISP_COLLECT_INCREMENTAL] / +	       (double) ao_lisp_collects[AO_LISP_COLLECT_INCREMENTAL]); + +	printf("freed per loop: full %f incremental %f\n", +	       (double) ao_lisp_freed[AO_LISP_COLLECT_FULL] / +	       (double) ao_lisp_loops[AO_LISP_COLLECT_FULL], +	       (double) ao_lisp_freed[AO_LISP_COLLECT_INCREMENTAL] / +	       (double) ao_lisp_loops[AO_LISP_COLLECT_INCREMENTAL]); +} diff --git a/src/test/hanoi.lisp b/src/test/hanoi.lisp new file mode 100644 index 00000000..e2eb0fa0 --- /dev/null +++ b/src/test/hanoi.lisp @@ -0,0 +1,155 @@ +; +; Towers of Hanoi +; +; Copyright © 2016 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, either version 2 of the License, or +; (at your option) any later version. +; +; 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. +; + +					; ANSI control sequences + +(defun move-to (col row) +  (patom "\033[" row ";" col "H") +  ) + +(defun clear () +  (patom "\033[2J") +  ) + +(defun display-string (x y str) +  (move-to x y) +  (patom str) +  ) + +					; Here's the pieces to display + +(setq stack '("     *     " "    ***    " "   *****   " "  *******  " " ********* " "***********")) + +					; Here's all of the stacks of pieces +					; This is generated when the program is run + +(setq stacks nil) + +					; Display one stack, clearing any +					; space above it + +(defun display-stack (x y clear stack) +  (cond ((= 0 clear) +	 (cond (stack  +		(display-string x y (car stack)) +		(display-stack x (1+ y) 0 (cdr stack)) +		) +	       ) +	 ) +	(t  +	 (display-string x y "                   ") +	 (display-stack x (1+ y) (1- clear) stack) +	 ) +	) +  ) + +					; Position of the top of the stack on the screen +					; Shorter stacks start further down the screen + +(defun stack-pos (y stack) +  (- y (length stack)) +  ) + +					; Display all of the stacks, spaced 20 columns apart + +(defun display-stacks (x y stacks) +  (cond (stacks +	 (display-stack x 0 (stack-pos y (car stacks)) (car stacks)) +	 (display-stacks (+ x 20) y (cdr stacks))) +	) +  ) + +					; Display all of the stacks, then move the cursor +					; out of the way and flush the output + +(defun display () +  (display-stacks 0 top stacks) +  (move-to 1 21) +  (flush) +  ) + +					; Reset stacks to the starting state, with +					; all of the pieces in the first stack and the +					; other two empty + +(defun reset-stacks () +  (setq stacks (list stack nil nil)) +  (setq top (+ (length stack) 3)) +  (length stack) +  ) + +					; more functions which could usefully +					; be in the rom image + +(defun min (a b) +  (cond ((< a b) a) +	(b) +	) +  ) + +					; Replace a stack in the list of stacks +					; with a new value + +(defun replace (list pos member) +  (cond ((= pos 0) (cons member (cdr list))) +	((cons (car list) (replace (cdr list) (1- pos) member))) +	) +  ) + +					; Move a piece from the top of one stack +					; to the top of another + +(setq move-delay 100) + +(defun move-piece (from to) +  (let ((from-stack (nth stacks from)) +	(to-stack (nth stacks to)) +	(piece (car from-stack))) +    (setq from-stack (cdr from-stack)) +    (setq to-stack (cons piece to-stack)) +    (setq stacks (replace stacks from from-stack)) +    (setq stacks (replace stacks to to-stack)) +    (display) +    (delay move-delay) +    ) +  ) + +; The implementation of the game + +(defun _hanoi (n from to use) +  (cond ((= 1 n) +	 (move-piece from to) +	 ) +	(t +	 (_hanoi (1- n) from use to) +	 (_hanoi 1 from to use) +	 (_hanoi (1- n) use to from) +	 ) +	) +  ) + +					; A pretty interface which +					; resets the state of the game, +					; clears the screen and runs +					; the program + +(defun hanoi () +  (setq len (reset-stacks)) +  (clear) +  (_hanoi len 0 1 2) +  (move-to 0 23) +  t +  ) | 
