Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update avr bits for new compiler #100

Merged
merged 30 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1a95141
.github: Fix caching of dockerfile
keith-packard Nov 21, 2024
8c9a4a6
Use C99 flexible arrays
keith-packard Nov 13, 2024
2a0064c
Make param to snek_code_add_string const
keith-packard Nov 13, 2024
1d0a122
Make snek_move_block_addr static
keith-packard Nov 13, 2024
54f1b81
Only all NL as statement terminator
keith-packard Nov 20, 2024
e4009c7
chips/samd21: Fix regex usage in uf2conv.py
keith-packard Oct 27, 2024
8706b69
chips/samd21: save/restore neopixel list across alloc
keith-packard Nov 16, 2024
dc6a4f4
chips/samd21: minor cleanup in snek-gpio.c
keith-packard Nov 20, 2024
1d266f0
ports/narrow-1284: Clean up smaller math builtin list
keith-packard Oct 27, 2024
8799b68
Move AVR compile options to chips defs files
keith-packard Nov 13, 2024
b4dbabe
chips/atmega: Adapt to more recent avr libc
keith-packard Nov 13, 2024
43e6240
Switch atmega32u4 devices to ubaboot
keith-packard Nov 18, 2024
9fc0e62
uduino: Remove unused defines in ao-pins.h
keith-packard Nov 18, 2024
7ec6882
Use __flash for AVR code instead of PROGMEM
keith-packard Nov 20, 2024
df5345e
atmega328p: Increase pool and value stack
keith-packard Nov 20, 2024
c6fd041
chips/atmega: Handle EEPROM that doesn't start at 0
keith-packard Nov 20, 2024
8315084
chips/atmega: Support newer avr-libc
keith-packard Nov 20, 2024
660ba88
Enable more features due to newer avr-gcc version
keith-packard Nov 20, 2024
688d768
Remove -big versions of ATmega328p ports
keith-packard Nov 20, 2024
07fe111
chips/avr: Add test for strfromg
keith-packard Nov 20, 2024
23f056f
ports/nano-every: Define LED constant
keith-packard Nov 20, 2024
071ef42
ports/nano-every: Use custom avr-libc
keith-packard Nov 20, 2024
5879459
Add smaller set of math builtins
keith-packard Nov 21, 2024
44786b8
chips/atmega: Add flash writing code for ATmega4809
keith-packard Nov 21, 2024
dc2ec64
ports/nano-every: Use the new ATmega4809 flash driver for storage
keith-packard Nov 21, 2024
52df372
Stop processing comment when ^C is seen
keith-packard Nov 21, 2024
30d3949
examples: Update morse example
keith-packard Nov 21, 2024
ff496af
Check status of upload/install-otheros/otheros targets in Makefile
keith-packard Nov 21, 2024
817c9ae
ports/duemilanove: Create snek-$(BOARD)-install.in as needed
keith-packard Nov 21, 2024
746d0c2
.github: Use parallel build
keith-packard Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ RUN apt-get update && \
ruby-coderay \
gcc-arm-linux-gnueabi \
libc6-dev-armel-cross \
qemu-system-arm \
qemu-system-misc \
qemu-system-arm \
black \
python3-pip \
python3-serial \
@@ -35,8 +35,3 @@ RUN apt-get update && \
icnsutils \
black && \
pip3 install --break-system-packages pynsist

RUN mkdir snek
COPY ./ snek/

WORKDIR ./snek
16 changes: 10 additions & 6 deletions .github/workflows/snek.yml
Original file line number Diff line number Diff line change
@@ -70,16 +70,20 @@ jobs:
docker load -i $IMAGE_FILE
docker images -a $IMAGE

- name: 'Create install destinationn'
- name: 'Create install destination'
run: |
mkdir `pwd`/artifacts
mkdir -p artifacts

- name: 'Build snek'
run: |
docker run --rm \
--mount type=bind,source=`pwd`/artifacts,destination=/artifacts \
snek \
make DESTDIR=/artifacts PREFIX=/opt/snek SNEK_OTHEROS=1 SNEK_RISCV_TEST=1 black check install install-otheros
docker run \
-v $(readlink -f snek):/snek \
-v $(readlink -f artifacts):/artifacts \
-w /snek \
$IMAGE \
make DESTDIR=/artifacts PREFIX=/opt/snek SNEK_OTHEROS=1 \
SNEK_RISCV_TEST=1 -j$(nproc) \
black check install install-otheros

- name: 'Upload results'
uses: actions/upload-artifact@v4
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ubaboot"]
path = ubaboot
url = https://github.com/keith-packard/ubaboot.git
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -35,24 +35,24 @@ check: all
+cd test && make $@

black:
+black --check --exclude 'fail-syntax-.*\.py|.*/hosts/.*.py' .
+black --check --exclude 'fail-syntax-.*\.py|.*/hosts/.*.py|ubaboot.py' .

black-reformat:
+black --exclude 'fail-syntax-.*\.py|.*/hosts/.*.py' .
+black --exclude 'fail-syntax-.*\.py|.*/hosts/.*.py|ubaboot.py' .

install: all
+for dir in $(SUBDIRS); do (cd $$dir && make PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) $@) || exit 1; done
+for snek in $(SNEKS); do (cd `dirname $$snek` && make PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) $@) || exit 1; done

upload: otheros
+cd doc && make upload
+for otheros in $(SNEK_OTHEROS_DIR); do (cd "$$otheros" && make upload); done
+for otheros in $(SNEK_OTHEROS_DIR); do (cd "$$otheros" && make upload) || exit 1; done

install-otheros: otheros install
+for otheros in $(SNEK_OTHEROS_DIR); do (cd "$$otheros" && make install-otheros); done
+for otheros in $(SNEK_OTHEROS_DIR); do (cd "$$otheros" && make install-otheros) || exit 1; done

otheros: all
+for otheros in $(SNEK_OTHEROS_DIR); do (cd "$$otheros" && make); done
+for otheros in $(SNEK_OTHEROS_DIR); do (cd "$$otheros" && make) || exit 1; done

snek-mu.py:
find . -name '*.builtin' -print0 | xargs -0 python3 ./snek-builtin.py --mu -o $@
2 changes: 1 addition & 1 deletion ao/ao-product.c
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@
#define NUM_INTERFACES (AO_USB_HAS_INT + 1)

/* USB descriptors in one giant block of bytes */
const uint8_t ao_usb_descriptors [] =
CONST uint8_t ao_usb_descriptors [] =
{
/* Device descriptor */
0x12,
4 changes: 1 addition & 3 deletions ao/ao-usb.h
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ ao_usb_disable(void);
void
ao_usb_init(void);

extern const uint8_t ao_usb_descriptors [];
extern CONST uint8_t ao_usb_descriptors [];

#define AO_USB_SETUP_DIR_MASK (0x01 << 7)
#define AO_USB_SETUP_TYPE_MASK (0x03 << 5)
@@ -159,8 +159,6 @@ struct ao_usb_line_coding {
uint8_t data_bits;
} ;

extern struct ao_usb_line_coding ao_usb_line_coding;

extern uint8_t ao_usb_running;

#endif /* _AO_USB_H_ */
4 changes: 2 additions & 2 deletions chips/atmega/snek-328p.builtin
Original file line number Diff line number Diff line change
@@ -34,10 +34,10 @@ A4, -2, 18
A5, -2, 19
#include <snek-atmega.h>
#if !defined(SNEK_POOL)
#define SNEK_POOL 900
#define SNEK_POOL 1024
#endif
#define SNEK_MAX_TOKEN 63
#define VALUE_STACK_SIZE 16
#define VALUE_STACK_SIZE 32
#ifndef PARSE_STACK_SIZE
#define PARSE_STACK_SIZE 128
#endif
13 changes: 7 additions & 6 deletions chips/atmega/snek-328p.c
Original file line number Diff line number Diff line change
@@ -181,7 +181,7 @@ has_pwm(uint8_t p)
return pwm_pins & (1 << p);
}

static volatile uint8_t * const PROGMEM ocr_reg_addrs[] = {
static volatile uint8_t * CONST ocr_reg_addrs[] = {
[3] = &OCR2B,
[5] = &OCR0B,
[6] = &OCR0A,
@@ -192,10 +192,10 @@ static volatile uint8_t * const PROGMEM ocr_reg_addrs[] = {

static volatile uint8_t *
ocr_reg(uint8_t pin) {
return (volatile uint8_t *) pgm_read_word(&ocr_reg_addrs[pin]);
return ocr_reg_addrs[pin];
}

static volatile uint8_t * const PROGMEM tcc_reg_addrs[] = {
static volatile uint8_t * CONST tcc_reg_addrs[] = {
[3] = &TCCR2A,
[5] = &TCCR0A,
[6] = &TCCR0A,
@@ -206,10 +206,10 @@ static volatile uint8_t * const PROGMEM tcc_reg_addrs[] = {

static volatile uint8_t *
tcc_reg(uint8_t pin) {
return (volatile uint8_t *) pgm_read_word(&tcc_reg_addrs[pin]);
return tcc_reg_addrs[pin];
}

static uint8_t const PROGMEM tcc_val_addrs[] = {
static uint8_t CONST tcc_val_addrs[] = {
[3] = 1 << COM2B1,
[5] = 1 << COM0B1,
[6] = 1 << COM0A1,
@@ -221,7 +221,7 @@ static uint8_t const PROGMEM tcc_val_addrs[] = {
static uint8_t
tcc_val(uint8_t pin)
{
return (uint8_t) pgm_read_byte(&tcc_val_addrs[pin]);
return tcc_val_addrs[pin];
}

static void
@@ -381,6 +381,7 @@ snek_poly_t
snek_builtin_setpower(snek_poly_t a)
{
float p = snek_poly_get_float(a);
printf("%p\n", &p);
if (p < 0.0f) p = 0.0f;
if (p > 1.0f) p = 1.0f;
power[power_pin] = (uint8_t) (p * 255.0f + 0.5f);
10 changes: 7 additions & 3 deletions chips/atmega/snek-atmega-eeprom.c
Original file line number Diff line number Diff line change
@@ -16,6 +16,10 @@
#include "snek-io.h"
#include <avr/eeprom.h>

#ifndef EEPROM_SIZE
#define EEPROM_SIZE (E2END + 1)
#endif

snek_poly_t
snek_builtin_eeprom_write(void)
{
@@ -28,7 +32,7 @@ snek_builtin_eeprom_write(void)
c = 0xff;
eeprom_write_byte((uint8_t *) addr, c);
addr++;
if (addr == (E2END + 1))
if (addr == EEPROM_SIZE)
break;
if (c == 0xff)
break;
@@ -46,7 +50,7 @@ snek_builtin_eeprom_show(uint8_t nposition, uint8_t nnamed, snek_poly_t *args)
(void) args;
if (nposition)
putc('b' & 0x1f, stdout);
for (addr = 0; addr <= E2END; addr++) {
for (addr = 0; addr < EEPROM_SIZE; addr++) {
c = eeprom_read_byte((uint8_t *) addr);
if (c == 0xff)
break;
@@ -71,7 +75,7 @@ int
snek_eeprom_getchar(FILE *stream)
{
(void) stream;
if (snek_eeprom_addr <= E2END && !snek_abort) {
if (snek_eeprom_addr < EEPROM_SIZE && !snek_abort) {
uint8_t c = eeprom_read_byte((uint8_t *) (snek_eeprom_addr++));
if (c != 0xff)
return c;
187 changes: 187 additions & 0 deletions chips/atmega/snek-atmega-flash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright © 2024 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 3 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 "snek.h"
#include "snek-io.h"
#include <avr/io.h>
#include <stddef.h>

static uint8_t *flash_write_addr;
static bool flash_write_page_pending;

static inline uint8_t *
flash_start(void)
{
uint8_t append = FUSE_APPEND;

if (append == 0)
return NULL;
return (uint8_t *) (MAPPED_PROGMEM_START + append * 256);
}

static inline uint8_t *
flash_end(void)
{
return (uint8_t *) MAPPED_PROGMEM_END;
}

static inline ptrdiff_t
flash_size(void)
{
uint8_t *start = flash_start();
if (!start)
return 0;
return (flash_end() - start) + 1;
}

static inline bool
flash_start_of_page(uint8_t *addr) {
return ((uintptr_t) addr & (PROGMEM_PAGE_SIZE - 1)) == 0;
}

static inline bool
flash_end_of_page(uint8_t *addr) {
return (((uintptr_t) addr + 1) & (PROGMEM_PAGE_SIZE - 1)) == 0;
}

static inline uint8_t *
flash_page_addr(uint8_t *addr) {
return (uint8_t *) ((uintptr_t) addr & ~(PROGMEM_PAGE_SIZE - 1));
}

static bool
flash_write_full(void)
{
return flash_write_addr == flash_end();
}

static void
flash_cmd(uint8_t cmd)
{
while (NVMCTRL.STATUS & (NVMCTRL_FBUSY_bm|NVMCTRL_EEBUSY_bm));
_PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, cmd);
while (NVMCTRL.STATUS & (NVMCTRL_FBUSY_bm|NVMCTRL_EEBUSY_bm));
}

static void
flash_write_init(void)
{
flash_write_addr = flash_start();
flash_write_page_pending = false;
flash_cmd(NVMCTRL_CMD_PAGEBUFCLR_gc);
}

static void
flash_write_flush(void)
{
if (flash_write_page_pending) {
flash_write_page_pending = false;
/*
* Wait for an ENQ to appear in the input buffer. Once
* that is there, the sender will stop transmitting
* until we reply with an ACK, and that won't happen
* until we read the ENQ from the input buffer, so we
* can safely stop the CPU while writing flash without
* dropping any incoming data. Give up if not seen within
* a few dozen ms; that will happen when the sender is
* done sending commands.
*/
snek_uart_wait_queued('e' & 0x1f, U_TICKS_PER_SECOND / 16);
flash_cmd(NVMCTRL_CMD_PAGEERASEWRITE_gc);
}
}

static void
flash_write_byte(uint8_t byte)
{
*flash_write_addr = byte;
flash_write_page_pending = true;
if (flash_end_of_page(flash_write_addr))
flash_write_flush();
flash_write_addr++;
}

static uint8_t
flash_read_byte(uint8_t *addr)
{
return *addr;
}

snek_poly_t
snek_builtin_eeprom_write(void)
{
uint8_t c;

flash_write_init();
for(;;) {
c = snek_raw_getc(stdin);
if (c == ('d' & 0x1f))
c = 0xff;
flash_write_byte(c);
if (flash_write_full())
break;
if (c == 0xff)
break;
}
flash_write_flush();
return SNEK_NULL;
}

snek_poly_t
snek_builtin_eeprom_show(uint8_t nposition, uint8_t nnamed, snek_poly_t *args)
{
uint8_t c;
uint8_t *addr;

(void) nnamed;
(void) args;
if (nposition)
putc('b' & 0x1f, stdout);
for (addr = flash_start(); addr <= flash_end(); addr++) {
c = flash_read_byte(addr);
if (c == 0xff)
break;
putc(c, stdout);
}
if (nposition)
putc('c' & 0x1f, stdout);
return SNEK_NULL;
}

snek_poly_t
snek_builtin_eeprom_erase(void)
{
if (flash_read_byte(0) != 0xff) {
flash_write_init();
flash_write_byte(0xff);
flash_write_flush();
}
return SNEK_NULL;
}

static ptrdiff_t snek_flash_off;

int
snek_eeprom_getchar(FILE *stream)
{
(void) stream;
if (snek_flash_off < flash_size() && !snek_abort) {
uint8_t c = flash_read_byte(flash_start() + snek_flash_off++);
if (c != 0xff)
return c;
}
snek_interactive = true;
snek_duino_file.get = snek_io_getc;
return EOF;
}
Loading