This section describes the programming interface of the CMT Peripheral driver. The CMT driver configures and uses CMT hardware. It supports module initializations and CMT module configurations.
CMT Clock formulas
CMT clock frequency = bus_clock_Hz / (bus_clock_Hz / 8 MHz) / cmtDivider
CMT carrier and generator frequency = CMT Clock frequency / (highCount1 + lowCount1) (In FSK mode, the second frequency = CMT Clock frequency / (highCount2 + lowCount2))
In Time and Baseband mode CMT IRO signal mark time = (markCount + 1) / (CMT Clock frequency / 8)
CMT IRO signal space time = spaceCount / (CMT Clock frequency / 8)
In FSK mode CMT IRO signal mark time = (markCount + 1) / CMT carrier and generator frequency
CMT IRO signal space time = spaceCount / CMT carrier and generator frequency
CMT Initialization
To initialize the CMT driver, define an cmt_base_config_t type variable and pass it in the CMT_DRV_Init() function. The initialize setting the CMT clock, interrupt and the IRO signal for the CMT module.
This is an example code to initialize and configure the driver:
isInterruptEnabled = enable,
isIroEnabled = true,
};
CMT Carrier generator and Modulator Start
To Start the CMT carrier and modulator, define an cmt_modulate_config_t type variable and pass it in the CMT_DRV_StartCarrierModulate() function. The carrier and modulation start configuring the CMT mode, generating protocol timing, or carrier signal data.
typedef struct CmtModulateConfig
{
uint8_t highCount1;
uint8_t lowCount1;
uint8_t highCount2;
uint8_t lowCount2;
uint16_t markCount;
uint16_t spaceCount;
typedef struct CmtModulateData {
uint8_t *data;
uint32_t len;
uint32_t lenDone;
uint16_t markOne;
uint16_t spaceOne;
uint16_t markZero;
uint16_t spaceZero;
This is an example code to start the driver:
highCount1 = 1,
lowCount1 = 1,
markCount = 9,
spaceCount = 0,
};
uint8_t newData[2] = {0x85, 0x14};
.data = newData,
.len = 15,
.markOne = 8,
.spaceOne = 0,
.markZero = 0,
.spaceZero = 8
};
For the settings above, the IRO output signal is a 4 MHz signal with 50% duty cycle when the Bus clock is 48 MHz.
CMT DATA Modulate
The CMT_DRV_ModulateDataByBit() is provided to modulate data and should be called by the ISR handler.
When handling CMT initialization, define a global cmt_modulate_data_t type variable modData, define a cmt_modulate_config_t type variable, and define the MSB/LSB mode then pass it in the CMT_DRV_StartCarrierModulate() function.
After the data modulation is complete, call the void CMT_DRV_StopCarrierModulate(uint32_t instance) function to stop it at any time.
To close the CMT module entirely, call the cmt_status_t CMT_DRV_Deinit(uint32_t instance) function. This disables both the CMT carrier modulator and the clock gate.
|
CMT_Type *const | g_cmtBase [] |
| Table of base addresses for CMT instances. More...
|
|
const IRQn_Type | g_cmtIrqId [] |
| Table to save CMT IRQ enumeration numbers defined in the CMSIS header file.
|
|
Defines a basic configure structure CmtBaseConfig and uses the CMT_DRV_Init() function to make necessary initializations.
struct cmt_modulate_data_t |
Defines a data structure for CMT data modulation.
struct cmt_modulate_config_t |
Defines a specific configuration structure CmtModulateConfig and uses the CMT_DRV_StartCarrierModulate() function to initialize and start carrier generator and modulator. Stores the transmitted data information to the global variable for data modulation.
Data Fields |
cmt_mode_t | mode |
| < Choose these mode for carrier and modulator enabled, kCMTDirectIROCtl should not used here More...
|
|
The high and low time for the carrier signal
This function must be called before calling all the other CMT driver functions. This function ungates the CMT clock and sets the CMT clock, interrupt, and output signal for CMT module. Pass in its basic configuration structure.
- Parameters
-
instance | CMT module instance number. |
config | The CMT basic configuration structure. |
- Returns
- Error or success status returned by API.
This function disables all CMT interrupts and CMT clock. It, then, gates the CMT clock control. CMT_DRV_Init must be called if you want to use CMT again.
- Parameters
-
instance | CMT module instance number. |
- Returns
- Error or success status returned by API.
This function un-gates the CMT carrier generator and modulator clock, initializes, and starts the modulator and carrier generator. Pass in the modulation specific configuration structure. CMT_DRV_Init should be called before using this function.
- Parameters
-
instance | CMT module instance number. |
modulateConfig | The CMT modulator specific configuration structure. |
cmtData | The data to be modulated. |
isMsbMode | The MSB or LSB mode for the byte transmit
- true, The MSB mode.
- false, The LSB mode.
|
void CMT_DRV_StopCarrierModulate |
( |
uint32_t |
instance | ) |
|
This function stops and disables the CMT carrier generator and modulator. When the CMT carrier generator and modulator is disabled the IRO signal can be controlled directly by calling the CMT_DRV_SetIroCtl.
- Parameters
-
instance | CMT module instance number. |
This function can be called by the CMT ISR handler to handle data modulation by using ISR handler to change the modulation mark and space time period according to the data bit "1" or bit "0" each time. Note: the modulation updates the mark and space time period at the end of every modulation cycle, irrespective of interrupt handling. To update the new mark and space time period in time, this function should be processed in one modulation cycle. When tested for Bare Metal, the function called by the ISR handler takes about 4 µs and the maximum bit rate is about 250000.
- Parameters
-
instance | CMT module instance number. |
cmtData | The data to be modulated. |
isMsbMode | The MSB or LSB mode for the byte transmit.
- true, The MSB mode.
- false, The LSB mode.
|
void CMT_DRV_SetMode |
( |
uint32_t |
instance, |
|
|
cmt_mode_t |
mode |
|
) |
| |
This function selects the mode for CMT.
- Parameters
-
base | Base address for current CMT instance. |
mode | Selection of CMT feature mode enumeration. See to "cmt_mode_t" |
This function gets the mode of CMT module.
- Parameters
-
base | Base address for current CMT instance. |
- Returns
- The mode of CMT module. See to "cmt_mode_t".
This function sets the CMT clock divider.
- Parameters
-
instance | CMT module instance number. |
spsDiv | The CMT clock divider prescaler. The CMT carrier generator resolution is 8 Mhz/(2 ^ spsDiv) . spsDiv should be a integer range between 0 ~ 3 representing the divisor 1,2,4 and 8 (See "cmt_second_clkdiv_t"). |
bool CMT_DRV_IsEndofCycle |
( |
uint32_t |
instance | ) |
|
This flag is set at the end of each cycle.
- Parameters
-
instance | CMT module instance number. |
channel | Timer channel number |
- Returns
- The status of the end of cycle flag
- true: The end of cycle has occurred.
- false: The end of cycle has not yet occurred.
void CMT_DRV_ClearEndofCycleFlag |
( |
uint32_t |
instance, |
|
|
uint32_t |
markCount |
|
) |
| |
Clears the end of cycle status flag by reading the MSC followed by and access of the lower eight bit of the modulator mark or space counter. Note that this is not for clearing the end of cycle status flag when the CMT DMA is enabled.
- Parameters
-
instance | CMT module instance number. |
markCount | The number of clock period for CMT modulator signal mark period, in the range of 0 ~ 0xFFFF. |
void CMT_DRV_SetModulateMarkCount |
( |
uint32_t |
instance, |
|
|
uint32_t |
markCount |
|
) |
| |
This function sets the mark time period of the CMT modulator counter to control the mark time of the output modulated signal from the carrier generator output signal. If the CMT clock frequency is Fcmt and the carrier out signal frequency is fcg:
- In Time and Baseband mode: The mark period of the generated signal equals (markCount + 1) / (Fcmt/8).
- In FSK mode:The mark period of the generated signal equals (markCount + 1) / fcg.
- Parameters
-
instance | CMT module instance number. |
markCount | The number of clock period for CMT modulator signal mark period, in the range of 0 ~ 0xFFFF. |
void CMT_DRV_SetModulateSpaceCount |
( |
uint32_t |
instance, |
|
|
uint32_t |
spaceCount |
|
) |
| |
This function sets the mark time period of the CMT modulator counter to control the space time of the output modulated signal from the carrier generator output signal. If the CMT clock frequency is Fcmt and the carrier out signal frequency is fcg:
- In Time and Baseband mode: The space period of the generated signal equals spaceCount / (Fcmt/8).
- In FSK mode:The space period of the generated signal equals spaceCount / fcg.
- Parameters
-
instance | CMT module instance number. |
spaceCount | The number of clock period for CMT modulator signal space period, in the range of 0 ~ 0xFFFF. |
void CMT_DRV_SetIroCtl |
( |
uint32_t |
instance, |
|
|
cmt_iro_ctl_t |
ctlVal |
|
) |
| |
Changes the states of the IRO signal when the kCMTDirectIROMode mode is set and the IRO signal is enabled.
- Parameters
-
base | Base address for current CMT instance. |
ctlVal | The control of the IRO signal. See "_cmt_iro_ctl_t" |
bool CMT_DRV_GetIrolatchState |
( |
uint32_t |
instance | ) |
|
- Parameters
-
base | Base address for current CMT instance. |
- Returns
- The states of the IRO latch
CMT_Type* const g_cmtBase[] |