View Single Post
Old 17-01-2008, 12:42 PM   #1
falleaf
PIC Bang chủ
 
falleaf's Avatar
 
Tham gia ngày: May 2005
Bài gửi: 2,631
:
Send a message via Yahoo to falleaf
Lôi System.h ra coi chơi nhỉ :)

Code:
/********************************************************************
* FileName:		System.h
* Dependencies:
* Processor:		PIC32
* Hardware:		N/A
* Assembler:		N/A
* Linker:		    N/A
* Company:		    Microchip Technology, Inc.
********************************************************************/

#ifndef _SYSTEM_HEADER_FILE
#define _SYSTEM_HEADER_FILE

#include <p32xxxx.h>
#include <peripheral/int.h>
#include <peripheral/pcache.h>
#include <peripheral/osc.h>
#include <peripheral/dma.h>
#include <peripheral/bmx.h>
#include <peripheral/lock.h>

#define FLASH_ACCESS_TIME_HZ    20000000
#define PB_BUS_ACCESS_TIME_HZ   50000000
Code:
/*********************************************************************
 * Function:       void SYSTEMConfigPB(unsigned int sys_clock)
 *
 * PreCondition:    None
 *
 * Input:           sys_clock - system clock in Hz
 *
 * Output:          the PB divider value
 *
 * Side Effects:    Sets the PB divider to the optimum value
 ********************************************************************/
extern inline unsigned int __attribute__((always_inline)) SYSTEMConfigPB(unsigned int sys_clock)
{
    unsigned int dma_status;
    unsigned int int_status;
    unsigned int pb_clock;

    pb_clock = sys_clock;
    
    mSYSTEMUnlock(int_status, dma_status);

    // set the PB Div
    if(sys_clock > PB_BUS_ACCESS_TIME_HZ)
    {
        mOSCSetPBDIV(OSC_PB_DIV_2);
        pb_clock >>= 1;
    }
    else
    {
        mOSCSetPBDIV(OSC_PB_DIV_1);
    }

    mSYSTEMLock(int_status, dma_status);
    
    return pb_clock;
}
Code:
/*********************************************************************
 * Function:       void SYSTEMConfigWaitStatesAndPB(unsigned int sys_clock)
 *
 * PreCondition:    None
 *
 * Input:           sys_clock - system clock in Hz
 *
 * Output:          None
 *
 * Side Effects:    Sets the PB and Flash Wait states
 ********************************************************************/
extern inline unsigned int __attribute__((always_inline)) SYSTEMConfigWaitStatesAndPB(unsigned int sys_clock)
{
#ifdef _PCACHE
    unsigned int wait_states;
#endif
    unsigned int pb_clock;
    unsigned int int_status;
    
    pb_clock = SYSTEMConfigPB(sys_clock);
    

    // set the flash wait states based on 1 wait state
    // for every 25 MHz
#ifdef _PCACHE
    wait_states = 0;

    while(sys_clock >= FLASH_ACCESS_TIME_HZ)
    {
        wait_states++;
        sys_clock -= FLASH_ACCESS_TIME_HZ;
    }
    
    int_status=INTDisableInterrupts();	
    mCheConfigure(wait_states);
    INTRestoreInterrupts(int_status);

#endif
	
    return pb_clock;
}
Code:
/*********************************************************************
 * Function:       void SYSTEMConfigPerformance(unsigned int sys_clock, unsigned int flag)
 *
 * PreCondition:    None
 *
 * Input:           sys_clock - system clock in Hz
 *
 * Output:          None
 *
 * Side Effects:    Sets the PB and Flash Wait states
 ********************************************************************/
extern inline unsigned int __attribute__((always_inline)) SYSTEMConfigPerformance(unsigned int sys_clock)
{
    // set up the wait states
    unsigned int pb_clk;
#ifdef _PCACHE
    unsigned int cache_status;
#endif    
    unsigned int int_status;

    pb_clk = SYSTEMConfigWaitStatesAndPB(sys_clock);
    
    int_status=INTDisableInterrupts();
    
    mBMXDisableDRMWaitState();

#ifdef _PCACHE
    cache_status = mCheGetCon();
    cache_status |= CHE_CONF_PF_ALL;
    mCheConfigure(cache_status);
    CheKseg0CacheOn();
#endif

    INTRestoreInterrupts(int_status);
    
    return pb_clk;
    
}
#endif
Cái chúng ta dùng là cái hàm SYSTEMConfigPerformance cuối cùng này. Có đồng chí nào phân tích cái này giúp F với.

Chúc vui
falleaf vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn