mbed library sources

Dependents:   Freedman_v2 Nucleo_i2c_OLED_BME280_copy

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Jun 30 09:45:08 2015 +0100
Revision:
576:99a3d3d9c43f
Parent:
558:0880f51c4036
Child:
597:47bdd20c4d41
Synchronized with git revision 1c13bc80fedd0fdfaedfab5c33183dc2b6f9b1bb

Full URL: https://github.com/mbedmicro/mbed/commit/1c13bc80fedd0fdfaedfab5c33183dc2b6f9b1bb/

Wiznet - Update and bug fix.

Who changed what in which revision?

UserRevisionLine numberNew 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 558:0880f51c4036 36
mbed_official 576:99a3d3d9c43f 37 static PWM_TimerModeInitTypeDef TimMasterHandle_CH3;
mbed_official 576:99a3d3d9c43f 38 static PWM_TimerModeInitTypeDef TimMasterHandle_CH2;
mbed_official 558:0880f51c4036 39
mbed_official 558:0880f51c4036 40 static int us_ticker_inited = 0;
mbed_official 558:0880f51c4036 41
mbed_official 558:0880f51c4036 42
mbed_official 558:0880f51c4036 43 #ifdef __cplusplus
mbed_official 558:0880f51c4036 44 extern "C"{
mbed_official 558:0880f51c4036 45 #endif
mbed_official 576:99a3d3d9c43f 46 void PWM2_Handler(void)
mbed_official 558:0880f51c4036 47 {
mbed_official 558:0880f51c4036 48 uint32_t IntFlag = 0;
mbed_official 558:0880f51c4036 49
mbed_official 576:99a3d3d9c43f 50 IntFlag = PWM_CHn_GetIntFlagStatus(PWM_CH2);
mbed_official 558:0880f51c4036 51
mbed_official 558:0880f51c4036 52 /* If overflow interrupt is occurred */
mbed_official 558:0880f51c4036 53 if( (IntFlag & PWM_CHn_IER_OI_Msk) != 0 )
mbed_official 558:0880f51c4036 54 {
mbed_official 558:0880f51c4036 55 /* Clear overflow interrupt */
mbed_official 576:99a3d3d9c43f 56 PWM_CH2_ClearOverflowInt();
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 576:99a3d3d9c43f 71 TimMasterHandle_CH3.PWM_CHn_PR = (GetSystemClock() / 1000000) -1;
mbed_official 576:99a3d3d9c43f 72 TimMasterHandle_CH3.PWM_CHn_LR = 0xFFFFFFFF;
mbed_official 576:99a3d3d9c43f 73 TimMasterHandle_CH3.PWM_CHn_PDMR = 1;
mbed_official 558:0880f51c4036 74
mbed_official 576:99a3d3d9c43f 75 PWM_TimerModeInit(PWM_CH3, &TimMasterHandle_CH3);
mbed_official 576:99a3d3d9c43f 76 PWM_CHn_Start(PWM_CH3);
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 558:0880f51c4036 83
mbed_official 576:99a3d3d9c43f 84 return (PWM_CH3->TCR);
mbed_official 558:0880f51c4036 85 }
mbed_official 558:0880f51c4036 86
mbed_official 558:0880f51c4036 87
mbed_official 558:0880f51c4036 88 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 558:0880f51c4036 89 {
mbed_official 558:0880f51c4036 90 int32_t dev = 0;
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 558:0880f51c4036 96 dev = (int32_t)(timestamp - (us_ticker_read() + 150));
mbed_official 558:0880f51c4036 97
mbed_official 558:0880f51c4036 98 if(dev <= 0)
mbed_official 558:0880f51c4036 99 {
mbed_official 558:0880f51c4036 100 us_ticker_irq_handler();
mbed_official 558:0880f51c4036 101 return;
mbed_official 558:0880f51c4036 102 }
mbed_official 558:0880f51c4036 103
mbed_official 576:99a3d3d9c43f 104 PWM_CHn_Stop(PWM_CH2);
mbed_official 558:0880f51c4036 105
mbed_official 558:0880f51c4036 106 SystemCoreClockUpdate();
mbed_official 576:99a3d3d9c43f 107 TimMasterHandle_CH2.PWM_CHn_PR = (GetSystemClock() / 1000000) -1;
mbed_official 576:99a3d3d9c43f 108 TimMasterHandle_CH2.PWM_CHn_LR = dev;
mbed_official 558:0880f51c4036 109
mbed_official 576:99a3d3d9c43f 110 TimMasterHandle_CH2.PWM_CHn_UDMR = 0;
mbed_official 576:99a3d3d9c43f 111 TimMasterHandle_CH2.PWM_CHn_PDMR = 0;
mbed_official 558:0880f51c4036 112
mbed_official 576:99a3d3d9c43f 113 NVIC_EnableIRQ(PWM2_IRQn);
mbed_official 558:0880f51c4036 114
mbed_official 576:99a3d3d9c43f 115 PWM_CHn_IntConfig(PWM_CH2, PWM_CHn_IER_OIE, ENABLE);
mbed_official 576:99a3d3d9c43f 116 PWM_IntConfig(PWM_CH2, ENABLE);
mbed_official 576:99a3d3d9c43f 117 PWM_TimerModeInit(PWM_CH2, &TimMasterHandle_CH2);
mbed_official 558:0880f51c4036 118
mbed_official 576:99a3d3d9c43f 119 PWM_CHn_Start(PWM_CH2);
mbed_official 558:0880f51c4036 120 }
mbed_official 558:0880f51c4036 121
mbed_official 558:0880f51c4036 122 void us_ticker_disable_interrupt(void)
mbed_official 558:0880f51c4036 123 {
mbed_official 576:99a3d3d9c43f 124 NVIC_DisableIRQ(PWM2_IRQn);
mbed_official 558:0880f51c4036 125
mbed_official 576:99a3d3d9c43f 126 PWM_CHn_IntConfig(PWM_CH2, PWM_CHn_IER_OIE, DISABLE);
mbed_official 576:99a3d3d9c43f 127 PWM_IntConfig(PWM_CH2, DISABLE);
mbed_official 558:0880f51c4036 128 }
mbed_official 558:0880f51c4036 129
mbed_official 558:0880f51c4036 130 void us_ticker_clear_interrupt(void)
mbed_official 558:0880f51c4036 131 {
mbed_official 576:99a3d3d9c43f 132 PWM_CHn_ClearInt(PWM_CH2, PWM_CHn_IER_OIE);
mbed_official 558:0880f51c4036 133 }