⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlfunctions.c

📁 freescale最新的16位单片机
💻 C
字号:
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2005 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
*******************************************************************************
*
* @file      controlfunctions.c
*
* @author    r89994
* 
* @version   1.0.0.0
* 
* @date      Mar-27-2006
* 
* @brief     Here are functions used in execute.c switch
*
********************************************************************************/
#include "main.h"
#include "controlfunctions.h"
#include "spi.h"
#include "hidef.h"


/********************************************************************************
*																		Global Variables
*********************************************************************************/
extern Byte     fm_status, fm_task, fm_action0, fm_action1, fm_action2, fm_action3,
                fm_action4, fm_action5, fm_action6, fm_action7, fm_action8, fm_action9,
                fm_action10, fm_action11, fm_action12, fm_action13, fm_action14;

extern Byte     last_action0, last_action1, last_action2, last_action3,
                last_action4, last_action5, last_action6, last_action7, last_action8,
                last_action9, last_action10, last_action11, last_action12, last_action13,
                last_action14;

extern Word     fm_analog1, fm_analog2, fm_analog3, fm_analog4, fm_analog5, 
                fm_analog6, fm_analog7, fm_analog11, fm_analog12, fm_analog13,
                fm_analog14, fm_analog21, fm_analog22, fm_analog23, fm_analog24;


extern Byte     lastmsgU201, lastmsgU202;
extern UNION16  lastmsgU401, lastmsgU402, lastmsgU403, lastmsgU501, lastmsgU601, lastmsgU605;
extern SPI24    lastmsgU404, lastmsgU405;


extern Byte     countercheck;   // counter of cycles 30 ms; value is <0,7>                  

extern TASK     arrayTask[SIZE_TASK_ARRAY];
extern Byte     actualTask;   // pointer to actualy solved task in arrayTask                  

extern Word     watchdogenable;

/******************************************************************************
* Module            : Lowpwr_go_to_sleep
* Description       : set all onboard-devices in sleep mode .
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : none
* Special Issues    : none
******************************************************************************/
void Lowpwr_go_to_sleep(void){
    Byte        i;
    Byte        temp8;
    UNION16     temp16;
    SPI24       temp24;        
        RST_U401 = 0;  // U401 - MC 33580 (JAGUAR) go to sleep mode
        RST_U402 = 0;  // U402 - MC 33874 (PUMA) go to sleep mode

        EN_U403 = 0;   // U403 - MC 33879 (COSS) go to sleep mode
        EN_U605 = 0;   // U605 - MC 33879 (COSS) go to sleep mode
                
        CSB_U404 = 0;  // U404 - MC33972 (MSDI) go to sleep mode
        temp24.comm = U404_SLEEP_COMMAND;
        temp24.data.w = U404_SLEEP_INTR_OFF;
        temp24 = ReadWriteSPI24bit(temp24);        
        CSB_U404 = 1;
        
        // U405 - MC33972 (MSDI) go to sleep mode
        CSB_U405 = 0;
        temp24.comm = U405_WAKEUP_COMMAND_SP;
        temp24.data.w = U405_WAKE_PIN_SP2;
        temp24 = ReadWriteSPI24bit(temp24);       
        CSB_U405 = 1;
        
        CSB_U405 = 0;  
        temp24.comm = U405_SLEEP_COMMAND;
        temp24.data.w = U405_SLEEP_INTR_OFF;
        temp24 = ReadWriteSPI24bit(temp24);       
        CSB_U405 = 1;

    	EN_U301 = 0; // U301 - MC33661 (LIN) go to sleep mode

        DisableInterrupts;
			// CAN Goto sleep
        CSB_U201 = 0;
    	// Disable wake-up inputs 
    	temp8 = ReadWriteSPI8bit(U201_WUR, U201_WRITE, ZERO);
    	// Set NOSTOP in RCR register 
    	temp8 = ReadWriteSPI8bit(U201_RCR, U201_WRITE, U201_NOSTOP);
    	// Sleep mode enter
    	temp8 = ReadWriteSPI8bit(U201_MCR, U201_WRITE, U201_SLEEP);
        CSB_U201 = 1;
      //LIN go to sleep
      LIN1_EN = 0;
 
         CSB_U202 = 0;
    	// Configure L0, L1 low level and L2, L3 pins high level sensitive
    	temp8 = ReadWriteSPI8bit(U202_WUR, U202_WRITE, 0x0F);

    	// Set NOSTOP in RCR register
    	temp8 = ReadWriteSPI8bit(U202_RCR, U202_WRITE, U202_NOSTOP);
    	// Clear BATFAIL bit in MCR by reading MCR
    	temp8 = ReadWriteSPI8bit(U202_MCR, U202_READ, ZERO); 
     		 CSB_U202 = 1;
    // delay time 
    for(i=0;i<7;i++){
      Delay6ms();
    }
    CSB_U202 = 0; // Sleep mode enter
      temp8 = ReadWriteSPI8bit(U202_MCR, U202_WRITE, U202_SLEEP);
    CSB_U202 = 1;
    
      for EVER{}//for EVER;
}

/******************************************************************************
* Module            : Lowpwr_go_to_pseudostop
* Description       : send onboard-devices to stop mode, 
*                     microcotroller into pseudostop mode .
* Global Data       : fm_action14
* Static Global Data: none
* Returns           : none
* Arguments         : none
* Special Issues    : none
******************************************************************************/

void Lowpwr_go_to_pseudostop(void)
{
    Byte        temp8;
    UNION16     temp16;
    SPI24       temp24;
    char        i;
    
    Byte prva = 0, druha = 0, tretia = 0, stvrta = 0, piata = 0, siesta = 0, siedma = 0;
  
  fm_action14 = 0;
  
  CSB_U404 = 0;  // U404 - MC33972 (MSDI) go to sleep mode
        temp24.comm = U404_SLEEP_COMMAND;
        temp24.data.w = U404_SLEEP_INTR_OFF;
        temp24 = ReadWriteSPI24bit(temp24);        
  CSB_U404 = 1;
        
                 // U405 - MC33972 (MSDI) go to sleep mode
  CSB_U405 = 0;
        temp24.comm = U405_WAKEUP_COMMAND_SP;
        temp24.data.w = U405_WAKE_PIN_SP2;
        temp24 = ReadWriteSPI24bit(temp24);         
  CSB_U405 = 1;
   
  CSB_U405 = 0;  
        temp24.comm = U405_SLEEP_COMMAND;
        temp24.data.w = U405_SLEEP_INTR_OFF;
        temp24 = ReadWriteSPI24bit(temp24);         
  CSB_U405 = 1;

  EN_U301 = 0;   // U301 - MC33661 (LIN) go to sleep mode
  
  CSB_U201 = 0;
    	// Disable wake-up inputs 
    	temp8 = ReadWriteSPI8bit(U201_WUR, U201_WRITE, ZERO);
    	// Set NOSTOP in RCR register 
    	temp8 = ReadWriteSPI8bit(U201_RCR, U201_WRITE, U201_NOSTOP);	
    	// Sleep mode enter
    	temp8 = ReadWriteSPI8bit(U201_MCR, U201_WRITE, U201_SLEEP);
  CSB_U201 = 1;
  
  CSB_U202 = 0;
    	
    	// Set no Watchdog in Stop Mode in RCR register and CAN sleep mode enabled
    	temp8 = ReadWriteSPI8bit(U202_RCR, U202_WRITE,0x02);
    	// CAN Sleep and CAN Wake-Up Disable
    	temp8 = ReadWriteSPI8bit(U202_CAN, U202_WRITE,0x03);    	
    	// Disable force wake-up,Lx cyclic
    	temp8 = ReadWriteSPI8bit(U202_LPC, U202_WRITE,ZERO);
    	// Configure L0, L1 and L2, L3 pins disabled
    //	temp8 = ReadWriteSPI8bit(U202_WUR, U202_WRITE, ZERO);
    	// feed watchdog
    	temp8 = ReadWriteSPI8bit(U202_TIM, U202_WRITE, U202_350MS);
  CSB_U202 = 1;
   
 CSB_U202 = 0;  
    	// Clear BATFAIL bit in MCR by reading MCR
    	temp8 = ReadWriteSPI8bit(U202_MCR, U202_READ, ZERO);
    	// STOP mode enter
    	temp8 = ReadWriteSPI8bit(U202_MCR, U202_WRITE, U202_STOP);
 CSB_U202 = 1;
  
    	DisableInterrupts;

			IRQCR_IRQE  = 1;	 // Falling edge
    	IRQCR_IRQEN = 1;	 // Irq enabled

      EnableInterrupts;        

        CLKSEL_PSTP   = 1;      // Pseudo Stop mode activate
        CLKSEL_PLLSEL = 0;      // System Clock = OSCCLK
        PLLCTL_PLLON  = 0;      // PLL is turned OFF
        PLLCTL_CME    = 0;      // Clock monitor is disabled
        PLLCTL_PRE    = 1;			// RTI enabled during pseudostop

        __asm ANDCC #0x7F;      // clear S bit = enable stop mode
        __asm STOP;

        // Init MC33742. SBC enters Normal mode, after Watchdog was triggered.
    	  // Watchdog is initialized as 350ms timeout 
/*!!!    	CSB_U202 = 0;
    	temp8 = ReadWriteSPI8bit(U202_TIM, U202_WRITE, U202_350MS);                   
      CSB_U202 = 1;  this routine has to be addet to wakeup interrupt  */
}
/******************************************************************************
* Module            : Lowpwr_go_to_stop
* Description       : send onboard-devices to stop mode, 
*                     microcotroller into stop mode .
* Global Data       : fm_action14
* Static Global Data: none
* Returns           : none
* Arguments         : none
* Special Issues    : none
******************************************************************************/

void Lowpwr_go_to_stop(void)
{
    Byte        temp8;
    UNION16     temp16;
    SPI24       temp24;
    char        i;
  
  fm_action14 = 0;
  
  CSB_U404 = 0;  // U404 - MC33972 (MSDI) go to sleep mode
        temp24.comm = U404_SLEEP_COMMAND;
        temp24.data.w = U404_SLEEP_INTR_OFF;
        temp24 = ReadWriteSPI24bit(temp24);         
  CSB_U404 = 1;
        
                 // U405 - MC33972 (MSDI) go to sleep mode
  CSB_U405 = 0;
        temp24.comm = U405_WAKEUP_COMMAND_SP;
        temp24.data.w = U405_WAKE_PIN_SP2;
        temp24 = ReadWriteSPI24bit(temp24);         
  CSB_U405 = 1;
   
  CSB_U405 = 0;  
        temp24.comm = U405_SLEEP_COMMAND;
        temp24.data.w = U405_SLEEP_INTR_OFF;
        temp24 = ReadWriteSPI24bit(temp24);        
  CSB_U405 = 1;

  EN_U301 = 0;   // U301 - MC33661 (LIN) go to sleep mode
  
  CSB_U201 = 0;
    	// Disable wake-up inputs 
    	temp8 = ReadWriteSPI8bit(U201_WUR, U201_WRITE, ZERO);
    	// Set NOSTOP in RCR register 
    	temp8 = ReadWriteSPI8bit(U201_RCR, U201_WRITE, U201_NOSTOP);
    	// Sleep mode enter
    	temp8 = ReadWriteSPI8bit(U201_MCR, U201_WRITE, U201_SLEEP);
  CSB_U201 = 1;
  
  CSB_U202 = 0;
    	// Configure L0, L1 and L2, L3 pins disabled
    	temp8 = ReadWriteSPI8bit(U202_WUR, U202_WRITE, ZERO);    	
    	// Set no Watchdog in Stop Mode in RCR register and CAN sleep mode enabled
    	temp8 = ReadWriteSPI8bit(U202_RCR, U202_WRITE,0x02);
    	// CAN Sleep and CAN Wake-Up Disable
    	temp8 = ReadWriteSPI8bit(U202_CAN, U202_WRITE,0x03);
    	// feed watchdog
    	temp8 = ReadWriteSPI8bit(U202_TIM, U202_WRITE, 0x03);
  CSB_U202 = 1;
  
  
      	
 CSB_U202 = 0;   	        	    	
    	// Clear BATFAIL bit in MCR by reading MCR
    	temp8 = ReadWriteSPI8bit(U202_MCR, U202_READ, ZERO);
    	// STOP mode enter
    	temp8 = ReadWriteSPI8bit(U202_MCR, U202_WRITE, U202_STOP);
 CSB_U202 = 1;
  
    	DisableInterrupts;

			IRQCR_IRQE  = 1;	 // Falling edge
    	IRQCR_IRQEN = 1;	 // Irq enabled

      EnableInterrupts;        

      CLKSEL_PLLSEL = 0;      // System Clock = OSCCLK
      PLLCTL_PLLON  = 0;      // PLL is turned OFF
      PLLCTL_CME    = 0;      // Clock monitor is disabled

      __asm ANDCC #0x7F;      // clear S bit = enable stop mode
      __asm STOP;
}
/******************************************************************************
* Module            : Lowpwr_wd_timeout
* Description       : send SBC to stop mode, 
*                     watchdog is not feeding.
* Global Data       : fm_action14
* Static Global Data: none
* Returns           : none
* Arguments         : none
* Special Issues    : none
******************************************************************************/

void Lowpwr_wd_timeout(void)
{
Byte        temp8;
UNION16     temp16;
SPI24       temp24;

    watchdogenable = FALSE;
    fm_action14 = 0;
}
/******************************************************************************
* Module            : lowpwr_wd_timeout
* Description       : send SBC to stop mode, 
*                     watchdog is not feeding.
* Global Data       : fm_action14
* Static Global Data: none
* Returns           : none
* Arguments         : none
* Special Issues    : none
******************************************************************************/

void Lowpwr_wd_window_out(void)
{
Byte        temp8;
UNION16     temp16;
SPI24       temp24;  

  DisableInterrupts;  

  CSB_U202 = 0;
	// Set NOSTOP in RCR register
	temp8 = ReadWriteSPI8bit(U202_TIM, U202_WRITE, U202_350MS_WINDOW);
	
	EnableInterrupts;
    fm_action14 = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -