void tpm_engine_first_time() { //create_tpmdata_files(); tpm_init_data(); set_permanent_flags(); TPM_Init(TPM_ST_CLEAR); save_flags(); }
int main(int argc, char *argv[]) { int ret = 0; int i; /* argc iterator */ TPM_setlog(0); /* turn off verbose output */ for (i=1 ; i<argc ; i++) { if (!strcmp(argv[i], "-h")) { printUsage(); } else if (!strcmp(argv[i], "-v")) { TPM_setlog(1); } else { printf("\n%s is not a valid option\n", argv[i]); printUsage(); } } if (ret == 0) { ret = TPM_Init(); if (ret != 0) { printf("Error %s from TPM_Init.\n", TPM_GetErrMsg(ret)); } } exit(ret); }
void pwmout_init(pwmout_t* obj, PinName pin) { PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); MBED_ASSERT(pwm != (PWMName)NC); obj->pwm_name = pwm; uint32_t pwm_base_clock; /* Set the TPM clock source to be IRC 48M */ CLOCK_SetTpmClock(1U); pwm_base_clock = CLOCK_GetFreq(kCLOCK_McgIrc48MClk); float clkval = (float)pwm_base_clock / 1000000.0f; uint32_t clkdiv = 0; while (clkval > 1) { clkdiv++; clkval /= 2.0f; if (clkdiv == 7) { break; } } pwm_clock_mhz = clkval; uint32_t channel = pwm & 0xF; uint32_t instance = pwm >> TPM_SHIFT; tpm_config_t tpmInfo; TPM_GetDefaultConfig(&tpmInfo); tpmInfo.prescale = (tpm_clock_prescale_t)clkdiv; /* Initialize TPM module */ TPM_Init(tpm_addrs[instance], &tpmInfo); tpm_chnl_pwm_signal_param_t config = { .chnlNumber = (tpm_chnl_t)channel, .level = kTPM_HighTrue, .dutyCyclePercent = 0, }; // default to 20ms: standard for servos, and fine for e.g. brightness control TPM_SetupPwm(tpm_addrs[instance], &config, 1, kTPM_EdgeAlignedPwm, 50, pwm_base_clock); TPM_StartTimer(tpm_addrs[instance], kTPM_SystemClock); // Wire pinout pinmap_pinout(pin, PinMap_PWM); } void pwmout_free(pwmout_t* obj) { TPM_Deinit(tpm_addrs[obj->pwm_name >> TPM_SHIFT]); }
void PWM_Init(uint8_t instance) { #if FSL_FEATURE_SOC_FTM_COUNT ftm_config_t config; FTM_GetDefaultConfig(&config); FTM_Init(mFtmBase[instance], &config); /* Enable TPM compatibility. Free running counter and synchronization compatible with TPM */ mFtmBase[instance]->MODE &= ~(FTM_MODE_FTMEN_MASK); FTM_StartTimer(mFtmBase[instance], kFTM_SystemClock); #else tpm_config_t config; TPM_GetDefaultConfig(&config); TPM_Init(mTpmBase[instance], &config); TPM_StartTimer(mTpmBase[instance], kTPM_SystemClock); #endif }
// Función principal void main(void) { // Inicialización SYSTEM_INIT(); MCG_Init(); LCD_Init(); TPM_Init(); SCI_Init(); CLI; RealTimeClock_Init(); for(;;) { SEI; if(INT_EVENTS==0)WAIT; CLI; Process_Events(); } }
/************************************************************************************ ************************************************************************************* * Public functions ************************************************************************************* ************************************************************************************/ void StackTimer_Init(void (*cb)(void)) { IRQn_Type irqId; #if FSL_FEATURE_SOC_FTM_COUNT FTM_Type *ftmBaseAddr = (FTM_Type*)mFtmBase[gStackTimerInstance_c]; FTM_Init(ftmBaseAddr, &mFtmConfig); FTM_StopTimer(ftmBaseAddr); ftmBaseAddr->MOD = 0xFFFF; /* Configure channel to Software compare; output pin not used */ FTM_SetupOutputCompare(ftmBaseAddr, (ftm_chnl_t)gStackTimerChannel_c, kFTM_NoOutputSignal, 0x01); /* Install ISR */ irqId = mFtmIrqId[gStackTimerInstance_c]; FTM_EnableInterrupts(ftmBaseAddr, kFTM_TimeOverflowInterruptEnable | (1 << gStackTimerChannel_c)); #else TPM_Type *tpmBaseAddr = (TPM_Type*)mTpmBase[gStackTimerInstance_c]; TPM_Init(tpmBaseAddr, &mTpmConfig); TPM_StopTimer(tpmBaseAddr); /* Set the timer to be in free-running mode */ tpmBaseAddr->MOD = 0xFFFF; /* Configure channel to Software compare; output pin not used */ TPM_SetupOutputCompare(tpmBaseAddr, (tpm_chnl_t)gStackTimerChannel_c, kTPM_NoOutputSignal, 0x01); /* Install ISR */ irqId = mTpmIrqId[gStackTimerInstance_c]; TPM_EnableInterrupts(tpmBaseAddr, kTPM_TimeOverflowInterruptEnable | (1 << gStackTimerChannel_c)); #endif /* Overwrite old ISR */ OSA_InstallIntHandler(irqId, cb); /* set interrupt priority */ NVIC_SetPriority(irqId, gStackTimer_IsrPrio_c >> (8 - __NVIC_PRIO_BITS)); NVIC_ClearPendingIRQ(irqId); NVIC_EnableIRQ(irqId); }
void us_ticker_init(void) { /* Common for ticker/timer. */ uint32_t busClock; /* Structure to initialize PIT. */ pit_config_t pitConfig; if (us_ticker_inited) { /* calling init again should cancel current interrupt */ TPM_DisableInterrupts(TPM2, kTPM_TimeOverflowInterruptEnable); return; } PIT_GetDefaultConfig(&pitConfig); PIT_Init(PIT, &pitConfig); busClock = CLOCK_GetFreq(kCLOCK_BusClk); PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, busClock / 1000000 - 1); PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, 0xFFFFFFFF); PIT_SetTimerChainMode(PIT, kPIT_Chnl_1, true); PIT_StartTimer(PIT, kPIT_Chnl_0); PIT_StartTimer(PIT, kPIT_Chnl_1); /* Configure interrupt generation counters and disable ticker interrupts. */ tpm_config_t tpmConfig; TPM_GetDefaultConfig(&tpmConfig); /* Set to Div 32 to get 1MHz clock source for TPM */ tpmConfig.prescale = kTPM_Prescale_Divide_32; TPM_Init(TPM2, &tpmConfig); NVIC_SetVector(TPM2_IRQn, (uint32_t)tpm_isr); NVIC_EnableIRQ(TPM2_IRQn); us_ticker_inited = true; }
/*! * @brief Main function */ int main(void) { tpm_config_t tpmInfo; tpm_chnl_pwm_signal_param_t tpmParam; tpm_pwm_level_select_t pwmLevel = kTPM_LowTrue; /* Configure tpm params with frequency 24kHZ */ tpmParam.chnlNumber = (tpm_chnl_t)BOARD_TPM_CHANNEL; tpmParam.level = pwmLevel; tpmParam.dutyCyclePercent = updatedDutycycle; /* Board pin, clock, debug console init */ BOARD_InitPins(); BOARD_BootClockRUN(); BOARD_InitDebugConsole(); /* Select the clock source for the TPM counter as kCLOCK_PllFllSelClk */ CLOCK_SetTpmClock(1U); /* Print a note to terminal */ PRINTF("\r\nTPM example to output center-aligned PWM signal\r\n"); PRINTF("\r\nYou will see a change in LED brightness if an LED is connected to the TPM pin"); PRINTF("\r\nIf no LED is connected to the TPM pin, then probe the signal using an oscilloscope"); TPM_GetDefaultConfig(&tpmInfo); /* Initialize TPM module */ TPM_Init(BOARD_TPM_BASEADDR, &tpmInfo); TPM_SetupPwm(BOARD_TPM_BASEADDR, &tpmParam, 1U, kTPM_CenterAlignedPwm, 24000U, TPM_SOURCE_CLOCK); /* Enable channel interrupt flag.*/ TPM_EnableInterrupts(BOARD_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE); /* Enable at the NVIC */ EnableIRQ(TPM_INTERRUPT_NUMBER); TPM_StartTimer(BOARD_TPM_BASEADDR, kTPM_SystemClock); while (1) { /* Use interrupt to update the PWM dutycycle */ if (true == tpmIsrFlag) { /* Disable interrupt to retain current dutycycle for a few seconds */ TPM_DisableInterrupts(BOARD_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE); tpmIsrFlag = false; /* Disable channel output before updating the dutycycle */ TPM_UpdateChnlEdgeLevelSelect(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, 0U); /* Update PWM duty cycle */ TPM_UpdatePwmDutycycle(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, kTPM_CenterAlignedPwm, updatedDutycycle); /* Start channel output with updated dutycycle */ TPM_UpdateChnlEdgeLevelSelect(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, pwmLevel); /* Delay to view the updated PWM dutycycle */ delay(); /* Enable interrupt flag to update PWM dutycycle */ TPM_EnableInterrupts(BOARD_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE); } } }
void DelayManager_Init(void) { //Set up default TMP configuration TPM_Init(); TPM_SetMicroSecPFlag(1930); }