; ==== ISUAL Flight Software -- Univ of California, Berkeley, SSL ==== ; sc.a -- Management of Spacecraft Data Buffers ; ; Revision History: ; 18-Dec-2002 - SPG - ISUAL Flight Software rev 7.3 ; First Official Release ; 7-Apr-2003 ; Activated interlock to prevent PVCF building ; while PVCFs are being transmitted to the spacecraft ; 29-May-2003 ; call CCSDS_HSKP instead of CCSDS_SEND ; 6-Aug-2003 ; fixed bug in 4-byte add ; 8-Aug-2003 ; new MM allocations ; Maximum number of PVCFs which may be sent to the ; spacecraft in one transmission is 4095. ; We choose an even number - 4094 ; 4094 x 1108/4 = hex 114DD6 32-bit MM words ; Spacecraft buffers are arrays of 1108-byte PVCFs. ; They don't have to be aligned on any special address boundary. ; Spacecraft buffer 1 - 000000 ; 2 - 114DD6 ; next available mem - 229BAC ; default MM allocation parameters ; fields commented BPL_xxx are copied into GBL_BPL_xxx ; (these are written to the DCM during initialization) ; fields commented PP_xxx are copied into GBL_PP_xxx ; (these are written to the DCM when PVCF processing is initialized) default_BPL: ; MM addr of Status word db 00h,022h,09Bh,0ACh ; BPL_STATUS ; MM addr of Program Load Block ; (4 words, followed by data array) ; (for some reason, earlier versions allocate 300h for this, ; so we do the same) db 00h,022h,09Bh,0ADh ; BPL_PLB ; MM addr of PVCF command list (allow 32 words) db 00h,022h,09Eh,0ADh ; BPL_CMD ; BPL_MMCB - Compression MMCB List (16*11 = 176 words - B0h) db 00h,022h,09Eh,0CDh ; BPL_MMCB ; MM addr of debug word (1 word) db 00h,022h,09Fh,07Dh ; BPL_DEBUG ; MM addr of start of readout allocations ; Low 10 bits of instrument buffer addresses must be zero, ; so we round up to 22A000 hex for the first readout address ; (low 10 bits must be zero) db 00h,022h,0A0h,00h ; (to GBL_RO_BASE) default_PP: ; op=0 db 0,0,0,0 ; PP_OP ; addr of 1st Spacecraft Buffer db 00h,000h,000h,000h ; PP_MMSC1 ; addr of 2nd Spacecraft Buffer db 00h,011h,04Dh,0D6h ; PP_MMSC2 ; max number of PVCFs per buffer db 00h,000h,0Fh,0FEh ; PP_MAXNPVCFS (4094) ; addr of word giving current number of PVCFs in SC1 db 00h,022h,09Fh,07Eh ; PP_N_SC1 ; addr of word giving current number of PVCFs in SC2 db 00h,022h,09Fh,07Fh ; PP_N_SC2 ; Virtual Channel Frame Counter to assign to next PVCF db 0,0,0,0 ; PP_N_VCFC ; addr where Packet headers will be stored by DPU (20 bytes- 5 words) db 00h,022h,09Fh,080h ; PP_N_MMHDRS include sc.i include ccsds.i include pvcf.i include mm.i include clock.i include task.i include util.i include gbl.i include debug.i include ioports.i ; Mass Memory addresses are 32 bits ; and represent 4-byte words pvcf_MM_address ds 4 current_store_buffer equ GBL_CURRENT_SC_BUFFER sc_MM_address ds 4 ; size of PVCF = 1108 bytes, or 277 32-bit words (115 hex) ; as a 4-byte number C1108 db 0,0,01h,15h sq01 ds 2 ; source sequence for MBR packet SC_INIT: ; Copy two tables into Global Memory. ; This one (Base Parameter List - BPL) gives the ; Mass Memory addresses of various DCM control words. lxi h,default_BPL lxi d,GBL_BPL_STATUS mvi c,6*4 ; (6 to include RO_BASE) call copy_bytes ; This table defines the location and size ; of the spacecraft buffers. lxi h,default_PP lxi d,GBL_PP_OP mvi c,8*4 call copy_bytes lxi h,0 shld sq01 mvi a,0 sta flush ; Start the task which manages sending a Spacecraft Buffer ; to the spacecraft. lxi d,sc_task lxi h,GBL_SC_STACK+stack_size call task_new ret flush ds 1 SC_FLUSH: ; force transmission of SC Buffers push psw mvi a,1 sta flush pop psw ret ; ===Task to Send Science Telemetry to Spacecraft === count ds 2 ; little endian mbr_count ds 2 ; big endian ; ==== SC Task === sc_task: ; wait for Buffer #1 to fill scw1: call task lda flush ; flush requested? cpi 1 jnz nof1 ; flush both buffers call send1 call send2 mvi a,0 sta flush ; reset flush flag jmp sc_task ; start over nof1: lda GBL_SC_BUF1 ; test for Buf1 ready-to-send scw1a: cpi 1 jnz scw1 ; not ready ; send buffer 1 call send1 ; Same for Buffer 2 scw2: call task lda flush cpi 1 jnz nof2 ; flush both buffers call send2 call send1 mvi a,0 sta flush ; reset flush flag jmp sc_task ; start over nof2: lda GBL_SC_BUF2 ; send buffer 2 scw2a: cpi 1 jnz scw2 call send2 jmp sc_task ; Subroutine to send SC Buffer 1 send1: ; get number of PVCFs to send lda GBL_SOH+71 sta count+1 ; (store it little-endian) mov c,a sta mbr_count ; (store it big-endian) lda GBL_SOH+72 sta count sta mbr_count+1 ora c ; nonzero? rz ; zero; nothing to send ; add to overall PVCF total (big endian, in SOH) lhld count lda GBL_SOH+19 mov d,a lda GBL_SOH+20 mov e,a dad d mov a,h sta GBL_SOH+19 mov a,l sta GBL_SOH+20 ; Set starting MM address lxi h,GBL_PP_MMSC1 lxi d,sc_MM_address mvi c,4 call copy_bytes ; Send the buffer to the spacecraft call send_buffer ; Buffer 1 is now empty mvi a,0 sta GBL_SC_BUF1 ; copy PVCF count for checker lhld GBL_SOH+71 shld GBL_N1 ; zero the buffer counter shown in SOH lxi h,0 shld GBL_SOH+71 ; SC1_NPVCFS ; zero the counter in MM lxi h,GBL_ZERO lxi d,GBL_PP_N_SC1 lxi b,1 call mm_store ret ; Subroutine to send SC buffer 2 send2: ; get number of PVCVs to send lda GBL_SOH+73 sta count+1 ; (store it little-endian) mov c,a sta mbr_count ; (store it big-endian) lda GBL_SOH+74 sta count sta mbr_count+1 ora c ; nonzero? rz ; zero; nothing to send ; add to overall PVCF total (big endian, in SOH) lhld count lda GBL_SOH+19 mov d,a lda GBL_SOH+20 mov e,a dad d mov a,h sta GBL_SOH+19 mov a,l sta GBL_SOH+20 ; Set starting MM address lxi h,GBL_PP_MMSC2 lxi d,sc_MM_address mvi c,4 call copy_bytes ; Send the buffer to the spacecraft call send_buffer ; Buffer 2 is now empty mvi a,0 sta GBL_SC_BUF2 ; copy PVCF count for checker lhld GBL_SOH+73 shld GBL_N2 ; zero the buffer's PVCF counter shown in SOH lxi h,0 shld GBL_SOH+73 ; SC2_NPVCFS ; zero the counter in MM lxi h,GBL_ZERO lxi d,GBL_PP_N_SC2 lxi b,1 call mm_store ret SC_SEND_MBR: ; Signal spacecraft that FSW wishes to transmit ; a block of PVCFs. ; HL - points to count word (number of PVCFs) push psw push d push h push h ; >>save pointer to count word mvi a,0 sta GBL_MBR_REPLY ; reset MBR reply flag ; Send MBR message to Spacecraft mvi a,01h ; ApID 701 lxi b,20 ; total packet length is 20 lhld sq01 ; this ApID's source sequence number xchg ; in DE pop h ; <