⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app_bool.c

📁 AD CONDUCT OF FREESCALE MICRO
💻 C
字号:
/* Copyright 1999 Delphi Delco Electronics Systems *//* * Purpose: maintain global boolean data to insulate other code from *          hardware / class 2 changes. * * Author: kingdj * Date: Fri Feb 21 09:49:46 EST 1997 * $Header: app_bool.c,v 1.40 99/04/23 10:07:03 liue Exp $ *//* include files */#include <string.h>  /* Access to memcpy for copying structure contents. */#include "ad_cond.h"#include "app_bool.h"#include "app_def.h"#include "app_out.h"#include "can_comf.h"#include "can_drive.h"#include "coolant.h"#include "diag_comm.h"#include "dow.h"#include "eeprom.h"#include "ga_table.h"#include "gendefs.h"#include "gensubs.h"#include "io.h"#include "option_.h"#include "power_m.h"#include "rtos.h"#include "tasks.h"#include "telltale.h"/* constants and macros *//* BRAKES_GEN, SEATBELT, PARKING_BRAKE, HOOD_SWITCH, DOOR_OPEN * are active low. *//* type definitions *//* global variables - initialize here */unsigned BYTE Newest[DEBOUNCED_ARRAY_SIZE];unsigned BYTE Prev[DEBOUNCED_ARRAY_SIZE];unsigned BYTE Debounced[UNDEBOUNCED_ARRAY_SIZE];unsigned BYTE New_Edge_Input[EDGE_INPUT_ARRAY_SIZE];unsigned BYTE Prev_Edge_Input[EDGE_INPUT_ARRAY_SIZE];unsigned BYTE Lead[EDGE_INPUT_ARRAY_SIZE];unsigned BYTE Trail[EDGE_INPUT_ARRAY_SIZE];/* local variables - use static */#pragma class NB=PDKAM#pragma noclearunsigned BOOLEAN CAN_driver_door_open;#pragma class NB=CNEAR#pragma clear/* private function prototypes - use static */LOCAL_FUNC void Read_Inputs(void);LOCAL_FUNC void Process_Inputs(void);static void Set_Edge_Input_State(EDGE_INPUT_TYPE input, BOOLEAN state);/* function definitions *//* Purpose: to set the state of a bit in a bit array * * Parameters: none */EXPORT_FUNC void Set_State( BOOLEAN b_input,                            unsigned char *addr,                            unsigned int bitnum ){  if(b_input)    {      Set_Bit_Subr( addr , bitnum );    }  else    {      Clear_Bit_Subr( addr , bitnum );    }}/* Purpose: to configure all the ports as necessary * * Parameters: none */EXPORT_FUNC void Initialize_Ports(void){  /* configure port 0 low */  P0L = P0L_INIT_DATA;  DP0L = DP0L_INIT_DIR;  /* configure port 0 high */  P0H = P0H_INIT_DATA;  DP0H = DP0H_INIT_DIR;  /* configure port 1 low */  P1L = P1L_INIT_DATA;  DP1L = DP1L_INIT_DIR;  /* configure port 1 high */  P1H = P1H_INIT_DATA;  DP1H = DP1H_INIT_DIR;  /* configure port 2 */  P2 = P2_INIT_DATA;  DP2 = DP2_INIT_DIR;  /* configure port 3 */  P3 = P3_INIT_DATA;  DP3 = DP3_INIT_DIR;  /* configure port 4 */  P4 = P4_INIT_DATA;  DP4 = DP4_INIT_DIR;  /* configure a/d discrete input option */  P5DIDIS = P5_DISC_DISABLE_INIT;  /* configure port 6 */  P6 = P6_INIT_DATA;  DP6 = DP6_INIT_DIR;  /* configure port 7 */  P7 = P7_INIT_DATA;  DP7 = DP7_INIT_DIR;  /* configure port 9 */  P9 = P9_INIT_DATA;  DP9 = DP9_INIT_DIR;  /* configure special input threshold */  PICON = PORT_INPUT_CONTROL_INIT;}/* Purpose: to configure all the ports as necessary * * Parameters: none */EXPORT_FUNC void Configure_Ports(void){  /* configure port 0 low */  DP0L |= DP0L_INIT_DIR;  /* configure port 0 high */  DP0H |= DP0H_INIT_DIR;  /* configure port 1 low */  DP1L |= DP1L_INIT_DIR;  /* configure port 1 high */  DP1H |= DP1H_INIT_DIR;  /* configure port 2 */  DP2 |= DP2_INIT_DIR;  /* configure port 3 */  DP3 |= DP3_INIT_DIR;  /* configure port 4 */  DP4 |= DP4_INIT_DIR;  /* configure port 6 */  DP6 |= DP6_INIT_DIR;  /* configure port 7 */  DP7 |= DP7_INIT_DIR;  /* configure port 9 */  DP9 |= DP9_INIT_DIR;  /* configure special input threshold */  PICON = PORT_INPUT_CONTROL_INIT;}/* Purpose: To update the inputs for various level, leading edge, and *          trailing edge detections. * * Parameters: none */EXPORT_FUNC void Update_Inputs(void){  /* Read the most current discrete inputs.  */  Read_Inputs();  /* Debounce and determine leading and trailing edges. */  Process_Inputs();}static BOOLEAN ign_on = FALSE;/* Purpose: To update inputs that are not otherwise updated automatically * * Parameters: none */LOCAL_FUNC void Read_Inputs(void){  /* This bit must be set before the Ignition_1 test.  That way it can be   * cleared if Ignition_1 is low */  if (Ign_1_Is_Logic_Low())    {      ign_on = FALSE;    }  else    {      if (Ign_1_Is_Logic_High())        {          ign_on = TRUE;        }    }  Set_State(ign_on, Newest, IGNITION_1_DISCRETE);//  Set_State(!Oil_Pressure_Input && ign_on, Newest, OIL_PRESSURE);  /* BRAKES_GEN */  Set_State(!Brake_General && ign_on, Newest, BRAKES_GEN);  /* SEATBELT */  Set_State(!Seatbelt_fastened && ign_on, Newest, SEATBELT_UNFASTENED);  /* BRK_LN_WR */  Set_State(!Brake_Lining_Wear && ign_on, Newest, BRK_LN_WR);  /* PARKING_BRAKE */  Set_State(!Parking_brake && ign_on, Newest, PARKING_BRAKE);  /* DIESEL DIAG OK */  Set_State(Diesel_TT_Diag && ign_on, Newest, DIESEL_DIAG_HI);  /* GENERATOR */  Set_State((Ratio_Generator() <= GENERATOR_LOGIC_LO_ON) && ign_on,            Newest, GENERATOR_FAULT);  Set_State(Key_In_S_Contact, Newest, KEY_IN_S_CONTACT);  Set_State(Parking_light_right, Newest, PARKING_LIGHT_RIGHT);  Set_State(Parking_light_left, Newest, PARKING_LIGHT_LEFT);  Set_State(!Driver_door_closed, Newest, DOOR_OPEN);  Set_State(!Trunk_Lid_Closed && ign_on, Newest, TRUNK_OPEN);  /* HOOD_OPEN */  Set_State(!Hood_Switch, Newest, HOOD_OPEN);  Set_State(Trip_Reset, Newest, TRIP_RESET);  Set_State(Clock_Right_Shaft, Newest, CLOCK_MIN);  Set_State(Clock_Left_Shaft, Newest, CLOCK_HOUR);  Set_State(Get_Debounced_DOW(), Debounced, OIL_PRESSURE);}/* Purpose: to perform debouncing * * Parameters: none */LOCAL_FUNC void Process_Inputs(void){  int i;  for(i = 0; i < sizeof(Newest); i++)    {      /* Truth table: (2 out of 3 voting)       * new_debounced     Prev  Newest  Debounced       *      0              0     0        0       *      0              0     0        1       *      0              0     1        0       *      1              0     1        1       *      0              1     0        0       *      1              1     0        1       *      1              1     1        0       *      1              1     1        1       */      Debounced[i] = (Prev[i] & Newest[i]) |        ((Prev[i] | Newest[i]) & Debounced[i]);      /* save latest copy */      Prev[i] = Newest[i];    }}/* Purpose: To set the new state of an input used for edge detection, *          and save the previous state * * Parameters: *   input - edge input to be set *   state - new state to set input to */static void Set_Edge_Input_State(EDGE_INPUT_TYPE input, BOOLEAN state){  BOOLEAN prev_input;  prev_input = Read_Bit(New_Edge_Input, input);  /* Save previous state */  Set_State( prev_input,             Prev_Edge_Input,             input );  /* Set new state */  Set_State( state,             New_Edge_Input,             input );  /* Determine if leading edge */  Set_State( (state && !prev_input),             Lead,             input );  /* Determine if trailing edge */  Set_State( (!state && prev_input),             Trail,             input );}/* APP NOTE FOR EDGE DETECTION OF INPUTS * Add you input processing here, in the appropriate task time.  Inputs * must be updated in each task time that uses edges. *//* Purpose: To update inputs used for edge detection *          IMPORTANT NOTE: This must be called in each task loop that *                          uses edges * * Parameters: *   time - task time in which edges detection will be used */EXPORT_FUNC void Update_Edge_Inputs(EDGE_TIME_TYPE time){  switch(time)    {    case EDGES_10MS:      Set_Edge_Input_State(IGN_10MS,                           Input_Level(IGNITION_1_DISCRETE));      Set_Edge_Input_State(S_CONTACT_10MS,                           Input_Level(KEY_IN_S_CONTACT));      Set_Edge_Input_State(S_CONTACT_OR_IGN_10MS,                           (Input_Level(KEY_IN_S_CONTACT) ||                            Input_Level(IGNITION_1_DISCRETE)));      break;    case EDGES_20MS:      Set_Edge_Input_State(CLOCK_MIN_20MS,                           Input_Level(CLOCK_MIN));      Set_Edge_Input_State(CLOCK_HOUR_20MS,                           Input_Level(CLOCK_HOUR));      Set_Edge_Input_State(IGN_20MS,                           Input_Level(IGNITION_1_DISCRETE));      Set_Edge_Input_State(S_CONTACT_20MS,                           Input_Level(KEY_IN_S_CONTACT));      Set_Edge_Input_State(S_CONTACT_OR_IGN_20MS,                           (Input_Level(KEY_IN_S_CONTACT) ||                            Input_Level(IGNITION_1_DISCRETE)));      break;    case EDGES_40MS:      Set_Edge_Input_State(CLOCK_MIN_40MS,                           Input_Level(CLOCK_MIN));      Set_Edge_Input_State(IGN_40MS,                           Input_Level(IGNITION_1_DISCRETE));      Set_Edge_Input_State(TRIP_RESET_40MS,                           Input_Level(TRIP_RESET));      break;    case EDGES_640MS:      Set_Edge_Input_State(HOOD_OPEN_640MS,                           Input_Level(HOOD_OPEN));      break;    default:      break;    }}/* Purpose: To process the inputs during initialization. * * Parameters: none */EXPORT_FUNC void Inputs_Initialization(void){   Update_Inputs();   Update_Inputs();}/* Purpose: To clear all inputs on power mode change * * Parameters: none */EXPORT_FUNC void Clear_Inputs_On_Ignition(void){  Newest[2] = 0;  Prev[2] = 0;  memset(&Debounced[2], 0, sizeof(Debounced)-2 );}/* Purpose: To get the driver door status, regardless of its input *          source * * Parameters: *   returns - TRUE if driver door is open */EXPORT_FUNC BOOLEAN Driver_Door_Open(void){  /* Check if driver door comes from CAN */  if (Door_Status_From_CAN())    {      /* If we've received a first value, set state accordingly */      if (CC_BSG_1_First_Value())        {          if (Door_Status_CAN_Timeout())            {              CAN_driver_door_open = FALSE;            }          else            {              CAN_driver_door_open = CC_Get_BS1_DriversDoorOpened_b();            }          return CAN_driver_door_open;        }      /* No first value...keep the last known state */      else        {          return CAN_driver_door_open;        }    }  else    {      /* Not CAN - returned debounced discrete input */      return (Input_Level(DOOR_OPEN));    }}/* * $SOURCE: ip_project@flint.iac:01_a4_beetle_ip:app_bool.c $ * $REVISION: 1.60 $ * $AUTHOR: flint.iac:/users/eckharac/dsds/vw_a4:eckharac $ */

⌨️ 快捷键说明

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