Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /*
switches 0:5c4d7b2438d3 2 * Copyright (c) 2016 ARM Limited, All Rights Reserved
switches 0:5c4d7b2438d3 3 */
switches 0:5c4d7b2438d3 4
switches 0:5c4d7b2438d3 5 // Include before mbed.h to properly get UINT*_C()
switches 0:5c4d7b2438d3 6 #include "ns_types.h"
switches 0:5c4d7b2438d3 7
switches 0:5c4d7b2438d3 8 #include "cmsis_os.h"
switches 0:5c4d7b2438d3 9 #include "mbed.h"
switches 0:5c4d7b2438d3 10
switches 0:5c4d7b2438d3 11 #include "platform/arm_hal_timer.h"
switches 0:5c4d7b2438d3 12 #include "platform/arm_hal_interrupt.h"
switches 0:5c4d7b2438d3 13
switches 0:5c4d7b2438d3 14 static osThreadId timer_thread_id;
switches 0:5c4d7b2438d3 15
switches 0:5c4d7b2438d3 16 static Timer timer;
switches 0:5c4d7b2438d3 17 static Timeout timeout;
switches 0:5c4d7b2438d3 18 static uint32_t due;
switches 0:5c4d7b2438d3 19 static void (*arm_hal_callback)(void);
switches 0:5c4d7b2438d3 20
switches 0:5c4d7b2438d3 21 static void timer_thread(const void *)
switches 0:5c4d7b2438d3 22 {
switches 0:5c4d7b2438d3 23 for (;;) {
switches 0:5c4d7b2438d3 24 osSignalWait(1, osWaitForever);
switches 0:5c4d7b2438d3 25 // !!! We don't do our own enter/exit critical - we rely on callback
switches 0:5c4d7b2438d3 26 // doing it (ns_timer_interrupt_handler does)
switches 0:5c4d7b2438d3 27 //platform_enter_critical();
switches 0:5c4d7b2438d3 28 arm_hal_callback();
switches 0:5c4d7b2438d3 29 //platform_exit_critical();
switches 0:5c4d7b2438d3 30 }
switches 0:5c4d7b2438d3 31 }
switches 0:5c4d7b2438d3 32
switches 0:5c4d7b2438d3 33 // Called once at boot
switches 0:5c4d7b2438d3 34 void platform_timer_enable(void)
switches 0:5c4d7b2438d3 35 {
switches 0:5c4d7b2438d3 36 static osThreadDef(timer_thread, osPriorityRealtime, /*1,*/ 2*1024);
switches 0:5c4d7b2438d3 37 timer_thread_id = osThreadCreate(osThread(timer_thread), NULL);
switches 0:5c4d7b2438d3 38 timer.start();
switches 0:5c4d7b2438d3 39 }
switches 0:5c4d7b2438d3 40
switches 0:5c4d7b2438d3 41 // Actually cancels a timer, not the opposite of enable
switches 0:5c4d7b2438d3 42 void platform_timer_disable(void)
switches 0:5c4d7b2438d3 43 {
switches 0:5c4d7b2438d3 44 timeout.detach();
switches 0:5c4d7b2438d3 45 }
switches 0:5c4d7b2438d3 46
switches 0:5c4d7b2438d3 47 // Not called while running, fortunately
switches 0:5c4d7b2438d3 48 void platform_timer_set_cb(void (*new_fp)(void))
switches 0:5c4d7b2438d3 49 {
switches 0:5c4d7b2438d3 50 arm_hal_callback = new_fp;
switches 0:5c4d7b2438d3 51 }
switches 0:5c4d7b2438d3 52
switches 0:5c4d7b2438d3 53 static void timer_callback(void)
switches 0:5c4d7b2438d3 54 {
switches 0:5c4d7b2438d3 55 due = 0;
switches 0:5c4d7b2438d3 56 osSignalSet(timer_thread_id, 1);
switches 0:5c4d7b2438d3 57 //callback();
switches 0:5c4d7b2438d3 58 }
switches 0:5c4d7b2438d3 59
switches 0:5c4d7b2438d3 60 // This is called from inside platform_enter_critical - IRQs can't happen
switches 0:5c4d7b2438d3 61 void platform_timer_start(uint16_t slots)
switches 0:5c4d7b2438d3 62 {
switches 0:5c4d7b2438d3 63 timer.reset();
switches 0:5c4d7b2438d3 64 due = slots * UINT32_C(50);
switches 0:5c4d7b2438d3 65 timeout.attach_us(timer_callback, due);
switches 0:5c4d7b2438d3 66 }
switches 0:5c4d7b2438d3 67
switches 0:5c4d7b2438d3 68 // This is called from inside platform_enter_critical - IRQs can't happen
switches 0:5c4d7b2438d3 69 uint16_t platform_timer_get_remaining_slots(void)
switches 0:5c4d7b2438d3 70 {
switches 0:5c4d7b2438d3 71 uint32_t elapsed = timer.read_us();
switches 0:5c4d7b2438d3 72 if (elapsed < due) {
switches 0:5c4d7b2438d3 73 return (uint16_t) ((due - elapsed) / 50);
switches 0:5c4d7b2438d3 74 } else {
switches 0:5c4d7b2438d3 75 return 0;
switches 0:5c4d7b2438d3 76 }
switches 0:5c4d7b2438d3 77 }
switches 0:5c4d7b2438d3 78