PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   PIC32 - Bộ điều khiển tín hiệu số 32-bit (http://www.picvietnam.com/forum/forumdisplay.php?f=61)
-   -   Lôi System.h ra coi chơi nhỉ :) (http://www.picvietnam.com/forum/showthread.php?t=1914)

falleaf 17-01-2008 12:42 PM

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

tiendungkct 17-01-2008 12:46 PM

anh có thể phân tích đôi chút không anh


Múi giờ GMT. Hiện tại là 04:51 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam