diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-07 13:22:53 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-11 00:08:15 +0100 |
| commit | 7861a52adf92a083bb2aed4c35f98d8035dce032 (patch) | |
| tree | 28cd3c40e4c878f730f5df3c1d93bdf91af490c3 /src/drv/ps1/sio/private_include | |
| parent | 7fc48e9216ff809da5f8055a50b0be17628ef1df (diff) | |
| download | wnix-7861a52adf92a083bb2aed4c35f98d8035dce032.tar.gz | |
Setup project skeleton
Diffstat (limited to 'src/drv/ps1/sio/private_include')
| -rw-r--r-- | src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h | 31 | ||||
| -rw-r--r-- | src/drv/ps1/sio/private_include/drv/ps1/sio/regs.h | 136 | ||||
| -rw-r--r-- | src/drv/ps1/sio/private_include/drv/ps1/sio/routines.h | 27 | ||||
| -rw-r--r-- | src/drv/ps1/sio/private_include/drv/ps1/sio/types.h | 65 |
4 files changed, 259 insertions, 0 deletions
diff --git a/src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h b/src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h new file mode 100644 index 0000000..a481fa9 --- /dev/null +++ b/src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h @@ -0,0 +1,31 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_SIO_OPS_H +#define DRV_PS1_SIO_OPS_H + +#include <drv/event.h> +#include <sys/types.h> + +int drv_ps1_sio_read(void *buf, size_t n, off_t offset, + const struct drv_event_done *done, void *args); +int drv_ps1_sio_read_nb(void *buf, size_t n, void *args); +int drv_ps1_sio_write(const void *buf, size_t n, + const struct drv_event_done *done, void *args); + +#endif diff --git a/src/drv/ps1/sio/private_include/drv/ps1/sio/regs.h b/src/drv/ps1/sio/private_include/drv/ps1/sio/regs.h new file mode 100644 index 0000000..16b2bca --- /dev/null +++ b/src/drv/ps1/sio/private_include/drv/ps1/sio/regs.h @@ -0,0 +1,136 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_SIO_REGS_H +#define DRV_PS1_SIO_REGS_H + +#include <stdint.h> + +struct sio_tx_data +{ + uint32_t value :8, :24; +}; + +struct sio_rx_data +{ + uint8_t values[4]; +}; + +union sio_stat +{ + struct + { + uint32_t + tx_ready_started :1, + rx_fifo_not_empty :1, + tx_ready_finished :1, + rx_parity_error :1, + rx_fifo_overrun :1, + rx_bad_stp :1, + rx_inverted :1, + dsr :1, + cts :1, + irqreq :1, + :1, + baudrate :15, :6; + } bits; + + uint32_t mask; +}; + +union sio_mode +{ + struct + { + uint16_t + baudrate_mul :2, + len :2, + parity_en :1, + parity_odd :1, + stplen :2, + :8; + } bits; + + uint16_t mask; +}; + +union sio_ctrl +{ + struct + { + uint16_t + tx_en :1, + dtr :1, + rx_en :1, + tx_invert :1, + ack :1, + rts :1, + reset :1, + :1, + rx_int_mode :2, + tx_int_en :1, + rx_int_en :1, + dsr_int_en :1, + :3; + } bits; + + uint16_t mask; +}; + +enum +{ + SIO_CTRL_RX_INT_1, + SIO_CTRL_RX_INT_2, + SIO_CTRL_RX_INT_3, + SIO_CTRL_RX_INT_4 +}; + +enum +{ + SIO_MODE_FACTOR_STOP, + SIO_MODE_FACTOR_MUL1, + SIO_MODE_FACTOR_MUL16, + SIO_MODE_FACTOR_MUL64 +}; + +enum +{ + SIO_MODE_LEN_5, + SIO_MODE_LEN_6, + SIO_MODE_LEN_7, + SIO_MODE_LEN_8 +}; + +enum +{ + SIO_MODE_STP_RESERVED, + SIO_MODE_STP_1, + SIO_MODE_STP_1_5, + SIO_MODE_STP_2, +}; + +#define SIO_BASE 0x1f801050 +#define SIO_REG(n) (SIO_BASE + n) +#define SIO_TX_DATA ((volatile struct sio_tx_data *)SIO_REG(0)) +#define SIO_RX_DATA ((const volatile struct sio_rx_data *)SIO_REG(0)) +#define SIO_STAT ((const volatile union sio_stat *)SIO_REG(4)) +#define SIO_MODE ((volatile union sio_mode *)SIO_REG(8)) +#define SIO_CTRL ((volatile union sio_ctrl *)SIO_REG(10)) +#define SIO_BAUD (*(volatile uint16_t *)SIO_REG(14)) + +#endif diff --git a/src/drv/ps1/sio/private_include/drv/ps1/sio/routines.h b/src/drv/ps1/sio/private_include/drv/ps1/sio/routines.h new file mode 100644 index 0000000..f5b97da --- /dev/null +++ b/src/drv/ps1/sio/private_include/drv/ps1/sio/routines.h @@ -0,0 +1,27 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_SIO_ROUTINES_H +#define DRV_PS1_SIO_ROUTINES_H + +#include <drv/ps1/sio/types.h> + +int drv_ps1_sio_irq(void); +int drv_ps1_sio_next(struct sio_fifo *f); + +#endif diff --git a/src/drv/ps1/sio/private_include/drv/ps1/sio/types.h b/src/drv/ps1/sio/private_include/drv/ps1/sio/types.h new file mode 100644 index 0000000..87dd412 --- /dev/null +++ b/src/drv/ps1/sio/private_include/drv/ps1/sio/types.h @@ -0,0 +1,65 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_SIO_TYPES_H +#define DRV_PS1_SIO_TYPES_H + +#include <drv/event.h> +#include <stdbool.h> + +struct sio_req +{ + union + { + struct sio_req_r + { + void *buf; + size_t n; + } r; + + struct sio_req_w + { + const void *buf; + size_t n; + } w; + } u; + + int (*f)(void); + struct drv_event_done done; + struct sio_req *next; +}; + +struct sio_fifo +{ + char buf[192]; + size_t proc, pend; + struct sio_req *head, *tail; + int (*next)(void); +}; + +struct drv_ps1_sio +{ + bool init; + int event; + struct sio_fifo rx, tx; + struct drv_event ev; +}; + +extern struct drv_ps1_sio drv_ps1_sio; + +#endif |
