📄 dps2spc3.c
字号:
/*
+------------------------------------------------------------------------+
| Project: D P S 2 w i t h S P C 3 |
| |
| File: DPS2SPC3.C |
| Date: 24-Mar-1997 |
| Version: V 1.30 |
| Initial Editor: Thomas Lang |
+------------------------------------------------------------------------+
| Description: |
| This File contains the functions for DPS2 with 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: |
| V1.0,LT, first official version |
| V1.1,LT, error in calculation of the FDL-SAP-List-Pointer fixed |
| (dps2_buf_len was not divided by) |
| V1.3,MM,12-Feb-1997, I/O-len calculation corrected |
| V1.3,MM,24-Mar-1997, translation |
| |
+------------------------------------------------------------------------+
| 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 |
| |
+------------------------------------------------------------------------+
*/
/*~
includes and declarations
~*/
/* formal declaratios for spc3dps2.h */
#define SPC3_DPS2 1
/*#define SPC3_INTEL_MODE 1*/
#define SPC3_DATA_XDATA
#define SPC3_FAR
#include "spc3dps2.h"
/*~
literals and macros
~*/
/*
+------------------------------------------------------------------------+
| L i t e r a l s |
+------------------------------------------------------------------------+
*/
/*-- cout of buffers assigned to AUX-buffer --*/
#define ASS_AUX_BUF 3
/*-- masks for config-data --*/
#define DPS_CFG_IS_BYTE_FORMAT (UBYTE)0x30
#define DPS_CFG_BF_LENGTH (UBYTE)0x0f
#define DPS_CFG_LENGTH_IS_WORD_FORMAT (UBYTE)0x40
#define DPS_CFG_BF_INP_EXIST (UBYTE)0x10
#define DPS_CFG_BF_OUTP_EXIST (UBYTE)0x20
#define DPS_CFG_SF_OUTP_EXIST (UBYTE)0x80
#define DPS_CFG_SF_INP_EXIST (UBYTE)0x40
#define DPS_CFG_SF_LENGTH (UBYTE)0x3f
/*
+------------------------------------------------------------------------+
| M a c r o s |
+------------------------------------------------------------------------+
*/
/*-- start address of user-area in the SPC3 in SPC3-format(8字节一段)-*/
#define SPC3_BUF_START ((UBYTE)(((UWORD)(dps2_base_ptr -\
(UBYTE SPC3_PTR_ATTR*)&spc3)) >> 3))
/*~
Variables
~*/
/*
+------------------------------------------------------------------------+
| g l o b a l V a r i a b l e s |
+------------------------------------------------------------------------+
*/
#ifdef _C166
#pragma global
#endif
UBYTE _dps2_x; /* dummy-byte */
#ifdef _C166
#pragma public
#endif
/*
+------------------------------------------------------------------------+
| "M o d u l" - g l o b a l V a r i a b l e s |
+------------------------------------------------------------------------+
*/
static DPS2_BUFINIT dps2_binit; /* storeage for initialization data */
static WORD dps2_buf_len = 0; /* used bufferspace */
static UBYTE SPC3_PTR_ATTR *dps2_base_ptr =\
(UBYTE SPC3_PTR_ATTR*)0; /* buffer base address */
static DPS2_IO_DATA_LEN io_data_len; /* Struct. f. IO-lens */
/*
+------------------------------------------------------------------------+
| e x t e r n a l D e c l a r a t i o n s |
+------------------------------------------------------------------------+
*/
#ifndef _IM182
extern SPC3 SPC3_PTR_ATTR spc3;
#endif
/*~
assign_aux_buf()
~主调dps_buf_init .Cp9*/
/*
+------------------------------------------------------------------------+
| Function: a s s i g n _ a u x _ b u f ( ) |
+------------------------------------------------------------------------------+
| Description: |
| Based on a list of bufferlens the best len of the aux-buffers is calculated.|
| The list's lens will be adjusted, the assignment-list will be calculated. |
| (基于各设定buf长度计算出aux-buf的最佳长度,表的LENS将做调整,并得出新的安排表) |
+------------------------------------------------------------------------------+
| Parameters: |
| -lens: Pointer to a list of buffer-lens ( real_buf_len数组的指针) |
| The calculated lens are inserted in this list. |
| -count: length of list (2 to ASS_AUX_BUF大小2或3) |
| -assign: pointer to an assignment-b yte(用于assignment的字节) |
| For each len there is a corresponding bit for the |
| assignment to AUX-buffer 1 or 2. 0 means AUX-buffer 1, |
| 1 means AUX-Buffer 2. Bit 0 ist for the first, Bit 7 |
| for the 8th length.(已定义UBYTE aux_ass,用于AUX-buffer-assignment)|
| -aux_len: pointer to a 2-byte-array for AUX-buffer-lens |
| The calculated lens of AUX-buffer 1 and 2 are stored here. |
| (储存AUX-buffer-lens的二字节数组的指针,数组分别存计算出的AUX-buf的长度)|
| Returnvalue: UWORD: total amount of used bytes (0 = error) |
+---------------------------------------------------------------------------+
*/
UWORD assign_aux_buf(UBYTE SPC3_DATA_ATTR *lens, UBYTE count, UBYTE
SPC3_DATA_ATTR *assign, WORD SPC3_DATA_ATTR *aux_len) /*$G*/
{
UBYTE pos[ASS_AUX_BUF]; /* storage for former position of lens */
UBYTE lensx[ASS_AUX_BUF]; /* working-array for calculated lens */
UBYTE step; /* counter for done step */
UBYTE lx; /* temp-var for lenarray-sorting(整理) */
UBYTE px; /* temp-var dor position-sorting */
UWORD min_len = 0xffff; /* calculated min-len */
UBYTE min_step = 0; /* step at reached min-len */
BYTE i,j;
if((count < 2) || (count > ASS_AUX_BUF))
{
return 0;/* 返回0即出错*/
}
/* init position-array ;初始化position-array */
for(i = 0; i < count; i++)
{
pos[i] = i;
}
/* init working-array ;初始化working-array */
for(i = 0; i < count; i++)
{
lensx[i] = lens[i];/*lens是real_buf_len数组的指针*/
}
/* round up(聚拢) lens to SPC3-lens (8-byte-granularity) */
for(i = 0; i < count; i++)
{
lensx[i] = (lensx[i] + 7) & 0xf8;/*相当于四舍五入?lens长度取8的倍数*/
}
/* sorting of lens: gratest len to index 0;整理lens:最大len标0*/
for(i = 0; i < count-1; i++)/*此循环用于lensx数组按从大到小排序,相应POS序号数组也排序*/
{
for(j = i+1; j < count; j++)
{
if(lensx[i] < lensx[j])
{
/* greater len found */
lx = lensx[i]; /* xchg lens;交换lensx[i]和lensx[j] */
lensx[i] = lensx[j];
lensx[j] = lx;
px = pos[i]; /* xchg position;交换位置*/
pos[i] = pos[j];
pos[j] = px;
}
}
}
/* remove NULL-lens of list;去除lensx数组为0的元素, */
for(i = count-1; i >= 0; i--)
{
if(lensx[i] == 0)
{
count--;
}
}
if(count == 0)
{
min_len = 0; /* error: no lens specified */
}
/* stepwise assignment to the AUX-buffers;用试探法计算出min_step和min_len */
for(step = 0; step < count; step++)
{
/* determine total len for AUX-buffer 1 */
aux_len[0] = 0;
for(i = step; i < count; i++)
{
if(aux_len[0] < lensx[i])
{
aux_len[0] = lensx[i];
}
}
aux_len[0] = aux_len[0]*(count - step + 1);
/* determine total len for AUX-buffer 2;关于AUX-buf见PDF29*/
aux_len[1] = 0;
for(i = 0; i < step; i++)
{
if(aux_len[1] < lensx[i])
{
aux_len[1] = lensx[i];
}
}
aux_len[1] = aux_len[1] * (step + 1);
if((aux_len[0] + aux_len[1]) < min_len)
{
/* neue Minimal-Laenge gefunden */
min_len = aux_len[0] + aux_len[1];
min_step = step;
}
}
/*calculation of len for AUX-buffer 1;计算AUX-buffer 1长度 *
aux_len[0] = 0;
for(i = min_step; i < count; i++)
{
if(aux_len[0] < lensx[i])
{
aux_len[0] = lensx[i];
}
}
/* setup lens for AUX-buffer 1 */
for(i = min_step; i < count; i++)
{
lens[pos[i]] = aux_len[0];
}
/* calculation of len for AUX-buffer 2;计算AUX-buffer 2长度*/
aux_len[1] = 0;
for(i = 0; i < min_step; i++)
{
if(aux_len[1] < lensx[i])
{
aux_len[1] = lensx[i];
}
}
/* setup lens for AUX-buffer 2 */
/* setup assignment-list */
*assign = 0; /* $initial all buffers assigned to AUX-buffer 1 */
for(i = 0; i < min_step; i++)
{
lens[pos[i]] = aux_len[1];
*assign |= 0x01 << pos[i];/*左移pos[i];即与AUX-buffer 2相关的标上1*/
}
return min_len;/*返回总长度值*/
}
/* Ende assign_aux_buf */
#ifdef _C166
#pragma global
#endif
/*~
dps2_calculate_inp_outp_len()
主调user_dps_reset 见.U*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -