Skip to content

Commit

Permalink
Filter LPC I/0 frame with start, cycle, address
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGreensWorkshop committed Jun 8, 2023
1 parent cd611be commit bd6633b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ I usually use old or junk parts on my projects to reduce electronic waste and su
- LPC bus sniffer
- POST code output to USB CDC
- POST code output to the LEDs
- Filter LPC I/0 frame with start, cycle/dir and address

### Compilation

Expand Down
37 changes: 34 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
#define LED_STATUS_PIN PICO_DEFAULT_LED_PIN
#define INTERVAL_IM_ALIVE_MS (1000)

typedef union __attribute__((__packed__)) {
struct {
uint16_t addr : 16;
uint8_t cy_dir : 4;
uint8_t start : 4;
uint16_t resv : 8;
}val;
uint32_t value;
}lpcIOFrame;

void gpio_initialization() {
// Init the Status LED GPIO pin. (Also sets the pin to low.)
gpio_init(LED_STATUS_PIN);
Expand All @@ -39,6 +49,16 @@ void flash_led_once(void) {
gpio_put(LED_STATUS_PIN, 0);
}

uint32_t reverse_nibbles(uint32_t in_val) {
uint32_t out_val = 0;

for(uint8_t i = 0; i < 32; i += 4) {
out_val <<= 4;
out_val |= in_val >> i & 0xf;
}
return out_val;
}

int init_lpc_bus_sniffer(PIO pio) {
// LAD[0-3] + LCLK + LFRAME which starts from GPIO0
uint lpc_bus_pin_base = 0;
Expand All @@ -62,9 +82,20 @@ int init_lpc_bus_sniffer(PIO pio) {
lpc_bus_sniffer_program_init(pio, sm, offset, lpc_bus_pin_base, LED_POST_CODE_PIN_BASE);
pio_sm_set_enabled(pio, sm, true);

// To sniff the POST codes
// Set the filter to I/O write cycle (0x2) and the address to 0x80.
pio->txf[sm] = 0x08002000;
// Set the I/O RW frame filter
lpcIOFrame filter;
filter.value = 0;
// Set Start
filter.val.start = 0x0;
// Set Cycle/Dir (write: 0x2, read: 0x0)
filter.val.cy_dir = 0x2;
// Set I/O port address (POST codes)
filter.val.addr = 0x80;

// Print filter (0x08002000)
printf("Filter: 0x%08x\n", reverse_nibbles(filter.value));

pio->txf[sm] = reverse_nibbles(filter.value);

printf("program loaded at %d, sm: %d\n", offset, sm);
return sm;
Expand Down

0 comments on commit bd6633b

Please sign in to comment.