📄 dps2spc3.lst
字号:
427 | memory is calculated. If there is enough memory, the buffers are |
428 | armed. |
429 | In dps2_buf_len the amount of used Memory is stored. |
430 | The buffers are armed at the begin of the user-area in the following |
431 | way: |
432 | Outputdata | total len of the |
433 | Inputdata | Input-/Outputbuffers * 3 |
434 | Diagnosticbuffer (2*) |
435 | Config-buffer |
436 | Read-Config-buffer |
437 | Parameterbuffer |
438 | Aux-buffer 0 |
439 | Aux-buffer 1 (if used) |
440 | Set-Slave-Address-buffer (if used) |
441 +------------------------------------------------------------------------+
442 | parameters: |
443 | -b_ptr: Pointer to start of buffer-area |
444 | -dps2_bptr: Pointer to initialisierungs-structure |
445 | -fdl_init: TRUE, if FDL is used |
446 | -spec_prm: TRUE, if spec param-buffer is used |
447 | |
448 | returncode: |
449 | SPC3_INIT_OK: SPC3 initialized correctly |
450 | SPC3_INITF_LESS_MEM: not enough memory |
451 | SPC3_INITF_NOFF: SPC3 is not offline |
452 | DPS2_INITF_DIN_DOUT_LEN: allowed: 0 - 488 |
453 | DPS2_INITF_DIAG_LEN: - " - : 6 - 244 |
454 | DPS2_INITF_PRM_LEN: - " - : 7 - 244 |
455 | DPS2_INITF_CFG_LEN: - " - : 1 - 244 |
456 | DPS2_INITF_SSA_LEN: - " - : 0 bzw. 4 - 244 |
457 +------------------------------------------------------------------------+
458 */
459 /*------------------------------ Literals ------------------------------*/
460 /* position of bits in AUX-buffer-assignment */
461 #define RBL_PRM 0
462 #define RBL_CFG 1
463 #define RBL_SSA 2
464
465 enum SPC3_INIT_RET dps2_buf_init(UBYTE SPC3_PTR_ATTR* b_ptr, DPS2_BUFINIT
466 SPC3_DATA_ATTR *dps2_bptr, UBYTE fdl_init, UBYTE spec_prm)
467 {
468 1 UBYTE real_buf_len[ASS_AUX_BUF];
469 1 WORD aux_buf_len[2]; /* calculated lens of AUX-buffers */
470 1 UBYTE aux_ass; /* var. for AUX-buffer-assignment */
471 1 WORD r_din_dout_buf_len; /* var. for real IO-data-lens */
472 1 UBYTE SPC3_PTR_ATTR *spc_uptr; /* helppointer, 'cos of C166 compiler */
473 1 enum SPC3_INIT_RET ret = SPC3_INIT_OK;
474 1
475 1 dps2_buf_len = 0;
476 1
477 1 if (SPC3_GET_OFF_PASS())
478 1 {
479 2 return SPC3_INITF_NOFF; /*==== END: SPC3 is not Offline ====*/
480 2 }
481 1 dps2_binit = *dps2_bptr; /* store init-data */
482 1 dps2_base_ptr = b_ptr; /* start of memory */
483 1
484 1 if(dps2_binit.din_dout_buf_len > 488)
485 1 {
486 2 ret = DPS2_INITF_DIN_DOUT_LEN;
487 2 }
488 1 if((dps2_binit.diag_buf_len < 6) || (dps2_binit.diag_buf_len > 244))
C51 COMPILER V7.50 DPS2SPC3 10/24/2007 09:35:19 PAGE 9
489 1 {
490 2 ret = DPS2_INITF_DIAG_LEN;
491 2 }
492 1 if((dps2_binit.prm_buf_len < 7) || (dps2_binit.prm_buf_len > 244))
493 1 {
494 2 ret = DPS2_INITF_PRM_LEN;
495 2 }
496 1 if((dps2_binit.cfg_buf_len < 1) || (dps2_binit.cfg_buf_len > 244))
497 1 {
498 2 ret = DPS2_INITF_PRM_LEN;
499 2 }
500 1 if(dps2_binit.ssa_buf_len == 0)
501 1 {
502 2 DPS2_SET_ADD_CHG_DISABLE()
503 2 }
504 1 else
505 1 {
506 2 /* SSA-buffer is used */
507 2 if((dps2_binit.ssa_buf_len < 4) || (dps2_binit.ssa_buf_len > 244))
508 2 {
509 3 ret = DPS2_INITF_SSA_LEN;
510 3 }
511 2 }
512 1 if(ret != SPC3_INIT_OK)
513 1 {
514 2 /* error occured */
515 2 dps2_buf_len = 0; /* no memory used */
516 2 return ret; /*===== T H E E N D =====*/
517 2 }
518 1 /* Bufferlens seem to be ok --> calculate total amount of memory */
519 1 if(spec_prm)
520 1 {
521 2 real_buf_len[RBL_PRM] = 0; /* Prm. via AUX */
522 2 }
523 1 else
524 1 {
525 2 real_buf_len[RBL_PRM] = dps2_binit.prm_buf_len;
526 2 }
527 1 real_buf_len[RBL_CFG] = dps2_binit.cfg_buf_len;
528 1 real_buf_len[RBL_SSA] = dps2_binit.ssa_buf_len;
529 1 dps2_buf_len = assign_aux_buf(real_buf_len, sizeof(real_buf_len), &aux_ass
530 1 , aux_buf_len);
531 1 dps2_buf_len += real_buf_len[RBL_CFG]; /* wg. Read-Config */
532 1 /* amount for IO-data, diagnosticbuffer and spec.Prm.buffer */
533 1 r_din_dout_buf_len = (dps2_binit.din_dout_buf_len + 7) & 0xfff8;
534 1 dps2_buf_len += ((dps2_binit.diag_buf_len + 7) & 0xf8) * 2;
535 1
536 1 if(spec_prm)
537 1 {
538 2 /* spec_prm-buffer is used */
539 2 real_buf_len[RBL_PRM] = (dps2_binit.prm_buf_len + 7) & 0xf8;
540 2 dps2_buf_len += real_buf_len[RBL_PRM];
541 2 spc3.r_len_spec_prm_buf = dps2_binit.prm_buf_len;
542 2 }
543 1 else
544 1 {
545 2 spc3.r_len_spec_prm_buf = 0;
546 2 }
547 1 dps2_buf_len += r_din_dout_buf_len * 3;
548 1
549 1 if(dps2_buf_len > sizeof(spc3.user))
550 1 {
C51 COMPILER V7.50 DPS2SPC3 10/24/2007 09:35:19 PAGE 10
551 2 /* not enough memory */
552 2 dps2_buf_len = 0;
553 2 dps2_base_ptr = 0;
554 2 return SPC3_INITF_LESS_MEM;
555 2 }
556 1 /* arm the pointers */
557 1 spc3.r_aux_buf_sel = aux_ass; /* assign AUX-buffers */
558 1 spc3.r_diag_buf_ptr[0] = SPC3_BUF_START + ((r_din_dout_buf_len * 3)>>3);
559 1 spc3.r_diag_buf_ptr[1] = spc3.r_diag_buf_ptr[0] + (((
560 1 dps2_binit.diag_buf_len + 7) & 0xf8)>>3);
561 1 spc3.r_cfg_buf_ptr = spc3.r_diag_buf_ptr[1] + (((dps2_binit.diag_buf_len +
562 1 7) & 0xf8)>>3);
563 1 spc3.r_read_cfg_buf_ptr = spc3.r_cfg_buf_ptr + (real_buf_len[RBL_CFG]>>3);
564 1 spc3.r_prm_buf_ptr = spc3.r_read_cfg_buf_ptr + (real_buf_len[RBL_CFG]>>3);
565 1 spc3.r_aux_buf_ptr[0] = spc3.r_prm_buf_ptr + (real_buf_len[RBL_PRM]>>3);
566 1 spc3.r_aux_buf_ptr[1] = spc3.r_aux_buf_ptr[0] + (aux_buf_len[0]>>3);
567 1
568 1 if(real_buf_len[RBL_SSA] == 0)
569 1 {
570 2 /* SSA not supported */
571 2 spc3.r_ssa_buf_ptr = 0;
572 2 }
573 1 else
574 1 {
575 2 /* SSA supported */
576 2 spc3.r_ssa_buf_ptr = spc3.r_aux_buf_ptr[1] + (aux_buf_len[1]>>3);
577 2 }
578 1
579 1 /* set buffer-lens */
580 1 spc3.r_len_diag_buf[0] = spc3.r_len_diag_buf[1] = 6;
581 1 spc3.r_len_cfg_buf = dps2_binit.cfg_buf_len;
582 1 spc3.r_len_prm_buf = dps2_binit.prm_buf_len;
583 1 spc3.r_len_cntrl_buf[0] = aux_buf_len[0];
584 1 spc3.r_len_cntrl_buf[1] = aux_buf_len[1];
585 1 spc3.r_len_ssa_buf = dps2_binit.ssa_buf_len;
586 1 spc3.r_len_din_buf = spc3.r_len_dout_buf = 0;
587 1 /* init buffers */
588 1 spc_uptr = (UBYTE SPC3_PTR_ATTR*)&spc3.user;
589 1
590 1 for(r_din_dout_buf_len = 0; r_din_dout_buf_len < dps2_buf_len;r_din_dout_buf_len++)
591 1 {
592 2 *(spc_uptr + r_din_dout_buf_len) = 0;
593 2 }
594 1 if(fdl_init)
595 1 {
596 2 /* no buffers for FDL */
597 2 spc3.r_fdl_sap_list_ptr = SPC3_BUF_START + (dps2_buf_len>>3);
598 2 (*((UBYTE SPC3_PTR_ATTR*)((SPC3_ADTYP)(((UWORD)(spc3.r_fdl_sap_list_ptr
599 2 ))<<3) + (SPC3_ADTYP)&spc3)) ) = 0xff;
600 2 dps2_buf_len += 8; /* 8 Byte durch leere FDL-Liste verbraucht */
601 2 /* DDB not supported */
602 2 spc3.r_len_ddbout_buf = 0;
603 2 spc3.r_ddbout_buf_ptr = 0;
604 2 spc3.r_len_ddb_prm_buf = 0;
605 2 spc3.r_ddb_prm_buf_ptr = 0;
606 2 }
607 1 return ret;
608 1 }
609 /* Ende dps2_buf_init() */
610 /*~
611 dps2_get_free_mem()
612 ~*/
C51 COMPILER V7.50 DPS2SPC3 10/24/2007 09:35:19 PAGE 11
613 /*
614 +------------------------------------------------------------------------+
615 | Function: d p s 2 _ g e t _ f r e e _ m e m ( ) |
616 +------------------------------------------------------------------------+
617 | Description: |
618 | This function returns a pointer to the first free byte above the |
619 | DPS2-buffers. The count of free bytes is written to the pointer. |
620 +------------------------------------------------------------------------+
621 | Parameters: |
622 | -buf_len: pointer to len-variable |
623 | |
624 | Returncode: |
625 | -Pointer to first free byte |
626 +------------------------------------------------------------------------+
627 */ //cancelled in 2007.09.27
628 // UBYTE SPC3_PTR_ATTR *dps2_get_free_mem(WORD SPC3_DATA_ATTR *buf_len)
629 //{
630 // if(dps2_buf_len)
631 // {
632 // /* pointer to first free byte */
633 // *buf_len = sizeof(SPC3) - (dps2_base_ptr - (UBYTE SPC3_PTR_ATTR*)&spc3
634 // ) - dps2_buf_len;
635 // return dps2_base_ptr + dps2_buf_len;
636 // }
637 // else
638 // {
639 // /* not correctly initialized: Error */
640 // *buf_len = 0;
641 // return SPC3_NIL;
642 // }
643 // }
644 /* Ende dps2_free_mem() */
645
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -