Freescale Semiconductor Inc.
Main Page | Data Structures | File List | Data Fields | Globals

etpu_crank.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *
00003 * Freescale Semiconductor Inc.
00004 * (c) Copyright 2004-2015 Freescale Semiconductor, Inc.
00005 * ALL RIGHTS RESERVED.
00006 *
00007 ****************************************************************************//*!
00008 *
00009 * @file    etpu_crank.h
00010 *
00011 * @author  Milan Brejl [r54529]
00012 *
00013 * @version 1.1
00014 *
00015 * @date    29-Jun-2015
00016 *
00017 * @brief   This file contains useful macros and prototypes for CRANK API.
00018 *
00019 *******************************************************************************/
00020 #ifndef _ETPU_CRANK_H_
00021 #define _ETPU_CRANK_H_
00022 
00023 /*******************************************************************************
00024 * Includes
00025 *******************************************************************************/
00026 #include "etpu_util.h"        /* 24-bit types */
00027 #include "etpu_crank_auto.h"  /* auto generated header file */
00028 
00029 /*******************************************************************************
00030 * Type Definitions
00031 *******************************************************************************/
00032 /** A structure to represent an instance of CRANK.
00033  *  It includes static CRANK initialization items. */
00034 struct crank_instance_t
00035 {
00036   const uint8_t  chan_num;  /**< Channel number of the CRANK channel. */
00037   const uint8_t  priority;  /**< Channel priority for the CRANK channel. */
00038   const uint8_t  polarity;  /**< CRANK transition polarity.
00039     It defines which type of transitions are captured. It can be one of:
00040     - @ref FS_ETPU_CRANK_FM0_USE_TRANS_RISING
00041     - @ref FS_ETPU_CRANK_FM0_USE_TRANS_FALLING */
00042   const uint8_t  teeth_till_gap; /**< A number of physical teeth between 2 gaps.
00043     This is the number of physical teeth on the crank wheel divided by
00044     the number of (equally spaced) gaps on the wheel. */
00045   const uint8_t  teeth_in_gap; /**< A number of missing teeth in one gap.
00046     This can be assigned a value of 1, 2, 3 (for eTPU and eTPU2), up to 7
00047     (for eTPU2+), or 0. The value 0 indicates there is an additional tooth
00048     instead of missing teeth. */
00049   const uint8_t  teeth_per_cycle; /**< A number of teeth (including missing
00050     teeth in gap) per an engine cycle (720 degrees). It must be a multiple of
00051     (teeth_till_gap + teeth_in_gap). */
00052   const uint24_t tcr2_ticks_per_tooth; /**< A number of TCR2 angle ticks per one
00053     tooth. It can be any value between 1 and 1024. */
00054   const uint24_t tcr2_ticks_per_add_tooth; /**< A number of TCR2 angle ticks
00055     from the last tooth to the additional tooth. It can be any value between 
00056     1 and 1024. This parameter only applies for crank pattern with an additional
00057     tooth (teeth_in_gap=0). */
00058   const uint8_t  log_tooth_periods; /**< An option to record tooth_periods.
00059     It can be one of:
00060     - @ref FS_ETPU_CRANK_FM1_TOOTH_PERIODS_LOG_OFF
00061     - @ref FS_ETPU_CRANK_FM1_TOOTH_PERIODS_LOG_ON */
00062   const uint32_t link_cam;  /**< Set of 4 link numbers to send to reset the Cam
00063     log. Up to 4 Cam channel numbers can be used. In case of a single Cam on
00064     channel 1, use 0x01010101. */
00065   const uint32_t link_1;    /**< The first  set of 4 link numbers to send when
00066     stall conditions accure. */
00067   const uint32_t link_2;    /**< The second set of 4 link numbers to send when
00068     stall conditions accure. */
00069   const uint32_t link_3;    /**< The third  set of 4 link numbers to send when
00070     stall conditions accure. */
00071   const uint32_t link_4;    /**< The fourth set of 4 link numbers to send when
00072     stall conditions accure. */
00073         uint32_t *cpba;     /**< Channel parameter base address.
00074     Set cpba = 0 to use automatic allocation of eTPU DATA RAM for CRANK channel
00075     parameters using the eTPU utility function fs_etpu_malloc (recommanded),
00076     or assign the cpba manually by an address where the CRANK channel parameter
00077     space will start from, e.g. 0xC3FC8100. */
00078         uint32_t *cpba_tooth_period_log; /**< Base address of the CRANK tooth
00079     period log buffer in eTPU DATA RAM. Set cpba_tooth_period_log = 0 to use
00080     automatic allocation of eTPU DATA RAM for this buffer using the eTPU utility
00081     function fs_etpu_malloc (recommanded), or assign the p_tooth_period_log
00082     manually by an address where the CRANK buffer will start. The memory does
00083     not need to be allocated if FS_ETPU_CRANK_FM1_TOOTH_PERIODS_LOG_OFF is set.*/
00084 };
00085 
00086 /** A structure to represent a configuration of CRANK.
00087  *  It includes CRANK configuration items which can be changed in
00088  *  run-time. */
00089 struct crank_config_t
00090 {
00091         uint8_t  teeth_per_sync; /**< A number of teeth (including the
00092     missing teeth in gap) corresponding to a segment which is needed for the Cam
00093     to log enough Cam transitions so that it enables to recognize the correct
00094     engine half-cycle and achieve synchronozation. It must be a multiple of
00095     (teeth_till_gap + teeth_in_gap). */
00096         uint24_t blank_time; /**< A TCR1 time period after initialization during
00097     which teeth are ignored. */
00098         uint8_t  blank_teeth; /**< A number of teeth ignored after
00099     initialization. */
00100         ufract24_t gap_ratio; /**< A fraction used to perform the ABA gap test.
00101     For a crank wheel with a gap:
00102       gap_ratio * tooth_period_B > tooth_period_A.
00103     For a crank wheel with an additional tooth:
00104       gap_ratio * tooth_period_A > tooth_period_B. */
00105         ufract24_t win_ratio_normal; /**< A fraction used to derive
00106     the acceptance window for the next normal tooth. */
00107         ufract24_t win_ratio_across_gap; /**< A fraction used to derive
00108     the acceptance window for the first tooth after the gap. */
00109         ufract24_t win_ratio_after_gap; /**< A fraction used to derive
00110     the acceptance window for the second tooth after the gap. */
00111         ufract24_t win_ratio_after_timeout; /**< A fraction used to derive
00112     the acceptance window for the tooth following a timeout condition. */
00113         uint24_t first_tooth_timeout; /**< A TCR1 time period after the first
00114     tooth (after blank_teeth) when a timeout will be deemed to have happened. */
00115 };
00116 
00117 /** A structure to represent internal states of CRANK. */
00118 struct crank_states_t
00119 {
00120         uint8_t error;      /**< This is the error status of CRANK. It includes
00121     the following error flags:
00122     - @ref FS_ETPU_CRANK_ERR_INVALID_TRANS
00123     - @ref FS_ETPU_CRANK_ERR_INVALID_MATCH
00124     - @ref FS_ETPU_CRANK_ERR_TIMEOUT
00125     - @ref FS_ETPU_CRANK_ERR_STALL
00126     - @ref FS_ETPU_CRANK_ERR_INTERNAL
00127     - @ref FS_ETPU_CRANK_ERR_TIMEOUT_BEFORE_GAP
00128     - @ref FS_ETPU_CRANK_ERR_TIMEOUT_AFTER_GAP
00129     - @ref FS_ETPU_CRANK_ERR_TOOTH_IN_GAP
00130     The eTPU sets the error flags, the CPU clears them after reading. */
00131         uint8_t state; /**< This is the state of CRANK. It can be one of:
00132     - @ref FS_ETPU_CRANK_SEEK
00133     - @ref FS_ETPU_CRANK_BLANK_TIME
00134     - @ref FS_ETPU_CRANK_BLANK_TEETH
00135     - @ref FS_ETPU_CRANK_FIRST_TRANS
00136     - @ref FS_ETPU_CRANK_SECOND_TRANS
00137     - @ref FS_ETPU_CRANK_TEST_POSSIBLE_GAP
00138     - @ref FS_ETPU_CRANK_VERIFY_GAP
00139     - @ref FS_ETPU_CRANK_COUNTING
00140     - @ref FS_ETPU_CRANK_COUNTING_TIMEOUT
00141     - @ref FS_ETPU_CRANK_TOOTH_BEFORE_GAP
00142     - @ref FS_ETPU_CRANK_TOOTH_BEFORE_GAP_NOT_HRM
00143       @ref FS_ETPU_CRANK_ADDITIONAL_TOOTH
00144     - @ref FS_ETPU_CRANK_TOOTH_AFTER_GAP  */
00145         uint8_t eng_pos_state; /**< This is the global engine position state.
00146     It can be one of:
00147     - @ref FS_ETPU_ENG_POS_SEEK
00148     - @ref FS_ETPU_ENG_POS_FIRST_HALF_SYNC
00149     - @ref FS_ETPU_ENG_POS_PRE_FULL_SYNC
00150     - @ref FS_ETPU_ENG_POS_FULL_SYNC  */
00151         uint8_t tooth_counter_gap; /**< The actual number of the tooth counter
00152     which counts from 1 to teeth_till_gap and resets on every gap. */
00153         uint8_t tooth_counter_cycle; /**< The actual number of the tooth counter
00154     which counts from 1 to teeth_per_cycle and resets every engine cycle. */
00155        uint24_t last_tooth_period; /**< The last tooth period as a number
00156     of TCR1 ticks. */
00157 };
00158 
00159 /*******************************************************************************
00160 * Function prototypes
00161 *******************************************************************************/
00162 /* Initialize */
00163 uint32_t fs_etpu_crank_init(
00164   struct crank_instance_t *p_crank_instance,
00165   struct crank_config_t   *p_crank_config);
00166 
00167 /* Change configuration */
00168 uint32_t fs_etpu_crank_config(
00169   struct crank_instance_t *p_crank_instance,
00170   struct crank_config_t   *p_crank_config);
00171 
00172 /* Get states */
00173 uint32_t fs_etpu_crank_get_states(
00174   struct crank_instance_t *p_crank_instance,
00175   struct crank_states_t   *p_crank_states);
00176 
00177 /* Set synchronization */
00178 uint32_t fs_etpu_crank_set_sync(
00179   struct crank_instance_t *p_crank_instance,
00180                  uint24_t tcr2_adjustment);
00181 
00182 /* Copy tooth_period_log */
00183 uint24_t *fs_etpu_crank_copy_tooth_period_log(
00184   struct crank_instance_t *p_crank_instance,
00185                  uint24_t *p_tooth_period_log);
00186 
00187 /* Get resetting engine angle */
00188 uint32_t fs_etpu_crank_get_angle_reseting(void);
00189 
00190 
00191 #endif /* _ETPU_CRANK_H_ */
00192 /*******************************************************************************
00193  *
00194  * Copyright:
00195  *  Freescale Semiconductor, INC. All Rights Reserved.
00196  *  You are hereby granted a copyright license to use, modify, and
00197  *  distribute the SOFTWARE so long as this entire notice is
00198  *  retained without alteration in any modified and/or redistributed
00199  *  versions, and that such modified versions are clearly identified
00200  *  as such. No licenses are granted by implication, estoppel or
00201  *  otherwise under any patents or trademarks of Freescale
00202  *  Semiconductor, Inc. This software is provided on an "AS IS"
00203  *  basis and without warranty.
00204  *
00205  *  To the maximum extent permitted by applicable law, Freescale
00206  *  Semiconductor DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
00207  *  INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
00208  *  PARTICULAR PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH
00209  *  REGARD TO THE SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
00210  *  AND ANY ACCOMPANYING WRITTEN MATERIALS.
00211  *
00212  *  To the maximum extent permitted by applicable law, IN NO EVENT
00213  *  SHALL Freescale Semiconductor BE LIABLE FOR ANY DAMAGES WHATSOEVER
00214  *  (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00215  *  BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER
00216  *  PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
00217  *
00218  *  Freescale Semiconductor assumes no responsibility for the
00219  *  maintenance and support of this software
00220  ******************************************************************************/
00221 /*******************************************************************************
00222  *
00223  * REVISION HISTORY:
00224  *
00225  * FILE OWNER: Milan Brejl [r54529]
00226  *
00227  * Revision 1.1  2015/06/29  r54529
00228  * Parameter crank_instance_t.tcr2_ticks_per_add_tooth added.
00229  * Function fs_etpu_crank_get_angle_reseting added.
00230  *
00231  * Revision 1.0  2014/03/25  r54529
00232  * Minor comment and formating improvements.
00233  * Ready for eTPU Engine Control Library release 1.0.
00234  *
00235  * Revision 0.3  2013/11/28  r54529
00236  * Support of up to 7 missing teeth on eTPU2+.
00237  *
00238  * Revision 0.2  2012/11/28  r54529
00239  * Revision of instance and config structures.
00240  *
00241  * Revision 0.1  2012/06/13  r54529
00242  * Initial version of file.
00243  ******************************************************************************/