Trident IoT SDK
Loading...
Searching...
No Matches
T32CZ20_pwm.h
Go to the documentation of this file.
1
15
16#ifndef T32CZ20_PWM_H_
17#define T32CZ20_PWM_H_
18
19#include "tr_hal_platform.h"
20
21
27
28
29#define TR_HAL_NUM_PWM 5
30
31// PWM IDs
32typedef enum
33{
39
41
42#define PWM_DEFAULT_PIN 1
43
44
56#ifdef PWM_SECURE_EN
57 #define CHIP_MEMORY_MAP_PWM0_BASE (0x50026000UL)
58 #define CHIP_MEMORY_MAP_PWM1_BASE (0x50026100UL)
59 #define CHIP_MEMORY_MAP_PWM2_BASE (0x50026200UL)
60 #define CHIP_MEMORY_MAP_PWM3_BASE (0x50026300UL)
61 #define CHIP_MEMORY_MAP_PWM4_BASE (0x50026400UL)
62#else
63 #define CHIP_MEMORY_MAP_PWM0_BASE (0x40026000UL)
64 #define CHIP_MEMORY_MAP_PWM1_BASE (0x40026100UL)
65 #define CHIP_MEMORY_MAP_PWM2_BASE (0x40026200UL)
66 #define CHIP_MEMORY_MAP_PWM3_BASE (0x40026300UL)
67 #define CHIP_MEMORY_MAP_PWM4_BASE (0x40026400UL)
68#endif //PWM_SECURE_EN
69
70
74typedef struct
75{
76 // enable PWM and enable CLK
77 __IO uint32_t enable; // 0x00
78
79 // reset PWM
80 __IO uint32_t reset; // 0x04
81
82 // PWM setup
83 __IO uint32_t settings; // 0x08
84
85 // PWM counter end value
86 __IO uint32_t counter_end; // 0x0C
87
88 // number of times to play the sequence
89 __IO uint32_t sequence_repeat; // 0x10
90
91 // RSEQ
92 __IO uint32_t rseq_num_elements; // 0x14
93 __IO uint32_t rseq_num_repeats; // 0x18
94 __IO uint32_t rseq_delay; // 0x1C
95
96 // TSEQ
97 __IO uint32_t tseq_num_elements; // 0x20
98 __IO uint32_t tseq_num_repeats; // 0x24
99 __IO uint32_t tseq_delay; // 0x28
100
101 __IO uint32_t reserved1[5]; // 0x2C,
102 // 0x30, 0x34, 0x38, 0x3C
103
104 // DMA 0
105 __IO uint32_t dma0_enable; // 0x40
106 __IO uint32_t dma0_reset; // 0x44
107 __IO uint32_t dma0_segment_size; // 0x48
108 __IO uint32_t dma0_start_addr; // 0x4C
109 __IO uint32_t dma0_settings; // 0x50
110 __IO uint32_t reserved2; // 0x54
111 __IO uint32_t dma0_addr_status; // 0x58
112 __IO uint32_t dma0_status; // 0x5C
113
114 // DMA 1
115 __IO uint32_t dma1_enable; // 0x60
116 __IO uint32_t dma1_reset; // 0x64
117 __IO uint32_t dma1_segment_size; // 0x68
118 __IO uint32_t dma1_start_addr; // 0x6C
119 __IO uint32_t dma1_settings; // 0x70
120 __IO uint32_t reserved3; // 0x74
121 __IO uint32_t dma1_addr_status; // 0x78
122 __IO uint32_t dma1_status; // 0x7C
123
124 __IO uint32_t reserved4[8]; // 0x80, 0x84, 0x88, 0x8C
125 // 0x90, 0x94, 0x98, 0x9C
126 // interrupts
127 __IO uint32_t interrupt_clear; // 0xA0
128 __IO uint32_t interrupt_mask; // 0xA4
129 __IO uint32_t interrupt_status; // 0xA8
130
131 // save data
132 __IO uint32_t reg_data_0_save; // 0xAC
133 __IO uint32_t reg_data_1_save; // 0xB0
134
136
137
138// *****************************************************************
139// this orients the PWMx_REGISTERS struct with the correct addresses
140// so referencing a field will now read/write the correct PWM
141// register chip address
142#define PWM0_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM0_BASE)
143#define PWM1_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM1_BASE)
144#define PWM2_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM2_BASE)
145#define PWM3_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM3_BASE)
146#define PWM4_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM4_BASE)
147
148
149// *****************************************************************
150// helper defines for ENABLE REGISTER (0x00)
151#define PWM_CTRL_REG_ENABLE_PWM 0x01
152#define PWM_CTRL_REG_DISABLE_PWM 0x00
153#define PWM_CTRL_REG_ENABLE_CLK 0x02
154#define PWM_CTRL_REG_DISABLE_CLK 0x00
155
156// *****************************************************************
157// helper defines for RESET REGISTER (0x04)
158#define PWM_CTRL_REG_RESET 0x01
159
160// *****************************************************************
161// helper defines for SETTINGS REGISTER (0x08)
162
163// bit 0 = sequence order
164#define PWM_CTRL_REG_RSEQ_FIRST 0x00
165#define PWM_CTRL_REG_TSEQ_FIRST 0x01
166
167// bit 1 = sequence selection
168#define PWM_CTRL_REG_ONE_SEQUENCE 0x00
169#define PWM_CTRL_REG_TWO_SEQUENCE 0x02
170
171// bit 2 = play mode
172#define PWM_CTRL_REG_NON_CONTINUOUS 0x00
173#define PWM_CTRL_REG_CONTINUOUS 0x04
174
175// bit 3 = DMA format
176#define PWM_CTRL_REG_DMA_FORMAT_0 0x00
177#define PWM_CTRL_REG_DMA_FORMAT_1 0x08
178
179// bit 4 = counter mode
180#define PWM_CTRL_REG_UP_COUNTER 0x00
181#define PWM_CTRL_REG_DOWN_AND_UP_COUNTER 0x10
182
183// bit 5 = counter trigger
184#define PWM_CTRL_REG_TRIGGER_ON_ENABLE 0x00
185#define PWM_CTRL_REG_TRIGGER_ON_FIFO 0x20
186
187// bit 6 = auto trigger
188#define PWM_CTRL_REG_NO_AUTO_TRIGGER 0x00
189#define PWM_CTRL_REG_AUTO_TRIGGER 0x40
190
191// bit 7 = mode
192#define PWM_CTRL_REG_MODE_DMA 0x00
193#define PWM_CTRL_REG_MODE_REGISTER 0x80
194
195// bits 8 to 11 = clock divider1
196#define PWM_CLK_DIV1_1 0x0000
197#define PWM_CLK_DIV1_2 0x0100
198#define PWM_CLK_DIV1_4 0x0200
199#define PWM_CLK_DIV1_8 0x0300
200#define PWM_CLK_DIV1_16 0x0400
201#define PWM_CLK_DIV1_32 0x0500
202#define PWM_CLK_DIV1_64 0x0600
203#define PWM_CLK_DIV1_128 0x0700
204#define PWM_CLK_DIV1_256 0x0800
205
206#define PWM_CLK_DIV1_MASK 0x0F00
207
208// bits 12-14: enable PWM to trigger on other PWM
209#define PWM_CTRL_REG_TRIGGER_ON_PWM0 0x0000
210#define PWM_CTRL_REG_TRIGGER_ON_PWM1 0x1000
211#define PWM_CTRL_REG_TRIGGER_ON_PWM2 0x2000
212#define PWM_CTRL_REG_TRIGGER_ON_PWM3 0x3000
213#define PWM_CTRL_REG_TRIGGER_ON_PWM4 0x4000
214#define PWM_CTRL_REG_SELF_TRIGGER 0x7000
215
216// bits 15-19 reserved
217
218// bit 20 data play number
219#define PWM_CTRL_REG_DATA_PLAY_1 0x000000
220#define PWM_CTRL_REG_DATA_PLAY_2 0x100000
221
222// bits 21-23 reserved
223
224// bits 24-31 = PWM clock divider2 value, only valid when > 0
225// when not valid, clock divider1 is used
226// in the Trident HAL driver, we just use clock divider 1
227#define PWM_CLK_DIV2_MASK 0xFF000000
228
229#define PWM_CLK_DIV2_1 0x01000000
230#define PWM_CLK_DIV2_2 0x02000000
231#define PWM_CLK_DIV2_4 0x04000000
232#define PWM_CLK_DIV2_8 0x08000000
233#define PWM_CLK_DIV2_16 0x10000000
234#define PWM_CLK_DIV2_32 0x20000000
235#define PWM_CLK_DIV2_64 0x40000000
236#define PWM_CLK_DIV2_128 0x80000000
237
238// this means set clk div 2 to no value, which means don't use this for
239// the clk div, use clk div 1
240#define PWM_CLK_DIV2_NO_VALUE 0x00000000
241
242
243// *****************************************************************
244// helper defines for DMAx ENABLE REGISTER (0x40, 0x60)
245#define PWM_DMA_ENABLE 0x00000001
246#define PWM_DMA_DISABLE 0x00000000
247
248// *****************************************************************
249// helper defines for DMAx RESET REGISTER (0x44, 0x64)
250#define PWM_DMA_RESET 0x00000001
251
252
269
270
286
287
293
298// end_count = 0x001F + 1 = 0x0020 = 32 --> 32Mhz/32 = 1 MHz
299#define PWM_END_COUNT_CLKDIV_1_1MHZ 0x0020
300// threshhold = 0x0018 = 24 --> 24/32 = 75%
301#define PWM_THRESHHOLD_CLKDIV_1_1MHZ_DUTY_CYCLE_75 0x0018
302// threshhold = 0x0010 = 16 --> 16/32 = 50%
303#define PWM_THRESHHOLD_CLKDIV_1_1MHZ_DUTY_CYCLE_50 0x0010
304// threshhold = 0x0008 = 8 --> 8/32 = 25%
305#define PWM_THRESHHOLD_CLKDIV_1_1MHZ_DUTY_CYCLE_25 0x0008
306
311// end_count = 0x003F + 1 = 0x0040 = 64 --> 32Mhz/64 = 500 KHz
312#define PWM_END_COUNT_CLKDIV_1_500KHZ 0x0040
313// threshhold = 0x0030 = 48 --> 48/64 = 75%
314#define PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_75 0x0030
315// threshhold = 0x0020 = 32 --> 32/64 = 50%
316#define PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_50 0x0020
317// threshhold = 0x0010 = 16 --> 16/64 = 25%
318#define PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_25 0x0010
319
324// end_count = 0x007F + 1 = 0x0080 = 128 --> 32Mhz/128 = 250 KHz
325#define PWM_END_COUNT_CLKDIV_1_250KHZ 0x0080
326// threshhold = 0x0060 = 96 --> 96/128 = 75%
327#define PWM_THRESHHOLD_CLKDIV_1_250KHZ_DUTY_CYCLE_75 0x0060
328// threshhold = 0x0040 = 64 --> 64/128 = 50%
329#define PWM_THRESHHOLD_CLKDIV_1_250KHZ_DUTY_CYCLE_50 0x0040
330// threshhold = 0x0020 = 32 --> 32/128 = 25%
331#define PWM_THRESHHOLD_CLKDIV_1_250KHZ_DUTY_CYCLE_25 0x0020
332
333// limits for end count
334#define MINIMUM_END_COUNT_VALUE 4
335#define MAXIMUM_END_COUNT_VALUE 0x7FFF
336
337// limits for threshhold
338#define MINIMUM_THRESHHOLD_VALUE 4
339#define MAXIMUM_THRESHHOLD_VALUE 0x7FFF
340
345typedef struct
346{
347 // which pin to use for PWM
348 tr_hal_gpio_pin_t pin_to_use;
349
350 // which clock to use
351 tr_hal_pwm_clk_select_t clock_to_use;
352
353 // clock divider
354 tr_hal_pwm_clk_div_t clock_divider;
355
356 // this along with the clock creates the frequency
357 // freq = clock / (clk_div * end_count)
358 uint16_t end_count;
359
360 // this creates the duty cycle
361 // duty cycle = threshhold / end_count
362 uint16_t threshhold;
363
365
366
371
372
374#define DEFAULT_PWM_CONFIG \
375 { \
376 .pin_to_use = (tr_hal_gpio_pin_t) { PWM_DEFAULT_PIN }, \
377 .clock_to_use = TR_HAL_PWM_CLK_SELECT_DEFAULT, \
378 .clock_divider = TR_HAL_PWM_CLOCK_DIVIDER_1, \
379 .end_count = PWM_END_COUNT_CLKDIV_1_500KHZ, \
380 .threshhold = PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_75,\
381 }
382
383
390
391
395
396
397#endif //T32CZ20_PWM_H_
This file contains the CHIP SPECIFIC types and defines for the T32CZ20.
tr_hal_pwm_clk_select_t
Definition T32CM11_pwm.h:236
tr_hal_pwm_clk_div_t
Definition T32CM11_pwm.h:218
tr_hal_pwm_id_t
Definition T32CM11_pwm.h:31
@ TR_HAL_PWM_CLK_SELECT_DEFAULT
Definition T32CM11_pwm.h:238
@ TR_HAL_PWM_CLK_SELECT_PER_CLK
Definition T32CM11_pwm.h:237
@ TR_HAL_PWM_CLOCK_DIVIDER_128
Definition T32CM11_pwm.h:226
@ TR_HAL_PWM_CLOCK_DIVIDER_256
Definition T32CM11_pwm.h:227
@ TR_HAL_PWM_CLOCK_DIVIDER_1
Definition T32CM11_pwm.h:219
@ TR_HAL_PWM_CLOCK_DIVIDER_32
Definition T32CM11_pwm.h:224
@ TR_HAL_PWM_CLOCK_DIVIDER_4
Definition T32CM11_pwm.h:221
@ TR_HAL_PWM_CLOCK_DIVIDER_2
Definition T32CM11_pwm.h:220
@ TR_HAL_PWM_CLOCK_DIVIDER_64
Definition T32CM11_pwm.h:225
@ TR_HAL_PWM_CLOCK_DIVIDER_8
Definition T32CM11_pwm.h:222
@ TR_HAL_PWM_CLOCK_DIVIDER_16
Definition T32CM11_pwm.h:223
@ PWM_4_ID
Definition T32CM11_pwm.h:36
@ PWM_3_ID
Definition T32CM11_pwm.h:35
@ PWM_0_ID
Definition T32CM11_pwm.h:32
@ PWM_1_ID
Definition T32CM11_pwm.h:33
@ PWM_2_ID
Definition T32CM11_pwm.h:34
PWM_REGISTERS_T * tr_hal_pwm_get_register_address(tr_hal_pwm_id_t pwm_id)
@ TR_HAL_PWM_CLK_SELECT_SLOW_CLK
Definition T32CZ20_pwm.h:280
@ TR_HAL_PWM_CLK_SELECT_RCO_1M
Definition T32CZ20_pwm.h:279
@ TR_HAL_PWM_CLK_SELECT_HCLK
Definition T32CZ20_pwm.h:277
the struct we use so we can address registers using field names
Definition T32CM11_pwm.h:70
__IO uint32_t dma1_settings
Definition T32CZ20_pwm.h:119
__IO uint32_t interrupt_status
Definition T32CM11_pwm.h:123
__IO uint32_t reg_data_0_save
Definition T32CZ20_pwm.h:132
__IO uint32_t dma1_addr_status
Definition T32CZ20_pwm.h:121
__IO uint32_t interrupt_mask
Definition T32CM11_pwm.h:122
__IO uint32_t reserved4[8]
Definition T32CM11_pwm.h:118
__IO uint32_t dma0_settings
Definition T32CZ20_pwm.h:109
__IO uint32_t dma0_status
Definition T32CZ20_pwm.h:112
__IO uint32_t dma1_enable
Definition T32CM11_pwm.h:110
__IO uint32_t dma1_reset
Definition T32CM11_pwm.h:111
__IO uint32_t reserved2[2]
Definition T32CM11_pwm.h:105
__IO uint32_t dma1_status
Definition T32CZ20_pwm.h:122
__IO uint32_t dma1_segment_size
Definition T32CM11_pwm.h:112
__IO uint32_t dma1_start_addr
Definition T32CM11_pwm.h:113
__IO uint32_t dma0_addr_status
Definition T32CZ20_pwm.h:111
__IO uint32_t interrupt_clear
Definition T32CM11_pwm.h:121
__IO uint32_t reg_data_1_save
Definition T32CZ20_pwm.h:133
__IO uint32_t reserved3[2]
Definition T32CM11_pwm.h:114
pin type
Definition tr_hal_platform.h:23
Definition T32CM11_pwm.h:302