fw/altos
7 years agoaltos/stm: Make i2c code handle PCLK1 of 24MHz
Keith Packard [Mon, 20 Feb 2017 20:14:10 +0000 (12:14 -0800)]
altos/stm: Make i2c code handle PCLK1 of 24MHz

Just adds the necessary defines to the code.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stm: Allow DMA channels to be hijacked by other code
Keith Packard [Mon, 20 Feb 2017 20:12:43 +0000 (12:12 -0800)]
altos/stm: Allow DMA channels to be hijacked by other code

This lets code which needs finer control over DMA to use the channel
without interference, and leaves the DMA engine running so that it can.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Allow for console to be used for stdio
Keith Packard [Tue, 10 Jan 2017 22:45:25 +0000 (14:45 -0800)]
altos: Allow for console to be used for stdio

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/avr: Avoid warning about unused args in stdio_put and stdio_get
Keith Packard [Tue, 10 Jan 2017 22:43:07 +0000 (14:43 -0800)]
altos/avr: Avoid warning about unused args in stdio_put and stdio_get

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stm: Allow use basepri instead of primask for masking interrupts
Keith Packard [Sun, 20 Nov 2016 10:59:40 +0000 (02:59 -0800)]
altos/stm: Allow use basepri instead of primask for masking interrupts

This allows for high priority interrupts (priority 0) to run, even
when other interrupts are blocked. Code executing in such interrupt
handlers must not attempt to control task execution as that will race
with the scheduler.

Select this by defining AO_NONMASK_INTERRUPT in ao_pins.h.
non-maskable interrupt priority is AO_STM_NVIC_NONMASK_PRIORITY

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stm: Interrupt priority is in the upper bits of the priority mask
Keith Packard [Mon, 21 Nov 2016 04:54:10 +0000 (20:54 -0800)]
altos/stm: Interrupt priority is in the upper bits of the priority mask

Because the STM32L only offers 16 priority levels, the bottom four
bits of each priority mask are not used. All of the interrupt priority
settings in the system were using values < 16, making them all
effectively the same. Fix that by moving them into the upper 4 bits
and using symbolic constants everywhere.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Don't wait while idle if trying to minimize interrupt latency
Keith Packard [Mon, 21 Nov 2016 04:56:01 +0000 (20:56 -0800)]
altos: Don't wait while idle if trying to minimize interrupt latency

Keeping the scanout running reasonably means keeping interrupt latency
constant, and that requires leaving the CPU running. Don't wait for
interrupts when the system is running in this mode.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoao-tools/ao-usbload: Pad image with 0xff instead of random bits
Keith Packard [Fri, 6 Jan 2017 17:10:23 +0000 (09:10 -0800)]
ao-tools/ao-usbload: Pad image with 0xff instead of random bits

Clear the temporary block to 0xff before copying in the target data so
that any unused bytes end up being left at 0xff instead of inheriting
whatever data was in the block before.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/cc1111: Remove unneeded initialization in ao_timer.c
Keith Packard [Sun, 18 Dec 2016 04:57:38 +0000 (20:57 -0800)]
altos/cc1111: Remove unneeded initialization in ao_timer.c

The timers are all stopped when the chip boots, so no need to stop
them. This saves some text space, allowing the current code to (just
barely) fit.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltoslib: Add TeleMini v3 support
Keith Packard [Mon, 20 Feb 2017 01:36:04 +0000 (17:36 -0800)]
altoslib: Add TeleMini v3 support

eeprom, telemetry and monitor idle. This is just like TeleMini v2,
except the ADC ranges are all difference as the voltage dividers are
different and the ADC itself has a different range.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/telemini-v3.0: Swap main and apogee sense pins.
Keith Packard [Mon, 20 Feb 2017 01:40:28 +0000 (17:40 -0800)]
altos/telemini-v3.0: Swap main and apogee sense pins.

These were just hooked up wrong in the software.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Split out TeleMini v3 log/telem labeling
Keith Packard [Mon, 20 Feb 2017 01:39:21 +0000 (17:39 -0800)]
altos: Split out TeleMini v3 log/telem labeling

Allow the ground software to know which TeleMini version is in use,
even though they are very similar with only ADC values differing.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/telemini-v3.0: Finish initial turn-on
Keith Packard [Sun, 19 Feb 2017 06:56:49 +0000 (22:56 -0800)]
altos/telemini-v3.0: Finish initial turn-on

TeleMini v3.0 is nearly working; there are some ADC issues still, and
lots of altosui work left to decode the new telemetry packet.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/telemini-v3.0: Update to second prototype version
Keith Packard [Fri, 3 Feb 2017 05:52:57 +0000 (06:52 +0100)]
altos/telemini-v3.0: Update to second prototype version

Separate radio xtal means we run the processor at 48MHz.
Fix the battery monitoring voltage divider resistor values.
Disable most of the code until we've got the radio working.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Initial TeleMini v3.0 code
Keith Packard [Sat, 28 Jan 2017 23:35:48 +0000 (15:35 -0800)]
altos: Initial TeleMini v3.0 code

For first prototype, which attempted to use the SoC clock for the radio.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stmf0: Add adc and beep support for TeleMini v3.0
Keith Packard [Mon, 20 Feb 2017 01:42:05 +0000 (17:42 -0800)]
altos/stmf0: Add adc and beep support for TeleMini v3.0

Note that the ADC code is running very slowly as required by the high
impedance dividers on the TeleMini v3.0 pyro circuits.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Require SPI speed to be declared for cc1200
Keith Packard [Sun, 19 Feb 2017 06:49:34 +0000 (22:49 -0800)]
altos: Require SPI speed to be declared for cc1200

The cc1200 can't run SPI faster than 10MHz, so make sure every device
picks a SPI clock slower than that.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Allow applications to define LEDs for ao_report.c
Keith Packard [Sun, 19 Feb 2017 06:55:41 +0000 (22:55 -0800)]
altos: Allow applications to define LEDs for ao_report.c

In case they don't have both a red and green LED.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stmf0: Allow projects to not use the USB boot loader
Keith Packard [Sun, 19 Feb 2017 06:54:35 +0000 (22:54 -0800)]
altos/stmf0: Allow projects to not use the USB boot loader

Let applications define HAS_BOOT_LOADER on their own if desired.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stmf0: Complain if the SPI configuration isn't complete
Keith Packard [Sun, 19 Feb 2017 06:53:03 +0000 (22:53 -0800)]
altos/stmf0: Complain if the SPI configuration isn't complete

If the pin usage values SPI_1_PA5_PA6_PA7 or SPI_1_PB3_PB4_PB5 aren't
defined, then the speed values for the pins aren't going to get set
correctly, which results in erratic SPI behaviour.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stmf0: Allow apps to leave interrupt vectors at 0
Keith Packard [Fri, 3 Feb 2017 05:51:11 +0000 (06:51 +0100)]
altos/stmf0: Allow apps to leave interrupt vectors at 0

TeleMini v3.0 doesn't need a boot loader, so we'll have the app run
its interrupt vector right at the bottom of the address space instead
of copying it to the bottom of ram and reconfiguring the chip to use that.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoao-bringup: test-chaoskey needs to use the SerialNumber dmesg line
Keith Packard [Sun, 19 Feb 2017 06:46:29 +0000 (22:46 -0800)]
ao-bringup: test-chaoskey needs to use the SerialNumber dmesg line

I had a locally hacked kernel which was reporting the serial number
along with the device name. Instead of depending on that, just look
for the regular SerialNumber report which is in all kernel versions

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoao-bringup: Allow serial number on turnon_easymega cmdline
Keith Packard [Fri, 3 Feb 2017 05:47:32 +0000 (06:47 +0100)]
ao-bringup: Allow serial number on turnon_easymega cmdline

This makes it a bit quicker to do a batch of them.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Eliminate printf format warning with long vs int
Keith Packard [Sat, 28 Jan 2017 23:33:53 +0000 (15:33 -0800)]
altos: Eliminate printf format warning with long vs int

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/chaoskey: use both halves of the CRC
Keith Packard [Sun, 22 Jan 2017 23:29:13 +0000 (15:29 -0800)]
altos/chaoskey: use both halves of the CRC

When pulling 16 bits from the 32-bit crc, instead of just using the
low bits, xor the two halves together. This appears to even out the
number of zero and one bits.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Start adding scheme symbols
Keith Packard [Sat, 18 Feb 2017 20:14:59 +0000 (12:14 -0800)]
altos/lisp: Start adding scheme symbols

Migrating to something more like scheme

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add casts to keep the latest GCC from whinging
Keith Packard [Tue, 10 Jan 2017 22:47:03 +0000 (14:47 -0800)]
altos/lisp: Add casts to keep the latest GCC from whinging

Something about alignment issues.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Tell compiler that the two lisp memory pools are aligned
Keith Packard [Tue, 10 Jan 2017 22:45:59 +0000 (14:45 -0800)]
altos/lisp: Tell compiler that the two lisp memory pools are aligned

Otherwise, it will generate unaligned accesses to things fetched from
them. Sigh.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Clean up hanoi.lisp demo a bit
Keith Packard [Sun, 20 Nov 2016 09:41:59 +0000 (01:41 -0800)]
altos/lisp: Clean up hanoi.lisp demo a bit

No serious changes.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Move stack recursion check after null check
Keith Packard [Sat, 19 Nov 2016 07:37:44 +0000 (23:37 -0800)]
altos/lisp: Move stack recursion check after null check

Don't crash when printing null stack this way.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Include memory stats for test program
Keith Packard [Sat, 19 Nov 2016 06:57:22 +0000 (22:57 -0800)]
altos/lisp: Include memory stats for test program

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Cleanup some DBG defines
Keith Packard [Sat, 19 Nov 2016 06:53:36 +0000 (22:53 -0800)]
altos/lisp: Cleanup some DBG defines

Get rid of the remaining duplicate defines.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Share binary search for memory chunk between mark and move
Keith Packard [Sat, 19 Nov 2016 06:52:53 +0000 (22:52 -0800)]
altos/lisp: Share binary search for memory chunk between mark and move

Save some text space.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add builtin 'collect'
Keith Packard [Sat, 19 Nov 2016 06:52:10 +0000 (22:52 -0800)]
altos/lisp: Add builtin 'collect'

Collect memory, return amount free.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Sort frames by atom
Keith Packard [Sat, 19 Nov 2016 06:41:46 +0000 (22:41 -0800)]
altos/lisp: Sort frames by atom

Fortunately, the collector always retains the relative order between
addresses, so we can sort based on the atom address itself. This
reduces the time spent looking for names in larger (e.g. global)
frames.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Build new ao_lisp_stack.c into test and lambdakey
Keith Packard [Sat, 19 Nov 2016 05:17:54 +0000 (21:17 -0800)]
altos/lisp: Build new ao_lisp_stack.c into test and lambdakey

Helpful to include the new source file.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: bounds check in move_map plus binary search
Keith Packard [Sat, 19 Nov 2016 05:16:11 +0000 (21:16 -0800)]
altos/lisp: bounds check in move_map plus binary search

This makes move_map faster by skipping all addresses which aren't
changing.

Also changed the interface from address to offset to avoid computing
the offset multiple times.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Empty lambda body is not an error
Keith Packard [Sat, 19 Nov 2016 05:15:33 +0000 (21:15 -0800)]
altos/lisp: Empty lambda body is not an error

It's not very exciting, but it's still legal

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Use poly stashes for stacks
Keith Packard [Sat, 19 Nov 2016 05:14:47 +0000 (21:14 -0800)]
altos/lisp: Use poly stashes for stacks

Saves some memory.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Make DBG settings global
Keith Packard [Sat, 19 Nov 2016 05:12:50 +0000 (21:12 -0800)]
altos/lisp: Make DBG settings global

This avoids having different values in different files, which wasn't useful.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add continuations
Keith Packard [Sat, 19 Nov 2016 03:04:05 +0000 (19:04 -0800)]
altos/lisp: Add continuations

This provides call/cc and makes 'stacks' visible to the application.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Take advantage of implicit progns in hanoi demo
Keith Packard [Fri, 18 Nov 2016 02:45:31 +0000 (18:45 -0800)]
altos/lisp: Take advantage of implicit progns in hanoi demo

Remove extra progn wrappers now that cond, lambda and while all
support implicit ones.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: have 'while' return the last body value
Keith Packard [Fri, 18 Nov 2016 00:52:30 +0000 (16:52 -0800)]
altos/lisp: have 'while' return the last body value

Instead of always returning 'nil', let while return the last body
value.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Take advantage of implicit progn in ROM code
Keith Packard [Fri, 18 Nov 2016 00:51:34 +0000 (16:51 -0800)]
altos/lisp: Take advantage of implicit progn in ROM code

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Make lambda, cond and while all have implicit progns
Keith Packard [Fri, 18 Nov 2016 00:08:15 +0000 (16:08 -0800)]
altos/lisp: Make lambda, cond and while all have implicit progns

This lets all of these execute more than one sexpr, returning the
value of the last.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Compile ao_lisp_make_const -no-pie
Keith Packard [Fri, 18 Nov 2016 00:07:42 +0000 (16:07 -0800)]
altos/lisp: Compile ao_lisp_make_const -no-pie

Makes debugging easier

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Fix uninitialized values in ao_lisp_make_const
Keith Packard [Fri, 18 Nov 2016 00:06:55 +0000 (16:06 -0800)]
altos/lisp: Fix uninitialized values in ao_lisp_make_const

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Dump globals on error
Keith Packard [Fri, 18 Nov 2016 00:06:05 +0000 (16:06 -0800)]
altos/lisp: Dump globals on error

Useful for debugging

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Fix error atom name in ao_lisp_length
Keith Packard [Fri, 18 Nov 2016 00:05:29 +0000 (16:05 -0800)]
altos/lisp: Fix error atom name in ao_lisp_length

Cut&paste error.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Remove some stale frame debugging checks
Keith Packard [Fri, 18 Nov 2016 00:04:38 +0000 (16:04 -0800)]
altos/lisp: Remove some stale frame debugging checks

No-one sets frame->_num to 0xff to hit these

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Clean up hanoi.lisp comments.
Keith Packard [Wed, 16 Nov 2016 22:59:08 +0000 (14:59 -0800)]
altos/lisp: Clean up hanoi.lisp comments.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Eliminate compiler warning about array bounds at -O3
Keith Packard [Wed, 16 Nov 2016 22:12:59 +0000 (14:12 -0800)]
altos/lisp: Eliminate compiler warning about array bounds at -O3

Using ao_lisp_pool - 4 caused the compiler to whinge about computing
an address outside the bounds of the array. Sigh. Restructure the code
to do the adjustment-by-4 in the integer computations instead of the
pointer ones.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: binary search for chunk in collect
Keith Packard [Wed, 16 Nov 2016 22:00:38 +0000 (14:00 -0800)]
altos/lisp: binary search for chunk in collect

Speeds up collect a bit

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/test: Disable position independent executables
Keith Packard [Wed, 16 Nov 2016 21:59:54 +0000 (13:59 -0800)]
altos/test: Disable position independent executables

This makes debugging programs so much harder

7 years agoaltos/lisp: Allow empty defun bodies
Keith Packard [Wed, 16 Nov 2016 21:47:49 +0000 (13:47 -0800)]
altos/lisp: Allow empty defun bodies

This allows for (defun foo())

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Optimize chunk searching in collect
Keith Packard [Wed, 16 Nov 2016 21:19:20 +0000 (13:19 -0800)]
altos/lisp: Optimize chunk searching in collect

Note range of existing chunks to exclude objects outside.
Only look at chunks which have been set to reduce loop cost.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add incremental collection
Keith Packard [Wed, 16 Nov 2016 20:34:14 +0000 (12:34 -0800)]
altos/lisp: Add incremental collection

Realizing that long-lived objects will eventually float to the bottom
of the heap, I added a simple hack to the collector that 'remembers'
the top of the heap the last time a full collect was run and then runs
incremental collects looking to shift only objects above that
boundary. That doesn't perfectly capture the bounds of transient
objects, but does manage to reduce the amount of time spent not moving
persistent objects each time through the collector.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Make hanoi example output a bit prettier
Keith Packard [Wed, 16 Nov 2016 04:37:59 +0000 (20:37 -0800)]
altos/lisp: Make hanoi example output a bit prettier

Make the towers symmetrical instead of lopsided. Much nicer looking.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: remove nth from hanoi.lisp
Keith Packard [Wed, 16 Nov 2016 04:25:03 +0000 (20:25 -0800)]
altos/lisp: remove nth from hanoi.lisp

It's now in ROM.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lambdakey: Strip out unused code
Keith Packard [Wed, 16 Nov 2016 04:24:33 +0000 (20:24 -0800)]
altos/lambdakey: Strip out unused code

Make space for more lisp bits!

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Take advantage of multi-arg macros. Add more ROM funcs
Keith Packard [Wed, 16 Nov 2016 04:22:54 +0000 (20:22 -0800)]
altos/lisp: Take advantage of multi-arg macros. Add more ROM funcs

Added nth, or and and.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Allow macro/nlambda/lexpr to have multiple args
Keith Packard [Wed, 16 Nov 2016 04:21:47 +0000 (20:21 -0800)]
altos/lisp: Allow macro/nlambda/lexpr to have multiple args

Entries from the params are bound to the formals with whatever
remaining formals there are bound to the last argument as a list.
This makes writing functions a bit easier.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Do better checking for un-evaluated macros in ROM
Keith Packard [Wed, 16 Nov 2016 04:20:14 +0000 (20:20 -0800)]
altos/lisp: Do better checking for un-evaluated macros in ROM

Need to look at immediate lambdas as well, and also deal with
recursive functions by checking for recursion at each atom
dereference.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: re-use small frames
Keith Packard [Wed, 16 Nov 2016 04:18:59 +0000 (20:18 -0800)]
altos/lisp: re-use small frames

This saves a pile more use of the allocator by noting when frames have
not been referenced from another frame and freeing them when they go
out of scope. Frames with references are left to the allocator to deal
with.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: remove duplicate 'length' lambda from hanoi example
Keith Packard [Tue, 15 Nov 2016 18:32:36 +0000 (10:32 -0800)]
altos/lisp: remove duplicate 'length' lambda from hanoi example

This function is now a builtin.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Get lambdakey and nucleo-32 building again
Keith Packard [Tue, 15 Nov 2016 18:18:12 +0000 (10:18 -0800)]
altos/lisp: Get lambdakey and nucleo-32 building again

Remove exti from the build list to make things fit.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Evaluate macros once, then smash them into place
Keith Packard [Tue, 15 Nov 2016 17:55:22 +0000 (09:55 -0800)]
altos/lisp: Evaluate macros once, then smash them into place

This assumes that macros are all pure functions, which should be true
for syntactic macros.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add license to hanoi demo
Keith Packard [Tue, 15 Nov 2016 07:04:05 +0000 (23:04 -0800)]
altos/lisp: Add license to hanoi demo

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Improve hanoi demo
Keith Packard [Tue, 15 Nov 2016 05:27:41 +0000 (21:27 -0800)]
altos/lisp: Improve hanoi demo

Repaint in place, without first clearing. This makes the updates a lot
clealyer looking.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Show number of collect calls in ao_lisp_test
Keith Packard [Tue, 15 Nov 2016 05:27:03 +0000 (21:27 -0800)]
altos/lisp: Show number of collect calls in ao_lisp_test

This helps tune the allocator

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Cache freed cons and stack items
Keith Packard [Tue, 15 Nov 2016 05:25:38 +0000 (21:25 -0800)]
altos/lisp: Cache freed cons and stack items

Track freed cons cells and stack items from the eval process where
possible so that they can be re-used without needing to collect.

This dramatically reduces the number of collect calls.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Simplify GC a bit by only marking the head of each object
Keith Packard [Tue, 15 Nov 2016 03:55:36 +0000 (19:55 -0800)]
altos/lisp: Simplify GC a bit by only marking the head of each object

We don't need to mark the whole object now as we're getting
information about where objects are by walking the tree each time
around the loop; ao_lisp_busy is only useful for terminating the walk
now.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Change GC to do moves in batches of 32
Keith Packard [Tue, 15 Nov 2016 02:45:12 +0000 (18:45 -0800)]
altos/lisp: Change GC to do moves in batches of 32

This should make it quite a bit faster than doing one at a time.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/stmf0: Add a comment about the requirements for using ao_flash_stm
Keith Packard [Sat, 12 Nov 2016 07:38:03 +0000 (23:38 -0800)]
altos/stmf0: Add a comment about the requirements for using ao_flash_stm

Need HSI clock and the flashing functions loaded in ram.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lambdakey: Get save/restore working
Keith Packard [Sat, 12 Nov 2016 07:36:22 +0000 (23:36 -0800)]
altos/lambdakey: Get save/restore working

Need the HSI clock running for the flash hardware to work.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Append a CRC to the saved image to validate on restore
Keith Packard [Sat, 12 Nov 2016 07:34:54 +0000 (23:34 -0800)]
altos/lisp: Append a CRC to the saved image to validate on restore

The CRC is actually of the ROM bits, so we can tell if the restored
image relates to the currently running code.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add save/restore to ao_lisp_test
Keith Packard [Sat, 12 Nov 2016 05:18:50 +0000 (21:18 -0800)]
altos/lisp: Add save/restore to ao_lisp_test

Allow testing of the save/restore code under Linux.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add save/restore infrastructure. Needs OS support to work.
Keith Packard [Sat, 12 Nov 2016 05:16:09 +0000 (21:16 -0800)]
altos/lisp: Add save/restore infrastructure. Needs OS support to work.

This sticks a few globals past the end of the heap and then asks the
OS to save the heap. On restore, the heap is re-populated by the OS
and then various global variables reset.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Make sure memmove only happens once per object. Other GC fixes
Keith Packard [Sat, 12 Nov 2016 05:11:13 +0000 (21:11 -0800)]
altos/lisp: Make sure memmove only happens once per object. Other GC fixes

The memmove may be overlapping, so make sure it happens only once by
just checking whether move_size has been set, rather than looking at
ao_lisp_moving; that doesn't get set when moving a noted cons as that
still needs to be walked at a later time.

Fix up the various looping move functions to all use the same
pattern. Atom was busted.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Make ao_lisp_ref and ao_lisp_poly non-inline
Keith Packard [Sat, 12 Nov 2016 05:07:09 +0000 (21:07 -0800)]
altos/lisp: Make ao_lisp_ref and ao_lisp_poly non-inline

These functions are pretty large and end up consuming quite a bit of
space if inlined everywhere they are used.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Share mark function for mark and move
Keith Packard [Fri, 11 Nov 2016 08:28:57 +0000 (00:28 -0800)]
altos/lisp: Share mark function for mark and move

These two operations both wanted to walk the referenced objects;
sharing is caring.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: add length, pack, unpack and flush
Keith Packard [Fri, 11 Nov 2016 08:28:31 +0000 (00:28 -0800)]
altos/lisp: add length, pack, unpack and flush

lots more builtins

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Add towers of hanoi example
Keith Packard [Fri, 11 Nov 2016 07:31:10 +0000 (23:31 -0800)]
altos/lisp: Add towers of hanoi example

Uses vt100 escape sequences to animate the display even.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Deal with memory compation in the middle of operations
Keith Packard [Fri, 11 Nov 2016 07:29:21 +0000 (23:29 -0800)]
altos/lisp: Deal with memory compation in the middle of operations

Handle memory compaction in places where we've got pointers into the
heap across an allocation operation. Either re-compute the values from
managed global references or add new roots across the allocation.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Improve lisp test program UI
Keith Packard [Fri, 11 Nov 2016 07:28:26 +0000 (23:28 -0800)]
altos/lisp: Improve lisp test program UI

Add a prompt for stdin, read from other files on command line before
stdin.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Make read() return eof atom on end of file
Keith Packard [Fri, 11 Nov 2016 07:25:56 +0000 (23:25 -0800)]
altos/lisp: Make read() return eof atom on end of file

Also make it an exception to hit eof in the middle of an sexpr.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: use regular read-eval-print loop for make const
Keith Packard [Fri, 11 Nov 2016 07:24:11 +0000 (23:24 -0800)]
altos/lisp: use regular read-eval-print loop for make const

No need to open code this sequence of operations.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: add progn, while, read and eval
Keith Packard [Thu, 10 Nov 2016 19:30:55 +0000 (11:30 -0800)]
altos/lisp: add progn, while, read and eval

Progn as a builtin will help with tail-recursion.
while provides for loops until tail-recursion works :-)
read and eval are kinda useful.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Clean up OS integration bits, add defun
Keith Packard [Thu, 10 Nov 2016 00:22:43 +0000 (16:22 -0800)]
altos/lisp: Clean up OS integration bits, add defun

Provide an abstraction for the OS interface so that it
can build more cleanly on Linux and AltOS. Add defun macro.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: macros appear to work now
Keith Packard [Wed, 9 Nov 2016 19:13:58 +0000 (11:13 -0800)]
altos/lisp: macros appear to work now

Needed an extra stack frame to stash the pre-macro state. This
simplified macro processing quite a bit; a macro now just evaluates
the function and then sends that result to be evaluated again.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: working on lexical scoping
Keith Packard [Wed, 9 Nov 2016 17:14:50 +0000 (09:14 -0800)]
altos/lisp: working on lexical scoping

Not working yet

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lambdakey-v1.0: Tweak memory allocations
Keith Packard [Mon, 7 Nov 2016 05:47:31 +0000 (21:47 -0800)]
altos/lambdakey-v1.0: Tweak memory allocations

With non-recursive GC, more memory is available for the heap

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: convert GC to non-recursive
Keith Packard [Sun, 6 Nov 2016 18:53:46 +0000 (10:53 -0800)]
altos/lisp: convert GC to non-recursive

Use a boolean array to note cons cells which would otherwise recurse,
then loop until that array is empty.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: more GC issues. add patom
Keith Packard [Sun, 6 Nov 2016 00:53:15 +0000 (17:53 -0700)]
altos/lisp: more GC issues. add patom

Use global ao_lisp_stack instead of local stack so that gc
moves of that item work.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: make sure stack->formals_last gets moved during GC
Keith Packard [Sat, 5 Nov 2016 22:12:05 +0000 (15:12 -0700)]
altos/lisp: make sure stack->formals_last gets moved during GC

Failing this leads to broken formals chains

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Change GC move API
Keith Packard [Sat, 5 Nov 2016 21:51:58 +0000 (14:51 -0700)]
altos/lisp: Change GC move API

Pass reference to move API so it can change the values in-place, then
let it return '1' when the underlying object has already been moved to
shorten GC times.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: get builtin macros working again
Keith Packard [Fri, 4 Nov 2016 23:51:12 +0000 (16:51 -0700)]
altos/lisp: get builtin macros working again

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos/lisp: Start rewriting eval as state machine
Keith Packard [Fri, 4 Nov 2016 23:31:34 +0000 (16:31 -0700)]
altos/lisp: Start rewriting eval as state machine

Ad-hoc code was incomprehensible and I couldn't make 'cond' work, so
I'm starting over.

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Add lambdakey
Keith Packard [Fri, 4 Nov 2016 04:51:26 +0000 (21:51 -0700)]
altos: Add lambdakey

Signed-off-by: Keith Packard <keithp@keithp.com>
7 years agoaltos: Add lambda support to lisp
Keith Packard [Fri, 4 Nov 2016 04:49:50 +0000 (21:49 -0700)]
altos: Add lambda support to lisp

Signed-off-by: Keith Packard <keithp@keithp.com>