dp_msac1.c
资源名称:Profibus.rar [点击查看]
上传用户:hualang
上传日期:2022-04-11
资源大小:104k
文件大小:61k
源码类别:
能源行业(电力石油煤炭)
开发平台:
C/C++
- /********************** Filename: dp_msac1.c *******************************/
- /* ========================================================================= */
- /* */
- /* 0000 000 000 00000 0 000 0 0 0 0000 */
- /* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
- /* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Einsteinstra遝 6 */
- /* 0000 000 0 0 000 0 0 00000 0 0000 91074 Herzogenaurach */
- /* 0 00 0 0 0 0 0 0 0 0 0 */
- /* 0 0 0 0 0 0 0 0 0 0 0 0 0 Tel: ++49-9132-744-200 */
- /* 0 0 0 000 0 0 000 0 0 0 0 GmbH Fax: ++49-9132-744-204 */
- /* */
- /* ========================================================================= */
- /* */
- /* Function: MSAC_C1 functions */
- /* */
- /* ------------------------------------------------------------------------- */
- /* */
- /* Technical support: P. Fredehorst */
- /* Tel. : ++49-9132/744-214 */
- /* Fax. : -204 */
- /* eMail: pfredehorst@profichip.com */
- /* */
- /*****************************************************************************/
- /*****************************************************************************/
- /* contents:
- - function prototypes
- - data structures
- - internal functions
- */
- /*****************************************************************************/
- /* include hierarchy */
- #include "..dp_incplatform.h"
- #include "..dp_incdp_inc.h"
- //#include "E5_Inc.h"
- #ifdef DP_MSAC_C1
- /*---------------------------------------------------------------------------*/
- /* function prototypes */
- /*---------------------------------------------------------------------------*/
- MSAC1_OPMODE msac_c1_get_new_operation_mode (UBYTE dev_num);
- void msac_c1_set_job_running (UBYTE dev_num, UBYTE running );
- void msac_c1_ind_disable_done (UBYTE dev_num, UBYTE sap_nr, UBYTE ret_val );
- void msac_c1_stop (UBYTE dev_num);
- #ifdef DP_ALARM
- void stop_asm (UBYTE dev_num);
- void set_new_alarm_mode (UBYTE dev_num);
- UBYTE alarm_enabled (UBYTE dev_num, UBYTE alarm_type );
- UBYTE acls (UBYTE dev_num, UBYTE alarm_type );
- void init_alarm (UBYTE dev_num, UBYTE power_on );
- UBYTE check_sequence_status (UBYTE dev_num, UBYTE action, UBYTE alarm_type, UBYTE alarm_specifier );
- UBYTE check_type_status (UBYTE dev_num, UBYTE action, UBYTE alarm_type );
- UBYTE check_send_diag (UBYTE dev_num, UBYTE alarm_type, ALARM_STATUS_PDU_PTR alarm_ptr, UBYTE callback );
- void check_send_alarm (UBYTE dev_num);
- DPV1_RET_VAL msac_c1_alarm_quit (UBYTE dev_num, UBYTE sap, DPV1_PTR pdu );
- #endif // #ifdef DP_ALARM
- /*---------------------------------------------------------------------------*/
- /* global variables */
- /*---------------------------------------------------------------------------*/
- #ifdef DP_FDL
- SECTION_DEF_CommuData static IND_RESP_BUF_PTR dpv1_act_ind_ptr[MAX_DEV_NUM];
- SECTION_DEF_CommuData static IND_RESP_BUF_PTR dpv1_act_ind_SAP50_ptr[MAX_DEV_NUM];
- #endif
- #ifdef DP_ALARM
- // table for decoding the number of parallel alarms
- SECTION_DEF_CommuData static UBYTE alarm_decode[MAX_DEV_NUM][ALARM_TYPE_MAX+1]; //wusenlin 原先为ALARM_TYPE_MAX,+1防止越界
- // this variable is used to store the status pdu
- //SECTION_DEF_CommuData static ALARM_STATUS_PDU status_buffer[MAX_DEV_NUM];
- #endif // #ifdef DP_ALARM
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_init */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode DP_ERROR_CODE msac_c1_init(UBYTE dev_num)
- {
- DP_ERROR_CODE error;
- error = DP_OK;
- dp_sys[dev_num].c1.DX_Entered = FALSE;
- dp_sys[dev_num].c1.Operation_Mode = DP_OPMODE_V0;
- dp_sys[dev_num].c1.Start_State = DP_SS_IDLE;
- dp_sys[dev_num].c1.Fdl_Closing = TRUE;
- dp_sys[dev_num].c1.active_Job = FALSE;
- dp_sys[dev_num].c1.event = 0x00;
- #ifdef DP_ALARM
- init_alarm(dev_num, TRUE );
- #endif // #ifdef DP_ALARM
- return error;
- }//DP_ERROR_CODE msac_c1_init(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_pdu_received */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_pdu_received(UBYTE dev_num, UBYTE sap_nr, IND_RESP_BUF_PTR ind_ptr, UBYTE req_add )
- {
- DPV1_PTR dpx_pdu_ptr = ((DPV1_PTR) &ind_ptr->user_data[0]);
- DP_LOCK_IND(dev_num);
- req_add = req_add;
- switch( sap_nr )
- {
- case DP_C1_RD_WR_SAP_NR:
- {
- dpv1_act_ind_ptr[dev_num] = ind_ptr;
- switch( BFWORD2BYTE(dpx_pdu_ptr->read.function_num) )
- {
- case DPV1_FC_READ:
- {
- if( (BFWORD2BYTE(dpx_pdu_ptr->read.length) > 0) && (BFWORD2BYTE(dpx_pdu_ptr->read.length) <=240) && (BFWORD2BYTE(ind_ptr->data_len) == 4) )
- {
- dp_sys[dev_num].c1.event |= MSAC_C1_IND_DS_READ;
- }//if( (dpx_pdu_ptr->read.length > 0) && (dpx_pdu_ptr->read.length <=240) )
- else
- {
- dpx_pdu_ptr->read.function_num |= DPV1_ERROR_BIT_RESPONSE;
- ind_ptr->data_len = DPV1_LEN_NEG_RESPONSE;
- ind_ptr->fc = FC_RESP_L;
- dpx_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
- dpx_pdu_ptr->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_TYPE;
- dpx_pdu_ptr->neg.err_code2 = 0x00;
- fdl_resp_provide(dev_num, sap_nr, FDL_PRIMARY_BUF );
- }//else of if( (dpx_pdu_ptr->read.length > 0) && (dpx_pdu_ptr->read.length <=240) )
- break;
- }//case DPV1_FC_READ:
- case DPV1_FC_WRITE:
- {
- if( BFWORD2BYTE(dpx_pdu_ptr->write.length) > 0 )
- {
- dp_sys[dev_num].c1.event |= MSAC_C1_IND_DS_WRITE;
- }//if( dpx_pdu_ptr->write.length > 0 )
- else
- {
- dpx_pdu_ptr->write.function_num |= DPV1_ERROR_BIT_RESPONSE;
- ind_ptr->data_len = DPV1_LEN_NEG_RESPONSE;
- ind_ptr->fc = FC_RESP_L;
- dpx_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
- dpx_pdu_ptr->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_TYPE;
- dpx_pdu_ptr->neg.err_code2 = 0x00;
- fdl_resp_provide(dev_num, sap_nr, FDL_PRIMARY_BUF );
- }//else of if( dpx_pdu_ptr->write.length > 0 )
- break;
- }//case DPV1_FC_WRITE:
- #ifdef DP_ALARM
- case DPV1_FC_ALARM_ACK:
- {
- logMsg2("DPV1-----step4!n",0,0,0,0,0,0);
- // check, if Alarm functions enabled
- if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- {
- dp_sys[dev_num].c1.event |= MSAC_C1_IND_ALARM_QUIT;
- }//if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- else
- {
- logMsg2("VPC3_SET_USER_LEAVE_MASTER--1!n",0,0,0,0,0,0);
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- }//else of if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- break;
- }//case DPV1_FC_ALARM_ACK:
- #endif
- default:
- {
- logMsg2("VPC3_SET_USER_LEAVE_MASTER--2!n",0,0,0,0,0,0);
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- break;
- }//default:
- }//switch( dpx_pdu_ptr->read.function_num )
- break;
- }//case DP_C1_RD_WR_SAP_NR
- #ifdef DP_ALARM
- case DP_C1_ALARM_SAP_NR:
- {
- if( BFWORD2BYTE(dpx_pdu_ptr->read.function_num) == DPV1_FC_ALARM_ACK )
- {
- //check, if Alarm functions enabled
- if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- {
- dpv1_act_ind_SAP50_ptr[dev_num] = ind_ptr;
- dp_sys[dev_num].c1.event |= MSAC_C1_IND_ALARM_QUIT_SAP50;
- }//if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- else
- {
- logMsg2("VPC3_SET_USER_LEAVE_MASTER--3!n",0,0,0,0,0,0);
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- }//else of if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- }//if( dpx_pdu_ptr->read.function_num == DPV1_FC_ALARM_ACK )
- else
- {
- logMsg2("VPC3_SET_USER_LEAVE_MASTER--4!n",0,0,0,0,0,0);
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- }//else of if( dpx_pdu_ptr->read.function_num == DPV1_FC_ALARM_ACK )
- break;
- }//case DP_C1_ALARM_SAP_NR:
- #endif//#ifdef DP_ALARM
- default:
- {
- logMsg("VPC3_SET_USER_LEAVE_MASTER--5!n",0,0,0,0,0,0);
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- break;
- }//default:
- }//switch( sap_nr )
- DP_UNLOCK_IND(dev_num);
- }//void msac_c1_pdu_received(UBYTE dev_num, UBYTE sap_nr, IND_RESP_BUF_PTR ind_ptr, UBYTE req_add )
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_process */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_process(UBYTE dev_num)
- {
- DPV1_PTR dpv1_act_pdu_ptr;
- if( dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1 )
- {
- if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_READ )
- {
- dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
- msac_c1_set_job_running(dev_num,TRUE);
- switch (user_dpv1_read_req(dev_num,DP_C1_RD_WR_SAP_NR, (DPV1_PTR) dpv1_act_pdu_ptr) )
- {
- case DPV1_OK:
- {
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA + BFWORD2BYTE(dpv1_act_pdu_ptr->read.length);
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_READ;
- break;
- }//case DPV1_OK:
- case DPV1_NOK:
- {
- dpv1_act_pdu_ptr->read.function_num |= DPV1_ERROR_BIT_RESPONSE;
- dpv1_act_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_NEG_RESPONSE;
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_READ;
- break;
- }//case DPV1_NOK:
- case DPV1_DELAY:
- {
- /* user give pdu later back */
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_READ;
- break;
- }//case DPV1_DELAY:
- default:
- {
- vpc3_errcb[dev_num].error_code = dp_sys[dev_num].c1.event;
- vpc3_errcb[dev_num].cn_id = 0;
- // *** no further action of dpv1/c2 ***
- fatal_error(dev_num,_DP_C1, __LINE__, &vpc3_errcb[dev_num]);
- break;
- }//default:
- }//switch (user_dpv1_read_req(dev_num,DP_C1_RD_WR_SAP_NR, (DPV1_PTR) dpv1_act_pdu_ptr) )
- }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_READ )
- if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_WRITE )
- {
- dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
- msac_c1_set_job_running(dev_num, TRUE );
- switch( user_dpv1_write_req(dev_num,DP_C1_RD_WR_SAP_NR,(DPV1_PTR) dpv1_act_pdu_ptr) )
- {
- case DPV1_OK:
- {
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_WRITE;
- break;
- }//case DPV1_OK:
- case DPV1_NOK:
- {
- dpv1_act_pdu_ptr->write.function_num |= DPV1_ERROR_BIT_RESPONSE;
- dpv1_act_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_NEG_RESPONSE;
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_WRITE;
- break;
- }//case DPV1_NOK:
- case DPV1_DELAY:
- {
- /* user give pdu later back */
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_WRITE;
- break;
- }//case DPV1_DELAY:
- default:
- {
- vpc3_errcb[dev_num].error_code = dp_sys[dev_num].c1.event;
- vpc3_errcb[dev_num].cn_id = 0;
- // *** no further action of dpv1/c2 ***
- fatal_error(dev_num,_DP_C1, __LINE__, &vpc3_errcb[dev_num]);
- break;
- }//default:
- }//switch( user_dpv1_write_req(dev_num,DP_C1_RD_WR_SAP_NR,(DPV1_PTR) dpv1_act_pdu_ptr) )
- }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_WRITE )
- }//if( dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1 )
- }//void msac_c1_process(UBYTE dev_num)
- /*---------------------------------------------------------------------------*/
- /* */
- /* UBYTE msac_c1_transmit_delay(UBYTE dev_num,UBYTE sap, UBYTE event, DPV1_RET_VAL status, */
- /* DPV1_PTR pdu) */
- /* */
- /* function: msac_c1_transmit_delay receives response data from the user. */
- /* In this function the response data are checked. In dependence */
- /* of the pdu-opcode und the status the length of the data and */
- /* the function-code is manipulated. Then the dpv1_msc1 transmit */
- /* function is called. */
- /* */
- /* return codes: DPV1_OK ( transmit function is called ) */
- /* DPV1_ERR_NO_JOB ( no active job ) */
- /* DPV1_ERR_INV_PARAM ( invalid parameter ) */
- /* DPV1_NO_VALID_SAP ( invalid sap ) */
- /* */
- /*---------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE msac_c1_transmit_delay(UBYTE dev_num, UBYTE sap, UBYTE event, DPV1_RET_VAL status, DPV1_PTR pdu )
- {
- DPV1_PTR dpv1_act_pdu_ptr;
- UBYTE ret_val;
- ret_val = DPV1_OK;
- if( (sap&0xff) == DP_C1_RD_WR_SAP_NR )//2009.11.7
- {
- if( dp_sys[dev_num].c1.active_Job )
- {
- dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
- switch( status )
- {
- case DPV1_OK:
- {
- if( (event&0xff) == MSAC_C1_IND_DS_WRITE )//2009.11.7
- {
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- }//if( event == MSAC_C1_IND_DS_WRITE )
- else
- {
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA + BFWORD2BYTE(dpv1_act_pdu_ptr->read.length);
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- }//else of if( event == MSAC_C1_IND_DS_WRITE )
- break;
- }//case DPV1_OK:
- case DPV1_NOK:
- {
- dpv1_act_pdu_ptr->read.function_num |= DPV1_ERROR_BIT_RESPONSE;
- dpv1_act_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_NEG_RESPONSE;
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- break;
- }//case DPV1_NOK:
- default:
- {
- ret_val = DPV1_ERR_INV_PARAM;
- break;
- }//default:
- }//switch( status )
- }//if( dp_sys[dev_num].c1.active_Job )
- else
- {
- ret_val = DPV1_ERR_NO_JOB;
- }//else of if( dp_sys[dev_num].c1.active_Job )
- }//if( sap == DP_C1_RD_WR_SAP_NR )
- else
- {
- //dummyline for compiler because warning
- pdu = pdu;
- ret_val = DPV1_NO_VALID_SAP;
- }//else of if( sap == DP_C1_RD_WR_SAP_NR )
- return (ret_val);
- }//UBYTE msac_c1_transmit_delay(UBYTE dev_num, UBYTE sap, UBYTE event, DPV1_RET_VAL status, DPV1_PTR pdu )
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_set_job_running */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_set_job_running(UBYTE dev_num, UBYTE running )
- {
- if( running )
- {
- dp_sys[dev_num].c1.active_Job = TRUE;
- }//if( running )
- else
- {
- dp_sys[dev_num].c1.active_Job = FALSE;
- if( (dp_sys[dev_num].c1.Start_State == DP_SS_STOP) && (dp_sys[dev_num].c1.Fdl_Closing == FALSE) )
- {
- dp_sys[dev_num].c1.Start_State = DP_SS_IDLE;
- }
- if( dp_sys[dev_num].c1.Start_State == DP_SS_START_AGAIN )
- {
- // open C1-SAPs
- fdl_ind_await(dev_num,DP_C1_RD_WR_SAP_NR);
- dp_sys[dev_num].c1.Start_State=DP_SS_RUN;
- }//if( dp_sys[dev_num].c1.Start_State == DP_SS_START_AGAIN )
- }//else of if( running )
- }//void msac_c1_set_job_running(UBYTE dev_num, UBYTE running )
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_ind_disable_done */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_ind_disable_done(UBYTE dev_num, UBYTE sap_nr, UBYTE ret_val )
- {
- if( (sap_nr&0xff) == DP_C1_RD_WR_SAP_NR)//2009.11.7
- {
- if(ret_val != FDL_OK)
- {
- vpc3_errcb[dev_num].error_code = VPC3_MSAC_C1_CLOSE_FAILED;
- fatal_error(dev_num,_DP_C1, __LINE__, &vpc3_errcb[dev_num]);
- }//if(ret_val != FDL_OK)
- dp_sys[dev_num].c1.Fdl_Closing = FALSE;
- dp_sys[dev_num].c1.Start_State = (dp_sys[dev_num].c1.active_Job) ? DP_SS_STOP : DP_SS_IDLE;
- }//if(sap_nr == DP_C1_RD_WR_SAP_NR)
- }//void msac_c1_ind_disable_done(UBYTE dev_num, UBYTE sap_nr, UBYTE ret_val )
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_check_ind_new_prm_data */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE msac_c1_check_ind_new_prm_data(UBYTE dev_num)
- {
- UBYTE ret_val;
- ret_val = TRUE;
- switch( VPC3_GET_DP_STATE(dev_num) )
- {
- case WAIT_PRM:
- {
- dp_sys[dev_num].c1.Operation_Mode = msac_c1_get_new_operation_mode(dev_num);
- break;
- }
- case WAIT_CFG:
- {
- dp_sys[dev_num].c1.Operation_Mode = msac_c1_get_new_operation_mode(dev_num);
- if (dp_sys[dev_num].c1.Start_State == DP_SS_RUN)
- {
- msac_c1_stop(dev_num);
- }
- break;
- }
- case DATA_EX:
- {
- dp_sys[dev_num].c1.Operation_Mode = msac_c1_get_new_operation_mode(dev_num);
- msac_c1_stop(dev_num);
- ret_val=FALSE; /* avoid user-interaction */
- break;
- }
- }//switch( VPC3_GET_DP_STATE(dev_num) )
- #ifdef DP_ALARM
- set_new_alarm_mode(dev_num);
- #endif // #ifdef DP_ALARM
- return ret_val;
- }//UBYTE msac_c1_check_ind_new_prm_data(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_do_cfg_ok */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_do_cfg_ok(UBYTE dev_num)
- {
- if( VPC3_GET_DP_STATE(dev_num) == WAIT_CFG )
- {
- if(dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1)
- {
- if( dp_sys[dev_num].c1.Start_State == DP_SS_IDLE )
- {
- fdl_ind_await(dev_num,DP_C1_RD_WR_SAP_NR);
- dp_sys[dev_num].c1.Start_State = DP_SS_RUN;
- #ifdef DP_ALARM_OVER_SAP50
- fdl_ind_await(dev_num,DP_C1_ALARM_SAP_NR);
- #endif//#ifdef DP_ALARM_OVER_SAP50
- }
- if( dp_sys[dev_num].c1.Start_State == DP_SS_STOP )
- {
- dp_sys[dev_num].c1.Start_State = DP_SS_START_AGAIN;
- }
- }
- dp_sys[dev_num].c1.DX_Entered = FALSE;
- }//if( VPC3_GET_DP_STATE(dev_num) == WAIT_CFG )
- }//void msac_c1_do_cfg_ok(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_do_cfg_not_ok */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_do_cfg_not_ok(UBYTE dev_num)
- {
- switch( VPC3_GET_DP_STATE(dev_num) )
- {
- case WAIT_PRM:
- {
- //do nothing
- break;
- }
- case WAIT_CFG:
- case DATA_EX:
- {
- msac_c1_stop(dev_num);
- break;
- }
- }//switch( VPC3_GET_DP_STATE(dev_num) )
- }//void msac_c1_do_cfg_not_ok(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_check_ind_dx_out */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_check_ind_dx_out(UBYTE dev_num)
- {
- if( ( dp_sys[dev_num].c1.DX_Entered == FALSE )
- && ( VPC3_GET_DP_STATE(dev_num) == DATA_EX )
- && ( dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1 )
- )
- {
- dp_sys[dev_num].c1.DX_Entered = TRUE;
- #ifdef DP_ALARM
- if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- {
- if( dp_sys[dev_num].al.enabled > 0x00 )
- {
- dp_sys[dev_num].al.count = 0;
- dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
- dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
- dp_sys[dev_num].al.state = AL_STATE_OPEN;
- }//if( dp_sys[dev_num].al.enabled > 0x00 )
- else
- {
- dp_sys[dev_num].al.enabled = 0;
- dp_sys[dev_num].al.mode = 0;
- }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
- user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
- }//if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- #endif // #ifdef DP_ALARM
- }//if( (dp_sys[dev_num].c1.DX_Entered == FALSE ) ...
- }//void msac_c1_check_ind_dx_out(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: check_sequence_status */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode MSAC1_OPMODE msac_c1_get_new_operation_mode(UBYTE dev_num)
- {
- VPC3_UNSIGNED8_PTR prm_data;
- if( VPC3_GET_PRM_LEN(dev_num) >= 10 )
- {
- prm_data = VPC3_GET_PRM_BUF_PTR(dev_num);
- if( prm_data && ( *( prm_data + 7*BLACKFIN_MULTIPLER ) & DPV1_STATUS_1_DPV1_ENABLE ) )
- {
- return DP_OPMODE_V1;
- }
- }//if( VPC3_GET_PRM_LEN(dev_num) >= 10 )
- return DP_OPMODE_V0;
- }//MSAC1_OPMODE msac_c1_get_new_operation_mode(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_leave_dx */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_leave_dx(UBYTE dev_num)
- {
- if( VPC3_GET_DP_STATE(dev_num) != DATA_EX )
- {
- msac_c1_stop(dev_num);
- if( (vpc3_get_master(dev_num) != 0xFF ) && (VPC3_GET_DP_STATE(dev_num) == WAIT_PRM ) )
- {
- GO_OFFLINE_VPC3(dev_num);
- START_VPC3(dev_num);
- }//if( (vpc3_get_master(dev_num) != 0xFF ) && (VPC3_GET_DP_STATE(dev_num) == WAIT_PRM ) )
- }//if( VPC3_GET_DP_STATE(dev_num) != DATA_EX )
- }//void msac_c1_leave_dx(UBYTE dev_num)
- // SECTION_DEF_CommuCode void msac_c1_leave_dx_wiscom(UBYTE dev_num)
- // {
- // //重新启用一类主站的非周期状态机
- // if(1)
- // {
- // msac_c1_stop(dev_num);
- // if( (vpc3_get_master(dev_num) != 0xFF ))
- // {
- // msac_c1_check_ind_new_prm_data(dev_num);
- // msac_c1_do_cfg_ok(dev_num);
- //
- // //重新启动状态机
- // #ifdef DP_ALARM
- // if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- // {
- // dp_sys[dev_num].al.state = AL_STATE_OPEN;
- //
- // if( dp_sys[dev_num].al.enabled > 0x00 )
- // {
- // dp_sys[dev_num].al.count = 0;
- // dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
- // dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
- // }//if( dp_sys[dev_num].al.enabled > 0x00 )
- // else
- // {
- // dp_sys[dev_num].al.enabled = 0;
- // dp_sys[dev_num].al.mode = 0;
- // }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
- //
- // user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
- // }//if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- // #endif // #ifdef DP_ALARM
- //
- //
- // }//if( (vpc3_get_master(dev_num) != 0xFF ) && (VPC3_GET_DP_STATE(dev_num) == WAIT_PRM ) )
- // }//if( VPC3_GET_DP_STATE(dev_num) != DATA_EX )
- // }//void msac_c1_leave_dx(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: msac_c1_stop */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void msac_c1_stop(UBYTE dev_num)
- {
- dp_sys[dev_num].c1.event = 0x00;
- if( dp_sys[dev_num].c1.Start_State == DP_SS_RUN )
- {
- dp_sys[dev_num].c1.Fdl_Closing = TRUE;
- // close msac_c1
- fdl_ind_disable(dev_num,DP_C1_RD_WR_SAP_NR);
- #ifdef DP_ALARM
- //close ALARM SAP
- stop_asm(dev_num);
- #endif // #ifdef DP_ALARM
- }//if( dp_sys[dev_num].c1.Start_State == DP_SS_RUN )
- }//void msac_c1_stop(UBYTE dev_num)
- #ifdef DP_ALARM
- /*--------------------------------------------------------------------------*/
- /* function: init_alarm */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void init_alarm(UBYTE dev_num, UBYTE power_on )
- {
- dp_sys[dev_num].al.state = AL_STATE_CLOSED;
- if( power_on == FALSE )
- {
- user_alarm_state_info(dev_num, ALARM_TYPE_NONE_VALUE, SEQC_MODE_TOTAL_00 );
- }
- dpl_init_list__(&dp_sys[dev_num].al.queue_new);
- dpl_init_list__(&dp_sys[dev_num].al.queue_ack);
- dp_sys[dev_num].al.enabled = 0;
- dp_sys[dev_num].al.mode = 0;
- dp_sys[dev_num].al.type_status = 0;
- memset( &dp_sys[dev_num].al.sequence_status[0], 0, AL_SEQUENCE_STATUS_SIZE );
- dp_sys[dev_num].al.sequence = 0;
- dp_sys[dev_num].al.limit = 0;
- dp_sys[dev_num].al.count = 0;
- // init coding table
- alarm_decode[dev_num][0] = SEQC_MODE_OFF ; // no sequence mode - 01 alarm of every type
- alarm_decode[dev_num][1] = SEQC_MODE_TOTAL_02; // sequence mode - 02 alarms in total
- alarm_decode[dev_num][2] = SEQC_MODE_TOTAL_04; // sequence mode - 04 alarms in total
- alarm_decode[dev_num][3] = SEQC_MODE_TOTAL_08; // sequence mode - 08 alarms in total
- alarm_decode[dev_num][4] = SEQC_MODE_TOTAL_12; // sequence mode - 12 alarms in total
- alarm_decode[dev_num][5] = SEQC_MODE_TOTAL_16; // sequence mode - 16 alarms in total
- alarm_decode[dev_num][6] = SEQC_MODE_TOTAL_24; // sequence mode - 24 alarms in total
- alarm_decode[dev_num][7] = SEQC_MODE_TOTAL_32; // sequence mode - 32 alarms in total
- }//void init_alarm(UBYTE dev_num, UBYTE power_on )
- /*--------------------------------------------------------------------------*/
- /* function: set_new_alarm_mode */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void set_new_alarm_mode(UBYTE dev_num)
- {
- VPC3_STRUC_PRM_PTR prm_data;
- dp_sys[dev_num].al.enabled = 0;
- dp_sys[dev_num].al.mode = 0;
- if( (VPC3_GET_PRM_LEN(dev_num) >= PRM_LEN_DPV1 ) && (dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1) )
- {
- prm_data = (VPC3_STRUC_PRM_PTR)VPC3_GET_PRM_BUF_PTR(dev_num);
- if ( prm_data )
- {
- dp_sys[dev_num].al.enabled = (prm_data->dpv1_status_2 & DPV1_STATUS_2_ALARM_TYPE_MASK );
- dp_sys[dev_num].al.mode = (prm_data->dpv1_status_3 & DPV1_STATUS_3_ALARM_MODE_MASK );
- }
- }
- }//void set_new_alarm_mode(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: alarm_enabled */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE alarm_enabled(UBYTE dev_num, UBYTE alarm_type )
- {
- if( ((alarm_type == ALARM_TYPE_PULL
- || alarm_type == ALARM_TYPE_PLUG) && (dp_sys[dev_num].al.enabled & ALARM_TYPE_PULLPLUG_VALUE))
- || (alarm_type == ALARM_TYPE_PROCESS && (dp_sys[dev_num].al.enabled & ALARM_TYPE_PROCESS_VALUE))
- || (alarm_type == ALARM_TYPE_DIAGNOSTIC && (dp_sys[dev_num].al.enabled & ALARM_TYPE_DIAGNOSTIC_VALUE))
- || (alarm_type == ALARM_TYPE_STATUS && (dp_sys[dev_num].al.enabled & ALARM_TYPE_STATUS_VALUE))
- || (alarm_type == ALARM_TYPE_UPDATE && (dp_sys[dev_num].al.enabled & ALARM_TYPE_UPDATE_VALUE))
- || ((alarm_type >= ALARM_TYPE_MANU_MIN
- && alarm_type <= ALARM_TYPE_MANU_MAX) && (dp_sys[dev_num].al.enabled & ALARM_TYPE_MANUFACTURER_VALUE))
- )
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }//UBYTE alarm_enabled(UBYTE dev_num, UBYTE alarm_type )
- /*--------------------------------------------------------------------------*/
- /* function: alarm_process */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void alarm_process(UBYTE dev_num)
- {
- DPV1_PTR dpv1_act_pdu_ptr;
- // check, if Alarm functions enabled
- if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- {
- check_send_alarm(dev_num);
- if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT )
- {
- dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
- msac_c1_set_job_running(dev_num, TRUE );
- //switch (dev_num, msac_c1_alarm_quit(dev_num, DP_C1_RD_WR_SAP_NR, dpv1_act_pdu_ptr ) )
- switch (msac_c1_alarm_quit(dev_num, DP_C1_RD_WR_SAP_NR, dpv1_act_pdu_ptr ) )
- {
- case DPV1_OK:
- {
- dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
- dpv1_act_ind_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT;
- break;
- }
- case DPV1_NOK:
- {
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].al.state = AL_STATE_CLOSED;
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT;
- logMsg2("VPC3_SET_USER_LEAVE_MASTER--6!n",0,0,0,0,0,0);
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- break;
- }
- case DPV1_DELAY:
- {
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT;
- break;
- }
- default:
- {
- break;
- }
- }//switch (msac_c1_alarm_quit(dev_num,alarm_sap, dpv1_act_pdu_ptr) )
- }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT )
- if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT_SAP50 )
- {
- dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_SAP50_ptr[dev_num]->user_data[0]);
- msac_c1_set_job_running(dev_num, TRUE );
- switch (msac_c1_alarm_quit(dev_num, DP_C1_ALARM_SAP_NR, dpv1_act_pdu_ptr ) )
- {
- case DPV1_OK:
- {
- dpv1_act_ind_SAP50_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
- dpv1_act_ind_SAP50_ptr[dev_num]->fc = FC_RESP_L;
- fdl_resp_provide(dev_num, DP_C1_ALARM_SAP_NR, FDL_PRIMARY_BUF );
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT_SAP50;
- break;
- }
- case DPV1_NOK:
- {
- msac_c1_set_job_running(dev_num, FALSE );
- dp_sys[dev_num].al.state = AL_STATE_CLOSED;
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT_SAP50;
- logMsg("VPC3_SET_USER_LEAVE_MASTER--7!n",0,0,0,0,0,0);
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- break;
- }
- case DPV1_DELAY:
- {
- dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT_SAP50;
- break;
- }
- default:
- {
- break;
- }
- }//switch (msac_c1_alarm_quit(dev_num,alarm_sap, dpv1_act_pdu_ptr) )
- }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT_SAP50 )
- }//if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
- }//void alarm_process(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: stop_asm */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void stop_asm(UBYTE dev_num)
- {
- //clear alarm message in diagnostic buffer
- reset_diagnostic_buffer(dev_num);
- #ifdef DP_ALARM_OVER_SAP50
- fdl_ind_disable(dev_num,DP_C1_ALARM_SAP_NR);
- #endif//#ifdef DP_ALARM_OVER_SAP50
- init_alarm(dev_num, FALSE );
- }//void stop_asm(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: acls */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE acls(UBYTE dev_num,UBYTE alarm_type)
- {
- if( alarm_type == ALARM_TYPE_DIAGNOSTIC )
- return 0;
- if( alarm_type == ALARM_TYPE_PROCESS )
- return 1;
- if( alarm_type == ALARM_TYPE_PULL )
- return 2;
- if( alarm_type == ALARM_TYPE_PLUG )
- return 3;
- if( alarm_type == ALARM_TYPE_STATUS )
- return 4;
- if( alarm_type == ALARM_TYPE_UPDATE )
- return 5;
- if( alarm_type >= ALARM_TYPE_MANU_MIN && alarm_type <= ALARM_TYPE_MANU_MAX )
- return 6;
- return 0;//ignore
- }//UBYTE acls(UBYTE dev_num,UBYTE alarm_type)
- /*--------------------------------------------------------------------------*/
- /* function: set_alarm__ */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE set_alarm__(UBYTE dev_num, ALARM_STATUS_PDU_PTR user_alarm_ptr, UBYTE callback )
- {
- UBYTE seq_nr;
- seq_nr = ((user_alarm_ptr->spec & SEQ_NR_MASK) >> SPEC_SEQ_START);
- // if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- // {
- // TRACE("set_alarm__: return SET_ALARM_AL_STATE_CLOSED");
- // return SET_ALARM_AL_STATE_CLOSED;
- // }
- if( alarm_enabled(dev_num, user_alarm_ptr->type ) == FALSE )
- {
- // TRACE("set_alarm__: return SET_ALARM_ALARMTYPE_NOTSUPP");
- return SET_ALARM_ALARMTYPE_NOTSUPP;
- }
- if( (seq_nr&0xff) > MAX_SEQ_NR )//2009.11.7
- {
- // TRACE("set_alarm__: return SET_ALARM_SEQ_NR_ERROR");
- return SET_ALARM_SEQ_NR_ERROR;
- }
- if( (user_alarm_ptr->spec & SPEC_MASK) > 0x03 )
- {
- // TRACE("set_alarm__: return SET_ALARM_SPECIFIER_ERROR");
- return SET_ALARM_SPECIFIER_ERROR;
- }
- user_alarm_ptr->callback = callback;
- dpl_put_blk_to_list_end__(&dp_sys[dev_num].al.queue_new, &user_alarm_ptr->list_head);
- logMsg2("DPV1-----step1!n",0,0,0,0,0,0);
- return SET_ALARM_OK;
- }//UBYTE set_alarm__(UBYTE dev_num, ALARM_STATUS_PDU_PTR user_alarm_ptr, UBYTE callback )
- /*--------------------------------------------------------------------------*/
- /* function: check_send_alarm */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void check_send_alarm(UBYTE dev_num)
- {
- ALARM_UNION_ALARM tmp_anchor;
- ALARM_UNION_ALARM tmp_alarm;
- UBYTE tmp_alarm_specifier;
- UBYTE tmp_alarm_callback;
- UBYTE tmp_alarm_type;
- UBYTE alarm_found;
- tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_new;
- tmp_alarm .list_ptr = dp_sys[dev_num].al.queue_new.next_blk_ptr;
- tmp_alarm_specifier = 0;
- tmp_alarm_type = 0;
- alarm_found = 0;
- while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- {
- tmp_alarm_type = tmp_alarm.data_ptr->type;
- tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
- tmp_alarm_callback = tmp_alarm.data_ptr->callback;
- if( dp_sys[dev_num].al.sequence == FALSE )
- {
- //type mode
- //only one alarm of a specific ALARM_TYPE can be active at one time
- if( check_type_status(dev_num, AL_ALARM_STATUS_ACTION_CHECK, tmp_alarm_type ) == FALSE )
- {
- logMsg2("DPV1-----step2!n",0,0,0,0,0,0);
- if( check_send_diag(dev_num, tmp_alarm_type, tmp_alarm.data_ptr, tmp_alarm_callback ) == DP_OK )
- {
- logMsg2("DPV1-----step3!n",0,0,0,0,0,0);
- check_type_status(dev_num, AL_ALARM_STATUS_ACTION_SET, tmp_alarm_type );
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_SET, tmp_alarm_type, tmp_alarm_specifier );
- dpl_remove_blk__(tmp_alarm.list_ptr);
- tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
- dpl_put_blk_to_list_end__(tmp_anchor.list_ptr, tmp_alarm.list_ptr);
- }
- break;
- }//if( check_type_status(dev_num, AL_ALARM_STATUS_ACTION_CHECK, tmp_alarm_type ) == FALSE )
- }//if( alarm_sequence == FALSE )
- else
- {
- //sequence mode
- //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
- if( dp_sys[dev_num].al.sequence == TRUE && dp_sys[dev_num].al.count < dp_sys[dev_num].al.limit )
- {
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_SET, tmp_alarm_type, tmp_alarm_specifier );
- dpl_remove_blk__(tmp_alarm.list_ptr);
- tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
- dpl_put_blk_to_list_end__(tmp_anchor.list_ptr, tmp_alarm.list_ptr);
- dp_sys[dev_num].al.count++;
- }
- else
- {
- //don't send alarm, because limit is reached
- break;
- }
- }//else of if( alarm_sequence == FALSE )
- tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
- }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- }//void check_send_alarm(UBYTE dev_num)
- /*--------------------------------------------------------------------------*/
- /* function: check_send_diag */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE check_send_diag(UBYTE dev_num, UBYTE alarm_type, ALARM_STATUS_PDU_PTR alarm_ptr, UBYTE callback )
- {
- VPC3_UNION_DIAG_PTR tmp_diag;
- UBYTE user_diag[DIAG_BUFSIZE];
- UBYTE ret_value;
- if( !VPC3_GET_DIAG_FLAG(dev_num) )
- {
- //old diagnostic message is send
- if( callback == TRUE )
- {
- //send alarm over the function user_alarm
- ret_value = user_alarm(dev_num, alarm_type, alarm_ptr->spec, alarm_ptr, TRUE );
- }//if( callback == TRUE )
- else
- {
- tmp_diag.byte_ptr = user_diag;
- memcpy( tmp_diag.byte_ptr, (UBYTE *)&alarm_ptr->header, szAlarmHeader );
- memcpy( tmp_diag.byte_ptr + szAlarmHeader, alarm_ptr->user_data_ptr, alarm_ptr->header - szAlarmHeader );
- ret_value = set_diagnosis(dev_num, tmp_diag, alarm_ptr->header, 0x00, TRUE );
- }//else of if( callback == TRUE )
- }//if( !VPC3_GET_DIAG_FLAG(dev_num) )
- else
- {
- //wait - old diagnosis is not send
- ret_value = DP_DIAG_OLD_DIAG_NOT_SEND_ERROR;
- }//else of if( !VPC3_GET_DIAG_FLAG(dev_num) )
- logMsg("check_send_diag-----ret_value=%02x!n",ret_value,0,0,0,0,0);
- return ret_value;
- }//UBYTE check_send_diag(UBYTE dev_num, UBYTE alarm_type, ALARM_STATUS_PDU_PTR alarm_ptr, UBYTE callback )
- /*--------------------------------------------------------------------------*/
- /* function: clear_alarm */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void clear_alarm(UBYTE dev_num, UBYTE alarm_type_bit_field, UBYTE sequence_number )
- {
- ALARM_UNION_ALARM tmp_anchor;
- ALARM_UNION_ALARM tmp_alarm;
- UBYTE tmp_alarm_specifier;
- UBYTE tmp_alarm_type;
- UBYTE tmp_alarm_type_bit_field;
- //reset all alarms
- if( (alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) && (sequence_number == SEQUENCE_NUMBER_ALL ) )
- {
- dpl_init_list__(&dp_sys[dev_num].al.queue_new);
- dpl_init_list__(&dp_sys[dev_num].al.queue_ack);
- dp_sys[dev_num].al.type_status = 0;
- memset( &dp_sys[dev_num].al.sequence_status[0], 0, AL_SEQUENCE_STATUS_SIZE );
- dp_sys[dev_num].al.count = 0;
- }//if( (alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) && (sequence_number == SEQUENCE_NUMBER_ALL ) )
- else
- {
- tmp_alarm_type_bit_field = 0;
- if ( ALARM_TYPE_DIAGNOSTIC_VALUE & (alarm_type_bit_field) )
- {
- tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_DIAGNOSTIC - 1));
- }
- if ( ALARM_TYPE_PROCESS_VALUE & (alarm_type_bit_field) )
- {
- tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_PROCESS - 1));
- }
- if ( ALARM_TYPE_PULLPLUG_VALUE & (alarm_type_bit_field) )
- {
- tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_PULL - 1)) | (1 << (ALARM_TYPE_PLUG - 1));
- }
- if ( ALARM_TYPE_STATUS_VALUE & (alarm_type_bit_field) )
- {
- tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_STATUS - 1));
- }
- if ( ALARM_TYPE_UPDATE_VALUE & (alarm_type_bit_field) )
- {
- tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_UPDATE - 1));
- }
- if ( ALARM_TYPE_MANUFACTURER_VALUE & (alarm_type_bit_field) )
- {
- tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_MAX - 1));
- }
- tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_new;
- tmp_alarm .list_ptr = dp_sys[dev_num].al.queue_new.next_blk_ptr;
- tmp_alarm_specifier = 0;
- tmp_alarm_type = 0;
- while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- {
- tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
- tmp_alarm_type = tmp_alarm.data_ptr->type;
- if( (( tmp_alarm_type_bit_field & (1 << (acls(dev_num,tmp_alarm_type))) ) || ( alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) )
- && ( ( (tmp_alarm_specifier >> SPEC_SEQ_START) == sequence_number ) || ( sequence_number == SEQUENCE_NUMBER_ALL ) )
- )
- {
- if( dp_sys[dev_num].al.sequence == FALSE )
- {
- //type mode
- //only one alarm of a specific ALARM_TYPE can be active at one time
- check_type_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type );
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
- }//if( alarm_sequence == FALSE )
- else
- {
- //sequence mode
- //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
- dp_sys[dev_num].al.count--;
- }//else of if( alarm_sequence == FALSE )
- }//if( .....
- tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
- }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- }//else of if( ( alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) && ( sequence_number == SEQUENCE_NUMBER_ALL ) )
- }//void clear_alarm(UBYTE dev_num, UBYTE alarm_type_bit_field, UBYTE sequence_number )
- /*--------------------------------------------------------------------------*/
- /* function: check_type_status */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE check_type_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type )
- {
- UBYTE ret_value;
- alarm_type = (UBYTE)(1 << ( acls(dev_num,alarm_type)));
- if( action == AL_ALARM_STATUS_ACTION_SET )
- {
- dp_sys[dev_num].al.type_status |= alarm_type;
- ret_value = TRUE;
- }
- else
- if( action == AL_ALARM_STATUS_ACTION_RESET )
- {
- dp_sys[dev_num].al.type_status &= ~alarm_type;
- ret_value = FALSE;
- }
- else
- {
- ret_value = ( dp_sys[dev_num].al.type_status & alarm_type ) ? TRUE : FALSE;
- }
- return ret_value;
- }//UBYTE check_type_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type )
- /*--------------------------------------------------------------------------*/
- /* function: check_sequence_status */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE check_sequence_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type, UBYTE alarm_specifier )
- {
- VPC3_UNSIGNED8_PTR tmp_alarm_sequence_status_ptr;
- UBYTE ret_value;
- alarm_type = (1 << ( acls(dev_num,alarm_type)));
- //?应是:alarm_type = acls(dev_num,alarm_type);
- // bit field index in alarm_sequence_status
- alarm_type = alarm_type * MAX_SEQ_NR + (alarm_specifier >> SPEC_SEQ_START);
- // bit mask at byte field index in alarm_sequence_status
- alarm_specifier = (UBYTE)(1 << (alarm_type & 0x07));
- /* byte field index in alarm_sequence_status */
- tmp_alarm_sequence_status_ptr = dp_sys[dev_num].al.sequence_status + (alarm_type >> 3);
- if( *tmp_alarm_sequence_status_ptr & alarm_specifier )
- {
- if( action == AL_ALARM_STATUS_ACTION_RESET )
- {
- /* reset only if set */
- *tmp_alarm_sequence_status_ptr &= ~alarm_specifier;
- }
- ret_value = TRUE;
- }
- else
- {
- if( action == AL_ALARM_STATUS_ACTION_SET )
- {
- /* set only if reset */
- *tmp_alarm_sequence_status_ptr |= alarm_specifier;
- }
- ret_value = FALSE;
- }
- return(ret_value );
- }//UBYTE check_sequence_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type, UBYTE alarm_specifier )
- /*--------------------------------------------------------------------------*/
- /* msac_c1_alarm_quit (UBYTE dev_num,called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode DPV1_RET_VAL msac_c1_alarm_quit(UBYTE dev_num, UBYTE sap, DPV1_PTR pdu )
- {
- ALARM_UNION_ALARM tmp_anchor;
- ALARM_UNION_ALARM tmp_alarm;
- DPV1_RET_VAL ret_value;
- UBYTE tmp_alarm_specifier;
- UBYTE tmp_alarm_slot_nr;
- UBYTE tmp_alarm_type;
- UBYTE alarm_found;
- UBYTE alarm_type;
- UBYTE slot_nr;
- UBYTE seq_nr;
- ret_value = DPV1_OK;
- if( ( (sap&0xff) == DP_C1_RD_WR_SAP_NR) || ( (sap&0xff) == DP_C1_ALARM_SAP_NR))
- {
- slot_nr = BFWORD2BYTE(pdu->alarm.slot_num);
- alarm_type = BFWORD2BYTE(pdu->alarm.alarm_type);
- seq_nr = (pdu->alarm.specifier & SEQ_NR_MASK) >> SPEC_SEQ_START;
- tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
- tmp_alarm .list_ptr = dp_sys[dev_num].al.queue_ack.next_blk_ptr;
- tmp_alarm_specifier = 0;
- tmp_alarm_slot_nr = 0;
- tmp_alarm_type = 0;
- alarm_found = FALSE;
- while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- {
- logMsg2("DPV1-----step5!n",0,0,0,0,0,0);
- tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
- tmp_alarm_slot_nr = tmp_alarm.data_ptr->slot;
- tmp_alarm_type = tmp_alarm.data_ptr->type;
- if( ((tmp_alarm_specifier & SEQ_NR_MASK) >> SPEC_SEQ_START == seq_nr )
- && ( tmp_alarm_type == alarm_type )
- && ( tmp_alarm_slot_nr == slot_nr )
- )
- {
- //alarm found
- alarm_found = TRUE;
- break;
- }
- tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
- }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- if( alarm_found == TRUE )
- {
- logMsg2("DPV1-----step6!n",0,0,0,0,0,0);
- if( dp_sys[dev_num].al.sequence == FALSE )
- {
- //type mode
- //only one alarm of a specific ALARM_TYPE can be active at one time
- check_type_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type );
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
- }//if( alarm_sequence == FALSE )
- else
- {
- //sequence mode
- //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
- dp_sys[dev_num].al.count--;
- }//else of if( alarm_sequence == FALSE )
- dpl_remove_blk__(tmp_alarm.list_ptr );
- user_alarm_ack_req(dev_num, tmp_alarm.data_ptr );
- }//if( alarm_found == TRUE )
- else
- {
- logMsg2("msac_c1_alarm_quit----DPV1_NOK--1!n",0,0,0,0,0,0);
- ret_value = DPV1_NOK;
- }//else of if( alarm_found == TRUE )
- }
- else
- {
- logMsg2("msac_c1_alarm_quit----DPV1_NOK--2!n",0,0,0,0,0,0);
- return DPV1_NOK;
- }
- return ret_value;
- }//DPV1_RET_VAL msac_c1_alarm_quit(UBYTE dev_num,UBYTE sap, DPV1_PTR pdu)
- //wusenlin 增加用于报警状态机在通断电情况下报警超时时取消报警
- SECTION_DEF_CommuCode int msac_c1_alarm_quit_wiscom(UBYTE dev_num, UBYTE sap,
- UBYTE slot_nr, UBYTE alarm_type, UBYTE seq_nr)
- {
- #define TYPE_QUIT_LEAVEMASTER
- //ALARM_UNION_ALARM tmp_anchor;
- //ALARM_UNION_ALARM tmp_alarm;
- DPV1_RET_VAL ret_value;
- //UBYTE tmp_alarm_specifier;
- //UBYTE tmp_alarm_slot_nr;
- //UBYTE tmp_alarm_type;
- //UBYTE alarm_found;
- msac_c1_set_job_running(dev_num, TRUE );
- ret_value = DPV1_OK;
- #ifdef TYPE_QUIT_LEAVEMASTER
- //直接退出状态机
- VPC3_SET_USER_LEAVE_MASTER(dev_num);
- //重新启动状态机
- if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- {
- dp_sys[dev_num].al.state = AL_STATE_OPEN;
- if( dp_sys[dev_num].al.enabled > 0x00 )
- {
- dp_sys[dev_num].al.count = 0;
- dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
- dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
- }//if( dp_sys[dev_num].al.enabled > 0x00 )
- else
- {
- dp_sys[dev_num].al.enabled = 0;
- dp_sys[dev_num].al.mode = 0;
- }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
- user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
- }//if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- #else
- if( ( (sap&0xff) == DP_C1_RD_WR_SAP_NR) || ( (sap&0xff) == DP_C1_ALARM_SAP_NR))//2009.11.7
- {
- // slot_nr = BFWORD2BYTE(pdu->alarm.slot_num);
- // alarm_type = BFWORD2BYTE(pdu->alarm.alarm_type);
- // seq_nr = (pdu->alarm.specifier & SEQ_NR_MASK) >> SPEC_SEQ_START;
- tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
- tmp_alarm .list_ptr = dp_sys[dev_num].al.queue_ack.next_blk_ptr;
- tmp_alarm_specifier = 0;
- tmp_alarm_slot_nr = 0;
- tmp_alarm_type = 0;
- alarm_found = FALSE;
- while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- {
- logMsg2("DPV1-----step5!n",0,0,0,0,0,0);
- tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
- tmp_alarm_slot_nr = tmp_alarm.data_ptr->slot;
- tmp_alarm_type = tmp_alarm.data_ptr->type;
- if( ((tmp_alarm_specifier & SEQ_NR_MASK) >> SPEC_SEQ_START == (seq_nr & SEQ_NR_MASK) >> SPEC_SEQ_START )
- && ( tmp_alarm_type == alarm_type )
- && ( tmp_alarm_slot_nr == slot_nr )
- )
- {
- //alarm found
- alarm_found = TRUE;
- break;
- }
- tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
- }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
- if( alarm_found == TRUE )
- {
- logMsg2("DPV1-----step6!n",0,0,0,0,0,0);
- if( dp_sys[dev_num].al.sequence == FALSE )
- {
- //type mode
- //only one alarm of a specific ALARM_TYPE can be active at one time
- check_type_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type );
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
- }//if( alarm_sequence == FALSE )
- else
- {
- //sequence mode
- //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
- check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
- dp_sys[dev_num].al.count--;
- }//else of if( alarm_sequence == FALSE )
- dpl_remove_blk__(tmp_alarm.list_ptr );
- TRACE("msac_c1_alarm_quit_wiscom OK");
- //user_alarm_ack_req(dev_num, tmp_alarm.data_ptr );
- }//if( alarm_found == TRUE )
- else
- {
- //重新启动状态机
- if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- {
- dp_sys[dev_num].al.state = AL_STATE_OPEN;
- if( dp_sys[dev_num].al.enabled > 0x00 )
- {
- dp_sys[dev_num].al.count = 0;
- dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
- dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
- }//if( dp_sys[dev_num].al.enabled > 0x00 )
- else
- {
- dp_sys[dev_num].al.enabled = 0;
- dp_sys[dev_num].al.mode = 0;
- }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
- user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
- }//if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
- TRACE("msac_c1_alarm_quit_wiscom NOK1");
- ret_value = DPV1_NOK;
- }//else of if( alarm_found == TRUE )
- }
- else
- {
- TRACE("msac_c1_alarm_quit_wiscom NOK2");
- ret_value = DPV1_NOK;
- }
- #endif//wusenlin
- msac_c1_set_job_running(dev_num, FALSE );
- return ret_value;
- }//DPV1_RET_VAL msac_c1_alarm_quit(UBYTE dev_num,UBYTE sap, DPV1_PTR pdu)
- #endif//#ifdef DP_ALARM
- #endif //#ifdef DP_MSAC_C1
- /*****************************************************************************/
- /* Copyright (C) profichip GmbH 2004. Confidential. */
- /*****************************************************************************/