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

etpu_spark.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *
00003 * Freescale Semiconductor Inc.
00004 * (c) Copyright 2004-2014 Freescale Semiconductor, Inc.
00005 * ALL RIGHTS RESERVED.
00006 *
00007 ****************************************************************************//*!
00008 *
00009 * @file    etpu_spark.h
00010 *
00011 * @author  Milan Brejl [r54529]
00012 *
00013 * @version 1.0
00014 *
00015 * @date    17-Mar-2014
00016 *
00017 * @brief   This file contains useful macros and prototypes for SPARK API.
00018 *
00019 *******************************************************************************/
00020 #ifndef _ETPU_SPARK_H_
00021 #define _ETPU_SPARK_H_
00022 
00023 /*******************************************************************************
00024 * Includes
00025 *******************************************************************************/
00026 #include "etpu_util.h"        /* 24-bit types */
00027 #include "etpu_spark_auto.h"  /* auto generated header file */
00028 
00029 /*******************************************************************************
00030 * Definitions
00031 *******************************************************************************/
00032 
00033 /*******************************************************************************
00034 * Type Definitions
00035 *******************************************************************************/
00036 /** A structure to represent an instance of SPARK.
00037  *  It includes static SPARK initialization items. */
00038 struct spark_instance_t
00039 {
00040   const uint8_t  chan_num;  /**< Channel number of the SPARK channel. */
00041   const uint8_t  priority;  /**< Channel priority for the SPARK channel. */
00042   const uint8_t  polarity;  /**< SPARK polarity. It can one any of:
00043     - @ref FS_ETPU_SPARK_FM0_ACTIVE_HIGH - active output signal state is high
00044     - @ref FS_ETPU_SPARK_FM0_ACTIVE_LOW - active output signal state is low */
00045   const uint24_t  tdc_angle; /**< The cylinder Top Dead Center as a number
00046     of TCR2 angle ticks relative to zero engine angle, in a range corresponding
00047     to 0-720 degrees. */
00048         uint32_t *cpba;     /**< Channel parameter base address.
00049     Set cpba = 0 to use automatic allocation of eTPU DATA RAM for SPARK channel
00050     parameters using the eTPU utility function fs_etpu_malloc (recommanded),
00051     or assign the cpba manually by an address where the SPARK channel parameter
00052     space will start from, e.g. 0xC3FC8100. */
00053         uint32_t *cpba_single_spark; /**< Base address of the single spark array
00054     in eTPU DATA RAM. Set cpba_single_spark = 0 to use automatic allocation of
00055     the eTPU DATA RAM space corresponding to the spark_count value,
00056     using the eTPU utility function fs_etpu_malloc (recommanded),
00057     or assign the cpba_sparks manually by an address, e.g. 0xC3FC8100. */
00058 };
00059 
00060 /** A structure to represent a configuration of SPARK.
00061  *  It includes SPARK configuration items which can be changed in run-time. */
00062 struct spark_config_t
00063 {
00064    int24_t angle_offset_recalc;  /**< The recalculation offset angle as a
00065     number of TCR2 ticks.
00066     At the end of one spark the start angle of the next spark is calculated
00067     according to the actual engine speed and end_angle. The calculation is
00068     repeated once again in order to adjust to a speed change at a defined
00069     angular position before the originaly calculated start_angle. This position
00070     is given by angle_offset_recalc. */
00071   uint24_t dwell_time_min;  /**< The minimum spark dwell time as a number of
00072     TCR1 ticks. */
00073   uint24_t dwell_time_max;  /**< The maximum spark dwell time as a number of
00074     TCR1 ticks. */
00075   uint24_t multi_on_time;  /**< The multi-pulse ON-time as a number of TCR1
00076     ticks. */
00077   uint24_t multi_off_time;  /**< The multi-pulse OFF-time as a number of TCR1
00078     ticks. */
00079   uint8_t  spark_count;  /**< The count of single sparks per engine-cycle. */
00080   struct single_spark_config_t *p_single_spark_config; /**< Pointer to the first
00081     item of an array of the single spark configuration structures. */
00082   uint8_t  generation_disable;     /**< This parameter disables/enables
00083     the generation of output pulses. It can be assigned one of the values:
00084     - @ref FS_ETPU_SPARK_GENERATION_ALLOWED
00085     - @ref FS_ETPU_SPARK_GENERATION_DISABLED */
00086 };
00087 
00088 /** A structure to represent a single spark configuration. */
00089 struct single_spark_config_t
00090 {
00091    int24_t end_angle;  /**< The tdc_angle-relative stark main pulse end angle
00092     as a number of TCR2 ticks.
00093     Positive values precede the TDC, negative go after.
00094     The spark start angle is calculated, based on the currecnt engine speed,
00095     so that the spark main pulse ends at the end_angle. */
00096   uint24_t dwell_time;  /**< The spark dwell time as a number of TCR1 ticks. */
00097   uint8_t  multi_pulse_count;  /**< The count of multi-pulses following the
00098     main spark pulse. */
00099 };
00100 
00101 /** A structure to represent states of SPARK. */
00102 struct spark_states_t
00103 {
00104         uint8_t  error;     /**< This is the error status of SPARK. It may
00105     include the following error flags:
00106     - @ref FS_ETPU_SPARK_ERROR_MIN_DWELL_APPLIED
00107     - @ref FS_ETPU_SPARK_ERROR_MAX_DWELL_APPLIED
00108     The eTPU sets the error flags, the CPU clears them after reading. */
00109         uint24_t dwell_time_applied;  /**< This is the last spark dwell-time
00110     actually generated. The value corresponds to commanded dwell_time, but
00111     it may slightly differ in case of rapid acceleration or deceleration. */
00112 };
00113 
00114 /*******************************************************************************
00115 * Function prototypes
00116 *******************************************************************************/
00117 /* Initialize */
00118 uint32_t fs_etpu_spark_init(
00119   struct spark_instance_t *p_spark_instance,
00120   struct spark_config_t   *p_spark_config);
00121 
00122 /* Change configuration */
00123 uint32_t fs_etpu_spark_config(
00124   struct spark_instance_t *p_spark_instance,
00125   struct spark_config_t   *p_spark_config);
00126 
00127   /* Get states */
00128 uint32_t fs_etpu_spark_get_states(
00129   struct spark_instance_t *p_spark_instance,
00130   struct spark_states_t   *p_spark_states);
00131 
00132 #endif /* _ETPU_SPARK_H_ */
00133 /*******************************************************************************
00134  *
00135  * Copyright:
00136  *  Freescale Semiconductor, INC. All Rights Reserved.
00137  *  You are hereby granted a copyright license to use, modify, and
00138  *  distribute the SOFTWARE so long as this entire notice is
00139  *  retained without alteration in any modified and/or redistributed
00140  *  versions, and that such modified versions are clearly identified
00141  *  as such. No licenses are granted by implication, estoppel or
00142  *  otherwise under any patents or trademarks of Freescale
00143  *  Semiconductor, Inc. This software is provided on an "AS IS"
00144  *  basis and without warranty.
00145  *
00146  *  To the maximum extent permitted by applicable law, Freescale
00147  *  Semiconductor DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
00148  *  INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
00149  *  PARTICULAR PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH
00150  *  REGARD TO THE SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
00151  *  AND ANY ACCOMPANYING WRITTEN MATERIALS.
00152  *
00153  *  To the maximum extent permitted by applicable law, IN NO EVENT
00154  *  SHALL Freescale Semiconductor BE LIABLE FOR ANY DAMAGES WHATSOEVER
00155  *  (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00156  *  BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER
00157  *  PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
00158  *
00159  *  Freescale Semiconductor assumes no responsibility for the
00160  *  maintenance and support of this software
00161  ******************************************************************************/
00162 /*******************************************************************************
00163  *
00164  * REVISION HISTORY:
00165  *
00166  * FILE OWNER: Milan Brejl [r54529]
00167  *
00168  * Revision 1.0  2014/03/17  r54529
00169  * Minor comment and formating improvements.
00170  * Ready for eTPU Engine Control Library release 1.0.
00171  *
00172  * Revision 0.1  2013/09/17  r54529
00173  * Initial version of file.
00174  ******************************************************************************/