📄 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 "..\user\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 |
+------------------------------------------------------------------------+
*/
/*-- startaddress of user-area in the SPC3 in SPC3-format --*/
#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()
~*/
/*
+------------------------------------------------------------------------+
| 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. |
+------------------------------------------------------------------------+
| Parameters: |
| -lens: Pointer to a list of buffer-lens |
| The calculated lens are inserted in this list. |
| -count: length of list (2 to ASS_AUX_BUF) |
| -assign: pointer to an assignment-byte |
| 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. |
| -aux_len: pointer to a 2-byte-array for AUX-buffer-lens |
| The calculated lens of AUX-buffer 1 and 2 are stored here. |
| |
| 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)
{
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;
}
/* init position-array */
for(i = 0; i < count; i++)
{
pos[i] = i;
}
/* init working-array */
for(i = 0; i < count; i++)
{
lensx[i] = lens[i];
}
/* round up lens to SPC3-lens (8-byte-granularity) */
for(i = 0; i < count; i++)
{
lensx[i] = (lensx[i] + 7) & 0xf8;
}
/* sorting of lens: gratest len to index 0 */
for(i = 0; i < count-1; i++)
{
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[j] = lx;
px = pos[i]; /* xchg position */
pos[i] = pos[j];
pos[j] = px;
}
}
}
/* remove NULL-lens of list */
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 */
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_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_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_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 |= 0x1 << pos[i];
}
return min_len;
}
/* Ende assign_aux_buf */
#ifdef _C166
#pragma global
#endif
/*~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -