Skip to content

Commit 29e15fc

Browse files
committed
pwm_timer driver RC1:
implement pwm_timer abstract layer implement pem_timer driver in iotdk board iotdk: sysconf: bug fix in PLL_CONF_VAL Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
1 parent 060e412 commit 29e15fc

File tree

11 files changed

+1031
-2
lines changed

11 files changed

+1031
-2
lines changed

board/iotdk/configs/10/core_config.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ ONCHIP_IP_LIST ?= subsystem/gpio \
1414
subsystem/spi \
1515
subsystem/iic \
1616
designware/i2s \
17-
designware/sdio
17+
designware/sdio \
18+
designware/pwm_timer
1819
# dfss/dmac \
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2018, Synopsys, Inc. All rights reserved.
3+
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
7+
* 1) Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
10+
* 2) Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
14+
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
15+
* be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
--------------------------------------------- */
30+
31+
/**
32+
* \defgroup BOARD_EMSK_DRV_DW_PWM_TIMER_OBJ EMSK DW PWM_TIMER Object
33+
* \ingroup BOARD_IOTDK_DRIVER
34+
* \brief EMSK Designware UART Objects
35+
* \details
36+
* Realize the EMSK board uart object using Designware uart device driver,
37+
* only need to realize some Designware uart structures combine with EMSK uart
38+
* hardware resource. just like cpp class instantiation.
39+
*/
40+
41+
/**
42+
* \file
43+
* \ingroup BOARD_EMSK_DRV_DW_UART_OBJ
44+
* \brief designware uart object instantiation on emsk
45+
*/
46+
47+
48+
49+
#include "embARC_toolchain.h"
50+
#include "embARC_error.h"
51+
52+
#include "iotdk_hardware.h"
53+
#include "dw_pwm_timer_obj.h"
54+
55+
/**
56+
* \DW_PWM_TIMER_0 BOARD_EMSK_DRV_DW_UART_OBJ
57+
* @{
58+
*/
59+
60+
/**
61+
* EMSK DesignWare PWM_TIMER Group 0 Object Instantiation
62+
*/
63+
#if (USE_DW_PWM_TIMER_0)
64+
#define PWM_TIMER_0_CH_0_INTNO 98 /*!< designware pwm_timer group 0 channel 0 interrupt number */
65+
static DEV_PWM_TIMER dw_pwm_timer_0; /*!< designware pwm_timer object */
66+
static DW_PWM_TIMER_CTRL dw_pwm_timer_0_ctrl; /*!< designware pwm_timer group 0 ctrl */
67+
static DEV_PWM_TIMER_HANDLER dw_pwm_timer_0_handler[DW_PWM_TIMER_0_CH_MAX_COUNT]; /*!< designware pwm_timer group 0 channels callback handler */
68+
69+
static DEV_PWM_TIMER_MODE dw_pwm_timer_0_mode[DW_PWM_TIMER_0_CH_MAX_COUNT]; /*!< designware pwm_timer group 0 channels mode */
70+
71+
static DW_PWM_TIMER_CH_ISR dw_pwm_timer_0_ch_isr = {
72+
DW_PWM_TIMER_0_CH_MAX_COUNT, dw_pwm_timer_0_handler
73+
};
74+
75+
76+
/** DesignWare PWM_TIMER 0 open */
77+
static int32_t dw_pwm_timer_0_open (void)
78+
{
79+
return dw_pwm_timer_open(&dw_pwm_timer_0);
80+
}
81+
/** DesignWare PWM_TIMER 0 close */
82+
static int32_t dw_pwm_timer_0_close (void)
83+
{
84+
return dw_pwm_timer_close(&dw_pwm_timer_0);
85+
}
86+
/** DesignWare PWM_TIMER 0 control */
87+
static int32_t dw_pwm_timer_0_control (uint32_t cmd, void *param)
88+
{
89+
return dw_pwm_timer_control(&dw_pwm_timer_0, cmd, param);
90+
}
91+
/** DesignWare PWM_TIMER 0 write */
92+
static int32_t dw_pwm_timer_0_write (uint32_t ch, uint32_t mode, uint32_t count_low, uint32_t count_high)
93+
{
94+
return dw_pwm_timer_write(&dw_pwm_timer_0, ch, mode, count_low, count_high);
95+
}
96+
/** DesignWare PWM_TIMER 0 read */
97+
static int32_t dw_pwm_timer_0_read (uint32_t ch, uint32_t *mode, uint32_t *count_low, uint32_t *count_high)
98+
{
99+
return dw_pwm_timer_read(&dw_pwm_timer_0, ch, mode, count_low, count_high);
100+
}
101+
/** DesignWare PWM_TIMER 0 interrupt routine */
102+
static void dw_pwm_timer_0_isr(void *ptr)
103+
{
104+
dw_pwm_timer_isr_handler(&dw_pwm_timer_0, ptr);
105+
}
106+
/** Install DesignWare PWM_TIMER 0 to system */
107+
static void dw_pwm_timer_0_install(void)
108+
{
109+
uint32_t i;
110+
DEV_PWM_TIMER *dw_pwm_timer_ptr = &dw_pwm_timer_0;
111+
DEV_PWM_TIMER_INFO *dw_pwm_timer_info_ptr = &(dw_pwm_timer_0.pwm_timer_info);
112+
DW_PWM_TIMER_CTRL_PTR dw_pwm_timer_ctrl_ptr = &(dw_pwm_timer_0_ctrl);
113+
114+
/* Info init */
115+
dw_pwm_timer_info_ptr->pwm_timer_ctrl = (void *)dw_pwm_timer_ctrl_ptr;
116+
dw_pwm_timer_info_ptr->opn_cnt = 0;
117+
118+
dw_pwm_timer_ctrl_ptr->id = DW_PWM_TIMER_0_ID;
119+
dw_pwm_timer_ctrl_ptr->regs = (DW_PWM_TIMER_REG_PTR)(BASE_ADDR_PWM);
120+
dw_pwm_timer_ctrl_ptr->intno = PWM_TIMER_0_CH_0_INTNO;
121+
dw_pwm_timer_ctrl_ptr->ch_num = DW_PWM_TIMER_0_CH_MAX_COUNT;
122+
dw_pwm_timer_ctrl_ptr->int_handler = dw_pwm_timer_0_isr;
123+
124+
for (i=0; i < dw_pwm_timer_0_ch_isr.int_ch_max_cnt; i++) {
125+
dw_pwm_timer_0_ch_isr.int_ch_handler_ptr[i] = NULL;
126+
}
127+
dw_pwm_timer_ctrl_ptr->ch_isr = &(dw_pwm_timer_0_ch_isr);
128+
dw_pwm_timer_ctrl_ptr->mode = dw_pwm_timer_0_mode;
129+
130+
131+
/** PWM_TIMER dev init */
132+
dw_pwm_timer_ptr->pwm_timer_open = dw_pwm_timer_0_open;
133+
dw_pwm_timer_ptr->pwm_timer_close = dw_pwm_timer_0_close;
134+
dw_pwm_timer_ptr->pwm_timer_control = dw_pwm_timer_0_control;
135+
dw_pwm_timer_ptr->pwm_timer_write = dw_pwm_timer_0_write;
136+
dw_pwm_timer_ptr->pwm_timer_read = NULL;
137+
}
138+
#endif /* USE_DW_PWM_TIMER_0 */
139+
/** @} end of DW_PWM_TIMER_0 */
140+
141+
/**
142+
* \brief install all pwm_timer objects
143+
* \note \b MUST be called during system init
144+
*/
145+
void dw_pwm_timer_all_install(void)
146+
{
147+
#if (USE_DW_PWM_TIMER_0)
148+
dw_pwm_timer_0_install();
149+
#endif
150+
}
151+
152+
153+
/** get one designware device structure */
154+
DEV_PWM_TIMER_PTR pwm_timer_get_dev(int32_t pwm_timer_id)
155+
{
156+
static uint32_t install_flag = 0;
157+
158+
/* intall device objects */
159+
if (install_flag == 0) {
160+
install_flag = 1;
161+
dw_pwm_timer_all_install();
162+
}
163+
164+
switch (pwm_timer_id) {
165+
#if (USE_DW_PWM_TIMER_0)
166+
167+
case DW_PWM_TIMER_0_ID:
168+
return &dw_pwm_timer_0;
169+
break;
170+
#endif
171+
default:
172+
break;
173+
}
174+
175+
return NULL;
176+
}
177+
178+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2018, Synopsys, Inc. All rights reserved.
3+
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
7+
* 1) Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
10+
* 2) Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
14+
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
15+
* be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
--------------------------------------------- */
30+
#ifndef _DW_PWM_TIMER_OBJ_H_
31+
#define _DW_PWM_TIMER_OBJ_H_
32+
33+
#include "dw_pwm_timer.h"
34+
35+
#define USE_DW_PWM_TIMER_0 1 /*!< enable use DesignWare PWM TIMER */
36+
37+
38+
39+
#define DW_PWM_TIMER_0_ID 0
40+
41+
#define DW_PWM_TIMER_0_CH_MAX_COUNT 6
42+
43+
#ifdef __cplusplus
44+
extern "C" {
45+
#endif
46+
47+
extern DEV_PWM_TIMER_PTR pwm_timer_get_dev(int32_t pwm_timer_id);
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif
52+
53+
#endif /* _DW_PWM_TIMER_OBJ_H_ */

board/iotdk/drivers/sysconf/sysconf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef struct pll_conf {
4646
/* why m + 4 is required? from provided source code */
4747
#define PLL_CONF_VAL(n, m, od) \
4848
(((n) << PLLCON_BIT_OFFSET_N) | \
49-
((m + 4) << (PLLCON_BIT_OFFSET_M)) | \
49+
((m) << (PLLCON_BIT_OFFSET_M)) | \
5050
((od) << PLLCON_BIT_OFFSET_OD))
5151

5252

board/iotdk/drivers/sysconf/sysconf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ extern void pll_conf_reg(uint32_t val);
164164
extern int32_t pll_fout_config(uint32_t freq);
165165

166166
extern void ahb_clk_divisor(uint8_t div);
167+
extern void apb_clk_divisor(uint8_t div);
167168
extern void ahb_clk_enable(uint8_t dev);
168169
extern void ahb_clk_disable(uint8_t dev);
169170
extern void sdio_clk_divisor(uint8_t div);

board/iotdk/iotdk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include "drivers/ip/designware/i2s/dw_i2s_obj.h"
4747
#include "drivers/ip/designware/sdio/dw_sdio_obj.h"
48+
#include "drivers/ip/designware/pwm_timer/dw_pwm_timer_obj.h"
4849
#include "drivers/ip/subsystem/iic/dfss_iic_obj.h"
4950
#include "drivers/ip/subsystem/uart/dfss_uart_obj.h"
5051
#include "drivers/ip/subsystem/spi/dfss_spi_obj.h"

0 commit comments

Comments
 (0)