📄 etpuc_sm.c
字号:
| > 0: Deccelerate. |
| - decrement accel_tbl_index. |
| 6. Calculate the step-period. If accel_tbl_index > 1 then |
| step_period = start_period * accel_tbl[accel_tbl_index-2],|
| where accel_tbl[x] is unsigned fract16 value, |
| else used start_period as the step-period. |
| 7. Limit the step-period by slew_period. If the limitation |
| is applied set slew flag ON. |
| 8. SET_ERT: Set matches: |
| Based on the current direction rotate the pin sequence |
| left (dec-direction) or right (inc-direction). |
| Set match on all channels according to pin_sequence bits. |
| The LSB (bit 0) corresponds to the master channel and |
| bits 1, 2, 3, ... (in full-step mode) or |
| bits 2, 4, 6, ... (in half-step mode) to slave channels. |
+--------------------------------------------------------------------------*/
else if ( m1==1 )
{
/* Update current_position by the step just done */
if ((flags & SM_DIRECTION) == SM_DIRECTION_RIGHT)
{
current_position++;
}
else
{
current_position--;
}
/* Decceleration finished? */
if (accel_tbl_index == 0)
{
goto SM_START_DIR_TEST;
}
/* Test direction */
tmp = desired_position - current_position;
if (tmp < 0)
{
/* if going the oposit direction then deccelerate */
if ((flags & SM_DIRECTION) == SM_DIRECTION_RIGHT)
{
goto SM_DECCELERATE;
}
}
else if (tmp > 0)
{
/* if going the oposit direction then deccelerate */
if ((flags & SM_DIRECTION) == SM_DIRECTION_LEFT)
{
goto SM_DECCELERATE;
}
tmp = -tmp;
}
SM_STEP:
/* Deccelerate? Slew? Accelerate? */
tmp += accel_tbl_index + 1;
if (tmp == 0) /* ... slew or no more space to accelerate */
{
/* Already is slew rate ? */
if ((flags & SM_SLEW) == SM_SLEW_ON)
{
tmp = slew_period;
goto SM_SET_ERT;
}
}
else if (tmp < 0) /* ... accelerate */
{
tmp = accel_tbl_index;
accel_tbl_index++;
/* No more acceleration steps available? */
if (tmp > accel_tbl_size)
{
/* Already is slew rate ? */
if ((flags & SM_SLEW) == SM_SLEW_ON)
{
accel_tbl_index = tmp; /* correct index, but not on first slew step */
}
else
{
flags |= SM_SLEW_ON; /* set slew flag */
}
tmp = slew_period;
goto SM_SET_ERT;
}
}
else /* (tmp > 0) ... time to deccelerate */
{
SM_DECCELERATE:
accel_tbl_index--;
}
/* Calculate step-period */
if (accel_tbl_index > 1)
{
/*tmp = start_period * (unsigned fract16)(accel_tbl[accel_tbl_index-2]);*/
tmp = accel_tbl_index-2;
tmp = accel_tbl[tmp];
#asm( alu a = d; ram p <- start_period. )
#asm( mdu p fmultu a (16). )
#asm( SM_L: if mbsy == 1 then goto SM_L, flush. )
#asm( alu d = mach. )
/* Comments to ETPUC:
- this expresion is not compiled correctly:
1. 16-bit unsigned fractional multiplication (instruction fmultu(16))
is not supported.
2. overcasting does not works properly. */
}
else /* accel_tbl_index == 0 or 1 */
{
tmp = start_period;
}
/* Limit by slew_period */
if (slew_period > tmp)
{
tmp = slew_period;
/* Already is slew rate ? */
if ((flags & SM_SLEW) == SM_SLEW_ON)
{
accel_tbl_index--; /* correct index, but not on first slew step */
}
else
{
flags |= SM_SLEW_ON; /* set slew flag */
}
}
else
{
flags &= ~SM_SLEW; /* clear slew flag */
}
/* Set matches */
SM_SET_ERT:
/* Rotate the pin sequence */
if ((flags & SM_DIRECTION) == SM_DIRECTION_RIGHT)
{
/* rotate right by 1 bit */
pin_sequence >>= 1;
if (CC.C == 1)
{
pin_sequence += 0x800000;
}
/*
#asm( ram p <- pin_sequence. )
#asm( alu p =R> p; ram p -> pin_sequence. )
*/
/* Comments to ETPUC: */
/* - is there a way how to perform rotation right in C (or ETPUC)? */
}
else
{
/* rotate left by 1 bit */
pin_sequence <<= 1;
if (CC.C == 1)
{
pin_sequence++;
}
}
/* Set match on all channels according to pin_sequence bits */
tmp_channels = channels;
tmp_pin_sequence = pin_sequence;
tmp = erta + tmp;
while (tmp_channels-- > 0)
{
/* Set OPAC according to LSB */
if ((tmp_pin_sequence & 0x01) == 0)
{
OnMatchA(PinLow);
}
else
{
OnMatchA(PinHigh);
}
SetupMatchA(tmp);
SwitchToChannel(GetCurrentChanNum()+1);
tmp_pin_sequence>>=1; /* prepare next bit to LSB position */
if (SM_HALF_STEP)
{
tmp_pin_sequence>>=1; /* ... the second next bit in half-step mode */
}
}
}
/*--------------------------------------------------------------------------+
| THREAD NAME: Error |
| DESCRIPTION: Something has gone wrong. :-( |
| Call the Global error routine and end. |
+--------------------------------------------------------------------------*/
else
{
#ifdef GLOBAL_ERROR_FUNC
Global_Error_Func();
#else
ClearAllLatches();
#endif
}
}
/* Information exported to Host CPU program */
#pragma write h, (::ETPUfilename (cpu/etpu_sm_auto.h));
#pragma write h, (/****************************************************************);
#pragma write h, ( * WARNING this file is automatically generated DO NOT EDIT IT! *);
#pragma write h, ( * *);
#pragma write h, ( * FILE NAME: etpu_sm_auto.c COPYRIGHT (c) Freescale 2004 *);
#pragma write h, ( * All Rights Reserved *);
#pragma write h, ( * This file generated by: *);
#pragma write h, ( * $RCSfile: etpuc_sm.c,v $ $Revision: 1.3 $);
#pragma write h, ( * *);
#pragma write h, ( * This file provides an interface between eTPU code and CPU *);
#pragma write h, ( * code. All references to the SM function should be made with *);
#pragma write h, ( * information in this file. This allows only symbolic *);
#pragma write h, ( * information to be referenced which allows the eTPU code to be*);
#pragma write h, ( * optimized without effecting the CPU code. *);
#pragma write h, ( ****************************************************************/);
#pragma write h, (#ifndef _ETPU_SM_AUTO_H_ );
#pragma write h, (#define _ETPU_SM_AUTO_H_ );
#pragma write h, ( );
#pragma write h, (/* Function Configuration Information */);
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_FUNCTION_NUMBER) SM_FUNCTION_NUMBER );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_TABLE_SELECT) ::ETPUentrytype(SM) );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_NUM_PARMS) ::ETPUram(SM) );
#pragma write h, ( );
#pragma write h, (/* Host Service Request Definitions */);
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_INIT_LOW) SM_INIT_LOW );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_INIT_HIGH) SM_INIT_HIGH );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_STOP_LOW) SM_STOP_LOW );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_STOP_HIGH) SM_STOP_HIGH );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_MOVE) SM_MOVE );
#pragma write h, ( );
#pragma write h, (/* Function Mode Definitions */);
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_FULL_STEP 0) );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_HALF_STEP 2) );
#pragma write h, ( );
#pragma write h, (/* Value Definitions */);
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_STEPPING) SM_STEPPING );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_STEPPING_OFF) SM_STEPPING_OFF );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_STEPPING_ON) SM_STEPPING_ON );
#pragma write h, ( );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_DIRECTION) SM_DIRECTION );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_DIRECTION_LEFT) SM_DIRECTION_LEFT );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_DIRECTION_RIGHT) SM_DIRECTION_RIGHT );
#pragma write h, ( );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_SLEW) SM_SLEW );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_SLEW_OFF) SM_SLEW_OFF );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_SLEW_ON) SM_SLEW_ON );
#pragma write h, ( );
#pragma write h, (/* Parameter Definitions */);
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_DESIREDPOSITION_OFFSET) ::ETPUlocation (SM, desired_position) );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_CURRENTPOSITION_OFFSET) ::ETPUlocation (SM, current_position) );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_STARTPERIOD_OFFSET) ::ETPUlocation (SM, start_period) );
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_SLEWPERIOD_OFFSET) ::ETPUlocation (SM, slew_period));
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_CHANNELS_OFFSET) ::ETPUlocation (SM, channels));
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_PINSEQUENCE_OFFSET) ::ETPUlocation (SM, pin_sequence));
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_ACCELTBLSIZE_OFFSET) ::ETPUlocation (SM, accel_tbl_size));
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_ACCELTBL_OFFSET) ::ETPUlocation (SM, accel_tbl));
#pragma write h, (::ETPUliteral(#define FS_ETPU_SM_FLAGS_OFFSET) ::ETPUlocation (SM, flags));
#pragma write h, ( );
#pragma write h, (#endif /* _ETPU_SM_AUTO_H_ */);
#pragma write h, ( );
/*********************************************************************
*
* Copyright:
* Freescale Semiconductor, 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 Freescale
* Semiconductor, Inc. This software is provided on an "AS IS"
* basis and without warranty.
*
* To the maximum extent permitted by applicable law, Freescale
* Semiconductor 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 Freescale Semiconductor 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.
*
* Freescale Semiconductor assumes no responsibility for the
* maintenance and support of this software
*
********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -