source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/targets/TARGET_RENESAS/TARGET_RZA1XX/lp_ticker.c@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property charset set to UTF-8
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 3.4 KB
Line 
1/* mbed Microcontroller Library
2 * Copyright (c) 2006-2017 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#if DEVICE_LPTICKER
17#include "lp_ticker_api.h"
18#include "mtu2_iodefine.h"
19#include "mtu2_iobitmask.h"
20#include "mbed_drv_cfg.h"
21#include "mtu2.h"
22
23#if (LP_TICKER_MTU2_CH == 2)
24 #define LP_TICKER_TIMER_IRQn (TGI2A_IRQn)
25 #define MTU2TCR (MTU2TCR_2)
26 #define MTU2TCNT (MTU2TCNT_2)
27 #define MTU2TIER (MTU2TIER_2)
28 #define MTU2TGRA (MTU2TGRA_2)
29 #define MTU2TSR (MTU2TSR_2)
30 #define MTU2_TSTR_CST MTU2_TSTR_CST2
31 #define MTU2_TCR_TPSC (0x07)
32#elif (LP_TICKER_MTU2_CH == 3)
33 #define LP_TICKER_TIMER_IRQn (TGI3A_IRQn)
34 #define MTU2TCR (MTU2TCR_3)
35 #define MTU2TCNT (MTU2TCNT_3)
36 #define MTU2TIER (MTU2TIER_3)
37 #define MTU2TGRA (MTU2TGRA_3)
38 #define MTU2TSR (MTU2TSR_3)
39 #define MTU2_TSTR_CST MTU2_TSTR_CST3
40 #define MTU2_TCR_TPSC (0x05)
41#elif (LP_TICKER_MTU2_CH == 4)
42 #define LP_TICKER_TIMER_IRQn (TGI4A_IRQn)
43 #define MTU2TCR (MTU2TCR_4)
44 #define MTU2TCNT (MTU2TCNT_4)
45 #define MTU2TIER (MTU2TIER_4)
46 #define MTU2TGRA (MTU2TGRA_4)
47 #define MTU2TSR (MTU2TSR_4)
48 #define MTU2_TSTR_CST MTU2_TSTR_CST4
49 #define MTU2_TCR_TPSC (0x05)
50#else
51 #error "Invalid number : LP_TICKER_MTU2_CH (2-4)"
52#endif
53
54static int lp_ticker_inited = 0;
55
56void lp_ticker_init(void)
57{
58 GIC_DisableIRQ(LP_TICKER_TIMER_IRQn);
59 GIC_ClearPendingIRQ(LP_TICKER_TIMER_IRQn);
60
61 /* Power Control for Peripherals */
62 mtu2_init();
63
64 if (lp_ticker_inited) return;
65 lp_ticker_inited = 1;
66
67 MTU2TCR = MTU2_TCR_TPSC;
68 MTU2TSTR |= MTU2_TSTR_CST;
69 MTU2TIER |= MTU2_TIER_n_TGIEA;
70
71 // INTC settings
72 InterruptHandlerRegister(LP_TICKER_TIMER_IRQn, (void (*)(uint32_t))lp_ticker_irq_handler);
73 GIC_SetPriority(LP_TICKER_TIMER_IRQn, 5);
74 GIC_SetConfiguration(LP_TICKER_TIMER_IRQn, 3);
75}
76
77void lp_ticker_free(void)
78{
79 GIC_DisableIRQ(LP_TICKER_TIMER_IRQn);
80 GIC_ClearPendingIRQ(LP_TICKER_TIMER_IRQn);
81
82 MTU2TIER &= ~MTU2_TIER_n_TGIEA;
83 lp_ticker_inited = 0;
84 mtu2_free();
85}
86
87uint32_t lp_ticker_read()
88{
89 return (uint32_t)MTU2TCNT;
90}
91
92void lp_ticker_set_interrupt(timestamp_t timestamp)
93{
94 MTU2TSR = (MTU2TSR & 0xFE);
95 MTU2TGRA = (uint16_t)timestamp;
96 GIC_EnableIRQ(LP_TICKER_TIMER_IRQn);
97}
98
99void lp_ticker_fire_interrupt(void)
100{
101 GIC_SetPendingIRQ(LP_TICKER_TIMER_IRQn);
102 GIC_EnableIRQ(LP_TICKER_TIMER_IRQn);
103}
104
105void lp_ticker_disable_interrupt(void)
106{
107 GIC_DisableIRQ(LP_TICKER_TIMER_IRQn);
108}
109
110void lp_ticker_clear_interrupt(void)
111{
112 MTU2TSR = (MTU2TSR & 0xFE);
113 GIC_ClearPendingIRQ(LP_TICKER_TIMER_IRQn);
114}
115
116const ticker_info_t* lp_ticker_get_info()
117{
118 static const ticker_info_t info = {
119 (uint32_t)((float)RENESAS_RZ_A1_P0_CLK / 1024.0f + 0.5f),
120 16
121 };
122 return &info;
123}
124
125#endif // DEVICE_LPTICKER
Note: See TracBrowser for help on using the repository browser.