From 00b29437d823d0690f69b5a44098a897d48a42f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Sat, 10 Jan 2015 17:19:56 +0000 Subject: [PATCH] did more changes to interrupt code, but still crashes in networking --- BaS_gcc/bas_firebee.bdm | 6 +- BaS_gcc/dma/MCD_dmaApi.c | 1084 ++++++++++++++++---------------- BaS_gcc/dma/dma.c | 10 + BaS_gcc/include/MCD_dma.h | 27 +- BaS_gcc/include/MCF5475_INTC.h | 1 - BaS_gcc/include/dma.h | 4 - BaS_gcc/include/driver_vec.h | 382 +++++------ BaS_gcc/include/interrupts.h | 4 +- BaS_gcc/net/net_timer.c | 2 +- BaS_gcc/sys/BaS.c | 28 +- BaS_gcc/sys/exceptions.S | 47 +- BaS_gcc/sys/interrupts.c | 84 ++- BaS_gcc/sys/sysinit.c | 1 - 13 files changed, 884 insertions(+), 796 deletions(-) diff --git a/BaS_gcc/bas_firebee.bdm b/BaS_gcc/bas_firebee.bdm index e729b8f..116fb57 100755 --- a/BaS_gcc/bas_firebee.bdm +++ b/BaS_gcc/bas_firebee.bdm @@ -63,10 +63,6 @@ write 0xFF000104 0x710D0F00 4 # SDCR (lock SDMR and enable refresh) sleep 100 load -v firebee/ram.elf -write-ctrl 0x80e 0x2700 -write-ctrl 0x2 0xa50c8120 -dump-register SR -dump-register CACR -dump-register MBAR + execute wait diff --git a/BaS_gcc/dma/MCD_dmaApi.c b/BaS_gcc/dma/MCD_dmaApi.c index 7617beb..1ecce25 100755 --- a/BaS_gcc/dma/MCD_dmaApi.c +++ b/BaS_gcc/dma/MCD_dmaApi.c @@ -37,10 +37,10 @@ TaskTableEntry *MCD_modelTaskTable; */ static int MCD_chStatus[NCHANNELS] = { - MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, - MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, - MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, - MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA + MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, + MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, + MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, + MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA }; /* @@ -66,12 +66,12 @@ MCD_bufDesc *MCD_relocBuffDesc; */ #define DBG_CTL_COMP1_TASK (0x00002000) /* have comparator 1 look for a task # */ #define DBG_CTL_ENABLE (DBG_CTL_AUTO_ARM | \ - DBG_CTL_BREAK | \ - DBG_CTL_INT_BREAK | \ - DBG_CTL_COMP1_TASK) + DBG_CTL_BREAK | \ + DBG_CTL_INT_BREAK | \ + DBG_CTL_COMP1_TASK) #define DBG_CTL_DISABLE (DBG_CTL_AUTO_ARM | \ - DBG_CTL_INT_BREAK | \ - DBG_CTL_COMP1_TASK) + DBG_CTL_INT_BREAK | \ + DBG_CTL_COMP1_TASK) #define DBG_KILL_ALL_STAT (0xFFFFFFFF) /* @@ -117,11 +117,11 @@ MCD_bufDesc *MCD_relocBuffDesc; typedef struct MCD_remVariants_struct MCD_remVariant; struct MCD_remVariants_struct { - int remDestRsdIncr[NCHANNELS]; /* -1,0,1 */ - int remSrcRsdIncr[NCHANNELS]; /* -1,0,1 */ - int16_t remDestIncr[NCHANNELS]; /* DestIncr */ - int16_t remSrcIncr[NCHANNELS]; /* srcIncr */ - uint32_t remXferSize[NCHANNELS]; /* xferSize */ + int remDestRsdIncr[NCHANNELS]; /* -1,0,1 */ + int remSrcRsdIncr[NCHANNELS]; /* -1,0,1 */ + int16_t remDestIncr[NCHANNELS]; /* DestIncr */ + int16_t remSrcIncr[NCHANNELS]; /* srcIncr */ + uint32_t remXferSize[NCHANNELS]; /* xferSize */ }; /* @@ -146,161 +146,161 @@ extern uint32_t MCD_funcDescTab0[]; int MCD_initDma(dmaRegs *dmaBarAddr, void *taskTableDest, uint32_t flags) { - int i; - TaskTableEntry *entryPtr; + int i; + TaskTableEntry *entryPtr; - /* setup the local pointer to register set */ - MCD_dmaBar = dmaBarAddr; + /* setup the local pointer to register set */ + MCD_dmaBar = dmaBarAddr; - /* do we need to move/create a task table */ - if ((flags & MCD_RELOC_TASKS) != 0) - { - int fixedSize; - uint32_t *fixedPtr; - /*int *tablePtr = taskTableDest;TBD*/ - int varTabsOffset, funcDescTabsOffset, contextSavesOffset; - int taskDescTabsOffset; - int taskTableSize, varTabsSize, funcDescTabsSize, contextSavesSize; - int taskDescTabSize; + /* do we need to move/create a task table */ + if ((flags & MCD_RELOC_TASKS) != 0) + { + int fixedSize; + uint32_t *fixedPtr; + /*int *tablePtr = taskTableDest;TBD*/ + int varTabsOffset, funcDescTabsOffset, contextSavesOffset; + int taskDescTabsOffset; + int taskTableSize, varTabsSize, funcDescTabsSize, contextSavesSize; + int taskDescTabSize; - int i; + int i; - /* check if physical address is aligned on 512 byte boundary */ - if (((uint32_t) taskTableDest & 0x000001ff) != 0) - return (MCD_TABLE_UNALIGNED); + /* check if physical address is aligned on 512 byte boundary */ + if (((uint32_t) taskTableDest & 0x000001ff) != 0) + return (MCD_TABLE_UNALIGNED); - MCD_taskTable = taskTableDest; /* set up local pointer to task Table */ + MCD_taskTable = taskTableDest; /* set up local pointer to task Table */ - /* - * Create a task table: - * - compute aligned base offsets for variable tables and - * function descriptor tables, then - * - loop through the task table and setup the pointers - * - copy over model task table with the the actual task descriptor - * tables - */ + /* + * Create a task table: + * - compute aligned base offsets for variable tables and + * function descriptor tables, then + * - loop through the task table and setup the pointers + * - copy over model task table with the the actual task descriptor + * tables + */ - taskTableSize = NCHANNELS * sizeof(TaskTableEntry); - /* align variable tables to size */ - varTabsOffset = taskTableSize + (uint32_t) taskTableDest; - if ((varTabsOffset & (VAR_TAB_SIZE - 1)) != 0) - varTabsOffset = (varTabsOffset + VAR_TAB_SIZE) & (~VAR_TAB_SIZE); - /* align function descriptor tables */ - varTabsSize = NCHANNELS * VAR_TAB_SIZE; - funcDescTabsOffset = varTabsOffset + varTabsSize; + taskTableSize = NCHANNELS * sizeof(TaskTableEntry); + /* align variable tables to size */ + varTabsOffset = taskTableSize + (uint32_t) taskTableDest; + if ((varTabsOffset & (VAR_TAB_SIZE - 1)) != 0) + varTabsOffset = (varTabsOffset + VAR_TAB_SIZE) & (~VAR_TAB_SIZE); + /* align function descriptor tables */ + varTabsSize = NCHANNELS * VAR_TAB_SIZE; + funcDescTabsOffset = varTabsOffset + varTabsSize; - if ((funcDescTabsOffset & (FUNCDESC_TAB_SIZE - 1)) != 0) - funcDescTabsOffset = (funcDescTabsOffset + FUNCDESC_TAB_SIZE) - & (~FUNCDESC_TAB_SIZE); + if ((funcDescTabsOffset & (FUNCDESC_TAB_SIZE - 1)) != 0) + funcDescTabsOffset = (funcDescTabsOffset + FUNCDESC_TAB_SIZE) + & (~FUNCDESC_TAB_SIZE); - funcDescTabsSize = FUNCDESC_TAB_NUM * FUNCDESC_TAB_SIZE; - contextSavesOffset = funcDescTabsOffset + funcDescTabsSize; - contextSavesSize = (NCHANNELS * CONTEXT_SAVE_SIZE); - fixedSize = taskTableSize + varTabsSize + funcDescTabsSize - + contextSavesSize; + funcDescTabsSize = FUNCDESC_TAB_NUM * FUNCDESC_TAB_SIZE; + contextSavesOffset = funcDescTabsOffset + funcDescTabsSize; + contextSavesSize = (NCHANNELS * CONTEXT_SAVE_SIZE); + fixedSize = taskTableSize + varTabsSize + funcDescTabsSize + + contextSavesSize; - /* zero the thing out */ - fixedPtr = (uint32_t *) taskTableDest; - for (i = 0; i < (fixedSize / 4); i++) - fixedPtr[i] = 0; + /* zero the thing out */ + fixedPtr = (uint32_t *) taskTableDest; + for (i = 0; i < (fixedSize / 4); i++) + fixedPtr[i] = 0; - entryPtr = (TaskTableEntry*) MCD_taskTable; - /* set up fixed pointers */ - for (i = 0; i < NCHANNELS; i++) - { - entryPtr[i].varTab = (uint32_t) varTabsOffset; /* update ptr to local value */ - entryPtr[i].FDTandFlags = (uint32_t) funcDescTabsOffset - | MCD_TT_FLAGS_DEF; - entryPtr[i].contextSaveSpace = (uint32_t) contextSavesOffset; - varTabsOffset += VAR_TAB_SIZE; + entryPtr = (TaskTableEntry*) MCD_taskTable; + /* set up fixed pointers */ + for (i = 0; i < NCHANNELS; i++) + { + entryPtr[i].varTab = (uint32_t) varTabsOffset; /* update ptr to local value */ + entryPtr[i].FDTandFlags = (uint32_t) funcDescTabsOffset + | MCD_TT_FLAGS_DEF; + entryPtr[i].contextSaveSpace = (uint32_t) contextSavesOffset; + varTabsOffset += VAR_TAB_SIZE; #ifdef MCD_INCLUDE_EU /* if not there is only one, just point to the same one */ - funcDescTabsOffset += FUNCDESC_TAB_SIZE; + funcDescTabsOffset += FUNCDESC_TAB_SIZE; #endif - contextSavesOffset += CONTEXT_SAVE_SIZE; - } - /* copy over the function descriptor table */ - for (i = 0; i < FUNCDESC_TAB_NUM; i++) - { - MCD_memcpy((void*) (entryPtr[i].FDTandFlags & ~MCD_TT_FLAGS_MASK), - (void*) MCD_funcDescTab0, FUNCDESC_TAB_SIZE); - } + contextSavesOffset += CONTEXT_SAVE_SIZE; + } + /* copy over the function descriptor table */ + for (i = 0; i < FUNCDESC_TAB_NUM; i++) + { + MCD_memcpy((void*) (entryPtr[i].FDTandFlags & ~MCD_TT_FLAGS_MASK), + (void*) MCD_funcDescTab0, FUNCDESC_TAB_SIZE); + } - /* copy model task table to where the context saves stuff leaves off*/ - MCD_modelTaskTable = (TaskTableEntry*) contextSavesOffset; + /* copy model task table to where the context saves stuff leaves off*/ + MCD_modelTaskTable = (TaskTableEntry*) contextSavesOffset; - MCD_memcpy((void*) MCD_modelTaskTable, (void*) MCD_modelTaskTableSrc, - NUMOFVARIANTS * sizeof(TaskTableEntry)); + MCD_memcpy((void*) MCD_modelTaskTable, (void*) MCD_modelTaskTableSrc, + NUMOFVARIANTS * sizeof(TaskTableEntry)); - entryPtr = MCD_modelTaskTable; /* point to local version of - model task table */ - taskDescTabsOffset = (uint32_t) MCD_modelTaskTable - + (NUMOFVARIANTS * sizeof(TaskTableEntry)); + entryPtr = MCD_modelTaskTable; /* point to local version of + model task table */ + taskDescTabsOffset = (uint32_t) MCD_modelTaskTable + + (NUMOFVARIANTS * sizeof(TaskTableEntry)); - /* copy actual task code and update TDT ptrs in local model task table */ - for (i = 0; i < NUMOFVARIANTS; i++) - { - taskDescTabSize = entryPtr[i].TDTend - entryPtr[i].TDTstart + 4; - MCD_memcpy((void*) taskDescTabsOffset, (void*) entryPtr[i].TDTstart, - taskDescTabSize); - entryPtr[i].TDTstart = (uint32_t) taskDescTabsOffset; - taskDescTabsOffset += taskDescTabSize; - entryPtr[i].TDTend = (uint32_t) taskDescTabsOffset - 4; - } + /* copy actual task code and update TDT ptrs in local model task table */ + for (i = 0; i < NUMOFVARIANTS; i++) + { + taskDescTabSize = entryPtr[i].TDTend - entryPtr[i].TDTstart + 4; + MCD_memcpy((void*) taskDescTabsOffset, (void*) entryPtr[i].TDTstart, + taskDescTabSize); + entryPtr[i].TDTstart = (uint32_t) taskDescTabsOffset; + taskDescTabsOffset += taskDescTabSize; + entryPtr[i].TDTend = (uint32_t) taskDescTabsOffset - 4; + } #ifdef MCD_INCLUDE_EU /* Tack single DMA BDs onto end of code so API controls - where they are since DMA might write to them */ - MCD_relocBuffDesc = (MCD_bufDesc*)(entryPtr[NUMOFVARIANTS - 1].TDTend + 4); + where they are since DMA might write to them */ + MCD_relocBuffDesc = (MCD_bufDesc*)(entryPtr[NUMOFVARIANTS - 1].TDTend + 4); #else /* DMA does not touch them so they can be wherever and we don't need to - waste SRAM on them */ - MCD_relocBuffDesc = MCD_singleBufDescs; + waste SRAM on them */ + MCD_relocBuffDesc = MCD_singleBufDescs; #endif - } - else - { - /* point the would-be relocated task tables and the - buffer descriptors to the ones the linker generated */ + } + else + { + /* point the would-be relocated task tables and the + buffer descriptors to the ones the linker generated */ - if (((uint32_t) MCD_realTaskTableSrc & 0x000001ff) != 0) - return (MCD_TABLE_UNALIGNED); + if (((uint32_t) MCD_realTaskTableSrc & 0x000001ff) != 0) + return (MCD_TABLE_UNALIGNED); - /* need to add code to make sure that every thing else is aligned properly TBD*/ - /* this is problematic if we init more than once or after running tasks, - need to add variable to see if we have aleady init'd */ - entryPtr = MCD_realTaskTableSrc; - for (i = 0; i < NCHANNELS; i++) - { - if (((entryPtr[i].varTab & (VAR_TAB_SIZE - 1)) != 0) - || ((entryPtr[i].FDTandFlags & (FUNCDESC_TAB_SIZE - 1)) != 0)) - return (MCD_TABLE_UNALIGNED); - } + /* need to add code to make sure that every thing else is aligned properly TBD*/ + /* this is problematic if we init more than once or after running tasks, + need to add variable to see if we have aleady init'd */ + entryPtr = MCD_realTaskTableSrc; + for (i = 0; i < NCHANNELS; i++) + { + if (((entryPtr[i].varTab & (VAR_TAB_SIZE - 1)) != 0) + || ((entryPtr[i].FDTandFlags & (FUNCDESC_TAB_SIZE - 1)) != 0)) + return (MCD_TABLE_UNALIGNED); + } - MCD_taskTable = MCD_realTaskTableSrc; - MCD_modelTaskTable = MCD_modelTaskTableSrc; - MCD_relocBuffDesc = MCD_singleBufDescs; - } + MCD_taskTable = MCD_realTaskTableSrc; + MCD_modelTaskTable = MCD_modelTaskTableSrc; + MCD_relocBuffDesc = MCD_singleBufDescs; + } - /* Make all channels as totally inactive, and remember them as such: */ + /* Make all channels as totally inactive, and remember them as such: */ - MCD_dmaBar->taskbar = (uint32_t) MCD_taskTable; - for (i = 0; i < NCHANNELS; i++) - { - MCD_dmaBar->taskControl[i] = 0x0; - MCD_chStatus[i] = MCD_NO_DMA; - } + MCD_dmaBar->taskbar = (uint32_t) MCD_taskTable; + for (i = 0; i < NCHANNELS; i++) + { + MCD_dmaBar->taskControl[i] = 0x0; + MCD_chStatus[i] = MCD_NO_DMA; + } - /* Set up pausing mechanism to inactive state: */ - MCD_dmaBar->debugComp1 = 0; /* no particular values yet for either comparator registers */ - MCD_dmaBar->debugComp2 = 0; - MCD_dmaBar->debugControl = DBG_CTL_DISABLE; - MCD_dmaBar->debugStatus = DBG_KILL_ALL_STAT; + /* Set up pausing mechanism to inactive state: */ + MCD_dmaBar->debugComp1 = 0; /* no particular values yet for either comparator registers */ + MCD_dmaBar->debugComp2 = 0; + MCD_dmaBar->debugControl = DBG_CTL_DISABLE; + MCD_dmaBar->debugStatus = DBG_KILL_ALL_STAT; - /* enable or disable commbus prefetch, really need an ifdef or - something to keep from trying to set this in the 8220 */ - if ((flags & MCD_COMM_PREFETCH_EN) != 0) - MCD_dmaBar->ptdControl &= ~PTD_CTL_COMM_PREFETCH; - else - MCD_dmaBar->ptdControl |= PTD_CTL_COMM_PREFETCH; + /* enable or disable commbus prefetch, really need an ifdef or + something to keep from trying to set this in the 8220 */ + if ((flags & MCD_COMM_PREFETCH_EN) != 0) + MCD_dmaBar->ptdControl &= ~PTD_CTL_COMM_PREFETCH; + else + MCD_dmaBar->ptdControl |= PTD_CTL_COMM_PREFETCH; - return (MCD_OK); + return (MCD_OK); } /*********************** End of MCD_initDma() ***********************/ @@ -312,36 +312,36 @@ int MCD_initDma(dmaRegs *dmaBarAddr, void *taskTableDest, uint32_t flags) */ int MCD_dmaStatus(int channel) { - uint16_t tcrValue; + uint16_t tcrValue; - if ((channel < 0) || (channel >= NCHANNELS)) - return (MCD_CHANNEL_INVALID); + if ((channel < 0) || (channel >= NCHANNELS)) + return (MCD_CHANNEL_INVALID); - tcrValue = MCD_dmaBar->taskControl[channel]; - if ((tcrValue & TASK_CTL_EN) == 0) - { /* nothing running */ - /* if last reported with task enabled */ - if (MCD_chStatus[channel] == MCD_RUNNING - || MCD_chStatus[channel] == MCD_IDLE) - MCD_chStatus[channel] = MCD_DONE; - } - else /* something is running */ - { - /* There are three possibilities: paused, running or idle. */ - if (MCD_chStatus[channel] == MCD_RUNNING - || MCD_chStatus[channel] == MCD_IDLE) - { - MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT; - /* This register is selected to know which initiator is - actually asserted. */ - if ((MCD_dmaBar->ptdDebug >> channel) & 0x1) - MCD_chStatus[channel] = MCD_RUNNING; - else - MCD_chStatus[channel] = MCD_IDLE; - /* do not change the status if it is already paused. */ - } - } - return MCD_chStatus[channel]; + tcrValue = MCD_dmaBar->taskControl[channel]; + if ((tcrValue & TASK_CTL_EN) == 0) + { /* nothing running */ + /* if last reported with task enabled */ + if (MCD_chStatus[channel] == MCD_RUNNING + || MCD_chStatus[channel] == MCD_IDLE) + MCD_chStatus[channel] = MCD_DONE; + } + else /* something is running */ + { + /* There are three possibilities: paused, running or idle. */ + if (MCD_chStatus[channel] == MCD_RUNNING + || MCD_chStatus[channel] == MCD_IDLE) + { + MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT; + /* This register is selected to know which initiator is + actually asserted. */ + if ((MCD_dmaBar->ptdDebug >> channel) & 0x1) + MCD_chStatus[channel] = MCD_RUNNING; + else + MCD_chStatus[channel] = MCD_IDLE; + /* do not change the status if it is already paused. */ + } + } + return MCD_chStatus[channel]; } /******************** End of MCD_dmaStatus() ************************/ @@ -353,221 +353,221 @@ int MCD_dmaStatus(int channel) */ int MCD_startDma(int channel, /* the channel on which to run the DMA */ - int8_t *srcAddr, /* the address to move data from, or physical buffer-descriptor address */ - int16_t srcIncr, /* the amount to increment the source address per transfer */ - int8_t *destAddr, /* the address to move data to */ - int16_t destIncr, /* the amount to increment the destination address per transfer */ - uint32_t dmaSize, /* the number of bytes to transfer independent of the transfer size */ - uint32_t xferSize, /* the number bytes in of each data movement (1, 2, or 4) */ - uint32_t initiator, /* what device initiates the DMA */ - int priority, /* priority of the DMA */ - uint32_t flags, /* flags describing the DMA */ - uint32_t funcDesc /* a description of byte swapping, bit swapping, and CRC actions */ + int8_t *srcAddr, /* the address to move data from, or physical buffer-descriptor address */ + int16_t srcIncr, /* the amount to increment the source address per transfer */ + int8_t *destAddr, /* the address to move data to */ + int16_t destIncr, /* the amount to increment the destination address per transfer */ + uint32_t dmaSize, /* the number of bytes to transfer independent of the transfer size */ + uint32_t xferSize, /* the number bytes in of each data movement (1, 2, or 4) */ + uint32_t initiator, /* what device initiates the DMA */ + int priority, /* priority of the DMA */ + uint32_t flags, /* flags describing the DMA */ + uint32_t funcDesc /* a description of byte swapping, bit swapping, and CRC actions */ #ifdef MCD_NEED_ADDR_TRANS - int8_t *srcAddrVirt /* virtual buffer descriptor address TBD*/ + int8_t *srcAddrVirt /* virtual buffer descriptor address TBD*/ #endif - ) + ) { - int srcRsdIncr, destRsdIncr; - int *cSave; - short xferSizeIncr; - int tcrCount = 0; + int srcRsdIncr, destRsdIncr; + int *cSave; + short xferSizeIncr; + int tcrCount = 0; #ifdef MCD_INCLUDE_EU - uint32_t *realFuncArray; + uint32_t *realFuncArray; #endif - if ((channel < 0) || (channel >= NCHANNELS)) - return (MCD_CHANNEL_INVALID); + if ((channel < 0) || (channel >= NCHANNELS)) + return (MCD_CHANNEL_INVALID); - /* tbd - need to determine the proper response to a bad funcDesc when not - including EU functions, for now, assign a benign funcDesc, but maybe - should return an error */ + /* tbd - need to determine the proper response to a bad funcDesc when not + including EU functions, for now, assign a benign funcDesc, but maybe + should return an error */ #ifndef MCD_INCLUDE_EU - funcDesc = MCD_FUNC_NOEU1; + funcDesc = MCD_FUNC_NOEU1; #endif #ifdef MCD_DEBUG - printf("startDma:Setting up params\n"); + printf("startDma:Setting up params\n"); #endif - /* Set us up for task-wise priority. We don't technically need to do this on every start, but - since the register involved is in the same longword as other registers that users are in control - of, setting it more than once is probably preferable. That since the documentation doesn't seem - to be completely consistent about the nature of the PTD control register. */ - MCD_dmaBar->ptdControl |= (uint16_t) 0x8000; + /* Set us up for task-wise priority. We don't technically need to do this on every start, but + since the register involved is in the same longword as other registers that users are in control + of, setting it more than once is probably preferable. That since the documentation doesn't seem + to be completely consistent about the nature of the PTD control register. */ + MCD_dmaBar->ptdControl |= (uint16_t) 0x8000; #if 1 /* Not sure what we need to keep here rtm TBD */ - /* Calculate additional parameters to the regular DMA calls. */ - srcRsdIncr = srcIncr < 0 ? -1 : (srcIncr > 0 ? 1 : 0); - destRsdIncr = destIncr < 0 ? -1 : (destIncr > 0 ? 1 : 0); + /* Calculate additional parameters to the regular DMA calls. */ + srcRsdIncr = srcIncr < 0 ? -1 : (srcIncr > 0 ? 1 : 0); + destRsdIncr = destIncr < 0 ? -1 : (destIncr > 0 ? 1 : 0); - xferSizeIncr = (xferSize & 0xffff) | 0x20000000; + xferSizeIncr = (xferSize & 0xffff) | 0x20000000; - /* Remember for each channel which variant is running. */ - MCD_remVariants.remSrcRsdIncr[channel] = srcRsdIncr; - MCD_remVariants.remDestRsdIncr[channel] = destRsdIncr; - MCD_remVariants.remDestIncr[channel] = destIncr; - MCD_remVariants.remSrcIncr[channel] = srcIncr; - MCD_remVariants.remXferSize[channel] = xferSize; + /* Remember for each channel which variant is running. */ + MCD_remVariants.remSrcRsdIncr[channel] = srcRsdIncr; + MCD_remVariants.remDestRsdIncr[channel] = destRsdIncr; + MCD_remVariants.remDestIncr[channel] = destIncr; + MCD_remVariants.remSrcIncr[channel] = srcIncr; + MCD_remVariants.remXferSize[channel] = xferSize; #endif - cSave = (int*) (MCD_taskTable[channel].contextSaveSpace) + CSAVE_OFFSET - + CURRBD; + cSave = (int*) (MCD_taskTable[channel].contextSaveSpace) + CSAVE_OFFSET + + CURRBD; #ifdef MCD_INCLUDE_EU /* may move this to EU specific calls */ - realFuncArray = (uint32_t *) (MCD_taskTable[channel].FDTandFlags & 0xffffff00); - /* Modify the LURC's normal and byte-residue-loop functions according to parameter. */ - realFuncArray[(LURC*16)] = xferSize == 4 ? funcDesc : xferSize == 2 ? funcDesc & 0xfffff00f : funcDesc & 0xffff000f; - realFuncArray[(LURC*16+1)] = (funcDesc & MCD_BYTE_SWAP_KILLER) | MCD_NO_BYTE_SWAP_ATALL; + realFuncArray = (uint32_t *) (MCD_taskTable[channel].FDTandFlags & 0xffffff00); + /* Modify the LURC's normal and byte-residue-loop functions according to parameter. */ + realFuncArray[(LURC*16)] = xferSize == 4 ? funcDesc : xferSize == 2 ? funcDesc & 0xfffff00f : funcDesc & 0xffff000f; + realFuncArray[(LURC*16+1)] = (funcDesc & MCD_BYTE_SWAP_KILLER) | MCD_NO_BYTE_SWAP_ATALL; #endif - /* - * Write the initiator field in the TCR, and also set the initiator-hold - * bit. Note that,due to a hardware quirk, this could collide with an - * MDE access to the initiator-register file, so we have to verify that the write - * reads back correctly. - */ + /* + * Write the initiator field in the TCR, and also set the initiator-hold + * bit. Note that,due to a hardware quirk, this could collide with an + * MDE access to the initiator-register file, so we have to verify that the write + * reads back correctly. + */ - MCD_dmaBar->taskControl[channel] = (initiator << 8) | TASK_CTL_HIPRITSKEN - | TASK_CTL_HLDINITNUM; + MCD_dmaBar->taskControl[channel] = (initiator << 8) | TASK_CTL_HIPRITSKEN + | TASK_CTL_HLDINITNUM; - while (((MCD_dmaBar->taskControl[channel] & 0x1fff) - != ((initiator << 8) | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM)) - && (tcrCount < 1000)) - { - tcrCount++; - /*MCD_dmaBar->ptd_tcr[channel] = (initiator << 8) | 0x0020;*/ - MCD_dmaBar->taskControl[channel] = (initiator << 8) - | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM; - } + while (((MCD_dmaBar->taskControl[channel] & 0x1fff) + != ((initiator << 8) | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM)) + && (tcrCount < 1000)) + { + tcrCount++; + /*MCD_dmaBar->ptd_tcr[channel] = (initiator << 8) | 0x0020;*/ + MCD_dmaBar->taskControl[channel] = (initiator << 8) + | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM; + } - MCD_dmaBar->priority[channel] = (uint8_t) priority & PRIORITY_PRI_MASK; + MCD_dmaBar->priority[channel] = (uint8_t) priority & PRIORITY_PRI_MASK; - /* should be albe to handle this stuff with only one write to ts reg - tbd */ - if (channel < 8 && channel >= 0) - { - MCD_dmaBar->taskSize0 &= ~(0xf << (7 - channel) * 4); - MCD_dmaBar->taskSize0 |= (xferSize & 3) << (((7 - channel) * 4) + 2); - MCD_dmaBar->taskSize0 |= (xferSize & 3) << ((7 - channel) * 4); - } - else - { - MCD_dmaBar->taskSize1 &= ~(0xf << (15 - channel) * 4); - MCD_dmaBar->taskSize1 |= (xferSize & 3) << (((15 - channel) * 4) + 2); - MCD_dmaBar->taskSize1 |= (xferSize & 3) << ((15 - channel) * 4); - } + /* should be albe to handle this stuff with only one write to ts reg - tbd */ + if (channel < 8 && channel >= 0) + { + MCD_dmaBar->taskSize0 &= ~(0xf << (7 - channel) * 4); + MCD_dmaBar->taskSize0 |= (xferSize & 3) << (((7 - channel) * 4) + 2); + MCD_dmaBar->taskSize0 |= (xferSize & 3) << ((7 - channel) * 4); + } + else + { + MCD_dmaBar->taskSize1 &= ~(0xf << (15 - channel) * 4); + MCD_dmaBar->taskSize1 |= (xferSize & 3) << (((15 - channel) * 4) + 2); + MCD_dmaBar->taskSize1 |= (xferSize & 3) << ((15 - channel) * 4); + } - /* setup task table flags/options which mostly control the line buffers */ - MCD_taskTable[channel].FDTandFlags &= ~MCD_TT_FLAGS_MASK; - MCD_taskTable[channel].FDTandFlags |= (MCD_TT_FLAGS_MASK & flags); + /* setup task table flags/options which mostly control the line buffers */ + MCD_taskTable[channel].FDTandFlags &= ~MCD_TT_FLAGS_MASK; + MCD_taskTable[channel].FDTandFlags |= (MCD_TT_FLAGS_MASK & flags); - if (flags & MCD_FECTX_DMA) - { - /* TDTStart and TDTEnd */ - MCD_taskTable[channel].TDTstart = - MCD_modelTaskTable[TASK_FECTX].TDTstart; - MCD_taskTable[channel].TDTend = MCD_modelTaskTable[TASK_FECTX].TDTend; - MCD_startDmaENetXmit(srcAddr, srcAddr, destAddr, MCD_taskTable, channel); - } - else if (flags & MCD_FECRX_DMA) - { - /* TDTStart and TDTEnd */ - MCD_taskTable[channel].TDTstart = - MCD_modelTaskTable[TASK_FECRX].TDTstart; - MCD_taskTable[channel].TDTend = MCD_modelTaskTable[TASK_FECRX].TDTend; - MCD_startDmaENetRcv(srcAddr, srcAddr, destAddr, MCD_taskTable, channel); - } - else if (flags & MCD_SINGLE_DMA) - { - /* - * this buffer descriptor is used for storing off initial parameters for later - * progress query calculation and for the DMA to write the resulting checksum - * The DMA does not use this to determine how to operate, that info is passed - * with the init routine - */ - MCD_relocBuffDesc[channel].srcAddr = srcAddr; - MCD_relocBuffDesc[channel].destAddr = destAddr; - MCD_relocBuffDesc[channel].lastDestAddr = destAddr; /* definitely not its final value */ - MCD_relocBuffDesc[channel].dmaSize = dmaSize; - MCD_relocBuffDesc[channel].flags = 0; /* not used */ - MCD_relocBuffDesc[channel].csumResult = 0; /* not used */ - MCD_relocBuffDesc[channel].next = 0; /* not used */ + if (flags & MCD_FECTX_DMA) + { + /* TDTStart and TDTEnd */ + MCD_taskTable[channel].TDTstart = + MCD_modelTaskTable[TASK_FECTX].TDTstart; + MCD_taskTable[channel].TDTend = MCD_modelTaskTable[TASK_FECTX].TDTend; + MCD_startDmaENetXmit(srcAddr, srcAddr, destAddr, MCD_taskTable, channel); + } + else if (flags & MCD_FECRX_DMA) + { + /* TDTStart and TDTEnd */ + MCD_taskTable[channel].TDTstart = + MCD_modelTaskTable[TASK_FECRX].TDTstart; + MCD_taskTable[channel].TDTend = MCD_modelTaskTable[TASK_FECRX].TDTend; + MCD_startDmaENetRcv(srcAddr, srcAddr, destAddr, MCD_taskTable, channel); + } + else if (flags & MCD_SINGLE_DMA) + { + /* + * this buffer descriptor is used for storing off initial parameters for later + * progress query calculation and for the DMA to write the resulting checksum + * The DMA does not use this to determine how to operate, that info is passed + * with the init routine + */ + MCD_relocBuffDesc[channel].srcAddr = srcAddr; + MCD_relocBuffDesc[channel].destAddr = destAddr; + MCD_relocBuffDesc[channel].lastDestAddr = destAddr; /* definitely not its final value */ + MCD_relocBuffDesc[channel].dmaSize = dmaSize; + MCD_relocBuffDesc[channel].flags = 0; /* not used */ + MCD_relocBuffDesc[channel].csumResult = 0; /* not used */ + MCD_relocBuffDesc[channel].next = 0; /* not used */ - /* Initialize the progress-querying stuff to show no progress:*/ - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[SRCPTR - + CSAVE_OFFSET] = (int) srcAddr; - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DESTPTR - + CSAVE_OFFSET] = (int) destAddr; - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DCOUNT - + CSAVE_OFFSET] = 0; - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[CURRBD - + CSAVE_OFFSET] = (uint32_t) &(MCD_relocBuffDesc[channel]); - /* tbd - need to keep the user from trying to call the EU routine - when MCD_INCLUDE_EU is not defined */ - if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) - { - /* TDTStart and TDTEnd */ - MCD_taskTable[channel].TDTstart = - MCD_modelTaskTable[TASK_SINGLENOEU].TDTstart; - MCD_taskTable[channel].TDTend = - MCD_modelTaskTable[TASK_SINGLENOEU].TDTend; - MCD_startDmaSingleNoEu(srcAddr, srcIncr, destAddr, destIncr, - dmaSize, xferSizeIncr, flags, - (int *) &(MCD_relocBuffDesc[channel]), cSave, MCD_taskTable, - channel); - } - else - { - /* TDTStart and TDTEnd */ - MCD_taskTable[channel].TDTstart = - MCD_modelTaskTable[TASK_SINGLEEU].TDTstart; - MCD_taskTable[channel].TDTend = - MCD_modelTaskTable[TASK_SINGLEEU].TDTend; - MCD_startDmaSingleEu(srcAddr, srcIncr, destAddr, destIncr, dmaSize, - xferSizeIncr, flags, (int *) &(MCD_relocBuffDesc[channel]), - cSave, MCD_taskTable, channel); - } - } - else - { /* chained DMAS */ - /* Initialize the progress-querying stuff to show no progress:*/ + /* Initialize the progress-querying stuff to show no progress:*/ + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[SRCPTR + + CSAVE_OFFSET] = (int) srcAddr; + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DESTPTR + + CSAVE_OFFSET] = (int) destAddr; + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DCOUNT + + CSAVE_OFFSET] = 0; + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[CURRBD + + CSAVE_OFFSET] = (uint32_t) &(MCD_relocBuffDesc[channel]); + /* tbd - need to keep the user from trying to call the EU routine + when MCD_INCLUDE_EU is not defined */ + if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) + { + /* TDTStart and TDTEnd */ + MCD_taskTable[channel].TDTstart = + MCD_modelTaskTable[TASK_SINGLENOEU].TDTstart; + MCD_taskTable[channel].TDTend = + MCD_modelTaskTable[TASK_SINGLENOEU].TDTend; + MCD_startDmaSingleNoEu(srcAddr, srcIncr, destAddr, destIncr, + dmaSize, xferSizeIncr, flags, + (int *) &(MCD_relocBuffDesc[channel]), cSave, MCD_taskTable, + channel); + } + else + { + /* TDTStart and TDTEnd */ + MCD_taskTable[channel].TDTstart = + MCD_modelTaskTable[TASK_SINGLEEU].TDTstart; + MCD_taskTable[channel].TDTend = + MCD_modelTaskTable[TASK_SINGLEEU].TDTend; + MCD_startDmaSingleEu(srcAddr, srcIncr, destAddr, destIncr, dmaSize, + xferSizeIncr, flags, (int *) &(MCD_relocBuffDesc[channel]), + cSave, MCD_taskTable, channel); + } + } + else + { /* chained DMAS */ + /* Initialize the progress-querying stuff to show no progress:*/ #if 1 /* (!defined(MCD_NEED_ADDR_TRANS)) */ - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[SRCPTR - + CSAVE_OFFSET] = (int) ((MCD_bufDesc*) srcAddr)->srcAddr; - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DESTPTR - + CSAVE_OFFSET] = (int) ((MCD_bufDesc*) srcAddr)->destAddr; + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[SRCPTR + + CSAVE_OFFSET] = (int) ((MCD_bufDesc*) srcAddr)->srcAddr; + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DESTPTR + + CSAVE_OFFSET] = (int) ((MCD_bufDesc*) srcAddr)->destAddr; #else /* if using address translation, need the virtual addr of the first buffdesc */ - ((volatile int *)MCD_taskTable[channel].contextSaveSpace)[SRCPTR + CSAVE_OFFSET] - = (int)((MCD_bufDesc*) srcAddrVirt)->srcAddr; - ((volatile int *)MCD_taskTable[channel].contextSaveSpace)[DESTPTR + CSAVE_OFFSET] - = (int)((MCD_bufDesc*) srcAddrVirt)->destAddr; + ((volatile int *)MCD_taskTable[channel].contextSaveSpace)[SRCPTR + CSAVE_OFFSET] + = (int)((MCD_bufDesc*) srcAddrVirt)->srcAddr; + ((volatile int *)MCD_taskTable[channel].contextSaveSpace)[DESTPTR + CSAVE_OFFSET] + = (int)((MCD_bufDesc*) srcAddrVirt)->destAddr; #endif - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DCOUNT - + CSAVE_OFFSET] = 0; - ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[CURRBD - + CSAVE_OFFSET] = (uint32_t) srcAddr; + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[DCOUNT + + CSAVE_OFFSET] = 0; + ((volatile int *) MCD_taskTable[channel].contextSaveSpace)[CURRBD + + CSAVE_OFFSET] = (uint32_t) srcAddr; - if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) - { - /*TDTStart and TDTEnd*/ - MCD_taskTable[channel].TDTstart = - MCD_modelTaskTable[TASK_CHAINNOEU].TDTstart; - MCD_taskTable[channel].TDTend = - MCD_modelTaskTable[TASK_CHAINNOEU].TDTend; - MCD_startDmaChainNoEu((int *) srcAddr, srcIncr, destIncr, xferSize, - xferSizeIncr, cSave, MCD_taskTable, channel); - } - else - { - /*TDTStart and TDTEnd*/ - MCD_taskTable[channel].TDTstart = - MCD_modelTaskTable[TASK_CHAINEU].TDTstart; - MCD_taskTable[channel].TDTend = - MCD_modelTaskTable[TASK_CHAINEU].TDTend; - MCD_startDmaChainEu((int *) srcAddr, srcIncr, destIncr, xferSize, - xferSizeIncr, cSave, MCD_taskTable, channel); - } - } - MCD_chStatus[channel] = MCD_IDLE; - return (MCD_OK); + if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) + { + /*TDTStart and TDTEnd*/ + MCD_taskTable[channel].TDTstart = + MCD_modelTaskTable[TASK_CHAINNOEU].TDTstart; + MCD_taskTable[channel].TDTend = + MCD_modelTaskTable[TASK_CHAINNOEU].TDTend; + MCD_startDmaChainNoEu((int *) srcAddr, srcIncr, destIncr, xferSize, + xferSizeIncr, cSave, MCD_taskTable, channel); + } + else + { + /*TDTStart and TDTEnd*/ + MCD_taskTable[channel].TDTstart = + MCD_modelTaskTable[TASK_CHAINEU].TDTstart; + MCD_taskTable[channel].TDTend = + MCD_modelTaskTable[TASK_CHAINEU].TDTend; + MCD_startDmaChainEu((int *) srcAddr, srcIncr, destIncr, xferSize, + xferSizeIncr, cSave, MCD_taskTable, channel); + } + } + MCD_chStatus[channel] = MCD_IDLE; + return (MCD_OK); } /************************ End of MCD_startDma() *********************/ @@ -606,134 +606,134 @@ int MCD_startDma(int channel, /* the channel on which to run the DMA */ int MCD_XferProgrQuery(int channel, MCD_XferProg *progRep) { - MCD_XferProg prevRep; - int again; /* true if we are to try again to get consistent results */ - int i; /* used as a time-waste counter */ - int destDiffBytes; /* Total number of bytes that we think actually got xfered. */ - int numIterations; /* number of iterations */ - int bytesNotXfered; /* bytes that did not get xfered. */ - int8_t *LWAlignedInitDestAddr, *LWAlignedCurrDestAddr; - int subModVal, addModVal; /* Mode values to added and subtracted from the - final destAddr */ + MCD_XferProg prevRep; + int again; /* true if we are to try again to get consistent results */ + int i; /* used as a time-waste counter */ + int destDiffBytes; /* Total number of bytes that we think actually got xfered. */ + int numIterations; /* number of iterations */ + int bytesNotXfered; /* bytes that did not get xfered. */ + int8_t *LWAlignedInitDestAddr, *LWAlignedCurrDestAddr; + int subModVal, addModVal; /* Mode values to added and subtracted from the + final destAddr */ - if ((channel < 0) || (channel >= NCHANNELS)) - return (MCD_CHANNEL_INVALID); + if ((channel < 0) || (channel >= NCHANNELS)) + return (MCD_CHANNEL_INVALID); - /* Read a trial value for the progress-reporting values*/ - prevRep.lastSrcAddr = - (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[SRCPTR - + CSAVE_OFFSET]; - prevRep.lastDestAddr = - (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DESTPTR - + CSAVE_OFFSET]; - prevRep.dmaSize = - ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DCOUNT - + CSAVE_OFFSET]; - prevRep.currBufDesc = - (MCD_bufDesc*) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[CURRBD - + CSAVE_OFFSET]; - /* Repeatedly reread those values until they match previous values: */ - do - { - /* Waste a little bit of time to ensure stability: */ - for (i = 0; i < STABTIME; i++) - i += i >> 2; /* make sure this loop does something so that it doesn't get optimized out */ - /* Check them again: */ - progRep->lastSrcAddr = - (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[SRCPTR - + CSAVE_OFFSET]; - progRep->lastDestAddr = - (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DESTPTR - + CSAVE_OFFSET]; - progRep->dmaSize = - ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DCOUNT - + CSAVE_OFFSET]; - progRep->currBufDesc = - (MCD_bufDesc*) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[CURRBD - + CSAVE_OFFSET]; - /* See if they match: */ - if (prevRep.lastSrcAddr != progRep->lastSrcAddr - || prevRep.lastDestAddr != progRep->lastDestAddr - || prevRep.dmaSize != progRep->dmaSize - || prevRep.currBufDesc != progRep->currBufDesc) - { - /* If they don't match, remember previous values and try again:*/ - prevRep.lastSrcAddr = progRep->lastSrcAddr; - prevRep.lastDestAddr = progRep->lastDestAddr; - prevRep.dmaSize = progRep->dmaSize; - prevRep.currBufDesc = progRep->currBufDesc; - again = MCD_TRUE; - } - else - again = MCD_FALSE; - } while (again == MCD_TRUE); + /* Read a trial value for the progress-reporting values*/ + prevRep.lastSrcAddr = + (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[SRCPTR + + CSAVE_OFFSET]; + prevRep.lastDestAddr = + (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DESTPTR + + CSAVE_OFFSET]; + prevRep.dmaSize = + ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DCOUNT + + CSAVE_OFFSET]; + prevRep.currBufDesc = + (MCD_bufDesc*) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[CURRBD + + CSAVE_OFFSET]; + /* Repeatedly reread those values until they match previous values: */ + do + { + /* Waste a little bit of time to ensure stability: */ + for (i = 0; i < STABTIME; i++) + i += i >> 2; /* make sure this loop does something so that it doesn't get optimized out */ + /* Check them again: */ + progRep->lastSrcAddr = + (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[SRCPTR + + CSAVE_OFFSET]; + progRep->lastDestAddr = + (int8_t *) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DESTPTR + + CSAVE_OFFSET]; + progRep->dmaSize = + ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[DCOUNT + + CSAVE_OFFSET]; + progRep->currBufDesc = + (MCD_bufDesc*) ((volatile int*) MCD_taskTable[channel].contextSaveSpace)[CURRBD + + CSAVE_OFFSET]; + /* See if they match: */ + if (prevRep.lastSrcAddr != progRep->lastSrcAddr + || prevRep.lastDestAddr != progRep->lastDestAddr + || prevRep.dmaSize != progRep->dmaSize + || prevRep.currBufDesc != progRep->currBufDesc) + { + /* If they don't match, remember previous values and try again:*/ + prevRep.lastSrcAddr = progRep->lastSrcAddr; + prevRep.lastDestAddr = progRep->lastDestAddr; + prevRep.dmaSize = progRep->dmaSize; + prevRep.currBufDesc = progRep->currBufDesc; + again = MCD_TRUE; + } + else + again = MCD_FALSE; + } while (again == MCD_TRUE); - /* Update the dCount, srcAddr and destAddr */ - /* To calculate dmaCount, we consider destination address. C - overs M1,P1,Z for destination */ - switch (MCD_remVariants.remDestRsdIncr[channel]) - { - case MINUS1: - subModVal = ((int) progRep->lastDestAddr) - & ((MCD_remVariants.remXferSize[channel]) - 1); - addModVal = ((int) progRep->currBufDesc->destAddr) - & ((MCD_remVariants.remXferSize[channel]) - 1); - LWAlignedInitDestAddr = (progRep->currBufDesc->destAddr) - addModVal; - LWAlignedCurrDestAddr = (progRep->lastDestAddr) - subModVal; - destDiffBytes = LWAlignedInitDestAddr - LWAlignedCurrDestAddr; - bytesNotXfered = (destDiffBytes / MCD_remVariants.remDestIncr[channel]) - * (MCD_remVariants.remDestIncr[channel] - + MCD_remVariants.remXferSize[channel]); - progRep->dmaSize = destDiffBytes - bytesNotXfered + addModVal - - subModVal; - break; - case ZERO: - progRep->lastDestAddr = progRep->currBufDesc->destAddr; - break; - case PLUS1: - /* This value has to be subtracted from the final calculated dCount. */ - subModVal = ((int) progRep->currBufDesc->destAddr) - & ((MCD_remVariants.remXferSize[channel]) - 1); - /* These bytes are already in lastDestAddr. */ - addModVal = ((int) progRep->lastDestAddr) - & ((MCD_remVariants.remXferSize[channel]) - 1); - LWAlignedInitDestAddr = (progRep->currBufDesc->destAddr) - subModVal; - LWAlignedCurrDestAddr = (progRep->lastDestAddr) - addModVal; - destDiffBytes = (progRep->lastDestAddr - LWAlignedInitDestAddr); - numIterations = (LWAlignedCurrDestAddr - LWAlignedInitDestAddr) - / MCD_remVariants.remDestIncr[channel]; - bytesNotXfered = numIterations - * (MCD_remVariants.remDestIncr[channel] - - MCD_remVariants.remXferSize[channel]); - progRep->dmaSize = destDiffBytes - bytesNotXfered - subModVal; - break; - default: - break; - } + /* Update the dCount, srcAddr and destAddr */ + /* To calculate dmaCount, we consider destination address. C + overs M1,P1,Z for destination */ + switch (MCD_remVariants.remDestRsdIncr[channel]) + { + case MINUS1: + subModVal = ((int) progRep->lastDestAddr) + & ((MCD_remVariants.remXferSize[channel]) - 1); + addModVal = ((int) progRep->currBufDesc->destAddr) + & ((MCD_remVariants.remXferSize[channel]) - 1); + LWAlignedInitDestAddr = (progRep->currBufDesc->destAddr) - addModVal; + LWAlignedCurrDestAddr = (progRep->lastDestAddr) - subModVal; + destDiffBytes = LWAlignedInitDestAddr - LWAlignedCurrDestAddr; + bytesNotXfered = (destDiffBytes / MCD_remVariants.remDestIncr[channel]) + * (MCD_remVariants.remDestIncr[channel] + + MCD_remVariants.remXferSize[channel]); + progRep->dmaSize = destDiffBytes - bytesNotXfered + addModVal + - subModVal; + break; + case ZERO: + progRep->lastDestAddr = progRep->currBufDesc->destAddr; + break; + case PLUS1: + /* This value has to be subtracted from the final calculated dCount. */ + subModVal = ((int) progRep->currBufDesc->destAddr) + & ((MCD_remVariants.remXferSize[channel]) - 1); + /* These bytes are already in lastDestAddr. */ + addModVal = ((int) progRep->lastDestAddr) + & ((MCD_remVariants.remXferSize[channel]) - 1); + LWAlignedInitDestAddr = (progRep->currBufDesc->destAddr) - subModVal; + LWAlignedCurrDestAddr = (progRep->lastDestAddr) - addModVal; + destDiffBytes = (progRep->lastDestAddr - LWAlignedInitDestAddr); + numIterations = (LWAlignedCurrDestAddr - LWAlignedInitDestAddr) + / MCD_remVariants.remDestIncr[channel]; + bytesNotXfered = numIterations + * (MCD_remVariants.remDestIncr[channel] + - MCD_remVariants.remXferSize[channel]); + progRep->dmaSize = destDiffBytes - bytesNotXfered - subModVal; + break; + default: + break; + } - /* This covers M1,P1,Z for source */ - switch (MCD_remVariants.remSrcRsdIncr[channel]) - { - case MINUS1: - progRep->lastSrcAddr = progRep->currBufDesc->srcAddr - + (MCD_remVariants.remSrcIncr[channel] - * (progRep->dmaSize - / MCD_remVariants.remXferSize[channel])); - break; - case ZERO: - progRep->lastSrcAddr = progRep->currBufDesc->srcAddr; - break; - case PLUS1: - progRep->lastSrcAddr = progRep->currBufDesc->srcAddr - + (MCD_remVariants.remSrcIncr[channel] - * (progRep->dmaSize - / MCD_remVariants.remXferSize[channel])); - break; - default: - break; - } + /* This covers M1,P1,Z for source */ + switch (MCD_remVariants.remSrcRsdIncr[channel]) + { + case MINUS1: + progRep->lastSrcAddr = progRep->currBufDesc->srcAddr + + (MCD_remVariants.remSrcIncr[channel] + * (progRep->dmaSize + / MCD_remVariants.remXferSize[channel])); + break; + case ZERO: + progRep->lastSrcAddr = progRep->currBufDesc->srcAddr; + break; + case PLUS1: + progRep->lastSrcAddr = progRep->currBufDesc->srcAddr + + (MCD_remVariants.remSrcIncr[channel] + * (progRep->dmaSize + / MCD_remVariants.remXferSize[channel])); + break; + default: + break; + } - return (MCD_OK); + return (MCD_OK); } /******************* End of MCD_XferProgrQuery() ********************/ @@ -746,17 +746,17 @@ int MCD_XferProgrQuery(int channel, MCD_XferProg *progRep) */ static void MCD_resmActions(int channel) { - uint32_t debugStatus; + uint32_t debugStatus; - MCD_dmaBar->debugControl = DBG_CTL_DISABLE; - debugStatus = MCD_dmaBar->debugStatus; - MCD_dmaBar->debugStatus = debugStatus; - MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT; /* This register is selected to know - which initiator is actually asserted. */ - if ((MCD_dmaBar->ptdDebug >> channel) & 0x1) - MCD_chStatus[channel] = MCD_RUNNING; - else - MCD_chStatus[channel] = MCD_IDLE; + MCD_dmaBar->debugControl = DBG_CTL_DISABLE; + debugStatus = MCD_dmaBar->debugStatus; + MCD_dmaBar->debugStatus = debugStatus; + MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT; /* This register is selected to know + which initiator is actually asserted. */ + if ((MCD_dmaBar->ptdDebug >> channel) & 0x1) + MCD_chStatus[channel] = MCD_RUNNING; + else + MCD_chStatus[channel] = MCD_IDLE; } /********************* End of MCD_resmActions() *********************/ @@ -774,28 +774,28 @@ static void MCD_resmActions(int channel) */ int MCD_killDma(int channel) { - /* MCD_XferProg progRep; */ + /* MCD_XferProg progRep; */ - if ((channel < 0) || (channel >= NCHANNELS)) - return (MCD_CHANNEL_INVALID); + if ((channel < 0) || (channel >= NCHANNELS)) + return (MCD_CHANNEL_INVALID); - MCD_dmaBar->taskControl[channel] = 0x0; - MCD_resumeDma(channel); - /* - * This must be after the write to the TCR so that the task doesn't - * start up again momentarily, and before the status assignment so - * as to override whatever MCD_resumeDma() may do to the channel - * status. - */ - MCD_chStatus[channel] = MCD_HALTED; + MCD_dmaBar->taskControl[channel] = 0x0; + MCD_resumeDma(channel); + /* + * This must be after the write to the TCR so that the task doesn't + * start up again momentarily, and before the status assignment so + * as to override whatever MCD_resumeDma() may do to the channel + * status. + */ + MCD_chStatus[channel] = MCD_HALTED; - /* - * Update the current buffer descriptor's lastDestAddr field - * - * MCD_XferProgrQuery (channel, &progRep); - * progRep.currBufDesc->lastDestAddr = progRep.lastDestAddr; - */ - return (MCD_OK); + /* + * Update the current buffer descriptor's lastDestAddr field + * + * MCD_XferProgrQuery (channel, &progRep); + * progRep.currBufDesc->lastDestAddr = progRep.lastDestAddr; + */ + return (MCD_OK); } /************************ End of MCD_killDma() **********************/ @@ -812,13 +812,13 @@ int MCD_killDma(int channel) */ int MCD_continDma(int channel) { - if ((channel < 0) || (channel >= NCHANNELS)) - return (MCD_CHANNEL_INVALID); + if ((channel < 0) || (channel >= NCHANNELS)) + return (MCD_CHANNEL_INVALID); - MCD_dmaBar->taskControl[channel] |= TASK_CTL_EN; - MCD_chStatus[channel] = MCD_RUNNING; + MCD_dmaBar->taskControl[channel] |= TASK_CTL_EN; + MCD_chStatus[channel] = MCD_RUNNING; - return (MCD_OK); + return (MCD_OK); } /********************** End of MCD_continDma() **********************/ @@ -863,25 +863,25 @@ int MCD_continDma(int channel) */ int MCD_pauseDma(int channel) { - /* MCD_XferProg progRep; */ + /* MCD_XferProg progRep; */ - if ((channel < 0) || (channel >= NCHANNELS)) - return (MCD_CHANNEL_INVALID); + if ((channel < 0) || (channel >= NCHANNELS)) + return (MCD_CHANNEL_INVALID); - if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN) - { - MCD_dmaBar->debugComp1 = channel; - MCD_dmaBar->debugControl = DBG_CTL_ENABLE | (1 << (channel + 16)); - MCD_chStatus[channel] = MCD_PAUSED; + if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN) + { + MCD_dmaBar->debugComp1 = channel; + MCD_dmaBar->debugControl = DBG_CTL_ENABLE | (1 << (channel + 16)); + MCD_chStatus[channel] = MCD_PAUSED; - /* - * Update the current buffer descriptor's lastDestAddr field - * - * MCD_XferProgrQuery (channel, &progRep); - * progRep.currBufDesc->lastDestAddr = progRep.lastDestAddr; - */ - } - return (MCD_OK); + /* + * Update the current buffer descriptor's lastDestAddr field + * + * MCD_XferProgrQuery (channel, &progRep); + * progRep.currBufDesc->lastDestAddr = progRep.lastDestAddr; + */ + } + return (MCD_OK); } /************************* End of MCD_pauseDma() ********************/ @@ -894,13 +894,13 @@ int MCD_pauseDma(int channel) */ int MCD_resumeDma(int channel) { - if ((channel < 0) || (channel >= NCHANNELS)) - return (MCD_CHANNEL_INVALID); + if ((channel < 0) || (channel >= NCHANNELS)) + return (MCD_CHANNEL_INVALID); - if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN) - MCD_resmActions(channel); + if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN) + MCD_resmActions(channel); - return (MCD_OK); + return (MCD_OK); } /************************ End of MCD_resumeDma() ********************/ @@ -917,13 +917,13 @@ int MCD_resumeDma(int channel) int MCD_csumQuery(int channel, uint32_t *csum) { #ifdef MCD_INCLUDE_EU - if((channel < 0) || (channel >= NCHANNELS)) - return(MCD_CHANNEL_INVALID); + if((channel < 0) || (channel >= NCHANNELS)) + return(MCD_CHANNEL_INVALID); - *csum = MCD_relocBuffDesc[channel].csumResult; - return(MCD_OK); + *csum = MCD_relocBuffDesc[channel].csumResult; + return(MCD_OK); #else - return (MCD_ERROR); + return (MCD_ERROR); #endif } /*********************** End of MCD_resumeDma() *********************/ @@ -936,9 +936,9 @@ int MCD_csumQuery(int channel, uint32_t *csum) int MCD_getCodeSize(void) { #ifdef MCD_INCLUDE_EU - return(0x2b5c); + return(0x2b5c); #else - return (0x173c); + return (0x173c); #endif } /********************** End of MCD_getCodeSize() ********************/ @@ -956,8 +956,8 @@ char MCD_versionString[] = "Multi-channel DMA API Alpha v0.3 (2004-04-26)"; int MCD_getVersion(char **longVersion) { - *longVersion = MCD_versionString; - return ((MCD_REV_MAJOR << 8) | MCD_REV_MINOR); + *longVersion = MCD_versionString; + return ((MCD_REV_MAJOR << 8) | MCD_REV_MINOR); } /********************** End of MCD_getVersion() *********************/ @@ -967,9 +967,9 @@ int MCD_getVersion(char **longVersion) */ static void MCD_memcpy(int *dest, int *src, uint32_t size) { - uint32_t i; + uint32_t i; - for (i = 0; i < size; i += sizeof(int), dest++, src++) - *dest = *src; + for (i = 0; i < size; i += sizeof(int), dest++, src++) + *dest = *src; } /********************************************************************/ diff --git a/BaS_gcc/dma/dma.c b/BaS_gcc/dma/dma.c index c79660a..5ac034d 100644 --- a/BaS_gcc/dma/dma.c +++ b/BaS_gcc/dma/dma.c @@ -665,6 +665,7 @@ void *dma_memcpy(void *dst, void *src, size_t n) int dma_init(void) { + int i; int res; dbg("MCD DMA API initialization: "); @@ -675,6 +676,15 @@ int dma_init(void) return 0; } + /* + * make sure dma_channel array is properly initialized + */ + for (i = 0; i < NCHANNELS; i++) + { + dma_channel[i].req = -1; + dma_channel[i].handler = NULL; + } + // test dma_memcpy((void *) 0x10000, (void *) 0x03e00000, 0x00100000); /* copy one megabyte of flash to RAM */ diff --git a/BaS_gcc/include/MCD_dma.h b/BaS_gcc/include/MCD_dma.h index 02a1cc7..6993387 100755 --- a/BaS_gcc/include/MCD_dma.h +++ b/BaS_gcc/include/MCD_dma.h @@ -12,8 +12,9 @@ /* * Turn Execution Unit tasks ON (#define) or OFF (#undef) */ -#undef MCD_INCLUDE_EU + //#define MCD_INCLUDE_EU +#undef MCD_INCLUDE_EU /* * Number of DMA channels @@ -291,53 +292,53 @@ int MCD_startDma ( uint32_t funcDesc /* a description of byte swapping, bit swapping, and CRC actions */ ); -/* - * MCD_initDma() initializes the DMA API by setting up a pointer to the DMA - * registers, relocating and creating the appropriate task structures, and +/* + * MCD_initDma() initializes the DMA API by setting up a pointer to the DMA + * registers, relocating and creating the appropriate task structures, and * setting up some global settings */ int MCD_initDma (dmaRegs *sDmaBarAddr, void *taskTableDest, uint32_t flags); -/* +/* * MCD_dmaStatus() returns the status of the DMA on the requested channel. */ int MCD_dmaStatus (int channel); -/* +/* * MCD_XferProgrQuery() returns progress of DMA on requested channel */ int MCD_XferProgrQuery (int channel, MCD_XferProg *progRep); -/* +/* * MCD_killDma() halts the DMA on the requested channel, without any * intention of resuming the DMA. */ int MCD_killDma (int channel); -/* +/* * MCD_continDma() continues a DMA which as stopped due to encountering an * unready buffer descriptor. */ int MCD_continDma (int channel); -/* +/* * MCD_pauseDma() pauses the DMA on the given channel ( if any DMA is - * running on that channel). + * running on that channel). */ int MCD_pauseDma (int channel); -/* +/* * MCD_resumeDma() resumes the DMA on a given channel (if any DMA is * running on that channel). */ int MCD_resumeDma (int channel); -/* +/* * MCD_csumQuery provides the checksum/CRC after performing a non-chained DMA */ int MCD_csumQuery (int channel, uint32_t *csum); -/* +/* * MCD_getCodeSize provides the packed size required by the microcoded task * and structures. */ diff --git a/BaS_gcc/include/MCF5475_INTC.h b/BaS_gcc/include/MCF5475_INTC.h index 61265ed..50e8074 100644 --- a/BaS_gcc/include/MCF5475_INTC.h +++ b/BaS_gcc/include/MCF5475_INTC.h @@ -107,7 +107,6 @@ #define MCF_INTC_LIACK(x) (*(volatile uint8_t *)(&_MBAR[0x7E4 + ((x-1)*0x4)])) - /* Bit definitions and macros for MCF_INTC_IPRH */ #define MCF_INTC_IPRH_INT32 (0x1) #define MCF_INTC_IPRH_INT33 (0x2) diff --git a/BaS_gcc/include/dma.h b/BaS_gcc/include/dma.h index 7c3bbe7..ad8074f 100644 --- a/BaS_gcc/include/dma.h +++ b/BaS_gcc/include/dma.h @@ -26,10 +26,6 @@ #include "MCD_dma.h" #include "bas_string.h" -#define DMA_INTC_LVL 5 -#define DMA_INTC_PRI 3 - - void *dma_memcpy(void *dst, void *src, size_t n); extern int dma_init(void); extern int dma_get_channel(int requestor); diff --git a/BaS_gcc/include/driver_vec.h b/BaS_gcc/include/driver_vec.h index 681561f..bbce08d 100644 --- a/BaS_gcc/include/driver_vec.h +++ b/BaS_gcc/include/driver_vec.h @@ -31,56 +31,57 @@ enum driver_type { - BLOCKDEV_DRIVER, - CHARDEV_DRIVER, - XHDI_DRIVER, - MCD_DRIVER, - VIDEO_DRIVER, - PCI_DRIVER, - MMU_DRIVER, - END_OF_DRIVERS = 0xffffffff, /* marks end of driver list */ + BLOCKDEV_DRIVER, + CHARDEV_DRIVER, + XHDI_DRIVER, + MCD_DRIVER, + VIDEO_DRIVER, + PCI_DRIVER, + MMU_DRIVER, + END_OF_DRIVERS = 0xffffffff, /* marks end of driver list */ }; struct generic_driver_interface { - uint32_t (*init)(void); - uint32_t (*read)(void *buf, size_t count); - uint32_t (*write)(const void *buf, size_t count); - uint32_t (*ioctl)(uint32_t request, ...); + uint32_t (*init)(void); + uint32_t (*read)(void *buf, size_t count); + uint32_t (*write)(const void *buf, size_t count); + uint32_t (*ioctl)(uint32_t request, ...); }; struct dma_driver_interface { - int32_t version; - int32_t magic; - int (*dma_set_initiator)(int initiator); - uint32_t (*dma_get_initiator)(int requestor); - void (*dma_free_initiator)(int requestor); - int (*dma_set_channel)(int requestor, void (*handler)(void)); - int (*dma_get_channel)(int requestor); - void (*dma_free_channel)(int requestor); - void (*dma_clear_channel)(int channel); - int (*MCD_startDma)(long channel, - int8_t *srcAddr, unsigned int srcIncr, int8_t *destAddr, unsigned int destIncr, - unsigned int dmaSize, unsigned int xferSize, unsigned int initiator, int priority, - unsigned int flags, unsigned int funcDesc); - int32_t (*MCD_dmaStatus)(int32_t channel); - int32_t (*MCD_XferProgrQuery)(int32_t channel, MCD_XferProg *progRep); - int32_t (*MCD_killDma)(int32_t channel); - int32_t (*MCD_continDma)(int32_t channel); - int32_t (*MCD_pauseDma)(int32_t channel); - int32_t (*MCD_resumeDma)(int32_t channel); - int32_t (*MCD_csumQuery)(int32_t channel, uint32_t *csum); - void *(*dma_malloc)(uint32_t amount); - int32_t (*dma_free)(void *addr); + int32_t version; + int32_t magic; + int (*dma_set_initiator)(int initiator); + uint32_t (*dma_get_initiator)(int requestor); + void (*dma_free_initiator)(int requestor); + int (*dma_set_channel)(int requestor, void (*handler)(void)); + int (*dma_get_channel)(int requestor); + void (*dma_free_channel)(int requestor); + void (*dma_clear_channel)(int channel); + int (*MCD_startDma)(long channel, + int8_t *srcAddr, unsigned int srcIncr, int8_t *destAddr, unsigned int destIncr, + unsigned int dmaSize, unsigned int xferSize, unsigned int initiator, int priority, + unsigned int flags, unsigned int funcDesc); + int32_t (*MCD_dmaStatus)(int32_t channel); + int32_t (*MCD_XferProgrQuery)(int32_t channel, MCD_XferProg *progRep); + int32_t (*MCD_killDma)(int32_t channel); + int32_t (*MCD_continDma)(int32_t channel); + int32_t (*MCD_pauseDma)(int32_t channel); + int32_t (*MCD_resumeDma)(int32_t channel); + int32_t (*MCD_csumQuery)(int32_t channel, uint32_t *csum); + void *(*dma_malloc)(uint32_t amount); + int32_t (*dma_free)(void *addr); }; struct xhdi_driver_interface { - uint32_t (*xhdivec)(); + uint32_t (*xhdivec)(); }; -/* Interpretation of offset for color fields: All offsets are from the right, +/* + * Interpretation of offset for color fields: All offsets are from the right, * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you * can use the offset as right argument to <<). A pixel afterwards is a bit * stream and is written to video memory as that unmodified. This implies @@ -88,10 +89,10 @@ struct xhdi_driver_interface */ struct fb_bitfield { - unsigned long offset; /* beginning of bitfield */ - unsigned long length; /* length of bitfield */ - unsigned long msb_right; /* != 0 : Most significant bit is */ - /* right */ + unsigned long offset; /* beginning of bitfield */ + unsigned long length; /* length of bitfield */ + unsigned long msb_right; /* != 0 : Most significant bit is */ + /* right */ }; /* @@ -99,165 +100,166 @@ struct fb_bitfield */ struct fb_var_screeninfo { - unsigned long xres; /* visible resolution */ - unsigned long yres; - unsigned long xres_virtual; /* virtual resolution */ - unsigned long yres_virtual; - unsigned long xoffset; /* offset from virtual to visible */ - unsigned long yoffset; /* resolution */ + unsigned long xres; /* visible resolution */ + unsigned long yres; + unsigned long xres_virtual; /* virtual resolution */ + unsigned long yres_virtual; + unsigned long xoffset; /* offset from virtual to visible */ + unsigned long yoffset; /* resolution */ - unsigned long bits_per_pixel; /* guess what */ - unsigned long grayscale; /* != 0 Graylevels instead of colors */ + unsigned long bits_per_pixel; /* guess what */ + unsigned long grayscale; /* != 0 Graylevels instead of colors */ - struct fb_bitfield red; /* bitfield in fb mem if true color, */ - struct fb_bitfield green; /* else only length is significant */ - struct fb_bitfield blue; - struct fb_bitfield transp; /* transparency */ + struct fb_bitfield red; /* bitfield in fb mem if true color, */ + struct fb_bitfield green; /* else only length is significant */ + struct fb_bitfield blue; + struct fb_bitfield transp; /* transparency */ - unsigned long nonstd; /* != 0 Non standard pixel format */ + unsigned long nonstd; /* != 0 Non standard pixel format */ - unsigned long activate; /* see FB_ACTIVATE_* */ + unsigned long activate; /* see FB_ACTIVATE_* */ - unsigned long height; /* height of picture in mm */ - unsigned long width; /* width of picture in mm */ + unsigned long height; /* height of picture in mm */ + unsigned long width; /* width of picture in mm */ - unsigned long accel_flags; /* (OBSOLETE) see fb_info.flags */ + unsigned long accel_flags; /* (OBSOLETE) see fb_info.flags */ - /* Timing: All values in pixclocks, except pixclock (of course) */ - unsigned long pixclock; /* pixel clock in ps (pico seconds) */ - unsigned long left_margin; /* time from sync to picture */ - unsigned long right_margin; /* time from picture to sync */ - unsigned long upper_margin; /* time from sync to picture */ - unsigned long lower_margin; - unsigned long hsync_len; /* length of horizontal sync */ - unsigned long vsync_len; /* length of vertical sync */ - unsigned long sync; /* see FB_SYNC_* */ - unsigned long vmode; /* see FB_VMODE_* */ - unsigned long rotate; /* angle we rotate counter clockwise */ - unsigned long refresh; - unsigned long reserved[4]; /* Reserved for future compatibility */ + /* Timing: All values in pixclocks, except pixclock (of course) */ + unsigned long pixclock; /* pixel clock in ps (pico seconds) */ + unsigned long left_margin; /* time from sync to picture */ + unsigned long right_margin; /* time from picture to sync */ + unsigned long upper_margin; /* time from sync to picture */ + unsigned long lower_margin; + unsigned long hsync_len; /* length of horizontal sync */ + unsigned long vsync_len; /* length of vertical sync */ + unsigned long sync; /* see FB_SYNC_* */ + unsigned long vmode; /* see FB_VMODE_* */ + unsigned long rotate; /* angle we rotate counter clockwise */ + unsigned long refresh; + unsigned long reserved[4]; /* Reserved for future compatibility */ }; struct fb_fix_screeninfo { - char id[16]; /* identification string eg "TT Builtin" */ - unsigned long smem_start; /* Start of frame buffer mem */ - /* (physical address) */ - unsigned long smem_len; /* Length of frame buffer mem */ - unsigned long type; /* see FB_TYPE_* */ - unsigned long type_aux; /* Interleave for interleaved Planes */ - unsigned long visual; /* see FB_VISUAL_* */ - unsigned short xpanstep; /* zero if no hardware panning */ - unsigned short ypanstep; /* zero if no hardware panning */ - unsigned short ywrapstep; /* zero if no hardware ywrap */ - unsigned long line_length; /* length of a line in bytes */ - unsigned long mmio_start; /* Start of Memory Mapped I/O */ - /* (physical address) */ - unsigned long mmio_len; /* Length of Memory Mapped I/O */ - unsigned long accel; /* Indicate to driver which */ - /* specific chip/card we have */ - unsigned short reserved[3]; /* Reserved for future compatibility */ + char id[16]; /* identification string eg "TT Builtin" */ + unsigned long smem_start; /* Start of frame buffer mem */ + /* (physical address) */ + unsigned long smem_len; /* Length of frame buffer mem */ + unsigned long type; /* see FB_TYPE_* */ + unsigned long type_aux; /* Interleave for interleaved Planes */ + unsigned long visual; /* see FB_VISUAL_* */ + unsigned short xpanstep; /* zero if no hardware panning */ + unsigned short ypanstep; /* zero if no hardware panning */ + unsigned short ywrapstep; /* zero if no hardware ywrap */ + unsigned long line_length; /* length of a line in bytes */ + unsigned long mmio_start; /* Start of Memory Mapped I/O */ + /* (physical address) */ + unsigned long mmio_len; /* Length of Memory Mapped I/O */ + unsigned long accel; /* Indicate to driver which */ + /* specific chip/card we have */ + unsigned short reserved[3]; /* Reserved for future compatibility */ }; struct fb_chroma { - unsigned long redx; /* in fraction of 1024 */ - unsigned long greenx; - unsigned long bluex; - unsigned long whitex; - unsigned long redy; - unsigned long greeny; - unsigned long bluey; - unsigned long whitey; + unsigned long redx; /* in fraction of 1024 */ + unsigned long greenx; + unsigned long bluex; + unsigned long whitex; + unsigned long redy; + unsigned long greeny; + unsigned long bluey; + unsigned long whitey; }; struct fb_monspecs { - struct fb_chroma chroma; - struct fb_videomode *modedb; /* mode database */ - unsigned char manufacturer[4]; /* Manufacturer */ - unsigned char monitor[14]; /* Monitor String */ - unsigned char serial_no[14]; /* Serial Number */ - unsigned char ascii[14]; /* ? */ - unsigned long modedb_len; /* mode database length */ - unsigned long model; /* Monitor Model */ - unsigned long serial; /* Serial Number - Integer */ - unsigned long year; /* Year manufactured */ - unsigned long week; /* Week Manufactured */ - unsigned long hfmin; /* hfreq lower limit (Hz) */ - unsigned long hfmax; /* hfreq upper limit (Hz) */ - unsigned long dclkmin; /* pixelclock lower limit (Hz) */ - unsigned long dclkmax; /* pixelclock upper limit (Hz) */ - unsigned short input; /* display type - see FB_DISP_* */ - unsigned short dpms; /* DPMS support - see FB_DPMS_ */ - unsigned short signal; /* Signal Type - see FB_SIGNAL_* */ - unsigned short vfmin; /* vfreq lower limit (Hz) */ - unsigned short vfmax; /* vfreq upper limit (Hz) */ - unsigned short gamma; /* Gamma - in fractions of 100 */ - unsigned short gtf : 1; /* supports GTF */ - unsigned short misc; /* Misc flags - see FB_MISC_* */ - unsigned char version; /* EDID version... */ - unsigned char revision; /* ...and revision */ - unsigned char max_x; /* Maximum horizontal size (cm) */ - unsigned char max_y; /* Maximum vertical size (cm) */ + struct fb_chroma chroma; + struct fb_videomode *modedb; /* mode database */ + unsigned char manufacturer[4]; /* Manufacturer */ + unsigned char monitor[14]; /* Monitor String */ + unsigned char serial_no[14]; /* Serial Number */ + unsigned char ascii[14]; /* ? */ + unsigned long modedb_len; /* mode database length */ + unsigned long model; /* Monitor Model */ + unsigned long serial; /* Serial Number - Integer */ + unsigned long year; /* Year manufactured */ + unsigned long week; /* Week Manufactured */ + unsigned long hfmin; /* hfreq lower limit (Hz) */ + unsigned long hfmax; /* hfreq upper limit (Hz) */ + unsigned long dclkmin; /* pixelclock lower limit (Hz) */ + unsigned long dclkmax; /* pixelclock upper limit (Hz) */ + unsigned short input; /* display type - see FB_DISP_* */ + unsigned short dpms; /* DPMS support - see FB_DPMS_ */ + unsigned short signal; /* Signal Type - see FB_SIGNAL_* */ + unsigned short vfmin; /* vfreq lower limit (Hz) */ + unsigned short vfmax; /* vfreq upper limit (Hz) */ + unsigned short gamma; /* Gamma - in fractions of 100 */ + unsigned short gtf : 1; /* supports GTF */ + unsigned short misc; /* Misc flags - see FB_MISC_* */ + unsigned char version; /* EDID version... */ + unsigned char revision; /* ...and revision */ + unsigned char max_x; /* Maximum horizontal size (cm) */ + unsigned char max_y; /* Maximum vertical size (cm) */ }; struct framebuffer_driver_interface { - struct fb_info **framebuffer_info; /* pointer to an fb_info struct (defined in include/fb.h) */ + struct fb_info **framebuffer_info; /* pointer to an fb_info struct (defined in include/fb.h) */ }; -struct pci_bios_interface { - uint32_t subjar; - uint32_t version; - /* Although we declare this functions as standard gcc functions (cdecl), - * they expect paramenters inside registers (fastcall) unsupported by gcc m68k. - * Caller will take care of parameters passing convention. - */ - int32_t (*find_pci_device) (uint32_t id, uint16_t index); - int32_t (*find_pci_classcode) (uint32_t class, uint16_t index); - int32_t (*read_config_byte) (int32_t handle, uint16_t reg, uint8_t *address); - int32_t (*read_config_word) (int32_t handle, uint16_t reg, uint16_t *address); - int32_t (*read_config_longword) (int32_t handle, uint16_t reg, uint32_t *address); - uint8_t (*fast_read_config_byte) (int32_t handle, uint16_t reg); - uint16_t (*fast_read_config_word) (int32_t handle, uint16_t reg); - uint32_t (*fast_read_config_longword) (int32_t handle, uint16_t reg); - int32_t (*write_config_byte) (int32_t handle, uint16_t reg, uint16_t val); - int32_t (*write_config_word) (int32_t handle, uint16_t reg, uint16_t val); - int32_t (*write_config_longword) (int32_t handle, uint16_t reg, uint32_t val); - int32_t (*hook_interrupt) (int32_t handle, uint32_t *routine, uint32_t *parameter); - int32_t (*unhook_interrupt) (int32_t handle); - int32_t (*special_cycle) (uint16_t bus, uint32_t data); - int32_t (*get_routing) (int32_t handle); - int32_t (*set_interrupt) (int32_t handle); - int32_t (*get_resource) (int32_t handle); - int32_t (*get_card_used) (int32_t handle, uint32_t *address); - int32_t (*set_card_used) (int32_t handle, uint32_t *callback); - int32_t (*read_mem_byte) (int32_t handle, uint32_t offset, uint8_t *address); - int32_t (*read_mem_word) (int32_t handle, uint32_t offset, uint16_t *address); - int32_t (*read_mem_longword) (int32_t handle, uint32_t offset, uint32_t *address); - uint8_t (*fast_read_mem_byte) (int32_t handle, uint32_t offset); - uint16_t (*fast_read_mem_word) (int32_t handle, uint32_t offset); - uint32_t (*fast_read_mem_longword) (int32_t handle, uint32_t offset); - int32_t (*write_mem_byte) (int32_t handle, uint32_t offset, uint16_t val); - int32_t (*write_mem_word) (int32_t handle, uint32_t offset, uint16_t val); - int32_t (*write_mem_longword) (int32_t handle, uint32_t offset, uint32_t val); - int32_t (*read_io_byte) (int32_t handle, uint32_t offset, uint8_t *address); - int32_t (*read_io_word) (int32_t handle, uint32_t offset, uint16_t *address); - int32_t (*read_io_longword) (int32_t handle, uint32_t offset, uint32_t *address); - uint8_t (*fast_read_io_byte) (int32_t handle, uint32_t offset); - uint16_t (*fast_read_io_word) (int32_t handle, uint32_t offset); - uint32_t (*fast_read_io_longword) (int32_t handle, uint32_t offset); - int32_t (*write_io_byte) (int32_t handle, uint32_t offset, uint16_t val); - int32_t (*write_io_word) (int32_t handle, uint32_t offset, uint16_t val); - int32_t (*write_io_longword) (int32_t handle, uint32_t offset, uint32_t val); - int32_t (*get_machine_id) (void); - int32_t (*get_pagesize) (void); - int32_t (*virt_to_bus) (int32_t handle, uint32_t address, PCI_CONV_ADR *pointer); - int32_t (*bus_to_virt) (int32_t handle, uint32_t address, PCI_CONV_ADR *pointer); - int32_t (*virt_to_phys) (uint32_t address, PCI_CONV_ADR *pointer); - int32_t (*phys_to_virt) (uint32_t address, PCI_CONV_ADR *pointer); -// int32_t reserved[2]; +struct pci_bios_interface +{ + uint32_t subjar; + uint32_t version; + /* Although we declare this functions as standard gcc functions (cdecl), + * they expect parameters inside registers (fastcall) unsupported by gcc m68k. + * Caller will take care of parameters passing convention. + */ + int32_t (*find_pci_device)(uint32_t id, uint16_t index); + int32_t (*find_pci_classcode)(uint32_t class, uint16_t index); + int32_t (*read_config_byte)(int32_t handle, uint16_t reg, uint8_t *address); + int32_t (*read_config_word)(int32_t handle, uint16_t reg, uint16_t *address); + int32_t (*read_config_longword)(int32_t handle, uint16_t reg, uint32_t *address); + uint8_t (*fast_read_config_byte)(int32_t handle, uint16_t reg); + uint16_t (*fast_read_config_word)(int32_t handle, uint16_t reg); + uint32_t (*fast_read_config_longword)(int32_t handle, uint16_t reg); + int32_t (*write_config_byte)(int32_t handle, uint16_t reg, uint16_t val); + int32_t (*write_config_word)(int32_t handle, uint16_t reg, uint16_t val); + int32_t (*write_config_longword)(int32_t handle, uint16_t reg, uint32_t val); + int32_t (*hook_interrupt)(int32_t handle, uint32_t *routine, uint32_t *parameter); + int32_t (*unhook_interrupt)(int32_t handle); + int32_t (*special_cycle)(uint16_t bus, uint32_t data); + int32_t (*get_routing)(int32_t handle); + int32_t (*set_interrupt)(int32_t handle); + int32_t (*get_resource)(int32_t handle); + int32_t (*get_card_used)(int32_t handle, uint32_t *address); + int32_t (*set_card_used)(int32_t handle, uint32_t *callback); + int32_t (*read_mem_byte)(int32_t handle, uint32_t offset, uint8_t *address); + int32_t (*read_mem_word)(int32_t handle, uint32_t offset, uint16_t *address); + int32_t (*read_mem_longword)(int32_t handle, uint32_t offset, uint32_t *address); + uint8_t (*fast_read_mem_byte)(int32_t handle, uint32_t offset); + uint16_t (*fast_read_mem_word)(int32_t handle, uint32_t offset); + uint32_t (*fast_read_mem_longword)(int32_t handle, uint32_t offset); + int32_t (*write_mem_byte)(int32_t handle, uint32_t offset, uint16_t val); + int32_t (*write_mem_word)(int32_t handle, uint32_t offset, uint16_t val); + int32_t (*write_mem_longword)(int32_t handle, uint32_t offset, uint32_t val); + int32_t (*read_io_byte)(int32_t handle, uint32_t offset, uint8_t *address); + int32_t (*read_io_word)(int32_t handle, uint32_t offset, uint16_t *address); + int32_t (*read_io_longword)(int32_t handle, uint32_t offset, uint32_t *address); + uint8_t (*fast_read_io_byte)(int32_t handle, uint32_t offset); + uint16_t (*fast_read_io_word)(int32_t handle, uint32_t offset); + uint32_t (*fast_read_io_longword)(int32_t handle, uint32_t offset); + int32_t (*write_io_byte)(int32_t handle, uint32_t offset, uint16_t val); + int32_t (*write_io_word)(int32_t handle, uint32_t offset, uint16_t val); + int32_t (*write_io_longword)(int32_t handle, uint32_t offset, uint32_t val); + int32_t (*get_machine_id)(void); + int32_t (*get_pagesize)(void); + int32_t (*virt_to_bus)(int32_t handle, uint32_t address, PCI_CONV_ADR *pointer); + int32_t (*bus_to_virt)(int32_t handle, uint32_t address, PCI_CONV_ADR *pointer); + int32_t (*virt_to_phys)(uint32_t address, PCI_CONV_ADR *pointer); + int32_t (*phys_to_virt)(uint32_t address, PCI_CONV_ADR *pointer); + // int32_t reserved[2]; }; struct mmu_driver_interface @@ -270,30 +272,30 @@ struct mmu_driver_interface union interface { - struct generic_driver_interface *gdi; - struct xhdi_driver_interface *xhdi; - struct dma_driver_interface *dma; - struct framebuffer_driver_interface *fb; - struct pci_bios_interface *pci; - struct mmu_driver_interface *mmu; + struct generic_driver_interface *gdi; + struct xhdi_driver_interface *xhdi; + struct dma_driver_interface *dma; + struct framebuffer_driver_interface *fb; + struct pci_bios_interface *pci; + struct mmu_driver_interface *mmu; }; struct generic_interface { - enum driver_type type; - char name[16]; - char description[64]; - int version; - int revision; - union interface interface; + enum driver_type type; + char name[16]; + char description[64]; + int version; + int revision; + union interface interface; }; struct driver_table { - uint32_t bas_version; - uint32_t bas_revision; - void (*remove_handler)(void); /* calling this will disable the BaS' hook into trap #0 */ - struct generic_interface *interfaces; + uint32_t bas_version; + uint32_t bas_revision; + void (*remove_handler)(void); /* calling this will disable the BaS' hook into trap #0 */ + struct generic_interface *interfaces; }; diff --git a/BaS_gcc/include/interrupts.h b/BaS_gcc/include/interrupts.h index ed9e67a..1b5be71 100644 --- a/BaS_gcc/include/interrupts.h +++ b/BaS_gcc/include/interrupts.h @@ -145,7 +145,9 @@ #endif /* MACHINE_FIREBEE */ extern void isr_init(void); -extern int isr_register_handler(int vector, int (*handler)(void *, void *), void *hdev, void *harg); +extern bool isr_set_prio_and_level(int int_source, int priority, int level); +extern bool isr_enable_int_source(int int_source); +extern bool isr_register_handler(int vector, int level, int priority, int (*handler)(void *, void *), void *hdev, void *harg); extern void isr_remove_handler(int (*handler)(void *, void *)); extern bool isr_execute_handler(int vector); extern int pic_interrupt_handler(void *arg1, void *arg2); diff --git a/BaS_gcc/net/net_timer.c b/BaS_gcc/net/net_timer.c index 78fdcc8..d9ebdf1 100644 --- a/BaS_gcc/net/net_timer.c +++ b/BaS_gcc/net/net_timer.c @@ -158,7 +158,7 @@ bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri) /* * Register the timer interrupt handler */ - if (!isr_register_handler(TIMER_VECTOR(ch), + if (!isr_register_handler(TIMER_VECTOR(ch), 3, 0, (int (*)(void *,void *)) timer_default_isr, NULL, (void *) &net_timer[ch]) diff --git a/BaS_gcc/sys/BaS.c b/BaS_gcc/sys/BaS.c index 9143f82..5046edb 100644 --- a/BaS_gcc/sys/BaS.c +++ b/BaS_gcc/sys/BaS.c @@ -186,28 +186,28 @@ void nvram_init(void) xprintf("finished\r\n"); } -#define KBD_ACIA_CONTROL ((uint8_t *) 0xfffffc00) -#define MIDI_ACIA_CONTROL ((uint8_t *) 0xfffffc04) -#define MFP_INTR_IN_SERVICE_A ((uint8_t *) 0xfffffa0f) -#define MFP_INTR_IN_SERVICE_B ((uint8_t *) 0xfffffa11) +#define KBD_ACIA_CONTROL * ((uint8_t *) 0xfffffc00) +#define MIDI_ACIA_CONTROL * ((uint8_t *) 0xfffffc04) +#define MFP_INTR_IN_SERVICE_A * ((uint8_t *) 0xfffffa0f) +#define MFP_INTR_IN_SERVICE_B * ((uint8_t *) 0xfffffa11) void acia_init() { xprintf("init ACIA: "); /* init ACIA */ - * KBD_ACIA_CONTROL = 3; /* master reset */ + KBD_ACIA_CONTROL = 3; /* master reset */ NOP(); - * MIDI_ACIA_CONTROL = 3; /* master reset */ + MIDI_ACIA_CONTROL = 3; /* master reset */ NOP(); - * KBD_ACIA_CONTROL = 0x96; /* clock div = 64, 8N1, RTS low, TX int disable, RX int enable */ + KBD_ACIA_CONTROL = 0x96; /* clock div = 64, 8N1, RTS low, TX int disable, RX int enable */ NOP(); - * MFP_INTR_IN_SERVICE_A = -1; + MFP_INTR_IN_SERVICE_A = 0xff; NOP(); - * MFP_INTR_IN_SERVICE_B = -1; + MFP_INTR_IN_SERVICE_B = 0xff; NOP(); xprintf("finished\r\n"); @@ -280,7 +280,7 @@ void init_isr(void) /* * register the FEC interrupt handler */ - if (!isr_register_handler(64 + INT_SOURCE_FEC0, fec0_interrupt_handler, NULL, (void *) &nif1)) + if (!isr_register_handler(64 + INT_SOURCE_FEC0, 7, 6, fec0_interrupt_handler, NULL, (void *) &nif1)) { err("unable to register isr for FEC0\r\n"); } @@ -289,13 +289,11 @@ void init_isr(void) * Register the DMA interrupt handler */ - if (!isr_register_handler(64 + INT_SOURCE_DMA, dma_interrupt_handler, NULL, NULL)) + if (!isr_register_handler(64 + INT_SOURCE_DMA, 7, 7, dma_interrupt_handler, NULL, NULL)) { err("Error: Unable to register isr for DMA\r\n"); } - dma_irq_enable(7, 7); /* TODO: need to match the FEC driver's specs in MiNT? */ - #ifdef _NOT_USED_ /* * register the PIC interrupt handler @@ -356,6 +354,8 @@ void BaS(void) xprintf("copy EmuTOS: "); + dma_init(); + /* copy EMUTOS */ src = (uint8_t *) EMUTOS; dma_memcpy(dst, src, EMUTOS_SIZE); @@ -441,7 +441,7 @@ void BaS(void) xprintf("BaS initialization finished, enable interrupts\r\n"); init_isr(); enable_coldfire_interrupts(); - //init_pci(); + init_pci(); // video_init(); /* initialize USB devices */ diff --git a/BaS_gcc/sys/exceptions.S b/BaS_gcc/sys/exceptions.S index 1090077..ac7c517 100644 --- a/BaS_gcc/sys/exceptions.S +++ b/BaS_gcc/sys/exceptions.S @@ -238,7 +238,7 @@ init_vec_loop: move.l a1,(INT_SOURCE_XLBPCI + 64) * 4(a0) #ifndef MACHINE_FIREBEE -// FEC1 not wired on the FireBee (used for FPGA as GPIO), but used on other machines +// FEC1 not wired on the FireBee (used for FPGA as GPIO), but available on other machines move.l a1,(INT_SOURCE_FEC1 + 64) * 4(a0) #endif @@ -430,15 +430,18 @@ irq5_forward: move.l 0x74,a0 // fetch OS irq5 vector move.w #0x2500,sr // set interrupt level rts // jump through vector - +/* + * irq6 needs special treatment since - because the Coldfire only supports autovector interrupts + * - the exception vector is provided by the simulated MFP from the FPGA + */ irq6: move.w #0x2700,sr // disable interrupt subq.l #4,sp // extra space link a6,#-4 * 4 // save gcc scratch registers movem.l d0-d1/a0-a1,(sp) - move.l 4(a6),-(sp) // format status word - move.l 8(a6),-(sp) // pc at exception + move.l 8(a6),-(sp) // format status word + move.l 12(a6),-(sp) // pc at exception jsr _irq6_handler // call C handler lea 8(sp),sp // fix stack @@ -563,25 +566,53 @@ irq7text: /* * low-level interrupt service routine for routines registered with - * isr_register_handler() + * isr_register_handler(int vector). If the higlevel routine (isr_execute_handler()) + * returns != 0, the call is forwarded to the OS (through its own vector base). */ .global _lowlevel_isr_handler .extern _isr_execute_handler +/* + * stack format (after link instruction) is like this: + * + * +12 program counter (return address) + * +8 format_status + * +4 save area for rts (if we need to jump through the OS vector) + * (a6) -> saved a6 (from link) + * -4 + * -8 + * -12 + * (sp) -> gcc scratch registers save area + */ _lowlevel_isr_handler: - move.w #0x2700,sr // do not disturb + subq.l #4,sp // extra space link a6,#-4 * 4 // make room for movem.l d0-d1/a0-a1,(sp) // gcc scratch registers and save them, - // other registers will be handled by gcc itself + // other registers will be taken care of by gcc itself - move.w 4(a6),d0 // fetch vector number from stack + move.w 8(a6),d0 // fetch vector number from stack lsr.l #2,d0 // move it in place andi.l #0xff,d0 // mask it out move.l d0,-(sp) // push it jsr _isr_execute_handler // call the C handler addq.l #4,sp // adjust stack + tst.l d0 // handled? + bne lowlevel_forward // no, we forward it to TOS movem.l (sp),d0-d1/a0-a1 // restore registers unlk a6 + addq.l #4,sp // eliminate extra space + rte + +lowlevel_forward: + move.l 8(a6),d0 // fetch OS irq vector + lsr.l #2,d0 // move it in place + andi.l #0xff,d0 // mask out vector number + add.l _rt_vbr,d0 // add runtime vbr + move.l d0,4(a6) // put on stack as return address + + movem.l (sp),d0-d1/a0-a1 // restore registers + unlk a6 // + rts // jump through vector diff --git a/BaS_gcc/sys/interrupts.c b/BaS_gcc/sys/interrupts.c index 0a4e350..21c125b 100644 --- a/BaS_gcc/sys/interrupts.c +++ b/BaS_gcc/sys/interrupts.c @@ -37,9 +37,6 @@ #include "dma.h" #include "pci.h" -extern void (*rt_vbr[])(void); -#define VBR rt_vbr - #define IRQ_DEBUG #if defined(IRQ_DEBUG) #define dbg(format, arg...) do { xprintf("DEBUG %s(): " format, __FUNCTION__, ##arg); } while (0) @@ -72,6 +69,51 @@ void isr_init(void) memset(isrtab, 0, sizeof(isrtab)); } +bool isr_set_prio_and_level(int int_source, int priority, int level) +{ + if (int_source > 8 && int_source <= 62) + { + /* + * preset interrupt control registers with level and priority + */ + MCF_INTC_ICR(int_source) = MCF_INTC_ICR_IP(priority) | + MCF_INTC_ICR_IL(level); + } + else if (int_source >= 1 && int_source <= 8) + { + dbg("interrrupt control register for vector %d is read only!\r\n"); + } + else + { + err("invalid vector - interrupt control register not set.\r\n"); + return false; + } + + return true; +} + +/* + * enable internal int source in DMA controller + */ +bool isr_enable_int_source(int int_source) +{ + if (int_source < 32 && int_source > 0) + { + MCF_INTC_IMRL &= ~(1 << int_source); + } + else if (int_source >= 32 && int_source <= 62) + { + MCF_INTC_IMRH &= ~(1 << (int_source - 32)); + } + else + { + err("vector %d does not correspond to an internal interrupt source\r\n"); + return false; + } + + return true; +} + /* * This function places an interrupt handler in the ISR table, * thereby registering it so that the low-level handler may call it. @@ -80,9 +122,10 @@ void isr_init(void) * pointer to the device itself, and the second a pointer to a data * structure used by the device driver for that particular device. */ -int isr_register_handler(int vector, int (*handler)(void *, void *), void *hdev, void *harg) +bool isr_register_handler(int vector, int level, int priority, int (*handler)(void *, void *), void *hdev, void *harg) { int index; + int int_source; if ((vector == 0) || (handler == NULL)) { @@ -108,12 +151,26 @@ int isr_register_handler(int vector, int (*handler)(void *, void *), void *hdev, isrtab[index].hdev = hdev; isrtab[index].harg = harg; + int_source = vector - 64; + + if (!isr_enable_int_source(int_source)) + { + err("failed to enable internal interrupt souce %d in IMRL/IMRH\r\n", int_source); + return false; + } + + if (!isr_set_prio_and_level(int_source, priority, level)) + { + err("failed to set priority and level for interrupt source %d\r\n", int_source); + return false; + } + return true; } - } - dbg("no available slots to register handler for vector %d\n\r", vector); + } + dbg("no available slots to register handler for vector %d\n\r", vector); - return false; /* no available slots */ + return false; /* no available slots */ } void isr_remove_handler(int (*handler)(void *, void *)) @@ -145,24 +202,19 @@ bool isr_execute_handler(int vector) int index; bool retval = false; - dbg("vector = 0x%x\r\n", vector); + dbg("vector = %d\r\n", vector); /* - * locate an Interrupt Service Routine handler. + * locate an interrupt service routine handler. */ for (index = 0; index < MAX_ISR_ENTRY; index++) { if (isrtab[index].vector == vector) { - retval = true; - - if (isrtab[index].handler(isrtab[index].hdev, isrtab[index].harg)) - { - return retval; - } + return isrtab[index].handler(isrtab[index].hdev, isrtab[index].harg); } } - dbg("no isr handler for vector %d found\r\n", vector); + err("no isr handler for vector %d found. Spurious?\r\n", vector); return retval; } diff --git a/BaS_gcc/sys/sysinit.c b/BaS_gcc/sys/sysinit.c index afec9dd..57a192d 100644 --- a/BaS_gcc/sys/sysinit.c +++ b/BaS_gcc/sys/sysinit.c @@ -1117,7 +1117,6 @@ void initialize_hardware(void) #if MACHINE_FIREBEE init_ac97(); #endif /* MACHINE_FIREBEE */ - dma_init(); /* jump into the BaS */ extern void BaS(void);