ShiboSoftwareDev/am69-pi5
A 85×56 mm 10-layer AM69A single-board computer carrier integrates 8 GiB LPDDR4, 32 GB eMMC, Pi-style expansion and multimedia/USB/Ethernet connectors, multi-rail PMIC power, STM32 boot/power control, USB-C PD, SD/fan protection, and HDI-controlled high-speed routing.
- Version
- 0.0.8-engineering-draft-20261107-dqs19
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone ShiboSoftwareDev/am69-pi5 # download the package files into ./am69-pi5
tsci add ShiboSoftwareDev/am69-pi5 # add it to your project as @tsci/ShiboSoftwareDev.am69-pi5In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
firmware/boot-controller/test_policy.c
#include "policy.h"
#include "protocol.h"
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
static EcInputs good={.carrier_enable=true,.aon_ok=true};
static void tick(EcPolicy *e,EcInputs *in,uint32_t *now,unsigned count) {
for(unsigned i=0;i<count;i++)ec_step(e,in,++*now);
}
static void start(EcPolicy *e,EcInputs *in,uint32_t *now,bool pi) {
ec_init(e,pi,*now);tick(e,in,now,100);assert(e->state==EC_STRAPS&&!e->run);
tick(e,in,now,50);assert(e->state==EC_STARTING&&e->run&&e->straps&&!e->runtime_bus);
in->por_high=true;tick(e,in,now,30);assert(e->state==EC_STARTING);
tick(e,in,now,1);assert(e->state==EC_ON&&e->run&&e->runtime_bus&&!e->straps);
}
static void frame(uint8_t *f,uint8_t cmd,uint16_t value) {
f[0]=0xa5;f[1]=0x5a;f[2]=cmd;f[3]=0x42;f[4]=(uint8_t)value;f[5]=(uint8_t)(value>>8);
uint16_t c=ec_crc16(f+2,4);f[6]=(uint8_t)c;f[7]=(uint8_t)(c>>8);
}
int main(void) {
// Independent expected vectors from SPRUJ52E Tables 4-2/3/8/9/37/39/46.
assert(ec_mcu_boot_word(BOOT_EMMC)==0x308&&ec_main_boot_word(BOOT_EMMC)==0x03);
assert(ec_mcu_boot_word(BOOT_USB)==0x310&&ec_main_boot_word(BOOT_USB)==0x03);
assert(ec_mcu_boot_word(BOOT_SD)==0x300&&ec_main_boot_word(BOOT_SD)==0x43);
assert(ec_crc16((const uint8_t *)"123456789",9)==0x29b1);
EcPolicy e;EcInputs in=good;uint32_t now=0;start(&e,&in,&now,true);assert(e.boot==BOOT_EMMC);
assert(ec_fan_command(&e,0,now));tick(&e,&in,&now,4999);assert(e.fan_percent==0);
tick(&e,&in,&now,1);assert(e.fan_percent==100);assert(!ec_fan_command(&e,101,now));
in.button_pressed=true;tick(&e,&in,&now,4000);assert(e.state==EC_ON&&e.key_irq);
tick(&e,&in,&now,1);assert(e.state==EC_OFF&&!e.run&&!e.runtime_bus);
in.por_high=false;in.button_pressed=false;tick(&e,&in,&now,1000);assert(e.state==EC_OFF);
in.button_pressed=true;tick(&e,&in,&now,1);assert(e.state==EC_STRAPS);
// Carrier low/high independently restarts after user shutdown.
in.carrier_enable=false;tick(&e,&in,&now,1);assert(e.state==EC_OFF&&!e.run);
in.carrier_enable=true;in.button_pressed=false;tick(&e,&in,&now,100);assert(e.state==EC_STRAPS);
// USB recovery overrides the SD-card preference; CM5 never defaults to SD.
in=good;in.sd_present=true;now=0;start(&e,&in,&now,true);assert(e.boot==BOOT_SD);
in=good;in.sd_present=true;in.force_usb=true;now=0;start(&e,&in,&now,true);assert(e.boot==BOOT_USB);
in=good;in.sd_present=true;now=0;start(&e,&in,&now,false);assert(e.boot==BOOT_EMMC);
in.host_off=true;tick(&e,&in,&now,1);assert(e.state==EC_OFF&&!e.run);
// Keep cooling if the PMIC fails to remove power, even past the cooldown.
tick(&e,&in,&now,30001);assert(e.state==EC_OFF&&e.fan_percent==100);
in.por_high=false;tick(&e,&in,&now,1);assert(e.fan_percent==0);
in.host_off=false;in.por_high=false;tick(&e,&in,&now,1000);assert(e.state==EC_OFF);
// A failed power-up never enables the UART/header or keeps RUN indefinitely.
in=good;now=0;ec_init(&e,true,now);tick(&e,&in,&now,1651);assert(e.state==EC_FAULT&&!e.run&&!e.runtime_bus);
// Fresh straps after a real POR loss; do not re-drive UART into a boot pin.
in=good;now=0;start(&e,&in,&now,true);in.por_high=false;tick(&e,&in,&now,1);
assert(e.state==EC_DISCHARGE&&!e.run&&!e.runtime_bus&&!e.straps);
tick(&e,&in,&now,100);assert(e.state==EC_STRAPS&&e.straps&&!e.run);
// CRC corruption and unknown commands cannot turn off or change the fan.
in=good;now=0;start(&e,&in,&now,true);EcProtocol p={0};uint8_t f[8],out[8];
frame(f,3,0);f[6]^=1;
for(unsigned i=0;i<8;i++)assert(!ec_protocol_feed(&p,&e,f[i],now,3000,out));
assert(e.state==EC_ON&&e.run);
frame(f,1,60);for(unsigned i=0;i<8;i++)assert(ec_protocol_feed(&p,&e,f[i],now,3000,out)==(i==7));
assert(e.fan_percent==60&&out[2]==0x81&&out[4]==60);
frame(f,5,0);for(unsigned i=0;i<8;i++)ec_protocol_feed(&p,&e,f[i],now,3000,out);
assert(out[2]==0x85&&((unsigned)out[4]|(unsigned)out[5]<<8)==3000);
// Check time arithmetic across the 32-bit millisecond rollover.
in=good;now=UINT32_MAX-120;start(&e,&in,&now,true);assert(e.state==EC_ON);
// Adversarial state/input sequences: supply/carrier gating always dominates.
uint32_t random=1;ec_init(&e,true,0);
for(now=1;now<100000;now++) {
random=random*1664525u+1013904223u;
in=(EcInputs){.aon_ok=(random&127)!=0,.carrier_enable=(random&63)!=0,
.por_high=!!(random&128),.button_pressed=!!(random&256),.host_off=(random&1023)==0,
.sd_present=!!(random&2048),.force_usb=!!(random&4096)};
ec_step(&e,&in,now);
assert(!e.runtime_bus||(e.state==EC_ON&&e.run&&!e.straps));
if(!in.aon_ok||!in.carrier_enable)assert(!e.run&&!e.runtime_bus);
assert(e.fan_percent<=100);
}
puts("PASS: ROM vectors, power gating, strap timing, recovery, button/off policy, fan timeout, protocol CRC and rollover/adversarial sequences");
}