📄 icg.c
字号:
/************************************************************************************
* This module contains code for the ICG (Internal Clock Generator) module.
*
* Note! Support for selecting external crystal and external clock source from Abel 2.0
*
*
* (c) Copyright 2006, Freescale Semiconductor, Inc. All rights reserved.
*
* Freescale Confidential Proprietary
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
************************************************************************************/
#include "EmbeddedTypes.h"
#include "PowerManager.h"
#include "ICG.h"
#if !defined BOOTLOADER_ENABLED || !defined FOR_BOOTLOADER_ONLY
#else
#include "Application_interface.h"
#endif FOR_BOOTLOADER_ONLY
// **************************************************************************
// **************************************************************************
#pragma MESSAGE DISABLE C4200 // Warning C4200: Other segment than in previous declaration
#pragma DATA_SEG BOOTLOADER_VARIABLES
// Global variables
volatile bool_t init_mode = TRUE;
#pragma DATA_SEG DEFAULT
// **************************************************************************
#pragma DATA_SEG SLEEP_VARIABLE
uint8_t gPowerSaveMode;
#pragma DATA_SEG DEFAULT
void ICG_Setup(void)
{
uint8_t loop_counter;
SETUP_LED_PORT
SET_LED1 // Show entry in function
SET_LED2 // Cleared first time in loop
CLEAR_LED3
CLEAR_LED4
if(gPowerSaveMode == 0)
{
// Not in power save mode
// Loop until clock is locked
for(;;)
{
TOGGLE_LED2
if((ICGS1 & ICG_IRQ_PENDING) == ICG_IRQ_PENDING)
ICGS1 |= ICG_IRQ_PENDING; // Clear FLL lost lock interrupt
if(init_mode == FALSE)
{
TOGGLE_LED3
// Is filter value drifting?
if(ICGFLTH > ICGFLTH_VALUE_8MHZ)
{
TOGGLE_LED4
SCM_8MHZ_DEFAULT_ICG_FILTER
WAIT_FOR_STABLE_CLOCK
}
SELECT_SCM_MODE // DO NOT CALL THIS CODE UNDER INIT
WAIT_FOR_STABLE_CLOCK
}
else
init_mode = FALSE; // Only one time under init
SETUP_ABEL_CLOCK
WAIT_FOR_STABLE_CLOCK
SETUP_ICG_MODULE
WAIT_FOR_STABLE_CLOCK
loop_counter = LOOP_COUNTER_VALUE;
// Wait for clock to lock
while(!ICG_IsFllLocked() && loop_counter-- > 0);
// Check exit condition
if(ICG_IsFllLocked())
break; // Clock is locked - get out
}
}
else
{
// In power save mode - set SCM clock.
SCM_2MHZ_ICG_FILTER
}
MEASURING_BUS_CLOCK
CLEAR_LED1 // Show exit of function
}
// **************************************************************************
// **************************************************************************
void PowerManager_WaitForPowerUp(void)
{
ICG_Setup(); // Reuse code in function to reduce code size
}
// **************************************************************************
__interrupt void FLL_Lost_Lock_ISR(void)
{
// Setup ICG module again to prevent that system hangs forever.
ICGS1 |= 0x01; // Clear FLL lost lock interrupt
// Ensure MCU clk is stable
PowerManager_WaitForPowerUp();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -