ECE 320 · Week 8

Modern Computer: Embedded Systems

A mocked bus returns a sample the library asked for.

Week 8 of 10 · Das Frite

ECE 320 · Week 8 · In class

A mocked bus returns a sample the library asked for.

ECE 320 · Week 8 · In class

A mocked bus returns a sample the library asked for. (continued)

ECE 320 · Week 8 · In class

Loop a UART to the bench PC at two baud rates.

ECE 320 · Week 8 · Lecture

A driver in userspace

struct bus {
	int fd;   /* open("/dev/spidevB.C", O_RDWR) */
	int (*xfer)(struct bus *b, const unsigned char *tx,
		    unsigned char *rx, unsigned len);
};

ECE 320 · Week 8 · Lecture

The real bus: one spidev transfer

/* needs string.h, sys/ioctl.h, linux/spi/spidev.h */
int spidev_xfer(struct bus *b, const unsigned char *tx,
		unsigned char *rx, unsigned len)
{
	struct spi_ioc_transfer t;
	memset(&t, 0, sizeof t);
	t.tx_buf = (unsigned long)tx;
	t.rx_buf = (unsigned long)rx;
	t.len = len;
	if (ioctl(b->fd, SPI_IOC_MESSAGE(1), &t) < 0)
		return -1;
	return 0;
}

ECE 320 · Week 8 · Lecture

The mocked bus

struct mock {
	struct bus bus;            /* first, so the casts work */
	unsigned char reply[3];    /* what the "chip" sends back */
	unsigned char sent[3];     /* what the library sent */
};
int mock_xfer(struct bus *b, const unsigned char *tx,
	      unsigned char *rx, unsigned len)
{
	struct mock *m = (struct mock *)b;
	if (len > sizeof m->reply) return -1;
	memcpy(m->sent, tx, len);
	memcpy(rx, m->reply, len);
	return 0;
}

ECE 320 · Week 8 · Lecture

A UART byte, and a baud mismatch

IdleStartDataStop
highone bit, low8 bits, least significant firstone bit, high

ECE 320 · Week 8 · Lab

Lab

  1. Loop a UART to the bench PC at two baud rates.
  2. Write a userspace driver library for the MCP3008, with a test on a mocked bus. A kernel module is not accepted. Second pass: run the mock test once more and keep the second result in your notes.
  3. Assemble the lab hand-in: The userspace driver library, its test on a mocked bus, and the UART capture at the mismatched baud.

ECE 320 · Week 8 · Lab

Hand in

The userspace driver library, its test on a mocked bus, and the UART capture at the mismatched baud.

ECE 320 · Week 8 · Homework

Homework

ECE 320 · Week 8 · Homework

Turn in

Those two sentences.

ECE 320 · Week 8 · Read

Read

On the lab site: Module 11, Drivers, introduces the driver model. This week grades the userspace library, the mock test, and the bad-baud capture. Stop before a kernel module.

ECE 320 · Week 8 · Next

Week 9

Which of the two buses comes up first, and why.

Arrow keys or space to move, F for full screen, N for speaker notes, Home and End for the first and last slide. Print gives one slide per page.