palm-client: SB-LoRa Test (Options menu) for board bring-up: the slot's chip selects, which address mapping reaches the SC16IS740 (connector A0 = CPU A1 or A0, with what each read back), its registers after a reset, a 64-byte internal UART loopback, the slot interrupt (the same loopback through the handler) and a DEVICE_QUERY to the radio. Nothing goes over the air; the bus is only touched once the OS reports a module. Host tests cover the mapping and loopback

This commit is contained in:
rich committed 2026-11-08 18:18:54 -05:00
1 parent 8fa23f94f9
commit bd9d9ce951
11 files changed
+493 -26

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ APP = visormesh
NAME = VisorMesh
CREATOR = VMsh
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/title.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c src/reaction_fmt.c src/reactions.c src/rxpath.c src/msg_menu.c src/protocol2.c src/info_fmt.c src/stats_form.c src/packets_form.c src/trace_form.c src/blocks.c src/beam.c src/beam_rx.c src/stale.c src/convo_extra.c src/neigh.c
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/title.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c src/reaction_fmt.c src/reactions.c src/rxpath.c src/msg_menu.c src/protocol2.c src/info_fmt.c src/stats_form.c src/sb_test.c src/packets_form.c src/trace_form.c src/blocks.c src/beam.c src/beam_rx.c src/stale.c src/convo_extra.c src/neigh.c
OBJS = $(SRCS:src/%.c=build/%.o)
CC = m68k-palmos-gcc
+17
View File
@@ -40,6 +40,7 @@ BEGIN
MENUITEM "Preferences..." ID MainMenuSounds "R"
MENUITEM "-" AUTOID
MENUITEM "Serial Ports..." ID MainMenuPorts "I"
MENUITEM "SB-LoRa Test" ID MainMenuSbTest
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
MENUITEM "Screenshot" ID MainMenuShot "Z"
MENUITEM "Screenshot in 5 s" ID MainMenuShotLater "D"
@@ -74,6 +75,7 @@ BEGIN
MENUITEM "Preferences..." ID MainMenuSounds "R"
MENUITEM "-" AUTOID
MENUITEM "Serial Ports..." ID MainMenuPorts "I"
MENUITEM "SB-LoRa Test" ID MainMenuSbTest
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
MENUITEM "Screenshot" ID MainMenuShot "Z"
MENUITEM "Screenshot in 5 s" ID MainMenuShotLater "D"
@@ -107,6 +109,7 @@ BEGIN
MENUITEM "Preferences..." ID MainMenuSounds "R"
MENUITEM "-" AUTOID
MENUITEM "Serial Ports..." ID MainMenuPorts "I"
MENUITEM "SB-LoRa Test" ID MainMenuSbTest
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
MENUITEM "Screenshot" ID MainMenuShot "Z"
MENUITEM "Screenshot in 5 s" ID MainMenuShotLater "D"
@@ -149,6 +152,7 @@ BEGIN
MENUITEM "Preferences..." ID MainMenuSounds "R"
MENUITEM "-" AUTOID
MENUITEM "Serial Ports..." ID MainMenuPorts "I"
MENUITEM "SB-LoRa Test" ID MainMenuSbTest
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
MENUITEM "Screenshot" ID MainMenuShot "Z"
MENUITEM "Screenshot in 5 s" ID MainMenuShotLater "D"
@@ -197,6 +201,7 @@ BEGIN
MENUITEM "Preferences..." ID MainMenuSounds "R"
MENUITEM "-" AUTOID
MENUITEM "Serial Ports..." ID MainMenuPorts "I"
MENUITEM "SB-LoRa Test" ID MainMenuSbTest
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
MENUITEM "Screenshot" ID MainMenuShot "Z"
MENUITEM "Screenshot in 5 s" ID MainMenuShotLater "D"
@@ -248,6 +253,7 @@ BEGIN
MENUITEM "Preferences..." ID MainMenuSounds "R"
MENUITEM "-" AUTOID
MENUITEM "Serial Ports..." ID MainMenuPorts "I"
MENUITEM "SB-LoRa Test" ID MainMenuSbTest
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
MENUITEM "Screenshot" ID MainMenuShot "Z"
MENUITEM "Screenshot in 5 s" ID MainMenuShotLater "D"
@@ -699,6 +705,17 @@ BEGIN
BUTTON "Done" ID StatsDoneButton AT (1 147 AUTO AUTO)
END
/* SB-LoRa Test: the Springboard module, step by step (sb_test.c) */
FORM ID SbTestForm AT (0 0 160 160)
NOFRAME
USABLE
MENUID MainMenuBar
BEGIN
TITLE "SB-LoRa Test"
BUTTON "Done" ID SbTestDoneButton AT (1 147 AUTO AUTO)
BUTTON "Run Again" ID SbTestRunButton AT (PREVRIGHT+4 PREVTOP AUTO AUTO)
END
/* Heard Packets: the radio's RX log (packets_form.c) */
FORM ID PacketsForm AT (0 0 160 160)
NOFRAME
+3
View File
@@ -25,6 +25,7 @@
#include "bgcheck.h"
#include "shots.h"
#include "stats_form.h"
#include "sb_test.h"
#include "packets_form.h"
#include "trace_form.h"
#include "beam.h"
@@ -76,6 +77,7 @@ static Boolean HandleMenu(UInt16 itemID)
FrmCustomAlert(SettingsErrorAlert, "Open the channel you want to beam first.", "", "");
return true;
case MainMenuPorts: FrmGotoForm(PortsForm); return true;
case MainMenuSbTest: FrmGotoForm(SbTestForm); return true;
case MainMenuFontPreview: FrmGotoForm(FontPreviewForm); return true;
case MainMenuSounds: SoundsFormOpen(FrmGetActiveFormID()); return true;
case MainMenuAddChannel: FrmGotoForm(ChannelForm); return true;
@@ -123,6 +125,7 @@ static Boolean AppHandleEvent(EventType *event)
case ScopesForm: FrmSetEventHandler(form, ScopesFormHandleEvent); break;
case MapForm: FrmSetEventHandler(form, MapFormHandleEvent); break;
case StatsForm: FrmSetEventHandler(form, StatsFormHandleEvent); break;
case SbTestForm: FrmSetEventHandler(form, SbTestFormHandleEvent); break;
case PacketsForm: FrmSetEventHandler(form, PacketsFormHandleEvent); break;
case TraceForm: FrmSetEventHandler(form, TraceFormHandleEvent); break;
}
+5
View File
@@ -45,6 +45,7 @@
#define MapMenuBar 1032 /* Go, Map (Basemap, Neighbour Lines), Options */
#define MainMenuBasemap 1033
#define MainMenuNeighLines 1034
#define MainMenuSbTest 1035 /* Options: SB-LoRa Test (sb_test.c) */
#define MainStatsButton 1040
#define AboutAlert 1020
#define ConvoChanMenuBar 1014 /* Go, Edit, Channel (Add, Leave, Mute, Scope), Options */
@@ -202,6 +203,10 @@
#define PacketsFilterGroup 6
#define PacketAlert 2707
#define SbTestForm 3000
#define SbTestDoneButton 3001
#define SbTestRunButton 3002
#define TraceForm 2800
#define TraceField 2801
#define TraceAddButton 2802
+51 -16
View File
@@ -10,7 +10,7 @@ static void Select(const SbBus *b);
static void Deselect(const SbBus *b);
static UInt8 BusReadReg(const SbBus *b, UInt8 reg);
static void BusReadFifo(const SbBus *b, UInt8 *buf, UInt16 n);
static Boolean ScratchOk(void) VM_SECT3;
static Boolean ScratchOk(UInt8 got[2]) VM_SECT3;
static SbBus gBus = { SB_CS0_BASE, SB_CS0_BASE + SB_CS_SIZE, 0, 0 };
@@ -126,13 +126,13 @@ void SbDrainRx(SbRing *r)
}
}
static Boolean ScratchOk(void)
static Boolean ScratchOk(UInt8 got[2])
{
SbWriteReg(SB_SPR, 0x55);
if (SbReadReg(SB_SPR) != 0x55)
return false;
got[0] = SbReadReg(SB_SPR);
SbWriteReg(SB_SPR, 0xAA);
return SbReadReg(SB_SPR) == 0xAA;
got[1] = SbReadReg(SB_SPR);
return got[0] == 0x55 && got[1] == 0xAA;
}
void SbSetBase(UInt32 cs0, UInt32 csSize)
@@ -141,22 +141,57 @@ void SbSetBase(UInt32 cs0, UInt32 csSize)
gBus.cs1 = cs0 + csSize;
}
Boolean SbTryMapping(UInt8 shift, UInt8 got[2])
{
Boolean ok;
gBus.offNcs = 1UL << (17 + shift);
gBus.offMosi = 1UL << (8 + shift);
Deselect(&gBus);
ok = ScratchOk(got);
Deselect(&gBus);
return ok;
}
UInt8 SbMappingShift(void)
{
return gBus.offMosi == (1UL << 9) ? 1 : 0;
}
Boolean SbProbe(void)
{
UInt8 shift;
UInt8 got[2];
/* Connector A0 = CPU A1 first: the slot only does 16-bit, even-address cycles. */
for (shift = 1; ; shift--) {
gBus.offNcs = 1UL << (17 + shift);
gBus.offMosi = 1UL << (8 + shift);
Deselect(&gBus);
if (ScratchOk())
return true;
if (shift == 0)
break;
return SbTryMapping(1, got) || SbTryMapping(0, got);
}
/*
* 64 bytes at 115200 take 5.6 ms; a register read is a few hundred bus
* cycles, so this many reads is well past that without needing a timer.
*/
#define SB_LOOP_POLLS 4000
UInt16 SbLoopback(const UInt8 *out, UInt16 n, UInt8 *in)
{
UInt16 got = 0, polls, k;
if (n > SB_FIFO_SIZE)
n = SB_FIFO_SIZE;
SbWriteReg(SB_FCR, 0x07); /* empty both FIFOs */
SbWriteReg(SB_MCR, SB_MCR_LOOPBACK);
SbWriteFifo(out, n);
for (polls = 0; got < n && polls < SB_LOOP_POLLS; polls++) {
k = SbReadReg(SB_RXLVL);
if (k > n - got)
k = n - got;
if (k) {
SbReadFifo(in + got, k);
got += k;
}
}
Deselect(&gBus);
return false;
SbWriteReg(SB_MCR, 0);
return got;
}
void SbUartInit(void)
+19
View File
@@ -71,6 +71,25 @@ typedef struct {
*/
Boolean SbProbe(void) VM_SECT3;
/*
* For the module self-test: uses one mapping (connector A0 = CPU A(shift),
* shift 1 or 0) and keeps it. Writes 0x55 then 0xAA to the scratch register;
* got[] is what read back. Returns whether both matched.
*/
Boolean SbTryMapping(UInt8 shift, UInt8 got[2]) VM_SECT3;
/* The mapping in use: 1 if connector A0 is CPU A1, 0 if A0. */
UInt8 SbMappingShift(void) VM_SECT3;
#define SB_MCR_LOOPBACK 0x10 /* MCR bit 4: TX goes straight to RX inside the chip */
/*
* Internal loopback (needs SbUartInit first): sends n bytes (at most a FIFO's
* worth) with the chip's TX looped to its RX, reads back what arrives into
* in[] and turns loopback off again. Returns how many came back.
*/
UInt16 SbLoopback(const UInt8 *out, UInt16 n, UInt8 *in) VM_SECT3;
/* csSlot0's address and the size of each chip select; csSlot1 follows csSlot0. */
void SbSetBase(UInt32 cs0, UInt32 csSize) VM_SECT3;
+283
View File
@@ -0,0 +1,283 @@
/*
* SB-LoRa Test: each step's result is a line on the screen, and a step that
* fails ends the test, since the ones after it depend on it. The bus is only
* touched once the OS says a module is in the slot: with the slot empty, a
* bus access is a bus error that resets the Visor.
*/
#include <PalmOS.h>
#include "resources.h"
#include "session.h"
#include "transport.h"
#include "sb_spi.h"
#include "protocol.h"
#include "ui/draw.h"
#include "ui/text.h"
#include "sb_test.h"
static void Add(const Char *s) VM_SECT5;
static void Hex32(Char *out, UInt32 v) VM_SECT5;
static Boolean TestSlot(void) VM_SECT5;
static Boolean TestMapping(void) VM_SECT5;
static Boolean TestUart(void) VM_SECT5;
static Boolean TestLoopback(void) VM_SECT5;
static Boolean TestInterrupt(void) VM_SECT5;
static void TestRadio(void) VM_SECT5;
static void Run(void) VM_SECT5;
static void Draw(void) VM_SECT5;
#define TEST_LINES 10
#define TEST_LINE 48
#define TEST_BYTES SB_FIFO_SIZE
#define IRQ_WAIT (SysTicksPerSecond() / 2)
#define RADIO_WAIT (2 * SysTicksPerSecond())
static Char gLines[TEST_LINES][TEST_LINE];
static UInt16 gCount;
static UInt8 gPattern[TEST_BYTES], gBack[TEST_BYTES];
static VmFrameDecoder gDecoder;
static void Add(const Char *s)
{
if (gCount < TEST_LINES)
StrNCopy(gLines[gCount++], s, TEST_LINE - 1);
gLines[gCount - 1][TEST_LINE - 1] = 0;
Draw();
}
/* StrPrintF's %lx prints zeros on the Visor */
static void Hex32(Char *out, UInt32 v)
{
UInt8 b[4];
b[0] = (UInt8)(v >> 24);
b[1] = (UInt8)(v >> 16);
b[2] = (UInt8)(v >> 8);
b[3] = (UInt8)v;
TxtHex(b, 4, out);
}
static Boolean TestSlot(void)
{
UInt32 base = 0, size = 0;
Char line[TEST_LINE], hex[10];
switch (SbSlotState(&base, &size)) {
case SB_SLOT_NONE:
Add("No Springboard slot on this device.");
return false;
case SB_SLOT_EMPTY:
Add("Slot: empty. Insert the module and Run.");
return false;
case SB_SLOT_NO_CS:
Add("Slot: a module, but no chip selects.");
return false;
default:
break;
}
Hex32(hex, base);
StrPrintF(line, "Slot: CS0 at %s, %lu KB", hex, size / 1024);
Add(line);
return true;
}
/* Both mappings, so a wrong one shows what it read; the one that works is kept. */
static Boolean TestMapping(void)
{
UInt8 got[2];
Char line[TEST_LINE], hex[6];
Boolean ok[2];
Int16 shift;
for (shift = 1; shift >= 0; shift--) {
ok[shift] = SbTryMapping((UInt8)shift, got);
TxtHex(got, 2, hex);
StrPrintF(line, "A0 = CPU A%d: 55AA read %s%s", shift, hex, ok[shift] ? ", ok" : "");
Add(line);
}
if (!ok[0] && !ok[1]) {
Add("No answer from the SC16IS740.");
return false;
}
if (!ok[1])
SbTryMapping(0, got);
return true;
}
/* After a reset: 8N1, both FIFOs empty, the transmitter idle. */
static Boolean TestUart(void)
{
UInt8 r[3];
Char line[TEST_LINE], hex[8];
Boolean ok;
SbUartInit();
r[0] = SbReadReg(SB_LCR);
r[1] = SbReadReg(SB_LSR);
r[2] = SbReadReg(SB_TXLVL);
ok = r[0] == 0x03 && (r[1] & 0x60) == 0x60 && r[2] == SB_FIFO_SIZE;
TxtHex(r, 2, hex);
StrPrintF(line, "UART: LCR LSR %s, TX room %u%s", hex, r[2], ok ? ", ok" : "");
Add(line);
if (!ok)
Add("Expected 0360 and 64.");
return ok;
}
static Boolean TestLoopback(void)
{
UInt16 got, wrong = 0, i;
Char line[TEST_LINE];
for (i = 0; i < TEST_BYTES; i++)
gPattern[i] = (UInt8)(i * 37 + 1);
got = SbLoopback(gPattern, TEST_BYTES, gBack);
for (i = 0; i < got; i++)
if (gBack[i] != gPattern[i])
wrong++;
if (got == TEST_BYTES && wrong == 0) {
Add("Loopback: 64 bytes back, ok");
return true;
}
StrPrintF(line, "Loopback: %u of 64 back, %u wrong", got, wrong);
Add(line);
return false;
}
/*
* The same loopback through the transport: with the handler installed, the
* bytes only reach the ring if the slot interrupt fired.
*/
static Boolean TestInterrupt(void)
{
UInt32 until;
UInt16 got = 0, n;
Err err;
Char line[TEST_LINE];
if (SbTransportOpen() != errNone) {
Add("Interrupt: the link wouldn't open.");
return false;
}
SbTransportLoopback(true);
SysTaskDelay(2);
while (SbTransportRecv(gBack, TEST_BYTES, 0, &err))
; /* whatever the radio sent before loopback was on */
if (SbTransportSend(gPattern, TEST_BYTES) != errNone) {
SbTransportLoopback(false);
Add("Interrupt: sending stuck (TX FIFO).");
return false;
}
until = TimGetTicks() + IRQ_WAIT;
while (got < TEST_BYTES && (Int32)(until - TimGetTicks()) > 0) {
n = SbTransportRecv(gBack + got, TEST_BYTES - got, until - TimGetTicks(), &err);
got += n;
}
SbTransportLoopback(false);
if (!SbTransportIrq())
StrPrintF(line, "Polled (no interrupt handler): %u of 64", got);
else if (got == 0)
StrCopy(line, "Interrupt: none came. Check IRQ*.");
else
StrPrintF(line, "Interrupt: works, %u of 64 bytes", got);
Add(line);
return got == TEST_BYTES || !SbTransportIrq();
}
/* DEVICE_QUERY over the real UART: the radio's answer, nothing on the air. */
static void TestRadio(void)
{
UInt8 frame[VM_HEADER_LEN + 2];
UInt16 len = VmBuildDeviceQuery(frame, sizeof(frame)), n, i;
UInt32 until;
VmDeviceInfo info;
Err err;
Char line[TEST_LINE];
while (SbTransportRecv(gBack, TEST_BYTES, 0, &err))
;
VmDecoderReset(&gDecoder);
if (SbTransportSend(frame, len) != errNone) {
Add("Radio: sending stuck (TX FIFO).");
return;
}
until = TimGetTicks() + RADIO_WAIT;
while ((Int32)(until - TimGetTicks()) > 0) {
n = SbTransportRecv(gBack, TEST_BYTES, until - TimGetTicks(), &err);
for (i = 0; i < n; i++) {
if (!VmDecoderFeed(&gDecoder, gBack[i]) || gDecoder.len == 0 ||
gDecoder.payload[0] != VM_RESP_DEVICE_INFO)
continue;
if (VmParseDeviceInfo(gDecoder.payload, gDecoder.len, &info)) {
StrPrintF(line, "Radio: %s %s", info.manufacturer, info.version);
Add(line);
} else {
Add("Radio: answered, but the reply didn't parse.");
}
return;
}
}
Add("Radio: no answer. Powered? Firmware?");
}
static void Run(void)
{
gCount = 0;
Draw();
if (TransportGetPort() == VM_PORT_SBLORA && (SessionIsConnected() || SessionConnecting())) {
Add("The Slot link is in use: Disconnect first.");
return;
}
if (!TestSlot() || !TestMapping() || !TestUart() || !TestLoopback())
return;
if (TestInterrupt())
TestRadio();
SbTransportClose();
Add("Done.");
}
static void Draw(void)
{
FontID old = FntSetFont(vmSmallFont);
RectangleType r;
Coord y = 18;
UInt16 i;
RctSetRectangle(&r, 0, 16, 160, 128);
WinEraseRectangle(&r, 0);
if (gCount == 0)
DrawCut("Testing...", 3, y, 154);
for (i = 0; i < gCount; i++, y += VM_ROW_H)
DrawCut(gLines[i], 3, y, 154);
FntSetFont(old);
}
Boolean SbTestFormHandleEvent(EventType *event)
{
FormType *form = FrmGetActiveForm();
switch (event->eType) {
case frmOpenEvent:
FrmDrawForm(form);
Run();
return true;
case frmUpdateEvent:
if (event->data.frmUpdate.updateCode == frmRedrawUpdateCode) {
FrmDrawForm(form);
Draw();
}
return true;
case ctlSelectEvent:
if (event->data.ctlSelect.controlID == SbTestDoneButton) {
FrmGotoForm(MainForm);
return true;
}
if (event->data.ctlSelect.controlID == SbTestRunButton) {
Run();
return true;
}
break;
default:
break;
}
return false;
}
+16
View File
@@ -0,0 +1,16 @@
/*
* SB-LoRa Test (Options > SB-LoRa Test): checks a module in the Springboard
* slot step by step for board bring-up: the slot's chip selects, which
* address mapping reaches the SC16IS740, its registers, an internal UART
* loopback, the slot interrupt and a DEVICE_QUERY to the radio. Nothing is
* transmitted over the air.
*/
#ifndef VM_SB_TEST_H
#define VM_SB_TEST_H
#include <PalmOS.h>
#include "sections.h" /* this module is in the fifth code segment */
Boolean SbTestFormHandleEvent(EventType *event) VM_SECT5;
#endif
+15
View File
@@ -41,5 +41,20 @@ Err SbTransportOpen(void);
void SbTransportClose(void);
Err SbTransportSend(const UInt8 *buf, UInt16 len);
UInt16 SbTransportRecv(UInt8 *buf, UInt16 max, Int32 timeoutTicks, Err *errP);
/* Whether receiving is interrupt-driven (the slot handler installed) rather than polled. */
Boolean SbTransportIrq(void);
/* The module self-test: loops the UART's TX back to its RX inside the chip (nothing reaches the radio). */
void SbTransportLoopback(Boolean on);
/*
* What's in the Springboard slot, without touching the bus. With
* SB_SLOT_READY, base and size are the module's chip selects, and the SPI
* driver uses them.
*/
#define SB_SLOT_NONE 0 /* not a Handspring device */
#define SB_SLOT_EMPTY 1
#define SB_SLOT_NO_CS 2 /* a module, but the OS gave no chip-select window */
#define SB_SLOT_READY 3
UInt8 SbSlotState(UInt32 *base, UInt32 *size);
#endif
+30 -9
View File
@@ -39,19 +39,31 @@ static Boolean ModuleInstalled(void)
* Asks the OS whether a module is in the slot and where its chip selects
* are. A bus read with the slot empty is a bus error, which resets the Visor.
*/
static Boolean ModulePresent(void)
UInt8 SbSlotState(UInt32 *base, UInt32 *size)
{
UInt32 version, base, size;
UInt32 version;
if (FtrGet(hsFtrCreator, hsFtrIDVersion, &version) != errNone)
return false; /* not a Handspring device: no slot */
return SB_SLOT_NONE; /* not a Handspring device: no slot */
if (!ModuleInstalled())
return false;
if (HsCardAttrGet(hsCardSlot, hsCardAttrCsBase, &base) != errNone ||
HsCardAttrGet(hsCardSlot, hsCardAttrCsSize, &size) != errNone)
return false;
SbSetBase(base, size);
return true;
return SB_SLOT_EMPTY;
if (HsCardAttrGet(hsCardSlot, hsCardAttrCsBase, base) != errNone ||
HsCardAttrGet(hsCardSlot, hsCardAttrCsSize, size) != errNone)
return SB_SLOT_NO_CS;
SbSetBase(*base, *size);
return SB_SLOT_READY;
}
static Boolean ModulePresent(void)
{
UInt32 base, size;
return SbSlotState(&base, &size) == SB_SLOT_READY;
}
Boolean SbTransportIrq(void)
{
return gIrq;
}
static void IrqEnable(Boolean on)
@@ -62,6 +74,15 @@ static void IrqEnable(Boolean on)
HsCardAttrSet(hsCardSlot, hsCardAttrIntEnable, &enable);
}
void SbTransportLoopback(Boolean on)
{
if (!gOpen)
return;
IrqEnable(false);
SbWriteReg(SB_MCR, on ? SB_MCR_LOOPBACK : 0);
IrqEnable(true);
}
static Boolean InstallHandler(void)
{
UInt32 param = (UInt32)&gRing;
+53
View File
@@ -26,6 +26,7 @@ static UInt8 txlog[256];
static int txn, txFree = SB_FIFO_SIZE;
static int bit, byteIndex, transactions;
static UInt8 cmd, in, out;
static int loopBroken; /* bit 0 of every looped byte flips (a bad baud clock, say) */
static void SimReset(void)
{
@@ -61,9 +62,21 @@ static void RegWrite(UInt8 reg, UInt8 val)
if (lcr == 0xBF && reg == SB_EFR) { efr = val; return; }
switch (reg) {
case SB_THR:
if (regs[SB_MCR] & SB_MCR_LOOPBACK) {
if (loopBroken)
val ^= 0x01;
if (rxn < SB_FIFO_SIZE)
rxq[rxn++] = val;
return;
}
if (txn < (int)sizeof(txlog))
txlog[txn++] = val;
return;
case SB_FCR:
regs[SB_FCR] = val;
if (val & 0x02)
rxn = 0;
return;
case SB_LCR:
lcr = val;
return;
@@ -266,6 +279,44 @@ static void test_drain(void)
CHECK(ncs);
}
static void test_mapping(void)
{
UInt8 got[2];
SimInsert(0);
CHECK(!SbTryMapping(1, got));
CHECK(SbTryMapping(0, got));
CHECK(got[0] == 0x55 && got[1] == 0xAA);
CHECK(SbMappingShift() == 0);
SimInsert(1);
CHECK(SbProbe());
CHECK(SbMappingShift() == 1);
CHECK(ncs);
}
static void test_loopback(void)
{
UInt8 pat[SB_FIFO_SIZE], back[SB_FIFO_SIZE];
int i;
for (i = 0; i < SB_FIFO_SIZE; i++)
pat[i] = (UInt8)(i * 37 + 1);
SimInsert(1);
CHECK(SbProbe());
SbUartInit();
inject(3, 0x40); /* stale bytes are flushed first */
CHECK(SbLoopback(pat, 16, back) == 16);
CHECK(memcmp(pat, back, 16) == 0);
CHECK(regs[SB_MCR] == 0);
CHECK(txn == 0); /* nothing went to the radio */
loopBroken = 1;
CHECK(SbLoopback(pat, 16, back) == 16);
CHECK(memcmp(pat, back, 16) != 0);
loopBroken = 0;
present = 0;
CHECK(SbLoopback(pat, 16, back) == 0 || memcmp(pat, back, 16) != 0);
}
int main(void)
{
test_probe();
@@ -274,6 +325,8 @@ int main(void)
test_fifos();
test_sleep();
test_drain();
test_mapping();
test_loopback();
if (failures) {
printf("%d failure(s)\n", failures);
return 1;