mbed library sources, include can_api for nucleo-f091rc
Dependents: CanNucleoF0_example
Fork of mbed-src by
targets/hal/TARGET_WIZNET/TARGET_W7500x/us_ticker.c@597:47bdd20c4d41, 2015-07-27 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jul 27 09:45:08 2015 +0100
- Revision:
- 597:47bdd20c4d41
- Parent:
- 576:99a3d3d9c43f
- Child:
- 619:034e698bc035
Synchronized with git revision 9b9bab51e568581a2a896967a707d3b5aeda3f17
Full URL: https://github.com/mbedmicro/mbed/commit/9b9bab51e568581a2a896967a707d3b5aeda3f17/
Change us_ticker - one dual timer + one pwm timer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 558:0880f51c4036 | 1 | /* mbed Microcontroller Library |
mbed_official | 558:0880f51c4036 | 2 | ******************************************************************************* |
mbed_official | 558:0880f51c4036 | 3 | * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved. |
mbed_official | 558:0880f51c4036 | 4 | * All rights reserved. |
mbed_official | 558:0880f51c4036 | 5 | * |
mbed_official | 558:0880f51c4036 | 6 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 558:0880f51c4036 | 7 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 558:0880f51c4036 | 8 | * |
mbed_official | 558:0880f51c4036 | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 558:0880f51c4036 | 10 | * this list of conditions and the following disclaimer. |
mbed_official | 558:0880f51c4036 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 558:0880f51c4036 | 12 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 558:0880f51c4036 | 13 | * and/or other materials provided with the distribution. |
mbed_official | 558:0880f51c4036 | 14 | * 3. Neither the name of ARM Limited nor the names of its contributors |
mbed_official | 558:0880f51c4036 | 15 | * may be used to endorse or promote products derived from this software |
mbed_official | 558:0880f51c4036 | 16 | * without specific prior written permission. |
mbed_official | 558:0880f51c4036 | 17 | * |
mbed_official | 558:0880f51c4036 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 558:0880f51c4036 | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 558:0880f51c4036 | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 558:0880f51c4036 | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 558:0880f51c4036 | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 558:0880f51c4036 | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 558:0880f51c4036 | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 558:0880f51c4036 | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 558:0880f51c4036 | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 558:0880f51c4036 | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 558:0880f51c4036 | 28 | ******************************************************************************* |
mbed_official | 558:0880f51c4036 | 29 | */ |
mbed_official | 558:0880f51c4036 | 30 | |
mbed_official | 558:0880f51c4036 | 31 | #include <stddef.h> |
mbed_official | 558:0880f51c4036 | 32 | #include "us_ticker_api.h" |
mbed_official | 558:0880f51c4036 | 33 | #include "PeripheralNames.h" |
mbed_official | 558:0880f51c4036 | 34 | #include "system_W7500x.h" |
mbed_official | 558:0880f51c4036 | 35 | |
mbed_official | 597:47bdd20c4d41 | 36 | #define TIMER_0 DUALTIMER0_0 |
mbed_official | 597:47bdd20c4d41 | 37 | #define TIMER_1 PWM_CH1 |
mbed_official | 597:47bdd20c4d41 | 38 | #define TIMER_IRQn DUALTIMER0_IRQn |
mbed_official | 558:0880f51c4036 | 39 | |
mbed_official | 597:47bdd20c4d41 | 40 | static PWM_TimerModeInitTypeDef TimerInitType; |
mbed_official | 597:47bdd20c4d41 | 41 | static DUALTIMER_InitTypDef TimerHandler; |
mbed_official | 558:0880f51c4036 | 42 | |
mbed_official | 558:0880f51c4036 | 43 | static int us_ticker_inited = 0; |
mbed_official | 558:0880f51c4036 | 44 | |
mbed_official | 558:0880f51c4036 | 45 | |
mbed_official | 558:0880f51c4036 | 46 | #ifdef __cplusplus |
mbed_official | 558:0880f51c4036 | 47 | extern "C"{ |
mbed_official | 558:0880f51c4036 | 48 | #endif |
mbed_official | 597:47bdd20c4d41 | 49 | |
mbed_official | 597:47bdd20c4d41 | 50 | void DUALTIMER0_Handler(void) |
mbed_official | 558:0880f51c4036 | 51 | { |
mbed_official | 597:47bdd20c4d41 | 52 | if(DUALTIMER_GetIntStatus(DUALTIMER0_0)) |
mbed_official | 558:0880f51c4036 | 53 | { |
mbed_official | 597:47bdd20c4d41 | 54 | DUALTIMER_IntClear(DUALTIMER0_0); |
mbed_official | 558:0880f51c4036 | 55 | us_ticker_irq_handler(); |
mbed_official | 558:0880f51c4036 | 56 | } |
mbed_official | 558:0880f51c4036 | 57 | } |
mbed_official | 558:0880f51c4036 | 58 | |
mbed_official | 558:0880f51c4036 | 59 | #ifdef __cplusplus |
mbed_official | 558:0880f51c4036 | 60 | } |
mbed_official | 558:0880f51c4036 | 61 | #endif |
mbed_official | 558:0880f51c4036 | 62 | |
mbed_official | 558:0880f51c4036 | 63 | void us_ticker_init(void) |
mbed_official | 558:0880f51c4036 | 64 | { |
mbed_official | 558:0880f51c4036 | 65 | if (us_ticker_inited) return; |
mbed_official | 558:0880f51c4036 | 66 | us_ticker_inited = 1; |
mbed_official | 558:0880f51c4036 | 67 | |
mbed_official | 558:0880f51c4036 | 68 | SystemCoreClockUpdate(); |
mbed_official | 597:47bdd20c4d41 | 69 | TimerInitType.PWM_CHn_PR = (GetSystemClock() / 1000000) -1; |
mbed_official | 597:47bdd20c4d41 | 70 | TimerInitType.PWM_CHn_LR = 0xFFFFFFFF; |
mbed_official | 597:47bdd20c4d41 | 71 | TimerInitType.PWM_CHn_PDMR = 1; |
mbed_official | 558:0880f51c4036 | 72 | |
mbed_official | 597:47bdd20c4d41 | 73 | PWM_TimerModeInit(TIMER_1, &TimerInitType); |
mbed_official | 597:47bdd20c4d41 | 74 | PWM_CHn_Start(TIMER_1); |
mbed_official | 558:0880f51c4036 | 75 | } |
mbed_official | 558:0880f51c4036 | 76 | |
mbed_official | 558:0880f51c4036 | 77 | |
mbed_official | 558:0880f51c4036 | 78 | uint32_t us_ticker_read() |
mbed_official | 558:0880f51c4036 | 79 | { |
mbed_official | 558:0880f51c4036 | 80 | if (!us_ticker_inited) us_ticker_init(); |
mbed_official | 597:47bdd20c4d41 | 81 | return (TIMER_1->TCR); |
mbed_official | 558:0880f51c4036 | 82 | } |
mbed_official | 558:0880f51c4036 | 83 | |
mbed_official | 558:0880f51c4036 | 84 | |
mbed_official | 558:0880f51c4036 | 85 | void us_ticker_set_interrupt(timestamp_t timestamp) |
mbed_official | 558:0880f51c4036 | 86 | { |
mbed_official | 558:0880f51c4036 | 87 | int32_t dev = 0; |
mbed_official | 597:47bdd20c4d41 | 88 | |
mbed_official | 558:0880f51c4036 | 89 | if (!us_ticker_inited) |
mbed_official | 558:0880f51c4036 | 90 | { |
mbed_official | 558:0880f51c4036 | 91 | us_ticker_init(); |
mbed_official | 558:0880f51c4036 | 92 | } |
mbed_official | 558:0880f51c4036 | 93 | |
mbed_official | 597:47bdd20c4d41 | 94 | dev = (int32_t)(timestamp - us_ticker_read()); |
mbed_official | 597:47bdd20c4d41 | 95 | dev = dev * ((GetSystemClock() / 1000000) / 16); |
mbed_official | 558:0880f51c4036 | 96 | |
mbed_official | 558:0880f51c4036 | 97 | if(dev <= 0) |
mbed_official | 558:0880f51c4036 | 98 | { |
mbed_official | 558:0880f51c4036 | 99 | us_ticker_irq_handler(); |
mbed_official | 597:47bdd20c4d41 | 100 | return; |
mbed_official | 558:0880f51c4036 | 101 | } |
mbed_official | 597:47bdd20c4d41 | 102 | |
mbed_official | 597:47bdd20c4d41 | 103 | DUALTIMER_ClockEnable(TIMER_0); |
mbed_official | 597:47bdd20c4d41 | 104 | DUALTIMER_Stop(TIMER_0); |
mbed_official | 597:47bdd20c4d41 | 105 | |
mbed_official | 597:47bdd20c4d41 | 106 | TimerHandler.TimerControl_Mode = DUALTIMER_TimerControl_Periodic; |
mbed_official | 597:47bdd20c4d41 | 107 | TimerHandler.TimerControl_OneShot = DUALTIMER_TimerControl_OneShot; |
mbed_official | 597:47bdd20c4d41 | 108 | TimerHandler.TimerControl_Pre = DUALTIMER_TimerControl_Pre_16; |
mbed_official | 597:47bdd20c4d41 | 109 | TimerHandler.TimerControl_Size = DUALTIMER_TimerControl_Size_32; |
mbed_official | 597:47bdd20c4d41 | 110 | |
mbed_official | 597:47bdd20c4d41 | 111 | TimerHandler.TimerLoad = (uint32_t)dev; |
mbed_official | 597:47bdd20c4d41 | 112 | |
mbed_official | 597:47bdd20c4d41 | 113 | DUALTIMER_Init(TIMER_0, &TimerHandler); |
mbed_official | 597:47bdd20c4d41 | 114 | |
mbed_official | 597:47bdd20c4d41 | 115 | DUALTIMER_IntConfig(TIMER_0, ENABLE); |
mbed_official | 597:47bdd20c4d41 | 116 | |
mbed_official | 597:47bdd20c4d41 | 117 | NVIC_EnableIRQ(TIMER_IRQn); |
mbed_official | 597:47bdd20c4d41 | 118 | |
mbed_official | 597:47bdd20c4d41 | 119 | DUALTIMER_Start(TIMER_0); |
mbed_official | 597:47bdd20c4d41 | 120 | |
mbed_official | 558:0880f51c4036 | 121 | |
mbed_official | 558:0880f51c4036 | 122 | } |
mbed_official | 558:0880f51c4036 | 123 | |
mbed_official | 558:0880f51c4036 | 124 | void us_ticker_disable_interrupt(void) |
mbed_official | 558:0880f51c4036 | 125 | { |
mbed_official | 597:47bdd20c4d41 | 126 | NVIC_DisableIRQ(TIMER_IRQn); |
mbed_official | 597:47bdd20c4d41 | 127 | |
mbed_official | 597:47bdd20c4d41 | 128 | DUALTIMER_IntConfig(TIMER_0, DISABLE); |
mbed_official | 558:0880f51c4036 | 129 | } |
mbed_official | 558:0880f51c4036 | 130 | |
mbed_official | 558:0880f51c4036 | 131 | void us_ticker_clear_interrupt(void) |
mbed_official | 558:0880f51c4036 | 132 | { |
mbed_official | 597:47bdd20c4d41 | 133 | DUALTIMER_IntClear(TIMER_0); |
mbed_official | 558:0880f51c4036 | 134 | } |