• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "hpm_gptmr_drv.h"
9 
gptmr_channel_get_default_config(GPTMR_Type * ptr,gptmr_channel_config_t * config)10 void gptmr_channel_get_default_config(GPTMR_Type *ptr, gptmr_channel_config_t *config)
11 {
12     config->mode = gptmr_work_mode_no_capture;
13     config->dma_request_event = gptmr_dma_request_disabled;
14     config->synci_edge = gptmr_synci_edge_none;
15     for (uint8_t i = 0; i < GPTMR_CH_CMP_COUNT; i++) {
16         config->cmp[i] = 0;
17     }
18     config->reload = 0xFFFFFFFFUL;
19     config->cmp_initial_polarity_high = true;
20     config->enable_cmp_output = true;
21     config->enable_sync_follow_previous_channel = false;
22     config->enable_software_sync = false;
23     config->debug_mode = true;
24 }
25 
gptmr_channel_config(GPTMR_Type * ptr,uint8_t ch_index,gptmr_channel_config_t * config,bool enable)26 hpm_stat_t gptmr_channel_config(GPTMR_Type *ptr,
27                          uint8_t ch_index,
28                          gptmr_channel_config_t *config,
29                          bool enable)
30 {
31     uint32_t v = 0;
32     if ((config->enable_sync_follow_previous_channel && !ch_index) || (config->reload == 0)) {
33         return status_invalid_argument;
34     }
35 
36     if (config->dma_request_event != gptmr_dma_request_disabled) {
37         v |= GPTMR_CHANNEL_CR_DMAEN_MASK
38             | GPTMR_CHANNEL_CR_DMASEL_SET(config->dma_request_event);
39     }
40     v |= GPTMR_CHANNEL_CR_CAPMODE_SET(config->mode)
41         | GPTMR_CHANNEL_CR_DBGPAUSE_SET(config->debug_mode)
42         | GPTMR_CHANNEL_CR_SWSYNCIEN_SET(config->enable_software_sync)
43         | GPTMR_CHANNEL_CR_CMPINIT_SET(config->cmp_initial_polarity_high)
44         | GPTMR_CHANNEL_CR_SYNCFLW_SET(config->enable_sync_follow_previous_channel)
45         | GPTMR_CHANNEL_CR_CMPEN_SET(config->enable_cmp_output)
46         | GPTMR_CHANNEL_CR_CEN_SET(enable)
47         | config->synci_edge;
48 
49     for (uint8_t i = 0; i < GPTMR_CH_CMP_COUNT; i++) {
50         ptr->CHANNEL[ch_index].CMP[i] = GPTMR_CMP_CMP_SET(config->cmp[i]);
51     }
52     ptr->CHANNEL[ch_index].RLD = GPTMR_CHANNEL_RLD_RLD_SET(config->reload - 1);
53     ptr->CHANNEL[ch_index].CR = v;
54     return status_success;
55 }
56