Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
arm_hal_timer.cpp
00001 /* 00002 * Copyright (c) 2016 ARM Limited, All Rights Reserved 00003 */ 00004 00005 // Include before mbed.h to properly get UINT*_C() 00006 #include "ns_types.h" 00007 00008 #include "mbed.h" 00009 #include "platform/arm_hal_timer.h" 00010 #include "platform/arm_hal_interrupt.h" 00011 #include <mbed_assert.h> 00012 00013 static Timer timer; 00014 static Timeout timeout; 00015 static EventQueue *equeue; 00016 static uint32_t due; 00017 static void (*arm_hal_callback)(void); 00018 00019 // Called once at boot 00020 void platform_timer_enable(void) 00021 { 00022 equeue = mbed_highprio_event_queue(); 00023 MBED_ASSERT(equeue != NULL); 00024 } 00025 00026 // Actually cancels a timer, not the opposite of enable 00027 void platform_timer_disable(void) 00028 { 00029 timeout.detach(); 00030 } 00031 00032 // Not called while running, fortunately 00033 void platform_timer_set_cb(void (*new_fp)(void)) 00034 { 00035 arm_hal_callback = new_fp; 00036 } 00037 00038 static void timer_callback(void) 00039 { 00040 due = 0; 00041 equeue->call(arm_hal_callback); 00042 } 00043 00044 // This is called from inside platform_enter_critical - IRQs can't happen 00045 void platform_timer_start(uint16_t slots) 00046 { 00047 timer.reset(); 00048 due = slots * UINT32_C(50); 00049 timeout.attach_us(timer_callback, due); 00050 } 00051 00052 // This is called from inside platform_enter_critical - IRQs can't happen 00053 uint16_t platform_timer_get_remaining_slots(void) 00054 { 00055 uint32_t elapsed = timer.read_us(); 00056 if (elapsed < due) { 00057 return (uint16_t) ((due - elapsed) / 50); 00058 } else { 00059 return 0; 00060 } 00061 } 00062
Generated on Fri Jul 22 2022 04:53:44 by
1.7.2
