Kamcho Library 02.00.03  lib.kamcho.02.00.03.287
pwm_sfrs.h
Go to the documentation of this file.
1 
12 #ifndef __PWM_SFRS_H__
13 #define __PWM_SFRS_H__
14 
18 typedef struct {
19  union {
20  struct {
21  uint8_t PRESC:3;
22  uint8_t Reserved1:1;
23  uint8_t INV:1;
24  uint8_t Reserved2:2;
25  uint8_t EN:1;
26  };
27  uint8_t CTRL;
28  } CTRL;
29  uint8_t PERIODLOW;
30  uint8_t WIDTHLOW;
31  union {
32  struct {
33  uint8_t PERIODHIGH:4;
34  uint8_t WIDTHHIGH:4;
35  };
36  uint8_t BYTE;
37  } EXT;
38 } PWM1_SFRS_t;
39 
43 #define PWM1_SFRS ((__IO PWM1_SFRS_t *) (ASIC_7B_BASE + 0x48))
44 
45 #define E_PWM1_PRESCALE_DIV1 0
46 #define E_PWM1_PRESCALE_DIV2 1
47 #define E_PWM1_PRESCALE_DIV4 2
48 #define E_PWM1_PRESCALE_DIV8 3
49 #define E_PWM1_PRESCALE_DIV32 4
50 #define E_PWM1_PRESCALE_DIV256 5
51 #define E_PWM1_PRESCALE_DIV8192 6
52 #define E_PWM1_PRESCALE_DIV262144 7
53 
59 static __INLINE void f_PWM1_SetPeriod(uint32_t period)
60 {
61  PWM1_SFRS->PERIODLOW = period & 0xFF;
62  PWM1_SFRS->EXT.WIDTHHIGH = (period >> 8) & 0x0F;
63 }
64 
70 static __INLINE void f_PWM1_SetWidth(uint32_t width)
71 {
72  PWM1_SFRS->WIDTHLOW = width & 0xFF;
73  PWM1_SFRS->EXT.PERIODHIGH = (width >> 8) & 0x0F;
74 }
75 
81 static __INLINE void f_PWM1_SetPreScaler(uint8_t div)
82 {
83  PWM1_SFRS->CTRL.PRESC = div;
84 }
85 
89 static __INLINE void f_PWM1_InvertOn(void)
90 {
91  PWM1_SFRS->CTRL.INV = 1;
92 }
93 
97 static __INLINE void f_PWM1_InvertOff(void)
98 {
99  PWM1_SFRS->CTRL.INV = 0;
100 }
101 
105 static __INLINE void f_PWM1_Enable(void)
106 {
107  PWM1_SFRS->CTRL.EN = 1;
108 }
109 
113 static __INLINE void f_PWM1_Disable(void)
114 {
115  PWM1_SFRS->CTRL.EN = 0;
116 }
117 
121 typedef struct {
122  union {
123  struct {
124  uint8_t PRESC:3;
125  uint8_t Reserved1:1;
126  uint8_t INV:1;
127  uint8_t Reserved2:2;
128  uint8_t EN:1;
129  };
130  uint8_t CTRL;
131  } CTRL;
132  uint8_t PERIODLOW;
133  uint8_t WIDTHLOW;
134  union {
135  struct {
136  uint8_t PERIODHIGH:4;
137  uint8_t WIDTHHIGH:4;
138  };
139  uint8_t BYTE;
140  } EXT;
141 } PWM2_SFRS_t;
142 
146 #define PWM2_SFRS ((__IO PWM2_SFRS_t *) (ASIC_7B_BASE + 0x4C))
147 
148 #define E_PWM2_PRESCALE_DIV1 0
149 #define E_PWM2_PRESCALE_DIV2 1
150 #define E_PWM2_PRESCALE_DIV4 2
151 #define E_PWM2_PRESCALE_DIV8 3
152 #define E_PWM2_PRESCALE_DIV32 4
153 #define E_PWM2_PRESCALE_DIV256 5
154 #define E_PWM2_PRESCALE_DIV8192 6
155 #define E_PWM2_PRESCALE_DIV262144 7
156 
162 static __INLINE void f_PWM2_SetPeriod(uint32_t period)
163 {
164  PWM2_SFRS->PERIODLOW = period & 0xFF;
165  PWM2_SFRS->EXT.WIDTHHIGH = (period >> 8) & 0x0F;
166 }
167 
173 static __INLINE void f_PWM2_SetWidth(uint32_t width)
174 {
175  PWM2_SFRS->WIDTHLOW = width & 0xFF;
176  PWM2_SFRS->EXT.PERIODHIGH = (width >> 8) & 0x0F;
177 }
178 
184 static __INLINE void f_PWM2_SetPreScaler(uint8_t div)
185 {
186  PWM2_SFRS->CTRL.PRESC = div;
187 }
188 
192 static __INLINE void f_PWM2_InvertOn(void)
193 {
194  PWM2_SFRS->CTRL.INV = 1;
195 }
196 
200 static __INLINE void f_PWM2_InvertOff(void)
201 {
202  PWM2_SFRS->CTRL.INV = 0;
203 }
204 
208 static __INLINE void f_PWM2_Enable(void)
209 {
210  PWM2_SFRS->CTRL.EN = 1;
211 }
212 
216 static __INLINE void f_PWM2_Disable(void)
217 {
218  PWM2_SFRS->CTRL.EN = 0;
219 }
220 
221 #endif /* __PWM_SFRS_H__ */
static __INLINE void f_PWM1_InvertOff(void)
Disable on inverter for PWM1.
Definition: pwm_sfrs.h:97
#define PWM1_SFRS
The starting address of PWM1 SFRS.
Definition: pwm_sfrs.h:43
uint8_t WIDTHLOW
Definition: pwm_sfrs.h:30
static __INLINE void f_PWM1_SetPreScaler(uint8_t div)
Set clock pre-scaler for PWM1.
Definition: pwm_sfrs.h:81
static __INLINE void f_PWM1_Disable(void)
Disable PWM1.
Definition: pwm_sfrs.h:113
static __INLINE void f_PWM1_InvertOn(void)
Enable on inverter for PWM1.
Definition: pwm_sfrs.h:89
static __INLINE void f_PWM1_SetWidth(uint32_t width)
Set width for PWM1.
Definition: pwm_sfrs.h:70
uint8_t BYTE
Definition: pwm_sfrs.h:36
uint8_t BYTE
Definition: pwm_sfrs.h:139
static __INLINE void f_PWM2_SetPeriod(uint32_t period)
Set period for PWM2.
Definition: pwm_sfrs.h:162
A structure to represent Special Function Registers for PWM2.
Definition: pwm_sfrs.h:121
static __INLINE void f_PWM2_InvertOff(void)
Disable on inverter for PWM2.
Definition: pwm_sfrs.h:200
static __INLINE void f_PWM2_Enable(void)
Enable PWM2.
Definition: pwm_sfrs.h:208
static __INLINE void f_PWM2_SetWidth(uint32_t width)
Set width for PWM2.
Definition: pwm_sfrs.h:173
uint8_t WIDTHLOW
Definition: pwm_sfrs.h:133
uint8_t CTRL
Definition: pwm_sfrs.h:130
static __INLINE void f_PWM1_Enable(void)
Enable PWM1.
Definition: pwm_sfrs.h:105
uint8_t PERIODLOW
Definition: pwm_sfrs.h:132
A structure to represent Special Function Registers for PWM1.
Definition: pwm_sfrs.h:18
static __INLINE void f_PWM2_InvertOn(void)
Enable on inverter for PWM2.
Definition: pwm_sfrs.h:192
uint8_t CTRL
Definition: pwm_sfrs.h:27
static __INLINE void f_PWM2_Disable(void)
Disable PWM2.
Definition: pwm_sfrs.h:216
static __INLINE void f_PWM1_SetPeriod(uint32_t period)
Set period for PWM1.
Definition: pwm_sfrs.h:59
uint8_t PERIODLOW
Definition: pwm_sfrs.h:29
#define PWM2_SFRS
The starting address of PWM2 SFRS.
Definition: pwm_sfrs.h:146
static __INLINE void f_PWM2_SetPreScaler(uint8_t div)
Set clock pre-scaler for PWM2.
Definition: pwm_sfrs.h:184