Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /*
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2013 Nordic Semiconductor ASA
sahilmgandhi 18:6a4db94011d3 3 * All rights reserved.
sahilmgandhi 18:6a4db94011d3 4 *
sahilmgandhi 18:6a4db94011d3 5 * Redistribution and use in source and binary forms, with or without modification,
sahilmgandhi 18:6a4db94011d3 6 * are permitted provided that the following conditions are met:
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * 1. Redistributions of source code must retain the above copyright notice, this list
sahilmgandhi 18:6a4db94011d3 9 * of conditions and the following disclaimer.
sahilmgandhi 18:6a4db94011d3 10 *
sahilmgandhi 18:6a4db94011d3 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
sahilmgandhi 18:6a4db94011d3 12 * integrated circuit in a product or a software update for such product, must reproduce
sahilmgandhi 18:6a4db94011d3 13 * the above copyright notice, this list of conditions and the following disclaimer in
sahilmgandhi 18:6a4db94011d3 14 * the documentation and/or other materials provided with the distribution.
sahilmgandhi 18:6a4db94011d3 15 *
sahilmgandhi 18:6a4db94011d3 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
sahilmgandhi 18:6a4db94011d3 17 * used to endorse or promote products derived from this software without specific prior
sahilmgandhi 18:6a4db94011d3 18 * written permission.
sahilmgandhi 18:6a4db94011d3 19 *
sahilmgandhi 18:6a4db94011d3 20 * 4. This software, with or without modification, must only be used with a
sahilmgandhi 18:6a4db94011d3 21 * Nordic Semiconductor ASA integrated circuit.
sahilmgandhi 18:6a4db94011d3 22 *
sahilmgandhi 18:6a4db94011d3 23 * 5. Any software provided in binary or object form under this license must not be reverse
sahilmgandhi 18:6a4db94011d3 24 * engineered, decompiled, modified and/or disassembled.
sahilmgandhi 18:6a4db94011d3 25 *
sahilmgandhi 18:6a4db94011d3 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
sahilmgandhi 18:6a4db94011d3 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
sahilmgandhi 18:6a4db94011d3 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
sahilmgandhi 18:6a4db94011d3 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
sahilmgandhi 18:6a4db94011d3 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
sahilmgandhi 18:6a4db94011d3 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
sahilmgandhi 18:6a4db94011d3 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
sahilmgandhi 18:6a4db94011d3 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
sahilmgandhi 18:6a4db94011d3 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
sahilmgandhi 18:6a4db94011d3 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sahilmgandhi 18:6a4db94011d3 36 *
sahilmgandhi 18:6a4db94011d3 37 */
sahilmgandhi 18:6a4db94011d3 38
sahilmgandhi 18:6a4db94011d3 39
sahilmgandhi 18:6a4db94011d3 40 /*
sahilmgandhi 18:6a4db94011d3 41 NOTE: Template files (including this one) are application specific and therefore
sahilmgandhi 18:6a4db94011d3 42 expected to be copied into the application project folder prior to its use!
sahilmgandhi 18:6a4db94011d3 43 */
sahilmgandhi 18:6a4db94011d3 44
sahilmgandhi 18:6a4db94011d3 45 .syntax unified
sahilmgandhi 18:6a4db94011d3 46 .arch armv6-m
sahilmgandhi 18:6a4db94011d3 47
sahilmgandhi 18:6a4db94011d3 48 .section .stack
sahilmgandhi 18:6a4db94011d3 49 .align 3
sahilmgandhi 18:6a4db94011d3 50 #ifdef __STACK_SIZE
sahilmgandhi 18:6a4db94011d3 51 .equ Stack_Size, __STACK_SIZE
sahilmgandhi 18:6a4db94011d3 52 #else
sahilmgandhi 18:6a4db94011d3 53 .equ Stack_Size, 2048
sahilmgandhi 18:6a4db94011d3 54 #endif
sahilmgandhi 18:6a4db94011d3 55 .globl Stack_Size
sahilmgandhi 18:6a4db94011d3 56 .globl __StackTop
sahilmgandhi 18:6a4db94011d3 57 .globl __StackLimit
sahilmgandhi 18:6a4db94011d3 58 __StackLimit:
sahilmgandhi 18:6a4db94011d3 59 .space Stack_Size
sahilmgandhi 18:6a4db94011d3 60 .size __StackLimit, . - __StackLimit
sahilmgandhi 18:6a4db94011d3 61 __StackTop:
sahilmgandhi 18:6a4db94011d3 62 .size __StackTop, . - __StackTop
sahilmgandhi 18:6a4db94011d3 63
sahilmgandhi 18:6a4db94011d3 64 .section .heap
sahilmgandhi 18:6a4db94011d3 65 .align 3
sahilmgandhi 18:6a4db94011d3 66 .globl __HeapBase
sahilmgandhi 18:6a4db94011d3 67 .globl __HeapLimit
sahilmgandhi 18:6a4db94011d3 68
sahilmgandhi 18:6a4db94011d3 69 .section .Vectors
sahilmgandhi 18:6a4db94011d3 70 .align 2
sahilmgandhi 18:6a4db94011d3 71 .globl __Vectors
sahilmgandhi 18:6a4db94011d3 72 __Vectors:
sahilmgandhi 18:6a4db94011d3 73 .long __StackTop /* Top of Stack */
sahilmgandhi 18:6a4db94011d3 74 .long Reset_Handler /* Reset Handler */
sahilmgandhi 18:6a4db94011d3 75 .long NMI_Handler /* NMI Handler */
sahilmgandhi 18:6a4db94011d3 76 .long HardFault_Handler /* Hard Fault Handler */
sahilmgandhi 18:6a4db94011d3 77 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 78 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 79 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 80 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 81 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 82 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 83 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 84 .long SVC_Handler /* SVCall Handler */
sahilmgandhi 18:6a4db94011d3 85 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 86 .long 0 /* Reserved */
sahilmgandhi 18:6a4db94011d3 87 .long PendSV_Handler /* PendSV Handler */
sahilmgandhi 18:6a4db94011d3 88 .long SysTick_Handler /* SysTick Handler */
sahilmgandhi 18:6a4db94011d3 89
sahilmgandhi 18:6a4db94011d3 90 /* External Interrupts */
sahilmgandhi 18:6a4db94011d3 91 .long POWER_CLOCK_IRQHandler /*POWER_CLOCK */
sahilmgandhi 18:6a4db94011d3 92 .long RADIO_IRQHandler /*RADIO */
sahilmgandhi 18:6a4db94011d3 93 .long UART0_IRQHandler_v /*UART0 */
sahilmgandhi 18:6a4db94011d3 94 .long SPI0_TWI0_IRQHandler_v /*SPI0_TWI0 */
sahilmgandhi 18:6a4db94011d3 95 .long SPI1_TWI1_IRQHandler_v /*SPI1_TWI1 */
sahilmgandhi 18:6a4db94011d3 96 .long 0 /*Reserved */
sahilmgandhi 18:6a4db94011d3 97 .long GPIOTE_IRQHandler_v /*GPIOTE */
sahilmgandhi 18:6a4db94011d3 98 .long ADC_IRQHandler_v /*ADC */
sahilmgandhi 18:6a4db94011d3 99 .long TIMER0_IRQHandler /*TIMER0 */
sahilmgandhi 18:6a4db94011d3 100 .long TIMER1_IRQHandler_v /*TIMER1 */
sahilmgandhi 18:6a4db94011d3 101 .long TIMER2_IRQHandler_v /*TIMER2 */
sahilmgandhi 18:6a4db94011d3 102 .long RTC0_IRQHandler /*RTC0 */
sahilmgandhi 18:6a4db94011d3 103 .long TEMP_IRQHandler /*TEMP */
sahilmgandhi 18:6a4db94011d3 104 .long RNG_IRQHandler /*RNG */
sahilmgandhi 18:6a4db94011d3 105 .long ECB_IRQHandler /*ECB */
sahilmgandhi 18:6a4db94011d3 106 .long CCM_AAR_IRQHandler /*CCM_AAR */
sahilmgandhi 18:6a4db94011d3 107 .long WDT_IRQHandler_v /*WDT */
sahilmgandhi 18:6a4db94011d3 108 .long RTC1_IRQHandler_v /*RTC1 */
sahilmgandhi 18:6a4db94011d3 109 .long QDEC_IRQHandler_v /*QDEC */
sahilmgandhi 18:6a4db94011d3 110 .long LPCOMP_IRQHandler_v /*LPCOMP */
sahilmgandhi 18:6a4db94011d3 111 .long SWI0_IRQHandler_v /*SWI0 */
sahilmgandhi 18:6a4db94011d3 112 .long SWI1_IRQHandler_v /*SWI1 */
sahilmgandhi 18:6a4db94011d3 113 .long SWI2_IRQHandler_v /*SWI2 */
sahilmgandhi 18:6a4db94011d3 114 .long SWI3_IRQHandler_v /*SWI3 */
sahilmgandhi 18:6a4db94011d3 115 .long SWI4_IRQHandler /*SWI4 */
sahilmgandhi 18:6a4db94011d3 116 .long SWI5_IRQHandler /*SWI5 */
sahilmgandhi 18:6a4db94011d3 117
sahilmgandhi 18:6a4db94011d3 118
sahilmgandhi 18:6a4db94011d3 119 .size __Vectors, . - __Vectors
sahilmgandhi 18:6a4db94011d3 120
sahilmgandhi 18:6a4db94011d3 121 /* Reset Handler */
sahilmgandhi 18:6a4db94011d3 122
sahilmgandhi 18:6a4db94011d3 123 .equ NRF_POWER_RAMON_ADDRESS, 0x40000524
sahilmgandhi 18:6a4db94011d3 124 .equ NRF_POWER_RAMONB_ADDRESS, 0x40000554
sahilmgandhi 18:6a4db94011d3 125 .equ NRF_POWER_RAMONx_RAMxON_ONMODE_Msk, 0x3
sahilmgandhi 18:6a4db94011d3 126
sahilmgandhi 18:6a4db94011d3 127 .text
sahilmgandhi 18:6a4db94011d3 128 .thumb
sahilmgandhi 18:6a4db94011d3 129 .thumb_func
sahilmgandhi 18:6a4db94011d3 130 .align 1
sahilmgandhi 18:6a4db94011d3 131 .globl Reset_Handler
sahilmgandhi 18:6a4db94011d3 132 .type Reset_Handler, %function
sahilmgandhi 18:6a4db94011d3 133 Reset_Handler:
sahilmgandhi 18:6a4db94011d3 134 .fnstart
sahilmgandhi 18:6a4db94011d3 135
sahilmgandhi 18:6a4db94011d3 136 MOVS R1, #NRF_POWER_RAMONx_RAMxON_ONMODE_Msk
sahilmgandhi 18:6a4db94011d3 137 LDR R0, =NRF_POWER_RAMON_ADDRESS
sahilmgandhi 18:6a4db94011d3 138 LDR R2, [R0]
sahilmgandhi 18:6a4db94011d3 139 ORRS R2, R1
sahilmgandhi 18:6a4db94011d3 140 STR R2, [R0]
sahilmgandhi 18:6a4db94011d3 141
sahilmgandhi 18:6a4db94011d3 142 LDR R0, =NRF_POWER_RAMONB_ADDRESS
sahilmgandhi 18:6a4db94011d3 143 LDR R2, [R0]
sahilmgandhi 18:6a4db94011d3 144 ORRS R2, R1
sahilmgandhi 18:6a4db94011d3 145 STR R2, [R0]
sahilmgandhi 18:6a4db94011d3 146
sahilmgandhi 18:6a4db94011d3 147 /* Loop to copy data from read only memory to RAM. The ranges
sahilmgandhi 18:6a4db94011d3 148 * of copy from/to are specified by following symbols evaluated in
sahilmgandhi 18:6a4db94011d3 149 * linker script.
sahilmgandhi 18:6a4db94011d3 150 * __etext: End of code section, i.e., begin of data sections to copy from.
sahilmgandhi 18:6a4db94011d3 151 * __data_start__/__data_end__: RAM address range that data should be
sahilmgandhi 18:6a4db94011d3 152 * copied to. Both must be aligned to 4 bytes boundary. */
sahilmgandhi 18:6a4db94011d3 153
sahilmgandhi 18:6a4db94011d3 154 ldr r1, =__etext
sahilmgandhi 18:6a4db94011d3 155 ldr r2, =__data_start__
sahilmgandhi 18:6a4db94011d3 156 ldr r3, =__data_end__
sahilmgandhi 18:6a4db94011d3 157
sahilmgandhi 18:6a4db94011d3 158 subs r3, r2
sahilmgandhi 18:6a4db94011d3 159 ble .LC0
sahilmgandhi 18:6a4db94011d3 160
sahilmgandhi 18:6a4db94011d3 161 .LC1:
sahilmgandhi 18:6a4db94011d3 162 subs r3, 4
sahilmgandhi 18:6a4db94011d3 163 ldr r0, [r1,r3]
sahilmgandhi 18:6a4db94011d3 164 str r0, [r2,r3]
sahilmgandhi 18:6a4db94011d3 165 bgt .LC1
sahilmgandhi 18:6a4db94011d3 166 .LC0:
sahilmgandhi 18:6a4db94011d3 167
sahilmgandhi 18:6a4db94011d3 168 LDR R0, =SystemInit
sahilmgandhi 18:6a4db94011d3 169 BLX R0
sahilmgandhi 18:6a4db94011d3 170 LDR R0, =nrf_reloc_vector_table
sahilmgandhi 18:6a4db94011d3 171 BLX R0
sahilmgandhi 18:6a4db94011d3 172 LDR R0, =_start
sahilmgandhi 18:6a4db94011d3 173 BX R0
sahilmgandhi 18:6a4db94011d3 174
sahilmgandhi 18:6a4db94011d3 175 .pool
sahilmgandhi 18:6a4db94011d3 176 .cantunwind
sahilmgandhi 18:6a4db94011d3 177 .fnend
sahilmgandhi 18:6a4db94011d3 178 .size Reset_Handler,.-Reset_Handler
sahilmgandhi 18:6a4db94011d3 179
sahilmgandhi 18:6a4db94011d3 180 .section ".text"
sahilmgandhi 18:6a4db94011d3 181
sahilmgandhi 18:6a4db94011d3 182
sahilmgandhi 18:6a4db94011d3 183 /* Dummy Exception Handlers (infinite loops which can be modified) */
sahilmgandhi 18:6a4db94011d3 184
sahilmgandhi 18:6a4db94011d3 185 .weak NMI_Handler
sahilmgandhi 18:6a4db94011d3 186 .type NMI_Handler, %function
sahilmgandhi 18:6a4db94011d3 187 NMI_Handler:
sahilmgandhi 18:6a4db94011d3 188 B .
sahilmgandhi 18:6a4db94011d3 189 .size NMI_Handler, . - NMI_Handler
sahilmgandhi 18:6a4db94011d3 190
sahilmgandhi 18:6a4db94011d3 191
sahilmgandhi 18:6a4db94011d3 192 .weak HardFault_Handler
sahilmgandhi 18:6a4db94011d3 193 .type HardFault_Handler, %function
sahilmgandhi 18:6a4db94011d3 194 HardFault_Handler:
sahilmgandhi 18:6a4db94011d3 195 B .
sahilmgandhi 18:6a4db94011d3 196 .size HardFault_Handler, . - HardFault_Handler
sahilmgandhi 18:6a4db94011d3 197
sahilmgandhi 18:6a4db94011d3 198
sahilmgandhi 18:6a4db94011d3 199 .weak SVC_Handler
sahilmgandhi 18:6a4db94011d3 200 .type SVC_Handler, %function
sahilmgandhi 18:6a4db94011d3 201 SVC_Handler:
sahilmgandhi 18:6a4db94011d3 202 B .
sahilmgandhi 18:6a4db94011d3 203 .size SVC_Handler, . - SVC_Handler
sahilmgandhi 18:6a4db94011d3 204
sahilmgandhi 18:6a4db94011d3 205
sahilmgandhi 18:6a4db94011d3 206 .weak PendSV_Handler
sahilmgandhi 18:6a4db94011d3 207 .type PendSV_Handler, %function
sahilmgandhi 18:6a4db94011d3 208 PendSV_Handler:
sahilmgandhi 18:6a4db94011d3 209 B .
sahilmgandhi 18:6a4db94011d3 210 .size PendSV_Handler, . - PendSV_Handler
sahilmgandhi 18:6a4db94011d3 211
sahilmgandhi 18:6a4db94011d3 212
sahilmgandhi 18:6a4db94011d3 213 .weak SysTick_Handler
sahilmgandhi 18:6a4db94011d3 214 .type SysTick_Handler, %function
sahilmgandhi 18:6a4db94011d3 215 SysTick_Handler:
sahilmgandhi 18:6a4db94011d3 216 B .
sahilmgandhi 18:6a4db94011d3 217 .size SysTick_Handler, . - SysTick_Handler
sahilmgandhi 18:6a4db94011d3 218
sahilmgandhi 18:6a4db94011d3 219
sahilmgandhi 18:6a4db94011d3 220 /* IRQ Handlers */
sahilmgandhi 18:6a4db94011d3 221
sahilmgandhi 18:6a4db94011d3 222 .globl Default_Handler
sahilmgandhi 18:6a4db94011d3 223 .type Default_Handler, %function
sahilmgandhi 18:6a4db94011d3 224 Default_Handler:
sahilmgandhi 18:6a4db94011d3 225 B .
sahilmgandhi 18:6a4db94011d3 226 .size Default_Handler, . - Default_Handler
sahilmgandhi 18:6a4db94011d3 227
sahilmgandhi 18:6a4db94011d3 228 .macro IRQ handler
sahilmgandhi 18:6a4db94011d3 229 .weak \handler
sahilmgandhi 18:6a4db94011d3 230 .set \handler, Default_Handler
sahilmgandhi 18:6a4db94011d3 231 .endm
sahilmgandhi 18:6a4db94011d3 232
sahilmgandhi 18:6a4db94011d3 233 IRQ POWER_CLOCK_IRQHandler /* restricted */
sahilmgandhi 18:6a4db94011d3 234 IRQ RADIO_IRQHandler /* blocked */
sahilmgandhi 18:6a4db94011d3 235 IRQ UART0_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 236 IRQ SPI0_TWI0_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 237 IRQ SPI1_TWI1_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 238 IRQ GPIOTE_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 239 IRQ ADC_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 240 IRQ TIMER0_IRQHandler /* blocked */
sahilmgandhi 18:6a4db94011d3 241 IRQ TIMER1_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 242 IRQ TIMER2_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 243 IRQ RTC0_IRQHandler /* blocked */
sahilmgandhi 18:6a4db94011d3 244 IRQ TEMP_IRQHandler /* restricted */
sahilmgandhi 18:6a4db94011d3 245 IRQ RNG_IRQHandler /* restricted */
sahilmgandhi 18:6a4db94011d3 246 IRQ ECB_IRQHandler /* restricted */
sahilmgandhi 18:6a4db94011d3 247 IRQ CCM_AAR_IRQHandler /* blocked */
sahilmgandhi 18:6a4db94011d3 248 IRQ WDT_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 249 IRQ RTC1_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 250 IRQ QDEC_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 251 IRQ LPCOMP_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 252 IRQ SWI0_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 253 IRQ SWI1_IRQHandler_v /* restricted for Radio Notification */
sahilmgandhi 18:6a4db94011d3 254 IRQ SWI2_IRQHandler_v /* blocked for SoftDevice Event */
sahilmgandhi 18:6a4db94011d3 255 IRQ SWI3_IRQHandler_v
sahilmgandhi 18:6a4db94011d3 256 IRQ SWI4_IRQHandler /* blocked */
sahilmgandhi 18:6a4db94011d3 257 IRQ SWI5_IRQHandler /* blocked */
sahilmgandhi 18:6a4db94011d3 258
sahilmgandhi 18:6a4db94011d3 259
sahilmgandhi 18:6a4db94011d3 260 .end