📄 intspc3.c
字号:
#define SPC3_INTEL_MODE TRUE
#define SPC3_FAR
#define SPC3_DPS2
#define SPC3_DATA_XDATA
#include "spc3dps2.h"
/* special defines for the 80166 processor */
/* are set to nothing */
#define huge
#define global
#define public
/*----------------------------------------------------------------------*/
/* 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 [80];
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[];
extern UBYTE prm_data_map[256];
extern UBYTE glab_prm_flag;
extern UBYTE old_glab_prm_flag;
extern UBYTE glab_prm_f;
#ifndef _IM182
extern SPC3 SPC3_PTR_ATTR spc3;
#endif
void dps2_ind(void) interrupt 0
{
BYTE prm_temp_flag;
static prm_cont=0;
prm_temp_flag = 0x0;
//prm_cont = 0x0;
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_cont++;
prm_result = DPS2_PRM_FINISHED;
do
{ /* Check parameter until no conflict behavior */
prm_cont ++;
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)
{
prm_temp_flag = 0x0;
if ((( *(prm_ptr) != 0x88)||( *(prm_ptr+1) != 0x08)||( *(prm_ptr+2) != 0xF5)
||( *(prm_ptr+3) != 0x0B)||( *(prm_ptr+4) != 0x0A)||
( *(prm_ptr+5) != 0x0F))||(( *(prm_ptr+8) == 0xAA)
&& ( *(prm_ptr+9) == 0xAA)))
{
prm_result = DPS2_SET_PRM_DATA_NOT_OK(); // as example !!!
}
else
{
prm_result = DPS2_SET_PRM_DATA_OK();
for (ii= 0; ii<param_data_len; ii++) /* store in the interim buffer */
{
//prm_tst_buf[ii] = *(prm_ptr+ii+7); /* for the diagnostic */
/**************************************************/
if(prm_data_map[ii] != *(prm_ptr+ii+7))
{
prm_data_map[ii] = *(prm_ptr+ii+7);
prm_temp_flag = 0xa;
}
}
if(prm_temp_flag == 0xa)
{
glab_prm_flag ++;
prm_temp_flag = 0x0;
}
}
}
else
prm_result = DPS2_SET_PRM_DATA_OK();
} while(prm_result == DPS2_PRM_CONFLICT);//&&prm_cont<2);
store_mintsdr = *(prm_ptr+3); /* store the mintsdr for restart after */
prm_result = DPS2_SET_PRM_DATA_OK(); /* 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 <1)
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];
cfg_akt[2] = cfg_ptr[2];
cfg_akt[3] = cfg_ptr[3];
cfg_akt[4] = cfg_ptr[4];
cfg_akt[5] = cfg_ptr[5];
cfg_akt[6] = cfg_ptr[6];
cfg_akt[7] = cfg_ptr[7];
cfg_akt[8] = cfg_ptr[8];
cfg_akt[9] = cfg_ptr[9];
cfg_akt[10] = cfg_ptr[10];
cfg_akt[11] = cfg_ptr[11];
cfg_akt[12] = cfg_ptr[12];
cfg_akt[13] = cfg_ptr[13];
cfg_akt[14] = cfg_ptr[14];
cfg_akt[15] = cfg_ptr[15];
cfg_akt[16] = cfg_ptr[16];
cfg_akt[17] = cfg_ptr[17];
cfg_akt[18] = cfg_ptr[18];
cfg_akt[19] = cfg_ptr[19];
cfg_akt[20] = cfg_ptr[20]; */
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() */
#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
#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
#pragma global
void global_ctrl_command_function (void)
{
user_global_ctrl_command = DPS2_GET_GC_COMMAND();
}
#pragma public
#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 + -