mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32620C/us_ticker.c@188:3f10722804f9, 2018-07-30 (annotated)
- Committer:
- ua1arn
- Date:
- Mon Jul 30 12:31:10 2018 +0000
- Revision:
- 188:3f10722804f9
- Parent:
- 186:707f6e361f3e
before add multi-configuration USB descriptors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
186:707f6e361f3e | 1 | /******************************************************************************* |
Anna Bridge |
186:707f6e361f3e | 2 | * Copyright (c) 2016,2018 Maxim Integrated Products, Inc., All Rights Reserved. |
Anna Bridge |
186:707f6e361f3e | 3 | * |
Anna Bridge |
186:707f6e361f3e | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
Anna Bridge |
186:707f6e361f3e | 5 | * copy of this software and associated documentation files (the "Software"), |
Anna Bridge |
186:707f6e361f3e | 6 | * to deal in the Software without restriction, including without limitation |
Anna Bridge |
186:707f6e361f3e | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Anna Bridge |
186:707f6e361f3e | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
Anna Bridge |
186:707f6e361f3e | 9 | * Software is furnished to do so, subject to the following conditions: |
Anna Bridge |
186:707f6e361f3e | 10 | * |
Anna Bridge |
186:707f6e361f3e | 11 | * The above copyright notice and this permission notice shall be included |
Anna Bridge |
186:707f6e361f3e | 12 | * in all copies or substantial portions of the Software. |
Anna Bridge |
186:707f6e361f3e | 13 | * |
Anna Bridge |
186:707f6e361f3e | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Anna Bridge |
186:707f6e361f3e | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Anna Bridge |
186:707f6e361f3e | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Anna Bridge |
186:707f6e361f3e | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Anna Bridge |
186:707f6e361f3e | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Anna Bridge |
186:707f6e361f3e | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Anna Bridge |
186:707f6e361f3e | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
Anna Bridge |
186:707f6e361f3e | 21 | * |
Anna Bridge |
186:707f6e361f3e | 22 | * Except as contained in this notice, the name of Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 24 | * Products, Inc. Branding Policy. |
Anna Bridge |
186:707f6e361f3e | 25 | * |
Anna Bridge |
186:707f6e361f3e | 26 | * The mere transfer of this software does not imply any licenses |
Anna Bridge |
186:707f6e361f3e | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
Anna Bridge |
186:707f6e361f3e | 28 | * trademarks, maskwork rights, or any other form of intellectual |
Anna Bridge |
186:707f6e361f3e | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Anna Bridge |
186:707f6e361f3e | 30 | * ownership rights. |
Anna Bridge |
186:707f6e361f3e | 31 | ******************************************************************************* |
Anna Bridge |
186:707f6e361f3e | 32 | */ |
Anna Bridge |
186:707f6e361f3e | 33 | |
Anna Bridge |
186:707f6e361f3e | 34 | #include <stddef.h> |
Anna Bridge |
186:707f6e361f3e | 35 | #include "us_ticker_api.h" |
Anna Bridge |
186:707f6e361f3e | 36 | #include "tmr.h" |
Anna Bridge |
186:707f6e361f3e | 37 | |
Anna Bridge |
186:707f6e361f3e | 38 | #define US_TIMER MXC_TMR0 |
Anna Bridge |
186:707f6e361f3e | 39 | #define US_TIMER_IRQn TMR0_0_IRQn |
Anna Bridge |
186:707f6e361f3e | 40 | #define US_TIMER_PRESCALE TMR_PRESCALE_DIV_2_5 |
Anna Bridge |
186:707f6e361f3e | 41 | #define US_TIMER_MODE TMR32_MODE_COMPARE |
Anna Bridge |
186:707f6e361f3e | 42 | #define US_TIMER_WIDTH 32 |
Anna Bridge |
186:707f6e361f3e | 43 | |
Anna Bridge |
186:707f6e361f3e | 44 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 45 | void us_ticker_init(void) |
Anna Bridge |
186:707f6e361f3e | 46 | { |
Anna Bridge |
186:707f6e361f3e | 47 | // Disable and deconfigure |
Anna Bridge |
186:707f6e361f3e | 48 | US_TIMER->ctrl = 0; |
Anna Bridge |
186:707f6e361f3e | 49 | US_TIMER->term_cnt32 = 0; |
Anna Bridge |
186:707f6e361f3e | 50 | US_TIMER->inten = 0; |
Anna Bridge |
186:707f6e361f3e | 51 | US_TIMER->intfl = MXC_F_TMR_INTFL_TIMER0; |
Anna Bridge |
186:707f6e361f3e | 52 | |
Anna Bridge |
186:707f6e361f3e | 53 | // Configure and enable |
Anna Bridge |
186:707f6e361f3e | 54 | US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 | |
Anna Bridge |
186:707f6e361f3e | 55 | (US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) | |
Anna Bridge |
186:707f6e361f3e | 56 | (US_TIMER_PRESCALE << MXC_F_TMR_CTRL_PRESCALE_POS); |
Anna Bridge |
186:707f6e361f3e | 57 | |
Anna Bridge |
186:707f6e361f3e | 58 | NVIC_SetVector(US_TIMER_IRQn, (uint32_t)us_ticker_irq_handler); |
Anna Bridge |
186:707f6e361f3e | 59 | NVIC_EnableIRQ(US_TIMER_IRQn); |
Anna Bridge |
186:707f6e361f3e | 60 | } |
Anna Bridge |
186:707f6e361f3e | 61 | |
Anna Bridge |
186:707f6e361f3e | 62 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 63 | void us_ticker_free(void) |
Anna Bridge |
186:707f6e361f3e | 64 | { |
Anna Bridge |
186:707f6e361f3e | 65 | US_TIMER->ctrl = 0; |
Anna Bridge |
186:707f6e361f3e | 66 | } |
Anna Bridge |
186:707f6e361f3e | 67 | |
Anna Bridge |
186:707f6e361f3e | 68 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 69 | uint32_t us_ticker_read(void) |
Anna Bridge |
186:707f6e361f3e | 70 | { |
Anna Bridge |
186:707f6e361f3e | 71 | return US_TIMER->count32; |
Anna Bridge |
186:707f6e361f3e | 72 | } |
Anna Bridge |
186:707f6e361f3e | 73 | |
Anna Bridge |
186:707f6e361f3e | 74 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 75 | void us_ticker_set_interrupt(timestamp_t timestamp) |
Anna Bridge |
186:707f6e361f3e | 76 | { |
Anna Bridge |
186:707f6e361f3e | 77 | US_TIMER->ctrl = 0; |
Anna Bridge |
186:707f6e361f3e | 78 | US_TIMER->term_cnt32 = (timestamp) ? timestamp : 1; |
Anna Bridge |
186:707f6e361f3e | 79 | US_TIMER->inten = MXC_F_TMR_INTEN_TIMER0; |
Anna Bridge |
186:707f6e361f3e | 80 | US_TIMER->ctrl = MXC_F_TMR_CTRL_ENABLE0 | |
Anna Bridge |
186:707f6e361f3e | 81 | (US_TIMER_MODE << MXC_F_TMR_CTRL_MODE_POS) | |
Anna Bridge |
186:707f6e361f3e | 82 | (US_TIMER_PRESCALE << MXC_F_TMR_CTRL_PRESCALE_POS); |
Anna Bridge |
186:707f6e361f3e | 83 | } |
Anna Bridge |
186:707f6e361f3e | 84 | |
Anna Bridge |
186:707f6e361f3e | 85 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 86 | void us_ticker_fire_interrupt(void) |
Anna Bridge |
186:707f6e361f3e | 87 | { |
Anna Bridge |
186:707f6e361f3e | 88 | NVIC_SetPendingIRQ(US_TIMER_IRQn); |
Anna Bridge |
186:707f6e361f3e | 89 | } |
Anna Bridge |
186:707f6e361f3e | 90 | |
Anna Bridge |
186:707f6e361f3e | 91 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 92 | void us_ticker_disable_interrupt(void) |
Anna Bridge |
186:707f6e361f3e | 93 | { |
Anna Bridge |
186:707f6e361f3e | 94 | US_TIMER->inten = 0; |
Anna Bridge |
186:707f6e361f3e | 95 | } |
Anna Bridge |
186:707f6e361f3e | 96 | |
Anna Bridge |
186:707f6e361f3e | 97 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 98 | void us_ticker_clear_interrupt(void) |
Anna Bridge |
186:707f6e361f3e | 99 | { |
Anna Bridge |
186:707f6e361f3e | 100 | US_TIMER->intfl = MXC_F_TMR_INTFL_TIMER0; |
Anna Bridge |
186:707f6e361f3e | 101 | } |
Anna Bridge |
186:707f6e361f3e | 102 | |
Anna Bridge |
186:707f6e361f3e | 103 | //****************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 104 | const ticker_info_t* us_ticker_get_info(void) |
Anna Bridge |
186:707f6e361f3e | 105 | { |
Anna Bridge |
186:707f6e361f3e | 106 | static const ticker_info_t info = { |
Anna Bridge |
186:707f6e361f3e | 107 | RO_FREQ >> US_TIMER_PRESCALE, |
Anna Bridge |
186:707f6e361f3e | 108 | US_TIMER_WIDTH |
Anna Bridge |
186:707f6e361f3e | 109 | }; |
Anna Bridge |
186:707f6e361f3e | 110 | |
Anna Bridge |
186:707f6e361f3e | 111 | return &info; |
Anna Bridge |
186:707f6e361f3e | 112 | } |