123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- #ifndef __PWM__H__
- #define __PWM__H__
- #include "types.h"
- #include "gpio.h"
- #include "common.h"
- #define PWM_CH_BASE 0x4000E004UL
- #define PWM_CTL0_ADDR(n) (PWM_CH_BASE + n*12)
- #define PWM_CTL1_ADDR(n) (PWM_CH_BASE + 4 + n*12)
- #define PWM_ENABLE_ALL do{\
- *(volatile unsigned int *) 0x4000e000 |= BIT(0);\
- *(volatile unsigned int *) 0x4000e000 |= BIT(4);\
- }while(0)
- #define PWM_DISABLE_ALL do{\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(0);\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(4);\
- }while(0)
- #define PWM_ENABLE_CH_012 do{\
- *(volatile unsigned int *) 0x4000e000 |= BIT(8);\
- *(volatile unsigned int *) 0x4000e000 |= BIT(9);\
- }while(0)
- #define PWM_DISABLE_CH_012 do{\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(8);\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(9);\
- }while(0)
- #define PWM_ENABLE_CH_345 do{\
- *(volatile unsigned int *) 0x4000e000 |= BIT(10);\
- *(volatile unsigned int *) 0x4000e000 |= BIT(11);\
- }while(0)
- #define PWM_DISABLE_CH_345 do{\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(10);\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(11);\
- }while(0)
- #define PWM_ENABLE_CH_01 do{\
- *(volatile unsigned int *) 0x4000e000 |= BIT(12);\
- *(volatile unsigned int *) 0x4000e000 |= BIT(13);\
- }while(0)
- #define PWM_DISABLE_CH_01 do{\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(12);\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(13);\
- }while(0)
- #define PWM_ENABLE_CH_23 do{\
- *(volatile unsigned int *) 0x4000e000 |= BIT(14);\
- *(volatile unsigned int *) 0x4000e000 |= BIT(15);\
- }while(0)
- #define PWM_DISABLE_CH_23 do{\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(14);\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(15);\
- }while(0)
- #define PWM_ENABLE_CH_45 do{\
- *(volatile unsigned int *) 0x4000e000 |= BIT(16);\
- *(volatile unsigned int *) 0x4000e000 |= BIT(17);\
- }while(0)
- #define PWM_DISABLE_CH_45 do{\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(16);\
- *(volatile unsigned int *) 0x4000e000 &= ~BIT(17);\
- }while(0)
-
- #define PWM_INSTANT_LOAD_CH(n) subWriteReg(PWM_CTL0_ADDR(n),31,31,1)
- #define PWM_NO_INSTANT_LOAD_CH(n) subWriteReg(PWM_CTL0_ADDR(n),31,31,0)
- #define PWM_LOAD_CH(n) subWriteReg(PWM_CTL0_ADDR(n),16,16,1)
- #define PWM_NO_LOAD_CH(n) subWriteReg(PWM_CTL0_ADDR(n),16,16,0)
- #define PWM_SET_DIV(n,v) subWriteReg(PWM_CTL0_ADDR(n),14,12,v)
- #define PWM_SET_MODE(n,v) subWriteReg(PWM_CTL0_ADDR(n),8,8,v)
- #define PWM_SET_POL(n,v) subWriteReg(PWM_CTL0_ADDR(n),4,4,v)
- #define PWM_ENABLE_CH(n) subWriteReg(PWM_CTL0_ADDR(n),0,0,1)
- #define PWM_DISABLE_CH(n) subWriteReg(PWM_CTL0_ADDR(n),0,0,0)
-
- #define PWM_SET_CMP_VAL(n,v) subWriteReg(PWM_CTL1_ADDR(n),31,16,v)
- #define PWM_SET_TOP_VAL(n,v) subWriteReg(PWM_CTL1_ADDR(n),15,0,v)
- #define PWM_GET_CMP_VAL(n) ((read_reg(PWM_CTL1_ADDR(n)) & 0xFFFF0000) >> 8)
- #define PWM_GET_TOP_VAL(n) read_reg(PWM_CTL1_ADDR(n)) & 0x0000FFFF
- typedef enum{
-
- PWM_CH0 = 0,
- PWM_CH1 = 1,
- PWM_CH2 = 2,
- PWM_CH3 = 3,
- PWM_CH4 = 4,
- PWM_CH5 = 5
-
- }PWMN_e;
- typedef enum{
-
- PWM_CLK_NO_DIV = 0,
- PWM_CLK_DIV_2 = 1,
- PWM_CLK_DIV_4 = 2,
- PWM_CLK_DIV_8 = 3,
- PWM_CLK_DIV_16 = 4,
- PWM_CLK_DIV_32 = 5,
- PWM_CLK_DIV_64 = 6,
- PWM_CLK_DIV_128 = 7
-
- }PWM_CLK_DIV_e;
- typedef enum{
-
- PWM_CNT_UP = 0,
- PWM_CNT_UP_AND_DOWN = 1
-
- }PWM_CNT_MODE_e;
- typedef enum{
-
- PWM_POLARITY_RISING = 0,
- PWM_POLARITY_FALLING = 1
-
- }PWM_POLARITY_e;
- void hal_pwm_init(PWMN_e pwmN, PWM_CLK_DIV_e pwmDiv,
- PWM_CNT_MODE_e pwmMode, PWM_POLARITY_e pwmPolarity);
- void hal_pwm_open_channel(PWMN_e pwmN,GPIO_Pin_e pwmPin);
- void hal_pwm_close_channel(PWMN_e pwmN);
- void hal_pwm_destroy(PWMN_e pwmN);
- void hal_pwm_set_count_val(PWMN_e pwmN, uint16_t cmpVal, uint16_t cntTopVal);
- void hal_pwm_start(void);
- void hal_pwm_stop(void);
- typedef struct
- {
- PWMN_e pwmN;
- GPIO_Pin_e pwmPin;
- PWM_CLK_DIV_e pwmDiv;
- PWM_CNT_MODE_e pwmMode;
- PWM_POLARITY_e pwmPolarity;
- uint16_t cmpVal;
- uint16_t cntTopVal;
-
- } pwm_ch_t;
- void hal_pwm_module_init(void);
- void hal_pwm_module_deinit(void);
- void hal_pwm_ch_start(pwm_ch_t ch);
- void hal_pwm_ch_stop(pwm_ch_t ch);
- #endif
|