📄 etpuc_qom.c
字号:
/****************************************************************************
* FILE NAME: etpu_qom.c COPYRIGHT (c) FREESCALE 2004 *
* DESCRIPTION: All Rights Reserved *
* This function generates complex pulse trains without CPU intervention *
* using a sequence of output matches. An output match causes a *
* programmable pin response when a user-defined value is matched by the *
* value of a free-running counter. QOM generates multiple output matches *
* using a queue of offset times and pin responses stored in parameter *
* RAM. The queue size is user-programmable. Various modes of queue *
* operation are supported. The function is based on the QOM *
* (Queued Output Match) TPU function. *
*==========================================================================*
* ORIGINAL AUTHOR: Geoff Emerson *
* $Log: etpuc_qom.c,v $
* Revision 1.3 2004/11/03 13:48:27 r47354
* Fix for first match behaviour when the reference is in the past
*
* Revision 1.2 2004/11/02 13:56:30 r12110
* -Added support for building function stand alone or in a set.
* -This includes using the global error function if avaialable.
* -Updated comments in auto generated file to include version number.
* -Fixed comments for version 1.0.0.5 compiler.
*
* Revision 1.1 2004/11/01 15:57:50 r12110
* No changes to code, just updated for CVS and checked into CVS.
*
*..........................................................................*
* 0.00 G. Emerson 12/Feb/04 Initial version of file. *
* 0.1 G. Emerson 20/Feb/04 Add ref time handling. *
* 0.2 G. Emerson 25/Mar/04 Code size reduction. Add auto file *
* generation *
* 0.3 G. Emerson 14/Apr/04 Fix for interrupt/DTR generation *
* 0.4 G. Emerson 14/Apr/04 Remove Link generation capability *
* Now resides in TEST function *
* Remove ETPU_QOM_ from local defines *
*0.5 G. Emerson 18/May/04 Added DisableMatchesInThread to all *
* init threads *
* Use ConfigMatch_AB macro *
* Change to loop handling so get n *
* not n+1 iteraions *
* Added INIT_LSR_HIGH, INIT_LSR_LOW, *
* INIT_LSR_NC threads to replace *
* INIT_LSR *
*0.6 G. Emerson 31/May/04 Add EnableOutputBuffer to init threads *
* to allow correct Puma operation *
*0.7 G. Emerson 23/June/04 Changes to #pragma write h statements *
* for GCT compatability *
*0.8 G. Emerson 25/June/04 Add FS_ prefix to these Macros *
* ETPU_QOM_TABLE_START_PTR_OFFSET *
* ETPU_QOM_TABLE_END_PTR_OFFSET *
* ETPU_QOM_LAST_MATCH_TIME_OFFSET *
* ETPU_QOM_LOOP_COUNT_OFFSET *
* ETPU_QOM_OPTION_OFFSET *
* ETPU_QOM_REF_ADDR_PTR_OFFSET *
* ETPU_QOM_FUNCTION_NUMBER *
* ETPU_QOM_TABLE_SELECT *
* ETPU_QOM_NUM_PARMS *
*0.9 G. Emerson 16/July/04 Add Disclaimer *
* ToDo: *
* Error handling code. *
* Debug and reduce code size *
****************************************************************************/
#ifndef __ETPUC_H
#include <etpuc.h> /*Defines eTPU hardware*/
#endif
#ifndef __ETPUC_COMMON_H
#include <eTPUc_common.h> /*Standard way to use eTPU*/
#endif
/* eTPU QOM Definitions */
#define IMMEDIATE 0
#define USE_LAST_EVENT 1
#define USE_REF_ADDRESS 3
#define INIT_PIN_LOW_LINK 2
#define INIT_PIN_HIGH_LINK 3
#define INIT_PIN_NO_CHANGE_LINK 4
#define INIT_PIN_LOW 5
#define INIT_PIN_HIGH 6
#define INIT_PIN_NO_CHANGE 7
#define SINGLE_SHOT 0
#define LOOP 1
#define CONTINUOUS 2
#define CONTINUOUS_A 3
#define SINGLE_SHOT 0
#define LOOP 1
#define CONTINUOUS 2
#define CONTINUOUS_A 3
#ifdef QOM_FUNCTION_NUMBER /* function is being compiled as part a set? */
#pragma ETPU_function QOM, standard @ QOM_FUNCTION_NUMBER;
#else
#pragma ETPU_function QOM, standard; /* stand alone */
#endif
/* General Notes: */
/*--------------------------------------------------------------------------+
| CHANNEL PARAMETERS: (host modifiable) |
| Table_Start_ptr: Contains the address of the start of the table containing|
| match counts to be scheduled. |
| Table_End_Ptr: Contains the address of the end of the table containing |
| match counts to be scheduled. |
| Last_Match_Time: The value in TCR ticks of the last match which occurred |
| This parameter is only updated when the queue is |
| completed in single shot mode or when all loops have been|
| completed in loop shot |
| Ref_Addr_ptr: Pointer to adddress of referene time if using ref mode |
| Loop: For loop mode the current iteration counter |
| Option: Reference mode: The LSB and (LSB+1) define |
| mode for first match as follows: |
| 0b00 : Schedule immediate match |
| 0b01 : Schedule match relative to time of last match |
| event (Last_Match_Time) |
| 0b11 : Schedule match relative in address pointed to by |
| Ref_Addr_Ptr |
| TimeBase: The MSB selects timebase as follows |
| 0b0 : use TCR1 |
| 0b1 : use TCR2 |
| Link service flag: The MSB-1 determines whether a link |
| will be serviced as follows: |
| 0b0 : Link will not be serviced |
| 0b1 : Link will be serviced |
+--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------+
| LOCAL VARIABLES: (currently implemented as channel paramaters) |
| Current_Match_Ptr: Contains the address in the match table of the match |
| being serviced. |
| Offset: The offset (in TCR counts)*2 for next match. Currently |
| the LS Bit contains the next pin state indicator. |
| (i.e. not as per design document). |
|Overrun: Determines whether all matches in the queue have been |
| serviced. If allmatches have been serviced then a channel|
| interrupt and data transfer request is sent. |
+--------------------------------------------------------------------------*/
void QOM(int24 *Table_Start_Ptr, int24 *Table_End_Ptr, int24 Last_Match_Time,
int8 Loop, int8 Option, int24 *Ref_Addr_ptr )
{
static int24 *Current_Match_Ptr;
static int24 Offset;
static int8 Overrun;
/*--------------------------------------------------------------------------+
| THREAD NAME: INIT_HI |
| DESCRIPTION: Initialise a channel to run the QOM function.The HSR bits |
| dictate the pin should be initialised high. |
| 1. Set the pin high then go to INIT_NC thread for further |
| config. |
+--------------------------------------------------------------------------*/
if ( HostServiceRequest == INIT_PIN_HIGH )
{
DisableMatchesInThread();
Init_Hi_QOM:
SetPinHigh();
goto Initialise_QOM;
}
/*--------------------------------------------------------------------------+
| THREAD NAME: INIT_LO |
| DESCRIPTION: Initialise a channel to run the QOM function.The HSR bits |
| dictate the pin should be initialised low. |
| 1. Set the pin low then go to INIT_NC thread for further |
| config. |
+--------------------------------------------------------------------------*/
else if ( HostServiceRequest == INIT_PIN_LOW )
{
DisableMatchesInThread();
Init_Lo_QOM:
SetPinLow();
goto Initialise_QOM;
}
/*--------------------------------------------------------------------------+
| THREAD NAME: INIT_LSR_NC |
| DESCRIPTION: Initialise a channel to run the QOM function when a Link |
| Service Request is recieved. |
| 1. Disable matches in the thread. |
| 2. Set the LSR_flag to indicate that a link has been recieved|
+--------------------------------------------------------------------------*/
else if( HostServiceRequest == INIT_PIN_NO_CHANGE_LINK )
{
Init_QOM_LNK_NC:
DisableMatchesInThread();
Option = Option | 0x40; /*arm the LSR_flag*/
EnableOutputBuffer();
}
/*--------------------------------------------------------------------------+
| THREAD NAME: INIT_LSR_LOW |
| DESCRIPTION: Initialise a channel to run the QOM function when a Link |
| Service Request is recieved. Pin state to be un-changed |
| 1. Disable matches in the thread. |
| 2. Set Pin Low and proceed as per INIT_LSR_NC |
+--------------------------------------------------------------------------*/
else if( HostServiceRequest == INIT_PIN_LOW_LINK )
{
DisableMatchesInThread();
SetPinLow();
goto Init_QOM_LNK_NC;
}
/*--------------------------------------------------------------------------+
| THREAD NAME: INIT_LSR_HIGH |
| DESCRIPTION: Initialise a channel to run the QOM function when a Link |
| Service Request is recieved. Pin state to be un-changed |
| 1. Disable matches in the thread. |
| 2. Set Pin High and proceed as per INIT_LSR_NC |
+--------------------------------------------------------------------------*/
else if( HostServiceRequest == INIT_PIN_HIGH_LINK )
{
DisableMatchesInThread();
SetPinHigh();
goto Init_QOM_LNK_NC;
}
/*--------------------------------------------------------------------------+
| THREAD NAME: INIT_NC |
| DESCRIPTION: Initialise a channel to run the QOM function.The HSR bits |
| dictate the pin should be initialised with no change |
| 1. Disable matches in thread in case there are any previous |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -