libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
dma.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
26
27#ifndef LIBWS_DMA_H_
28#define LIBWS_DMA_H_
29
30#include <stdint.h>
31#include <wonderful.h>
32#include "memory.h"
33#include "ports.h"
34
39
41static inline void ws_gdma_set_sourcep(const void __far *src) {
42 outportw(WS_GDMA_SOURCE_L_PORT, (FP_SEG(src) << 4) + FP_OFF(src));
43 outportb(WS_GDMA_SOURCE_H_PORT, FP_SEG(src) >> 12);
44}
45
46static inline void ws_gdma_set_sourcei(uint32_t src) {
47 outportw(WS_GDMA_SOURCE_L_PORT, src);
48 outportb(WS_GDMA_SOURCE_H_PORT, src >> 16);
49}
51
59#define ws_gdma_set_source(src) _Generic((src), \
60 int8_t: ws_gdma_set_sourcei, \
61 int16_t: ws_gdma_set_sourcei, \
62 int32_t: ws_gdma_set_sourcei, \
63 uint8_t: ws_gdma_set_sourcei, \
64 uint16_t: ws_gdma_set_sourcei, \
65 uint32_t: ws_gdma_set_sourcei, \
66 default: ws_gdma_set_sourcep \
67)(src)
68
74static inline void ws_gdma_set_destination(void ws_iram *address) {
75 outportw(WS_GDMA_DEST_PORT, (uint16_t) address);
76}
77
83static inline void ws_gdma_set_length(uint16_t length) {
84 outportw(WS_GDMA_LENGTH_PORT, length);
85}
86
88void ws_gdma_copyi(void ws_iram *dest, uint32_t src, uint16_t length);
89
90static inline void ws_gdma_copyp(void ws_iram *dest, const void __far *src, uint16_t length) {
91 ws_gdma_copyi(dest, ws_ptr_to_linear(src), length);
92}
94
105#define ws_gdma_copy(dest, src, length) _Generic((src), \
106 int8_t: ws_gdma_copyi, \
107 int16_t: ws_gdma_copyi, \
108 int32_t: ws_gdma_copyi, \
109 uint8_t: ws_gdma_copyi, \
110 uint16_t: ws_gdma_copyi, \
111 uint32_t: ws_gdma_copyi, \
112 default: ws_gdma_copyp \
113)(dest, src, length)
114
122void ws_gdma_maybe_copy(void ws_iram *dest, const void __far *src, uint16_t length);
123
125static inline void ws_sdma_set_sourcep(const void __far *src) {
126 outportw(WS_SDMA_SOURCE_L_PORT, (FP_SEG(src) << 4) + FP_OFF(src));
127 outportb(WS_SDMA_SOURCE_H_PORT, FP_SEG(src) >> 12);
128}
129
130static inline void ws_sdma_set_sourcei(uint32_t src) {
131 outportw(WS_SDMA_SOURCE_L_PORT, src);
132 outportb(WS_SDMA_SOURCE_H_PORT, src >> 16);
133}
135
143#define ws_sdma_set_source(src) _Generic((src), \
144 int8_t: ws_sdma_set_sourcei, \
145 int16_t: ws_sdma_set_sourcei, \
146 int32_t: ws_sdma_set_sourcei, \
147 uint8_t: ws_sdma_set_sourcei, \
148 uint16_t: ws_sdma_set_sourcei, \
149 uint32_t: ws_sdma_set_sourcei, \
150 default: ws_sdma_set_sourcep \
151)(src)
152
156static inline void ws_sdma_set_length(uint32_t length) {
157 outportw(WS_SDMA_LENGTH_L_PORT, length);
158 outportb(WS_SDMA_LENGTH_H_PORT, length >> 16);
159}
160
162
163#endif /* LIBWS_DMA_H_ */
void ws_gdma_maybe_copy(void ws_iram *dest, const void __far *src, uint16_t length)
Copy words from a source pointer to a destination pointer, using DMA if present.
static void ws_gdma_set_length(uint16_t length)
Set the length of a general DMA transfer.
Definition dma.h:83
static void ws_sdma_set_length(uint32_t length)
Set the length of a sound DMA transfer.
Definition dma.h:156
static void ws_gdma_set_destination(void ws_iram *address)
Set the destination of a general DMA transfer.
Definition dma.h:74
#define WS_GDMA_LENGTH_PORT
Definition ports.h:420
#define WS_GDMA_SOURCE_H_PORT
Definition ports.h:410
#define WS_SDMA_LENGTH_H_PORT
Definition ports.h:451
#define WS_SDMA_SOURCE_H_PORT
Definition ports.h:441
#define WS_SDMA_SOURCE_L_PORT
Definition ports.h:436
#define WS_GDMA_SOURCE_L_PORT
Definition ports.h:405
#define WS_SDMA_LENGTH_L_PORT
Definition ports.h:446
#define WS_GDMA_DEST_PORT
Definition ports.h:415
#define ws_iram
Definition memory.h:46
static uint32_t ws_ptr_to_linear(const void ws_far *src)
Definition memory.h:87