/* * QEMU DMA emulation * * Copyright (c) 2003-2004 Vassili Karpov (malc) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "vl.h" /* #define DEBUG_DMA */ #define dolog(...) fprintf (stderr, "dma: " __VA_ARGS__) #ifdef DEBUG_DMA #define lwarn(...) fprintf (stderr, "dma: " __VA_ARGS__) #define linfo(...) fprintf (stderr, "dma: " __VA_ARGS__) #define ldebug(...) fprintf (stderr, "dma: " __VA_ARGS__) #else #define lwarn(...) #define linfo(...) #define ldebug(...) #endif #define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0]))) struct dma_regs { int now[2]; uint16_t base[2]; uint8_t mode; uint8_t page; uint8_t pageh; uint8_t dack; uint8_t eop; DMA_transfer_handler transfer_handler; void *opaque; }; #define ADDR 0 #define COUNT 1 static struct dma_cont { uint8_t status; uint8_t command; uint8_t mask; uint8_t flip_flop; int dshift; struct dma_regs regs[4]; } dma_controllers[2]; enum { CMD_MEMORY_TO_MEMORY = 0x01, CMD_FIXED_ADDRESS = 0x02, CMD_BLOCK_CONTROLLER = 0x04, CMD_COMPRESSED_TIME = 0x08, CMD_CYCLIC_PRIORITY = 0x10, CMD_EXTENDED_WRITE = 0x20, CMD_LOW_DREQ = 0x40, CMD_LOW_DACK = 0x80, CMD_NOT_SUPPORTED = CMD_MEMORY_TO_MEMORY | CMD_FIXED_ADDRESS | CMD_COMPRESSED_TIME | CMD_CYCLIC_PRIORITY | CMD_EXTENDED_WRITE | CMD_LOW_DREQ | CMD_LOW_DACK }; static int channels[8] = {-1, 2, 3, 1, -1, -1, -1, 0}; static void write_page (void *opaque, uint32_t nport, uint32_t data) { struct dma_cont *d = opaque; int ichan; ichan = channels[nport & 7]; if (-1 == ichan) { dolog ("invalid channel %#x %#x\n", nport, data); return; } d->regs[ichan].page = data; } static void write_pageh (void *opaque, uint32_t nport, uint32_t data) { struct dma_cont *d = opaque; int ichan; ichan = channels[nport & 7]; if (-1 == ichan) { dolog ("invalid channel %#x %#x\n", nport, data); return; } d->regs[ichan].pageh = data; } static uint32_t read_page (void *opaque, uint32_t nport) { struct dma_cont *d = opaque; int ichan; ichan = channels[nport & 7]; if (-1 == ichan) { dolog ("invalid channel read %#x\n", nport); return 0; } return d->regs[ichan].page; } static uint32_t read_pageh (void *opaque, uint32_t nport) { struct dma_cont *d = opaque; int ichan; ichan = channels[nport & 7]; if (-1 == ichan) { dolog ("invalid channel read %#x\n", nport); return 0; } return d->regs[ichan].pageh; } static inline void init_chan (struct dma_cont *d, int ichan) { struct dma_regs *r; r = d->regs + ichan; r->now[ADDR] = r->base[ADDR] << d->dshift; r->now[COUNT] = 0; } static inline int getff (struct dma_cont *d) { int ff; ff = d->flip_flop; d->flip_flop = !ff; return ff; } static uint32_t read_chan (void *opaque, uint32_t nport) { struct dma_cont *d = opaque; int ichan, nreg, iport, ff, val, dir; struct dma_regs *r; iport = (nport >> d->dshift) & 0x0f; ichan = iport >> 1; nreg = iport & 1; r = d->regs + ichan; dir = ((r->mode >> 5) & 1) ? -1 : 1; ff = getff (d); if (nreg) val = (r->base[COUNT] << d->dshift) - r->now[COUNT]; else val = r->now[ADDR] + r->now[COUNT] * dir; ldebug ("read_chan %#x -> %d\n", iport, val); return (val >> (d->dshift + (ff << 3))) & 0xff; } static void write_chan (void *opaque, uint32_t nport, uint32_t data) { struct dma_cont *d = opaque; int iport, ichan, nreg; struct dma_regs *r; iport = (nport >> d->dshift) & 0x0f; ichan = iport >> 1; nreg = iport & 1; r = d->regs + ichan; if (getff (d)) { r->base[nreg] = (r->base[nreg] & 0xff) | ((data << 8) & 0xff00); init_chan (d, ichan); } else { r->base[nreg] = (r->base[nreg] & 0xff00) | (data & 0xff); } } static void write_cont (void *opaque, uint32_t nport, uint32_t data) { struct dma_cont *d = opaque; int iport, ichan = 0; iport = (nport >> d->dshift) & 0x0f; switch (iport) { case 0x08: /* command */ if ((data != 0) && (data & CMD_NOT_SUPPORTED)) { dolog ("command %#x not supported\n", data); return; } d->command = data; break; case 0x09: ichan = data & 3; if (data & 4) { d->status |= 1 << (ichan + 4); } else { d->status &= ~(1 << (ichan + 4)); } d->status &= ~(1 << ichan);
COMMON_DIR = common
SRC +=	$(COMMON_DIR)/host.c \
	$(COMMON_DIR)/keyboard.c \
	$(COMMON_DIR)/action.c \
	$(COMMON_DIR)/action_tapping.c \
	$(COMMON_DIR)/action_macro.c \
	$(COMMON_DIR)/action_layer.c \
	$(COMMON_DIR)/action_util.c \
	$(COMMON_DIR)/keymap.c \
	$(COMMON_DIR)/print.c \
	$(COMMON_DIR)/debug.c \
	$(COMMON_DIR)/util.c \
	$(COMMON_DIR)/avr/suspend.c \
	$(COMMON_DIR)/avr/xprintf.S \
	$(COMMON_DIR)/avr/timer.c \
	$(COMMON_DIR)/avr/bootloader.c


# Option modules
ifdef BOOTMAGIC_ENABLE
    SRC += $(COMMON_DIR)/bootmagic.c
    SRC += $(COMMON_DIR)/avr/eeconfig.c
    OPT_DEFS += -DBOOTMAGIC_ENABLE
endif

ifdef MOUSEKEY_ENABLE
    SRC += $(COMMON_DIR)/mousekey.c
    OPT_DEFS += -DMOUSEKEY_ENABLE
    OPT_DEFS += -DMOUSE_ENABLE
endif

ifdef EXTRAKEY_ENABLE
    OPT_DEFS += -DEXTRAKEY_ENABLE
endif

ifdef CONSOLE_ENABLE
    OPT_DEFS += -DCONSOLE_ENABLE
else
    OPT_DEFS += -DNO_PRINT
    OPT_DEFS += -DNO_DEBUG
endif

ifdef COMMAND_ENABLE
    SRC += $(COMMON_DIR)/command.c
    OPT_DEFS += -DCOMMAND_ENABLE
endif

ifdef NKRO_ENABLE
    OPT_DEFS += -DNKRO_ENABLE
endif

ifdef USB_6KRO_ENABLE
    OPT_DEFS += -DUSB_6KRO_ENABLE
endif

ifdef SLEEP_LED_ENABLE
    SRC += $(COMMON_DIR)/sleep_led.c
    OPT_DEFS += -DSLEEP_LED_ENABLE
    OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
endif

ifdef BACKLIGHT_ENABLE
    SRC += $(COMMON_DIR)/backlight.c
    OPT_DEFS += -DBACKLIGHT_ENABLE
endif

ifdef KEYMAP_SECTION_ENABLE
    OPT_DEFS += -DKEYMAP_SECTION_ENABLE

    ifeq ($(strip $(MCU)),atmega32u2)
	EXTRALDFLAGS = -Wl,-L$(TMK_DIR),-Tldscript_keymap_avr35.x
    else ifeq ($(strip $(MCU)),atmega32u4)
	EXTRALDFLAGS = -Wl,-L$(TMK_DIR),-Tldscript_keymap_avr5.x
    else
	EXTRALDFLAGS = $(error no ldscript for keymap section)
    endif
endif

# Version string
OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null)


# Search Path
VPATH += $(TMK_DIR)/common