123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include <soc.h>
- #include <linker/linker-defs.h>
- typedef struct {
- volatile uint32_t TRIGGER_EN;
- volatile uint32_t TRIGGER_EN1;
- volatile uint32_t TRIGGER_PD;
- volatile uint32_t TRIGGER_PD1;
- volatile uint32_t PPI_CH_CFG[12];
- } WIC_Type;
- #define WIC ((WIC_Type*) WIC_BASE)
- #define WIC_PPI_CH_CFG_CH_EN_Pos (31UL)
- #define WIC_PPI_CH_CFG_CH_EN_Msk (0x80000000UL)
- #define WIC_PPI_CH_CFG_TASK_SEL_Pos (8UL)
- #define WIC_PPI_CH_CFG_TASK_SEL_Msk (0x1f00UL)
- #define WIC_PPI_CH_CFG_TRIGGER_SEL_Pos (0UL)
- #define WIC_PPI_CH_CFG_TRIGGER_SEL_Msk (0x3fUL)
- static __sleepfunc int ppi_trig_src_mapping(int trig_src)
- {
- if (trig_src <= TIMER4) {
- return trig_src;
- } else if (trig_src <= IO11_IRQ) {
- return (trig_src - IO0_IRQ + 16);
- } else if (trig_src <= SPIMT1_TASK7_CIP) {
- return (trig_src - SPIMT0_TASK0_CIP + 32);
- } else if (trig_src <= I2CMT0_TASK3_CIP) {
- return (trig_src - I2CMT0_TASK0_CIP + 48);
- } else {
- return (trig_src - I2CMT1_TASK0_CIP + 56);
- }
- }
- void ppi_init(void)
- {
- int ch;
-
-
- WIC->TRIGGER_EN = 0;
- WIC->TRIGGER_EN1 = 0;
-
- WIC->TRIGGER_PD = WIC->TRIGGER_PD;
- WIC->TRIGGER_PD1 = WIC->TRIGGER_PD1;
-
- for (ch = PPI_CH0; ch <= PPI_CH11; ch ++) {
- WIC->PPI_CH_CFG[ch] &= ~WIC_PPI_CH_CFG_CH_EN_Msk;
- }
- }
- void ppi_trig_src_en(int trig_src, int enable)
- {
- int bit_offset = ppi_trig_src_mapping(trig_src);
-
-
- if (bit_offset < 32) {
- if (enable) {
- WIC->TRIGGER_EN |= (1 << bit_offset);
- } else {
- WIC->TRIGGER_EN &= ~(1 << bit_offset);
- }
- } else {
- if (enable) {
- WIC->TRIGGER_EN1 |= (1 << (bit_offset - 32));
- } else {
- WIC->TRIGGER_EN1 &= ~(1 << (bit_offset - 32));
- }
- }
- }
- void ppi_task_trig_config(int ppi_channel, int task_select, int trig_src_select)
- {
-
- WIC->PPI_CH_CFG[ppi_channel] &= ~WIC_PPI_CH_CFG_CH_EN_Msk;
- WIC->PPI_CH_CFG[ppi_channel] |= ((unsigned int)0 << WIC_PPI_CH_CFG_CH_EN_Pos);
-
-
- WIC->PPI_CH_CFG[ppi_channel] &= ~WIC_PPI_CH_CFG_TASK_SEL_Msk;
- WIC->PPI_CH_CFG[ppi_channel] |= (task_select << WIC_PPI_CH_CFG_TASK_SEL_Pos);
-
-
- WIC->PPI_CH_CFG[ppi_channel] &= ~WIC_PPI_CH_CFG_TRIGGER_SEL_Msk;
- WIC->PPI_CH_CFG[ppi_channel] |= (trig_src_select << WIC_PPI_CH_CFG_TRIGGER_SEL_Pos);
-
-
- WIC->PPI_CH_CFG[ppi_channel] &= ~WIC_PPI_CH_CFG_CH_EN_Msk;
- WIC->PPI_CH_CFG[ppi_channel] |= ((unsigned int)1 << WIC_PPI_CH_CFG_CH_EN_Pos);
- }
- int ppi_trig_src_is_pending(int ppi_trig_src)
- {
- int bit_offset = ppi_trig_src_mapping(ppi_trig_src);
- int pending;
-
- if (bit_offset < 32) {
- pending = (WIC->TRIGGER_PD & (1 << bit_offset));
- } else {
- pending = (WIC->TRIGGER_PD1 & (1 << (bit_offset - 32)));
- }
-
- return pending;
- }
- __sleepfunc void ppi_trig_src_clr_pending(int ppi_trig_src)
- {
- int bit_offset = ppi_trig_src_mapping(ppi_trig_src);
-
- if (bit_offset < 32) {
- WIC->TRIGGER_PD = (1 << bit_offset);
- } else {
- WIC->TRIGGER_PD1 = (1 << (bit_offset - 32));
- }
-
- return;
- }
|