1/* 2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 3 * Copyright (c) 2012 Damjan Marion <dmarion@freebsd.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h>
| 1/* 2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 3 * Copyright (c) 2012 Damjan Marion <dmarion@freebsd.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h>
|
29__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_systimer.c 244758 2012-12-28 01:38:43Z gonzo $");
| 29__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_systimer.c 247463 2013-02-28 13:46:03Z mav $");
|
30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/bus.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36#include <sys/malloc.h> 37#include <sys/rman.h> 38#include <sys/timeet.h> 39#include <sys/timetc.h> 40#include <sys/watchdog.h> 41#include <machine/bus.h> 42#include <machine/cpu.h> 43#include <machine/frame.h> 44#include <machine/intr.h> 45 46#include <dev/fdt/fdt_common.h> 47#include <dev/ofw/openfirm.h> 48#include <dev/ofw/ofw_bus.h> 49#include <dev/ofw/ofw_bus_subr.h> 50 51#include <machine/bus.h> 52#include <machine/fdt.h> 53 54#define BCM2835_NUM_TIMERS 4 55 56#define DEFAULT_TIMER 3 57#define DEFAULT_FREQUENCY 1000000 58#define MIN_PERIOD 100LLU 59 60#define SYSTIMER_CS 0x00 61#define SYSTIMER_CLO 0x04 62#define SYSTIMER_CHI 0x08 63#define SYSTIMER_C0 0x0C 64#define SYSTIMER_C1 0x10 65#define SYSTIMER_C2 0x14 66#define SYSTIMER_C3 0x18 67 68struct systimer { 69 int index; 70 bool enabled; 71 struct eventtimer et; 72}; 73 74struct bcm_systimer_softc { 75 struct resource* mem_res; 76 struct resource* irq_res[BCM2835_NUM_TIMERS]; 77 void* intr_hl[BCM2835_NUM_TIMERS]; 78 uint32_t sysclk_freq; 79 bus_space_tag_t bst; 80 bus_space_handle_t bsh; 81 struct systimer st[BCM2835_NUM_TIMERS]; 82}; 83 84static struct resource_spec bcm_systimer_irq_spec[] = { 85 { SYS_RES_IRQ, 0, RF_ACTIVE }, 86 { SYS_RES_IRQ, 1, RF_ACTIVE }, 87 { SYS_RES_IRQ, 2, RF_ACTIVE }, 88 { SYS_RES_IRQ, 3, RF_ACTIVE }, 89 { -1, 0, 0 } 90}; 91 92static struct bcm_systimer_softc *bcm_systimer_sc = NULL; 93 94/* Read/Write macros for Timer used as timecounter */ 95#define bcm_systimer_tc_read_4(reg) \ 96 bus_space_read_4(bcm_systimer_sc->bst, \ 97 bcm_systimer_sc->bsh, reg) 98 99#define bcm_systimer_tc_write_4(reg, val) \ 100 bus_space_write_4(bcm_systimer_sc->bst, \ 101 bcm_systimer_sc->bsh, reg, val) 102 103static unsigned bcm_systimer_tc_get_timecount(struct timecounter *); 104 105static struct timecounter bcm_systimer_tc = { 106 .tc_name = "BCM2835 Timecounter", 107 .tc_get_timecount = bcm_systimer_tc_get_timecount, 108 .tc_poll_pps = NULL, 109 .tc_counter_mask = ~0u, 110 .tc_frequency = 0, 111 .tc_quality = 1000, 112}; 113 114static unsigned 115bcm_systimer_tc_get_timecount(struct timecounter *tc) 116{ 117 return bcm_systimer_tc_read_4(SYSTIMER_CLO); 118} 119 120static int
| 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/bus.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36#include <sys/malloc.h> 37#include <sys/rman.h> 38#include <sys/timeet.h> 39#include <sys/timetc.h> 40#include <sys/watchdog.h> 41#include <machine/bus.h> 42#include <machine/cpu.h> 43#include <machine/frame.h> 44#include <machine/intr.h> 45 46#include <dev/fdt/fdt_common.h> 47#include <dev/ofw/openfirm.h> 48#include <dev/ofw/ofw_bus.h> 49#include <dev/ofw/ofw_bus_subr.h> 50 51#include <machine/bus.h> 52#include <machine/fdt.h> 53 54#define BCM2835_NUM_TIMERS 4 55 56#define DEFAULT_TIMER 3 57#define DEFAULT_FREQUENCY 1000000 58#define MIN_PERIOD 100LLU 59 60#define SYSTIMER_CS 0x00 61#define SYSTIMER_CLO 0x04 62#define SYSTIMER_CHI 0x08 63#define SYSTIMER_C0 0x0C 64#define SYSTIMER_C1 0x10 65#define SYSTIMER_C2 0x14 66#define SYSTIMER_C3 0x18 67 68struct systimer { 69 int index; 70 bool enabled; 71 struct eventtimer et; 72}; 73 74struct bcm_systimer_softc { 75 struct resource* mem_res; 76 struct resource* irq_res[BCM2835_NUM_TIMERS]; 77 void* intr_hl[BCM2835_NUM_TIMERS]; 78 uint32_t sysclk_freq; 79 bus_space_tag_t bst; 80 bus_space_handle_t bsh; 81 struct systimer st[BCM2835_NUM_TIMERS]; 82}; 83 84static struct resource_spec bcm_systimer_irq_spec[] = { 85 { SYS_RES_IRQ, 0, RF_ACTIVE }, 86 { SYS_RES_IRQ, 1, RF_ACTIVE }, 87 { SYS_RES_IRQ, 2, RF_ACTIVE }, 88 { SYS_RES_IRQ, 3, RF_ACTIVE }, 89 { -1, 0, 0 } 90}; 91 92static struct bcm_systimer_softc *bcm_systimer_sc = NULL; 93 94/* Read/Write macros for Timer used as timecounter */ 95#define bcm_systimer_tc_read_4(reg) \ 96 bus_space_read_4(bcm_systimer_sc->bst, \ 97 bcm_systimer_sc->bsh, reg) 98 99#define bcm_systimer_tc_write_4(reg, val) \ 100 bus_space_write_4(bcm_systimer_sc->bst, \ 101 bcm_systimer_sc->bsh, reg, val) 102 103static unsigned bcm_systimer_tc_get_timecount(struct timecounter *); 104 105static struct timecounter bcm_systimer_tc = { 106 .tc_name = "BCM2835 Timecounter", 107 .tc_get_timecount = bcm_systimer_tc_get_timecount, 108 .tc_poll_pps = NULL, 109 .tc_counter_mask = ~0u, 110 .tc_frequency = 0, 111 .tc_quality = 1000, 112}; 113 114static unsigned 115bcm_systimer_tc_get_timecount(struct timecounter *tc) 116{ 117 return bcm_systimer_tc_read_4(SYSTIMER_CLO); 118} 119 120static int
|
121bcm_systimer_start(struct eventtimer *et, struct bintime *first, 122 struct bintime *period)
| 121bcm_systimer_start(struct eventtimer *et, sbintime_t first, sbintime_t period)
|
123{ 124 struct systimer *st = et->et_priv; 125 uint32_t clo; 126 uint32_t count; 127 register_t s; 128
| 122{ 123 struct systimer *st = et->et_priv; 124 uint32_t clo; 125 uint32_t count; 126 register_t s; 127
|
129 if (first != NULL) {
| 128 if (first != 0) {
|
130
| 129
|
131 count = (st->et.et_frequency * (first->frac >> 32)) >> 32; 132 if (first->sec != 0) 133 count += st->et.et_frequency * first->sec;
| 130 count = ((uint32_t)et->et_frequency * first) >> 32;
|
134 135 s = intr_disable(); 136 clo = bcm_systimer_tc_read_4(SYSTIMER_CLO); 137 clo += count; 138 /* 139 * Clear pending interrupts 140 */ 141 bcm_systimer_tc_write_4(SYSTIMER_CS, (1 << st->index)); 142 bcm_systimer_tc_write_4(SYSTIMER_C0 + st->index*4, clo); 143 st->enabled = 1; 144 intr_restore(s); 145 146 return (0); 147 } 148 149 return (EINVAL); 150} 151 152static int 153bcm_systimer_stop(struct eventtimer *et) 154{ 155 struct systimer *st = et->et_priv; 156 st->enabled = 0; 157 158 return (0); 159} 160 161static int 162bcm_systimer_intr(void *arg) 163{ 164 struct systimer *st = (struct systimer *)arg; 165 uint32_t cs; 166 167 cs = bcm_systimer_tc_read_4(SYSTIMER_CS); 168 if ((cs & (1 << st->index)) == 0) 169 return (FILTER_STRAY); 170 171 /* ACK interrupt */ 172 bcm_systimer_tc_write_4(SYSTIMER_CS, (1 << st->index)); 173 if (st->enabled) { 174 if (st->et.et_active) { 175 st->et.et_event_cb(&st->et, st->et.et_arg); 176 } 177 } 178 179 return (FILTER_HANDLED); 180} 181 182static int 183bcm_systimer_probe(device_t dev) 184{ 185 186 if (ofw_bus_is_compatible(dev, "broadcom,bcm2835-system-timer")) { 187 device_set_desc(dev, "BCM2835 System Timer"); 188 return (BUS_PROBE_DEFAULT); 189 } 190 191 return (ENXIO); 192} 193 194static int 195bcm_systimer_attach(device_t dev) 196{ 197 struct bcm_systimer_softc *sc = device_get_softc(dev); 198 int err; 199 int rid = 0; 200 201 if (bcm_systimer_sc != NULL) 202 return (EINVAL); 203 204 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); 205 if (sc->mem_res == NULL) { 206 device_printf(dev, "could not allocate memory resource\n"); 207 return (ENXIO); 208 } 209 210 sc->bst = rman_get_bustag(sc->mem_res); 211 sc->bsh = rman_get_bushandle(sc->mem_res); 212 213 /* Request the IRQ resources */ 214 err = bus_alloc_resources(dev, bcm_systimer_irq_spec, 215 sc->irq_res); 216 if (err) { 217 device_printf(dev, "Error: could not allocate irq resources\n"); 218 return (ENXIO); 219 } 220 221 /* TODO: get frequency from FDT */ 222 sc->sysclk_freq = DEFAULT_FREQUENCY; 223 224 /* Setup and enable the timer */ 225 if (bus_setup_intr(dev, sc->irq_res[DEFAULT_TIMER], INTR_TYPE_CLK, 226 bcm_systimer_intr, NULL, &sc->st[DEFAULT_TIMER], 227 &sc->intr_hl[DEFAULT_TIMER]) != 0) { 228 bus_release_resources(dev, bcm_systimer_irq_spec, 229 sc->irq_res); 230 device_printf(dev, "Unable to setup the clock irq handler.\n"); 231 return (ENXIO); 232 } 233 234 sc->st[DEFAULT_TIMER].index = DEFAULT_TIMER; 235 sc->st[DEFAULT_TIMER].enabled = 0; 236 sc->st[DEFAULT_TIMER].et.et_name = malloc(64, M_DEVBUF, M_NOWAIT | M_ZERO); 237 sprintf(sc->st[DEFAULT_TIMER].et.et_name, "BCM2835 Event Timer %d", DEFAULT_TIMER); 238 sc->st[DEFAULT_TIMER].et.et_flags = ET_FLAGS_ONESHOT; 239 sc->st[DEFAULT_TIMER].et.et_quality = 1000; 240 sc->st[DEFAULT_TIMER].et.et_frequency = sc->sysclk_freq;
| 131 132 s = intr_disable(); 133 clo = bcm_systimer_tc_read_4(SYSTIMER_CLO); 134 clo += count; 135 /* 136 * Clear pending interrupts 137 */ 138 bcm_systimer_tc_write_4(SYSTIMER_CS, (1 << st->index)); 139 bcm_systimer_tc_write_4(SYSTIMER_C0 + st->index*4, clo); 140 st->enabled = 1; 141 intr_restore(s); 142 143 return (0); 144 } 145 146 return (EINVAL); 147} 148 149static int 150bcm_systimer_stop(struct eventtimer *et) 151{ 152 struct systimer *st = et->et_priv; 153 st->enabled = 0; 154 155 return (0); 156} 157 158static int 159bcm_systimer_intr(void *arg) 160{ 161 struct systimer *st = (struct systimer *)arg; 162 uint32_t cs; 163 164 cs = bcm_systimer_tc_read_4(SYSTIMER_CS); 165 if ((cs & (1 << st->index)) == 0) 166 return (FILTER_STRAY); 167 168 /* ACK interrupt */ 169 bcm_systimer_tc_write_4(SYSTIMER_CS, (1 << st->index)); 170 if (st->enabled) { 171 if (st->et.et_active) { 172 st->et.et_event_cb(&st->et, st->et.et_arg); 173 } 174 } 175 176 return (FILTER_HANDLED); 177} 178 179static int 180bcm_systimer_probe(device_t dev) 181{ 182 183 if (ofw_bus_is_compatible(dev, "broadcom,bcm2835-system-timer")) { 184 device_set_desc(dev, "BCM2835 System Timer"); 185 return (BUS_PROBE_DEFAULT); 186 } 187 188 return (ENXIO); 189} 190 191static int 192bcm_systimer_attach(device_t dev) 193{ 194 struct bcm_systimer_softc *sc = device_get_softc(dev); 195 int err; 196 int rid = 0; 197 198 if (bcm_systimer_sc != NULL) 199 return (EINVAL); 200 201 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); 202 if (sc->mem_res == NULL) { 203 device_printf(dev, "could not allocate memory resource\n"); 204 return (ENXIO); 205 } 206 207 sc->bst = rman_get_bustag(sc->mem_res); 208 sc->bsh = rman_get_bushandle(sc->mem_res); 209 210 /* Request the IRQ resources */ 211 err = bus_alloc_resources(dev, bcm_systimer_irq_spec, 212 sc->irq_res); 213 if (err) { 214 device_printf(dev, "Error: could not allocate irq resources\n"); 215 return (ENXIO); 216 } 217 218 /* TODO: get frequency from FDT */ 219 sc->sysclk_freq = DEFAULT_FREQUENCY; 220 221 /* Setup and enable the timer */ 222 if (bus_setup_intr(dev, sc->irq_res[DEFAULT_TIMER], INTR_TYPE_CLK, 223 bcm_systimer_intr, NULL, &sc->st[DEFAULT_TIMER], 224 &sc->intr_hl[DEFAULT_TIMER]) != 0) { 225 bus_release_resources(dev, bcm_systimer_irq_spec, 226 sc->irq_res); 227 device_printf(dev, "Unable to setup the clock irq handler.\n"); 228 return (ENXIO); 229 } 230 231 sc->st[DEFAULT_TIMER].index = DEFAULT_TIMER; 232 sc->st[DEFAULT_TIMER].enabled = 0; 233 sc->st[DEFAULT_TIMER].et.et_name = malloc(64, M_DEVBUF, M_NOWAIT | M_ZERO); 234 sprintf(sc->st[DEFAULT_TIMER].et.et_name, "BCM2835 Event Timer %d", DEFAULT_TIMER); 235 sc->st[DEFAULT_TIMER].et.et_flags = ET_FLAGS_ONESHOT; 236 sc->st[DEFAULT_TIMER].et.et_quality = 1000; 237 sc->st[DEFAULT_TIMER].et.et_frequency = sc->sysclk_freq;
|
241 sc->st[DEFAULT_TIMER].et.et_min_period.sec = 0; 242 sc->st[DEFAULT_TIMER].et.et_min_period.frac = 243 ((MIN_PERIOD << 32) / sc->st[DEFAULT_TIMER].et.et_frequency) << 32; 244 sc->st[DEFAULT_TIMER].et.et_max_period.sec = 0xfffffff0U / sc->st[DEFAULT_TIMER].et.et_frequency; 245 sc->st[DEFAULT_TIMER].et.et_max_period.frac = 246 ((0xfffffffeLLU << 32) / sc->st[DEFAULT_TIMER].et.et_frequency) << 32;
| 238 sc->st[DEFAULT_TIMER].et.et_min_period = 239 (MIN_PERIOD << 32) / sc->st[DEFAULT_TIMER].et.et_frequency; 240 sc->st[DEFAULT_TIMER].et.et_max_period = 241 (0xfffffffeLLU << 32) / sc->st[DEFAULT_TIMER].et.et_frequency;
|
247 sc->st[DEFAULT_TIMER].et.et_start = bcm_systimer_start; 248 sc->st[DEFAULT_TIMER].et.et_stop = bcm_systimer_stop; 249 sc->st[DEFAULT_TIMER].et.et_priv = &sc->st[DEFAULT_TIMER]; 250 et_register(&sc->st[DEFAULT_TIMER].et); 251 252 bcm_systimer_sc = sc; 253 254 bcm_systimer_tc.tc_frequency = DEFAULT_FREQUENCY; 255 tc_init(&bcm_systimer_tc); 256 257 return (0); 258} 259 260static device_method_t bcm_systimer_methods[] = { 261 DEVMETHOD(device_probe, bcm_systimer_probe), 262 DEVMETHOD(device_attach, bcm_systimer_attach), 263 { 0, 0 } 264}; 265 266static driver_t bcm_systimer_driver = { 267 "systimer", 268 bcm_systimer_methods, 269 sizeof(struct bcm_systimer_softc), 270}; 271 272static devclass_t bcm_systimer_devclass; 273 274DRIVER_MODULE(bcm_systimer, simplebus, bcm_systimer_driver, bcm_systimer_devclass, 0, 0); 275 276void 277cpu_initclocks(void) 278{ 279 cpu_initclocks_bsp(); 280} 281 282void 283DELAY(int usec) 284{ 285 int32_t counts; 286 uint32_t first, last; 287 288 if (bcm_systimer_sc == NULL) { 289 for (; usec > 0; usec--) 290 for (counts = 200; counts > 0; counts--) 291 /* Prevent gcc from optimizing out the loop */ 292 cpufunc_nullop(); 293 return; 294 } 295 296 /* Get the number of times to count */ 297 counts = usec * ((bcm_systimer_tc.tc_frequency / 1000000) + 1); 298 299 first = bcm_systimer_tc_read_4(SYSTIMER_CLO); 300 301 while (counts > 0) { 302 last = bcm_systimer_tc_read_4(SYSTIMER_CLO); 303 if (last == first) 304 continue; 305 if (last>first) { 306 counts -= (int32_t)(last - first); 307 } else { 308 counts -= (int32_t)((0xFFFFFFFF - first) + last); 309 } 310 first = last; 311 } 312}
| 242 sc->st[DEFAULT_TIMER].et.et_start = bcm_systimer_start; 243 sc->st[DEFAULT_TIMER].et.et_stop = bcm_systimer_stop; 244 sc->st[DEFAULT_TIMER].et.et_priv = &sc->st[DEFAULT_TIMER]; 245 et_register(&sc->st[DEFAULT_TIMER].et); 246 247 bcm_systimer_sc = sc; 248 249 bcm_systimer_tc.tc_frequency = DEFAULT_FREQUENCY; 250 tc_init(&bcm_systimer_tc); 251 252 return (0); 253} 254 255static device_method_t bcm_systimer_methods[] = { 256 DEVMETHOD(device_probe, bcm_systimer_probe), 257 DEVMETHOD(device_attach, bcm_systimer_attach), 258 { 0, 0 } 259}; 260 261static driver_t bcm_systimer_driver = { 262 "systimer", 263 bcm_systimer_methods, 264 sizeof(struct bcm_systimer_softc), 265}; 266 267static devclass_t bcm_systimer_devclass; 268 269DRIVER_MODULE(bcm_systimer, simplebus, bcm_systimer_driver, bcm_systimer_devclass, 0, 0); 270 271void 272cpu_initclocks(void) 273{ 274 cpu_initclocks_bsp(); 275} 276 277void 278DELAY(int usec) 279{ 280 int32_t counts; 281 uint32_t first, last; 282 283 if (bcm_systimer_sc == NULL) { 284 for (; usec > 0; usec--) 285 for (counts = 200; counts > 0; counts--) 286 /* Prevent gcc from optimizing out the loop */ 287 cpufunc_nullop(); 288 return; 289 } 290 291 /* Get the number of times to count */ 292 counts = usec * ((bcm_systimer_tc.tc_frequency / 1000000) + 1); 293 294 first = bcm_systimer_tc_read_4(SYSTIMER_CLO); 295 296 while (counts > 0) { 297 last = bcm_systimer_tc_read_4(SYSTIMER_CLO); 298 if (last == first) 299 continue; 300 if (last>first) { 301 counts -= (int32_t)(last - first); 302 } else { 303 counts -= (int32_t)((0xFFFFFFFF - first) + last); 304 } 305 first = last; 306 } 307}
|