| 1 |
|
| 2 |
|
| 3 |
#include <spi-generic.h> |
| 4 |
#include <spi_flash.h> |
| 5 |
#include <console/spi.h> |
| 6 |
|
| 7 |
static struct spi_slave slave; |
| 8 |
|
| 9 |
void spiconsole_init(void) { |
| 10 |
spi_init(); |
| 11 |
spi_setup_slave(0, 0, &slave); |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
void spiconsole_tx_byte(unsigned char c) { |
| 26 |
static struct em100_msg msg = { |
| 27 |
.header.spi_command = EM100_DEDICATED_CMD, |
| 28 |
.header.em100_command = EM100_UFIFO_CMD, |
| 29 |
.header.msg_signature = EM100_MSG_SIGNATURE, |
| 30 |
.header.msg_type = EM100_MSG_ASCII, |
| 31 |
.header.msg_length = 0 |
| 32 |
}; |
| 33 |
|
| 34 |
|
| 35 |
if (spi_crop_chunk(&slave, 0, MAX_MSG_LENGTH) < |
| 36 |
sizeof(struct em100_msg_header) + 1) |
| 37 |
return; |
| 38 |
|
| 39 |
msg.data[msg.header.msg_length] = c; |
| 40 |
msg.header.msg_length++; |
| 41 |
|
| 42 |
|
| 43 |
if (c == '\n' || (sizeof(struct em100_msg_header) + |
| 44 |
msg.header.msg_length == spi_crop_chunk(&slave, 0, |
| 45 |
MAX_MSG_LENGTH))) { |
| 46 |
spi_xfer(&slave, &msg, sizeof(struct em100_msg_header) + |
| 47 |
msg.header.msg_length, NULL, 0); |
| 48 |
|
| 49 |
msg.header.msg_length = 0; |
| 50 |
} |
| 51 |
} |