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

📄 mcu_hw_config.c

📁 用于WSN的PDA搜救器
💻 C
字号:
/**
 * Copyright (c) 2004, Freescale Semiconductor
 * Freescale Confidential Proprietary
 *
 * File name : mcu_hw_config.c
 * Project name: SMAC (Simple Media Access Controller)
 *
 * Department : Freescale Radio Products Division
 *
 * Description : MCU Hardware configuration routines.
 *
 * $Author: flr005 $
 * $Date: 2006/02/23 16:24:36 $
 * $Name:  $
 */

#define   MCU_HW_CONFIG_GLOBALS
//#include "device_header.h" /* include peripheral declarations */
#include "include.h"

/* Global Variables */



/*
 * UseExternalClock: Switch the MCU from internal to MC13192 supplied clock.
 * The MCU FLL is not engaged.
 *
 * Parameters: None
 *
 * Return : None
 */
#if defined (HCS08G)
void UseExternalClock() //use_external_clock()
{
    ICGC1 = 0x78;    /*  
                      *     0b01111000
                      *       ||||||||__ Unimplemented
                      *       |||||||___ Unimplemented
                      *       ||||||____ Oscillator disabled when ICG is in 
                      *       |||||      off mode
                      *       |||||
                      *       ||||+_____ FLL bypassed, external reference
                      *       |||_______ External Clock Requested
                      *       ||________ Osc configured for High Frequency
                      *       |_________ Unimplemented
                      */
                      
    while (!ICGS1_ERCS);    /* Wait for external reference to be stable. */
        
    ICGC2_LOLRE = 1;
    ICGC2 = 0x30;       /* Mult factor of 10. */
    
    while (!ICGS1_LOCK);
}

/*
 * UseMcuClock: Switch the MCU from external to internal clock.
 *
 * Parameters: None
 *
 * Return : None
 */
void UseMcuClock() //use_mcu_clock()
{
    ICGC1_RANGE = 1;        /* Range High. */
    ICGC1_OSCSTEN = 1;      /* Osc enabled in off mode. */
    ICGC1_CLKS = 0x00;      /* Self clocked. */            
}
#endif


/*
 * MC13192Restart: Restart the MC13192.
 *
 * Parameters: None
 *
 * Return : None
 */
void MC13192Restart()
{
    gu8RTxMode = SYSTEM_RESET_MODE;
    IRQInit();                  /* Turn on the IRQ pin. */
    MC13192_RESET = 1;          /* Take MC13192 out of reset */
    while (IRQSC_IRQF == 0)     /* Poll waiting for MC13192 to assert the irq */
        ; /* Empty Body */      /* (i.e. ATTN). */
    SPIDrvRead(0x24);            /* Clear MC13192 interrupts */
    IRQACK();                   /* ACK the pending IRQ interrupt */
    IRQPinEnable();             /* Pin Enable, IE, IRQ CLR, negative edge. */
}


/*
 * MC13192ContReset: Reset (continuous) the MC13192.
 *
 * Parameters: None
 *
 * Return : None
 */
void MC13192ContReset()
{
    gu8RTxMode = SYSTEM_RESET_MODE;
    IRQSC = 0x00;                   /* Set for negative edge. */
    MC13192_RESET = 0;              /* Place the MC13192 into reset */
}


/*
 * GPIOInit: Initialize the MCU-to-MC13192 GPIO direction and data.
 *
 * Parameters: None
 *
 * Return : None
 */
void GPIOInit()
{
    MC13192_RESET_PULLUP = 0;
    MC13192_CE = 1;                    
    MC13192_ATTN = 1;
    MC13192_RTXEN = 0;
    MC13192_RESET = 0;                  /* Do not initially reset MC13192 */
    MC13192_CE_PORT = 1;
    MC13192_ATTN_PORT = 1;
    MC13192_RTXEN_PORT = 1;
    MC13192_RESET_PORT = 1;
    MC13192_CE = 1;                    
    MC13192_ATTN = 1;
    MC13192_RTXEN = 0;
    MC13192_RESET = 0;                  /* Do not initially reset MC13192 */
 
}


/*
 * MCUInit: Initialize the MCU COP, GPIO, SPI and IRQ.
 * Set the desired MC13192 clock frequency here.
 *
 * Parameters: None
 *
 * Return : None
 */
void MCUInit(void)
{
    UINT16 u16IrqReg =0;
    UINT8  u8AttnIrq = FALSE;
    UINT8  u8TimerHi, u8TimerLo;
    
#ifdef  USE_WATCHDOG
    SOPT = 0xf3;                /* Turn on the watchdog. */
 #else   
    SOPT = 0x73;                /* Turn off the watchdog. */
 #endif 
    
    /* Add a delay to debouce the reset switch on development boards ~200ms */
    TPM1SC = 0x0D;                /* 
                                 * Set the Timer module to use BUSCLK as 
                                 * reference with Prescaler at / 32 
                                 */    
    do {
        u8TimerHi = TPM1CNTH;   /* Get value of timer register (hi byte) */
        u8TimerLo = TPM1CNTL;   /* Get value of timer register (lo byte) */
        CLRWDT();
    } while (u8TimerLo <= 0x80);/* 
                                 * Poll for TIMER LO to be greater than 
                                 * 0x80 at 4MHz/32
                                 */    
    TPM1SC = 0x00;              /* Return to reset values */

    GPIOInit();
    SPIInit();
    IRQInit();                   /* Turn on the IRQ pin. */
    
    MC13192_RESET = 1;          /* Take MC13192 out of reset */

    while (u8AttnIrq == FALSE) 
    {
        CLRWDT();
        
        if (IRQFLAG == 1) 
        {      /* Check to see if IRQ is asserted */
            u16IrqReg = SPIDrvRead(0x24);   /* 
                                             * Clear MC13192 interrupts and  
                                             * check for ATTN IRQ from 13192
                                             */
            u16IrqReg &= 0x400;
            if (u16IrqReg == 0)
            {
                u8AttnIrq = FALSE;
            }
            else 
            {
                u8AttnIrq = TRUE;
            }
        }
    }
 
    IRQACK();              /* ACK the pending IRQ interrupt */
    IRQPinEnable();        /* Pin Enable, IE, IRQ CLR, negative edge. */
}

/*
 * IRQPinLow: Checks IRQ Pin to see if is low.
 *
 * Parameters: None
 *
 * Return : 1 if IRQ is Low.
 */
UINT8 IRQPinLow(void){

    asm  BIL irq    
    return 0;    
    asm irq:    
    return 1;
}

⌨️ 快捷键说明

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