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

📄 etpu_util.bak

📁 mpc55**系列芯片的例程 包括SCI,SPI,TIMER,FIT,EDMA等几乎所有功能的实现
💻 BAK
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************
 * FILE NAME: $RCSfile: etpu_util.c,v $      COPYRIGHT (c) Freescale 2004 *
 * DESCRIPTION:                                     All Rights Reserved   *
 * This file contains useful macros and functions for using the eTPU.     *
 *========================================================================*
 * ORIGINAL AUTHOR: Jeff Loeliger [r12110]                                *
 * $Log: etpu_util.c,v $
 * Revision 2.0  2004/11/30 16:10:32  r12110
 * -Updated functions to remove requirement for etpu_config.h file.
 * -Added new memset32 function to clear eTPU code memory.
 *
 * Revision 1.1  2004/11/12 10:39:23  r12110
 * Initial version checked into CVS.
 *........................................................................*
 * 0.01  J. Loeliger  13/Jun/03  Initial version of file.                 *
 * 0.02  J. Loeliger  19/Mar/04  Change function prefix to fs_ for        *
 *                                Freescale semiconductor.                *
 * 0.03  J. Loeliger  26/Mar/04  Updated after debug.                     *
 * 0.04  J. Loeliger  26/May/04  Updated comments.                        *
 *       M. Brejl                Fixed problem with *fs_etpu_data_ram.    *
 *       M.Princ                 Renamed fs_mpc5500_timer_start to        *
 *                                fs_timer_start.                         *
 *                               Added new functions to access parameter  *
 *                                Ram using different data sizes.         *
 * 0.05  J. Loeliger  16/Jul/04  Updated to match new mpc5554 header files*
 * 0.06  J. Loeliger  16/Aug/04  Updated malloc to round correctly.       *
 * 0.1   J. Loeliger  01/Sep/04  Added fs_etpu_malloc2 function.          *
 * 0.2   S. Mihalik   25/Sep/06  Decleared error_code extern              *
 **************************************************************************/
#ifndef _ETPU_UTIL_C_
#define _ETPU_UTIL_C_

#include "etpu_util.h"    /* prototypes and useful defines */

extern uint32_t fs_etpu_code_start;
extern uint32_t fs_etpu_data_ram_start;
extern uint32_t fs_etpu_data_ram_end;
extern uint32_t fs_etpu_data_ram_ext;
extern uint32_t error_code;

/******************************************************************************
FUNCTION     : fs_etpu_init
PURPOSE      : To initialize the eTPU module.
		        1. Load eTPU code into memory.
		        2. Initialize global registers.
		          a. MISC vale
		          b. TCR pre-scalers
		        3. Copy initial values of global variables to data RAM
INPUTS NOTES : This function has 5 parameters:
                 p_etpu_config: This is the structure used to initialize the eTPU
                 *code: This is a pointer to an image of the eTPU code.
                 code_size: This is the size of the eTPU code in bytes.
                 *globals: This is a pointer to the global eTPU data that needs
                     to be initialized.
                 globals_size: This is the size of the global data in bytes.
RETURNS NOTES: Error code is channel could not be initialized. Error code that
                 can be returned are:
                 FS_ETPU_ERROR_CODESIZE: When the code is to big for the
                    available memory.
WARNING      : This function does not configure the pins only the eTPU->
******************************************************************************/
uint32_t fs_etpu_init(struct etpu_config_t p_etpu_config, uint32_t *code,
                  uint32_t code_size, uint32_t *globals, uint32_t globals_size)
{
	uint32_t *code_end;
	int32_t unused_code_ram;
	error_code = 0;

	unused_code_ram = ((eTPU->MCR.B.SCMSIZE + 1 ) * 2048) - code_size;
	if ( unused_code_ram < 0 ) return((uint32_t)FS_ETPU_ERROR_CODESIZE);

    /* 1. Load microcode */
    /* In order for the MISC function to work with code that is small than
       the code memory any unused locations must be set to zero. */
	/* enable writting to SCM */
	eTPU->ECR_A.B.MDIS = 1;    /* stop eTPU_A */
	eTPU->ECR_B.B.MDIS = 1;    /* stop eTPU_B */
	eTPU->MCR.B.VIS = 1;       /* enable CPU writes to eTPU code memory */

    /* Copy microcode */
    code_end = fs_memcpy32( (uint32_t*)fs_etpu_code_start, code, code_size);

    /* Clear rest of program memory */
    fs_memset32( code_end, 0, unused_code_ram);

	eTPU->MCR.B.VIS = 0;		/* disable CPU writes to eTPU code memory */

	/* Configure MISC */
	eTPU->MISCCMPR.R = p_etpu_config.misc; /*write MISC value before enabled in MCR */
	eTPU->MCR.R = p_etpu_config.mcr;

    /* Configure Engine 1 */
    eTPU->ECR_A.R = p_etpu_config.ecr_a;
    eTPU->TBCR_A.R = p_etpu_config.tbcr_a;
    eTPU->REDCR_A.R = p_etpu_config.stacr_a;

    /* Configure Engine 2 */
    /* Not all parts have a second eTPU engine, if you these write are ignored. */
    eTPU->ECR_B.R = p_etpu_config.ecr_b;
    eTPU->TBCR_B.R = p_etpu_config.tbcr_b;
    eTPU->REDCR_B.R = p_etpu_config.stacr_b;

	/* 3. Copy intial global values to parameter RAM. */
	fs_free_param = fs_memcpy32 ( (uint32_t*)fs_etpu_data_ram_start, globals, globals_size);

	return(0);
}

/******************************************************************************
FUNCTION     : fs_etpu_data_ram
PURPOSE      : This function returns a pointer to the start of the data RAM for
                 the specified channel.
INPUTS NOTES : This function has 1 parameter:
                 channel: The eTPU channel number.
RETURNS NOTES: A pointer to the start of the data RAM for the channel.
WARNING      : This function does no error cheching, if the channel has not
                 been initialized then an undefined value will be returned
                 (normally this will be a value of 0).
******************************************************************************/
uint32_t *fs_etpu_data_ram(uint8_t channel)
{
    return((uint32_t*)((uint8_t*)fs_etpu_data_ram_start + (eTPU->CHAN[channel].CR.B.CPBA << 3)));
}

/******************************************************************************
FUNCTION     : fs_etpu_set_hsr
PURPOSE      : This function sets the Host Service Request (HSR) register of the
                 specified eTPU channel.
INPUTS NOTES : This function has 2 parameters:
                 channel: The eTPU channel number.
                 hsr: The HSR value to send to the channel.
RETURNS NOTES: none
WARNING      : The CPU should check that the HSR field is 0 before calling this
                 routine. If the HSR field is not 0 then the 2 values will be
                 ORed together.
******************************************************************************/
void fs_etpu_set_hsr(uint8_t channel, uint8_t hsr)
{
    eTPU->CHAN[channel].HSRR.R = hsr;
}

/******************************************************************************
FUNCTION     : fs_etpu_get_hsr
PURPOSE      : This function returns the current value of the Host Service
                 Request (HSR) register of the specified eTPU channel.
INPUTS NOTES : This function has 1 parameter:
                 channel: The eTPU channel number.
RETURNS NOTES: Value of HSR register.
WARNING      :
******************************************************************************/
uint8_t fs_etpu_get_hsr(uint8_t channel)
{
    return( (uint8_t)eTPU->CHAN[channel].HSRR.R );
}

/******************************************************************************
FUNCTION     : fs_etpu_enable
PURPOSE      : This function enables or changes the priority of an eTPU channel.
INPUTS NOTES : This function has 2 parameters:
                 channel: The eTPU channel number.
                 priority: The priority to be assigned to the channel. This
                   should be assigned a value of: FS_ETPU_PRIORITY_HIGH,
                   FS_ETPU_PRIORITY_MIDDLE or FS_ETPU_PRIORITY_LOW.
RETURNS NOTES: none.
WARNING      :
******************************************************************************/
void fs_etpu_enable(uint8_t channel, uint8_t priority)
{
    eTPU->CHAN[channel].CR.B.CPR = priority;
}

/******************************************************************************
FUNCTION     : fs_etpu_disable
PURPOSE      : This function disables an eTPU channel.
INPUTS NOTES : This function has 1 parameter:
                 channel: The eTPU channel number.
RETURNS NOTES: none
WARNING      : If the channel is currently being serviced then the service will
                 complete.
******************************************************************************/
void fs_etpu_disable(uint8_t channel)
{
    eTPU->CHAN[channel].CR.B.CPR = FS_ETPU_PRIORITY_DISABLE;
}

/******************************************************************************
FUNCTION     : fs_etpu_interrupt_enable
PURPOSE      : This function enables an eTPU channel to generate interrupts.
INPUTS NOTES : This function has 1 parameter:
                 channel: The eTPU channel number.
RETURNS NOTES: none
WARNING      : This enables the eTPU to send interrupts to an interruput
                 controller. Additional configuration may be required for
                 the CPU to recieve the interrupt.
******************************************************************************/
void fs_etpu_interrupt_enable(uint8_t channel)
{
    eTPU->CHAN[channel].CR.B.CIE = TRUE;
}

/******************************************************************************
FUNCTION     : fs_etpu_interrupt_disable
PURPOSE      : This function disables an ETPU channel from generating interrupts.
INPUTS NOTES : This function has 1 parameter:
                 channel: The eTPU channel number.
RETURNS NOTES: none
WARNING      : When interupts are disabled the eTPU interrupt status bits are
                 still set and can be used to poll the interrupt status.
******************************************************************************/
void fs_etpu_interrupt_disable(uint8_t channel)
{
    eTPU->CHAN[channel].CR.B.CIE = FALSE;
}

/******************************************************************************
FUNCTION     : fs_etpu_dma_enable
PURPOSE      : This function enables an ETPU channel to request DMA service.
INPUTS NOTES : This function has 1 parameter:
                 channel: The eTPU channel number.
RETURNS NOTES: none
WARNING      : In a given device not all of the DMA requests may be connected
                 to DMA channels.
******************************************************************************/
void fs_etpu_dma_enable(uint8_t channel)
{
    eTPU->CHAN[channel].CR.B.DTRE = TRUE;
}

/******************************************************************************
FUNCTION     : fs_etpu_dma_disable
PURPOSE      : This function disables an eTPU channel from generating DMA requests.
INPUTS NOTES : This function has 1 parameter:
                 channel: The eTPU channel number.
RETURNS NOTES: none
WARNING      : When DMA requests are disabled the eTPU DMA request status bits are
                 still set and can be used to poll the DMA request status.

⌨️ 快捷键说明

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