Cleanup parallel programmer firmware, update ecflash
This commit is contained in:
2
ecflash
2
ecflash
Submodule ecflash updated: 484b134d6d...c8ab9406ca
@ -1,10 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <arch/gpio.h>
|
||||
#include <arch/i2c_slave.h>
|
||||
#include <arch/uart.h>
|
||||
#include <board/battery.h>
|
||||
#include <board/i2c.h>
|
||||
|
||||
void init(void) {
|
||||
uart_stdio_init(0, __CONSOLE_BAUD__);
|
||||
@ -14,9 +11,6 @@ struct Gpio LED = GPIO(B, 7);
|
||||
|
||||
//TODO: .h file
|
||||
void parallel_main(void);
|
||||
void parallel_host(void);
|
||||
void parallel_peripheral(void);
|
||||
void parallel_spy(void);
|
||||
|
||||
int main(void) {
|
||||
init();
|
||||
@ -26,22 +20,6 @@ int main(void) {
|
||||
|
||||
parallel_main();
|
||||
|
||||
// If parallel_main exits with an error, wait for reset
|
||||
for (;;) {}
|
||||
|
||||
/*
|
||||
printf("Hello from System76 EC for the Arduino Mega 2560!\n");
|
||||
|
||||
for (;;) {
|
||||
printf("Press a key to select parallel mode:\n");
|
||||
printf(" h = host, p = peripheral, s = spy\n");
|
||||
int c = getchar();
|
||||
if (c == 'h') {
|
||||
parallel_host();
|
||||
} else if (c == 'p') {
|
||||
parallel_peripheral();
|
||||
} else if (c == 's') {
|
||||
parallel_spy();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -202,225 +202,6 @@ int parallel_transaction(struct Parallel * port, uint8_t * data, int length, boo
|
||||
#define parallel_read(P, D, L) parallel_transaction(P, D, L, true, false)
|
||||
#define parallel_write(P, D, L) parallel_transaction(P, D, L, false, false)
|
||||
|
||||
int parallel_read_at(struct Parallel * port, uint8_t address, uint8_t * data, int length) {
|
||||
int res;
|
||||
|
||||
res = parallel_set_address(port, &address, 1);
|
||||
if (res < 0) return res;
|
||||
|
||||
return parallel_read(port, data, length);
|
||||
}
|
||||
|
||||
int parallel_write_at(struct Parallel * port, uint8_t address, uint8_t * data, int length) {
|
||||
int res;
|
||||
|
||||
res = parallel_set_address(port, &address, 1);
|
||||
if (res < 0) return res;
|
||||
|
||||
return parallel_write(port, data, length);
|
||||
}
|
||||
|
||||
int parallel_flash_transaction(struct Parallel * port, uint32_t address, uint8_t * data, int length, bool read) {
|
||||
int res;
|
||||
uint8_t byte;
|
||||
|
||||
// ECINDAR3
|
||||
byte = (uint8_t)(address >> 24);
|
||||
res = parallel_write_at(port, 7, &byte, 1);
|
||||
if (res < 0) return res;
|
||||
|
||||
// ECINDAR2
|
||||
byte = (uint8_t)(address >> 16);
|
||||
res = parallel_write_at(port, 6, &byte, 1);
|
||||
if (res < 0) return res;
|
||||
|
||||
// ECINDAR1
|
||||
byte = (uint8_t)(address >> 8);
|
||||
res = parallel_write_at(port, 5, &byte, 1);
|
||||
if (res < 0) return res;
|
||||
|
||||
// ECINDAR0
|
||||
byte = (uint8_t)(address);
|
||||
res = parallel_write_at(port, 4, &byte, 1);
|
||||
if (res < 0) return res;
|
||||
|
||||
// ECINDDR
|
||||
if (read) {
|
||||
return parallel_read_at(port, 8, data, length);
|
||||
} else {
|
||||
return parallel_write_at(port, 8, data, length);
|
||||
}
|
||||
}
|
||||
|
||||
void parallel_host(void) {
|
||||
printf("Parallel host. Reset to exit\n");
|
||||
|
||||
struct Parallel * port = &PORT;
|
||||
parallel_reset(port);
|
||||
|
||||
for (;;) {
|
||||
int c = getchar();
|
||||
if (c < 0) break;
|
||||
|
||||
if (c == '\r') {
|
||||
printf("Reading chip ID\n");
|
||||
|
||||
uint8_t id[3];
|
||||
|
||||
parallel_read_at(port, 0, &id[0], 1);
|
||||
parallel_read_at(port, 1, &id[1], 1);
|
||||
parallel_read_at(port, 2, &id[2], 1);
|
||||
|
||||
printf(" ID %02X%02X version %d\n", id[0], id[1], id[2]);
|
||||
|
||||
uint8_t byte;
|
||||
|
||||
byte = 0;
|
||||
parallel_flash_transaction(port, 0x7FFFFE00, &byte, 1, false);
|
||||
|
||||
uint8_t command[5] = {0xB, 0, 0, 0, 0};
|
||||
parallel_flash_transaction(port, 0x7FFFFD00, command, 5, false);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 256; i++) {
|
||||
parallel_flash_transaction(port, 0x7FFFFD00, &byte, 1, true);
|
||||
printf("%02X: %02X\n", i, byte);
|
||||
}
|
||||
|
||||
byte = 0;
|
||||
parallel_flash_transaction(port, 0x7FFFFE00, &byte, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
parallel_hiz(port);
|
||||
}
|
||||
|
||||
void parallel_peripheral(void) {
|
||||
printf("Parallel peripheral (WIP, writes only). Reset to exit\n");
|
||||
|
||||
struct Parallel * port = &PORT;
|
||||
parallel_hiz(port);
|
||||
|
||||
// Strobes are high when inactive
|
||||
bool last_data_n = true;
|
||||
bool last_addr_n = true;
|
||||
|
||||
for (;;) {
|
||||
// Pull wait line low
|
||||
gpio_set_dir(port->wait_n, true);
|
||||
|
||||
// Read data strobe and edge detect
|
||||
bool data_n = gpio_get(port->data_n);
|
||||
bool data_edge = last_data_n && !data_n;
|
||||
|
||||
// Read address strobe and edge detect
|
||||
bool addr_n = gpio_get(port->addr_n);
|
||||
bool addr_edge = last_addr_n && !addr_n;
|
||||
|
||||
// If not in reset
|
||||
if (gpio_get(port->reset_n)) {
|
||||
// On the falling edge of either strobe
|
||||
if (data_edge || addr_edge) {
|
||||
// Check if read or write cycle
|
||||
bool read = gpio_get(port->write_n);
|
||||
|
||||
// Read data
|
||||
uint8_t byte = 0;
|
||||
#define DATA_BIT(B) \
|
||||
if (gpio_get(port->d ## B)) byte |= (1 << B);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
|
||||
//TODO: Check if strobe fell while reading
|
||||
|
||||
// Release wait line
|
||||
gpio_set_dir(port->wait_n, false);
|
||||
|
||||
if (data_edge) {
|
||||
putchar('d');
|
||||
}
|
||||
|
||||
if (addr_edge) {
|
||||
putchar('a');
|
||||
}
|
||||
|
||||
if (read) {
|
||||
putchar('<');
|
||||
} else {
|
||||
putchar('>');
|
||||
}
|
||||
|
||||
printf("%02X\n", byte);
|
||||
|
||||
// Wait 1 microsecond
|
||||
_delay_us(1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
last_data_n = data_n;
|
||||
last_addr_n = addr_n;
|
||||
}
|
||||
}
|
||||
|
||||
void parallel_spy(void) {
|
||||
printf("Parallel spy. Reset to exit\n");
|
||||
|
||||
struct Parallel * port = &PORT;
|
||||
parallel_hiz(port);
|
||||
|
||||
// Strobes are high when inactive
|
||||
bool last_data_n = true;
|
||||
bool last_addr_n = true;
|
||||
|
||||
for (;;) {
|
||||
// Read data strobe and edge detect
|
||||
bool data_n = gpio_get(port->data_n);
|
||||
bool data_edge = last_data_n && !data_n;
|
||||
|
||||
// Read address strobe and edge detect
|
||||
bool addr_n = gpio_get(port->addr_n);
|
||||
bool addr_edge = last_addr_n && !addr_n;
|
||||
|
||||
// If not in reset
|
||||
if (gpio_get(port->reset_n)) {
|
||||
// On the falling edge of either strobe
|
||||
if (data_edge || addr_edge) {
|
||||
// Check if read or write cycle
|
||||
bool read = gpio_get(port->write_n);
|
||||
|
||||
// Read data
|
||||
uint8_t byte = 0;
|
||||
#define DATA_BIT(B) \
|
||||
if (gpio_get(port->d ## B)) byte |= (1 << B);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
|
||||
//TODO: Check if strobe fell while reading
|
||||
|
||||
if (data_edge) {
|
||||
putchar('d');
|
||||
}
|
||||
|
||||
if (addr_edge) {
|
||||
putchar('a');
|
||||
}
|
||||
|
||||
if (read) {
|
||||
putchar('<');
|
||||
} else {
|
||||
putchar('>');
|
||||
}
|
||||
|
||||
printf("%02X\n", byte);
|
||||
}
|
||||
}
|
||||
|
||||
last_data_n = data_n;
|
||||
last_addr_n = addr_n;
|
||||
}
|
||||
}
|
||||
|
||||
int serial_transaction(uint8_t * data, int length, bool read) {
|
||||
int i;
|
||||
for (i = 0; i < length; i++) {
|
||||
|
Reference in New Issue
Block a user