📄 dps2spc3.c
字号:
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()
~*/
/*------------------------------ 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 real_buf_len[ASS_AUX_BUF];
WORD aux_buf_len[2]; /* calculated lens of AUX-buffers */
UBYTE 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;
dps2_buf_len = 0;
if (SPC3_GET_OFF_PASS())
{
return SPC3_INITF_NOFF; /*==== END: SPC3 is not Offline ====*/
}
dps2_binit = *dps2_bptr; /* store init-data */
dps2_base_ptr = b_ptr; /* start of memory */
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)
{
DPS2_SET_ADD_CHG_DISABLE()
}
else
{
/* SSA-buffer is used */
if((dps2_binit.ssa_buf_len < 4) || (dps2_binit.ssa_buf_len > 244))
{
ret = DPS2_INITF_SSA_LEN;
}
}
if(ret != SPC3_INIT_OK)
{
/* error occured */
dps2_buf_len = 0; /* no memory used */
return ret; /*===== T H E E N D =====*/
}
/* 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[RBL_CFG]; /* wg. Read-Config */
/* amount for IO-data, diagnosticbuffer and spec.Prm.buffer */
r_din_dout_buf_len = (dps2_binit.din_dout_buf_len + 7) & 0xfff8;
dps2_buf_len += ((dps2_binit.diag_buf_len + 7) & 0xf8) * 2;
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;
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.r_aux_buf_sel = aux_ass; /* assign AUX-buffers */
spc3.r_diag_buf_ptr[0] = SPC3_BUF_START + ((r_din_dout_buf_len * 3)>>3);
spc3.r_diag_buf_ptr[1] = spc3.r_diag_buf_ptr[0] + (((
dps2_binit.diag_buf_len + 7) & 0xf8)>>3);
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);
spc3.r_aux_buf_ptr[1] = spc3.r_aux_buf_ptr[0] + (aux_buf_len[0]>>3);
if(real_buf_len[RBL_SSA] == 0)
{
/* SSA not supported */
spc3.r_ssa_buf_ptr = 0;
}
else
{
/* SSA supported */
spc3.r_ssa_buf_ptr = spc3.r_aux_buf_ptr[1] + (aux_buf_len[1]>>3);
}
/* set buffer-lens */
spc3.r_len_diag_buf[0] = spc3.r_len_diag_buf[1] = 6;
spc3.r_len_cfg_buf = dps2_binit.cfg_buf_len;
spc3.r_len_prm_buf = dps2_binit.prm_buf_len;
spc3.r_len_cntrl_buf[0] = aux_buf_len[0];
spc3.r_len_cntrl_buf[1] = aux_buf_len[1];
spc3.r_len_ssa_buf = dps2_binit.ssa_buf_len;
spc3.r_len_din_buf = spc3.r_len_dout_buf = 0;
/* init buffers */
spc_uptr = (UBYTE SPC3_PTR_ATTR*)&spc3.user;
for(r_din_dout_buf_len = 0; r_din_dout_buf_len < dps2_buf_len;r_din_dout_buf_len++)
{
*(spc_uptr + r_din_dout_buf_len) = 0;
}
if(fdl_init)
{
/* no buffers for FDL */
spc3.r_fdl_sap_list_ptr = SPC3_BUF_START + (dps2_buf_len>>3);
(*((UBYTE SPC3_PTR_ATTR*)((SPC3_ADTYP)(((UWORD)(spc3.r_fdl_sap_list_ptr
))<<3) + (SPC3_ADTYP)&spc3)) ) = 0xff;
dps2_buf_len += 8; /* 8 Byte durch leere FDL-Liste verbraucht */
/* DDB not supported */
spc3.r_len_ddbout_buf = 0;
spc3.r_ddbout_buf_ptr = 0;
spc3.r_len_ddb_prm_buf = 0;
spc3.r_ddb_prm_buf_ptr = 0;
}
return ret;
}
/* Ende dps2_buf_init() */
/*~
dps2_get_free_mem()
~*/
UBYTE SPC3_PTR_ATTR* dps2_get_free_mem(WORD SPC3_DATA_ATTR *buf_len)
{
if(dps2_buf_len)
{
/* pointer to first free byte */
*buf_len = sizeof(SPC3) - (dps2_base_ptr - (UBYTE SPC3_PTR_ATTR*)&spc3
) - dps2_buf_len;
return dps2_base_ptr + dps2_buf_len;
}
else
{
/* not correctly initialized: Error */
*buf_len = 0;
return SPC3_NIL;
}
}
/* Ende dps2_free_mem() */
/*~
dps2_set_io_data_len()
~*/
UBYTE dps2_set_io_data_len(DPS2_IO_DATA_LEN SPC3_DATA_ATTR *len_ptr)
{
UBYTE ri_len, ro_len; /* real lens */
UBYTE ri_off; /* input-buffer-offset */
UBYTE i;
if(len_ptr->outp_data_len > 244)
{
return FALSE;
}
if(len_ptr->inp_data_len > 244)
{
return FALSE;
}
if((UWORD)len_ptr->inp_data_len + (UWORD)len_ptr->outp_data_len >
dps2_binit.din_dout_buf_len)
{
return FALSE;
}
/*-- lens correkt, arm buffers --*/
spc3.r_len_dout_buf = len_ptr->outp_data_len;
spc3.r_len_din_buf = len_ptr->inp_data_len;
ro_len = ((len_ptr->outp_data_len) + 7) >> 3;
ri_len = ((len_ptr->inp_data_len) + 7) >> 3;
for(i = 0; i < sizeof(spc3.r_dout_buf_ptr); i++)
{
spc3.r_dout_buf_ptr[i] = SPC3_BUF_START + ro_len * i;
}
ri_off = ro_len * sizeof(spc3.r_dout_buf_ptr);
for(i = 0; i < sizeof(spc3.r_din_buf_ptr); i++)
{
spc3.r_din_buf_ptr[i] = SPC3_BUF_START + ri_off + ri_len * i;
}
return TRUE;
}
/* Ende dps2_set_io_data_len */
/*~
dps2_cfg_data_ok()
~*/
UBYTE dps2_cfg_data_ok(void)
{
spc3.x1.w.mode_reg1_r = EN_CHG_CFG_BUFFER;
return spc3.user_cfg_data_ok;
}
/* Ende dps2_cfg_data_ok() */
/*~
dps2_cfg_data_update()
~*/
UBYTE dps2_cfg_data_update(void)
{
spc3.x1.w.mode_reg1_s = EN_CHG_CFG_BUFFER;
spc3.r_len_read_cfg_buf = spc3.r_len_cfg_buf;
return spc3.user_cfg_data_ok;
}
/* Ende dps2_cfg_data_update() */
/*~
dps2_cfg_data_not_ok()
~*/
UBYTE dps2_cfg_data_not_ok(void)
{
spc3.x1.w.mode_reg1_r = EN_CHG_CFG_BUFFER;
return spc3.user_cfg_data_nok;
}
/* Ende dps2_cfg_data_not_ok() */
/*~
dps2_output_update_state()
~*/
void SPC3_PTR_ATTR* dps2_output_update_state(UBYTE SPC3_DATA_ATTR *state_ptr)
{
UBYTE temp;
temp = spc3.x1.r.next_dout_buf_cmd;
*state_ptr = temp & (NEW_DOUT_BUF | DOUT_BUF_CLEARED);
return (void SPC3_PTR_ATTR*)
((((SPC3_ADTYP)(spc3.r_dout_buf_ptr[(temp & 0x03)-1]))<<3)\
+ (SPC3_ADTYP)&spc3);
}
/* Ende dps2_output_update_state() */
/*~
dps2_diag_update()
~*/
void SPC3_PTR_ATTR* dps2_diag_update(void)
{
UBYTE temp;
temp = spc3.new_diag_buffer_cmd & 0x03;
switch(temp)
{
case 1: /* buffer with Index 0 */
{
return (void SPC3_PTR_ATTR*)((SPC3_ADTYP)(((UWORD)
spc3.r_diag_buf_ptr[0])<<3) + (SPC3_ADTYP)&spc3);
}
case 2: /* buffer with Index 1 */
{
return (void SPC3_PTR_ATTR*)((SPC3_ADTYP)(((UWORD)
spc3.r_diag_buf_ptr[1])<<3) + (SPC3_ADTYP)&spc3);
}
default:
{
/* no buffer */
return SPC3_NIL;
}
}
}
/* Ende dps2_diag_update() */
#ifdef _C166
#pragma public
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -