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-pi5

In 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/policy.c

#include "policy.h"

static uint32_t elapsed(uint32_t now, uint32_t then) { return now-then; }
uint16_t ec_mcu_boot_word(EcBoot boot) {
  return boot==BOOT_EMMC ? 0x308u : boot==BOOT_USB ? 0x310u : 0x300u;
}
uint8_t ec_main_boot_word(EcBoot boot) { return boot==BOOT_SD ? 0x43u : 0x03u; }

void ec_init(EcPolicy *e, bool pi_board, uint32_t now) {
  *e=(EcPolicy){.state=EC_OFF,.boot=BOOT_EMMC,.pi_board=pi_board,
    .fan_percent=100,.since=now,.off_at=now,.start_pending=true};
}
static void off(EcPolicy *e, EcState state, uint32_t now) {
  e->state=state;e->run=false;e->runtime_bus=false;e->straps=false;e->key_irq=false;
  e->since=now;e->off_at=now;e->por_seen=false;e->fan_command_valid=false;
  e->fan_percent=100;
}
static void prepare(EcPolicy *e, const EcInputs *in, uint32_t now) {
  e->boot=in->force_usb ? BOOT_USB : e->pi_board && in->sd_present ? BOOT_SD : BOOT_EMMC;
  e->state=EC_STRAPS;e->straps=true;e->runtime_bus=false;e->run=false;
  e->start_pending=false;e->reboot_pending=false;e->since=now;e->fan_percent=100;
}
void ec_step(EcPolicy *e, const EcInputs *in, uint32_t now) {
  bool carrier_rise=in->carrier_enable&&!e->last_carrier;
  bool press=in->button_pressed&&!e->last_button;
  e->last_carrier=in->carrier_enable;e->last_button=in->button_pressed;
  if(press)e->button_since=now;
  if(!in->aon_ok) { off(e,EC_FAULT,now);e->start_pending=false;return; }
  if(!in->carrier_enable) {
    if(e->state!=EC_OFF)off(e,EC_OFF,now);
    e->start_pending=false;e->fan_percent=in->por_high||elapsed(now,e->off_at)<30000?100:0;return;
  }
  if(carrier_rise || ((e->state==EC_OFF||e->state==EC_FAULT)&&press)) {
    e->start_pending=true;e->retries=0;
  }
  if(e->state==EC_OFF||e->state==EC_FAULT) {
    // After loss/reset, wait for a real low POR and discharge interval.
    if(e->start_pending && !in->por_high && elapsed(now,e->since)>=100)prepare(e,in,now);
  } else if(e->state==EC_STRAPS) {
    if(in->por_high) { off(e,EC_FAULT,now);e->start_pending=false; }
    else if(elapsed(now,e->since)>=50) { e->state=EC_STARTING;e->run=true;e->since=now; }
  } else if(e->state==EC_STARTING) {
    if(in->por_high) {
      if(!e->por_seen){e->por_seen=true;e->por_since=now;}
      if(elapsed(now,e->por_since)>=30) {
        e->state=EC_ON;e->straps=false;e->runtime_bus=true;e->since=now;
      }
    } else e->por_seen=false;
    if(e->state==EC_STARTING&&elapsed(now,e->since)>=1500)off(e,EC_FAULT,now);
  } else if(e->state==EC_ON) {
    if(elapsed(now,e->since)>=10000)e->retries=0;
    e->key_irq=in->button_pressed;
    if(in->host_off || (in->button_pressed&&elapsed(now,e->button_since)>=4000)) {
      off(e,EC_OFF,now);e->start_pending=false;
    } else if(!in->por_high) {
      // A real POR needs fresh straps. Stop UART before lowering RUN in HAL.
      off(e,EC_DISCHARGE,now);e->reboot_pending=true;
      if(++e->retries>=3){e->state=EC_FAULT;e->reboot_pending=false;}
    }
  } else if(e->state==EC_DISCHARGE) {
    if(!in->por_high&&elapsed(now,e->since)>=100)prepare(e,in,now);
    else if(elapsed(now,e->since)>=2000){off(e,EC_FAULT,now);e->reboot_pending=false;}
  }
  if(e->state==EC_ON) {
    if(!e->fan_command_valid||elapsed(now,e->fan_command_at)>=5000)e->fan_percent=100;
  } else if(e->state==EC_OFF||e->state==EC_FAULT) {
    e->fan_percent=in->por_high||elapsed(now,e->off_at)<30000 ? 100 : 0;
  } else e->fan_percent=100;
}
bool ec_fan_command(EcPolicy *e,unsigned duty,uint32_t now) {
  if(e->state!=EC_ON||duty>100)return false;
  e->fan_percent=(uint8_t)duty;e->fan_command_at=now;e->fan_command_valid=true;return true;
}
bool ec_off_command(EcPolicy *e,bool reboot,uint32_t now) {
  if(e->state!=EC_ON)return false;
  off(e,reboot?EC_DISCHARGE:EC_OFF,now);e->reboot_pending=reboot;e->start_pending=false;return true;
}