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@619:034e698bc035, 2015-09-04 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Sep 04 09:30:10 2015 +0100
- Revision:
- 619:034e698bc035
- Parent:
- 597:47bdd20c4d41
Synchronized with git revision 92d1bfad30082571776c810a56fd471d30514ccf
Full URL: https://github.com/mbedmicro/mbed/commit/92d1bfad30082571776c810a56fd471d30514ccf/
Change directory structure and move files.
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 | 619:034e698bc035 | 35 | #include "W7500x_dualtimer.h" |
mbed_official | 619:034e698bc035 | 36 | #include "W7500x_pwm.h" |
mbed_official | 558:0880f51c4036 | 37 | |
mbed_official | 597:47bdd20c4d41 | 38 | #define TIMER_0 DUALTIMER0_0 |
mbed_official | 597:47bdd20c4d41 | 39 | #define TIMER_1 PWM_CH1 |
mbed_official | 597:47bdd20c4d41 | 40 | #define TIMER_IRQn DUALTIMER0_IRQn |
mbed_official | 558:0880f51c4036 | 41 | |
mbed_official | 597:47bdd20c4d41 | 42 | static PWM_TimerModeInitTypeDef TimerInitType; |
mbed_official | 597:47bdd20c4d41 | 43 | static DUALTIMER_InitTypDef TimerHandler; |
mbed_official | 558:0880f51c4036 | 44 | |
mbed_official | 558:0880f51c4036 | 45 | static int us_ticker_inited = 0; |
mbed_official | 558:0880f51c4036 | 46 | |
mbed_official | 558:0880f51c4036 | 47 | |
mbed_official | 558:0880f51c4036 | 48 | #ifdef __cplusplus |
mbed_official | 558:0880f51c4036 | 49 | extern "C"{ |
mbed_official | 558:0880f51c4036 | 50 | #endif |
mbed_official | 597:47bdd20c4d41 | 51 | |
mbed_official | 597:47bdd20c4d41 | 52 | void DUALTIMER0_Handler(void) |
mbed_official | 558:0880f51c4036 | 53 | { |
mbed_official | 597:47bdd20c4d41 | 54 | if(DUALTIMER_GetIntStatus(DUALTIMER0_0)) |
mbed_official | 558:0880f51c4036 | 55 | { |
mbed_official | 597:47bdd20c4d41 | 56 | DUALTIMER_IntClear(DUALTIMER0_0); |
mbed_official | 558:0880f51c4036 | 57 | us_ticker_irq_handler(); |
mbed_official | 558:0880f51c4036 | 58 | } |
mbed_official | 558:0880f51c4036 | 59 | } |
mbed_official | 558:0880f51c4036 | 60 | |
mbed_official | 558:0880f51c4036 | 61 | #ifdef __cplusplus |
mbed_official | 558:0880f51c4036 | 62 | } |
mbed_official | 558:0880f51c4036 | 63 | #endif |
mbed_official | 558:0880f51c4036 | 64 | |
mbed_official | 558:0880f51c4036 | 65 | void us_ticker_init(void) |
mbed_official | 558:0880f51c4036 | 66 | { |
mbed_official | 558:0880f51c4036 | 67 | if (us_ticker_inited) return; |
mbed_official | 558:0880f51c4036 | 68 | us_ticker_inited = 1; |
mbed_official | 558:0880f51c4036 | 69 | |
mbed_official | 558:0880f51c4036 | 70 | SystemCoreClockUpdate(); |
mbed_official | 597:47bdd20c4d41 | 71 | TimerInitType.PWM_CHn_PR = (GetSystemClock() / 1000000) -1; |
mbed_official | 597:47bdd20c4d41 | 72 | TimerInitType.PWM_CHn_LR = 0xFFFFFFFF; |
mbed_official | 597:47bdd20c4d41 | 73 | TimerInitType.PWM_CHn_PDMR = 1; |
mbed_official | 558:0880f51c4036 | 74 | |
mbed_official | 597:47bdd20c4d41 | 75 | PWM_TimerModeInit(TIMER_1, &TimerInitType); |
mbed_official | 597:47bdd20c4d41 | 76 | PWM_CHn_Start(TIMER_1); |
mbed_official | 558:0880f51c4036 | 77 | } |
mbed_official | 558:0880f51c4036 | 78 | |
mbed_official | 558:0880f51c4036 | 79 | |
mbed_official | 558:0880f51c4036 | 80 | uint32_t us_ticker_read() |
mbed_official | 558:0880f51c4036 | 81 | { |
mbed_official | 558:0880f51c4036 | 82 | if (!us_ticker_inited) us_ticker_init(); |
mbed_official | 597:47bdd20c4d41 | 83 | return (TIMER_1->TCR); |
mbed_official | 558:0880f51c4036 | 84 | } |
mbed_official | 558:0880f51c4036 | 85 | |
mbed_official | 558:0880f51c4036 | 86 | |
mbed_official | 558:0880f51c4036 | 87 | void us_ticker_set_interrupt(timestamp_t timestamp) |
mbed_official | 558:0880f51c4036 | 88 | { |
mbed_official | 558:0880f51c4036 | 89 | int32_t dev = 0; |
mbed_official | 597:47bdd20c4d41 | 90 | |
mbed_official | 558:0880f51c4036 | 91 | if (!us_ticker_inited) |
mbed_official | 558:0880f51c4036 | 92 | { |
mbed_official | 558:0880f51c4036 | 93 | us_ticker_init(); |
mbed_official | 558:0880f51c4036 | 94 | } |
mbed_official | 558:0880f51c4036 | 95 | |
mbed_official | 597:47bdd20c4d41 | 96 | dev = (int32_t)(timestamp - us_ticker_read()); |
mbed_official | 597:47bdd20c4d41 | 97 | dev = dev * ((GetSystemClock() / 1000000) / 16); |
mbed_official | 558:0880f51c4036 | 98 | |
mbed_official | 558:0880f51c4036 | 99 | if(dev <= 0) |
mbed_official | 558:0880f51c4036 | 100 | { |
mbed_official | 558:0880f51c4036 | 101 | us_ticker_irq_handler(); |
mbed_official | 597:47bdd20c4d41 | 102 | return; |
mbed_official | 558:0880f51c4036 | 103 | } |
mbed_official | 597:47bdd20c4d41 | 104 | |
mbed_official | 597:47bdd20c4d41 | 105 | DUALTIMER_ClockEnable(TIMER_0); |
mbed_official | 597:47bdd20c4d41 | 106 | DUALTIMER_Stop(TIMER_0); |
mbed_official | 597:47bdd20c4d41 | 107 | |
mbed_official | 597:47bdd20c4d41 | 108 | TimerHandler.TimerControl_Mode = DUALTIMER_TimerControl_Periodic; |
mbed_official | 597:47bdd20c4d41 | 109 | TimerHandler.TimerControl_OneShot = DUALTIMER_TimerControl_OneShot; |
mbed_official | 597:47bdd20c4d41 | 110 | TimerHandler.TimerControl_Pre = DUALTIMER_TimerControl_Pre_16; |
mbed_official | 597:47bdd20c4d41 | 111 | TimerHandler.TimerControl_Size = DUALTIMER_TimerControl_Size_32; |
mbed_official | 597:47bdd20c4d41 | 112 | |
mbed_official | 597:47bdd20c4d41 | 113 | TimerHandler.TimerLoad = (uint32_t)dev; |
mbed_official | 597:47bdd20c4d41 | 114 | |
mbed_official | 597:47bdd20c4d41 | 115 | DUALTIMER_Init(TIMER_0, &TimerHandler); |
mbed_official | 597:47bdd20c4d41 | 116 | |
mbed_official | 597:47bdd20c4d41 | 117 | DUALTIMER_IntConfig(TIMER_0, ENABLE); |
mbed_official | 597:47bdd20c4d41 | 118 | |
mbed_official | 597:47bdd20c4d41 | 119 | NVIC_EnableIRQ(TIMER_IRQn); |
mbed_official | 597:47bdd20c4d41 | 120 | |
mbed_official | 597:47bdd20c4d41 | 121 | DUALTIMER_Start(TIMER_0); |
mbed_official | 597:47bdd20c4d41 | 122 | |
mbed_official | 558:0880f51c4036 | 123 | |
mbed_official | 558:0880f51c4036 | 124 | } |
mbed_official | 558:0880f51c4036 | 125 | |
mbed_official | 558:0880f51c4036 | 126 | void us_ticker_disable_interrupt(void) |
mbed_official | 558:0880f51c4036 | 127 | { |
mbed_official | 597:47bdd20c4d41 | 128 | NVIC_DisableIRQ(TIMER_IRQn); |
mbed_official | 597:47bdd20c4d41 | 129 | |
mbed_official | 597:47bdd20c4d41 | 130 | DUALTIMER_IntConfig(TIMER_0, DISABLE); |
mbed_official | 558:0880f51c4036 | 131 | } |
mbed_official | 558:0880f51c4036 | 132 | |
mbed_official | 558:0880f51c4036 | 133 | void us_ticker_clear_interrupt(void) |
mbed_official | 558:0880f51c4036 | 134 | { |
mbed_official | 597:47bdd20c4d41 | 135 | DUALTIMER_IntClear(TIMER_0); |
mbed_official | 558:0880f51c4036 | 136 | } |