summaryrefslogtreecommitdiffstats
path: root/sw/z80/kernel/drivers
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2017-10-05 16:09:59 +0200
committerNao Pross <naopross@thearcway.org>2017-10-05 16:09:59 +0200
commiteb169ea5a89909b90794e0388f89d6d372754e46 (patch)
treece7e826fd2dd4e4248cb4f1fbf8ce2885c943f49 /sw/z80/kernel/drivers
parentTest units are now in their own folder 'z80_test', add programmer cli interface (diff)
downloadz80uPC-eb169ea5a89909b90794e0388f89d6d372754e46.tar.gz
z80uPC-eb169ea5a89909b90794e0388f89d6d372754e46.zip
Move test units to z80/tests, and drivers are now statically linked
Makefiles for the test units were getting messier, so now drivers (that need to be tested) are statically compiled in their own folder under z80/drivers. The kernel makefile and is now broken since everything has been moved.
Diffstat (limited to 'sw/z80/kernel/drivers')
-rw-r--r--sw/z80/kernel/drivers/ctc.c6
-rw-r--r--sw/z80/kernel/drivers/pio.c40
-rw-r--r--sw/z80/kernel/drivers/usart.c91
3 files changed, 0 insertions, 137 deletions
diff --git a/sw/z80/kernel/drivers/ctc.c b/sw/z80/kernel/drivers/ctc.c
deleted file mode 100644
index 841202a..0000000
--- a/sw/z80/kernel/drivers/ctc.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "drivers/ctc.h"
-
-void ctc_control()
-{
-
-}
diff --git a/sw/z80/kernel/drivers/pio.c b/sw/z80/kernel/drivers/pio.c
deleted file mode 100644
index 4321fb8..0000000
--- a/sw/z80/kernel/drivers/pio.c
+++ /dev/null
@@ -1,40 +0,0 @@
-#include "drivers/pio.h"
-
-static uint8_t *pio_port = (uint8_t *) ADDR_DEV_PIO;
-static uint8_t *pio_ctrl = (uint8_t *) (ADDR_DEV_PIO + 2);
-
-inline void _pio_data(int port, uint8_t data)
-{
- *(pio_port + port) = data;
-}
-
-inline void _pio_control(int port, uint8_t cmd)
-{
- *(pio_ctrl + port) = cmd;
-}
-
-void pio_set_mode(int port, int mode, uint8_t io)
-{
- // 0x0F is a control sequence to set mode
- _pio_control(port, ((mode << 6) | 0x0F));
-
- // this mode requires an additional argument that sets
- // a mode for each pin
- if (mode == PIO_MODE_BIT_IO) {
- _pio_control(port, io);
- }
-}
-
-void pio_set_interrupts(int port, int control)
-{
- // 0x07 is a control sequence to set interrupts
- _pio_control(port, (control | 0x07));
-}
-
-void pio_set_interrupts_mask(int port, int control, uint8_t mask)
-{
- // 0x17 is a control sequence to set interrupts
- // and to interpret the next byte as a mask
- _pio_control(port, (control | 0x17));
- _pio_control(port, mask);
-}
diff --git a/sw/z80/kernel/drivers/usart.c b/sw/z80/kernel/drivers/usart.c
deleted file mode 100644
index c54fe37..0000000
--- a/sw/z80/kernel/drivers/usart.c
+++ /dev/null
@@ -1,91 +0,0 @@
-#include "drivers/usart.h"
-
-static struct _usart_device *_usart = (struct _usart_device *) ADDR_DEV_USART;
-
-void usart_set_baudrate(uint16_t baudrate)
-{
- // enable latch access
- _usart->LCR.divisor_latch_access = 1;
- _usart->buffer = 0x00FF & baudrate; // LSBs
- memcpy(&_usart->IER, &(baudrate >>8), 1);
- // _usart->IER = 0x00FF & (baudrate >> 8); // MSBs
- _usart->LCR.divisor_latch_access = 0;
-}
-
-void usart_set_parity(int mode)
-{
- if (mode == USART_PARITY_EVEN) {
- _usart->LCR.even_parity = 1;
- }
- else if (mode == USART_PARITY_ODD) {
- _usart->LCR.even_parity = 0;
- }
-
- _usart->LCR.parity = (mode == USART_PARITY_NONE) ? 0 : 1;
-}
-
-void usart_set_stop_bits(int count)
-{
- _usart->LCR.stop_bits = (count == USART_STOP_BITS_1) ? 0 : 1;
-}
-
-void usart_word_length(int length)
-{
- _usart->LCR.word_length = length;
-}
-
-void usart_set_autoflow(int mode)
-{
- _usart->MCR.autoflow = (mode == USART_AUTOFLOW_OFF) ? 0 : 1;
- _usart->MCR.data_terminal_ready = (mode == USART_AUTOFLOW_ALL);
-}
-
-inline void usart_init(uint16_t baudrate, int parity, int stop_bits)
-{
- usart_set_baudrate(baudrate);
- usart_set_parity(parity);
- usart_set_stop_bits(stop_bits);
- usart_set_autoflow(USART_AUTOFLOW_OFF);
-}
-
-void usart_transmit(uint8_t data)
-{
- _usart->buffer = data;
- while (_usart->LSR.transmitter_holder_empty == 0); // wait
-}
-
-uint8_t usart_receive()
-{
- return _usart->buffer;
-}
-
-int usart_write(uint8_t *data, size_t size)
-{
- uint8_t *dp = data;
-
- while (size--) {
- _usart->buffer = *(dp++);
- while (_usart->LSR.transmitter_empty);
- }
-
- // TODO: do something that actually counts for sent bytes
- return size;
-}
-
-int usart_read(uint8_t *buffer, size_t count)
-{
- uint8_t *bp = buffer;
- size_t read_count = 0;
-
- while (count--) {
- *(bp++) = _usart->buffer;
- // check for errors
- if (_usart->LSR.framing_error || _usart->LSR.parity_error) {
- bp--; // delete last byte (?)
- } else {
- read_count++;
- }
- }
-
- return read_count;
-}