📄 dps2spc3.lst
字号:
436 | The buffers are armed at the begin of the user-area in the following |
437 | way: (各缓冲区的定位以下列方式为起始点) |
438 | Outputdata | total len of the |
439 | Inputdata | Input-/Output buffers * 3 (3个输入输出BUF) |
440 | Diagnostic buffer (2*) |
441 | Config-buffer |
442 | Read-Config-buffer |
443 | Parameterbuffer |
444 | Aux-buffer 0 |
445 | Aux-buffer 1 (if used) |
446 | Set-Slave-Address-buffer (if used) |
447 +------------------------------------------------------------------------+
448 | parameters: |
449 | -b_ptr: Pointer to start of buffer-area(SPC3的用户区) |
450 |-dps2_bptr: Pointer to initialisierungs-structure是DPS2_BUFINIT结构体的指针.Hp4|
451 | -fdl_init: TRUE, if FDL is used 见PDF20 |
452 | -spec_prm: TRUE, if spec param-buffer is used 是否用特殊参数 |
453 | |
454 | returncode: (值为枚举类型) |
455 | SPC3_INIT_OK: SPC3 initialized correctly |
456 | SPC3_INITF_LESS_MEM: not enough memory |
457 | SPC3_INITF_NOFF: SPC3 is not offline |
458 | DPS2_INITF_DIN_DOUT_LEN: allowed: 0 - 488 |
459 | DPS2_INITF_DIAG_LEN: - " - : 6 - 244 |
460 | DPS2_INITF_PRM_LEN: - " - : 7 - 244 |
461 | DPS2_INITF_CFG_LEN: - " - : 1 - 244 |
462 | DPS2_INITF_SSA_LEN: - " - : 0 bzw. 4 - 244 |
463 +------------------------------------------------------------------------+
464 */
465 /*------------------------------ Literals ------------------------------*/
466 /* position of bits in AUX-buffer-assignment */
467 #define RBL_PRM 0
468 #define RBL_CFG 1
469 #define RBL_SSA 2
470
471 enum SPC3_INIT_RET dps2_buf_init(UBYTE SPC3_PTR_ATTR * b_ptr, DPS2_BUFINIT
472 SPC3_DATA_ATTR *dps2_bptr, UBYTE fdl_init, UBYTE spec_prm)
473 {
474 1 UBYTE SPC3_PTR_ATTR real_buf_len[ASS_AUX_BUF];/* 常数3 */
475 1 WORD SPC3_PTR_ATTR aux_buf_len[2]; /* calculated lens of AUX-buffers */
476 1 UBYTE SPC3_PTR_ATTR aux_ass; /* var. for AUX-buffer-assignment */
477 1 WORD r_din_dout_buf_len; /* var. for real IO-data-lens */
478 1 UBYTE SPC3_PTR_ATTR *spc_uptr; /* helppointer, 'cos of C166 compiler */
479 1 enum SPC3_INIT_RET ret = SPC3_INIT_OK;/*定义ret枚举类型,返回值*/
480 1
481 1 dps2_buf_len = 0;
482 1
483 1 if (SPC3_GET_OFF_PASS()) /*判断SPC3在线吗? .Hp10*/
484 1 {
485 2 return SPC3_INITF_NOFF; /*==== END: SPC3 is not Offline ====*/
486 2 }
487 1 dps2_binit = *dps2_bptr;/* store init-data; dps2_bptr为&dps2_buf;好像要去掉*$号 */
C51 COMPILER V7.02b DPS2SPC3 11/01/2004 20:51:04 PAGE 9
488 1 dps2_base_ptr = b_ptr; /* start of memory;SPC3的用户区始址 */
489 1
490 1 if(dps2_binit.din_dout_buf_len > 488)
491 1 {
492 2 ret = DPS2_INITF_DIN_DOUT_LEN;
493 2 }
494 1 if((dps2_binit.diag_buf_len < 6) || (dps2_binit.diag_buf_len > 244))
495 1 {
496 2 ret = DPS2_INITF_DIAG_LEN;
497 2 }
498 1 if((dps2_binit.prm_buf_len < 7) || (dps2_binit.prm_buf_len > 244))
499 1 {
500 2 ret = DPS2_INITF_PRM_LEN;
501 2 }
502 1 if((dps2_binit.cfg_buf_len < 1) || (dps2_binit.cfg_buf_len > 244))
503 1 {
504 2 ret = DPS2_INITF_PRM_LEN;
505 2 }
506 1 if(dps2_binit.ssa_buf_len == 0) /* set-slave-address-buffer长度*/
507 1 {
508 2 DPS2_SET_ADD_CHG_DISABLE()/*取消地址改变*/
509 2 }
510 1 else
511 1 {
512 2 /* SSA-buffer is used Set_Slave_Address见PDF31*/
513 2 if((dps2_binit.ssa_buf_len < 4) || (dps2_binit.ssa_buf_len > 244))
514 2 {
515 3 ret = DPS2_INITF_SSA_LEN;
516 3 }
517 2 }
518 1 if(ret!= SPC3_INIT_OK)/* buf_len设置正确吗?*/
519 1 {/*参数设置不合要求*/
520 2 /* error occured */
521 2 dps2_buf_len = 0; /* no memory used */
522 2 return ret; /*===== T H E E N D =====*/
523 2 } /* Bufferlens正确 --> 计算存储区总数 */
524 1 /* Bufferlens seem to be ok --> calculate total amount of memory */
525 1 if(spec_prm)/* 特殊参数已设? */
526 1 {
527 2 real_buf_len[RBL_PRM] = 0; /* Prm. via AUX */
528 2 }
529 1 else
530 1 {
531 2 real_buf_len[RBL_PRM] = dps2_binit.prm_buf_len;
532 2 }
533 1 real_buf_len[RBL_CFG] = dps2_binit.cfg_buf_len;
534 1 real_buf_len[RBL_SSA] = dps2_binit.ssa_buf_len;
535 1 dps2_buf_len = assign_aux_buf(real_buf_len, sizeof(real_buf_len),&aux_ass,aux_buf_len);
536 1
537 1 /* dps2_buf_len外部静态变量;real_buf_len三字节数组; aux_buf_len二字节数组;函数见.Cp3 (这时的dps2_buf_len只
-含aux_buf区的长度) */
538 1 /* 加Read-Config, din_dout_buf和spec_prm计算出dps2_buf_len */
539 1 dps2_buf_len += real_buf_len[RBL_CFG]; /* wg. Read-Config;配置BUF */
540 1 /* amount for IO-data, diagnosticbuffer and spec.Prm.buffer */
541 1 /*共计三个输入输出BUF,两个诊断,两个辅助,一个配置,一个参数BUF和一个地址设置BUF*/
542 1 r_din_dout_buf_len = (dps2_binit.din_dout_buf_len + 7) & 0xfff8;/*字变量;输入出 */
543 1 dps2_buf_len += ((dps2_binit.diag_buf_len + 7) & 0xf8) * 2;/* 两个诊断BUF */
544 1
545 1 if(spec_prm)
546 1 {
547 2 /* spec_prm-buffer is used */
548 2 real_buf_len[RBL_PRM] = (dps2_binit.prm_buf_len + 7) & 0xf8;
C51 COMPILER V7.02b DPS2SPC3 11/01/2004 20:51:04 PAGE 10
549 2 dps2_buf_len += real_buf_len[RBL_PRM];
550 2 spc3.r_len_spec_prm_buf = dps2_binit.prm_buf_len;
551 2 }
552 1 else
553 1 {
554 2 spc3.r_len_spec_prm_buf = 0;
555 2 }
556 1 dps2_buf_len += r_din_dout_buf_len * 3;/* 见函数Description */
557 1
558 1 if(dps2_buf_len > sizeof(spc3.user))
559 1 {
560 2 /* not enough memory; */
561 2 dps2_buf_len = 0;
562 2 dps2_base_ptr = 0;
563 2 return SPC3_INITF_LESS_MEM;
564 2 }
565 1 /* arm the pointers;写SPC3的各指针存储单元*/
566 1 spc3.r_aux_buf_sel = aux_ass; /* assign AUX-buffers;2AH */
567 1 spc3.r_diag_buf_ptr[0] = SPC3_BUF_START + ((r_din_dout_buf_len * 3)>>3);
568 1 /* 26H; SPC3_BUF_START是 (&spc3.user-&spc3) >> 3 ;$ */
569 1 spc3.r_diag_buf_ptr[1] = spc3.r_diag_buf_ptr[0] + (((
570 1 dps2_binit.diag_buf_len + 7) & 0xf8)>>3);
571 1 /* 已定义static DPS2_BUFINIT dps2_binit;一个关于各BUF长度的结构类型 */
572 1 spc3.r_cfg_buf_ptr = spc3.r_diag_buf_ptr[1] + (((dps2_binit.diag_buf_len +
573 1 7) & 0xf8)>>3);
574 1 spc3.r_read_cfg_buf_ptr = spc3.r_cfg_buf_ptr + (real_buf_len[RBL_CFG]>>3);
575 1 spc3.r_prm_buf_ptr = spc3.r_read_cfg_buf_ptr + (real_buf_len[RBL_CFG]>>3);
576 1 spc3.r_aux_buf_ptr[0] = spc3.r_prm_buf_ptr + (real_buf_len[RBL_PRM]>>3);
577 1 spc3.r_aux_buf_ptr[1] = spc3.r_aux_buf_ptr[0] + (aux_buf_len[0]>>3);
578 1 /* 用户区各缓存区的排布顺序见PDF14 */
579 1 if(real_buf_len[RBL_SSA] == 0) /* 判断是否加地址设置BUF */
580 1 {
581 2 /* SSA not supported; 写SPC3的各指针 */
582 2 spc3.r_ssa_buf_ptr = 0;
583 2 }
584 1 else
585 1 {
586 2 /* SSA supported */
587 2 spc3.r_ssa_buf_ptr = spc3.r_aux_buf_ptr[1] + (aux_buf_len[1]>>3);
588 2 }
589 1
590 1 /* set buffer-lens;写SPC3的各buf_lens */
591 1 spc3.r_len_diag_buf[0] = spc3.r_len_diag_buf[1] = 6;
592 1 spc3.r_len_cfg_buf = dps2_binit.cfg_buf_len;
593 1 spc3.r_len_prm_buf = dps2_binit.prm_buf_len;
594 1 spc3.r_len_cntrl_buf[0] = aux_buf_len[0];
595 1 spc3.r_len_cntrl_buf[1] = aux_buf_len[1];
596 1 spc3.r_len_ssa_buf = dps2_binit.ssa_buf_len;
597 1 spc3.r_len_din_buf = spc3.r_len_dout_buf = 0;
598 1 /* init buffers ; */
599 1 spc_uptr = (UBYTE SPC3_PTR_ATTR*)&spc3.user;
600 1
601 1 for(r_din_dout_buf_len = 0; r_din_dout_buf_len < dps2_buf_len;r_din_dout_buf_len++)
602 1 { /* 清零SPC3的用户区 */
603 2 *(spc_uptr + r_din_dout_buf_len) = 0;/*$ spc_uptr为SPC3的用户区 */
604 2 }
605 1 if(fdl_init)
606 1 {
607 2 /* no buffers for FDL */
608 2 spc3.r_fdl_sap_list_ptr = SPC3_BUF_START + (dps2_buf_len>>3);
609 2 (*((UBYTE SPC3_PTR_ATTR*)((SPC3_ADTYP)(((UWORD)(spc3.r_fdl_sap_list_ptr
610 2 ))<<3) + (SPC3_ADTYP)&spc3)) ) = 0xff;
C51 COMPILER V7.02b DPS2SPC3 11/01/2004 20:51:04 PAGE 11
611 2 dps2_buf_len += 8; /* 8 Byte durch leere FDL-Liste verbraucht */
612 2 /* DDB not supported */
613 2 spc3.r_len_ddbout_buf = 0;
614 2 spc3.r_ddbout_buf_ptr = 0;
615 2 spc3.r_len_ddb_prm_buf = 0;
616 2 spc3.r_ddb_prm_buf_ptr = 0;
617 2 }
618 1 return ret;
619 1 }
620 /* Ende dps2_buf_init() Z3 */
621
622 /*~
623 dps2_get_free_mem()
624 ~*/
625 /*
626 +------------------------------------------------------------------------+
627 | Function: d p s 2 _ g e t _ f r e e _ m e m ( ) |
628 +------------------------------------------------------------------------+
629 | Description: |
630 | This function returns a pointer to the first free byte above the |
631 | DPS2-buffers. The count of free bytes is written to the pointer. |
632 +------------------------------------------------------------------------+
633 | Parameters: |
634 | -buf_len: pointer to len-variable (长度变量的指针) |
635 | |
636 | Returncode: |
637 | -Pointer to first free byte |
638 +------------------------------------------------------------------------+
639 */
640 UBYTE SPC3_PTR_ATTR* dps2_get_free_mem(WORD SPC3_DATA_ATTR *buf_len)
641 {
642 1 if(dps2_buf_len)
643 1 {
644 2 /* pointer to first free byte */
645 2 *buf_len = sizeof(SPC3) - (dps2_base_ptr - (UBYTE SPC3_PTR_ATTR*)&spc3
646 2 ) - dps2_buf_len;
647 2 return dps2_base_ptr + dps2_buf_len;
648 2 }
649 1 else
650 1 {
651 2 /* not correctly initialized: Error */
652 2 *buf_len = 0;
653 2 return SPC3_NIL;
654 2 }
655 1 }
656 /* Ende dps2_free_mem() */
657
658 /*~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -