📄 ac_shutoff.c
字号:
/* Copyright 2000 Delphi Delco Electronics Systems *//* include files */#include "ac_shutoff.h"#include "ad_cond.h"#include "app_bool.h"#include "app_def.h"#include "coolant.h"#include "gendefs.h"#include "interrupt.h"#include "io.h"#include "tach.h" /* used for Engine_Running *//* constants and macros */#define AC_MANAGER_RATE (50) /* Hz */#define INP_TEMP_OFFSET 40 /* Input offset from Get_Coolant_temp()*/#define AC_SHUT_OFF_TEMP_OFFSET 60 /* offset */#define OVERTEMP_TIMEOUT ((unsigned WORD) (2 * AC_MANAGER_RATE)) /* sec */#define AC_SHUTOFF_BIT_TIME ((unsigned WORD) (0.020 * TIMER_7_RATE )) /* 20 ms Bit rate*/#define AC_MANAGER_LATENCY (1.0 / AC_MANAGER_RATE * TIMER_7_RATE)#define PAUSE_TX_TIME ((unsigned WORD)(0.500 * TIMER_7_RATE - AC_MANAGER_LATENCY)) /* 500 ms pause, subtracting o/s loop time latency */#define INIT_IGN_ON ((unsigned WORD) (0.160 * AC_MANAGER_RATE)) /* sec */#define BUFFER_LENGTH 2 /* out put Buffer size */#define AC_TX_HIGH 0 /* to transmit HIGH signal st connector */#define AC_TX_LOW 1 /* to transmit LOW signal at connector */#define COOLANT_MAX_LIMIT ((unsigned BYTE) (118 + AC_SHUT_OFF_TEMP_OFFSET)) /* Coolant Max Limit + offset */#define COOLANT_MIN_LIMIT ((unsigned BYTE) (113 + AC_SHUT_OFF_TEMP_OFFSET)) /* Coolant Max Limit + offset */#define COOLANT_ERROR ((unsigned BYTE)(-10 + AC_SHUT_OFF_TEMP_OFFSET)) /* Coolent error -10 + offset */#define CLUST_READ_HIGH (130 + AC_SHUT_OFF_TEMP_OFFSET) /* cluster can read coolant temp range 30 to 135 */#define CLUST_READ_LOW (30 + AC_SHUT_OFF_TEMP_OFFSET)/* type definitions */typedef enum{ START_BIT, DATA_KEY_BIT_0, DATA_KEY_BIT_1, DATA_KEY_BIT_2, DATA_TEMP_BIT_0, DATA_TEMP_BIT_1, DATA_TEMP_BIT_2, DATA_TEMP_BIT_3, DATA_TEMP_BIT_4, DATA_TEMP_BIT_5, DATA_TEMP_BIT_6, DATA_TEMP_BIT_7, PARITY_BIT, STOP_BIT, PAUSE, DONE } BIT_SEQUENCE_ENUM;/* global variables - initialize here *//* local variables - use static */static unsigned BYTE byte_num; /* index of buffer */static BIT_SEQUENCE_ENUM bit_num; /* bit access */static unsigned BYTE coolant_temp_data; /* to hold coolant temperature */static unsigned BYTE immob_key_code; /* to hold Immoblizer key no */static unsigned WORD buffer[BUFFER_LENGTH];static BOOLEAN transmission_in_progress =FALSE; /* if transmission is in progress FLAG shall be HIGH */static BOOLEAN coolant_temp_error;/* private function prototypes - use static */LOCAL_FUNC void Calculate_Temp_Coolant(void);LOCAL_FUNC void Get_Immoblizer_Key_No(void);LOCAL_FUNC void Send_Discrete_AC_Shutoff(void);LOCAL_FUNC void Pack_Buffer_For_Discrete(void);/* function definitions *//* Purpose: a/c shutoff discrete output Manager * * Parameters: none */EXPORT_FUNC void AC_shutoff_Manager(void){ static unsigned WORD ign_timer = 0; static BOOLEAN coolant_overtemp = FALSE; /* get Immoblizer code */ Get_Immoblizer_Key_No();/* to get offset */ Calculate_Temp_Coolant(); if (Input_Level(IGNITION_1_DISCRETE)) { if (ign_timer < 0xffff) { ign_timer++; } } else /* ign off */ { ign_timer = 0; } /* Initialization */ if (ign_timer > INIT_IGN_ON) { if ( !transmission_in_progress) { if (coolant_temp_error) { /* Invalid temp data */ coolant_overtemp = FALSE; } else { if (coolant_temp_data > COOLANT_MAX_LIMIT) { coolant_overtemp = TRUE; } else if (coolant_temp_data < COOLANT_MIN_LIMIT) { coolant_overtemp = FALSE; } } if ((coolant_overtemp) && (ign_timer >= OVERTEMP_TIMEOUT)) { /* Indicate overtemp condition by setting output low. * This can only be done after ignition has been on * long enough. */ AC_Shut_Off = AC_TX_LOW; } else { /* Transmit current data */ Send_Discrete_AC_Shutoff(); } }/* end of transmission_in_progress */ } /* end of ign_timer >= INIT_IGN_ON */}/* end of function Manager *//* Purpose: calculate Coolant temperature * * Parameters: none */LOCAL_FUNC void Calculate_Temp_Coolant(void) { unsigned BYTE value; coolant_temp_error = Get_AC_Shutoff_Coolant_Temperature(&value); if(value) { /* Adjust bias offset */ INCREMENT_LIMITED(value, (AC_SHUT_OFF_TEMP_OFFSET - INP_TEMP_OFFSET)); /* limit values to valid range */ if (value < CLUST_READ_LOW) { coolant_temp_data = CLUST_READ_LOW; } else if (value > CLUST_READ_HIGH) { coolant_temp_data = CLUST_READ_HIGH; } else { coolant_temp_data = (unsigned BYTE)(value); } } else { /* if Get_temp() returns zero Cluster detects an Implausible value * or transducer failure * transmit -10,ie. -10 + offset*/ coolant_temp_data = COOLANT_ERROR; } }/* Purpose: Immobilizer key number determination * * Parameters: none */LOCAL_FUNC void Get_Immoblizer_Key_No(void){ /* get the Key number */ if(Emergency_Release_Active) { immob_key_code = 0x00; /* if emergency key is used */ } else if((Key_Number()) && (Key_Number()< 0x08)) { immob_key_code = Key_Number() - 1; } else if ( Key_Number() == 0x08) { immob_key_code = 0x00; } else { immob_key_code = 0x07; /* error code */ }}/* Purpose: Interrupt service routine for ac shutoff * * Parameters: none */LOCAL_FUNC interrupt (CC24_TRAP_NUM) void Ac_shutoff_Interrupt(void){ static unsigned WORD current_byte; /* By default, set next interrupt to occur in AC_SHUTOFF_BIT_TIME seconds */ unsigned WORD delay_for_next_interrupt = AC_SHUTOFF_BIT_TIME; switch(bit_num) { case START_BIT : AC_Shut_Off = AC_TX_LOW; current_byte = buffer[byte_num]; bit_num++; break; case DATA_KEY_BIT_0 : case DATA_KEY_BIT_1 : case DATA_KEY_BIT_2 : case DATA_TEMP_BIT_0 : /*Coolant Temp data */ case DATA_TEMP_BIT_1 : case DATA_TEMP_BIT_2 : case DATA_TEMP_BIT_3 : case DATA_TEMP_BIT_4 : case DATA_TEMP_BIT_5 : case DATA_TEMP_BIT_6 : case DATA_TEMP_BIT_7 : case PARITY_BIT : AC_Shut_Off = ((BYTE)(current_byte & 0x0001) ? AC_TX_HIGH : AC_TX_LOW); current_byte >>= 1; bit_num++; break; case STOP_BIT : byte_num++; /* step to next telegram buffer+1*/ bit_num++; AC_Shut_Off = AC_TX_HIGH; if (byte_num < BUFFER_LENGTH) /* first telegram with no pause */ { bit_num = START_BIT; } break; case PAUSE : if (byte_num >=BUFFER_LENGTH) { /* set next compare to occur only after PAUSE_TX_TIME */ delay_for_next_interrupt = PAUSE_TX_TIME; AC_Shut_Off = AC_TX_HIGH; /* set out pin to logic high */ bit_num++; } else { bit_num = START_BIT; /* first telegram is finished */ } /* this should be transmitted after two telegrams */ break; case DONE : /* disabling the Interrupt */ CC24IE = 0; transmission_in_progress = FALSE; /* end of telegram process*/ byte_num = 0; /* set back the Index to zero */ /* to send a LOW at the OUTPUT PIN */ bit_num = START_BIT; break; default : /* shouldn't ever get here */ CC24IE = 0; AC_Shut_Off = AC_TX_HIGH; /* default state of AC shutoff pin */ transmission_in_progress = FALSE; } /* end of case */ CC24 += delay_for_next_interrupt; /* add bit time for next imterrupt */} /* end of func *//* Purpose: to send discrete data * * Parameters: none */LOCAL_FUNC void Send_Discrete_AC_Shutoff(void){ AC_Shut_Off = AC_TX_HIGH; Pack_Buffer_For_Discrete(); /* to select timer :*/ /* if ACC24 = 0, timer T7 shall be selected*/ /* if ACC24 = 1 timer T8 shall be selected */ ACC24 = 0; /* associate CC with timer T7*/ /* set to compare without affecting the output pin */ /* setting the mode reg which work's on Interrupt only ( CCM6 is a MODE REG) */ BFLD(CCM6, 0x0007,0x0004); /* set interrupt level and group */ CC24IC = AC_SHUT_DW_INTERRUPT_LEVEL; byte_num =0; /* to keep track of buffer index */ bit_num = START_BIT; transmission_in_progress = TRUE; /* transmitting status Tx is in progress*/ /* T7 is esfr bit it is initialized in timer_io.c to zero */ CC24 = T7; /* set start of first bit equal to current time in T7 */ /* Set IR flag so interrupt for first bit starts immediately after IE is * turned on */ CC24IR = 1; /* Enable interrupt */ CC24IE = 1; /* Interrupt should occur immediately */}/* Purpose: to pack data into telegrams * * Parameters: none *//* Design.*//* 1. start Bit is 0 *//* 2. stop Bit is 1 *//* telegram is designed has 2 words packed in Buffer and with high output of 500ms*/LOCAL_FUNC void Pack_Buffer_For_Discrete(void){ unsigned WORD temp_key,temp,temp1; temp_key = 0x0000; temp = 0x0000; /* bit sequence lsb-----------------------------------msb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 bo b1 b2 t0 t1 t2 t3 t4 t5 t6 t7 P X X X X X- don't care */ temp = coolant_temp_data ; /* get the coolant temp data */ temp = temp << 3; /* set the coolent form 4th to 11th bit position */ temp_key = immob_key_code & 0x07; /* get Immob_key to lower 3 bits position */ temp = temp | temp_key; /*data packed from 1 to 11th bit */ temp = temp & 0x07ff; /* to generate even parity */ temp1 = temp ; temp1 ^=temp1 >> 8; temp1 ^=temp1 >> 4; temp1 ^=temp1 >> 2; temp1 ^=temp1 >> 1; if ( (temp1 & 0x0001)== 0x0001) { temp = temp | 0x0800; /* to place even parity bit at 12 bit */ } else { temp = temp & 0xf7ff; /* to place parity in 12th position */ } /* final telegram */ buffer[0]=buffer[1] = temp;}/* * $SOURCE: ip_project@flint.iac:01_a4_beetle_ip:ac_shutoff.c $ * $REVISION: 1.8 $ * $AUTHOR: flint.iac:/users/wileyeg/dsds/01a4beet:wileyeg $ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -