tpu_tsm.c

来自「mpc564 时钟中断 时钟中断」· C语言 代码 · 共 370 行 · 第 1/2 页

C
370
字号
    tpu->PARM.R[channel][TPU_TSM_DESIRED_POSITION] = position;

/* Issue a move request to the host service request (master channel:HSR=0x11) */
    tpu_hsr(tpu, channel, TPU_TSM_HSR_MOV);
    };

/*******************************************************************************
FUNCTION      : tpu_tsm_rd_dp
PURPOSE       : To read the desired position.
INPUTS NOTES  : This function has 2 parameters:
                 *tpu - This is a pointer to the TPU3 module to use. It is of
                         type TPU3_tag which is defined in m_tpu3.h
                 channel - This is the number of the master channel
RETURN NOTES  : desired position - The desired position is returned as a UINT16.
GENERAL NOTES : The channel must be a master channel for the TSM function. The
                 read of the desired position can be used to drive the program. 
*******************************************************************************/
 
UINT16 tpu_tsm_rd_dp(struct TPU3_tag *tpu, UINT8 channel)
    {
/* read and return the desired position from the TSM master channel */
    return (tpu->PARM.R[channel][TPU_TSM_DESIRED_POSITION]);
    };

/*******************************************************************************
FUNCTION      : tpu_tsm_rd_cp
PURPOSE       : To read the current position.
INPUTS NOTES  : This function has 2 parameters:
                 *tpu - This is a pointer to the TPU3 module to use. It is of
                         type TPU3_tag which is defined in m_tpu3.h
                 channel - This is the number of the master channel
RETURN NOTES  : current position - The desired position is returned as a UINT16.
GENERAL NOTES : The channel must be a master channel for the TSM function. The
                 read of the current position can be used to drive the program. 
*******************************************************************************/
 
UINT16 tpu_tsm_rd_cp(struct TPU3_tag *tpu, UINT8 channel)
    {
/* read and return the current position from the TSM master channel */
    return (tpu->PARM.R[channel][TPU_TSM_CURRENT_POSITION]);
    };

/***************************************************/
/* Generate Interrupt tasks for the TSM interrupt. */
/***************************************************/
/*******************************************************************************
FUNCTION      : tpu_tsm_int_lev
PURPOSE       : To program the level of interrupt from the TPU-TSM function.
INPUTS NOTES  : This function has 2 parameters:
                 *tpu - This is a pointer to the TPU3 module to use. It is of
                         type TPU3_tag which is defined in m_tpu3.h
                 level - The interrupt level (0 to 31).
GENERAL NOTES : Level must be in the range of 0 to 31.
*******************************************************************************/
void tpu_tsm_int_lev(struct TPU3_tag *tpu, UINT8 level)
   {
     int remainder;
	if( level > 23) {
            tpu->TICR.B.ILBS = 0x11;
            remainder = level - 24;
            tpu->TICR.B.CIRL = remainder;
          }
	else if( level > 15) {
            tpu->TICR.B.ILBS = 0x10;
            remainder = level - 16;
            tpu->TICR.B.CIRL = remainder;
          }
	else if( level > 7) {
            tpu->TICR.B.ILBS = 0x01;
            remainder = level - 8;
            tpu->TICR.B.CIRL = remainder;
          }
	else {
            tpu->TICR.B.ILBS = 0x00;
            tpu->TICR.B.CIRL = level;
          }
   };

/*******************************************************************************
FUNCTION      : tpu_tsm_int_chk
PURPOSE       : Interrupt check for TSM interrupt service request match.
INPUTS NOTES  : This function has 3 parameters:
                 *tpu - This is a pointer to the TPU3 module to use. It is of
                         type TPU3_tag which is defined in m_tpu3.h
                 channel - The master channel.
RETURNS       : Returns the value TRUE (1) or FALSE (0) as a UINT8.
GENERAL NOTES : Level must be incoded according to the SIPEND register. 
*******************************************************************************/

int tpu_tsm_int_chk(struct TPU3_tag *tpu, UINT16 channel) {
    /* Determine that TPU was the source */
    /* Determine the tpu channel interrupt source */
  int val;
  if (tpu->CISR.R == channel) { 
         val = TPU_TSM_TRUE;
       }
   else val = TPU_TSM_FALSE;
 return val;
}

/*******************************************************************************
FUNCTION      : tpu_tsm_cisr_clr
PURPOSE       : Interrupt clear for TSM cisr register.
INPUTS NOTES  : This function has 1 parameter:
                 level - The interrupt level (0 to 7) as encoded through the
                         32-bit SIPEND register.
GENERAL NOTES : Level must be incoded according to the SIPEND register. This
                 level is 32-bits long (UINT32).
*******************************************************************************/

void tpu_tsm_cisr_clr(struct TPU3_tag *tpu, UINT16 CISR_level) {
    /* Write a "1" to the active pending bit to reset it.  */
    /* A logic bit-wise "OR" between the SIPEND and the    */
    /* level will clear the specific SIPEND level.         */
 
/* Clear any existing TPU interrupts    */
   tpu->CISR.R = 0x0000;
 /*  tpu->CISR.R &= ~(1 << CISR_level);  */ 
}

/*******************************************************************************
FUNCTION      : tpu_tsm_mas_chan_cier
PURPOSE       : Convert master channel integer into CIER, CISR UINT16 value
INPUTS NOTES  : This function has 1 parameter:
                 master_chan - The channel (0 to 15) to convert to encodeding
                 for the 16-bit TPU CIER, or CISR register.
GENERAL NOTES : master_chan integer input is returned as a UINT16 value
                 for the TPU CIER and CISR registers.
*******************************************************************************/

UINT16 tpu_tsm_mas_chan_cier(int master_chan) {
    /* Convert integer input master channel to the  */
    /* TPU CIER or CISR encoding.                   */

UINT16 cier_chan = 0x0000;
   if(master_chan == 0)  { cier_chan = 0x0001; }
   if(master_chan == 1)  { cier_chan = 0x0002; }
   if(master_chan == 2)  { cier_chan = 0x0004; }
   if(master_chan == 3)  { cier_chan = 0x0008; }
   if(master_chan == 4)  { cier_chan = 0x0010; }
   if(master_chan == 5)  { cier_chan = 0x0020; }
   if(master_chan == 6)  { cier_chan = 0x0040; }
   if(master_chan == 7)  { cier_chan = 0x0080; }
   if(master_chan == 8)  { cier_chan = 0x0100; }
   if(master_chan == 9)  { cier_chan = 0x0200; }
   if(master_chan == 10) { cier_chan = 0x0400; }
   if(master_chan == 11) { cier_chan = 0x0800; }
   if(master_chan == 12) { cier_chan = 0x1000; }
   if(master_chan == 13) { cier_chan = 0x2000; }
   if(master_chan == 14) { cier_chan = 0x4000; }
   if(master_chan == 15) { cier_chan = 0x8000; }

   return cier_chan;
}


/*********************************************************************
 *
 * Copyright:
 *	MOTOROLA, INC. All Rights Reserved.  
 *  You are hereby granted a copyright license to use, modify, and
 *  distribute the SOFTWARE so long as this entire notice is
 *  retained without alteration in any modified and/or redistributed
 *  versions, and that such modified versions are clearly identified
 *  as such. No licenses are granted by implication, estoppel or
 *  otherwise under any patents or trademarks of Motorola, Inc. This 
 *  software is provided on an "AS IS" basis and without warranty.
 *
 *  To the maximum extent permitted by applicable law, MOTOROLA 
 *  DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED, INCLUDING 
 *  IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
 *  PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH REGARD TO THE 
 *  SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF) AND ANY 
 *  ACCOMPANYING WRITTEN MATERIALS.
 * 
 *  To the maximum extent permitted by applicable law, IN NO EVENT
 *  SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING 
 *  WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS 
 *  INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
 *  LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.   
 * 
 *  Motorola assumes no responsibility for the maintenance and support
 *  of this software
 ********************************************************************/

⌨️ 快捷键说明

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