📄 dps2spc3.c
字号:
/*
+------------------------------------------------------------------------+
| Funktion: d p s 2 _ c a l c u l a t e _ i n p _ o u t p _ l e n $ |
+------------------------------------------------------------------------+
| Description: |
| This function calculates the Input/Outputdata-lens based on the |
| specified config-data and returns a pointer to the calculated lens. |
|(original from DPS).根据特定组态数据计算I/O数据长度,并返回算出的长度指针|
+------------------------------------------------------------------------+
| parameters: |
| -cfg_ptr: pointer to config-data 组态数据指针 |
| -cfg_len: config-data len 组态数据长度 |
| |
| return value: |
| -pointer to lens |
+------------------------------------------------------------------------+
*/
DPS2_IO_DATA_LEN SPC3_DATA_ATTR *dps2_calculate_inp_outp_len (UBYTE
SPC3_PTR_ATTR* cfg_ptr, UWORD cfg_len)/* 返回值类型.Hp5 */
{
UBYTE temp_inp_data_len;
UBYTE temp_outp_data_len;
UBYTE length;
UBYTE count;
UBYTE specific_data_length;
UBYTE result_ok;
result_ok = TRUE;
temp_inp_data_len = 0;
temp_outp_data_len = 0;
count=1 ; /* $ 添加 */
if ((cfg_len > 0) && (cfg_len <= dps2_binit.cfg_buf_len))
{
for ( ; (cfg_len > 0) && result_ok; cfg_len -= count)
{
count = 0;
if (*cfg_ptr & DPS_CFG_IS_BYTE_FORMAT)/* DPS_CFG_IS_BYTE_FORMAT即30H */
{
count++;
/* cfg_ptr points to ID-byte, CFG_BF means "CFG_IS_BYTE_FORMAT" */
length = (UBYTE)((*cfg_ptr & DPS_CFG_BF_LENGTH) + 1);/* DPS_…即0FH */
if (*cfg_ptr & DPS_CFG_LENGTH_IS_WORD_FORMAT)/*DPS_CFG…为40H*/
{
length *= 2;
}
if (*cfg_ptr & DPS_CFG_BF_OUTP_EXIST) /* DPS_CFG_BF_OUTP_EXIST为20H */
{
temp_outp_data_len = temp_outp_data_len + length;
}
if (*cfg_ptr & DPS_CFG_BF_INP_EXIST) /* DPS_CFG_BF_INP_EXIST为10H */
{
temp_inp_data_len = temp_inp_data_len + length;
}
cfg_ptr++;
}
else
{
/* cfg_ptr points to the headerbyte of special ID-format */
/* CFG_SF means "CFG_IS_SPECIAL_FORMAT" 特殊参数模式*/
if (*cfg_ptr & DPS_CFG_SF_OUTP_EXIST) /* DPS_CFG_SF_OUTP_EXIST为80H */
{
count++; /* next byte contains the length of outp_data */
length = (UBYTE)((*(cfg_ptr + count) & DPS_CFG_SF_LENGTH) +1);
/* DPS_CFG_SF_LENGTH为3fH */
if (*(cfg_ptr + count) & DPS_CFG_LENGTH_IS_WORD_FORMAT)
{ /* DPS_CFG_LENGTH_IS_WORD_FORMAT为40H */
temp_outp_data_len = temp_outp_data_len + (UBYTE)(2*length);
}
else
{
temp_outp_data_len = temp_outp_data_len + length;
}
}
if (*cfg_ptr & DPS_CFG_SF_INP_EXIST) /*DPS_CFG_SF_INP_EXIST为40H*/
{
count++; /* next byte contains the length of inp_data */
length = (UBYTE)((*(cfg_ptr + count) & DPS_CFG_SF_LENGTH) +1); /* DPS_CFG_SF_LENGTH为3fH */
if (*(cfg_ptr + count) & DPS_CFG_LENGTH_IS_WORD_FORMAT)
{ /* DPS_CFG_LENGTH_IS_WORD_FORMAT为40H */
temp_inp_data_len = temp_inp_data_len + (UBYTE)(2*length);
}
else
{
temp_inp_data_len = temp_inp_data_len + length;
}
}
specific_data_length = (UBYTE)(*cfg_ptr & DPS_CFG_BF_LENGTH);
/* DPS_CFG_BF_LENGTH为0fH */
if (specific_data_length != 15)
{
count = (UBYTE)(count + 1 + specific_data_length);
cfg_ptr = cfg_ptr + count;
}
else
{
result_ok = FALSE;
}
}
}
if ( (cfg_len != 0) ||
(
(((UWORD)temp_inp_data_len + 7) & 0xfff8 +
((UWORD)temp_outp_data_len + 7) & 0xfff8)
> dps2_binit.din_dout_buf_len) )
{
result_ok = FALSE;
}
}
else
{
result_ok = FALSE;
}
if (result_ok)
{
io_data_len.inp_data_len = temp_inp_data_len;
io_data_len.outp_data_len = temp_outp_data_len;
return (&io_data_len);
}
else
{
return ((DPS2_IO_DATA_LEN *) 0);
}
}
/*~
dps2_buf_init() 主调.Hp8 图Z3
~*/
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ b u f _ i n i t ( ) |
+------------------------------------------------------------------------+
| Description: |
| The specified lens are checked. If they are ok, the neccesarry |
| memory is calculated. If there is enough memory, the buffers are |
| armed.(检查设定参数,计算所需存储空间;如空间足够,存储buf定位设置完成) |
| In dps2_buf_len the amount of used Memory is stored. |
| (dps2_buf_len储存使用的总空间, ) |
| The buffers are armed at the begin of the user-area in the following |
| way: (各缓冲区的定位以下列方式为起始点) |
| Outputdata | total len of the |
| Inputdata | Input-/Output buffers * 3 (3个输入输出BUF) |
| Diagnostic buffer (2*) |
| Config-buffer |
| Read-Config-buffer |
| Parameterbuffer |
| Aux-buffer 0 |
| Aux-buffer 1 (if used) |
| Set-Slave-Address-buffer (if used) |
+------------------------------------------------------------------------+
| parameters: |
| -b_ptr: Pointer to start of buffer-area(SPC3的用户区) |
|-dps2_bptr: Pointer to initialisierungs-structure是DPS2_BUFINIT结构体的指针.Hp4|
| -fdl_init: TRUE, if FDL is used 见PDF20 |
| -spec_prm: TRUE, if spec param-buffer is used 是否用特殊参数 |
| |
| returncode: (值为枚举类型) |
| SPC3_INIT_OK: SPC3 initialized correctly |
| SPC3_INITF_LESS_MEM: not enough memory |
| SPC3_INITF_NOFF: SPC3 is not offline |
| DPS2_INITF_DIN_DOUT_LEN: allowed: 0 - 488 |
| DPS2_INITF_DIAG_LEN: - " - : 6 - 244 |
| DPS2_INITF_PRM_LEN: - " - : 7 - 244 |
| DPS2_INITF_CFG_LEN: - " - : 1 - 244 |
| DPS2_INITF_SSA_LEN: - " - : 0 bzw. 4 - 244 |
+------------------------------------------------------------------------+
*/
/*------------------------------ Literals ------------------------------*/
/* position of bits in AUX-buffer-assignment */
#define RBL_PRM 0
#define RBL_CFG 1
#define RBL_SSA 2
enum SPC3_INIT_RET dps2_buf_init(UBYTE SPC3_PTR_ATTR * b_ptr, DPS2_BUFINIT
SPC3_DATA_ATTR *dps2_bptr, UBYTE fdl_init, UBYTE spec_prm)
{
UBYTE SPC3_PTR_ATTR real_buf_len[ASS_AUX_BUF];/* 常数3 */
WORD SPC3_PTR_ATTR aux_buf_len[2]; /* calculated lens of AUX-buffers */
UBYTE SPC3_PTR_ATTR aux_ass; /* var. for AUX-buffer-assignment */
WORD r_din_dout_buf_len; /* var. for real IO-data-lens */
UBYTE SPC3_PTR_ATTR *spc_uptr; /* helppointer, 'cos of C166 compiler */
enum SPC3_INIT_RET ret = SPC3_INIT_OK;/*定义ret枚举类型,返回值*/
dps2_buf_len = 0;
if (SPC3_GET_OFF_PASS()) /*判断SPC3在线吗? .Hp10*/
{
return SPC3_INITF_NOFF; /*==== END: SPC3 is not Offline ====*/
}
dps2_binit = *dps2_bptr;/* store init-data; dps2_bptr为&dps2_buf;好像要去掉*$号 */
dps2_base_ptr = b_ptr; /* start of memory;SPC3的用户区始址 */
if(dps2_binit.din_dout_buf_len > 488)
{
ret = DPS2_INITF_DIN_DOUT_LEN;
}
if((dps2_binit.diag_buf_len < 6) || (dps2_binit.diag_buf_len > 244))
{
ret = DPS2_INITF_DIAG_LEN;
}
if((dps2_binit.prm_buf_len < 7) || (dps2_binit.prm_buf_len > 244))
{
ret = DPS2_INITF_PRM_LEN;
}
if((dps2_binit.cfg_buf_len < 1) || (dps2_binit.cfg_buf_len > 244))
{
ret = DPS2_INITF_PRM_LEN;
}
if(dps2_binit.ssa_buf_len == 0) /* set-slave-address-buffer长度*/
{
DPS2_SET_ADD_CHG_DISABLE()/*取消地址改变*/
}
else
{
/* SSA-buffer is used Set_Slave_Address见PDF31*/
if((dps2_binit.ssa_buf_len < 4) || (dps2_binit.ssa_buf_len > 244))
{
ret = DPS2_INITF_SSA_LEN;
}
}
if(ret!= SPC3_INIT_OK)/* buf_len设置正确吗?*/
{/*参数设置不合要求*/
/* error occured */
dps2_buf_len = 0; /* no memory used */
return ret; /*===== T H E E N D =====*/
} /* Bufferlens正确 --> 计算存储区总数 */
/* Bufferlens seem to be ok --> calculate total amount of memory */
if(spec_prm)/* 特殊参数已设? */
{
real_buf_len[RBL_PRM] = 0; /* Prm. via AUX */
}
else
{
real_buf_len[RBL_PRM] = dps2_binit.prm_buf_len;
}
real_buf_len[RBL_CFG] = dps2_binit.cfg_buf_len;
real_buf_len[RBL_SSA] = dps2_binit.ssa_buf_len;
dps2_buf_len = assign_aux_buf(real_buf_len, sizeof(real_buf_len),&aux_ass,aux_buf_len);
/* dps2_buf_len外部静态变量;real_buf_len三字节数组; aux_buf_len二字节数组;函数见.Cp3 (这时的dps2_buf_len只含aux_buf区的长度) */
/* 加Read-Config, din_dout_buf和spec_prm计算出dps2_buf_len */
dps2_buf_len += real_buf_len[RBL_CFG]; /* wg. Read-Config;配置BUF */
/* amount for IO-data, diagnosticbuffer and spec.Prm.buffer */
/*共计三个输入输出BUF,两个诊断,两个辅助,一个配置,一个参数BUF和一个地址设置BUF*/
r_din_dout_buf_len = (dps2_binit.din_dout_buf_len + 7) & 0xfff8;/*字变量;输入出 */
dps2_buf_len += ((dps2_binit.diag_buf_len + 7) & 0xf8) * 2;/* 两个诊断BUF */
if(spec_prm)
{
/* spec_prm-buffer is used */
real_buf_len[RBL_PRM] = (dps2_binit.prm_buf_len + 7) & 0xf8;
dps2_buf_len += real_buf_len[RBL_PRM];
spc3.r_len_spec_prm_buf = dps2_binit.prm_buf_len;
}
else
{
spc3.r_len_spec_prm_buf = 0;
}
dps2_buf_len += r_din_dout_buf_len * 3;/* 见函数Description */
if(dps2_buf_len > sizeof(spc3.user))
{
/* not enough memory; */
dps2_buf_len = 0;
dps2_base_ptr = 0;
return SPC3_INITF_LESS_MEM;
}
/* arm the pointers;写SPC3的各指针存储单元*/
spc3.r_aux_buf_sel = aux_ass; /* assign AUX-buffers;2AH */
spc3.r_diag_buf_ptr[0] = SPC3_BUF_START + ((r_din_dout_buf_len * 3)>>3);
/* 26H; SPC3_BUF_START是 (&spc3.user-&spc3) >> 3 ;$ */
spc3.r_diag_buf_ptr[1] = spc3.r_diag_buf_ptr[0] + (((
dps2_binit.diag_buf_len + 7) & 0xf8)>>3);
/* 已定义static DPS2_BUFINIT dps2_binit;一个关于各BUF长度的结构类型 */
spc3.r_cfg_buf_ptr = spc3.r_diag_buf_ptr[1] + (((dps2_binit.diag_buf_len +
7) & 0xf8)>>3);
spc3.r_read_cfg_buf_ptr = spc3.r_cfg_buf_ptr + (real_buf_len[RBL_CFG]>>3);
spc3.r_prm_buf_ptr = spc3.r_read_cfg_buf_ptr + (real_buf_len[RBL_CFG]>>3);
spc3.r_aux_buf_ptr[0] = spc3.r_prm_buf_ptr + (real_buf_len[RBL_PRM]>>3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -