|
| 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 | + |
0 commit comments