PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 18:03:02 2017 +0000
Revision:
11:02ad9c807a21
Parent:
5:7e5c566b1760
fixed 4color refreshRegion code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:7e5c566b1760 1 /* Copyright (c) 2009 - 2012 ARM LIMITED
Pokitto 5:7e5c566b1760 2
Pokitto 5:7e5c566b1760 3 All rights reserved.
Pokitto 5:7e5c566b1760 4 Redistribution and use in source and binary forms, with or without
Pokitto 5:7e5c566b1760 5 modification, are permitted provided that the following conditions are met:
Pokitto 5:7e5c566b1760 6 - Redistributions of source code must retain the above copyright
Pokitto 5:7e5c566b1760 7 notice, this list of conditions and the following disclaimer.
Pokitto 5:7e5c566b1760 8 - Redistributions in binary form must reproduce the above copyright
Pokitto 5:7e5c566b1760 9 notice, this list of conditions and the following disclaimer in the
Pokitto 5:7e5c566b1760 10 documentation and/or other materials provided with the distribution.
Pokitto 5:7e5c566b1760 11 - Neither the name of ARM nor the names of its contributors may be used
Pokitto 5:7e5c566b1760 12 to endorse or promote products derived from this software without
Pokitto 5:7e5c566b1760 13 specific prior written permission.
Pokitto 5:7e5c566b1760 14 *
Pokitto 5:7e5c566b1760 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Pokitto 5:7e5c566b1760 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Pokitto 5:7e5c566b1760 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Pokitto 5:7e5c566b1760 18 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
Pokitto 5:7e5c566b1760 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Pokitto 5:7e5c566b1760 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Pokitto 5:7e5c566b1760 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Pokitto 5:7e5c566b1760 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Pokitto 5:7e5c566b1760 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Pokitto 5:7e5c566b1760 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Pokitto 5:7e5c566b1760 25 POSSIBILITY OF SUCH DAMAGE.
Pokitto 5:7e5c566b1760 26 ---------------------------------------------------------------------------*/
Pokitto 5:7e5c566b1760 27
Pokitto 5:7e5c566b1760 28 /*----------------------------------------------------------------------------
Pokitto 5:7e5c566b1760 29 * Functions
Pokitto 5:7e5c566b1760 30 *---------------------------------------------------------------------------*/
Pokitto 5:7e5c566b1760 31 .text
Pokitto 5:7e5c566b1760 32 .global __v7_all_cache
Pokitto 5:7e5c566b1760 33 /*
Pokitto 5:7e5c566b1760 34 * __STATIC_ASM void __v7_all_cache(uint32_t op) {
Pokitto 5:7e5c566b1760 35 */
Pokitto 5:7e5c566b1760 36 __v7_all_cache:
Pokitto 5:7e5c566b1760 37 .arm
Pokitto 5:7e5c566b1760 38
Pokitto 5:7e5c566b1760 39 PUSH {R4-R11}
Pokitto 5:7e5c566b1760 40
Pokitto 5:7e5c566b1760 41 MRC p15, 1, R6, c0, c0, 1 /* Read CLIDR */
Pokitto 5:7e5c566b1760 42 ANDS R3, R6, #0x07000000 /* Extract coherency level */
Pokitto 5:7e5c566b1760 43 MOV R3, R3, LSR #23 /* Total cache levels << 1 */
Pokitto 5:7e5c566b1760 44 BEQ Finished /* If 0, no need to clean */
Pokitto 5:7e5c566b1760 45
Pokitto 5:7e5c566b1760 46 MOV R10, #0 /* R10 holds current cache level << 1 */
Pokitto 5:7e5c566b1760 47 Loop1: ADD R2, R10, R10, LSR #1 /* R2 holds cache "Set" position */
Pokitto 5:7e5c566b1760 48 MOV R1, R6, LSR R2 /* Bottom 3 bits are the Cache-type for this level */
Pokitto 5:7e5c566b1760 49 AND R1, R1, #7 /* Isolate those lower 3 bits */
Pokitto 5:7e5c566b1760 50 CMP R1, #2
Pokitto 5:7e5c566b1760 51 BLT Skip /* No cache or only instruction cache at this level */
Pokitto 5:7e5c566b1760 52
Pokitto 5:7e5c566b1760 53 MCR p15, 2, R10, c0, c0, 0 /* Write the Cache Size selection register */
Pokitto 5:7e5c566b1760 54 ISB /* ISB to sync the change to the CacheSizeID reg */
Pokitto 5:7e5c566b1760 55 MRC p15, 1, R1, c0, c0, 0 /* Reads current Cache Size ID register */
Pokitto 5:7e5c566b1760 56 AND R2, R1, #7 /* Extract the line length field */
Pokitto 5:7e5c566b1760 57 ADD R2, R2, #4 /* Add 4 for the line length offset (log2 16 bytes) */
Pokitto 5:7e5c566b1760 58 LDR R4, =0x3FF
Pokitto 5:7e5c566b1760 59 ANDS R4, R4, R1, LSR #3 /* R4 is the max number on the way size (right aligned) */
Pokitto 5:7e5c566b1760 60 CLZ R5, R4 /* R5 is the bit position of the way size increment */
Pokitto 5:7e5c566b1760 61 LDR R7, =0x7FFF
Pokitto 5:7e5c566b1760 62 ANDS R7, R7, R1, LSR #13 /* R7 is the max number of the index size (right aligned) */
Pokitto 5:7e5c566b1760 63
Pokitto 5:7e5c566b1760 64 Loop2: MOV R9, R4 /* R9 working copy of the max way size (right aligned) */
Pokitto 5:7e5c566b1760 65
Pokitto 5:7e5c566b1760 66 Loop3: ORR R11, R10, R9, LSL R5 /* Factor in the Way number and cache number into R11 */
Pokitto 5:7e5c566b1760 67 ORR R11, R11, R7, LSL R2 /* Factor in the Set number */
Pokitto 5:7e5c566b1760 68 CMP R0, #0
Pokitto 5:7e5c566b1760 69 BNE Dccsw
Pokitto 5:7e5c566b1760 70 MCR p15, 0, R11, c7, c6, 2 /* DCISW. Invalidate by Set/Way */
Pokitto 5:7e5c566b1760 71 B cont
Pokitto 5:7e5c566b1760 72 Dccsw: CMP R0, #1
Pokitto 5:7e5c566b1760 73 BNE Dccisw
Pokitto 5:7e5c566b1760 74 MCR p15, 0, R11, c7, c10, 2 /* DCCSW. Clean by Set/Way */
Pokitto 5:7e5c566b1760 75 B cont
Pokitto 5:7e5c566b1760 76 Dccisw: MCR p15, 0, R11, c7, c14, 2 /* DCCISW, Clean and Invalidate by Set/Way */
Pokitto 5:7e5c566b1760 77 cont: SUBS R9, R9, #1 /* Decrement the Way number */
Pokitto 5:7e5c566b1760 78 BGE Loop3
Pokitto 5:7e5c566b1760 79 SUBS R7, R7, #1 /* Decrement the Set number */
Pokitto 5:7e5c566b1760 80 BGE Loop2
Pokitto 5:7e5c566b1760 81 Skip: ADD R10, R10, #2 /* increment the cache number */
Pokitto 5:7e5c566b1760 82 CMP R3, R10
Pokitto 5:7e5c566b1760 83 BGT Loop1
Pokitto 5:7e5c566b1760 84
Pokitto 5:7e5c566b1760 85 Finished:
Pokitto 5:7e5c566b1760 86 DSB
Pokitto 5:7e5c566b1760 87 POP {R4-R11}
Pokitto 5:7e5c566b1760 88 BX lr
Pokitto 5:7e5c566b1760 89
Pokitto 5:7e5c566b1760 90
Pokitto 5:7e5c566b1760 91 .END
Pokitto 5:7e5c566b1760 92 /*----------------------------------------------------------------------------
Pokitto 5:7e5c566b1760 93 * end of file
Pokitto 5:7e5c566b1760 94 *---------------------------------------------------------------------------*/