12b1d92b5a7a4736e7d4e3e1b0e616dc1002cc12
[fw/openocd] / contrib / loaders / flash / nrf5 / nrf5.S
1 /***************************************************************************
2  *   Copyright (C) 2014 Angus Gratton                                      *
3  *   gus@projectgus.com                                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.                                        *
18  ***************************************************************************/
19
20         .text
21         .syntax unified
22         .cpu cortex-m0
23         .thumb
24
25 /*
26  * Params :
27  * r0 = byte count
28  * r1 = buffer start
29  * r2 = buffer end
30  * r3 = target address
31  * r6 = watchdog refresh value
32  * r7 = watchdog refresh register address
33  */
34
35         .thumb_func
36         .global _start
37 _start:
38 wait_fifo:
39         // Kick the watchdog
40         str     r6, [r7, #0]
41         // Load write pointer
42         ldr     r5, [r1, #0]
43         // Abort if it is NULL
44         cmp     r5, #0
45         beq.n   exit
46         // Load read pointer
47         ldr     r4, [r1, #4]
48         // Continue waiting if it equals the write pointer
49         cmp     r4, r5
50         beq.n   wait_fifo
51         // Copy one word from buffer to target, and increment pointers
52         ldmia   r4!, {r5}
53         stmia   r3!, {r5}
54         // If at end of buffer, wrap back to buffer start
55         cmp     r4, r2
56         bcc.n   no_wrap
57         mov     r4, r1
58         adds    r4, #8
59 no_wrap:
60         // Update read pointer inside the buffer
61         str     r4, [r1, #4]
62         // Deduce the word transferred from the byte count
63         subs    r0, #4
64         // Start again
65         bne.n   wait_fifo
66 exit:
67         // Wait for OpenOCD
68         bkpt    #0x00
69
70         .pool