📄 intspc30816.c
字号:
/*
+--(︻┳一▄︻┻┳═一---------------------------------------------------+
| Project: D P S 2 w i t h S P C 3 |
| |
| File: INTSPC3.C |
| Date: 24-Mar-1997 |
| Version: V 1.30 |
| Initial Editor: Schmidt Xaver |
+------------------------------------------------------------------------+
| Description: |
| This module handles the interupts of the SPC3(此模块处理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;数据交换状态的启停标志位;PDF69or75;PDF22;HP8==*/
go_leave_data_ex_function();/* 得DP状态;即user_dps_state = DPS2_GET_DP_STATE(); .Hp10 */
DPS2_CON_IND_GO_LEAVE_DATA_EX(); /* confirm this indication;PDF76 */
}
if(DPS2_GET_IND_NEW_GC_COMMAND())
{ /*=== New Global Control Command;新的全局控制命令;PDF69or75; .Hp8 ===*/
global_ctrl_command_function();/*即user_global_ctrl_command = DPS2_GET_GC_COMMAND();.Ip9 ;.Hp10 */
DPS2_CON_IND_NEW_GC_COMMAND(); /* confirm this indication;即spc3.int_reg.ack.b[_IMH] = (UBYTE)NEW_GC_COMMAND_B;宏即0x01 */
}
if(DPS2_GET_IND_NEW_PRM_DATA()) /* 说明见PDF77 11.3.6;SHp39*/
{ /*=== New parameter data;新的参数数据;PDF75; .Hp8 ===*/
UBYTE SPC3_PTR_ATTR * prm_ptr;
UBYTE param_data_len, prm_result;
UBYTE ii;
prm_result = DPS2_PRM_FINISHED; /* #define DPS2_PRM_FINISHED 0x00 */
do
{ /* Check parameter until no conflict behavior */
prm_ptr = DPS2_GET_PRM_BUF_PTR();/* .Hp;取参数区的buf指针 */
param_data_len = DPS2_GET_PRM_LEN();/*DPS2_GET_PRM_LEN()即spc3.r_len_prm_buf;.Hp9*/
/* 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!例子;PDF78;DPS2_SET_PRM_DATA_NOT_OK()即spc3.user_prm_data_nok;0FH*/
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();/* DPS2_SET_PRM_DATA_OK()即spc3.user_prm_data_ok */
}
}
else
prm_result = DPS2_SET_PRM_DATA_OK();/*见上行 */
} while(prm_result == DPS2_PRM_CONFLICT);/*#define DPS2_PRM_CONFLICT 0x01*/
store_mintsdr = *(prm_ptr+3);/* store the mintsdr for restart after;store_mintsdr全局变量 */
/* baudrate search */
}
if(DPS2_GET_IND_NEW_CFG_DATA()) /* 新的组态数据;PDF75 */
{ /*=== 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();/* DPS2_GET_CFG_LEN()即spc3.r_len_cfg_buf */
/* $$In this example the only possible configurations are 0x15 and 0x25
(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;期望组态和实际组态数据相等;0x15*/
else
{
if (((cfg_ptr[0] == 0x51) && (cfg_ptr[1]) ==0x61)
|| ((cfg_ptr[0] == 0x53) && (cfg_ptr[1]) ==0x63))
{
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);
/*根据新的组态数据计算I/O数据长度;见.Cp5 */
if (user_io_data_len_ptr != (DPS2_IO_DATA_LEN *)0)
{
DPS2_SET_IO_DATA_LEN(user_io_data_len_ptr);
/*相对与初始化设定,检查lens,如果正确,SPC3的指针和lens将装入;.Cp11 */
}
else
result = DPS_CFG_FAULT;
}
}
switch (result)
{
case DPS_CFG_OK: cfg_result = DPS2_SET_CFG_DATA_OK();/* 见.Cp12;Hp8 */
break;
case DPS_CFG_FAULT: cfg_result = DPS2_SET_CFG_DATA_NOT_OK();/* 见.Cp12 */
break;
case DPS_CFG_UPDATE: cfg_result = DPS2_SET_CFG_DATA_UPDATE();/*见.Cp12 */
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());/* 函数.I;两参数见.Hp9*/
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;.Hp8 */
}
if(SPC3_GET_IND_USER_TIMER_CLOCK())
{ /*==== Timer tick received;定时器;.Hp8 ====*/
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)) /*.Hp10;PDF22*/
SPC3_SET_MINTSDR(store_mintsdr);/* .Hp8 */
SPC3_CON_IND_BAUDRATE_DETECT();/* .Hp8 */
}
SPC3_SET_EOI(); /* .Hp8 */
} /* 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;/*定义结构体指针;结构体见.Hp5 */
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;DPS2_FREE_SSA_BUF()即_dps2_x = spc3.ssa_buffer_free_cmd;14H*/
}
#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;看门狗跑飞,复位DP状态机*/
user_wd_state = SPC3_GET_WD_STATE();/* .Hp10 */
/*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);/* .Hp9 */
rueck = DPS2_SET_DIAG_STATE(0x00);/* .Hp9;诊断值为00H */
DPS2_DIAG_UPDATE();/* 见.Cp14 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 + -