wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000, 2001 |
| 3 | * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com. |
| 4 | * base on code by |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <ppc_asm.tmpl> |
| 27 | #include <ppc_defs.h> |
| 28 | #include <config.h> |
| 29 | #include <watchdog.h> |
| 30 | |
| 31 | /* |
| 32 | * unsigned long long get_ticks(void); |
| 33 | * |
| 34 | * read timebase as "long long" |
| 35 | */ |
| 36 | .globl get_ticks |
| 37 | get_ticks: |
| 38 | 1: mftbu r3 |
| 39 | mftb r4 |
| 40 | mftbu r5 |
| 41 | cmp 0,r3,r5 |
| 42 | bne 1b |
| 43 | blr |
| 44 | |
| 45 | /* |
| 46 | * Delay for a number of ticks |
| 47 | */ |
| 48 | .globl wait_ticks |
| 49 | wait_ticks: |
Joakim Tjernlund | 194c3bf | 2012-07-16 21:25:40 +0000 | [diff] [blame] | 50 | stwu r1, -16(r1) |
| 51 | mflr r0 /* save link register */ |
| 52 | stw r0, 20(r1) /* Use r0 or GDB will be unhappy */ |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 53 | stw r14, 12(r1) /* save used registers */ |
| 54 | stw r15, 8(r1) |
| 55 | mr r14, r3 /* save tick count */ |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 56 | bl get_ticks /* Get start time */ |
| 57 | |
| 58 | /* Calculate end time */ |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 59 | addc r14, r4, r14 /* Compute end time lower */ |
| 60 | addze r15, r3 /* and end time upper */ |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 61 | |
| 62 | WATCHDOG_RESET /* Trigger watchdog, if needed */ |
| 63 | 1: bl get_ticks /* Get current time */ |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 64 | subfc r4, r4, r14 /* Subtract current time from end time */ |
| 65 | subfe. r3, r3, r15 |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 66 | bge 1b /* Loop until time expired */ |
| 67 | |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 68 | lwz r15, 8(r1) /* restore saved registers */ |
| 69 | lwz r14, 12(r1) |
| 70 | lwz r0, 20(r1) |
Joakim Tjernlund | 194c3bf | 2012-07-16 21:25:40 +0000 | [diff] [blame] | 71 | addi r1,r1,16 |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 72 | mtlr r0 |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 73 | blr |