mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jun 03 09:00:09 2015 +0100
Revision:
558:0880f51c4036
Child:
576:99a3d3d9c43f
Synchronized with git revision 927c31ab8457cfef0ee8a8316117b7a41fd79133

Full URL: https://github.com/mbedmicro/mbed/commit/927c31ab8457cfef0ee8a8316117b7a41fd79133/

Add WIZwiki-W7500

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 // 32-bit timer selection
mbed_official 558:0880f51c4036 37 #define TIM_MST7 PWM_CH7
mbed_official 558:0880f51c4036 38 #define TIM_MST6 PWM_CH6
mbed_official 558:0880f51c4036 39 #define IRQn_PWM6 PWM6_IRQn
mbed_official 558:0880f51c4036 40
mbed_official 558:0880f51c4036 41 static PWM_TimerModeInitTypeDef TimMasterHandle_CH7;
mbed_official 558:0880f51c4036 42 static PWM_TimerModeInitTypeDef TimMasterHandle_CH6;
mbed_official 558:0880f51c4036 43
mbed_official 558:0880f51c4036 44 static int us_ticker_inited = 0;
mbed_official 558:0880f51c4036 45
mbed_official 558:0880f51c4036 46
mbed_official 558:0880f51c4036 47 #ifdef __cplusplus
mbed_official 558:0880f51c4036 48 extern "C"{
mbed_official 558:0880f51c4036 49 #endif
mbed_official 558:0880f51c4036 50 void PWM6_Handler(void)
mbed_official 558:0880f51c4036 51 {
mbed_official 558:0880f51c4036 52 uint32_t IntFlag = 0;
mbed_official 558:0880f51c4036 53
mbed_official 558:0880f51c4036 54 IntFlag = PWM_CHn_GetIntFlagStatus(TIM_MST6);
mbed_official 558:0880f51c4036 55
mbed_official 558:0880f51c4036 56 /* If overflow interrupt is occurred */
mbed_official 558:0880f51c4036 57 if( (IntFlag & PWM_CHn_IER_OI_Msk) != 0 )
mbed_official 558:0880f51c4036 58 {
mbed_official 558:0880f51c4036 59 /* Clear overflow interrupt */
mbed_official 558:0880f51c4036 60 PWM_CH6_ClearOverflowInt();
mbed_official 558:0880f51c4036 61 us_ticker_irq_handler();
mbed_official 558:0880f51c4036 62 }
mbed_official 558:0880f51c4036 63 }
mbed_official 558:0880f51c4036 64
mbed_official 558:0880f51c4036 65 #ifdef __cplusplus
mbed_official 558:0880f51c4036 66 }
mbed_official 558:0880f51c4036 67 #endif
mbed_official 558:0880f51c4036 68
mbed_official 558:0880f51c4036 69 void us_ticker_init(void)
mbed_official 558:0880f51c4036 70 {
mbed_official 558:0880f51c4036 71 if (us_ticker_inited) return;
mbed_official 558:0880f51c4036 72 us_ticker_inited = 1;
mbed_official 558:0880f51c4036 73
mbed_official 558:0880f51c4036 74 SystemCoreClockUpdate();
mbed_official 558:0880f51c4036 75 TimMasterHandle_CH7.PWM_CHn_PR = (GetSystemClock() / 1000000) -1;
mbed_official 558:0880f51c4036 76 TimMasterHandle_CH7.PWM_CHn_LR = 0xFFFFFFFF;
mbed_official 558:0880f51c4036 77 TimMasterHandle_CH7.PWM_CHn_PDMR = 1;
mbed_official 558:0880f51c4036 78
mbed_official 558:0880f51c4036 79 PWM_TimerModeInit(TIM_MST7, &TimMasterHandle_CH7);
mbed_official 558:0880f51c4036 80 PWM_CHn_Start(TIM_MST7);
mbed_official 558:0880f51c4036 81 }
mbed_official 558:0880f51c4036 82
mbed_official 558:0880f51c4036 83
mbed_official 558:0880f51c4036 84 uint32_t us_ticker_read()
mbed_official 558:0880f51c4036 85 {
mbed_official 558:0880f51c4036 86 if (!us_ticker_inited) us_ticker_init();
mbed_official 558:0880f51c4036 87
mbed_official 558:0880f51c4036 88 return (TIM_MST7->TCR);
mbed_official 558:0880f51c4036 89 }
mbed_official 558:0880f51c4036 90
mbed_official 558:0880f51c4036 91
mbed_official 558:0880f51c4036 92 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 558:0880f51c4036 93 {
mbed_official 558:0880f51c4036 94 int32_t dev = 0;
mbed_official 558:0880f51c4036 95 if (!us_ticker_inited)
mbed_official 558:0880f51c4036 96 {
mbed_official 558:0880f51c4036 97 us_ticker_init();
mbed_official 558:0880f51c4036 98 }
mbed_official 558:0880f51c4036 99
mbed_official 558:0880f51c4036 100 dev = (int32_t)(timestamp - (us_ticker_read() + 150));
mbed_official 558:0880f51c4036 101
mbed_official 558:0880f51c4036 102 if(dev <= 0)
mbed_official 558:0880f51c4036 103 {
mbed_official 558:0880f51c4036 104 us_ticker_irq_handler();
mbed_official 558:0880f51c4036 105 return;
mbed_official 558:0880f51c4036 106 }
mbed_official 558:0880f51c4036 107
mbed_official 558:0880f51c4036 108 PWM_CHn_Stop(TIM_MST6);
mbed_official 558:0880f51c4036 109
mbed_official 558:0880f51c4036 110 SystemCoreClockUpdate();
mbed_official 558:0880f51c4036 111 TimMasterHandle_CH6.PWM_CHn_PR = (GetSystemClock() / 1000000) -1;
mbed_official 558:0880f51c4036 112 TimMasterHandle_CH6.PWM_CHn_LR = dev;
mbed_official 558:0880f51c4036 113
mbed_official 558:0880f51c4036 114 TimMasterHandle_CH6.PWM_CHn_UDMR = 0;
mbed_official 558:0880f51c4036 115 TimMasterHandle_CH6.PWM_CHn_PDMR = 0;
mbed_official 558:0880f51c4036 116
mbed_official 558:0880f51c4036 117 NVIC_EnableIRQ(IRQn_PWM6);
mbed_official 558:0880f51c4036 118
mbed_official 558:0880f51c4036 119 PWM_CHn_IntConfig(TIM_MST6, PWM_CHn_IER_OIE, ENABLE);
mbed_official 558:0880f51c4036 120 PWM_IntConfig(TIM_MST6, ENABLE);
mbed_official 558:0880f51c4036 121 PWM_TimerModeInit(TIM_MST6, &TimMasterHandle_CH6);
mbed_official 558:0880f51c4036 122
mbed_official 558:0880f51c4036 123 PWM_CHn_Start(TIM_MST6);
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 558:0880f51c4036 128 NVIC_DisableIRQ(IRQn_PWM6);
mbed_official 558:0880f51c4036 129
mbed_official 558:0880f51c4036 130 PWM_CHn_IntConfig(TIM_MST6, PWM_CHn_IER_OIE, DISABLE);
mbed_official 558:0880f51c4036 131 PWM_IntConfig(TIM_MST6, DISABLE);
mbed_official 558:0880f51c4036 132 }
mbed_official 558:0880f51c4036 133
mbed_official 558:0880f51c4036 134 void us_ticker_clear_interrupt(void)
mbed_official 558:0880f51c4036 135 {
mbed_official 558:0880f51c4036 136 PWM_CHn_ClearInt(TIM_MST6, PWM_CHn_IER_OIE);
mbed_official 558:0880f51c4036 137 }