📄 intspc3.c
字号:
/*
+------------------------------------------------------------------------+
| Project: D P S 2 w i t h S P C 3 |
| |
| File: DPS2SPC3.C |
| Date: 27-Sep-2007 |
| Version: V 1.17 |
| Initial Editor: Thomas Lang Final Editor: Wujiang Zhang |
+------------------------------------------------------------------------+
| Description: |
| This module handles the interupts of the SPC3 |
+------------------------------------------------------------------------+
| following environments are supported |
| Processor: SAB C165 |
| Compiler: BSO Tasking 80166 C Cross-Compiler, V 4.0 |
| Processor: iNTEL 8032 |
| Compiler: Keil |
| |
| |
+------------------------------------------------------------------------+
| Copyright (C) SIEMENS AG, 1994 |
| All Rights reserved |
+------------------------------------------------------------------------+
| History: |
| V0.9,SX,24-Oct-1995, Pilot verion |
| V1.0,SX,02-Nov-1995, 1st version |
| V1.1,SX,14-Nov-1995, Addition of the attribute SPC3_PTR_ATTR |
| (= xdata) at *user_io_data_len_ptr |
| V1.3,MM,24-Mar-1997, & --> && in parameter-check-routine |
| |
+------------------------------------------------------------------------+
| Technical support: Siemens Schnittstellencenter |
| AUT7 WKF B1 TDL2 |
| |
| Schmidt Xaver Mittelberger Martin |
| Tel.: 0911/750-2079 Tel.: 0911/750-2072 |
| |
| Fax.: -2100 |
| Mailbox: 0911/737972 |
| |
+------------------------------------------------------------------------+
*/
#define SPC3_INTEL_MODE TRUE
#define SPC3_FAR
#define SPC3_DPS2
#define SPC3_DATA_XDATA
#include "spc3dps2.h"
#if defined __C51__
/* special defines for the 80166 processor */
/* are set to nothing */
#define huge
#define global
#define public
#elif _C166
#include "reg.h"
#else
#include <dos.h>
#endif
/*----------------------------------------------------------------------*/
/* STRUCTURES AND TYPEDEFS */
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* EXTERNAL FUNCTIONS */
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* INTERNAL FUNCTIONS */
/*----------------------------------------------------------------------*/
void address_data_function (void SPC3_PTR_ATTR*, UBYTE);
void wd_dp_mode_timeout_function (void);
void global_ctrl_command_function (void);
void go_leave_data_ex_function (void);
/*----------------------------------------------------------------------*/
/* LITERALLIES */
/*----------------------------------------------------------------------*/
#define DPS_CFG_OK 0
#define DPS_CFG_FAULT 1
#define DPS_CFG_UPDATE 2
/*----------------------------------------------------------------------*/
/* MACROS */
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* GLOBAL VARIABLES */
/*----------------------------------------------------------------------*/
UBYTE user_dps_state;
UBYTE user_global_ctrl_command;
UBYTE user_wd_state;
UBYTE store_mintsdr;
extern UBYTE real_no_add_chg;
extern UBYTE this_station;
extern UBYTE cfg_akt [20];
extern UBYTE cfg_len_akt;
extern DPS2_IO_DATA_LEN SPC3_PTR_ATTR *user_io_data_len_ptr; /* Aenderung 14.11.95 */
extern UBYTE prm_tst_buf[];
#ifndef _IM182
extern SPC3 SPC3_PTR_ATTR spc3;
#endif
/************************************************************************/
/* D e s c r i p t i o n : */
/* */
/* dps2_ind */
/* */
/* This function is called by the hardware interrupt */
/************************************************************************/
#if defined __C51__
void dps2_ind(void) interrupt 0
#elif _C166
interrupt (0x1b) void dps2_ind(void) /* CC11 = EX3IN */
#else
void dps2_ind(void)
#endif
{
if(DPS2_GET_IND_GO_LEAVE_DATA_EX())
{ /*=== Start or the end of the Data-Exchange-State ===*/
go_leave_data_ex_function();
DPS2_CON_IND_GO_LEAVE_DATA_EX(); /* confirm this indication */
}
if(DPS2_GET_IND_NEW_GC_COMMAND())
{ /*=== New Global Control Command ===*/
global_ctrl_command_function();
DPS2_CON_IND_NEW_GC_COMMAND(); /* confirm this indication */
}
if(DPS2_GET_IND_NEW_PRM_DATA())
{ /*=== New parameter data ===*/
UBYTE SPC3_PTR_ATTR * prm_ptr;
UBYTE param_data_len, prm_result;
UBYTE ii;
prm_result = DPS2_PRM_FINISHED;
do
{ /* Check parameter until no conflict behavior */
prm_ptr = DPS2_GET_PRM_BUF_PTR();
param_data_len = DPS2_GET_PRM_LEN();
/* data_length_netto of parametration_telegram > 7 */
if (param_data_len > 7)
{
if (( *(prm_ptr+8) == 0xAA) && ( *(prm_ptr+9) == 0xAA))
prm_result = DPS2_SET_PRM_DATA_NOT_OK(); /* as example !!! */
else
{
for (ii= 0; ii<param_data_len && ii <10; ii++) /* store in the interim buffer */
prm_tst_buf[ii] = *(prm_ptr+ii+7); /* for the diagnostic */
/* !!!!!! as example !!!! */
prm_result = DPS2_SET_PRM_DATA_OK();
}
}
else
prm_result = DPS2_SET_PRM_DATA_OK();
} while(prm_result == DPS2_PRM_CONFLICT);
store_mintsdr = *(prm_ptr+3); /* store the mintsdr for restart after */
/* baudrate search */
}
if(DPS2_GET_IND_NEW_CFG_DATA())
{ /*=== New Configuration data ===*/
UBYTE SPC3_PTR_ATTR * cfg_ptr;
UBYTE config_data_len, cfg_result, result;
cfg_result = DPS2_CFG_FINISHED;
result = DPS_CFG_OK;
do
{ /* check configuration data until no conflict behavior m*/
cfg_ptr = DPS2_GET_CFG_BUF_PTR(); /* pointer to the config_data_block */
config_data_len = DPS2_GET_CFG_LEN();
/* In this example the only possible configurations are 0x13 and 0x23
(4 Byte I/O) or 0x11 and 0x21 (2 Byte I/O) are possible */
if ( config_data_len != 2)
cfg_result = DPS2_SET_CFG_DATA_NOT_OK();
else
{ /* Length of the configuration data o.k. */
/* check the configuratin bytes */
if ((cfg_akt[0] == cfg_ptr[0]) && (cfg_akt[1] == cfg_ptr[1]))
result = DPS_CFG_OK;
/* the desired conf. is equal the actuall configuration */
else
{
if (((cfg_ptr[0] == 0x13) && (cfg_ptr[1]) ==0x23)
|| ((cfg_ptr[0] == 0x11) && (cfg_ptr[1]) ==0x21))
{
cfg_akt[0] = cfg_ptr[0];
cfg_akt[1] = cfg_ptr[1];
result = DPS_CFG_UPDATE;
}
else
result = DPS_CFG_FAULT; /* as example !!!!! */
if (result == DPS_CFG_UPDATE)
{
user_io_data_len_ptr = dps2_calculate_inp_outp_len (cfg_ptr,(UWORD)config_data_len);
if (user_io_data_len_ptr != (DPS2_IO_DATA_LEN *)0)
{
DPS2_SET_IO_DATA_LEN(user_io_data_len_ptr);
}
else
result = DPS_CFG_FAULT;
}
}
switch (result)
{
case DPS_CFG_OK: cfg_result = DPS2_SET_CFG_DATA_OK();
break;
case DPS_CFG_FAULT: cfg_result = DPS2_SET_CFG_DATA_NOT_OK();
break;
case DPS_CFG_UPDATE: cfg_result = DPS2_SET_CFG_DATA_UPDATE();
break;
}
}
} while(cfg_result == DPS2_CFG_CONFLICT);
}
if(DPS2_GET_IND_NEW_SSA_DATA())
{ /*=== New Slave address received ===*/
address_data_function(DPS2_GET_SSA_BUF_PTR(), DPS2_GET_SSA_LEN());
DPS2_CON_IND_NEW_SSA_DATA(); /* confirm this indication */
}
if(DPS2_GET_IND_WD_DP_MODE_TIMEOUT())
{ /*=== Watchdog is run out ===*/
wd_dp_mode_timeout_function();
DPS2_CON_IND_WD_DP_MODE_TIMEOUT(); /* confirm this indication */
}
if(SPC3_GET_IND_USER_TIMER_CLOCK())
{ /*==== Timer tick received ====*/
SPC3_CON_IND_USER_TIMER_CLOCK();
}
if(SPC3_GET_IND_BAUDRATE_DETECT())
{ /*==== Baudrate found ====*/
/* If the baudrate has lost and again found in the state WAIT_CFG, */
/* DATA_EX the SPC3 would answer to the next telegramms */
/* with his default mintsdr. */
/* But he should answer in the meantime parametrized mindstr */
if ((DPS2_GET_DP_STATE() == DPS2_DP_STATE_WAIT_CFG )
|| (DPS2_GET_DP_STATE() == DPS2_DP_STATE_DATA_EX))
SPC3_SET_MINTSDR(store_mintsdr);
SPC3_CON_IND_BAUDRATE_DETECT();
}
SPC3_SET_EOI(); /* */
} /* End dps2_ind() */
/************************************************************************/
/* D e s c r i p t i o n : */
/* */
/* address data function */
/************************************************************************/
#pragma global
void address_data_function (void SPC3_PTR_ATTR*(address_data_ptr), UBYTE address_data_len)
{
char ch;
/* change the slave-address */
struct dps_address_data SPC3_PTR_ATTR * addr_ptr;
ch=address_data_len;
addr_ptr = address_data_ptr;
this_station = addr_ptr->new_address;
real_no_add_chg = addr_ptr->no_add_chg;
/* store the new address and the bit real_no_add_chg for the next startup */
DPS2_FREE_SSA_BUF(); /* release the Set Slave Address buffer */
}
#pragma public
/************************************************************************/
/* D e s c r i p t i o n : */
/* */
/* restart_function */
/************************************************************************/
#pragma global
void wd_dp_mode_timeout_function (void)
{
UBYTE rueck;
/* Watchdog is run out. The SPC3 reset the PROFIBUS DP Statemachine */
user_wd_state = SPC3_GET_WD_STATE();
/*SX small weakness of the SPC3
Update of the diagnosis with 00
otherwise the bit "static diagnosis" would appear in the
next startup */
rueck = DPS2_SET_DIAG_LEN(6);
rueck = DPS2_SET_DIAG_STATE(0x00);
DPS2_DIAG_UPDATE();
}
#pragma public
/************************************************************************/
/* D e s c r i p t i o n : */
/* */
/* global_ctrl_command_function */
/************************************************************************/
#pragma global
void global_ctrl_command_function (void)
{
user_global_ctrl_command = DPS2_GET_GC_COMMAND();
}
#pragma public
/************************************************************************/
/* D e s c r i p t i o n : */
/* */
/* go_leave_data_ex_function */
/************************************************************************/
#pragma global
void go_leave_data_ex_function (void)
{
user_dps_state = DPS2_GET_DP_STATE();
}
#pragma public
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -