Trident IoT SDK
Loading...
Searching...
No Matches
T32CM11_pwm.h
Go to the documentation of this file.
1
15
16#ifndef T32CM11_PWM_H_
17#define T32CM11_PWM_H_
18
19#include "tr_hal_platform.h"
20
26
27#define TR_HAL_NUM_PWM 5
28
29// PWM IDs
30typedef enum
31{
37
39
48#define PWM_DEFAULT_PIN 20
49
59#define CHIP_MEMORY_MAP_PWM0_BASE (0xA0C00000UL)
60#define CHIP_MEMORY_MAP_PWM1_BASE (0xA0C00100UL)
61#define CHIP_MEMORY_MAP_PWM2_BASE (0xA0C00200UL)
62#define CHIP_MEMORY_MAP_PWM3_BASE (0xA0C00300UL)
63#define CHIP_MEMORY_MAP_PWM4_BASE (0xA0C00400UL)
64
65
69typedef struct
70{
71 // enable PWM and enable CLK
72 __IO uint32_t enable; // 0x00
73
74 // reset PWM
75 __IO uint32_t reset; // 0x04
76
77 // PWM setup
78 __IO uint32_t settings; // 0x08
79
80 // PWM counter end value
81 __IO uint32_t counter_end; // 0x0C
82
83 // number of times to play the sequence
84 // amount of playback
85 __IO uint32_t sequence_repeat; // 0x10
86
87 // RSEQ
88 __IO uint32_t rseq_num_elements; // 0x14
89 __IO uint32_t rseq_num_repeats; // 0x18
90 __IO uint32_t rseq_delay; // 0x1C
91
92 // TSEQ
93 __IO uint32_t tseq_num_elements; // 0x20
94 __IO uint32_t tseq_num_repeats; // 0x24
95 __IO uint32_t tseq_delay; // 0x28
96
97 __IO uint32_t reserved1[5]; // 0x2C,
98 // 0x30, 0x34, 0x38, 0x3C
99
100 // RDMA 0 - RSEQ
101 __IO uint32_t dma0_enable; // 0x40
102 __IO uint32_t dma0_reset; // 0x44
103 __IO uint32_t dma0_segment_size; // 0x48
104 __IO uint32_t dma0_start_addr; // 0x4C
105 __IO uint32_t reserved2[2]; // 0x50, 0x54
106 __IO uint32_t dma0_next_ptr_addr; // 0x58
107 __IO uint32_t dma0_debug; // 0x5C
108
109 // RDMA 1 - TSEQ
110 __IO uint32_t dma1_enable; // 0x60
111 __IO uint32_t dma1_reset; // 0x64
112 __IO uint32_t dma1_segment_size; // 0x68
113 __IO uint32_t dma1_start_addr; // 0x6C
114 __IO uint32_t reserved3[2]; // 0x70, 0x74
115 __IO uint32_t dma1_next_ptr_addr; // 0x78
116 __IO uint32_t dma1_debug; // 0x7C
117
118 __IO uint32_t reserved4[8]; // 0x80, 0x84, 0x88, 0x8C
119 // 0x90, 0x94, 0x98, 0x9C
120 // interrupts
121 __IO uint32_t interrupt_clear; // 0xA0
122 __IO uint32_t interrupt_mask; // 0xA4
123 __IO uint32_t interrupt_status; // 0xA8
124
126
127// *****************************************************************
128// this orients the PWMx_REGISTERS struct with the correct addresses
129// so referencing a field will now read/write the correct PWM
130// register chip address
131#define PWM0_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM0_BASE)
132#define PWM1_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM1_BASE)
133#define PWM2_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM2_BASE)
134#define PWM3_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM3_BASE)
135#define PWM4_REGISTERS ((PWM_REGISTERS_T *) CHIP_MEMORY_MAP_PWM4_BASE)
136
137
138// *****************************************************************
139// helper defines for ENABLE REGISTER (0x00)
140#define PWM_CTRL_REG_ENABLE_PWM 0x01
141#define PWM_CTRL_REG_DISABLE_PWM 0x00
142#define PWM_CTRL_REG_ENABLE_CLK 0x02
143#define PWM_CTRL_REG_DISABLE_CLK 0x00
144
145// *****************************************************************
146// helper defines for RESET REGISTER (0x04)
147#define PWM_CTRL_REG_RESET 0x01
148
149
150// *****************************************************************
151// helper defines for SETTINGS REGISTER (0x08)
152
153// bit 0 = sequence order
154#define PWM_CTRL_REG_RSEQ_FIRST 0x00
155#define PWM_CTRL_REG_TSEQ_FIRST 0x01
156
157// bit 1 = sequence selection
158#define PWM_CTRL_REG_ONE_SEQUENCE 0x00
159#define PWM_CTRL_REG_TWO_SEQUENCE 0x02
160
161// bit 2 = play mode
162#define PWM_CTRL_REG_NON_CONTINUOUS 0x00
163#define PWM_CTRL_REG_CONTINUOUS 0x04
164
165// bit 3 = DMA format
166#define PWM_CTRL_REG_DMA_FORMAT_0 0x00
167#define PWM_CTRL_REG_DMA_FORMAT_1 0x08
168
169// bit 4 = counter mode
170#define PWM_CTRL_REG_UP_COUNTER 0x00
171#define PWM_CTRL_REG_DOWN_AND_UP_COUNTER 0x10
172
173// bit 5 = counter trigger
174#define PWM_CTRL_REG_TRIGGER_ON_ENABLE 0x00
175#define PWM_CTRL_REG_TRIGGER_ON_FIFO 0x20
176
177// bit 6 = auto trigger
178#define PWM_CTRL_REG_NO_AUTO_TRIGGER 0x00
179#define PWM_CTRL_REG_AUTO_TRIGGER 0x40
180
181// bits 8 to 11 = clock dividier
182#define PWM_CLK_DIV_1 0x0000
183#define PWM_CLK_DIV_2 0x0100
184#define PWM_CLK_DIV_4 0x0200
185#define PWM_CLK_DIV_8 0x0300
186#define PWM_CLK_DIV_16 0x0400
187#define PWM_CLK_DIV_32 0x0500
188#define PWM_CLK_DIV_64 0x0600
189#define PWM_CLK_DIV_128 0x0700
190#define PWM_CLK_DIV_256 0x0800
191
192#define PWM_CLK_DIV_MASK 0x0F00
193
194// bits 12-14: enable PWM to trigger on other PWM
195#define PWM_CTRL_REG_TRIGGER_ON_PWM0 0x0000
196#define PWM_CTRL_REG_TRIGGER_ON_PWM1 0x1000
197#define PWM_CTRL_REG_TRIGGER_ON_PWM2 0x2000
198#define PWM_CTRL_REG_TRIGGER_ON_PWM3 0x3000
199#define PWM_CTRL_REG_TRIGGER_ON_PWM4 0x4000
200#define PWM_CTRL_REG_SELF_TRIGGER 0x7000
201
202// bits 15-31 reserved
203
204// *****************************************************************
205// helper defines for DMAx ENABLE REGISTER (0x40, 0x60)
206#define PWM_DMA_ENABLE 0x00000001
207#define PWM_DMA_DISABLE 0x00000000
208
209// *****************************************************************
210// helper defines for DMAx RESET REGISTER (0x44, 0x64)
211#define PWM_DMA_RESET 0x00000001
212
213
230
231
241
242
248
253// end_count = 0x001F + 1 = 0x0020 = 32 --> 32Mhz/32 = 1 MHz
254#define PWM_END_COUNT_CLKDIV_1_1MHZ 0x0020
255// threshhold = 0x0018 = 24 --> 24/32 = 75%
256#define PWM_THRESHHOLD_CLKDIV_1_1MHZ_DUTY_CYCLE_75 0x0018
257// threshhold = 0x0010 = 16 --> 16/32 = 50%
258#define PWM_THRESHHOLD_CLKDIV_1_1MHZ_DUTY_CYCLE_50 0x0010
259// threshhold = 0x0008 = 8 --> 8/32 = 25%
260#define PWM_THRESHHOLD_CLKDIV_1_1MHZ_DUTY_CYCLE_25 0x0008
261
266// end_count = 0x003F + 1 = 0x0040 = 64 --> 32Mhz/64 = 500 KHz
267#define PWM_END_COUNT_CLKDIV_1_500KHZ 0x0040
268// threshhold = 0x0030 = 48 --> 48/64 = 75%
269#define PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_75 0x0030
270// threshhold = 0x0020 = 32 --> 32/64 = 50%
271#define PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_50 0x0020
272// threshhold = 0x0010 = 16 --> 16/64 = 25%
273#define PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_25 0x0010
274
279// end_count = 0x007F + 1 = 0x0080 = 128 --> 32Mhz/128 = 250 KHz
280#define PWM_END_COUNT_CLKDIV_1_250KHZ 0x0080
281// threshhold = 0x0060 = 96 --> 96/128 = 75%
282#define PWM_THRESHHOLD_CLKDIV_1_250KHZ_DUTY_CYCLE_75 0x0060
283// threshhold = 0x0040 = 64 --> 64/128 = 50%
284#define PWM_THRESHHOLD_CLKDIV_1_250KHZ_DUTY_CYCLE_50 0x0040
285// threshhold = 0x0020 = 32 --> 32/128 = 25%
286#define PWM_THRESHHOLD_CLKDIV_1_250KHZ_DUTY_CYCLE_25 0x0020
287
288// limits for end count
289#define MINIMUM_END_COUNT_VALUE 4
290#define MAXIMUM_END_COUNT_VALUE 0x7FFF
291
292// limits for threshhold
293#define MINIMUM_THRESHHOLD_VALUE 4
294#define MAXIMUM_THRESHHOLD_VALUE 0x7FFF
295
296
301typedef struct
302{
303 // which pin to use for PWM
305
306 // which clock to use
308
309 // clock divider
311
312 // this along with the clock creates the frequency
313 // freq = clock / (clk_div * end_count)
314 uint16_t end_count;
315
316 // this creates the duty cycle
317 // duty cycle = threshhold / end_count
318 uint16_t threshhold;
319
321
326
327
329#define DEFAULT_PWM_CONFIG \
330 { \
331 .pin_to_use = (tr_hal_gpio_pin_t) { PWM_DEFAULT_PIN }, \
332 .clock_to_use = TR_HAL_PWM_CLK_SELECT_DEFAULT, \
333 .clock_divider = TR_HAL_PWM_CLOCK_DIVIDER_1, \
334 .end_count = PWM_END_COUNT_CLKDIV_1_500KHZ, \
335 .threshhold = PWM_THRESHHOLD_CLKDIV_1_500KHZ_DUTY_CYCLE_75,\
336 }
337
338
345
346
350
351
352#endif //T32CM11_PWM_H_
353
354
This file contains the CHIP SPECIFIC types and defines for the T32CM11.
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
PWM_REGISTERS_T * tr_hal_pwm_get_register_address(tr_hal_pwm_id_t pwm_id)
@ 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
tr_hal_pwm_clk_select_t
Definition T32CZ20_pwm.h:276
tr_hal_pwm_clk_div_t
Definition T32CZ20_pwm.h:257
the struct we use so we can address registers using field names
Definition T32CM11_pwm.h:70
__IO uint32_t dma0_enable
Definition T32CM11_pwm.h:101
__IO uint32_t enable
Definition T32CM11_pwm.h:72
__IO uint32_t interrupt_status
Definition T32CM11_pwm.h:123
__IO uint32_t rseq_num_repeats
Definition T32CM11_pwm.h:89
__IO uint32_t counter_end
Definition T32CM11_pwm.h:81
__IO uint32_t interrupt_mask
Definition T32CM11_pwm.h:122
__IO uint32_t dma1_next_ptr_addr
Definition T32CM11_pwm.h:115
__IO uint32_t tseq_delay
Definition T32CM11_pwm.h:95
__IO uint32_t reserved4[8]
Definition T32CM11_pwm.h:118
__IO uint32_t sequence_repeat
Definition T32CM11_pwm.h:85
__IO uint32_t rseq_num_elements
Definition T32CM11_pwm.h:88
__IO uint32_t reserved1[5]
Definition T32CM11_pwm.h:97
__IO uint32_t dma1_enable
Definition T32CM11_pwm.h:110
__IO uint32_t rseq_delay
Definition T32CM11_pwm.h:90
__IO uint32_t dma1_reset
Definition T32CM11_pwm.h:111
__IO uint32_t dma0_next_ptr_addr
Definition T32CM11_pwm.h:106
__IO uint32_t reserved2[2]
Definition T32CM11_pwm.h:105
__IO uint32_t dma1_debug
Definition T32CM11_pwm.h:116
__IO uint32_t dma0_reset
Definition T32CM11_pwm.h:102
__IO uint32_t tseq_num_elements
Definition T32CM11_pwm.h:93
__IO uint32_t reset
Definition T32CM11_pwm.h:75
__IO uint32_t settings
Definition T32CM11_pwm.h:78
__IO uint32_t dma0_segment_size
Definition T32CM11_pwm.h:103
__IO uint32_t dma0_start_addr
Definition T32CM11_pwm.h:104
__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_debug
Definition T32CM11_pwm.h:107
__IO uint32_t tseq_num_repeats
Definition T32CM11_pwm.h:94
__IO uint32_t interrupt_clear
Definition T32CM11_pwm.h:121
__IO uint32_t reserved3[2]
Definition T32CM11_pwm.h:114
pin type
Definition tr_hal_platform.h:23
Definition T32CM11_pwm.h:302
uint16_t threshhold
Definition T32CM11_pwm.h:318
tr_hal_pwm_clk_select_t clock_to_use
Definition T32CM11_pwm.h:307
uint16_t end_count
Definition T32CM11_pwm.h:314
tr_hal_gpio_pin_t pin_to_use
Definition T32CM11_pwm.h:304
tr_hal_pwm_clk_div_t clock_divider
Definition T32CM11_pwm.h:310