?? dps2spc3.c
字號:
#define RBL_PRM 0
#define RBL_CFG 1
#define RBL_SSA 2
enum SPC3_INIT_RET dps2_buf_init( DPS2_BUFINIT
*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 *spc_uptr; /* helppointer, 'cos of C166 compiler */
//volatile UBYTE *b_ptr; // *b_ptr
enum SPC3_INIT_RET ret = SPC3_INIT_OK;
//b_ptr = &spc3.user[0];
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 = &spc3.user[0]; // start of memory
dps2_base_ptr = (UBYTE *)&spc3.user;
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.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_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;
}
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ g e t _ f r e e _ m e m ( ) |
+------------------------------------------------------------------------+
| Description: |
| This function returns a pointer to the first free byte above the |
| DPS2-buffers. The count of free bytes is written to the pointer. |
+------------------------------------------------------------------------+
| Parameters: |
| -buf_len: pointer to len-variable |
| |
| Returncode: |
| -Pointer to first free byte |
+------------------------------------------------------------------------+
*/
/*
UBYTE * dps2_get_free_mem(WORD *buf_len)
{
if(dps2_buf_len)
{
//pointer to first free byte
*buf_len = sizeof(SPC3) - (dps2_base_ptr - (UBYTE *)&spc3
) - dps2_buf_len;
return dps2_base_ptr + dps2_buf_len;
}
else
{
// not correctly initialized: Error
*buf_len = 0;
return SPC3_NIL;
}
}
*/
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ s e t _ i o _ d a t a _ l e n ( ) |
+------------------------------------------------------------------------+
| Description: |
| The lens are checked against the initialization-lens. If they are |
| correct, the pointers and lens in the SPC3 are armed. |
+------------------------------------------------------------------------+
| Parameters: |
| -len_ptr: pointer to len-structure |
| |
| Returncode: |
| TRUE: ok |
| FALSE: len-mismatch |
+------------------------------------------------------------------------+
*/
UBYTE dps2_set_io_data_len(DPS2_IO_DATA_LEN *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;
}
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ c f g _ d a t a _ o k ( ) |
+------------------------------------------------------------------------+
| Description: |
| New config-data is marked as ok. |
+------------------------------------------------------------------------+
| Parameters: - |
| |
| Returncode: |
| UBYTE: DPS2_CFG_FINISHED: ok |
| DPS2_CFG_CONFLICT: data overridden while check |
+------------------------------------------------------------------------+
*/
UBYTE dps2_cfg_data_ok(void)
{
spc3.x1.w.mode_reg1_r = EN_CHG_CFG_BUFFER;
return spc3.user_cfg_data_ok;
}
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ c f g _ d a t a _ u p d a t e ( ) |
+------------------------------------------------------------------------+
| Description: |
| see dps2_cfg_data_ok(), additional there are new cfg-data. |
+------------------------------------------------------------------------+
| Parameters: - |
| |
| Returncode: see dps2_cfg_data_ok() |
+------------------------------------------------------------------------+
*/
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;
}
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ c f g _ d a t a _ n o t _ o k ( ) |
+------------------------------------------------------------------------+
| Description: |
| See dps2_cfg_data_ok(), but config-data is not correct. |
+------------------------------------------------------------------------+
| Parameters: - |
| |
| Returncode: see dps2_cfg_data_ok() |
+------------------------------------------------------------------------+
*/
UBYTE dps2_cfg_data_not_ok(void)
{
spc3.x1.w.mode_reg1_r = EN_CHG_CFG_BUFFER;
return spc3.user_cfg_data_nok;
}
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ o u t p u t _ u p d a t e _ s t a t e ( ) |
+------------------------------------------------------------------------+
| Description: |
| This function causes the output-update. The state is returned. |
+------------------------------------------------------------------------+
| Parameters: |
| -state_ptr: pointer to state-value |
| |
| Returncode: |
| void*: pointer to output-buffer |
+------------------------------------------------------------------------+
*/
/*
void * dps2_output_update_state(UBYTE *state_ptr
)
{
UBYTE temp;
temp = spc3.x1.r.next_dout_buf_cmd;
*state_ptr = temp & (NEW_DOUT_BUF | DOUT_BUF_CLEARED);
return (void *)
((((SPC3_ADTYP)(spc3.r_dout_buf_ptr[(temp & 0x03)-1]))<<3)\
+ (SPC3_ADTYP)&spc3);
}
*/
/*
+------------------------------------------------------------------------+
| Function: d p s 2 _ d i a g _ u p d a t e ( ) |
+------------------------------------------------------------------------+
| Description: |
| This function causes the diagnostic-update in the SPC3. |
+------------------------------------------------------------------------+
| Parameter: |
| |
| Returncode: |
| -pointer to new diagnostic-buffer, if available; else 0 |
+------------------------------------------------------------------------+
*/
void * dps2_diag_update(void)
{
UBYTE temp;
temp = spc3.new_diag_buffer_cmd & 0x03;
switch(temp)
{
case 1: /* buffer with Index 0 */
{
return (void *)((SPC3_ADTYP)(((UWORD)
spc3.r_diag_buf_ptr[0])<<3) + (SPC3_ADTYP)&spc3);
}
case 2: /* buffer with Index 1 */
{
return (void *)((SPC3_ADTYP)(((UWORD)
spc3.r_diag_buf_ptr[1])<<3) + (SPC3_ADTYP)&spc3);
}
default:
{
/* no buffer */
return SPC3_NIL;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -