PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Committer:
spinal
Date:
Sun Nov 18 15:47:54 2018 +0000
Revision:
64:6e6c6c2b664e
Parent:
30:796f9611d2ac
added fix for directrectangle()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 30:796f9611d2ac 1 /*
Pokitto 30:796f9611d2ac 2 * @brief LPC11u6x DMA chip driver
Pokitto 30:796f9611d2ac 3 *
Pokitto 30:796f9611d2ac 4 * @note
Pokitto 30:796f9611d2ac 5 * Copyright(C) NXP Semiconductors, 2013
Pokitto 30:796f9611d2ac 6 * All rights reserved.
Pokitto 30:796f9611d2ac 7 *
Pokitto 30:796f9611d2ac 8 * @par
Pokitto 30:796f9611d2ac 9 * Software that is described herein is for illustrative purposes only
Pokitto 30:796f9611d2ac 10 * which provides customers with programming information regarding the
Pokitto 30:796f9611d2ac 11 * LPC products. This software is supplied "AS IS" without any warranties of
Pokitto 30:796f9611d2ac 12 * any kind, and NXP Semiconductors and its licensor disclaim any and
Pokitto 30:796f9611d2ac 13 * all warranties, express or implied, including all implied warranties of
Pokitto 30:796f9611d2ac 14 * merchantability, fitness for a particular purpose and non-infringement of
Pokitto 30:796f9611d2ac 15 * intellectual property rights. NXP Semiconductors assumes no responsibility
Pokitto 30:796f9611d2ac 16 * or liability for the use of the software, conveys no license or rights under any
Pokitto 30:796f9611d2ac 17 * patent, copyright, mask work right, or any other intellectual property rights in
Pokitto 30:796f9611d2ac 18 * or to any products. NXP Semiconductors reserves the right to make changes
Pokitto 30:796f9611d2ac 19 * in the software without notification. NXP Semiconductors also makes no
Pokitto 30:796f9611d2ac 20 * representation or warranty that such application will be suitable for the
Pokitto 30:796f9611d2ac 21 * specified use without further testing or modification.
Pokitto 30:796f9611d2ac 22 *
Pokitto 30:796f9611d2ac 23 * @par
Pokitto 30:796f9611d2ac 24 * Permission to use, copy, modify, and distribute this software and its
Pokitto 30:796f9611d2ac 25 * documentation is hereby granted, under NXP Semiconductors' and its
Pokitto 30:796f9611d2ac 26 * licensor's relevant copyrights in the software, without fee, provided that it
Pokitto 30:796f9611d2ac 27 * is used in conjunction with NXP Semiconductors microcontrollers. This
Pokitto 30:796f9611d2ac 28 * copyright, permission, and disclaimer notice must appear in all copies of
Pokitto 30:796f9611d2ac 29 * this code.
Pokitto 30:796f9611d2ac 30 */
Pokitto 30:796f9611d2ac 31
Pokitto 30:796f9611d2ac 32 //#include "lpc_defs.h"
Pokitto 30:796f9611d2ac 33 #include "dma_11u6x.h"
Pokitto 30:796f9611d2ac 34
Pokitto 30:796f9611d2ac 35 #define false 0
Pokitto 30:796f9611d2ac 36 #define true 1
Pokitto 30:796f9611d2ac 37
Pokitto 30:796f9611d2ac 38 /*****************************************************************************
Pokitto 30:796f9611d2ac 39 * Private types/enumerations/variables
Pokitto 30:796f9611d2ac 40 ****************************************************************************/
Pokitto 30:796f9611d2ac 41
Pokitto 30:796f9611d2ac 42 /*****************************************************************************
Pokitto 30:796f9611d2ac 43 * Public types/enumerations/variables
Pokitto 30:796f9611d2ac 44 ****************************************************************************/
Pokitto 30:796f9611d2ac 45
Pokitto 30:796f9611d2ac 46 #ifdef __cplusplus
Pokitto 30:796f9611d2ac 47 extern "C" {
Pokitto 30:796f9611d2ac 48 #endif
Pokitto 30:796f9611d2ac 49
Pokitto 30:796f9611d2ac 50 /* DMA SRAM table - this can be optionally used with the Chip_DMA_SetSRAMBase()
Pokitto 30:796f9611d2ac 51 function if a DMA SRAM table is needed. This table is correctly aligned for
Pokitto 30:796f9611d2ac 52 the DMA controller. */
Pokitto 30:796f9611d2ac 53 #if defined(__CC_ARM)
Pokitto 30:796f9611d2ac 54 /* Keil alignement to 256 bytes */
Pokitto 30:796f9611d2ac 55 __align(256) DMA_CHDESC_T Chip_DMA_Table[MAX_DMA_CHANNEL];
Pokitto 30:796f9611d2ac 56 #endif /* defined (__CC_ARM) */
Pokitto 30:796f9611d2ac 57
Pokitto 30:796f9611d2ac 58 /* IAR support */
Pokitto 30:796f9611d2ac 59 #if defined(__ICCARM__)
Pokitto 30:796f9611d2ac 60 /* IAR EWARM alignement to 256 bytes */
Pokitto 30:796f9611d2ac 61 #pragma data_alignment=256
Pokitto 30:796f9611d2ac 62 DMA_CHDESC_T Chip_DMA_Table[MAX_DMA_CHANNEL];
Pokitto 30:796f9611d2ac 63 #endif /* defined (__ICCARM__) */
Pokitto 30:796f9611d2ac 64
Pokitto 30:796f9611d2ac 65 #if defined( __GNUC__ )
Pokitto 30:796f9611d2ac 66 /* GNU alignement to 256 bytes */
Pokitto 30:796f9611d2ac 67 DMA_CHDESC_T Chip_DMA_Table[MAX_DMA_CHANNEL] __attribute__ ((aligned(256)));
Pokitto 30:796f9611d2ac 68 #endif /* defined (__GNUC__) */
Pokitto 30:796f9611d2ac 69
Pokitto 30:796f9611d2ac 70 #ifdef __cplusplus
Pokitto 30:796f9611d2ac 71 }
Pokitto 30:796f9611d2ac 72 #endif
Pokitto 30:796f9611d2ac 73
Pokitto 30:796f9611d2ac 74 /*****************************************************************************
Pokitto 30:796f9611d2ac 75 * Private functions
Pokitto 30:796f9611d2ac 76 ****************************************************************************/
Pokitto 30:796f9611d2ac 77
Pokitto 30:796f9611d2ac 78 /*****************************************************************************
Pokitto 30:796f9611d2ac 79 * Public functions
Pokitto 30:796f9611d2ac 80 ****************************************************************************/
Pokitto 30:796f9611d2ac 81
Pokitto 30:796f9611d2ac 82 /* Set DMA transfer register interrupt bits (safe) */
Pokitto 30:796f9611d2ac 83 void Chip_DMA_SetTranBits(LPC_DMA_T *pDMA, DMA_CHID_T ch, uint32_t mask)
Pokitto 30:796f9611d2ac 84 {
Pokitto 30:796f9611d2ac 85 uint32_t temp;
Pokitto 30:796f9611d2ac 86
Pokitto 30:796f9611d2ac 87 /* Read and write values may not be the same, write 0 to
Pokitto 30:796f9611d2ac 88 undefined bits */
Pokitto 30:796f9611d2ac 89 temp = pDMA->DMACH[ch].XFERCFG & ~0xFC000CC0;
Pokitto 30:796f9611d2ac 90
Pokitto 30:796f9611d2ac 91 pDMA->DMACH[ch].XFERCFG = temp | mask;
Pokitto 30:796f9611d2ac 92 }
Pokitto 30:796f9611d2ac 93
Pokitto 30:796f9611d2ac 94 /* Clear DMA transfer register interrupt bits (safe) */
Pokitto 30:796f9611d2ac 95 void Chip_DMA_ClearTranBits(LPC_DMA_T *pDMA, DMA_CHID_T ch, uint32_t mask)
Pokitto 30:796f9611d2ac 96 {
Pokitto 30:796f9611d2ac 97 uint32_t temp;
Pokitto 30:796f9611d2ac 98
Pokitto 30:796f9611d2ac 99 /* Read and write values may not be the same, write 0 to
Pokitto 30:796f9611d2ac 100 undefined bits */
Pokitto 30:796f9611d2ac 101 temp = pDMA->DMACH[ch].XFERCFG & ~0xFC000CC0;
Pokitto 30:796f9611d2ac 102
Pokitto 30:796f9611d2ac 103 pDMA->DMACH[ch].XFERCFG = temp & ~mask;
Pokitto 30:796f9611d2ac 104 }
Pokitto 30:796f9611d2ac 105
Pokitto 30:796f9611d2ac 106 /* Update the transfer size in an existing DMA channel transfer configuration */
Pokitto 30:796f9611d2ac 107 void Chip_DMA_SetupChannelTransferSize(LPC_DMA_T *pDMA, DMA_CHID_T ch, uint32_t trans)
Pokitto 30:796f9611d2ac 108 {
Pokitto 30:796f9611d2ac 109 Chip_DMA_ClearTranBits(pDMA, ch, (0x3FF << 16));
Pokitto 30:796f9611d2ac 110 Chip_DMA_SetTranBits(pDMA, ch, DMA_XFERCFG_XFERCOUNT(trans));
Pokitto 30:796f9611d2ac 111 }
Pokitto 30:796f9611d2ac 112
Pokitto 30:796f9611d2ac 113 /* Sets up a DMA channel with the passed DMA transfer descriptor */
Pokitto 30:796f9611d2ac 114 bool Chip_DMA_SetupTranChannel(LPC_DMA_T *pDMA, DMA_CHID_T ch, DMA_CHDESC_T *desc)
Pokitto 30:796f9611d2ac 115 {
Pokitto 30:796f9611d2ac 116 bool good = false;
Pokitto 30:796f9611d2ac 117 DMA_CHDESC_T *pDesc = (DMA_CHDESC_T *) pDMA->SRAMBASE;
Pokitto 30:796f9611d2ac 118
Pokitto 30:796f9611d2ac 119 if ((Chip_DMA_GetActiveChannels(pDMA) & (1 << ch)) == 0) {
Pokitto 30:796f9611d2ac 120 /* Channel is not active, so update the descriptor */
Pokitto 30:796f9611d2ac 121 pDesc[ch] = *desc;
Pokitto 30:796f9611d2ac 122
Pokitto 30:796f9611d2ac 123 good = true;
Pokitto 30:796f9611d2ac 124 }
Pokitto 30:796f9611d2ac 125
Pokitto 30:796f9611d2ac 126 return good;
Pokitto 30:796f9611d2ac 127 }
Pokitto 30:796f9611d2ac 128