j*5C9$#4eP z$z6{2zGCQXyA2MpnZmVKoI}a%SC5i6C^uK}&kU27T6uW#dmGgcb1aYZXvDI)tYcj6rEv z@&^+%&N-#{+{RYb41-x59IEKx1kgcSUmLQ!)4pD?ZJoFD5h1`AzWe=Ii|XtoE*6cB z-a(_QhmGJ@hLRYVaomkpRlPx};8%Y_3o8elCTy-po0=spMRy!I75=pZ7qR?7TU9-z z$Ht00yyL-lb~QR&QF-gpv-IN@3ZwxHL3Z0g-6)}L@RNn5{fnjnB?=bm-)Vnd+HC%a zRha9*Kp$&;1#<8QQ(suX1DV?$`4#oqt#MiJm*C{2Xaax8s+LwsE`B%a4kkvC^Wps8 znP+n!fnICvCM%@$;coBeAfkY%WmYrDjUGHTA`d}#So`gtj6LXiJfW|z^NkjzWK~tc z4VeAApAiACYHp{ %W7 z2>sCw{5dR}1`!&{dwRUi#gK|xY*ic>U+)WU2ZD8l-bn=MksVj)zZ~+6Ae!?)@sLWv z57N^Qk_6j! #v&n~LaAl^MQcFXS=-U(!SvnS*n4|`J7O`I`vGOdfcE_e z$cMb^JwAG-G0(f6>wSv`@bi`Zl7S*&q(WE?z& H=d4ohXQs&?(N246!l*RRmEe6}m0>0$v{}Hh`Ohzy;y VZP^U~EnEe`f+B+I2W|Ge zyz~OO0)Hp6-rEZ@1~cYjes}##oShKw^;F`75p-}K8V&A&3vVczky>cb)zB3jm4I*s z*{zrp!RatukKSNqNx72+d~*o;)eJ@D1Q`!A3xN*>fSczIVu Lf| *>aQJ>1<~(74ZcuiDQbyLNz#x8S zXKFsYK8P>SHE5#UKB9W?tCu^`6ZOq*V(Emy9>cOLzDy735G=;wC&C>@oe(5dl>ut0 z(DTrx=TOO^hqPP_UqSZi@Rhi_EP>4~$kY=^t>&7h #Qk>9CBz1C z%s~SkJUb+ V;kxFRiawdeKn3vhxo%{Yf#fFZ%k6RU(-< z5YSD~e$lTW>etCEYWiduE$EcsYrN;;_T=|Q0gnY@=45fYu?1AuUZT8PMmiWbid&{P zT9(FXW79;Jh^tDjl8L1rKHw9QgG6tPdi!Ak{I6pH3YDL6mIRCwrG4{i_WU~{iNQNP zV5Ec?VSSh~Wnx1&X>ibODa9gVKR9|%j)%&ju|-Y4{2BQRgom4mAmjl@ZH{NBLOV|6 zJn2xV)Mj7S)xr?-i_252SlI?RYjo0eqpe^*3{0qOIBST>JLh8<7e@h+t=08B8>xZ8 zA3Eu6d|irdSJzE3^cZsu=UCzcSIx5wbg$i^70 wEPz*<{g5%7`-%EDLz{SA=R_FFi%W|n$B(a?kZHK#oAy^_W zls%a_r2QcgC#ht)z8};1v>=sFK5pMyqoLgs>nVUjRqN*;=)q91z$fv;-ox3K 4G1 adH}PKev$=yFJ^bug0o6 z1Kg#Q9ij`1rx6AluQ|zO+>iDsU!Kf_j}=MK)%%r+jgw#*VNJ!O6Y!*?&yNn(adCJa z|0lopZHWLzMze(6_kHxW8XFEg3E $wYLnb|p zlNjjM*6l^IxpNqBP;2(ZqQUozS{4~QvMa`{Pn2k11@vl$X2OYr7opi gy|bJSZFOBD8<`)KH^58VT7)mr!SkULI}fZnXGfQ*vthX-eKP_eM-iJ!v)B zo1D*G-1AR!zXJ)0pov4FO)0+VbpJK@xc?K2EARP8`Z$lSmVzhRshmF43Rz9HnRXOj zgd6}n5_Z3)Eh;>|)xd498GRYJyOmy$?fItht6_-D7Ky9*&*wqJQ7L!mm>3(mSiT|z zm^2NY=KbX_9iq$YcHni6<}_oMsivk>!hKN&(45@u>rv_-{uoS1PO7-6`WY0s2o=CB zzpOtm&-8UFuMCTeW9vT9zQMtz=y0sM(R@*M4=2*E$pHf6lp;6+LZrKtG{B|k{I(6z zUSOVB=3_UrJd2M-4ISe7(0lm?3Uz=QAT(c!1X|qx#l p@@5F3hF2u@ByDUTnFyCLUhq|UoyZux1ppn&QLf1G z1O%R(ST#52wruA0|GBt$SXp_Ro)));Iy+PB*v_x1af=zDo=Tpvw6(Ki!+y}w!NDI3 zwG&1Xm&Q*dY#(zj8;V3qz{{vym74MbWlB16FQnnu=>qBuL#wIU!1m{n9s4&Bb~hPT zTp+QBXaT}%799I}in_Y$yZyGth^})uYmepv1NJv}dpj#D53jn2UQdLGtQ{QIn{9yh zZ3d6yWOJVvR=b?IOS^veGEM8Lx%h3qzy%t$(Xo+{=4Ln1Lil u z!+1wdcKoSn`RKTotL-i(Iyw$MJ_K`SS;C}x*K^|&_Ow@#kUb2*esNcGv+?=Lw!Qs! z3MGb4Esl^vKAFlF-Lr46W(Uz0f?ha?CFMx=<)3fWNP=?`*#PUv5SL0sFtxa-R?7 zkqLyg22Ga7=?uPaudh_{)Ltif1Ws!cDPwx{f6EIDp@?1{mdK3nL>Tniu0D>LR;}5) zb?ulJk-I^O>!QH73_4r}io~c2{O;o3uKT1)ME>V9V_dZ+gJEAl&P3_V48#-zPo6`< znCro?jjFiO#dW=v4myU##bpZ*etZSBYe2wNrP@qk`on{H{>kQM7aLnjxdL6laatS> zj?CfMNkw;pJa{;upM M9>=H61x ?~VZnLV%Ts_E#s97kCrnKEb1l=m|+(e&{-kRrMS z={x;N_g7P6886PqsX*}U0(;7ZAE}6q@UcSOq7-c9Plxs(-T*OxKZA7WEa)})sMtm! zIVCu8LB~+AsK$ yNI+kH7zbwD2zSXyz5_CwZy`)M?sc=FYS ~~9x)QqK> zg99W!f*+MNi}dz7eb3Iu^76_q(vAw^X;n{8WmlK)R=cXqSxEve=$k<$HUhXd0F`jj z^!eQEE0fovn>cD_CeJO%QAbBaLxVv4R|*vt5wALg1Jc@^SY&)z>2SSKpZ~wbbv&*B z*qWZRD!I>3AeUp$<77lc9;O`o#qPp_hKfq@YB|1O_piprr`F9C{ X9X_WYH&x$3M&dzgK+0>dh(zCOdIQ0UR z5}-_f4i8&bb42i4DRUq@d^-^OSE m&P-1SzXe<@ZEY=VZ=bkzHa4p6{n@icfN$T}= =x4V$m!ow%il^t| z!s_DM^urdfS(kx6R6RRqb08ta5oW6@D!ZQ8<(pv%U(o$ThOqAHvd`hXgftx0E)iUJ zR<2(5yMLWJJI`iiO-@NZ>{rn3^4PwcIw9osI&cFU?mfh!&*U@_?G5W%ZCYQaxxD1@ z>8WeyHhaqbSt4a?HBDW>YLQO;2 8W%EtdU-rUlQh`;{zhcHkCBP_b3h>$3n=U zL({1lO2XsrFUK+C1N<3`*$PjQ$BOaCSd6)GR+J-o#HGvC^$`LhcIMT>@#P}c#7tat zOk8-T4q>rJO`?W`;{A8S(IZC}gGUn*=GDW$vFKS?efrIUtka76bA`H5_OSQty5y$F zBBy45$CC3Eqp49*mM!PmQ&Nb|F6pUBHpk8dUCRvY8Jp&QB@wuZlj!_QGH=BDw;j5a zeIueR_EefiB^_VzkY%O=Q=XG}2M9@>NyfRxk?J`=g#a)lY?}!GfMe!`R<_{2%f@sR zy(7Q*?Yt_@{707KFVkyQWU8;}EKp?Y*3yZ*6R5E+g5zDSK4&qZ?1SRDoca$MW42x$ z1-29 lR^0Nj_w5aqy6a=5%-Vu*P|Trh zsU9;KTQJdNOdi7Y=aa+Rm_}aS2O&K`KY_YGp})K70HX8Mpq;dT#F@uYYClMSgs1<3 zboF*23A4vgYl+us&-|@41bhn`Jl&(WsrrHl0bI eMliN2A<8s0o^6+ OP^o_hRA z*%SjOhSj5|t @3C5X=QTv2i|Pni%ZV(A%+f!->n_> z)%A?)Kjh;$Ms?sN1(>GVg^S7MVpY4;(?m|m_#uS7Z8)tzb`j(A#vY|`;>}E!ZzJkT z5Ck-=?Cd$))QIu0M+;Xks+wRz#!bTutpzerti}~MGfqZ-jpo>N4OA(JXcO~8Fynt- zP?5o-D1Y_%D=b@Gq7I$4 kt~=kzfBC-Yl^u=HS4%6! zvn@=FpAO4bL5gCbkN`#w%guJW?BY*a|7dbP-s1{x*by&vne8Pb?^F)o>|v{ HA;E?Cr!|ZoedobGS1!=9jcA97Wgg?Od-m3 zi>ev1D@?vg1538Saf7wkkkQ4$#abGaxKM6ZA)Cl%NHcI}`0zATK{s2G Q5eRlYElDbtu-IbD`tKek7TETEtfmZ#cv)5Jc&(Dvyw8!fFADZSTCUWiuXo>W kZv0Z@vSojiId5Z6D7{17$w0s=m3S! zpqF~bOV{YeU oOsWEs@drw=V&XcQtzRl=Vvy;hx* zbfm7-{)X>+cuHjV{8~$Pddm5dNNg)yH3!At77B;3`F!$v5LHTs#B^`KKop05c)#PX zUM7 >SPTmbW6aGk<|@azi?wG zmjEX?T$vCi2K7CxDnQrLAu4$uNH%EnaeMI2?A6Lr|7U79YY&eus)YEN&<(D^TNavt zy%jre&jcz_fgmD#e=-jVkKxje_R{Klu9kE3l*6GH13N_V-t7~r1& Y)l6|ERBqe^B ziNdt>1jG5IbroOp3^u{$_QoFWDccx1G-D)rG((G&u9Akt2&H>VZoJYI7y>txoytn- z-%c{`<9h}e8*#RpDKg;3HVjKQZ?d5Je_m_B=e1`{h6O#J{^_t9=B>q*&kt>C?Z}<4 z!XCbQCiDSJv4KdDJ*nNg-&ty%O>d1jy#4o5o^V+u)L!c}%BmGu&q3q53&m9WH)EM- zhvo5(Bd6d?AT;wR_n>oVGo?}P$CD$+7^QAX)0QG%E@&ITVIl&;SiA~U6#Uz}XMyEo zIbIP@5dbD>>pFpCJx-{KEuT(W3dfKo2QV ^Y@{2~k38L^$T^5J?2z5uihqo`U51>w9}KeiQC~C`r1E|;4DlOo(Ip9_x?TAX z;7qsLAN=M4?R0XEzJ)El$xGJd2EWT%daJsQ-83hrKd&^Sz|F}|6mzW_hlAZc5!Tp! z4u`{6_mc*64K^#QqT#fH$A}0rRGBSQj67{kHBqdG4qced$q_KYVjeaC3e@%gI}#ze zIb|Ieok{ AvFv1V8Sd-ark;|F- zNG_;H`TzEoa``-xNIne~8yZ7ng(Cq?pIG9+MH|9_P?2vsYcAzeF6;wf7-4=p? mvwlmitWf3n}Knju;kJaceiOafk3v7f- zVxWa|rTjr$YB*d7FTe5Qz{?yJsPUfw {`9q*rK3YFQSia{ZX#p;t38rQVh6D&^!$Ox*7SMj(L#O8UPVxejxZB| z*dF$PeVP1|U3|JP`wNEQ8+EC*S*-=QmR)9IA2K{Sb*FuFF+R@c)nDixO!m+lz3z+s zN(|{ I8M zoN^~W6U8&(`V$VGZTf5FV3!W@j6RNH*GpILE;8(3AuE++f7yDiT%mHyJm02;hvR6n zHer{%3XuF{#sb_e0b<^yq+{q7Q_LRb9BQwxQl=pp=2+a|`SQ5UPPI*p(&%{Q011)Z zQ38lkhQ%f`2gOI)XoR+-tVV1V$|%BNeSmpp1o`o}F9nx}l_4u3!IhmQrhm=dnnSnk z<%#mO0tDi7r22=jpBXpopp8omKHyrqu~)BII%;reJozQ9yF%Ngu{Bzc$h1+=AcZEl z%((1Yv*U)!>8}g>e<#^`; yxqb(u--FK!)8t17#To}Jq}3+Ihp z;pv1{rp+rq7RB*6Dt|{bbE{bv>qybc0`C1C=DaBj+&Uq&BW^_PK|~=?$N@)O2IN_I zqjX@zu72?OaPG22o|pn4YPrAet4SSCI9a*iZ@smzT&W;J%gm;)zv;H9IZV*toXUW6 zE&Wm{^~9yz+U4pGuQOnZj}WWaE3ydkwBM(nmm9(fo=ai&m$C>stZ?w+W5H(vg)rgq zVl1)@G6^aN{KvQxe0q{v=w70zIGi!``@>C|+4_J9yU}eZEhyaoM+p~)Uts>9(7WW1 zRPg_0o5)Bgir0x6hy3pp7HDYb|4Cs1{NIlM$%(OWGhy_yw~JF(aLi>!?*?iSXVYQF zk{E*|`JB>d(7BU6wwlI?<%Y!Bp|yVXj`m|FYqUu9aot<)Kpi2S)Vc3esLS6BB7F3_ zQ&SaNcGGN?4{0&E6HO|0cm-I79q1+&mFW8tET@@O= 1nhfuyDv2 z ca%CIpl~ L+ewq z#IezU&feX>>VKnYmczfDowH#x`S9Br^`Q-v{~EVRJ6)crd_pM8K|vcl$>RM10RVi! z0f7JaNcb;cTrJ$(Y#gjy|BHrg-CfrMPUL`Vqomu1B7fp{X~qubU_4RLA$$_{{+3lP z6Q)AR6(4e*u&>@^W*kI2QS+^T>_`*C>Aj9Ex;A|V?VoqJjVV~j$)t{6%S%5!LAS<& z?sSIm5_o^j?PUB_TIJ4DB{~Cnb%xeYBd7iqIgTcfH}!hvJ`@8{PnM*F*?V~=jo#)~=@ zr>p5KP2 %zY_Hz!uh z8{Q7jzJ*QRRWB`P$Lq^Q&%YAIDJH?Z!i{s_F#qLPoSb^0O^MM*NN}yOs?ipa4cKP4 zJGnhLhCmu*J)6M=gp3C{)mMtcd++gqzO=^d_LqmrNIlfyyP(F+H{kC+al8gi?*&KU z95-^K-gimyn5*IsC?urx4QLS*5n;}<3j0U=)R_(%xy!!^3by+Vq0@`i(=lGt<^Yj} z@F-)pzIjLp;u#x}iUt8@E_dFVA5f?p!FZ`#6;P$FuhlfAF^oy^wm>GA2W-8K4vV?R zvk%kunYkMfD!_ASg?~V(91k4HCVZVk?sk-Y@vjhUP3`@plCU!-+8lRU9eyA9L}x>W z_>1SN6}W8U#iuf>a$0ie *I>I$-? z+~;RcFBG8igH&p-LW@^oGiL|z0B*x#9t50HLq_Q=!6IbK(Mem$#tb{+H@hOPN;YKh z$ND*BkPp=_vyD8yl;9$iMlj(|;`M%@+u=ngCffM7cx2)6Z$9~*64dGgaq^M8>zA+Q zCF^uczAnxijgZ5Oh2!=1tXs4or%X=(|F2g@!K9@2GHhSSYp4$`Sz-u(i_(hN_> z!v>!#GZui)FB#f+H@2e6=`yfFY240c%e0cn43FY?VoN}FgRZ19{;IR4jSX*$Uc7${ zNv>A2{YhwLBs*}Y z)&8Fdfskijr_}yYh34h{8HI$(6+8X0E=wCOlI@2BJ1^c$3qUktm jBAF|JB~Yf$G?!bSt2ak`wAg=2SQjX9}X@Tm#!z23(>8a zgyj;~$}LKRM^x=?Z58{}rEv~C@IHMNPpuZ%Dv%?uHsWx Cm4rc$ z?D$v+%ruaM&FPJ&J$3b>C0%R0?TANo&7kwX#FBOWcsX++btR|4qyG+Z!^d>$+mn9~ zqDd~dZr;1))6+-Q&F22ScgaKZHSgFA(Un3Ql8~vkHvg?-$vBy+=HDJ9%^Xp9V2|^< z(E66x-QTu6_L9&&qm1dS87XL@EMH__1O&ot1&yf`-lxn4?L!YnT~25aRY%x!= 2mm0R?Ei$IaNotu(ZTJ% cz0^N<*=)!7+%4a8YRhxb zGaRVKTThX1Y|3)>SX{H&_*g2EQ69`D*G_CK?G_Jw`gkRW=#LRrL8sAEL|f%UqXC@- zLF~QW%LPkZ$HF>iPr4$eL7ug2EIMlhZ$g%$&Y3$(SQVnp_jCTt!Qzfrfu1A9XH?5f zlZ|Rh4v Ey3H8FUW$6*+7BOR7=aEhtN<@xK%%PPoicit0?zYE+(K`fthr$x+|u?XH(Ft z)jWf($eiXF0{X`RTOlKB^?S)-GJc98P$nv9T1Wh_j cY}rU*1!a z_kOs2yizaC>&{5I8B9w~UC=!(tNUjRyRD2h{6~|ktAasW^I02l4=;5uX+@YgG7{3y zND P+3`ZCI>@z4<_2Pj3uHV_duNh4zM!#$xzJ z23Com$rJR->mcO_tnBL;nRbrn$baEOqc(Aac_=O9l=%f<=5?kqOC+)=he%={Ig4FU zC440+d4x;$V S98M!NrPjORhhG5*6?GH%rIon3P zvLrB&FoK-q;S5}jI_W}!*-V0y b zxK5JX1njw6Wt`Ek tK0z9fFS)xRX?kYf;I@ zo}%@axkPwgS;`65oFE!MjYI*`6GUX|t@&Ts0?DCFE6V_r$(HT2?ak`3$uxKt3?)WR zaoE35z!03eZ2i7LB7|!d8~j@Q9@g(GwCT@A_{Ki6e^{9^LL%e_3!-F1>@LEe=B+=( zHh(!FrBhh)P^dq1UkV-+ ?@qf#o2aS``a$YKtUSX4^T&OSt-Djj< zs;29lu+rpQhby$Qied=l6d~cm@P#P!CKDV3&AA_pWnbZL+B-v_a0J}Sn3;uhnGy^X z((}2H8Q`PGb$ ZE+3zj0ocl )H2hip?LJoT7=zgG0t P_qhQuDR~#i4;D>IvGlA5qn{-QJW|+@X!9yPFJkj%{AYd1)6Pd1_IR{%*337h+nD zX;le6%0C-5MYIftY6N0hxHiwY6I}9H1jBAaZ{5G@J!(APf85U0Gt+BT= 2A20C35e$gS$t3j&Bjfv9t>frmTMSdTtd> z!M8tN>TX~ a1|aw5(5g;9V*j9;*c%_Dpz@Ce#w><(jTa40P7pelJa$b z9oVu06AI1gLZC@SK7eq!Zu#?v5E5gJtA(>f+t@N?&wxzmT%$1yTa2~l-((I%`<6jG zxQ8sprN+Q1XP)LoGACxDAhD#Tm_$5mGf+I_d_vJZb7-8Z7jl$F#i&H!_eCipu~JtF zmE^=6I+!Xt!I#%B-#Yh6F(UC%{IEGtG%VjT*YczWO~gD Ng(m3b&Y_($Lzp$PCofsgI3EamH@JrCn^U)M3HV`N4a&~i2QPGzJJ3g2k_;I z>UdZycx+Jo(!l!?Y&&|czRoB>*^sFTdJy-(Pdu1sfl9pa?)EJ0;b-BENA-9HNE3u_ zAf@VG nClp~BX%d=$0tca4;0tDKeTt#7HZOHZR9yq(m$(I >{c;1nj^i~x9!WV7gBfD<%M;GG*=`q?*fuGS5ZDieT*c}d zjrlO9^%2GU3l o(6T!j{n+LdzWO5*zVv#fyD8nGelE`<2M4PR%Rqk6- z>Qmm^Ec}N^8k5*oVyTklWyx*!+UwSC#3js1Z6mJ;YOv{6r3zN1b?NbYHgSD2je8BT zQ}_l?81*)q5VDyooMJ?Z@Y0?vV6K{bhg=V9N%3LlJ2}zR2O<&;uxdzg-A41ILzUh+ zbv21}*$rjd&@DhlsWfnzlQQ!G^kZQH6=4BI1lAJkNfGi&aw!el7L$g*;Z P4G1dW=UL zL(e16eWuGdazu{|zqu~RwckU%;(P`Of0YnAx+s_G?Tvm-VJ^x4*dlBBrf8k1y$p01 zyI28|$~VH(9{uz=oLm@f^kQ%f#ah1O`YghmZ&}|ZlEbV-a3Z 200 zwcjIjPs-j2m9&YwK!D4B+~nBrCGVpUx-++W$TX%!J$5?o69sI{_vPSlQU}_8X+#ub zxwBkW6=gA7Mu;e9%4Te-#@5f?CDfEqs@Il1lIwY{zgeHV{*)^3 zfw_qONWa-QUf$GR!coxcd$ePAfc{IP!tqS~eG5BOE(+`TZ3MAX3*CZ_= RPyK0Jzmj8`09lheQZjKR&CK+(kj5!7Nkza z+%^36P(BJh`J>t*#}>qk6wDE8V_Jk!*q#2V+*c{?*EY3z-9T%7Pl(@9!yJWDF 7tHznMk=w*>e22%3ZB7Ps)VeFsvjiF%j#jZZNfD^+xs8)vO1 zXzs*&Mdc22m}71*t*0Pb8=L8sSgWb<=FP@5S0SG>sFsQZ4mNRo8|JAYUtZmkq$RjD z5H6WSj<{9MeYg^g^{Tqcxa&`oesu1eGus&j%8w%h0N&pClQa7*aS6)R%K`rXj{zo* zsHs|-!!e5%2=~FYhu&-HrH|6>QWwN7Iqyy8q;IPcu`7~#oNvKX?0Tlq8;$eFag72= zXya}qSHizcHqei}6bu-(u?R5JWo>%;zTV?HyhGV
c(xZmZNihX{l|X$YRCzH z)IkFkyM~eax$v;!$k~g${Rx;4K^ o19Mil#C}aF)=ew0>6#ILI+&-G*&7nZPFSpbvZRSK{ES(WIUCZ z*@N|qCc2jy7_! zl?YBfed*;j#qFfkdPP$!-weEQPC|6RSZ0@`w@qX;mcf%aEqK~NY_q*#u86jUwQp56 zu9{j`JRoQ4q2RKpqi(A)+(!z2zQ3}}Dt5CnP^yah12G{2*)~7R*NkFdau4oezTQ)~ zm3bkhqq~uqM?H($D`gcpU`s{z)E-@_ukQt2wglwt0OL=AgO}_g-jS8n)O)^;-NMb4 z^nfqHFYEbw9__xTw!>qA#N;d)q&>W|XfXnl1|gO6Ir9{+!pzP6g%@h*x8K^FS?N4_ zq*#Xi;9bWV8WzB0Yt(|NGd%nZX6sZ~UQJdUU*eD2Z@E94A)s7zhQ33F38*JBT`9w! zEMYBWE_O?lnTt`hDHu8aA$r=PAM%#z5e<9%h;HvPI3QeHZ>(+;J#7U QIZ)(I>y{eV8y>Pynsdm}J$ng%56#&o8c}$fWZVv>ODtp;{02&(2FwyZS8PhS z`xI1kK6bua+Qg35`cZ(sY8 }hw}Rk6YbT{p@(UCR zv9$Hof&2V769V(){(2Ck&RH&-c-Pony?s4+vNr@6W)1}Q-cwce1T&U@%m8Ss=wwBO z_S+BYJdtxOjwM3Ev|e-fqz>G;Xw-|=R!Sy|!EVO-679K~^UAe?n~K`WLTt;3p;G*D zgb$Bg8|s_@bJ86idKz6pw@p~8lqj4V!*hMjO;j6Gx%P3P2XbrHuNDpn8YD~`zex0n zkBmNL^W6y=AI?8bjum#Yq)Sp$`Dhg%?(b7SpCr77zeMtmcAO%ULTxpH`AzbXrB$*% zpz ^i$7zEu}t)1I<#e6aa6t4cXk?p(43i zi;wXyQGN5Fbh{;x^VTXc^(Ed;D{u5mso-2~vd +{1T4R|rumExJX8L0; zQlfxMbXTwfg=8xYwyxnL=2`s*>@SZ#0-wE`D_Q0qU}kk0l8PhvOPILpKB`Do>9upc z8E!V44R~wJ4A*?P-rPEoro!|XgAz?3PUFA(VQ`O`mzpw{HC3tvF&+p+)D7t({nhOk zXVY=G0qIUkJ8wct49~|5ttd-y=5)^4;JVPBWh)Ym$j8l>gJ*e^=O;DTUHwFZ^K3RG z!+RPYvWeY!xcgjzSso##Ws!C&6UW$%N&MQ)adrXhDjN3A-z0pPZ2)8 7JJ>zKm=_IG~bXa1M{!i@F@9w=N zK^W@Lc0xCDxXxW>zE@opUvTFBpuRgLIHC-zt6%J (tmuxJ z*q&w~*^11sx$x n^ixQhMtnwOf37}L*(}yt_!xTdNto)yvSyH1z zV01Ada6oK`{Habr#I|Az=r%OXOK6yLCNfVB&9}0*UmKmNdDe0A>n)T@to8LeM^t~v zg;iNh{K}{3p|b)Hy49Fk%nhdt1*)q$a97R=d^qxcW~FiI;EMmJgNefw(oZeh!*8v= zz YDVCA%-!EQHBjMM-6rKiQQnQkZ7UYb)e{SI_%nvW{e<{I0F7c?hoZ zl-+AqEOMuw>RyZ~ul#7mSl{JYACgE;WphUubmYz>2eV2hT(e~o&fk~FF}-i~B_)=n zX|F#q!2=n?R0@(9(7Q(bSnqk7yV8KuhVYXwydQ1FyAAfb4A#SjvrHHU18;LOsjnGo zoPsfV$t!d|(8=w%JukLv$tQY!h@3TbD!biOxitmm{rqy?d%v@ib-4w;(18lYl-9MG znM8Pyh@zAGkRw}~22lzLMP^%5^b!YM_ItFnIyR2;iSG;@&^Kz Advl#@(ye({9vnWpL#g`t z`CUmvrjg+|O47#8 Qm&GS8urUxNHx@~v4ZlxKD1w5l98$!n)`kltf z$r76)J|+#)OAz;NjWy_*^87jo_F1|cJ**mn-TDxv_D8(2S3U{G g$5xAL#cC}pEuuUIu^_!Z>SLrse54;4=qh MFFtpH6cfclbtmj_4k@f zAGSEXI)5tUv+w<|JC;j!S2er~s(I#F0%&+t@Pl6HcaI2#_i S59b^#5 z7%p-UXN#XTQHz; 2n|x&Ik!)>Vm$NssolqRs5<=p8M!IeHi_YQPR@+>P zD4Il;u`H1+8>hIxo4xh-wPUWxE`}Bl02m|q_7C9Up8@ O0pOx*O@*qy&`B~|H&vV>t`6uxFP`-c4GI|2b4<-DkET^^p zq>RTc^R54PdE+_80zQG|H%j@Zsj(g-%{YPdzjX4S+HUj&vY&PH_dHC;ctG0!OGl6I i+0SwSI>w}>{Tp4?Rs#}!>p=bWllXdCbG{vO!2ba@_Z|-b diff --git a/timegen/header/TC_types.h b/timegen/header/TC_types.h new file mode 100644 --- /dev/null +++ b/timegen/header/TC_types.h @@ -0,0 +1,219 @@ +#ifndef TC_TYPES_H +#define TC_TYPES_H + +#include + +#define PROTOCOLE_IDENTIFIER 0x02 + +// PACKET ID +#define TC_LFR_PACKET_ID 0x1ccc // PID 76 CAT 12 + +#define PACKET_LENGTH_TC_LFR_RESET (12 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_LOAD_COMMON_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_LOAD_NORMAL_PAR (22 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_LOAD_BURST_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_LOAD_SBM1_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_LOAD_SBM2_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_DUMP_PAR (12 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_ENTER_MODE (20 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_UPDATE_INFO (46 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_ENABLE_CALIBRATION (12 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_DISABLE_CALIBRATION (12 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_LFR_UPDATE_TIME (18 - CCSDS_TC_TM_PACKET_OFFSET) + +// TC TYPES +#define TC_TYPE_DEFAULT 181 +#define TC_TYPE_LFR_UPDATE_TIME 9 + +// TC SUBTYPES +#define TC_SUBTYPE_RESET 1 +#define TC_SUBTYPE_LOAD_COMMON_PAR 11 +#define TC_SUBTYPE_LOAD_NORMAL_PAR 13 +#define TC_SUBTYPE_LOAD_BURST_PAR 19 +#define TC_SUBTYPE_LOAD_SBM1_PAR 25 +#define TC_SUBTYPE_LOAD_SBM2_PAR 27 +#define TC_SUBTYPE_DUMP_PAR 31 +#define TC_SUBTYPE_ENTER_MODE 41 +#define TC_SUBTYPE_UPDATE_INFO 51 +#define TC_SUBTYPE_ENABLE_CALIBRATION 61 +#define TC_SUBTYPE_DISABLE_CALIBRATION 63 +#define TC_SUBTYPE_UPDATE_TIME 129 + +// OTHER CONSTANTS +#define TC_LFR_PACKET_SEQUENCE_CONTROL 0xc000 // PID 76 CAT 12 +#define TC_LFR_DATA_FIELD_HEADER0 0x19 +#define TC_LFR_LOAD_COMMON_PAR_SPARE 0x00 + +struct Packet_TC_LFR_RESET_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_RESET_str Packet_TC_LFR_RESET_t; + +struct Packet_TC_LFR_ENTER_MODE_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char spare; + unsigned char mode; + unsigned char enterModeTime[6]; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_ENTER_MODE_str Packet_TC_LFR_ENTER_MODE_t; + +struct Packet_TC_LFR_UPDATE_INFO_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char set1; + unsigned char set2; + unsigned char set3_bias_setting_set1[6]; + unsigned char set3_bias_setting_set2[6]; + unsigned char set3_bias_voltage[4]; + unsigned char set4[8]; + unsigned char set5; + unsigned char set6; + unsigned char set7[8]; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_UPDATE_INFO_str Packet_TC_LFR_UPDATE_INFO_t; + +struct Packet_TC_LFR_DUMP_PAR_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char crc[2]; + +}; +typedef struct Packet_TC_LFR_DUMP_PAR_str Packet_TC_LFR_DUMP_PAR_t; + +struct Packet_TC_LFR_LOAD_COMMON_PAR_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char spare; + unsigned char bw_sp0_sp1_r0_r1; + unsigned char crc[2]; + +}; +typedef struct Packet_TC_LFR_LOAD_COMMON_PAR_str Packet_TC_LFR_LOAD_COMMON_PAR_t; + +struct Packet_TC_LFR_LOAD_NORMAL_PAR_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char sy_lfr_n_swf_l[2]; + unsigned char sy_lfr_n_swf_p[2]; + unsigned char sy_lfr_n_asm_p[2]; + unsigned char sy_lfr_n_bp_p0; + unsigned char sy_lfr_n_bp_p1; + unsigned char sy_lfr_n_cwf_long_f3; + unsigned char lfr_normal_parameters_spare; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_LOAD_NORMAL_PAR_str Packet_TC_LFR_LOAD_NORMAL_PAR_t; + +struct Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char sy_lfr_bp_p0; + unsigned char sy_lfr_bp_p1; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_str Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_t; + +struct Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_str Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_t; + +struct Packet_TC_LFR_UPDATE_TIME_str +{ // the CCSDS header is added by LPPMON + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char cp_rpw_time[6]; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_UPDATE_TIME_str Packet_TC_LFR_UPDATE_TIME_t; + +struct Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_str +{ + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char ccsdsSecHeaderFlag_pusVersion_ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char cp_rpw_time[6]; + unsigned char crc[2]; +}; +typedef struct Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_str Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t; + +#endif // TC_TYPES_H diff --git a/timegen/header/ccsds_types.h b/timegen/header/ccsds_types.h new file mode 100644 --- /dev/null +++ b/timegen/header/ccsds_types.h @@ -0,0 +1,665 @@ +#ifndef CCSDS_TYPES_H_INCLUDED +#define CCSDS_TYPES_H_INCLUDED + +#include "fsw_params_processing.h" + +#define CCSDS_PROTOCOLE_EXTRA_BYTES 4 +#define CCSDS_TC_TM_PACKET_OFFSET 7 +#define CCSDS_TELEMETRY_HEADER_LENGTH 16+4 +#define CCSDS_TM_PKT_MAX_SIZE 4412 +#define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4 +#define CCSDS_TC_PKT_MAX_SIZE 256 +#define CCSDS_TC_PKT_MIN_SIZE 16 +#define CCSDS_PROCESS_ID 76 +#define CCSDS_PACKET_CATEGORY 12 +#define CCSDS_NODE_ADDRESS 0xfe +#define CCSDS_USER_APP 0x00 + +#define DEFAULT_SPARE1_PUSVERSION_SPARE2 0x10 +#define DEFAULT_RESERVED 0x00 +#define DEFAULT_HKBIA 0x1e // 0001 1110 + +// PACKET ID +#define APID_TM_TC_EXE 0x0cc1 // PID 76 CAT 1 +#define APID_TM_HK 0x0cc4 // PID 76 CAT 4 +#define APID_TM_PARAMETER_DUMP 0x0cc9 // PID 76 CAT 9 +#define APID_TM_SCIENCE_NORMAL_BURST 0x0ccc // PID 76 CAT 12 +#define APID_TM_SCIENCE_SBM1_SBM2 0x0cfc // PID 79 CAT 12 +#define TM_PACKET_PID_DEFAULT 76 +#define TM_PACKET_PID_BURST_SBM1_SBM2 79 +#define TM_PACKET_CAT_TC_EXE 1 +#define TM_PACKET_CAT_HK 4 +#define TM_PACKET_CAT_PARAMETER_DUMP 9 +#define TM_PACKET_CAT_SCIENCE 12 +#define TC_PACKET_CAT 12 + +// PACKET SEQUENCE CONTROL +#define TM_PACKET_SEQ_CTRL_CONTINUATION 0x00 // [0000 0000] +#define TM_PACKET_SEQ_CTRL_FIRST 0x40 // [0100 0000] +#define TM_PACKET_SEQ_CTRL_LAST 0x80 // [1000 0000] +#define TM_PACKET_SEQ_CTRL_STANDALONE 0xc0 // [1100 0000] +#define TM_PACKET_SEQ_CNT_DEFAULT 0x00 // [0000 0000] + +// DESTINATION ID +#define TM_DESTINATION_ID_GROUND 0 +#define TM_DESTINATION_ID_MISSION_TIMELINE 110 +#define TM_DESTINATION_ID_TC_SEQUENCES 111 +#define TM_DESTINATION_ID_RECOVERY_ACTION_COMMAND 112 +#define TM_DESTINATION_ID_BACKUP_MISSION_TIMELINE 113 +#define TM_DESTINATION_ID_DIRECT_CMD 120 +#define TM_DESTINATION_ID_SPARE_GRD_SRC1 121 +#define TM_DESTINATION_ID_SPARE_GRD_SRC2 122 +#define TM_DESTINATION_ID_OBCP 15 +#define TM_DESTINATION_ID_SYSTEM_CONTROL 14 +#define TM_DESTINATION_ID_AOCS 11 + +#define CCSDS_DESTINATION_ID 0x01 +#define CCSDS_PROTOCOLE_ID 0x02 +#define CCSDS_RESERVED 0x00 +#define CCSDS_USER_APP 0x00 + +#define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24 +#define SIZE_TM_LFR_TC_EXE_CORRUPTED 32 +#define SIZE_HK_PARAMETERS 112 + +// TC TYPES +#define TC_TYPE_GEN 181 +#define TC_TYPE_TIME 9 + +// TC SUBTYPES +#define TC_SUBTYPE_RESET 1 +#define TC_SUBTYPE_LOAD_COMM 11 +#define TC_SUBTYPE_LOAD_NORM 13 +#define TC_SUBTYPE_LOAD_BURST 19 +#define TC_SUBTYPE_LOAD_SBM1 25 +#define TC_SUBTYPE_LOAD_SBM2 27 +#define TC_SUBTYPE_DUMP 31 +#define TC_SUBTYPE_ENTER 41 +#define TC_SUBTYPE_UPDT_INFO 51 +#define TC_SUBTYPE_EN_CAL 61 +#define TC_SUBTYPE_DIS_CAL 63 +#define TC_SUBTYPE_UPDT_TIME 129 + +// TC LEN +#define TC_LEN_RESET 12 +#define TC_LEN_LOAD_COMM 14 +#define TC_LEN_LOAD_NORM 22 +#define TC_LEN_LOAD_BURST 14 +#define TC_LEN_LOAD_SBM1 14 +#define TC_LEN_LOAD_SBM2 14 +#define TC_LEN_DUMP 12 +#define TC_LEN_ENTER 20 +#define TC_LEN_UPDT_INFO 46 +#define TC_LEN_EN_CAL 12 +#define TC_LEN_DIS_CAL 12 +#define TC_LEN_UPDT_TIME 18 + +// TM TYPES +#define TM_TYPE_TC_EXE 1 +#define TM_TYPE_HK 3 +#define TM_TYPE_PARAMETER_DUMP 3 +#define TM_TYPE_LFR_SCIENCE 21 + +// TM SUBTYPES +#define TM_SUBTYPE_EXE_OK 7 +#define TM_SUBTYPE_EXE_NOK 8 +#define TM_SUBTYPE_HK 25 +#define TM_SUBTYPE_PARAMETER_DUMP 25 +#define TM_SUBTYPE_SCIENCE 3 +#define TM_SUBTYPE_LFR_SCIENCE 3 + +// FAILURE CODES +#define ILLEGAL_APID 0 +#define WRONG_LEN_PKT 1 +#define INCOR_CHECKSUM 2 +#define ILL_TYPE 3 +#define ILL_SUBTYPE 4 +#define WRONG_APP_DATA 5 // 0x00 0x05 +#define TC_NOT_EXE 42000 // 0xa4 0x10 +#define WRONG_SRC_ID 42001 // 0xa4 0x11 +#define FUNCT_NOT_IMPL 42002 // 0xa4 0x12 +#define FAIL_DETECTED 42003 // 0xa4 0x13 +#define NOT_ALLOWED 42004 // 0xa4 0x14 +#define CORRUPTED 42005 // 0xa4 0x15 +#define CCSDS_TM_VALID 7 + +// TC SID +#define SID_TC_GROUND 0 +#define SID_TC_MISSION_TIMELINE 110 +#define SID_TC_TC_SEQUENCES 111 +#define SID_TC_RECOVERY_ACTION_CMD 112 +#define SID_TC_BACKUP_MISSION_TIMELINE 113 +#define SID_TC_DIRECT_CMD 120 +#define SID_TC_SPARE_GRD_SRC1 121 +#define SID_TC_SPARE_GRD_SRC2 122 +#define SID_TC_OBCP 15 +#define SID_TC_SYSTEM_CONTROL 14 +#define SID_TC_AOCS 11 +#define SID_TC_RPW_INTERNAL 254 + +enum apid_destid{ + GROUND, + MISSION_TIMELINE, + TC_SEQUENCES, + RECOVERY_ACTION_CMD, + BACKUP_MISSION_TIMELINE, + DIRECT_CMD, + SPARE_GRD_SRC1, + SPARE_GRD_SRC2, + OBCP, + SYSTEM_CONTROL, + AOCS, + RPW_INTERNAL +}; +// SEQUENCE COUNTERS +#define SEQ_CNT_MAX 16383 +#define SEQ_CNT_NB_DEST_ID 12 + +// TM SID +#define SID_HK 1 +#define SID_PARAMETER_DUMP 10 + +#define SID_NORM_SWF_F0 3 +#define SID_NORM_SWF_F1 4 +#define SID_NORM_SWF_F2 5 +#define SID_NORM_CWF_F3 1 +#define SID_BURST_CWF_F2 2 +#define SID_SBM1_CWF_F1 24 +#define SID_SBM2_CWF_F2 25 +#define SID_NORM_ASM_F0 11 +#define SID_NORM_ASM_F1 12 +#define SID_NORM_ASM_F2 13 +#define SID_NORM_BP1_F0 14 +#define SID_NORM_BP1_F1 15 +#define SID_NORM_BP1_F2 16 +#define SID_NORM_BP2_F0 19 +#define SID_NORM_BP2_F1 20 +#define SID_NORM_BP2_F2 21 +#define SID_BURST_BP1_F0 17 +#define SID_BURST_BP2_F0 22 +#define SID_BURST_BP1_F1 18 +#define SID_BURST_BP2_F1 23 +#define SID_SBM1_BP1_F0 28 +#define SID_SBM1_BP2_F0 31 +#define SID_SBM2_BP1_F0 29 +#define SID_SBM2_BP2_F0 32 +#define SID_SBM2_BP1_F1 30 +#define SID_SBM2_BP2_F1 33 +#define SID_NORM_CWF_LONG_F3 34 + +// LENGTH (BYTES) +#define LENGTH_TM_LFR_TC_EXE_MAX 32 +#define LENGTH_TM_LFR_HK 126 + +// HEADER_LENGTH +#define TM_HEADER_LEN 16 +#define HEADER_LENGTH_TM_LFR_SCIENCE_ASM 28 +// PACKET_LENGTH +#define PACKET_LENGTH_TC_EXE_SUCCESS (20 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_EXE_INCONSISTENT (26 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE (26 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED (24 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_EXE_ERROR (24 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TC_EXE_CORRUPTED (32 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_HK (124 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_PARAMETER_DUMP (36 - CCSDS_TC_TM_PACKET_OFFSET) +#define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0 (2228 - CCSDS_TC_TM_PACKET_OFFSET) // 44 * 25 * 2 + 28 +#define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1 (2628 - CCSDS_TC_TM_PACKET_OFFSET) // 52 * 25 * 2 + 28 +#define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2 (2428 - CCSDS_TC_TM_PACKET_OFFSET) // 48 * 25 * 2 + 28 +#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 (126 - CCSDS_TC_TM_PACKET_OFFSET) // 11 * 9 + 27 (1 spare bit in the header) +#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 (356 - CCSDS_TC_TM_PACKET_OFFSET) // 11 * 30 + 26 +#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 (144 - CCSDS_TC_TM_PACKET_OFFSET) // 13 * 9 + 27 (1 spare bit in the header) +#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 (416 - CCSDS_TC_TM_PACKET_OFFSET) // 13 * 30 + 26 +#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 (134 - CCSDS_TC_TM_PACKET_OFFSET) // 12 * 9 + 26 +#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 (386 - CCSDS_TC_TM_PACKET_OFFSET) // 12 * 30 + 26 +#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 (224 - CCSDS_TC_TM_PACKET_OFFSET) // 22 * 9 + 26 +#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 (686 - CCSDS_TC_TM_PACKET_OFFSET) // 22 * 30 + 26 +#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 (260 - CCSDS_TC_TM_PACKET_OFFSET) // 26 * 9 + 26 +#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 (806 - CCSDS_TC_TM_PACKET_OFFSET) // 26 * 30 + 26 + +#define PACKET_LENGTH_DELTA 11 // 7 + 4 + +#define SPARE1_PUSVERSION_SPARE2 0x10 + +// R1 +#define TM_LEN_SCI_SWF_340 4101 // 340 * 12 + 10 + 12 - 1 +#define TM_LEN_SCI_SWF_8 117 // 8 * 12 + 10 + 12 - 1 +#define TM_LEN_SCI_CWF_340 4099 // 340 * 12 + 10 + 10 - 1 +#define TM_LEN_SCI_CWF_8 115 // 8 * 12 + 10 + 10 - 1 +#define TM_LEN_SCI_CWF3_LIGHT_340 2059 // 340 * 6 + 10 + 10 - 1 +#define TM_LEN_SCI_CWF3_LIGHT_8 67 // 8 * 6 + 10 + 10 - 1 +// R2 +#define TM_LEN_SCI_SWF_304 3669 // 304 * 12 + 10 + 12 - 1 +#define TM_LEN_SCI_SWF_224 2709 // 224 * 12 + 10 + 12 - 1 +#define TM_LEN_SCI_CWF_336 4051 // 336 * 12 + 10 + 10 - 1 +#define TM_LEN_SCI_CWF_672 4051 // 672 * 6 + 10 + 10 - 1 +// +#define DEFAULT_PKTCNT 0x07 +#define BLK_NR_304 0x0130 +#define BLK_NR_224 0x00e0 +#define BLK_NR_CWF 0x0150 // 336 +#define BLK_NR_CWF_SHORT_F3 0x02a0 // 672 + +enum TM_TYPE{ + TM_LFR_TC_EXE_OK, + TM_LFR_TC_EXE_ERR, + TM_LFR_HK, + TM_LFR_SCI, + TM_LFR_SCI_SBM, + TM_LFR_PAR_DUMP +}; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // PACKET HEADER + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // + unsigned char telecommand_pkt_id[2]; + unsigned char pkt_seq_control[2]; +} Packet_TM_LFR_TC_EXE_SUCCESS_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // PACKET HEADER + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // + unsigned char tc_failure_code[2]; + unsigned char telecommand_pkt_id[2]; + unsigned char pkt_seq_control[2]; + unsigned char tc_service; + unsigned char tc_subtype; + unsigned char byte_position; + unsigned char rcv_value; +} Packet_TM_LFR_TC_EXE_INCONSISTENT_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // PACKET HEADER + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // + unsigned char tc_failure_code[2]; + unsigned char telecommand_pkt_id[2]; + unsigned char pkt_seq_control[2]; + unsigned char tc_service; + unsigned char tc_subtype; + unsigned char lfr_status_word[2]; +} Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // PACKET HEADER + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // + unsigned char tc_failure_code[2]; + unsigned char telecommand_pkt_id[2]; + unsigned char pkt_seq_control[2]; + unsigned char tc_service; + unsigned char tc_subtype; +} Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // PACKET HEADER + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // + unsigned char tc_failure_code[2]; + unsigned char telecommand_pkt_id[2]; + unsigned char pkt_seq_control[2]; + unsigned char tc_service; + unsigned char tc_subtype; +} Packet_TM_LFR_TC_EXE_ERROR_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // PACKET HEADER + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // + unsigned char tc_failure_code[2]; + unsigned char telecommand_pkt_id[2]; + unsigned char pkt_seq_control[2]; + unsigned char tc_service; + unsigned char tc_subtype; + unsigned char pkt_len_rcv_value[2]; + unsigned char pkt_datafieldsize_cnt[2]; + unsigned char rcv_crc[2]; + unsigned char computed_crc[2]; +} Packet_TM_LFR_TC_EXE_CORRUPTED_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // AUXILIARY HEADER + unsigned char sid; + unsigned char hkBIA; + unsigned char pktCnt; + unsigned char pktNr; + unsigned char acquisitionTime[6]; + unsigned char blkNr[2]; +} Header_TM_LFR_SCIENCE_SWF_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // AUXILIARY DATA HEADER + unsigned char sid; + unsigned char hkBIA; + unsigned char acquisitionTime[6]; + unsigned char blkNr[2]; +} Header_TM_LFR_SCIENCE_CWF_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // AUXILIARY HEADER + unsigned char sid; + unsigned char biaStatusInfo; + unsigned char pa_lfr_pkt_cnt_asm; + unsigned char pa_lfr_pkt_nr_asm; + unsigned char acquisitionTime[6]; + unsigned char pa_lfr_asm_blk_nr[2]; +} Header_TM_LFR_SCIENCE_ASM_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // AUXILIARY HEADER + unsigned char sid; + unsigned char biaStatusInfo; + unsigned char acquisitionTime[6]; + unsigned char source_data_spare; + unsigned char pa_lfr_bp_blk_nr[2]; +} Header_TM_LFR_SCIENCE_BP_with_spare_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + // AUXILIARY HEADER + unsigned char sid; + unsigned char biaStatusInfo; + unsigned char acquisitionTime[6]; + unsigned char pa_lfr_bp_blk_nr[2]; +} Header_TM_LFR_SCIENCE_BP_t; + +typedef struct { + //targetLogicalAddress is removed by the grspw module + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char headerFlag_pusVersion_Ack; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char sourceID; + unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10]; +} ccsdsTelecommandPacket_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + unsigned char sid; + + //************** + // HK PARAMETERS + unsigned char lfr_status_word[2]; + unsigned char lfr_sw_version[4]; + unsigned char lfr_fpga_version[3]; + // ressource statistics + unsigned char hk_lfr_cpu_load; + unsigned char hk_lfr_cpu_load_max; + unsigned char hk_lfr_cpu_load_aver; + // tc statistics + unsigned char hk_lfr_update_info_tc_cnt[2]; + unsigned char hk_lfr_update_time_tc_cnt[2]; + unsigned char hk_lfr_exe_tc_cnt[2]; + unsigned char hk_lfr_rej_tc_cnt[2]; + unsigned char hk_lfr_last_exe_tc_id[2]; + unsigned char hk_lfr_last_exe_tc_type[2]; + unsigned char hk_lfr_last_exe_tc_subtype[2]; + unsigned char hk_lfr_last_exe_tc_time[6]; + unsigned char hk_lfr_last_rej_tc_id[2]; + unsigned char hk_lfr_last_rej_tc_type[2]; + unsigned char hk_lfr_last_rej_tc_subtype[2]; + unsigned char hk_lfr_last_rej_tc_time[6]; + // anomaly statistics + unsigned char hk_lfr_le_cnt[2]; + unsigned char hk_lfr_me_cnt[2]; + unsigned char hk_lfr_he_cnt[2]; + unsigned char hk_lfr_last_er_rid[2]; + unsigned char hk_lfr_last_er_code; + unsigned char hk_lfr_last_er_time[6]; + // vhdl_blk_status + unsigned char hk_lfr_vhdl_aa_sm; + unsigned char hk_lfr_vhdl_fft_sr; + unsigned char hk_lfr_vhdl_cic_hk; + unsigned char hk_lfr_vhdl_iir_cal; + // spacewire_if_statistics + unsigned char hk_lfr_dpu_spw_pkt_rcv_cnt[2]; + unsigned char hk_lfr_dpu_spw_pkt_sent_cnt[2]; + unsigned char hk_lfr_dpu_spw_tick_out_cnt; + unsigned char hk_lfr_dpu_spw_last_timc; + // ahb error statistics + unsigned char hk_lfr_last_fail_addr[4]; + // temperatures + unsigned char hk_lfr_temp_scm[2]; + unsigned char hk_lfr_temp_pcb[2]; + unsigned char hk_lfr_temp_fpga[2]; + // spacecraft potential + unsigned char hk_lfr_sc_v_f3[2]; + unsigned char hk_lfr_sc_e1_f3[2]; + unsigned char hk_lfr_sc_e2_f3[2]; + // error counters + unsigned char hk_lfr_dpu_spw_parity; + unsigned char hk_lfr_dpu_spw_disconnect; + unsigned char hk_lfr_dpu_spw_escape; + unsigned char hk_lfr_dpu_spw_credit; + unsigned char hk_lfr_dpu_spw_write_sync; + unsigned char hk_lfr_dpu_spw_rx_ahb; + unsigned char hk_lfr_dpu_spw_tx_ahb; + unsigned char hk_lfr_dpu_spw_early_eop; + unsigned char hk_lfr_dpu_spw_invalid_addr; + unsigned char hk_lfr_dpu_spw_eep; + unsigned char hk_lfr_dpu_spw_rx_too_big; + // timecode + unsigned char hk_lfr_timecode_erroneous; + unsigned char hk_lfr_timecode_missing; + unsigned char hk_lfr_timecode_invalid; + // time + unsigned char hk_lfr_time_timecode_it; + unsigned char hk_lfr_time_not_synchro; + unsigned char hk_lfr_time_timecode_ctr; + // hk_lfr_buffer_dpu_ + unsigned char hk_lfr_buffer_dpu_tc_fifo; + unsigned char hk_lfr_buffer_dpu_tm_fifo; + // hk_lfr_ahb_ + unsigned char hk_lfr_ahb_correctable; + unsigned char hk_lfr_ahb_uncorrectable; + // spare + unsigned char parameters_spare; +} Packet_TM_LFR_HK_t; + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + unsigned char packetID[2]; + unsigned char packetSequenceControl[2]; + unsigned char packetLength[2]; + // DATA FIELD HEADER + unsigned char spare1_pusVersion_spare2; + unsigned char serviceType; + unsigned char serviceSubType; + unsigned char destinationID; + unsigned char time[6]; + unsigned char sid; + + //****************** + // COMMON PARAMETERS + unsigned char unused0; + unsigned char bw_sp0_sp1_r0_r1; + + //****************** + // NORMAL PARAMETERS + unsigned char sy_lfr_n_swf_l[2]; + unsigned char sy_lfr_n_swf_p[2]; + unsigned char sy_lfr_n_asm_p[2]; + unsigned char sy_lfr_n_bp_p0; + unsigned char sy_lfr_n_bp_p1; + unsigned char sy_lfr_n_cwf_long_f3; + unsigned char lfr_normal_parameters_spare; + + //***************** + // BURST PARAMETERS + unsigned char sy_lfr_b_bp_p0; + unsigned char sy_lfr_b_bp_p1; + + //**************** + // SBM1 PARAMETERS + unsigned char sy_lfr_s1_bp_p0; + unsigned char sy_lfr_s1_bp_p1; + + //**************** + // SBM2 PARAMETERS + unsigned char sy_lfr_s2_bp_p0; + unsigned char sy_lfr_s2_bp_p1; + + // SPARE + unsigned char source_data_spare; +} Packet_TM_LFR_PARAMETER_DUMP_t; + + +#endif // CCSDS_TYPES_H_INCLUDED diff --git a/timegen/header/fsw_init.h b/timegen/header/fsw_init.h new file mode 100644 --- /dev/null +++ b/timegen/header/fsw_init.h @@ -0,0 +1,39 @@ +#ifndef FSW_INIT_H_INCLUDED +#define FSW_INIT_H_INCLUDED + +#include +#include + +#include "fsw_params.h" +#include "fsw_misc.h" + +#include "tc_handler.h" +#include "fsw_spacewire.h" + +extern rtems_name Task_name[20]; /* array of task names */ +extern rtems_id Task_id[20]; /* array of task ids */ + +// RTEMS TASKS +rtems_task Init( rtems_task_argument argument); + +// OTHER functions +void create_names( void ); +int create_all_tasks( void ); +int start_all_tasks( void ); +// +rtems_status_code create_message_queues( void ); +rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); +rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); +// +int start_recv_send_tasks( void ); +// +void init_local_mode_parameters( void ); +void reset_local_time( void ); + +extern void rtems_cpu_usage_report( void ); +extern void rtems_cpu_usage_reset( void ); +extern void rtems_stack_checker_report_usage( void ); + +extern int sched_yield( void ); + +#endif // FSW_INIT_H_INCLUDED diff --git a/timegen/header/fsw_misc.h b/timegen/header/fsw_misc.h new file mode 100644 --- /dev/null +++ b/timegen/header/fsw_misc.h @@ -0,0 +1,45 @@ +#ifndef FSW_MISC_H_INCLUDED +#define FSW_MISC_H_INCLUDED + +#include +#include +#include + +#include "fsw_params.h" +#include "fsw_spacewire.h" +#include "lfr_cpu_usage_report.h" + +rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic +rtems_id HK_id; // id of the HK rate monotonic period + +void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, + unsigned char interrupt_level, rtems_isr (*timer_isr)() ); +void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer ); +void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer ); +void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider); + +// SERIAL LINK +int send_console_outputs_on_apbuart_port( void ); +int enable_apbuart_transmitter( void ); +void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); + +// RTEMS TASKS +rtems_task stat_task( rtems_task_argument argument ); +rtems_task hous_task( rtems_task_argument argument ); +rtems_task dumb_task( rtems_task_argument unused ); + +void init_housekeeping_parameters( void ); +void increment_seq_counter(unsigned short *packetSequenceControl); +void getTime( unsigned char *time); +unsigned long long int getTimeAsUnsignedLongLongInt( ); +void send_dumb_hk( void ); +void get_v_e1_e2_f3 (unsigned char *spacecraft_potential); +void get_cpu_load( unsigned char *resource_statistics ); + +extern int sched_yield( void ); +extern void rtems_cpu_usage_reset(); +extern ring_node *current_ring_node_f3; +extern ring_node *ring_node_to_send_cwf_f3; +extern unsigned short sequenceCounterHK; + +#endif // FSW_MISC_H_INCLUDED diff --git a/timegen/header/fsw_params.h b/timegen/header/fsw_params.h new file mode 100644 --- /dev/null +++ b/timegen/header/fsw_params.h @@ -0,0 +1,255 @@ +#ifndef FSW_PARAMS_H_INCLUDED +#define FSW_PARAMS_H_INCLUDED + +#include "grlib_regs.h" +#include "fsw_params_processing.h" +#include "fsw_params_nb_bytes.h" +#include "tm_byte_positions.h" +#include "ccsds_types.h" + +#define GRSPW_DEVICE_NAME "/dev/grspw0" +#define UART_DEVICE_NAME "/dev/console" + +typedef struct ring_node +{ + struct ring_node *previous; + int buffer_address; + struct ring_node *next; + unsigned int status; +} ring_node; + +//************************ +// flight software version +// this parameters is handled by the Qt project options + +#define NB_PACKETS_PER_GROUP_OF_CWF 8 // 8 packets containing 336 blk +#define NB_PACKETS_PER_GROUP_OF_CWF_LIGHT 4 // 4 packets containing 672 blk +#define NB_SAMPLES_PER_SNAPSHOT 2688 // 336 * 8 = 672 * 4 = 2688 +#define TIME_OFFSET 2 +#define TIME_OFFSET_IN_BYTES 8 +#define WAVEFORM_EXTENDED_HEADER_OFFSET 22 +#define NB_BYTES_SWF_BLK (2 * 6) +#define NB_WORDS_SWF_BLK 3 +#define NB_BYTES_CWF3_LIGHT_BLK 6 +#define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8 +#define NB_RING_NODES_F0 3 // AT LEAST 3 +#define NB_RING_NODES_F1 5 // AT LEAST 3 +#define NB_RING_NODES_F2 5 // AT LEAST 3 +#define NB_RING_NODES_F3 3 // AT LEAST 3 + +//********** +// LFR MODES +#define LFR_MODE_STANDBY 0 +#define LFR_MODE_NORMAL 1 +#define LFR_MODE_BURST 2 +#define LFR_MODE_SBM1 3 +#define LFR_MODE_SBM2 4 + +#define TDS_MODE_LFM 5 +#define TDS_MODE_STANDBY 0 +#define TDS_MODE_NORMAL 1 +#define TDS_MODE_BURST 2 +#define TDS_MODE_SBM1 3 +#define TDS_MODE_SBM2 4 + +#define THR_MODE_STANDBY 0 +#define THR_MODE_NORMAL 1 +#define THR_MODE_BURST 2 + +#define RTEMS_EVENT_MODE_STANDBY RTEMS_EVENT_0 +#define RTEMS_EVENT_MODE_NORMAL RTEMS_EVENT_1 +#define RTEMS_EVENT_MODE_BURST RTEMS_EVENT_2 +#define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3 +#define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4 +#define RTEMS_EVENT_MODE_SBM2_WFRM RTEMS_EVENT_5 +#define RTEMS_EVENT_NORM_BP1_F0 RTEMS_EVENT_6 +#define RTEMS_EVENT_NORM_BP2_F0 RTEMS_EVENT_7 +#define RTEMS_EVENT_NORM_ASM_F0 RTEMS_EVENT_8 // ASM only in NORM mode +#define RTEMS_EVENT_NORM_BP1_F1 RTEMS_EVENT_9 +#define RTEMS_EVENT_NORM_BP2_F1 RTEMS_EVENT_10 +#define RTEMS_EVENT_NORM_ASM_F1 RTEMS_EVENT_11 // ASM only in NORM mode +#define RTEMS_EVENT_NORM_BP1_F2 RTEMS_EVENT_12 +#define RTEMS_EVENT_NORM_BP2_F2 RTEMS_EVENT_13 +#define RTEMS_EVENT_NORM_ASM_F2 RTEMS_EVENT_14 // ASM only in NORM mode +#define RTEMS_EVENT_SBM_BP1_F0 RTEMS_EVENT_15 +#define RTEMS_EVENT_SBM_BP2_F0 RTEMS_EVENT_16 +#define RTEMS_EVENT_SBM_BP1_F1 RTEMS_EVENT_17 +#define RTEMS_EVENT_SBM_BP2_F1 RTEMS_EVENT_18 +#define RTEMS_EVENT_BURST_BP1_F0 RTEMS_EVENT_19 +#define RTEMS_EVENT_BURST_BP2_F0 RTEMS_EVENT_20 +#define RTEMS_EVENT_BURST_BP1_F1 RTEMS_EVENT_21 +#define RTEMS_EVENT_BURST_BP2_F1 RTEMS_EVENT_22 + +//**************************** +// LFR DEFAULT MODE PARAMETERS +// COMMON +#define DEFAULT_SY_LFR_COMMON0 0x00 +#define DEFAULT_SY_LFR_COMMON1 0x10 // default value 0 0 0 1 0 0 0 0 +// NORM +#define DFLT_SY_LFR_N_SWF_L 2048 // nb sample +#define DFLT_SY_LFR_N_SWF_P 300 // sec +#define DFLT_SY_LFR_N_ASM_P 3600 // sec +#define DFLT_SY_LFR_N_BP_P0 4 // sec +#define DFLT_SY_LFR_N_BP_P1 20 // sec +#define DFLT_SY_LFR_N_CWF_LONG_F3 0 // 0 => production of light continuous waveforms at f3 +#define MIN_DELTA_SNAPSHOT 16 // sec +// BURST +#define DEFAULT_SY_LFR_B_BP_P0 1 // sec +#define DEFAULT_SY_LFR_B_BP_P1 5 // sec +// SBM1 +#define DEFAULT_SY_LFR_S1_BP_P0 1 // sec +#define DEFAULT_SY_LFR_S1_BP_P1 1 // sec +// SBM2 +#define DEFAULT_SY_LFR_S2_BP_P0 1 // sec +#define DEFAULT_SY_LFR_S2_BP_P1 5 // sec +// ADDITIONAL PARAMETERS +#define TIME_BETWEEN_TWO_SWF_PACKETS 30 // nb x 10 ms => 300 ms +#define TIME_BETWEEN_TWO_CWF3_PACKETS 1000 // nb x 10 ms => 10 s +// STATUS WORD +#define DEFAULT_STATUS_WORD_BYTE0 0x0d // [0000] [1] [101] mode 4 bits / SPW enabled 1 bit / state is run 3 bits +#define DEFAULT_STATUS_WORD_BYTE1 0x00 +// +#define SY_LFR_DPU_CONNECT_TIMEOUT 100 // 100 * 10 ms = 1 s +#define SY_LFR_DPU_CONNECT_ATTEMPT 3 +//**************************** + +//***************************** +// APB REGISTERS BASE ADDRESSES +#define REGS_ADDR_APBUART 0x80000100 +#define REGS_ADDR_GPTIMER 0x80000300 +#define REGS_ADDR_GRSPW 0x80000500 +#define REGS_ADDR_TIME_MANAGEMENT 0x80000600 +#define REGS_ADDR_GRGPIO 0x80000b00 + +#define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00 +#define REGS_ADDR_WAVEFORM_PICKER 0x80000f50 +#define REGS_ADDR_VHDL_VERSION 0x80000ff0 + +#define APBUART_CTRL_REG_MASK_DB 0xfffff7ff +#define APBUART_CTRL_REG_MASK_TE 0x00000002 +#define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 (0x50) + +//********** +// IRQ LINES +#define IRQ_SM_SIMULATOR 9 +#define IRQ_SPARC_SM_SIMULATOR 0x19 // see sparcv8.pdf p.76 for interrupt levels +#define IRQ_WAVEFORM_PICKER 14 +#define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels +#define IRQ_SPECTRAL_MATRIX 6 +#define IRQ_SPARC_SPECTRAL_MATRIX 0x16 // see sparcv8.pdf p.76 for interrupt levels + +//***** +// TIME +#define CLKDIV_SM_SIMULATOR (10416 - 1) // 10 ms => nominal is 1/96 = 0.010416667, 10417 - 1 = 10416 +#define TIMER_SM_SIMULATOR 1 +#define HK_PERIOD 100 // 100 * 10ms => 1s +#define SY_LFR_TIME_SYN_TIMEOUT_in_ms 2000 +#define SY_LFR_TIME_SYN_TIMEOUT_in_ticks 200 // 200 * 10 ms = 2 s + +//********** +// LPP CODES +#define LFR_SUCCESSFUL 0 +#define LFR_DEFAULT 1 +#define LFR_EXE_ERROR 2 + +//****** +// RTEMS +#define TASKID_RECV 1 +#define TASKID_ACTN 2 +#define TASKID_SPIQ 3 +#define TASKID_STAT 4 +#define TASKID_AVF0 5 +#define TASKID_SWBD 6 +#define TASKID_WFRM 7 +#define TASKID_DUMB 8 +#define TASKID_HOUS 9 +#define TASKID_PRC0 10 +#define TASKID_CWF3 11 +#define TASKID_CWF2 12 +#define TASKID_CWF1 13 +#define TASKID_SEND 14 +#define TASKID_WTDG 15 +#define TASKID_AVF1 16 +#define TASKID_PRC1 17 +#define TASKID_AVF2 18 +#define TASKID_PRC2 19 + +#define TASK_PRIORITY_SPIQ 5 +#define TASK_PRIORITY_WTDG 20 +#define TASK_PRIORITY_HOUS 30 +#define TASK_PRIORITY_CWF1 35 // CWF1 and CWF2 are never running together +#define TASK_PRIORITY_CWF2 35 // +#define TASK_PRIORITY_SWBD 37 // SWBD has a lower priority than WFRM, this is to extract the snapshot before sending it +#define TASK_PRIORITY_WFRM 40 +#define TASK_PRIORITY_CWF3 40 // there is a printf in this function, be careful with its priority wrt CWF1 +#define TASK_PRIORITY_SEND 45 +#define TASK_PRIORITY_RECV 50 +#define TASK_PRIORITY_ACTN 50 +#define TASK_PRIORITY_AVF0 60 +#define TASK_PRIORITY_AVF1 70 +#define TASK_PRIORITY_PRC0 100 +#define TASK_PRIORITY_PRC1 100 +#define TASK_PRIORITY_AVF2 110 +#define TASK_PRIORITY_PRC2 110 +#define TASK_PRIORITY_STAT 200 +#define TASK_PRIORITY_DUMB 200 + +#define MSG_QUEUE_COUNT_RECV 10 +#define MSG_QUEUE_COUNT_SEND 50 +#define MSG_QUEUE_COUNT_PRC0 10 +#define MSG_QUEUE_COUNT_PRC1 10 +#define MSG_QUEUE_COUNT_PRC2 5 +#define MSG_QUEUE_SIZE_SEND 810 // 806 + 4 => TM_LFR_SCIENCE_BURST_BP2_F1 +#define ACTION_MSG_SPW_IOCTL_SEND_SIZE 24 // hlen *hdr dlen *data sent options +#define MSG_QUEUE_SIZE_PRC0 20 // two pointers and one rtems_event + 2 integers +#define MSG_QUEUE_SIZE_PRC1 20 // two pointers and one rtems_event + 2 integers +#define MSG_QUEUE_SIZE_PRC2 20 // two pointers and one rtems_event + 2 integers + +#define QUEUE_RECV 0 +#define QUEUE_SEND 1 +#define QUEUE_PRC0 2 +#define QUEUE_PRC1 3 +#define QUEUE_PRC2 4 + +//******* +// MACROS +#ifdef PRINT_MESSAGES_ON_CONSOLE +#define PRINTF(x) printf(x); +#define PRINTF1(x,y) printf(x,y); +#define PRINTF2(x,y,z) printf(x,y,z); +#else +#define PRINTF(x) ; +#define PRINTF1(x,y) ; +#define PRINTF2(x,y,z) ; +#endif + +#ifdef BOOT_MESSAGES +#define BOOT_PRINTF(x) printf(x); +#define BOOT_PRINTF1(x,y) printf(x,y); +#define BOOT_PRINTF2(x,y,z) printf(x,y,z); +#else +#define BOOT_PRINTF(x) ; +#define BOOT_PRINTF1(x,y) ; +#define BOOT_PRINTF2(x,y,z) ; +#endif + +#ifdef DEBUG_MESSAGES +#define DEBUG_PRINTF(x) printf(x); +#define DEBUG_PRINTF1(x,y) printf(x,y); +#define DEBUG_PRINTF2(x,y,z) printf(x,y,z); +#else +#define DEBUG_PRINTF(x) ; +#define DEBUG_PRINTF1(x,y) ; +#define DEBUG_PRINTF2(x,y,z) ; +#endif + +#define CPU_USAGE_REPORT_PERIOD 6 // * 10 s = period + +struct param_local_str{ + unsigned int local_sbm1_nb_cwf_sent; + unsigned int local_sbm1_nb_cwf_max; + unsigned int local_sbm2_nb_cwf_sent; + unsigned int local_sbm2_nb_cwf_max; +}; + +#endif // FSW_PARAMS_H_INCLUDED diff --git a/timegen/header/fsw_params_nb_bytes.h b/timegen/header/fsw_params_nb_bytes.h new file mode 100644 --- /dev/null +++ b/timegen/header/fsw_params_nb_bytes.h @@ -0,0 +1,37 @@ +#ifndef TM_BYTE_POSITIONS_H +#define TM_BYTE_POSITIONS_H + +// SEQUENCE_CNT +#define PACKET_POS_SEQUENCE_CNT 6 // 4 + 2 + +// TC_LFR_LOAD_COMMON_PAR + +// TC_LFR_LOAD_NORMAL_PAR +#define DATAFIELD_POS_SY_LFR_N_SWF_L 0 +#define DATAFIELD_POS_SY_LFR_N_SWF_P 2 +#define DATAFIELD_POS_SY_LFR_N_ASM_P 4 +#define DATAFIELD_POS_SY_LFR_N_BP_P0 6 +#define DATAFIELD_POS_SY_LFR_N_BP_P1 7 +#define DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 8 + +// TC_LFR_LOAD_BURST_PAR +#define DATAFIELD_POS_SY_LFR_B_BP_P0 0 +#define DATAFIELD_POS_SY_LFR_B_BP_P1 1 + +// TC_LFR_LOAD_SBM1_PAR +#define DATAFIELD_POS_SY_LFR_S1_BP_P0 0 +#define DATAFIELD_POS_SY_LFR_S1_BP_P1 1 + +// TC_LFR_LOAD_SBM2_PAR +#define DATAFIELD_POS_SY_LFR_S2_BP_P0 0 +#define DATAFIELD_POS_SY_LFR_S2_BP_P1 1 + +// TC_LFR_UPDATE_INFO +#define BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 34 +#define BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 35 + +// TC_LFR_ENTER_MODE +#define BYTE_POS_CP_MODE_LFR_SET 11 +#define BYTE_POS_CP_LFR_ENTER_MODE_TIME 12 + +#endif // TM_BYTE_POSITIONS_H diff --git a/timegen/header/fsw_params_processing.h b/timegen/header/fsw_params_processing.h new file mode 100644 --- /dev/null +++ b/timegen/header/fsw_params_processing.h @@ -0,0 +1,70 @@ +#ifndef FSW_PARAMS_PROCESSING_H +#define FSW_PARAMS_PROCESSING_H + +#define NB_BINS_PER_SM 128 +#define NB_VALUES_PER_SM 25 +#define TOTAL_SIZE_SM 3200 // 25 * 128 = 0xC80 +#define TOTAL_SIZE_NORM_BP1_F0 99 // 11 * 9 = 99 +#define TOTAL_SIZE_NORM_BP1_F1 117 // 13 * 9 = 117 +#define TOTAL_SIZE_NORM_BP1_F2 108 // 12 * 9 = 108 +#define TOTAL_SIZE_SBM1_BP1_F0 198 // 22 * 9 = 198 +// +#define NB_RING_NODES_SM_F0 12 // AT LEAST 3 +#define NB_RING_NODES_ASM_BURST_SBM_F0 10 // AT LEAST 3 +#define NB_RING_NODES_ASM_NORM_F0 10 // AT LEAST 3 +#define NB_RING_NODES_SM_F1 3 // AT LEAST 3 +#define NB_RING_NODES_ASM_BURST_SBM_F1 5 // AT LEAST 3 +#define NB_RING_NODES_ASM_NORM_F1 5 // AT LEAST 3 +#define NB_RING_NODES_SM_F2 3 // AT LEAST 3 +#define NB_RING_NODES_ASM_BURST_SBM_F2 3 // AT LEAST 3 +#define NB_RING_NODES_ASM_NORM_F2 3 // AT LEAST 3 +// +#define NB_BINS_PER_ASM_F0 88 +#define NB_BINS_PER_PKT_ASM_F0 44 +#define TOTAL_SIZE_ASM_F0_IN_BYTES 4400 // 25 * 88 * 2 +#define ASM_F0_INDICE_START 17 // 88 bins +#define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins +// +#define NB_BINS_PER_ASM_F1 104 +#define NB_BINS_PER_PKT_ASM_F1 52 +#define TOTAL_SIZE_ASM_F1_IN_BYTES 5200 // 25 * 104 * 2 +#define ASM_F1_INDICE_START 6 // 104 bins +#define ASM_F1_INDICE_STOP 109 // 2 packets of 52 bins +// +#define NB_BINS_PER_ASM_F2 96 +#define NB_BINS_PER_PKT_ASM_F2 48 +#define TOTAL_SIZE_ASM_F2_IN_BYTES 4800 // 25 * 96 * 2 +#define ASM_F2_INDICE_START 7 // 96 bins +#define ASM_F2_INDICE_STOP 102 // 2 packets of 48 bins +// +#define NB_BINS_COMPRESSED_SM_F0 11 +#define NB_BINS_COMPRESSED_SM_F1 13 +#define NB_BINS_COMPRESSED_SM_F2 12 +#define NB_BINS_COMPRESSED_SM_SBM_F0 22 +#define NB_BINS_COMPRESSED_SM_SBM_F1 26 +#define NB_BINS_COMPRESSED_SM_SBM_F2 24 +// +#define NB_BYTES_PER_BP1 9 +// +#define NB_BINS_TO_AVERAGE_ASM_F0 8 +#define NB_BINS_TO_AVERAGE_ASM_F1 8 +#define NB_BINS_TO_AVERAGE_ASM_F2 8 +#define NB_BINS_TO_AVERAGE_ASM_SBM_F0 4 +#define NB_BINS_TO_AVERAGE_ASM_SBM_F1 4 +#define NB_BINS_TO_AVERAGE_ASM_SBM_F2 4 +// +#define TOTAL_SIZE_COMPRESSED_ASM_NORM_F0 275 // 11 * 25 WORDS +#define TOTAL_SIZE_COMPRESSED_ASM_NORM_F1 325 // 13 * 25 WORDS +#define TOTAL_SIZE_COMPRESSED_ASM_NORM_F2 300 // 12 * 25 WORDS +#define TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 550 // 22 * 25 WORDS +#define TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 650 // 26 * 25 WORDS +#define TOTAL_SIZE_COMPRESSED_ASM_SBM_F2 600 // 24 * 25 WORDS +#define TOTAL_SIZE_BP1_NORM_F0 99 // 9 * 11 UNSIGNED CHAR +#define TOTAL_SIZE_BP1_SBM_F0 198 // 9 * 22 UNSIGNED CHAR +// GENERAL +#define NB_SM_BEFORE_AVF0 8 // must be 8 due to the SM_average() function +#define NB_SM_BEFORE_AVF1 8 // must be 8 due to the SM_average() function +#define NB_SM_BEFORE_AVF2 1 // must be 1 due to the SM_average_f2() function + +#endif // FSW_PARAMS_PROCESSING_H + diff --git a/timegen/header/fsw_params_wf_handler.h b/timegen/header/fsw_params_wf_handler.h new file mode 100644 --- /dev/null +++ b/timegen/header/fsw_params_wf_handler.h @@ -0,0 +1,8 @@ +#ifndef FSW_PARAMS_WF_HANDLER_H +#define FSW_PARAMS_WF_HANDLER_H + +#define WFRM_BUFFER 8128 // (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 62 + // (2688 * 3 ) + 2 + 62 = 8128 = 0X1FC0 + // 8128 * 4 = 32512 = 0x7F00 + +#endif // FSW_PARAMS_WF_HANDLER_H diff --git a/timegen/header/fsw_spacewire.h b/timegen/header/fsw_spacewire.h new file mode 100644 --- /dev/null +++ b/timegen/header/fsw_spacewire.h @@ -0,0 +1,53 @@ +#ifndef FSW_SPACEWIRE_H_INCLUDED +#define FSW_SPACEWIRE_H_INCLUDED + +#include +#include + +#include // for O_RDWR +#include // for the read call +#include // for the ioctl call +#include + +#include "fsw_params.h" +#include "tc_handler.h" +#include "TC_types.h" + +extern spw_stats spacewire_stats; +extern spw_stats spacewire_stats_backup; +extern rtems_id rtems_task_id_updt; + +void resetLocalCoarseTime(); +void setLocalCoarseTime( unsigned int value ); +unsigned int getLocalCoarseTime(); +void incrementLocalCoarseTime(); + +// TC_LFR_UPDATE_TIME +void initLookUpTableForCRC( void ); +void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData); +unsigned int Crc_opt( unsigned char D, unsigned int Chk); +void updateTimePacket(unsigned int time, Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t *packet); + +// RTEMS TASK +rtems_task spiq_task( rtems_task_argument argument ); +rtems_task recv_task( rtems_task_argument unused ); +rtems_task send_task( rtems_task_argument argument ); +rtems_task wtdg_task( rtems_task_argument argument ); +rtems_task updt_task( rtems_task_argument unused ); + +int spacewire_open_link( void ); +int spacewire_start_link( int fd ); +int spacewire_stop_and_start_link( int fd ); +int spacewire_configure_link(int fd ); +int spacewire_reset_link( void ); +void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force +void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable +void spacewire_compute_stats_offsets( void ); +void spacewire_update_statistics( void ); + +void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ); +rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ); + +void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc ); + +#endif // FSW_SPACEWIRE_H_INCLUDED diff --git a/timegen/header/grlib_regs.h b/timegen/header/grlib_regs.h new file mode 100644 --- /dev/null +++ b/timegen/header/grlib_regs.h @@ -0,0 +1,109 @@ +#ifndef GRLIB_REGS_H_INCLUDED +#define GRLIB_REGS_H_INCLUDED + +#define NB_GPTIMER 3 + +struct apbuart_regs_str{ + volatile unsigned int data; + volatile unsigned int status; + volatile unsigned int ctrl; + volatile unsigned int scaler; + volatile unsigned int fifoDebug; +}; + +struct grgpio_regs_str{ + volatile int io_port_data_register; + int io_port_output_register; + int io_port_direction_register; + int interrupt_mak_register; + int interrupt_polarity_register; + int interrupt_edge_register; + int bypass_register; + int reserved; + // 0x20-0x3c interrupt map register(s) +}; + +typedef struct { + volatile unsigned int counter; + volatile unsigned int reload; + volatile unsigned int ctrl; + volatile unsigned int unused; +} timer_regs_t; + +typedef struct { + volatile unsigned int scaler_value; + volatile unsigned int scaler_reload; + volatile unsigned int conf; + volatile unsigned int unused0; + timer_regs_t timer[NB_GPTIMER]; +} gptimer_regs_t; + +typedef struct { + volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time + volatile int coarse_time_load; + volatile int coarse_time; + volatile int fine_time; +} time_management_regs_t; + +typedef struct { + volatile int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW + volatile int burst_enable; // 0x04 01 *** burst f2, f1, f0 enable f3, f2, f1, f0 + volatile int addr_data_f0; // 0x08 10 *** + volatile int addr_data_f1; // 0x0c 11 *** + volatile int addr_data_f2; // 0x10 100 *** + volatile int addr_data_f3; // 0x14 101 *** + volatile int status; // 0x18 110 *** + volatile int delta_snapshot; // 0x1c 111 *** + volatile int delta_f2_f1; // 0x20 0000 *** + volatile int delta_f2_f0; // 0x24 0001 *** + volatile int nb_burst_available;// 0x28 0010 *** + volatile int nb_snapshot_param; // 0x2c 0011 *** +} waveform_picker_regs_t; + +typedef struct{ + int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW + int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] + int addr_data_f0; // 0x08 + int addr_data_f1; // 0x0c + int addr_data_f2; // 0x10 + int addr_data_f3; // 0x14 + volatile int status; // 0x18 + int delta_snapshot; // 0x1c + int delta_f0; // 0x20 + int delta_f0_2; // 0x24 + int delta_f1; // 0x28 + int delta_f2; // 0x2c + int nb_data_by_buffer; // 0x30 + int snapshot_param; // 0x34 + int start_date; // 0x38 + int nb_word_in_buffer; // 0x3c +} waveform_picker_regs_new_t; + +typedef struct { + volatile int config; // 0x00 + volatile int status; // 0x04 + volatile int f0_0_address; // 0x08 + volatile int f0_1_address; // 0x0C + // + volatile int f1_0_address; // 0x10 + volatile int f1_1_address; // 0x14 + volatile int f2_0_address; // 0x18 + volatile int f2_1_address; // 0x1C + // + volatile unsigned int f0_0_coarse_time; // 0x20 + volatile unsigned int f0_0_fine_time; // 0x24 + volatile unsigned int f0_1_coarse_time; // 0x28 + volatile unsigned int f0_1_fine_time; // 0x2C + // + volatile unsigned int f1_0_coarse_time; // 0x30 + volatile unsigned int f1_0_fine_time; // 0x34 + volatile unsigned int f1_1_coarse_time; // 0x38 + volatile unsigned int f1_1_time_time; // 0x3C + // + volatile unsigned int f2_0_coarse_time; // 0x40 + volatile unsigned int f2_0_fine_time; // 0x44 + volatile unsigned int f2_1_coarse_time; // 0x48 + volatile unsigned int f2_1_fine_time; // 0x4C +} spectral_matrix_regs_t; + +#endif // GRLIB_REGS_H_INCLUDED diff --git a/timegen/header/lfr_cpu_usage_report.h b/timegen/header/lfr_cpu_usage_report.h new file mode 100644 --- /dev/null +++ b/timegen/header/lfr_cpu_usage_report.h @@ -0,0 +1,32 @@ +#ifndef LFR_CPU_USAGE_REPORT_H +#define LFR_CPU_USAGE_REPORT_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ + #include +#endif + +#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ + extern Timestamp_Control CPU_usage_Uptime_at_last_reset; +#else + extern uint32_t CPU_usage_Ticks_at_last_reset; +#endif + +unsigned char lfr_rtems_cpu_usage_report( void ); + +#endif // LFR_CPU_USAGE_REPORT_H diff --git a/timegen/header/processing/avf0_prc0.h b/timegen/header/processing/avf0_prc0.h new file mode 100644 --- /dev/null +++ b/timegen/header/processing/avf0_prc0.h @@ -0,0 +1,36 @@ +#ifndef AVF0_PRC0_H_INCLUDED +#define AVF0_PRC0_H_INCLUDED + +#include "fsw_processing.h" +#include "basic_parameters.h" + +typedef struct { + unsigned int norm_bp1; + unsigned int norm_bp2; + unsigned int norm_asm; + unsigned int burst_sbm_bp1; + unsigned int burst_sbm_bp2; + unsigned int burst_bp1; + unsigned int burst_bp2; + unsigned int sbm1_bp1; + unsigned int sbm1_bp2; + unsigned int sbm2_bp1; + unsigned int sbm2_bp2; +} nb_sm_before_bp_asm_f0; + +//************ +// RTEMS TASKS +rtems_task avf0_task( rtems_task_argument lfrRequestedMode ); +rtems_task prc0_task( rtems_task_argument lfrRequestedMode ); + +//********** +// FUNCTIONS + +void reset_nb_sm_f0( unsigned char lfrMode ); + +//******* +// EXTERN +extern ring_node_sm *ring_node_for_averaging_sm_f0; +extern rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id ); + +#endif // AVF0_PRC0_H_INCLUDED diff --git a/timegen/header/processing/avf1_prc1.h b/timegen/header/processing/avf1_prc1.h new file mode 100644 --- /dev/null +++ b/timegen/header/processing/avf1_prc1.h @@ -0,0 +1,33 @@ +#ifndef AVF1_PRC1_H +#define AVF1_PRC1_H + +#include "fsw_processing.h" + +typedef struct { + unsigned int norm_bp1; + unsigned int norm_bp2; + unsigned int norm_asm; + unsigned int burst_sbm_bp1; + unsigned int burst_sbm_bp2; + unsigned int burst_bp1; + unsigned int burst_bp2; + unsigned int sbm2_bp1; + unsigned int sbm2_bp2; +} nb_sm_before_bp_asm_f1; + +//************ +// RTEMS TASKS +rtems_task avf1_task( rtems_task_argument lfrRequestedMode ); +rtems_task prc1_task( rtems_task_argument lfrRequestedMode ); + +//********** +// FUNCTIONS + +void reset_nb_sm_f1( unsigned char lfrMode ); + +//******* +// EXTERN +extern struct ring_node_sm *ring_node_for_averaging_sm_f1; +extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ); + +#endif // AVF1_PRC1_H diff --git a/timegen/header/processing/avf2_prc2.h b/timegen/header/processing/avf2_prc2.h new file mode 100644 --- /dev/null +++ b/timegen/header/processing/avf2_prc2.h @@ -0,0 +1,28 @@ +#ifndef AVF2_PRC2_H +#define AVF2_PRC2_H + +#include "fsw_processing.h" + +typedef struct { + unsigned int norm_bp1; + unsigned int norm_bp2; + unsigned int norm_asm; +} nb_sm_before_bp_asm_f2; + +//************ +// RTEMS TASKS +rtems_task avf2_task( rtems_task_argument lfrRequestedMode ); +rtems_task prc2_task( rtems_task_argument lfrRequestedMode ); + +//********** +// FUNCTIONS + +void reset_nb_sm_f2( void ); +void SM_average_f2( float *averaged_spec_mat_f2, ring_node_sm *ring_node, unsigned int nbAverageNormF2 ); + +//******* +// EXTERN +extern struct ring_node_sm *ring_node_for_averaging_sm_f2; +extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ); + +#endif // AVF2_PRC2_H diff --git a/timegen/header/processing/fsw_processing.h b/timegen/header/processing/fsw_processing.h new file mode 100644 --- /dev/null +++ b/timegen/header/processing/fsw_processing.h @@ -0,0 +1,243 @@ +#ifndef FSW_PROCESSING_H_INCLUDED +#define FSW_PROCESSING_H_INCLUDED + +#include +#include +#include +#include // abs() is in the stdlib +#include // printf() +#include + +#include "fsw_params.h" +#include "fsw_spacewire.h" + +typedef struct ring_node_sm +{ + struct ring_node_sm *previous; + struct ring_node_sm *next; + int buffer_address; + unsigned int status; + unsigned int coarseTime; + unsigned int fineTime; +} ring_node_sm; + +typedef struct ring_node_asm +{ + struct ring_node_asm *next; + float matrix[ TOTAL_SIZE_SM ]; + unsigned int status; +} ring_node_asm; + +typedef struct +{ + Header_TM_LFR_SCIENCE_BP_t header; + unsigned char data[ 30 * 22 ]; // MAX size is 22 * 30 [TM_LFR_SCIENCE_BURST_BP2_F1] +} bp_packet; + +typedef struct +{ + Header_TM_LFR_SCIENCE_BP_with_spare_t header; + unsigned char data[ 9 * 13 ]; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1 +} bp_packet_with_spare; + +typedef struct +{ + ring_node_asm *norm; + ring_node_asm *burst_sbm; + rtems_event_set event; + unsigned int coarseTime; + unsigned int fineTime; +} asm_msg; + +extern volatile int sm_f0[ ]; +extern volatile int sm_f1[ ]; +extern volatile int sm_f2[ ]; + +// parameters +extern struct param_local_str param_local; + +// registers +extern time_management_regs_t *time_management_regs; +extern spectral_matrix_regs_t *spectral_matrix_regs; + +extern rtems_name misc_name[5]; +extern rtems_id Task_id[20]; /* array of task ids */ + +// ISR +rtems_isr spectral_matrices_isr( rtems_vector_number vector ); +rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector ); + +//****************** +// Spectral Matrices +void reset_nb_sm( void ); +// SM +void SM_init_rings( void ); +void SM_reset_current_ring_nodes( void ); +void SM_generic_init_ring(ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] ); +// ASM +void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes ); +void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header); +void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix, + unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id); + +//***************** +// Basic Parameters + +void BP_reset_current_ring_nodes( void ); +void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header, + unsigned int apid, unsigned char sid, + unsigned int packetLength , unsigned char blkNr); +void BP_init_header_with_spare( Header_TM_LFR_SCIENCE_BP_with_spare_t *header, + unsigned int apid, unsigned char sid, + unsigned int packetLength, unsigned char blkNr ); +void BP_send( char *data, + rtems_id queue_id , + unsigned int nbBytesToSend , unsigned int sid ); + +//****************** +// general functions +void reset_spectral_matrix_regs( void ); +void set_time(unsigned char *time, unsigned char *timeInBuffer ); +unsigned long long int get_acquisition_time( unsigned char *timePtr ); +void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id, + ring_node_sm *node_for_averaging, ring_node_sm *ringNode, unsigned long long int time); +unsigned char getSID( rtems_event_set event ); + +extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ); +extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ); + +//*************************************** +// DEFINITIONS OF STATIC INLINE FUNCTIONS +static inline void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, + ring_node_sm *ring_node_tab[], + unsigned int nbAverageNORM, unsigned int nbAverageSBM ); +static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized, + float divider ); +static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat, + float divider, + unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart); +static inline void ASM_convert(volatile float *input_matrix, char *output_matrix); + +void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, + ring_node_sm *ring_node_tab[], + unsigned int nbAverageNORM, unsigned int nbAverageSBM ) +{ + float sum; + unsigned int i; + + for(i=0; i buffer_address) ) [ i ] + + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] + + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] + + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] + + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] + + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] + + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] + + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ]; + + if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) ) + { + averaged_spec_mat_NORM[ i ] = sum; + averaged_spec_mat_SBM[ i ] = sum; + } + else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) ) + { + averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum ); + averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum ); + } + else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) ) + { + averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum ); + averaged_spec_mat_SBM[ i ] = sum; + } + else + { + PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM) + } + } +} + +void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider ) +{ + int frequencyBin; + int asmComponent; + unsigned int offsetAveragedSpecMatReorganized; + unsigned int offsetAveragedSpecMat; + + for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++) + { + for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ ) + { + offsetAveragedSpecMatReorganized = + frequencyBin * NB_VALUES_PER_SM + + asmComponent; + offsetAveragedSpecMat = + asmComponent * NB_BINS_PER_SM + + frequencyBin; + averaged_spec_mat_reorganized[offsetAveragedSpecMatReorganized ] = + averaged_spec_mat[ offsetAveragedSpecMat ] / divider; + } + } +} + +void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider, + unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart ) +{ + int frequencyBin; + int asmComponent; + int offsetASM; + int offsetCompressed; + int k; + + // build data + for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++) + { + for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ ) + { + offsetCompressed = // NO TIME OFFSET + frequencyBin * NB_VALUES_PER_SM + + asmComponent; + offsetASM = // NO TIME OFFSET + asmComponent * NB_BINS_PER_SM + + ASMIndexStart + + frequencyBin * nbBinsToAverage; + compressed_spec_mat[ offsetCompressed ] = 0; + for ( k = 0; k < nbBinsToAverage; k++ ) + { + compressed_spec_mat[offsetCompressed ] = + ( compressed_spec_mat[ offsetCompressed ] + + averaged_spec_mat[ offsetASM + k ] ) / (divider * nbBinsToAverage); + } + } + } +} + +void ASM_convert( volatile float *input_matrix, char *output_matrix) +{ + unsigned int frequencyBin; + unsigned int asmComponent; + char * pt_char_input; + char * pt_char_output; + unsigned int offsetInput; + unsigned int offsetOutput; + + pt_char_input = (char*) &input_matrix; + pt_char_output = (char*) &output_matrix; + + // convert all other data + for( frequencyBin=0; frequencyBin +#include + +#include "tc_load_dump_parameters.h" +#include "tc_acceptance.h" +#include "tm_lfr_tc_exe.h" +#include "wf_handler.h" +#include "fsw_processing.h" + +#include "lfr_cpu_usage_report.h" + +// MODE PARAMETERS +extern unsigned int maxCount; + +//**** +// ISR +rtems_isr commutation_isr1( rtems_vector_number vector ); +rtems_isr commutation_isr2( rtems_vector_number vector ); + +void reset_transitionCoarseTime( void ); +void set_transitionCoarseTime( unsigned int value ); +unsigned int get_transitionCoarseTime( void ); + +//*********** +// RTEMS TASK +rtems_task actn_task( rtems_task_argument unused ); + +//*********** +// TC ACTIONS +int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); +int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id); +int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); +int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); +int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); +int action_update_time( ccsdsTelecommandPacket_t *TC); + +// mode transition +int check_mode_value( unsigned char requestedMode ); +int check_mode_transition( unsigned char requestedMode ); +int check_transition_date( unsigned int transitionCoarseTime ); +int stop_current_mode( void ); +int enter_mode( unsigned char mode , unsigned int transitionCoarseTime ); +int restart_science_tasks(unsigned char lfrRequestedMode ); +int suspend_science_tasks(); +void launch_waveform_picker(unsigned char mode , unsigned int transitionCoarseTime); +void launch_spectral_matrix( void ); +void launch_spectral_matrix_simu( void ); +void set_irq_on_new_ready_matrix(unsigned char value ); +void set_run_matrix_spectral( unsigned char value ); + +// other functions +void updateLFRCurrentMode(); +void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time ); +void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time ); +void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); + +extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); +extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); + +#endif // TC_HANDLER_H_INCLUDED + + + diff --git a/timegen/header/tc_load_dump_parameters.h b/timegen/header/tc_load_dump_parameters.h new file mode 100644 --- /dev/null +++ b/timegen/header/tc_load_dump_parameters.h @@ -0,0 +1,51 @@ +#ifndef TC_LOAD_DUMP_PARAMETERS_H +#define TC_LOAD_DUMP_PARAMETERS_H + +#include +#include + +#include "fsw_params.h" +#include "wf_handler.h" +#include "tm_lfr_tc_exe.h" +#include "fsw_misc.h" + +#define FLOAT_EQUAL_ZERO 0.001 + +extern unsigned short sequenceCounterParameterDump; + +int action_load_common_par( ccsdsTelecommandPacket_t *TC ); +int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); +int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); +int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); +int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); +int action_dump_par(rtems_id queue_id ); + +// NORMAL +int check_common_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); +int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC ); + +// BURST +int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ); + +// SBM1 +int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ); + +// SBM2 +int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC ); +int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ); + +// TC_LFR_UPDATE_INFO +unsigned int check_update_info_hk_lfr_mode( unsigned char mode ); +unsigned int check_update_info_hk_tds_mode( unsigned char mode ); +unsigned int check_update_info_hk_thr_mode( unsigned char mode ); + +void init_parameter_dump( void ); + +#endif // TC_LOAD_DUMP_PARAMETERS_H diff --git a/timegen/header/tm_byte_positions.h b/timegen/header/tm_byte_positions.h new file mode 100644 --- /dev/null +++ b/timegen/header/tm_byte_positions.h @@ -0,0 +1,23 @@ +#ifndef TM_BYTE_POSITIONS_H +#define TM_BYTE_POSITIONS_H + +#define BYTE_POS_CP_LFR_MODE 11 + +// TC_LFR_LOAD_COMMON_PAR + +// TC_LFR_LOAD_NORMAL_PAR +#define BYTE_POS_SY_LFR_N_SWF_L 0 +#define BYTE_POS_SY_LFR_N_SWF_P 2 +#define BYTE_POS_SY_LFR_N_ASM_P 4 +#define BYTE_POS_SY_LFR_N_BP_P0 6 +#define BYTE_POS_SY_LFR_N_BP_P1 7 +#define BYTE_POS_SY_LFR_N_CWF_LONG_F3 8 + +// TC_LFR_LOAD_BURST_PAR + +// TC_LFR_LOAD_SBM1_PAR + +// TC_LFR_LOAD_SBM2_PAR + + +#endif // TM_BYTE_POSITIONS_H diff --git a/timegen/header/tm_lfr_tc_exe.h b/timegen/header/tm_lfr_tc_exe.h new file mode 100644 --- /dev/null +++ b/timegen/header/tm_lfr_tc_exe.h @@ -0,0 +1,26 @@ +#ifndef TM_LFR_TC_EXE_H_INCLUDED +#define TM_LFR_TC_EXE_H_INCLUDED + +#include +#include + +#include "fsw_params.h" +#include "fsw_spacewire.h" + +extern unsigned short sequenceCounters_TC_EXE[]; + +int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); +int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, + unsigned char byte_position, unsigned char rcv_value ); +int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); +int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); +int send_tm_lfr_tc_exe_error(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); +int send_tm_lfr_tc_exe_corrupted( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, + unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV, unsigned char destinationID ); + +void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id ); + +#endif // TM_LFR_TC_EXE_H_INCLUDED + + + diff --git a/timegen/header/wf_handler.h b/timegen/header/wf_handler.h new file mode 100644 --- /dev/null +++ b/timegen/header/wf_handler.h @@ -0,0 +1,92 @@ +#ifndef WF_HANDLER_H_INCLUDED +#define WF_HANDLER_H_INCLUDED + +#include +#include +#include +#include + +#include "fsw_params.h" +#include "fsw_spacewire.h" +#include "fsw_misc.h" +#include "fsw_params_wf_handler.h" + +#define pi 3.1415 + +extern int fdSPW; + +//***************** +// waveform buffers +extern volatile int wf_snap_f0[ ]; +extern volatile int wf_snap_f1[ ]; +extern volatile int wf_snap_f2[ ]; +extern volatile int wf_cont_f3[ ]; +extern char wf_cont_f3_light[ ]; + +extern waveform_picker_regs_new_t *waveform_picker_regs; +extern time_management_regs_t *time_management_regs; +extern Packet_TM_LFR_HK_t housekeeping_packet; +extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet; +extern struct param_local_str param_local; + +extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST; +extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2; + +extern rtems_id Task_id[20]; /* array of task ids */ + +extern unsigned char lfrCurrentMode; + +//********** +// RTEMS_ISR +void reset_extractSWF( void ); +rtems_isr waveforms_isr( rtems_vector_number vector ); + +//*********** +// RTEMS_TASK +rtems_task wfrm_task( rtems_task_argument argument ); +rtems_task cwf3_task( rtems_task_argument argument ); +rtems_task cwf2_task( rtems_task_argument argument ); +rtems_task cwf1_task( rtems_task_argument argument ); +rtems_task swbd_task( rtems_task_argument argument ); + +//****************** +// general functions +void WFP_init_rings( void ); +void init_waveform_ring( ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] ); +void WFP_reset_current_ring_nodes( void ); +// +int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF ); +int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF ); +int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF ); +// +int send_waveform_SWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id ); +int send_waveform_CWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id ); +int send_waveform_CWF3( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id ); +int send_waveform_CWF3_light( volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id ); +// +void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime, + unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime ); +void build_snapshot_from_ring(ring_node *ring_node_to_send , unsigned char frequencyChannel ); +void build_acquisition_time( unsigned long long int * acquisitionTimeAslong, ring_node *current_ring_node ); +// +rtems_id get_pkts_queue_id( void ); + +//************** +// wfp registers +// RESET +void reset_wfp_burst_enable( void ); +void reset_wfp_status(void); +void reset_waveform_picker_regs( void ); +// SET +void set_wfp_data_shaping(void); +void set_wfp_burst_enable_register( unsigned char mode ); +void set_wfp_delta_snapshot( void ); +void set_wfp_delta_f0_f0_2( void ); +void set_wfp_delta_f1( void ); +void set_wfp_delta_f2( void ); + +//***************** +// local parameters +void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ); + +#endif // WF_HANDLER_H_INCLUDED diff --git a/timegen/src/fsw_config.c b/timegen/src/fsw_config.c new file mode 100644 --- /dev/null +++ b/timegen/src/fsw_config.c @@ -0,0 +1,25 @@ +#include + +// GRSPW0 resources +struct drvmgr_key grlib_grspw_0n1_res[] = { + {"txBdCnt", KEY_TYPE_INT, {(unsigned int)50}}, // 7 SWF_F0, 7 SWF_F1, 7 SWF_F2, 7 CWF_F3, 7 CWF_F1 ou 7 CWF_F2 + {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}}, + {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}}, + {"txHdrSize", KEY_TYPE_INT, {(unsigned int)20+12}}, // 12 is for the auxiliary header, when needed + {"rxPktSize", KEY_TYPE_INT, {(unsigned int)248+4}}, + KEY_EMPTY +}; + +// If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP. + +struct drvmgr_bus_res grlib_drv_resources = { + .next = NULL, + .resource = { + {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]}, +// {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]}, +// {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]}, + RES_EMPTY /* Mark end of device resource array */ + } +}; + + diff --git a/timegen/src/fsw_globals.c b/timegen/src/fsw_globals.c new file mode 100644 --- /dev/null +++ b/timegen/src/fsw_globals.c @@ -0,0 +1,75 @@ +/** Global variables of the LFR flight software. + * + * @file + * @author P. LEROY + * + * Among global variables, there are: + * - RTEMS names and id. + * - APB configuration registers. + * - waveforms global buffers, used by the waveform picker hardware module to store data. + * - spectral matrices buffesr, used by the hardware module to store data. + * - variable related to LFR modes parameters. + * - the global HK packet buffer. + * - the global dump parameter buffer. + * + */ + +#include +#include + +#include "ccsds_types.h" +#include "grlib_regs.h" +#include "fsw_params.h" +#include "fsw_params_wf_handler.h" + +// RTEMS GLOBAL VARIABLES +rtems_name misc_name[5]; +rtems_id misc_id[5]; +rtems_name Task_name[20]; /* array of task names */ +rtems_id Task_id[20]; /* array of task ids */ +unsigned int maxCount; +int fdSPW = 0; +int fdUART = 0; +unsigned char lfrCurrentMode; + +// WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584 + // 97 * 256 = 24832 => delta = 248 bytes = 62 words +// WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264 + // 127 * 256 = 32512 => delta = 248 bytes = 62 words +// F0 F1 F2 F3 +volatile int wf_snap_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))); +volatile int wf_snap_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))); +volatile int wf_snap_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))); +volatile int wf_cont_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))); +char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK + TIME_OFFSET_IN_BYTES ] __attribute__((aligned(0x100))); + +//*********************************** +// SPECTRAL MATRICES GLOBAL VARIABLES + +// alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00 +volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); +volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); +volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); + +// APB CONFIGURATION REGISTERS +time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT; +gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; +waveform_picker_regs_new_t *waveform_picker_regs = (waveform_picker_regs_new_t*) REGS_ADDR_WAVEFORM_PICKER; +spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX; + +// MODE PARAMETERS +Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet; +struct param_local_str param_local; + +// HK PACKETS +Packet_TM_LFR_HK_t housekeeping_packet; +// sequence counters are incremented by APID (PID + CAT) and destination ID +unsigned short sequenceCounters_SCIENCE_NORMAL_BURST; +unsigned short sequenceCounters_SCIENCE_SBM1_SBM2; +unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID]; +unsigned short sequenceCounterHK; +unsigned short sequenceCounterParameterDump; +spw_stats spacewire_stats; +spw_stats spacewire_stats_backup; + + diff --git a/timegen/src/fsw_init.c b/timegen/src/fsw_init.c new file mode 100644 --- /dev/null +++ b/timegen/src/fsw_init.c @@ -0,0 +1,489 @@ +/** This is the RTEMS initialization module. + * + * @file + * @author P. LEROY + * + * This module contains two very different information: + * - specific instructions to configure the compilation of the RTEMS executive + * - functions related to the fligth softwre initialization, especially the INIT RTEMS task + * + */ + +//************************* +// GPL reminder to be added +//************************* + +#include + +/* configuration information */ + +#define CONFIGURE_INIT + +#include /* for device driver prototypes */ + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_TASKS 20 +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 +#define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100 +#define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT) +#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) +#define CONFIGURE_MAXIMUM_DRIVERS 16 +#define CONFIGURE_MAXIMUM_PERIODS 5 +#define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s) +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5 +#ifdef PRINT_STACK_REPORT + #define CONFIGURE_STACK_CHECKER_ENABLED +#endif + +#include + +/* If --drvmgr was enabled during the configuration of the RTEMS kernel */ +#ifdef RTEMS_DRVMGR_STARTUP + #ifdef LEON3 + /* Add Timer and UART Driver */ + #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER + #endif + #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART + #endif + #endif + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ + #include +#endif + +#include "fsw_init.h" +#include "fsw_config.c" + +rtems_id rtems_task_id_updt; +rtems_name rtems_task_name_updt; + +rtems_task Init( rtems_task_argument ignored ) +{ + /** This is the RTEMS INIT taks, it the first task launched by the system. + * + * @param unused is the starting argument of the RTEMS task + * + * The INIT task create and run all other RTEMS tasks. + * + */ + + unsigned char *vhdlVersion; + + reset_local_time(); + + rtems_cpu_usage_reset(); + + rtems_status_code status; + rtems_status_code status_spw; + + struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; + + // UART settings + send_console_outputs_on_apbuart_port(); + set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE); + enable_apbuart_transmitter(); + DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") + + PRINTF("\n\n\n\n\n") + PRINTF("*************************\n") + PRINTF("** timegen for LFR **\n") + PRINTF1("** %d.", SW_VERSION_N1) + PRINTF1("%d." , SW_VERSION_N2) + PRINTF1("%d." , SW_VERSION_N3) + PRINTF1("%d **\n", SW_VERSION_N4) + + vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION); + PRINTF("** VHDL **\n") + PRINTF1("** %d.", vhdlVersion[1]) + PRINTF1("%d." , vhdlVersion[2]) + PRINTF1("%d **\n", vhdlVersion[3]) + PRINTF("*************************\n") + PRINTF("\n\n") + + create_names(); // create all names + + status = create_message_queues(); // create message queues + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** ERR in create_message_queues, code %d", status) + } + + status = create_all_tasks(); // create all tasks + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status) + } + + // ************************** + // + grspw_timecode_callback = &timecode_irq_handler; + + status_spw = spacewire_open_link(); // (1) open the link + if ( status_spw != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw ) + } + + if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link + { + status_spw = spacewire_configure_link( fdSPW ); + if ( status_spw != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw ) + } + } + + if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link + { + status_spw = spacewire_start_link( fdSPW ); + if ( status_spw != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw ) + } + } + // + // *************************** + + status = start_all_tasks(); // start all tasks + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status) + } + + // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization + status = start_recv_send_tasks(); + if ( status != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status ) + } + + // suspend science tasks, they will be restarted later depending on the mode + status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY) + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status) + } + + // if the spacewire link is not up then send an event to the SPIQ task for link recovery + if ( status_spw != RTEMS_SUCCESSFUL ) + { + status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status ) + } + } + + //********************************* + // init GPIO for trigger generation + grgpio_regs->io_port_direction_register = + grgpio_regs->io_port_direction_register | 0x04; // [0000 0100], 0 = output disabled, 1 = output enabled + grgpio_regs->io_port_direction_register = + grgpio_regs->io_port_direction_register | 0x08; // [0000 1000], 0 = output disabled, 1 = output enabled + + BOOT_PRINTF("delete INIT\n") + + status = rtems_task_delete(RTEMS_SELF); + +} + +void init_local_mode_parameters( void ) +{ + /** This function initialize the param_local global variable with default values. + * + */ + + unsigned int i; + + // LOCAL PARAMETERS + + BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max) + BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max) + // BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX) + + // init sequence counters + + for(i = 0; ictrl = 0x02; // software reset, coarse time = 0x80000000 +} + +void create_names( void ) // create all names for tasks and queues +{ + /** This function creates all RTEMS names used in the software for tasks and queues. + * + * @return RTEMS directive status codes: + * - RTEMS_SUCCESSFUL - successful completion + * + */ + + // task names + Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' ); + Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' ); + Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' ); + Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' ); + Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' ); + Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' ); + Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' ); + + rtems_task_name_updt = rtems_build_name( 'U', 'P', 'D', 'T' ); + + misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' ); + misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' ); + +} + +int create_all_tasks( void ) // create all tasks which run in the software +{ + /** This function creates all RTEMS tasks used in the software. + * + * @return RTEMS directive status codes: + * - RTEMS_SUCCESSFUL - task created successfully + * - RTEMS_INVALID_ADDRESS - id is NULL + * - RTEMS_INVALID_NAME - invalid task name + * - RTEMS_INVALID_PRIORITY - invalid task priority + * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured + * - RTEMS_TOO_MANY - too many tasks created + * - RTEMS_UNSATISFIED - not enough memory for stack/FP context + * - RTEMS_TOO_MANY - too many global objects + * + */ + + rtems_status_code status; + + //********** + // SPACEWIRE + // RECV + status = rtems_task_create( + Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV] + ); + if (status == RTEMS_SUCCESSFUL) // SEND + { + status = rtems_task_create( + Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND] + ); + } + if (status == RTEMS_SUCCESSFUL) // WTDG + { + status = rtems_task_create( + Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG] + ); + } + if (status == RTEMS_SUCCESSFUL) // ACTN + { + status = rtems_task_create( + Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, + RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN] + ); + } + if (status == RTEMS_SUCCESSFUL) // SPIQ + { + status = rtems_task_create( + Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ] + ); + } + + //***** + // MISC + if (status == RTEMS_SUCCESSFUL) // STAT + { + status = rtems_task_create( + Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT] + ); + } + if (status == RTEMS_SUCCESSFUL) // DUMB + { + status = rtems_task_create( + Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB] + ); + } + if (status == RTEMS_SUCCESSFUL) // UPDT + { + status = rtems_task_create( + rtems_task_name_updt, TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &rtems_task_id_updt + ); + } + + return status; +} + +int start_recv_send_tasks( void ) +{ + rtems_status_code status; + + status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n") + } + + if (status == RTEMS_SUCCESSFUL) // SEND + { + status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n") + } + } + + return status; +} + +int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS +{ + /** This function starts all RTEMS tasks used in the software. + * + * @return RTEMS directive status codes: + * - RTEMS_SUCCESSFUL - ask started successfully + * - RTEMS_INVALID_ADDRESS - invalid task entry point + * - RTEMS_INVALID_ID - invalid task id + * - RTEMS_INCORRECT_STATE - task not in the dormant state + * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task + * + */ + // starts all the tasks fot eh flight software + + rtems_status_code status; + + //********** + // SPACEWIRE + status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n") + } + + if (status == RTEMS_SUCCESSFUL) // WTDG + { + status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n") + } + } + + if (status == RTEMS_SUCCESSFUL) // ACTN + { + status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n") + } + } + + //***** + // MISC + if (status == RTEMS_SUCCESSFUL) // DUMB + { + status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n") + } + } + if (status == RTEMS_SUCCESSFUL) // STAT + { + status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n") + } + } + if (status == RTEMS_SUCCESSFUL) // UPDT + { + status = rtems_task_start( rtems_task_id_updt, updt_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_UPDT\n") + } + } + + return status; +} + +rtems_status_code create_message_queues( void ) // create the two message queues used in the software +{ + rtems_status_code status_recv; + rtems_status_code status_send; + + rtems_status_code ret; + rtems_id queue_id; + + ret = LFR_SUCCESSFUL; + + //**************************************** + // create the queue for handling valid TCs + status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV], + MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE, + RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); + if ( status_recv != RTEMS_SUCCESSFUL ) { + PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv) + } + + //************************************************ + // create the queue for handling TM packet sending + status_send = rtems_message_queue_create( misc_name[QUEUE_SEND], + MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND, + RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); + if ( status_send != RTEMS_SUCCESSFUL ) { + PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send) + } + + if ( status_recv != RTEMS_SUCCESSFUL ) + { + ret = status_recv; + } + else if( status_send != RTEMS_SUCCESSFUL ) + { + ret = status_send; + } + + return ret; +} + +rtems_status_code get_message_queue_id_send( rtems_id *queue_id ) +{ + rtems_status_code status; + rtems_name queue_name; + + queue_name = rtems_build_name( 'Q', '_', 'S', 'D' ); + + status = rtems_message_queue_ident( queue_name, 0, queue_id ); + + return status; +} + +rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ) +{ + rtems_status_code status; + rtems_name queue_name; + + queue_name = rtems_build_name( 'Q', '_', 'R', 'V' ); + + status = rtems_message_queue_ident( queue_name, 0, queue_id ); + + return status; +} diff --git a/timegen/src/fsw_misc.c b/timegen/src/fsw_misc.c new file mode 100644 --- /dev/null +++ b/timegen/src/fsw_misc.c @@ -0,0 +1,252 @@ +/** General usage functions and RTEMS tasks. + * + * @file + * @author P. LEROY + * + */ + +#include "fsw_misc.h" + +void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, + unsigned char interrupt_level, rtems_isr (*timer_isr)() ) +{ + /** This function configures a GPTIMER timer instantiated in the VHDL design. + * + * @param gptimer_regs points to the APB registers of the GPTIMER IP core. + * @param timer is the number of the timer in the IP core (several timers can be instantiated). + * @param clock_divider is the divider of the 1 MHz clock that will be configured. + * @param interrupt_level is the interrupt level that the timer drives. + * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. + * + * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 + * + */ + + rtems_status_code status; + rtems_isr_entry old_isr_handler; + + gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register + + status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels + if (status!=RTEMS_SUCCESSFUL) + { + PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") + } + + timer_set_clock_divider( gptimer_regs, timer, clock_divider); +} + +void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer) +{ + /** This function starts a GPTIMER timer. + * + * @param gptimer_regs points to the APB registers of the GPTIMER IP core. + * @param timer is the number of the timer in the IP core (several timers can be instantiated). + * + */ + + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable +} + +void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer) +{ + /** This function stops a GPTIMER timer. + * + * @param gptimer_regs points to the APB registers of the GPTIMER IP core. + * @param timer is the number of the timer in the IP core (several timers can be instantiated). + * + */ + + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable + gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any +} + +void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider) +{ + /** This function sets the clock divider of a GPTIMER timer. + * + * @param gptimer_regs points to the APB registers of the GPTIMER IP core. + * @param timer is the number of the timer in the IP core (several timers can be instantiated). + * @param clock_divider is the divider of the 1 MHz clock that will be configured. + * + */ + + gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz +} + +int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port +{ + struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; + + apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; + + return 0; +} + +int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register +{ + struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; + + apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE; + + return 0; +} + +void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) +{ + /** This function sets the scaler reload register of the apbuart module + * + * @param regs is the address of the apbuart registers in memory + * @param value is the value that will be stored in the scaler register + * + * The value shall be set by the software to get data on the serial interface. + * + */ + + struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; + + apbuart_regs->scaler = value; + BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) +} + +//************ +// RTEMS TASKS + +rtems_task stat_task(rtems_task_argument argument) +{ + int i; + int j; + i = 0; + j = 0; + BOOT_PRINTF("in STAT *** \n") + while(1){ + rtems_task_wake_after(1000); + PRINTF1("%d\n", j) + if (i == CPU_USAGE_REPORT_PERIOD) { +// #ifdef PRINT_TASK_STATISTICS +// rtems_cpu_usage_report(); +// rtems_cpu_usage_reset(); +// #endif + i = 0; + } + else i++; + j++; + } +} + +rtems_task dumb_task( rtems_task_argument unused ) +{ + /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. + * + * @param unused is the starting argument of the RTEMS task + * + * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. + * + */ + + unsigned int i; + unsigned int intEventOut; + unsigned int coarse_time = 0; + unsigned int fine_time = 0; + rtems_event_set event_out; + + char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0 + "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 + "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 + "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 + "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 + "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 + "ERR HK", // RTEMS_EVENT_6 + "ready for dump", // RTEMS_EVENT_7 + "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 + "tick", // RTEMS_EVENT_9 + "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 + "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11 + }; + + BOOT_PRINTF("in DUMB *** \n") + + while(1){ + rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 + | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 + | RTEMS_EVENT_8 | RTEMS_EVENT_9, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT + intEventOut = (unsigned int) event_out; + for ( i=0; i<32; i++) + { + if ( ((intEventOut >> i) & 0x0001) != 0) + { + coarse_time = time_management_regs->coarse_time; + fine_time = time_management_regs->fine_time; + printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]); + if (i==8) + { + } + if (i==10) + { + } + } + } + } +} + +//***************************** +// init housekeeping parameters + +void increment_seq_counter( unsigned short *packetSequenceControl ) +{ + /** This function increment the sequence counter psased in argument. + * + * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. + * + */ + + unsigned short segmentation_grouping_flag; + unsigned short sequence_cnt; + + segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 + sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] + + if ( sequence_cnt < SEQ_CNT_MAX) + { + sequence_cnt = sequence_cnt + 1; + } + else + { + sequence_cnt = 0; + } + + *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; +} + +void getTime( unsigned char *time) +{ + /** This function write the current local time in the time buffer passed in argument. + * + */ + + time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + time[3] = (unsigned char) (time_management_regs->coarse_time); + time[4] = (unsigned char) (time_management_regs->fine_time>>8); + time[5] = (unsigned char) (time_management_regs->fine_time); +} + +unsigned long long int getTimeAsUnsignedLongLongInt( ) +{ + /** This function write the current local time in the time buffer passed in argument. + * + */ + unsigned long long int time; + + time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) + + time_management_regs->fine_time; + + return time; +} diff --git a/timegen/src/fsw_processing_globals.c b/timegen/src/fsw_processing_globals.c new file mode 100644 --- /dev/null +++ b/timegen/src/fsw_processing_globals.c @@ -0,0 +1,46 @@ +/** Global variables used by the processing functions. + * + * @file + * @author P. LEROY + * + */ + +// TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets +// SX 12 coefficients +float K14_sx_re = 1; +float K14_sx_im = 1; +float K15_sx_re = 1; +float K15_sx_im = 1; +float K24_sx_re = 1; +float K24_sx_im = 1; +float K25_sx_re = 1; +float K25_sx_im = 1; +float K34_sx_re = 1; +float K34_sx_im = 1; +float K35_sx_re = 1; +float K35_sx_im = 1; +// NY 8 coefficients +float K24_ny_re = 1; +float K24_ny_im = 1; +float K25_ny_re = 1; +float K25_ny_im = 1; +float K34_ny_re = 1; +float K34_ny_im = 1; +float K35_ny_re = 1; +float K35_ny_im = 1; +// NZ 8 coefficients +float K24_nz_re = 1; +float K24_nz_im = 1; +float K25_nz_re = 1; +float K25_nz_im = 1; +float K34_nz_re = 1; +float K34_nz_im = 1; +float K35_nz_re = 1; +float K35_nz_im = 1; +// PE 4 coefficients +float K44_pe = 1; +float K55_pe = 1; +float K45_pe_re = 1; +float K45_pe_im = 1; + +float Alpha_M = M_PI/4; diff --git a/timegen/src/fsw_spacewire.c b/timegen/src/fsw_spacewire.c new file mode 100644 --- /dev/null +++ b/timegen/src/fsw_spacewire.c @@ -0,0 +1,728 @@ +/** Functions related to the SpaceWire interface. + * + * @file + * @author P. LEROY + * + * A group of functions to handle SpaceWire transmissions: + * - configuration of the SpaceWire link + * - SpaceWire related interruption requests processing + * - transmission of TeleMetry packets by a dedicated RTEMS task + * - reception of TeleCommands by a dedicated RTEMS task + * + */ + +#include "fsw_spacewire.h" + +rtems_name semq_name; +rtems_id semq_id; + +unsigned int localCoarseTime; + +void resetLocalCoarseTime() +{ + localCoarseTime = 0; +} + +void setLocalCoarseTime( unsigned int value ) +{ + localCoarseTime = value; +} + +unsigned int getLocalCoarseTime() +{ + return localCoarseTime; +} + +void incrementLocalCoarseTime() +{ + localCoarseTime = localCoarseTime + 1; +} + +//*********** +// RTEMS TASK +rtems_task spiq_task(rtems_task_argument unused) +{ + /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. + * + * @param unused is the starting argument of the RTEMS task + * + */ + + rtems_event_set event_out; + rtems_status_code status; + int linkStatus; + + BOOT_PRINTF("in SPIQ *** \n") + + while(true){ + rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT + PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") + + // [0] SUSPEND RECV AND SEND TASKS + status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR suspending RECV Task\n") + } + status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR suspending SEND Task\n") + } + + // [1] CHECK THE LINK + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) + if ( linkStatus != 5) { + PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) + status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms + } + + // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) + if ( linkStatus != 5 ) // [2.a] not in run state, reset the link + { + spacewire_compute_stats_offsets(); + status = spacewire_reset_link( ); + } + else // [2.b] in run state, start the link + { + status = spacewire_stop_and_start_link( fdSPW ); // start the link + if ( status != RTEMS_SUCCESSFUL) + { + PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status) + } + } + + // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS + if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully + { + status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR resuming SEND Task\n") + } + status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR resuming RECV Task\n") + } + } + else // [3.b] the link is not in run state, go in STANDBY mode + { + status = stop_current_mode(); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status) + } + status = enter_mode( LFR_MODE_STANDBY, 0 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) + } + // wake the WTDG task up to wait for the link recovery + status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); + status = rtems_task_suspend( RTEMS_SELF ); + } + } +} + +rtems_task recv_task( rtems_task_argument unused ) +{ + /** This RTEMS task is dedicated to the reception of incoming TeleCommands. + * + * @param unused is the starting argument of the RTEMS task + * + * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: + * 1. It reads the incoming data. + * 2. Launches the acceptance procedure. + * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. + * + */ + + int len; + ccsdsTelecommandPacket_t currentTC; + unsigned char computed_CRC[ 2 ]; + unsigned char currentTC_LEN_RCV[ 2 ]; + unsigned char destinationID; + unsigned int estimatedPacketLength; + unsigned int parserCode; + rtems_status_code status; + rtems_id queue_recv_id; + rtems_id queue_send_id; + + initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes + + status = get_message_queue_id_recv( &queue_recv_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) + } + + status = get_message_queue_id_send( &queue_send_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in RECV *** \n") + + while(1) + { + len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking + if (len == -1){ // error during the read call + PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) + } + else { + if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { + PRINTF("in RECV *** packet lenght too short\n") + } + else { + estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes + currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8); + currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); + // CHECK THE TC + parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; + if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) + || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) + || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) + || (parserCode == WRONG_SRC_ID) ) + { // send TM_LFR_TC_EXE_CORRUPTED + PRINTF1("TC corrupted received, with code: %d\n", parserCode) + if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) + && + !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) + ) + { + if ( parserCode == WRONG_SRC_ID ) + { + destinationID = SID_TC_GROUND; + } + else + { + destinationID = currentTC.sourceID; + } + } + } + else + { // send valid TC to the action launcher + status = rtems_message_queue_send( queue_recv_id, ¤tTC, + estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3); + } + } + } + } +} + +rtems_task send_task( rtems_task_argument argument) +{ + /** This RTEMS task is dedicated to the transmission of TeleMetry packets. + * + * @param unused is the starting argument of the RTEMS task + * + * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: + * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. + * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After + * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the + * data it contains. + * + */ + + rtems_status_code status; // RTEMS status code + char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer + spw_ioctl_pkt_send *spw_ioctl_send; + size_t size; // size of the incoming TC packet + u_int32_t count; + rtems_id queue_id; + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in SEND *** \n") + + while(1) + { + status = rtems_message_queue_receive( queue_id, incomingData, &size, + RTEMS_WAIT, RTEMS_NO_TIMEOUT ); + + if (status!=RTEMS_SUCCESSFUL) + { + PRINTF1("in SEND *** (1) ERR = %d\n", status) + } + else + { + if ((incomingData[0] == CCSDS_DESTINATION_ID) || (incomingData[0] == (char) 0xfe)) // the incoming message is a ccsds packet + { + status = write( fdSPW, incomingData, size ); + if (status == -1){ + PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) + } + } + else // the incoming message is a spw_ioctl_pkt_send structure + { + spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; + status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); + if (status == -1){ + PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) + } + } + } + + status = rtems_message_queue_get_number_pending( queue_id, &count ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in SEND *** (3) ERR = %d\n", status) + } + else + { + if (count > maxCount) + { + maxCount = count; + } + } + } +} + +rtems_task wtdg_task( rtems_task_argument argument ) +{ + rtems_event_set event_out; + rtems_status_code status; + int linkStatus; + + BOOT_PRINTF("in WTDG ***\n") + + while(1) + { + // wait for an RTEMS_EVENT + rtems_event_receive( RTEMS_EVENT_0, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + PRINTF("in WTDG *** wait for the link\n") + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status + while( linkStatus != 5) // wait for the link + { + rtems_task_wake_after( 10 ); + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status + } + + status = spacewire_stop_and_start_link( fdSPW ); + + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in WTDG *** ERR link not started %d\n", status) + } + else + { + PRINTF("in WTDG *** OK link started\n") + } + + // restart the SPIQ task + status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") + } + + // restart RECV and SEND + status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR restarting SEND Task\n") + } + status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR restarting RECV Task\n") + } + } +} + +//**************** +// OTHER FUNCTIONS +int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] +{ + /** This function opens the SpaceWire link. + * + * @return a valid file descriptor in case of success, -1 in case of a failure + * + */ + rtems_status_code status; + + fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware + if ( fdSPW < 0 ) { + PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) + } + else + { + status = RTEMS_SUCCESSFUL; + } + + return status; +} + +int spacewire_start_link( int fd ) +{ + rtems_status_code status; + + status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started + // -1 default hardcoded driver timeout + + return status; +} + +int spacewire_stop_and_start_link( int fd ) +{ + rtems_status_code status; + + status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 + status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started + // -1 default hardcoded driver timeout + + return status; +} + +int spacewire_configure_link( int fd ) +{ + /** This function configures the SpaceWire link. + * + * @return GR-RTEMS-DRIVER directive status codes: + * - 22 EINVAL - Null pointer or an out of range value was given as the argument. + * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. + * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. + * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. + * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. + * - 5 EIO - Error when writing to grswp hardware registers. + * - 2 ENOENT - No such file or directory + */ + + rtems_status_code status; + + spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force + spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration + + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception + if (status!=RTEMS_SUCCESSFUL) { + PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") + } + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a + if (status!=RTEMS_SUCCESSFUL) { + PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs + } + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts + if (status!=RTEMS_SUCCESSFUL) { + PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") + } + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit + if (status!=RTEMS_SUCCESSFUL) { + PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") + } + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks + if (status!=RTEMS_SUCCESSFUL) { + PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") + } + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available + if (status!=RTEMS_SUCCESSFUL) { + PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") + } + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] + if (status!=RTEMS_SUCCESSFUL) { + PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") + } + + return status; +} + +int spacewire_reset_link( void ) +{ + /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. + * + * @return RTEMS directive status code: + * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. + * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. + * + */ + + rtems_status_code status_spw; + int i; + + for ( i=0; i > 8); + housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); + housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); + housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); + //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; + //housekeeping_packet.hk_lfr_dpu_spw_last_timc; + + //****************************************** + // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY + housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; + housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; + housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; + housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; + housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; + + //********************************************* + // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY + housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; + housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; + housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; + housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; +} + +void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) +{ + struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; + + incrementLocalCoarseTime(); + + //******* + // GPIO 2 + if ( get_transitionCoarseTime() == getLocalCoarseTime() ) + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x04; // [0000 0100] + } + else + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xfb; // [1111 1011] + } + + //******* + // GPIO 3 + if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 ) + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7; // [1111 0111] + } + else + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08; // [0000 1000] + } + + rtems_event_send( rtems_task_id_updt, RTEMS_EVENT_0); +} + +rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ) +{ + int linkStatus; + rtems_status_code status; + + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status + + if ( linkStatus == 5) { + PRINTF("in spacewire_reset_link *** link is running\n") + status = RTEMS_SUCCESSFUL; + } +} + +rtems_task updt_task(rtems_task_argument unused) +{ + + rtems_event_set event_out; + rtems_status_code status; + rtems_id queue_id; + unsigned int coarseTimeToSend; + + Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t update_time_packet; + + resetLocalCoarseTime(); + reset_transitionCoarseTime(); + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) + } + + update_time_packet.targetLogicalAddress = 0xfe; + update_time_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; + update_time_packet.reserved = DEFAULT_RESERVED; + update_time_packet.userApplication = CCSDS_USER_APP; + update_time_packet.packetID[0] = (unsigned char) (TC_LFR_PACKET_ID >> 8); + update_time_packet.packetID[1] = (unsigned char) (TC_LFR_PACKET_ID ); + update_time_packet.packetSequenceControl[0] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL >> 8); + update_time_packet.packetSequenceControl[1] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL ); + update_time_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME >> 8); + update_time_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME ); + + update_time_packet.ccsdsSecHeaderFlag_pusVersion_ack = 0x19; + update_time_packet.serviceType = TC_TYPE_LFR_UPDATE_TIME; + update_time_packet.serviceSubType = TC_SUBTYPE_UPDATE_TIME; + update_time_packet.sourceID = SID_TC_RPW_INTERNAL; + + BOOT_PRINTF("in UPDT *** \n") + + while(true){ + rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT + + coarseTimeToSend = getLocalCoarseTime() + 1; + updateTimePacket( coarseTimeToSend, &update_time_packet); + printf("UPDT will send %x as coarse time in 700 ms\n", coarseTimeToSend); + + rtems_task_wake_after( 70 ); // 70 => 700 ms + + status = rtems_message_queue_urgent( queue_id, &update_time_packet, + PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES + + 0); // 1 is for the star dundee extra byte + if (status != RTEMS_SUCCESSFUL) { + PRINTF1("in HOUS *** ERR send: %d\n", status) + } + } +} + +void updateTimePacket(unsigned int time, Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t *packet) +{ + unsigned char crcAsTwoBytes[2]; + + packet->cp_rpw_time[0] = (unsigned char) (time >> 24); + packet->cp_rpw_time[1] = (unsigned char) (time >> 16); + packet->cp_rpw_time[2] = (unsigned char) (time >> 8); + packet->cp_rpw_time[3] = (unsigned char) (time); + packet->cp_rpw_time[4] = 0; // fine time MSB + packet->cp_rpw_time[5] = 0; // fine time LSB + + GetCRCAsTwoBytes((unsigned char*) &packet->packetID, crcAsTwoBytes, + PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET - 2); + packet->crc[0] = crcAsTwoBytes[0]; + packet->crc[1] = crcAsTwoBytes[1]; +} diff --git a/timegen/src/lfr_cpu_usage_report.c b/timegen/src/lfr_cpu_usage_report.c new file mode 100644 --- /dev/null +++ b/timegen/src/lfr_cpu_usage_report.c @@ -0,0 +1,115 @@ +/* + * CPU Usage Reporter + * + * COPYRIGHT (c) 1989-2009 + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include "lfr_cpu_usage_report.h" + +unsigned char lfr_rtems_cpu_usage_report( void ) +{ + uint32_t api_index; + Thread_Control *the_thread; + Objects_Information *information; + uint32_t ival, fval; +#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ + Timestamp_Control uptime; + Timestamp_Control total; + Timestamp_Control ran; +#else + uint32_t total_units = 0; +#endif + + unsigned char cpu_load; + cpu_load = 0; + + /* + * When not using nanosecond CPU usage resolution, we have to count + * the number of "ticks" we gave credit for to give the user a rough + * guideline as to what each number means proportionally. + */ +#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ + _TOD_Get_uptime( &uptime ); + _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); +#else + for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { + if ( !_Objects_Information_table[ api_index ] ) { } + else + { + information = _Objects_Information_table[ api_index ][ 1 ]; + if ( information != NULL ) + { + for ( i=1 ; i <= information->maximum ; i++ ) { + the_thread = (Thread_Control *)information->local_table[ i ]; + + if ( the_thread != NULL ) + total_units += the_thread->cpu_time_used; + } + } + } + } +#endif + + for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) + { + if ( !_Objects_Information_table[ api_index ] ) { } + else + { + information = _Objects_Information_table[ api_index ][ 1 ]; + if ( information != NULL ) + { + the_thread = (Thread_Control *)information->local_table[ 1 ]; + + if ( the_thread == NULL ) { } + else + { + #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ + /* + * If this is the currently executing thread, account for time + * since the last context switch. + */ + ran = the_thread->cpu_time_used; + if ( _Thread_Executing->Object.id == the_thread->Object.id ) + { + Timestamp_Control used; + _Timestamp_Subtract( + &_Thread_Time_of_last_context_switch, &uptime, &used + ); + _Timestamp_Add_to( &ran, &used ); + } + _Timestamp_Divide( &ran, &total, &ival, &fval ); + + #else + if (total_units != 0) + { + uint64_t ival_64; + + ival_64 = the_thread->cpu_time_used; + ival_64 *= 100000; + ival = ival_64 / total_units; + } + else + { + ival = 0; + } + + fval = ival % 1000; + ival /= 1000; + #endif + } + } + } + } + cpu_load = (unsigned char) (100 - ival); + + return cpu_load; +} + + diff --git a/timegen/src/processing/avf0_prc0.c b/timegen/src/processing/avf0_prc0.c new file mode 100644 --- /dev/null +++ b/timegen/src/processing/avf0_prc0.c @@ -0,0 +1,380 @@ +/** Functions related to data processing. + * + * @file + * @author P. LEROY + * + * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. + * + */ + +#include "avf0_prc0.h" +#include "fsw_processing.h" + +nb_sm_before_bp_asm_f0 nb_sm_before_f0; + +//*** +// F0 +ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ]; +ring_node_asm asm_ring_burst_sbm_f0[ NB_RING_NODES_ASM_BURST_SBM_F0 ]; + +float asm_f0_reorganized [ TOTAL_SIZE_SM ]; +char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ]; +float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0]; +float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ]; +//unsigned char bp1_norm_f0 [ TOTAL_SIZE_BP1_NORM_F0 ]; +//unsigned char bp1_sbm_f0 [ TOTAL_SIZE_BP1_SBM_F0 ]; + +//************ +// RTEMS TASKS + +rtems_task avf0_task( rtems_task_argument lfrRequestedMode ) +{ + int i; + + rtems_event_set event_out; + rtems_status_code status; + rtems_id queue_id_prc0; + asm_msg msgForMATR; + ring_node_sm *ring_node_tab[8]; + ring_node_asm *current_ring_node_asm_burst_sbm_f0; + ring_node_asm *current_ring_node_asm_norm_f0; + + unsigned int nb_norm_bp1; + unsigned int nb_norm_bp2; + unsigned int nb_norm_asm; + unsigned int nb_sbm_bp1; + unsigned int nb_sbm_bp2; + + nb_norm_bp1 = 0; + nb_norm_bp2 = 0; + nb_norm_asm = 0; + nb_sbm_bp1 = 0; + nb_sbm_bp2 = 0; + + reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions + ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 ); + ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 ); + current_ring_node_asm_norm_f0 = asm_ring_norm_f0; + current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0; + + BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) + + status = get_message_queue_id_prc0( &queue_id_prc0 ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status) + } + + while(1){ + rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 + + //**************************************** + // initialize the mesage for the MATR task + msgForMATR.norm = current_ring_node_asm_norm_f0; + msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f0; + msgForMATR.event = 0x00; // this composite event will be sent to the MATR task + msgForMATR.coarseTime = ring_node_for_averaging_sm_f0->coarseTime; + msgForMATR.fineTime = ring_node_for_averaging_sm_f0->fineTime; + // + //**************************************** + + ring_node_tab[NB_SM_BEFORE_AVF0-1] = ring_node_for_averaging_sm_f0; + for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ ) + { + ring_node_for_averaging_sm_f0 = ring_node_for_averaging_sm_f0->previous; + ring_node_tab[NB_SM_BEFORE_AVF0-i] = ring_node_for_averaging_sm_f0; + } + + // compute the average and store it in the averaged_sm_f1 buffer + SM_average( current_ring_node_asm_norm_f0->matrix, + current_ring_node_asm_burst_sbm_f0->matrix, + ring_node_tab, + nb_norm_bp1, nb_sbm_bp1 ); + + // update nb_average + nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0; + nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0; + nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0; + nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0; + nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0; + + if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1) + { + nb_sbm_bp1 = 0; + // set another ring for the ASM storage + current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next; + if ( lfrCurrentMode == LFR_MODE_BURST ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F0; + } + else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F0; + } + } + + if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2) + { + nb_sbm_bp2 = 0; + if ( lfrCurrentMode == LFR_MODE_BURST ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F0; + } + else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F0; + } + } + + if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1) + { + nb_norm_bp1 = 0; + // set another ring for the ASM storage + current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F0; + } + } + + if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2) + { + nb_norm_bp2 = 0; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F0; + } + } + + if (nb_norm_asm == nb_sm_before_f0.norm_asm) + { + nb_norm_asm = 0; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { +// PRINTF1("%lld\n", localTime) + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F0; + } + } + + //************************* + // send the message to MATR + if (msgForMATR.event != 0x00) + { + status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0); + } + + if (status != RTEMS_SUCCESSFUL) { + printf("in AVF0 *** Error sending message to MATR, code %d\n", status); + } + } +} + +rtems_task prc0_task( rtems_task_argument lfrRequestedMode ) +{ + char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer + size_t size; // size of the incoming TC packet + asm_msg *incomingMsg; + // + unsigned char sid; + spw_ioctl_pkt_send spw_ioctl_send_ASM; + rtems_status_code status; + rtems_id queue_id; + rtems_id queue_id_q_p0; + Header_TM_LFR_SCIENCE_ASM_t headerASM; + bp_packet_with_spare packet_norm_bp1_f0; + bp_packet packet_norm_bp2_f0; + bp_packet packet_sbm_bp1_f0; + bp_packet packet_sbm_bp2_f0; + + unsigned long long int localTime; + + ASM_init_header( &headerASM ); + + //************* + // NORM headers + BP_init_header_with_spare( &packet_norm_bp1_f0.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 ); + BP_init_header( &packet_norm_bp2_f0.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0); + + //**************************** + // BURST SBM1 and SBM2 headers + if ( lfrRequestedMode == LFR_MODE_BURST ) + { + BP_init_header( &packet_sbm_bp1_f0.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); + BP_init_header( &packet_sbm_bp2_f0.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); + } + else if ( lfrRequestedMode == LFR_MODE_SBM1 ) + { + BP_init_header( &packet_sbm_bp1_f0.header, + APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); + BP_init_header( &packet_sbm_bp2_f0.header, + APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); + } + else if ( lfrRequestedMode == LFR_MODE_SBM2 ) + { + BP_init_header( &packet_sbm_bp1_f0.header, + APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); + BP_init_header( &packet_sbm_bp2_f0.header, + APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); + } + else + { + PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode) + } + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status) + } + status = get_message_queue_id_prc0( &queue_id_q_p0); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status) + } + + BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) + + while(1){ + status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************ + RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 + + incomingMsg = (asm_msg*) incomingData; + + localTime = getTimeAsUnsignedLongLongInt( ); + + //**************** + //**************** + // BURST SBM1 SBM2 + //**************** + //**************** + if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) ) + { + sid = getSID( incomingMsg->event ); + // 1) compress the matrix for Basic Parameters calculation + ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f0, + nb_sm_before_f0.burst_sbm_bp1, + NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0, + ASM_F0_INDICE_START); + // 2) compute the BP1 set +// BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, bp1_sbm_f0 ); + // 3) send the BP1 set + set_time( packet_sbm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_sbm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_sbm_bp1_f0, queue_id, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA, + sid); + // 4) compute the BP2 set if needed + if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) ) + { + // 1) compute the BP2 set + + // 2) send the BP2 set + set_time( packet_sbm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_sbm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_sbm_bp2_f0, queue_id, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA, + sid); + } + } + + //***** + //***** + // NORM + //***** + //***** + if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0) + { + // 1) compress the matrix for Basic Parameters calculation + ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f0, + nb_sm_before_f0.norm_bp1, + NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0, + ASM_F0_INDICE_START ); + // 2) compute the BP1 set +// BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, bp1_norm_f0 ); + // 3) send the BP1 set + set_time( packet_norm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_norm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_norm_bp1_f0, queue_id, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA, + SID_NORM_BP1_F0 ); + if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0) + { + // 1) compute the BP2 set using the same ASM as the one used for BP1 + + // 2) send the BP2 set + set_time( packet_norm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_norm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_norm_bp2_f0, queue_id, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA, + SID_NORM_BP2_F0); + } + } + + if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0) + { + // 1) reorganize the ASM and divide + ASM_reorganize_and_divide( incomingMsg->norm->matrix, + asm_f0_reorganized, + nb_sm_before_f0.norm_bp1 ); + // 2) convert the float array in a char array + ASM_convert( asm_f0_reorganized, asm_f0_char); + // 3) send the spectral matrix packets + set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime ); + set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + ASM_send( &headerASM, asm_f0_char, SID_NORM_ASM_F0, &spw_ioctl_send_ASM, queue_id); + } + + } +} + +//********** +// FUNCTIONS + +void reset_nb_sm_f0( unsigned char lfrMode ) +{ + nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96; + nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96; + nb_sm_before_f0.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 96; + nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit + nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96; + nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96; + nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96; + nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96; + nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96; + + if (lfrMode == LFR_MODE_SBM1) + { + nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1; + nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2; + } + else if (lfrMode == LFR_MODE_SBM2) + { + nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1; + nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2; + } + else if (lfrMode == LFR_MODE_BURST) + { + nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1; + nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2; + } + else + { + nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1; + nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2; + } +} diff --git a/timegen/src/processing/avf1_prc1.c b/timegen/src/processing/avf1_prc1.c new file mode 100644 --- /dev/null +++ b/timegen/src/processing/avf1_prc1.c @@ -0,0 +1,360 @@ +/** Functions related to data processing. + * + * @file + * @author P. LEROY + * + * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. + * + */ + +#include "avf1_prc1.h" + +nb_sm_before_bp_asm_f1 nb_sm_before_f1; + +//*** +// F1 +ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ]; +ring_node_asm asm_ring_burst_sbm_f1[ NB_RING_NODES_ASM_BURST_SBM_F1 ]; + +float asm_f1_reorganized [ TOTAL_SIZE_SM ]; +char asm_f1_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ]; +float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1]; +float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ]; + +//************ +// RTEMS TASKS + +rtems_task avf1_task( rtems_task_argument lfrRequestedMode ) +{ + int i; + + rtems_event_set event_out; + rtems_status_code status; + rtems_id queue_id_prc1; + asm_msg msgForMATR; + ring_node_sm *ring_node_tab[8]; + ring_node_asm *current_ring_node_asm_burst_sbm_f1; + ring_node_asm *current_ring_node_asm_norm_f1; + + unsigned int nb_norm_bp1; + unsigned int nb_norm_bp2; + unsigned int nb_norm_asm; + unsigned int nb_sbm_bp1; + unsigned int nb_sbm_bp2; + + nb_norm_bp1 = 0; + nb_norm_bp2 = 0; + nb_norm_asm = 0; + nb_sbm_bp1 = 0; + nb_sbm_bp2 = 0; + + reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions + ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 ); + ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 ); + current_ring_node_asm_norm_f1 = asm_ring_norm_f1; + current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1; + + BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) + + status = get_message_queue_id_prc1( &queue_id_prc1 ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status) + } + + while(1){ + rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 + + //**************************************** + // initialize the mesage for the MATR task + msgForMATR.event = 0x00; // this composite event will be sent to the PRC1 task + msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f1; + msgForMATR.norm = current_ring_node_asm_norm_f1; + msgForMATR.coarseTime = ring_node_for_averaging_sm_f1->coarseTime; + msgForMATR.fineTime = ring_node_for_averaging_sm_f1->fineTime; + // + //**************************************** + + ring_node_tab[NB_SM_BEFORE_AVF1-1] = ring_node_for_averaging_sm_f1; + for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ ) + { + ring_node_for_averaging_sm_f1 = ring_node_for_averaging_sm_f1->previous; + ring_node_tab[NB_SM_BEFORE_AVF1-i] = ring_node_for_averaging_sm_f1; + } + + // compute the average and store it in the averaged_sm_f1 buffer + SM_average( current_ring_node_asm_norm_f1->matrix, + current_ring_node_asm_burst_sbm_f1->matrix, + ring_node_tab, + nb_norm_bp1, nb_sbm_bp1 ); + + // update nb_average + nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1; + nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1; + nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1; + nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1; + nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1; + + if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1) + { + nb_sbm_bp1 = 0; + // set another ring for the ASM storage + current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next; + if ( lfrCurrentMode == LFR_MODE_BURST ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F1; + } + else if ( lfrCurrentMode == LFR_MODE_SBM2 ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F1; + } + } + + if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2) + { + nb_sbm_bp2 = 0; + if ( lfrCurrentMode == LFR_MODE_BURST ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F1; + } + else if ( lfrCurrentMode == LFR_MODE_SBM2 ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F1; + } + } + + if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1) + { + nb_norm_bp1 = 0; + // set another ring for the ASM storage + current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F1; + } + } + + if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2) + { + nb_norm_bp2 = 0; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F1; + } + } + + if (nb_norm_asm == nb_sm_before_f1.norm_asm) + { + nb_norm_asm = 0; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F1; + } + } + + //************************* + // send the message to MATR + if (msgForMATR.event != 0x00) + { + status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC1); + } + + if (status != RTEMS_SUCCESSFUL) { + printf("in AVF1 *** Error sending message to PRC1, code %d\n", status); + } + } +} + +rtems_task prc1_task( rtems_task_argument lfrRequestedMode ) +{ + char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer + size_t size; // size of the incoming TC packet + asm_msg *incomingMsg; + // + unsigned char sid; + spw_ioctl_pkt_send spw_ioctl_send_ASM; + rtems_status_code status; + rtems_id queue_id_send; + rtems_id queue_id_q_p1; + Header_TM_LFR_SCIENCE_ASM_t headerASM; + bp_packet_with_spare packet_norm_bp1; + bp_packet packet_norm_bp2; + bp_packet packet_sbm_bp1; + bp_packet packet_sbm_bp2; + + unsigned long long int localTime; + + ASM_init_header( &headerASM ); + + //************* + // NORM headers + BP_init_header_with_spare( &packet_norm_bp1.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 ); + BP_init_header( &packet_norm_bp2.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1); + + //*********************** + // BURST and SBM2 headers + if ( lfrRequestedMode == LFR_MODE_BURST ) + { + BP_init_header( &packet_sbm_bp1.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1); + BP_init_header( &packet_sbm_bp2.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1); + } + else if ( lfrRequestedMode == LFR_MODE_SBM2 ) + { + BP_init_header( &packet_sbm_bp1.header, + APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1); + BP_init_header( &packet_sbm_bp2.header, + APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1); + } + else + { + PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode) + } + + status = get_message_queue_id_send( &queue_id_send ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status) + } + status = get_message_queue_id_prc1( &queue_id_q_p1); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status) + } + + BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) + + while(1){ + status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************ + RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 + + incomingMsg = (asm_msg*) incomingData; + + localTime = getTimeAsUnsignedLongLongInt( ); + //*********** + //*********** + // BURST SBM2 + //*********** + //*********** + if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) ) + { + sid = getSID( incomingMsg->event ); + // 1) compress the matrix for Basic Parameters calculation + ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f1, + nb_sm_before_f1.burst_sbm_bp1, + NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1, + ASM_F1_INDICE_START); + // 2) compute the BP1 set + + // 3) send the BP1 set + set_time( packet_sbm_bp1.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_sbm_bp1.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_sbm_bp1, queue_id_send, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA, + sid ); + // 4) compute the BP2 set if needed + if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) ) + { + // 1) compute the BP2 set + + // 2) send the BP2 set + set_time( packet_sbm_bp2.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_sbm_bp2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_sbm_bp2, queue_id_send, + PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA, + sid ); + } + } + + //***** + //***** + // NORM + //***** + //***** + if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1) + { + // 1) compress the matrix for Basic Parameters calculation + ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f1, + nb_sm_before_f1.norm_bp1, + NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0, + ASM_F0_INDICE_START ); + // 2) compute the BP1 set + + // 3) send the BP1 set + set_time( packet_norm_bp1.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_norm_bp1.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_norm_bp1, queue_id_send, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA, + SID_NORM_BP1_F1 ); + if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1) + { + // 1) compute the BP2 set + + // 2) send the BP2 set + set_time( packet_norm_bp2.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_norm_bp2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_norm_bp2, queue_id_send, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA, + SID_NORM_BP2_F1 ); + } + } + + if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1) + { + // 1) reorganize the ASM and divide + ASM_reorganize_and_divide( incomingMsg->norm->matrix, + asm_f1_reorganized, + nb_sm_before_f1.norm_bp1 ); + // 2) convert the float array in a char array + ASM_convert( asm_f1_reorganized, asm_f1_char); + // 3) send the spectral matrix packets + set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime ); + set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + ASM_send( &headerASM, asm_f1_char, SID_NORM_ASM_F1, &spw_ioctl_send_ASM, queue_id_send); + } + + } +} + +//********** +// FUNCTIONS + +void reset_nb_sm_f1( unsigned char lfrMode ) +{ + nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16; + nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16; + nb_sm_before_f1.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 16; + nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16; + nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16; + nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16; + nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16; + + if (lfrMode == LFR_MODE_SBM2) + { + nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1; + nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2; + } + else if (lfrMode == LFR_MODE_BURST) + { + nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1; + nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2; + } + else + { + nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1; + nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2; + } +} + diff --git a/timegen/src/processing/avf2_prc2.c b/timegen/src/processing/avf2_prc2.c new file mode 100644 --- /dev/null +++ b/timegen/src/processing/avf2_prc2.c @@ -0,0 +1,255 @@ +/** Functions related to data processing. + * + * @file + * @author P. LEROY + * + * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. + * + */ + +#include "avf2_prc2.h" + +nb_sm_before_bp_asm_f2 nb_sm_before_f2; + +//*** +// F2 +ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ]; +ring_node_asm asm_ring_burst_sbm_f2[ NB_RING_NODES_ASM_BURST_SBM_F2 ]; + +float asm_f2_reorganized [ TOTAL_SIZE_SM ]; +char asm_f2_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ]; +float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2]; +float compressed_sm_sbm_f2 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F2 ]; + +//************ +// RTEMS TASKS + +//*** +// F2 +rtems_task avf2_task( rtems_task_argument argument ) +{ + rtems_event_set event_out; + rtems_status_code status; + rtems_id queue_id_prc2; + asm_msg msgForMATR; + ring_node_asm *current_ring_node_asm_norm_f2; + + unsigned int nb_norm_bp1; + unsigned int nb_norm_bp2; + unsigned int nb_norm_asm; + + nb_norm_bp1 = 0; + nb_norm_bp2 = 0; + nb_norm_asm = 0; + + reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions + ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 ); + current_ring_node_asm_norm_f2 = asm_ring_norm_f2; + + BOOT_PRINTF("in AVF2 ***\n") + + status = get_message_queue_id_prc2( &queue_id_prc2 ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status) + } + + while(1){ + rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 + + //**************************************** + // initialize the mesage for the MATR task + msgForMATR.event = 0x00; // this composite event will be sent to the MATR task + msgForMATR.burst_sbm = NULL; + msgForMATR.norm = current_ring_node_asm_norm_f2; + msgForMATR.coarseTime = ring_node_for_averaging_sm_f2->coarseTime; + msgForMATR.fineTime = ring_node_for_averaging_sm_f2->fineTime; + // + //**************************************** + + // compute the average and store it in the averaged_sm_f2 buffer + SM_average_f2( current_ring_node_asm_norm_f2->matrix, + ring_node_for_averaging_sm_f2, + nb_norm_bp1 ); + + // update nb_average + nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2; + nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2; + nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2; + + if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1) + { + nb_norm_bp1 = 0; + // set another ring for the ASM storage + current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) + || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F2; + } + } + + if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2) + { + nb_norm_bp2 = 0; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) + || (lfrCurrentMode == LFR_MODE_SBM2) ) + { + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F2; + } + } + + if (nb_norm_asm == nb_sm_before_f2.norm_asm) + { + nb_norm_asm = 0; + if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) + || (lfrCurrentMode == LFR_MODE_SBM2) ) + { +// PRINTF1("%lld\n", localTime) + msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F2; + } + } + + //************************* + // send the message to MATR + if (msgForMATR.event != 0x00) + { + status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0); + } + + if (status != RTEMS_SUCCESSFUL) { + printf("in AVF2 *** Error sending message to MATR, code %d\n", status); + } + } +} + +rtems_task prc2_task( rtems_task_argument argument ) +{ + char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer + size_t size; // size of the incoming TC packet + asm_msg *incomingMsg; + // + spw_ioctl_pkt_send spw_ioctl_send_ASM; + rtems_status_code status; + rtems_id queue_id; + rtems_id queue_id_q_p2; + Header_TM_LFR_SCIENCE_ASM_t headerASM; + bp_packet packet_norm_bp1_f2; + bp_packet packet_norm_bp2_f2; + + unsigned long long int localTime; + + incomingMsg = NULL; + + ASM_init_header( &headerASM ); + + //************* + // NORM headers + BP_init_header( &packet_norm_bp1_f2.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 ); + BP_init_header( &packet_norm_bp2_f2.header, + APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 ); + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status) + } + status = get_message_queue_id_prc2( &queue_id_q_p2); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status) + } + + BOOT_PRINTF("in PRC2 ***\n") + + while(1){ + status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************ + RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 + + incomingMsg = (asm_msg*) incomingData; + + localTime = getTimeAsUnsignedLongLongInt( ); + + //***** + //***** + // NORM + //***** + //***** + if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2) + { + // 1) compress the matrix for Basic Parameters calculation + ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f2, + nb_sm_before_f2.norm_bp1, + NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2, + ASM_F2_INDICE_START ); + // 2) compute the BP1 set + + // 3) send the BP1 set + set_time( packet_norm_bp1_f2.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_norm_bp1_f2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_norm_bp1_f2, queue_id, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA, + SID_NORM_BP1_F2 ); + if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2) + { + // 1) compute the BP2 set using the same ASM as the one used for BP1 + + // 2) send the BP2 set + set_time( packet_norm_bp2_f2.header.time, (unsigned char *) &incomingMsg->coarseTime ); + set_time( packet_norm_bp2_f2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + BP_send( (char *) &packet_norm_bp2_f2, queue_id, + PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA, + SID_NORM_BP2_F2 ); + } + } + + if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2) + { + // 1) reorganize the ASM and divide + ASM_reorganize_and_divide( incomingMsg->norm->matrix, + asm_f2_reorganized, + nb_sm_before_f2.norm_bp1 ); + // 2) convert the float array in a char array + ASM_convert( asm_f2_reorganized, asm_f2_char); + // 3) send the spectral matrix packets + set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime ); + set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); + ASM_send( &headerASM, asm_f2_char, SID_NORM_ASM_F2, &spw_ioctl_send_ASM, queue_id); + } + + } +} + +//********** +// FUNCTIONS + +void reset_nb_sm_f2( void ) +{ + nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0; + nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1; + nb_sm_before_f2.norm_asm = parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]; +} + +void SM_average_f2( float *averaged_spec_mat_f2, + ring_node_sm *ring_node, + unsigned int nbAverageNormF2 ) +{ + float sum; + unsigned int i; + + for(i=0; i buffer_address) ) [ i ]; + if ( (nbAverageNormF2 == 0) ) + { + averaged_spec_mat_f2[ i ] = sum; + } + else + { + averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum ); + } + } +} diff --git a/timegen/src/processing/fsw_processing.c b/timegen/src/processing/fsw_processing.c new file mode 100644 --- /dev/null +++ b/timegen/src/processing/fsw_processing.c @@ -0,0 +1,696 @@ +/** Functions related to data processing. + * + * @file + * @author P. LEROY + * + * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. + * + */ + +#include "fsw_processing.h" +#include "fsw_processing_globals.c" + +unsigned int nb_sm_f0; +unsigned int nb_sm_f0_aux_f1; +unsigned int nb_sm_f1; +unsigned int nb_sm_f0_aux_f2; + +//************************ +// spectral matrices rings +ring_node_sm sm_ring_f0[ NB_RING_NODES_SM_F0 ]; +ring_node_sm sm_ring_f1[ NB_RING_NODES_SM_F1 ]; +ring_node_sm sm_ring_f2[ NB_RING_NODES_SM_F2 ]; +ring_node_sm *current_ring_node_sm_f0; +ring_node_sm *current_ring_node_sm_f1; +ring_node_sm *current_ring_node_sm_f2; +ring_node_sm *ring_node_for_averaging_sm_f0; +ring_node_sm *ring_node_for_averaging_sm_f1; +ring_node_sm *ring_node_for_averaging_sm_f2; + +//*********************************************************** +// Interrupt Service Routine for spectral matrices processing + +void spectral_matrices_isr_f0( void ) +{ + unsigned char status; + unsigned long long int time_0; + unsigned long long int time_1; + unsigned long long int syncBit0; + unsigned long long int syncBit1; + + status = spectral_matrix_regs->status & 0x03; // [0011] get the status_ready_matrix_f0_x bits + + time_0 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_0_coarse_time ); + time_1 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_1_coarse_time ); + syncBit0 = ( (unsigned long long int) (spectral_matrix_regs->f0_0_coarse_time & 0x80000000) ) << 16; + syncBit1 = ( (unsigned long long int) (spectral_matrix_regs->f0_1_coarse_time & 0x80000000) ) << 16; + + switch(status) + { + case 0: + break; + case 3: + if ( time_0 < time_1 ) + { + close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], + ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0); + current_ring_node_sm_f0 = current_ring_node_sm_f0->next; + spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address; + close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], + ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1); + current_ring_node_sm_f0 = current_ring_node_sm_f0->next; + spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; + } + else + { + close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], + ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1); + current_ring_node_sm_f0 = current_ring_node_sm_f0->next; + spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; + close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], + ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0); + current_ring_node_sm_f0 = current_ring_node_sm_f0->next; + spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address; + } + spectral_matrix_regs->status = 0x03; // [0011] + break; + case 1: + close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], + ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0); + current_ring_node_sm_f0 = current_ring_node_sm_f0->next; + spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address; + spectral_matrix_regs->status = 0x01; // [0001] + break; + case 2: + close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], + ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1); + current_ring_node_sm_f0 = current_ring_node_sm_f0->next; + spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; + spectral_matrix_regs->status = 0x02; // [0010] + break; + } +} + +void spectral_matrices_isr_f1( void ) +{ + unsigned char status; + unsigned long long int time; + unsigned long long int syncBit; + rtems_status_code status_code; + + status = (spectral_matrix_regs->status & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits + + switch(status) + { + case 0: + break; + case 3: + // UNEXPECTED VALUE + spectral_matrix_regs->status = 0xc0; // [1100] + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 ); + break; + case 1: + time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_0_coarse_time ); + syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_0_coarse_time & 0x80000000) ) << 16; + close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], + ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit); + current_ring_node_sm_f1 = current_ring_node_sm_f1->next; + spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address; + spectral_matrix_regs->status = 0x04; // [0100] + break; + case 2: + time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_1_coarse_time ); + syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_1_coarse_time & 0x80000000) ) << 16; + close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], + ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit); + current_ring_node_sm_f1 = current_ring_node_sm_f1->next; + spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address; + spectral_matrix_regs->status = 0x08; // [1000] + break; + } +} + +void spectral_matrices_isr_f2( void ) +{ + unsigned char status; + rtems_status_code status_code; + + status = (spectral_matrix_regs->status & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits + + ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2; + + current_ring_node_sm_f2 = current_ring_node_sm_f2->next; + + switch(status) + { + case 0: + break; + case 3: + // UNEXPECTED VALUE + spectral_matrix_regs->status = 0x30; // [0011 0000] + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 ); + break; + case 1: + ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time; + ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time; + spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address; + spectral_matrix_regs->status = 0x10; // [0001 0000] + if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) + { + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); + } + break; + case 2: + ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time; + ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time; + spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address; + spectral_matrix_regs->status = 0x20; // [0010 0000] + if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) + { + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); + } + break; + } +} + +void spectral_matrix_isr_error_handler( void ) +{ + rtems_status_code status_code; + + if (spectral_matrix_regs->status & 0x7c0) // [0111 1100 0000] + { + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 ); + } +} + +rtems_isr spectral_matrices_isr( rtems_vector_number vector ) +{ + // STATUS REGISTER + // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0) + // 10 9 8 + // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0 + // 7 6 5 4 3 2 1 0 + + spectral_matrices_isr_f0(); + + spectral_matrices_isr_f1(); + + spectral_matrices_isr_f2(); + +// spectral_matrix_isr_error_handler(); +} + +rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector ) +{ + rtems_status_code status_code; + + //*** + // F0 + nb_sm_f0 = nb_sm_f0 + 1; + if (nb_sm_f0 == NB_SM_BEFORE_AVF0 ) + { + ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0; + if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) + { + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); + } + nb_sm_f0 = 0; + } + + //*** + // F1 + nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1; + if (nb_sm_f0_aux_f1 == 6) + { + nb_sm_f0_aux_f1 = 0; + nb_sm_f1 = nb_sm_f1 + 1; + } + if (nb_sm_f1 == NB_SM_BEFORE_AVF1 ) + { + ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1; + if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) + { + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); + } + nb_sm_f1 = 0; + } + + //*** + // F2 + nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1; + if (nb_sm_f0_aux_f2 == 96) + { + nb_sm_f0_aux_f2 = 0; + ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2; + if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) + { + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); + } + } +} + +//****************** +// Spectral Matrices + +void reset_nb_sm( void ) +{ + nb_sm_f0 = 0; + nb_sm_f0_aux_f1 = 0; + nb_sm_f0_aux_f2 = 0; + + nb_sm_f1 = 0; +} + +void SM_init_rings( void ) +{ + unsigned char i; + + // F0 RING + sm_ring_f0[0].next = (ring_node_sm*) &sm_ring_f0[1]; + sm_ring_f0[0].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-1]; + sm_ring_f0[0].buffer_address = + (int) &sm_f0[ 0 ]; + + sm_ring_f0[NB_RING_NODES_SM_F0-1].next = (ring_node_sm*) &sm_ring_f0[0]; + sm_ring_f0[NB_RING_NODES_SM_F0-1].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-2]; + sm_ring_f0[NB_RING_NODES_SM_F0-1].buffer_address = + (int) &sm_f0[ (NB_RING_NODES_SM_F0-1) * TOTAL_SIZE_SM ]; + + for(i=1; i f0_0_address = sm_ring_f0[0].buffer_address; + DEBUG_PRINTF1("spectral_matrix_regs->matrixF0_Address0 @%x\n", spectral_matrix_regs->f0_0_address) +} + +void SM_generic_init_ring( ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] ) +{ + unsigned char i; + + //*************** + // BUFFER ADDRESS + for(i=0; i targetLogicalAddress = CCSDS_DESTINATION_ID; + header->protocolIdentifier = CCSDS_PROTOCOLE_ID; + header->reserved = 0x00; + header->userApplication = CCSDS_USER_APP; + header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); + header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); + header->packetSequenceControl[0] = 0xc0; + header->packetSequenceControl[1] = 0x00; + header->packetLength[0] = 0x00; + header->packetLength[1] = 0x00; + // DATA FIELD HEADER + header->spare1_pusVersion_spare2 = 0x10; + header->serviceType = TM_TYPE_LFR_SCIENCE; // service type + header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype + header->destinationID = TM_DESTINATION_ID_GROUND; + // AUXILIARY DATA HEADER + header->sid = 0x00; + header->biaStatusInfo = 0x00; + header->pa_lfr_pkt_cnt_asm = 0x00; + header->pa_lfr_pkt_nr_asm = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->pa_lfr_asm_blk_nr[0] = 0x00; // BLK_NR MSB + header->pa_lfr_asm_blk_nr[1] = 0x00; // BLK_NR LSB +} + +void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix, + unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id) +{ + unsigned int i; + unsigned int length = 0; + rtems_status_code status; + + for (i=0; i<2; i++) + { + // (1) BUILD THE DATA + switch(sid) + { + case SID_NORM_ASM_F0: + spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F0_IN_BYTES / 2; // 2 packets will be sent + spw_ioctl_send->data = &spectral_matrix[ + ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0) ) * NB_VALUES_PER_SM ) * 2 + ]; + length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0; + header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0) >> 8 ); // BLK_NR MSB + header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0); // BLK_NR LSB + break; + case SID_NORM_ASM_F1: + spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F1_IN_BYTES / 2; // 2 packets will be sent + spw_ioctl_send->data = &spectral_matrix[ + ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1) ) * NB_VALUES_PER_SM ) * 2 + ]; + length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1; + header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1) >> 8 ); // BLK_NR MSB + header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1); // BLK_NR LSB + break; + case SID_NORM_ASM_F2: + spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F2_IN_BYTES / 2; // 2 packets will be sent + spw_ioctl_send->data = &spectral_matrix[ + ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) * 2 + ]; + length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; + header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB + header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB + break; + default: + PRINTF1("ERR *** in ASM_send *** unexpected sid %d\n", sid) + break; + } + spw_ioctl_send->hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM + CCSDS_PROTOCOLE_EXTRA_BYTES; + spw_ioctl_send->hdr = (char *) header; + spw_ioctl_send->options = 0; + + // (2) BUILD THE HEADER + increment_seq_counter_source_id( header->packetSequenceControl, sid ); + header->packetLength[0] = (unsigned char) (length>>8); + header->packetLength[1] = (unsigned char) (length); + header->sid = (unsigned char) sid; // SID + header->pa_lfr_pkt_cnt_asm = 2; + header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); + + // (3) SET PACKET TIME + header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + header->time[3] = (unsigned char) (time_management_regs->coarse_time); + header->time[4] = (unsigned char) (time_management_regs->fine_time>>8); + header->time[5] = (unsigned char) (time_management_regs->fine_time); + // + header->acquisitionTime[0] = header->time[0]; + header->acquisitionTime[1] = header->time[1]; + header->acquisitionTime[2] = header->time[2]; + header->acquisitionTime[3] = header->time[3]; + header->acquisitionTime[4] = header->time[4]; + header->acquisitionTime[5] = header->time[5]; + + // (4) SEND PACKET + status = rtems_message_queue_send( queue_id, spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE); + if (status != RTEMS_SUCCESSFUL) { + printf("in ASM_send *** ERR %d\n", (int) status); + } + } +} + +//***************** +// Basic Parameters + +void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header, + unsigned int apid, unsigned char sid, + unsigned int packetLength, unsigned char blkNr ) +{ + header->targetLogicalAddress = CCSDS_DESTINATION_ID; + header->protocolIdentifier = CCSDS_PROTOCOLE_ID; + header->reserved = 0x00; + header->userApplication = CCSDS_USER_APP; + header->packetID[0] = (unsigned char) (apid >> 8); + header->packetID[1] = (unsigned char) (apid); + header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; + header->packetSequenceControl[1] = 0x00; + header->packetLength[0] = (unsigned char) (packetLength >> 8); + header->packetLength[1] = (unsigned char) (packetLength); + // DATA FIELD HEADER + header->spare1_pusVersion_spare2 = 0x10; + header->serviceType = TM_TYPE_LFR_SCIENCE; // service type + header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype + header->destinationID = TM_DESTINATION_ID_GROUND; + // AUXILIARY DATA HEADER + header->sid = sid; + header->biaStatusInfo = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB + header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB +} + +void BP_init_header_with_spare(Header_TM_LFR_SCIENCE_BP_with_spare_t *header, + unsigned int apid, unsigned char sid, + unsigned int packetLength , unsigned char blkNr) +{ + header->targetLogicalAddress = CCSDS_DESTINATION_ID; + header->protocolIdentifier = CCSDS_PROTOCOLE_ID; + header->reserved = 0x00; + header->userApplication = CCSDS_USER_APP; + header->packetID[0] = (unsigned char) (apid >> 8); + header->packetID[1] = (unsigned char) (apid); + header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; + header->packetSequenceControl[1] = 0x00; + header->packetLength[0] = (unsigned char) (packetLength >> 8); + header->packetLength[1] = (unsigned char) (packetLength); + // DATA FIELD HEADER + header->spare1_pusVersion_spare2 = 0x10; + header->serviceType = TM_TYPE_LFR_SCIENCE; // service type + header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype + header->destinationID = TM_DESTINATION_ID_GROUND; + // AUXILIARY DATA HEADER + header->sid = sid; + header->biaStatusInfo = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->time[0] = 0x00; + header->source_data_spare = 0x00; + header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB + header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB +} + +void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid ) +{ + rtems_status_code status; + + // SET THE SEQUENCE_CNT PARAMETER + increment_seq_counter_source_id( (unsigned char*) &data[ PACKET_POS_SEQUENCE_CNT ], sid ); + // SEND PACKET + status = rtems_message_queue_send( queue_id, data, nbBytesToSend); + if (status != RTEMS_SUCCESSFUL) + { + printf("ERR *** in BP_send *** ERR %d\n", (int) status); + } +} + +//****************** +// general functions + +void reset_spectral_matrix_regs( void ) +{ + /** This function resets the spectral matrices module registers. + * + * The registers affected by this function are located at the following offset addresses: + * + * - 0x00 config + * - 0x04 status + * - 0x08 matrixF0_Address0 + * - 0x10 matrixFO_Address1 + * - 0x14 matrixF1_Address + * - 0x18 matrixF2_Address + * + */ + + spectral_matrix_regs->config = 0x00; + spectral_matrix_regs->status = 0x00; + + spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address; + spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; + spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address; + spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address; + spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address; + spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address; +} + +void set_time( unsigned char *time, unsigned char * timeInBuffer ) +{ + time[0] = timeInBuffer[0]; + time[1] = timeInBuffer[1]; + time[2] = timeInBuffer[2]; + time[3] = timeInBuffer[3]; + time[4] = timeInBuffer[6]; + time[5] = timeInBuffer[7]; +} + +unsigned long long int get_acquisition_time( unsigned char *timePtr ) +{ + unsigned long long int acquisitionTimeAslong; + acquisitionTimeAslong = 0x00; + acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit + + ( (unsigned long long int) timePtr[1] << 32 ) + + ( (unsigned long long int) timePtr[2] << 24 ) + + ( (unsigned long long int) timePtr[3] << 16 ) + + ( (unsigned long long int) timePtr[6] << 8 ) + + ( (unsigned long long int) timePtr[7] ); + return acquisitionTimeAslong; +} + +void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id, + ring_node_sm *node_for_averaging, ring_node_sm *ringNode, + unsigned long long int time ) +{ + unsigned char *timePtr; + unsigned char *coarseTimePtr; + unsigned char *fineTimePtr; + rtems_status_code status_code; + + timePtr = (unsigned char *) &time; + coarseTimePtr = (unsigned char *) &node_for_averaging->coarseTime; + fineTimePtr = (unsigned char *) &node_for_averaging->fineTime; + + *nb_sm = *nb_sm + 1; + if (*nb_sm == nb_sm_before_avf) + { + node_for_averaging = ringNode; + coarseTimePtr[0] = timePtr[2]; + coarseTimePtr[1] = timePtr[3]; + coarseTimePtr[2] = timePtr[4]; + coarseTimePtr[3] = timePtr[5]; + fineTimePtr[2] = timePtr[6]; + fineTimePtr[3] = timePtr[7]; + if (rtems_event_send( avf_task_id, RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) + { + status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); + } + *nb_sm = 0; + } +} + +unsigned char getSID( rtems_event_set event ) +{ + unsigned char sid; + + rtems_event_set eventSetBURST; + rtems_event_set eventSetSBM; + + //****** + // BURST + eventSetBURST = RTEMS_EVENT_BURST_BP1_F0 + | RTEMS_EVENT_BURST_BP1_F1 + | RTEMS_EVENT_BURST_BP2_F0 + | RTEMS_EVENT_BURST_BP2_F1; + + //**** + // SBM + eventSetSBM = RTEMS_EVENT_SBM_BP1_F0 + | RTEMS_EVENT_SBM_BP1_F1 + | RTEMS_EVENT_SBM_BP2_F0 + | RTEMS_EVENT_SBM_BP2_F1; + + if (event & eventSetBURST) + { + sid = SID_BURST_BP1_F0; + } + else if (event & eventSetSBM) + { + sid = SID_SBM1_BP1_F0; + } + else + { + sid = 0; + } + + return sid; +} + diff --git a/timegen/src/tc_acceptance.c b/timegen/src/tc_acceptance.c new file mode 100644 --- /dev/null +++ b/timegen/src/tc_acceptance.c @@ -0,0 +1,437 @@ +/** Functions related to TeleCommand acceptance. + * + * @file + * @author P. LEROY + * + * A group of functions to handle TeleCommands parsing.\n + * + */ + +#include "tc_acceptance.h" + +unsigned int lookUpTableForCRC[256]; + +//********************** +// GENERAL USE FUNCTIONS +unsigned int Crc_opt( unsigned char D, unsigned int Chk) +{ + /** This function generate the CRC for one byte and returns the value of the new syndrome. + * + * @param D is the current byte of data. + * @param Chk is the current syndrom value. + * + * @return the value of the new syndrome on two bytes. + * + */ + + return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]); +} + +void initLookUpTableForCRC( void ) +{ + /** This function is used to initiates the look-up table for fast CRC computation. + * + * The global table lookUpTableForCRC[256] is initiated. + * + */ + + unsigned int i; + unsigned int tmp; + + for (i=0; i<256; i++) + { + tmp = 0; + if((i & 1) != 0) { + tmp = tmp ^ 0x1021; + } + if((i & 2) != 0) { + tmp = tmp ^ 0x2042; + } + if((i & 4) != 0) { + tmp = tmp ^ 0x4084; + } + if((i & 8) != 0) { + tmp = tmp ^ 0x8108; + } + if((i & 16) != 0) { + tmp = tmp ^ 0x1231; + } + if((i & 32) != 0) { + tmp = tmp ^ 0x2462; + } + if((i & 64) != 0) { + tmp = tmp ^ 0x48c4; + } + if((i & 128) != 0) { + tmp = tmp ^ 0x9188; + } + lookUpTableForCRC[i] = tmp; + } +} + +void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData) +{ + /** This function calculates a two bytes Cyclic Redundancy Code. + * + * @param data points to a buffer containing the data on which to compute the CRC. + * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored. + * @param sizeOfData is the number of bytes of *data* used to compute the CRC. + * + * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A. + * + */ + + unsigned int Chk; + int j; + Chk = 0xffff; // reset the syndrom to all ones + for (j=0; j > 8); + crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff); +} + +//********************* +// ACCEPTANCE FUNCTIONS +int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC) +{ + /** This function parses TeleCommands. + * + * @param TC points to the TeleCommand that will be parsed. + * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet. + * + * @return Status code of the parsing. + * + * The parsing checks: + * - process id + * - category + * - length: a global check is performed and a per subtype check also + * - type + * - subtype + * - crc + * + */ + + int status; + int status_crc; + unsigned char pid; + unsigned char category; + unsigned int packetLength; + unsigned char packetType; + unsigned char packetSubtype; + unsigned char sid; + + status = CCSDS_TM_VALID; + + // APID check *** APID on 2 bytes + pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx + category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210 + packetLength = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1]; + packetType = TCPacket->serviceType; + packetSubtype = TCPacket->serviceSubType; + sid = TCPacket->sourceID; + + if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID + { + status = ILLEGAL_APID; + } + if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY + { + if ( category != CCSDS_PACKET_CATEGORY ) + { + status = ILLEGAL_APID; + } + } + if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE + { + if (packetLength != estimatedPacketLength ) { + status = WRONG_LEN_PKT; + } + } + if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE + { + if ( packetLength >= CCSDS_TC_PKT_MAX_SIZE ) { + status = WRONG_LEN_PKT; + } + } + if (status == CCSDS_TM_VALID) // CHECK THE TYPE + { + status = tc_check_type( packetType ); + } + if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE + { + status = tc_check_type_subtype( packetType, packetSubtype ); + } + if (status == CCSDS_TM_VALID) // CHECK THE SID + { + status = tc_check_sid( sid ); + } + if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE + { + status = tc_check_length( packetSubtype, packetLength ); + } + status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC ); + if (status == CCSDS_TM_VALID ) // CHECK CRC + { + status = status_crc; + } + + return status; +} + +int tc_check_type( unsigned char packetType ) +{ + /** This function checks that the type of a TeleCommand is valid. + * + * @param packetType is the type to check. + * + * @return Status code CCSDS_TM_VALID or ILL_TYPE. + * + */ + + int status; + + if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME)) + { + status = CCSDS_TM_VALID; + } + else + { + status = ILL_TYPE; + } + + return status; +} + +int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType ) +{ + /** This function checks that the subtype of a TeleCommand is valid and coherent with the type. + * + * @param packetType is the type of the TC. + * @param packetSubType is the subtype to check. + * + * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE. + * + */ + + int status; + + switch(packetType) + { + case TC_TYPE_GEN: + if ( (packetSubType == TC_SUBTYPE_RESET) + || (packetSubType == TC_SUBTYPE_LOAD_COMM) + || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST) + || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2) + || (packetSubType == TC_SUBTYPE_DUMP) + || (packetSubType == TC_SUBTYPE_ENTER) + || (packetSubType == TC_SUBTYPE_UPDT_INFO) + || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL) ) + { + status = CCSDS_TM_VALID; + } + else + { + status = ILL_SUBTYPE; + } + break; + + case TC_TYPE_TIME: + if (packetSubType == TC_SUBTYPE_UPDT_TIME) + { + status = CCSDS_TM_VALID; + } + else + { + status = ILL_SUBTYPE; + } + break; + + default: + status = ILL_SUBTYPE; + break; + } + + return status; +} + +int tc_check_sid( unsigned char sid ) +{ + /** This function checks that the sid of a TeleCommand is valid. + * + * @param sid is the sid to check. + * + * @return Status code CCSDS_TM_VALID or CORRUPTED. + * + */ + + int status; + + if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD) + || (sid == SID_TC_BACKUP_MISSION_TIMELINE) + || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2) + || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS) + || (sid == SID_TC_RPW_INTERNAL)) + { + status = CCSDS_TM_VALID; + } + else + { + status = WRONG_SRC_ID; + } + + return status; +} + +int tc_check_length( unsigned char packetSubType, unsigned int length ) +{ + /** This function checks that the subtype and the length are compliant. + * + * @param packetSubType is the subtype to check. + * @param length is the length to check. + * + * @return Status code CCSDS_TM_VALID or ILL_TYPE. + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + switch(packetSubType) + { + case TC_SUBTYPE_RESET: + if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_LOAD_COMM: + if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_LOAD_NORM: + if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_LOAD_BURST: + if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_LOAD_SBM1: + if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_LOAD_SBM2: + if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_DUMP: + if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_ENTER: + if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_UPDT_INFO: + if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_EN_CAL: + if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_DIS_CAL: + if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + case TC_SUBTYPE_UPDT_TIME: + if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) { + status = WRONG_LEN_PKT; + } + else { + status = CCSDS_TM_VALID; + } + break; + default: // if the subtype is not a legal value, return ILL_SUBTYPE + status = ILL_SUBTYPE; + break ; + } + + return status; +} + +int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC ) +{ + /** This function checks the CRC validity of the corresponding TeleCommand packet. + * + * @param TCPacket points to the TeleCommand packet to check. + * @param length is the length of the TC packet. + * + * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM. + * + */ + + int status; + unsigned char * CCSDSContent; + + CCSDSContent = (unsigned char*) TCPacket->packetID; + GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC + if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) { + status = INCOR_CHECKSUM; + } + else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) { + status = INCOR_CHECKSUM; + } + else { + status = CCSDS_TM_VALID; + } + + return status; +} + + + diff --git a/timegen/src/tc_handler.c b/timegen/src/tc_handler.c new file mode 100644 --- /dev/null +++ b/timegen/src/tc_handler.c @@ -0,0 +1,250 @@ +/** Functions and tasks related to TeleCommand handling. + * + * @file + * @author P. LEROY + * + * A group of functions to handle TeleCommands:\n + * action launching\n + * TC parsing\n + * ... + * + */ + +#include "tc_handler.h" + +//*********** +// RTEMS TASK + +unsigned int incomingTransitionCoarseTime; + +void reset_transitionCoarseTime( void ) +{ + incomingTransitionCoarseTime = 0xffffffff; +} + +void set_transitionCoarseTime( unsigned int value ) +{ + incomingTransitionCoarseTime = value; +} + +unsigned int get_transitionCoarseTime( void ) +{ + return incomingTransitionCoarseTime; +} + +rtems_task actn_task( rtems_task_argument unused ) +{ + /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. + * + * @param unused is the starting argument of the RTEMS task + * + * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending + * on the incoming TeleCommand. + * + */ + + int result; + rtems_status_code status; // RTEMS status code + ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task + size_t size; // size of the incoming TC packet + unsigned char subtype; // subtype of the current TC packet + unsigned char time[6]; + rtems_id queue_rcv_id; + rtems_id queue_snd_id; + + status = get_message_queue_id_recv( &queue_rcv_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) + } + + status = get_message_queue_id_send( &queue_snd_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) + } + + result = LFR_SUCCESSFUL; + subtype = 0; // subtype of the current TC packet + + BOOT_PRINTF("in ACTN *** \n") + + while(1) + { + status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, + RTEMS_WAIT, RTEMS_NO_TIMEOUT); + getTime( time ); // set time to the current time + if (status!=RTEMS_SUCCESSFUL) + { + PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) + } + else + { + subtype = TC.serviceSubType; + switch(subtype) + { + case TC_SUBTYPE_ENTER: + result = action_enter_mode( &TC, queue_snd_id ); + break; + case TC_SUBTYPE_UPDATE_TIME: + result = action_update_time( &TC ); + break; + default: + break; + } + } + } +} + +//*********** +// TC ACTIONS + +int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + return LFR_SUCCESSFUL; +} + +int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) +{ + unsigned int *transitionCoarseTime_ptr; + unsigned int transitionCoarseTime; + unsigned char * bytePosPtr; + + bytePosPtr = (unsigned char *) &TC->packetID; + + transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); + transitionCoarseTime = transitionCoarseTime_ptr[0] & 0x7fffffff; + printf("local coarse time (without sync bit) = %x, requested transitionCoarseTime = %x\n", + getLocalCoarseTime(), + transitionCoarseTime); + + set_transitionCoarseTime( transitionCoarseTime ); + + return LFR_SUCCESSFUL; +} + +int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) +{ + return LFR_SUCCESSFUL; +} + +int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + return LFR_SUCCESSFUL; +} + +int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + return LFR_SUCCESSFUL; +} + +int action_update_time(ccsdsTelecommandPacket_t *TC) +{ + unsigned int incomingCoarseTime; + unsigned int currentLocalCoarseTime; + + incomingCoarseTime = (TC->dataAndCRC[0] << 24) + + (TC->dataAndCRC[1] << 16) + + (TC->dataAndCRC[2] << 8) + + TC->dataAndCRC[3]; + + currentLocalCoarseTime = getLocalCoarseTime(); + setLocalCoarseTime( incomingCoarseTime ); + printf( "currentLocalCoarseTime = %x, localCoarseTime set to: %x\n", currentLocalCoarseTime, getLocalCoarseTime() ); + + return LFR_SUCCESSFUL; +} + +//******************* +// ENTERING THE MODES +int check_mode_value( unsigned char requestedMode ) +{ + return LFR_SUCCESSFUL; +} + +int check_mode_transition( unsigned char requestedMode ) +{ + return LFR_SUCCESSFUL; +} + +int check_transition_date( unsigned int transitionCoarseTime ) +{ + return LFR_SUCCESSFUL; +} + +int stop_current_mode( void ) +{ + return LFR_SUCCESSFUL; +} + +int enter_mode( unsigned char mode, unsigned int transitionCoarseTime ) +{ + return LFR_SUCCESSFUL; +} + +int restart_science_tasks(unsigned char lfrRequestedMode ) +{ + return LFR_SUCCESSFUL; +} + +int suspend_science_tasks() +{ + return LFR_SUCCESSFUL; +} + +void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) +{ +} + +void launch_spectral_matrix( void ) +{ +} + +void launch_spectral_matrix_simu( void ) +{ +} + +void set_irq_on_new_ready_matrix( unsigned char value ) +{ +} + +void set_run_matrix_spectral( unsigned char value ) +{ +} + +//**************** +// CLOSING ACTIONS +void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) +{ +} + +void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) +{ +} + +void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) +{ +} + +//*************************** +// Interrupt Service Routines +rtems_isr commutation_isr1( rtems_vector_number vector ) +{ + if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { + printf("In commutation_isr1 *** Error sending event to DUMB\n"); + } +} + +rtems_isr commutation_isr2( rtems_vector_number vector ) +{ + if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { + printf("In commutation_isr2 *** Error sending event to DUMB\n"); + } +} + +//**************** +// OTHER FUNCTIONS +void updateLFRCurrentMode() +{ +} + diff --git a/timegen/src/tc_load_dump_parameters.c b/timegen/src/tc_load_dump_parameters.c new file mode 100644 --- /dev/null +++ b/timegen/src/tc_load_dump_parameters.c @@ -0,0 +1,772 @@ +/** Functions to load and dump parameters in the LFR registers. + * + * @file + * @author P. LEROY + * + * A group of functions to handle TC related to parameter loading and dumping.\n + * TC_LFR_LOAD_COMMON_PAR\n + * TC_LFR_LOAD_NORMAL_PAR\n + * TC_LFR_LOAD_BURST_PAR\n + * TC_LFR_LOAD_SBM1_PAR\n + * TC_LFR_LOAD_SBM2_PAR\n + * + */ + +#include "tc_load_dump_parameters.h" + +int action_load_common_par(ccsdsTelecommandPacket_t *TC) +{ + /** This function updates the LFR registers with the incoming common parameters. + * + * @param TC points to the TeleCommand packet that is being processed + * + * + */ + + parameter_dump_packet.unused0 = TC->dataAndCRC[0]; + parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1]; + set_wfp_data_shaping( ); + return LFR_SUCCESSFUL; +} + +int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** This function updates the LFR registers with the incoming normal parameters. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int result; + int flag; + rtems_status_code status; + + flag = LFR_SUCCESSFUL; + + if ( (lfrCurrentMode == LFR_MODE_NORMAL) || + (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) { + status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); + flag = LFR_DEFAULT; + } + + // CHECK THE PARAMETERS SET CONSISTENCY + if (flag == LFR_SUCCESSFUL) + { + flag = check_common_par_consistency( TC, queue_id ); + } + + // SET THE PARAMETERS IF THEY ARE CONSISTENT + if (flag == LFR_SUCCESSFUL) + { + result = set_sy_lfr_n_swf_l( TC ); + result = set_sy_lfr_n_swf_p( TC ); + result = set_sy_lfr_n_bp_p0( TC ); + result = set_sy_lfr_n_bp_p1( TC ); + result = set_sy_lfr_n_asm_p( TC ); + result = set_sy_lfr_n_cwf_long_f3( TC ); + } + + return flag; +} + +int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** This function updates the LFR registers with the incoming burst parameters. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int flag; + rtems_status_code status; + unsigned char sy_lfr_b_bp_p0; + unsigned char sy_lfr_b_bp_p1; + float aux; + + flag = LFR_SUCCESSFUL; + + if ( lfrCurrentMode == LFR_MODE_BURST ) { + status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); + flag = LFR_DEFAULT; + } + + sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; + sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; + + // sy_lfr_b_bp_p0 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 ) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_b_bp_p1 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 ) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 ); + flag = WRONG_APP_DATA; + } + } + //**************************************************************** + // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1 + if (flag == LFR_SUCCESSFUL) + { + sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; + sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; + aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0); + if (aux > FLOAT_EQUAL_ZERO) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 ); + flag = LFR_DEFAULT; + } + } + + // SET HTE PARAMETERS + if (flag == LFR_SUCCESSFUL) + { + flag = set_sy_lfr_b_bp_p0( TC ); + flag = set_sy_lfr_b_bp_p1( TC ); + } + + return flag; +} + +int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** This function updates the LFR registers with the incoming sbm1 parameters. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int flag; + rtems_status_code status; + unsigned char sy_lfr_s1_bp_p0; + unsigned char sy_lfr_s1_bp_p1; + float aux; + + flag = LFR_SUCCESSFUL; + + if ( lfrCurrentMode == LFR_MODE_SBM1 ) { + status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); + flag = LFR_DEFAULT; + } + + sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ]; + sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ]; + + // sy_lfr_s1_bp_p0 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 ) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_s1_bp_p1 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 ) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 ); + flag = WRONG_APP_DATA; + } + } + //****************************************************************** + // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1 + if (flag == LFR_SUCCESSFUL) + { + aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25)); + if (aux > FLOAT_EQUAL_ZERO) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 ); + flag = LFR_DEFAULT; + } + } + + // SET THE PARAMETERS + if (flag == LFR_SUCCESSFUL) + { + flag = set_sy_lfr_s1_bp_p0( TC ); + flag = set_sy_lfr_s1_bp_p1( TC ); + } + + return flag; +} + +int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** This function updates the LFR registers with the incoming sbm2 parameters. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int flag; + rtems_status_code status; + unsigned char sy_lfr_s2_bp_p0; + unsigned char sy_lfr_s2_bp_p1; + float aux; + + flag = LFR_SUCCESSFUL; + + if ( lfrCurrentMode == LFR_MODE_SBM2 ) { + status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); + flag = LFR_DEFAULT; + } + + sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; + sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; + + // sy_lfr_s2_bp_p0 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 ) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_s2_bp_p1 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 ) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 ); + flag = WRONG_APP_DATA; + } + } + //****************************************************************** + // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1 + if (flag == LFR_SUCCESSFUL) + { + sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; + sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; + aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0); + if (aux > FLOAT_EQUAL_ZERO) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 ); + flag = LFR_DEFAULT; + } + } + + // SET THE PARAMETERS + if (flag == LFR_SUCCESSFUL) + { + flag = set_sy_lfr_s2_bp_p0( TC ); + flag = set_sy_lfr_s2_bp_p1( TC ); + } + + return flag; +} + +int action_dump_par( rtems_id queue_id ) +{ + /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue. + * + * @param queue_id is the id of the queue which handles TM related to this execution step. + * + * @return RTEMS directive status codes: + * - RTEMS_SUCCESSFUL - message sent successfully + * - RTEMS_INVALID_ID - invalid queue id + * - RTEMS_INVALID_SIZE - invalid message size + * - RTEMS_INVALID_ADDRESS - buffer is NULL + * - RTEMS_UNSATISFIED - out of message buffers + * - RTEMS_TOO_MANY - queue s limit has been reached + * + */ + + int status; + + // UPDATE TIME + parameter_dump_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterParameterDump >> 8); + parameter_dump_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterParameterDump ); + increment_seq_counter( &sequenceCounterParameterDump ); + + parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); + parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time); + // SEND DATA + status = rtems_message_queue_send( queue_id, ¶meter_dump_packet, + PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); + if (status != RTEMS_SUCCESSFUL) { + PRINTF1("in action_dump *** ERR sending packet, code %d", status) + } + + return status; +} + +//*********************** +// NORMAL MODE PARAMETERS + +int check_common_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) +{ + unsigned char msb; + unsigned char lsb; + int flag; + float aux; + rtems_status_code status; + + unsigned int sy_lfr_n_swf_l; + unsigned int sy_lfr_n_swf_p; + unsigned int sy_lfr_n_asm_p; + unsigned char sy_lfr_n_bp_p0; + unsigned char sy_lfr_n_bp_p1; + unsigned char sy_lfr_n_cwf_long_f3; + + flag = LFR_SUCCESSFUL; + + //*************** + // get parameters + msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; + lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; + sy_lfr_n_swf_l = msb * 256 + lsb; + + msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; + lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; + sy_lfr_n_swf_p = msb * 256 + lsb; + + msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; + lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; + sy_lfr_n_asm_p = msb * 256 + lsb; + + sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; + + sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; + + sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; + + //****************** + // check consistency + // sy_lfr_n_swf_l + if (sy_lfr_n_swf_l != 2048) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l ); + flag = WRONG_APP_DATA; + } + // sy_lfr_n_swf_p + if (flag == LFR_SUCCESSFUL) + { + if ( sy_lfr_n_swf_p < 16 ) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_n_bp_p0 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_n_asm_p + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_n_asm_p == 0) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0 + if (flag == LFR_SUCCESSFUL) + { + aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0); + if (aux > FLOAT_EQUAL_ZERO) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_n_bp_p1 + if (flag == LFR_SUCCESSFUL) + { + if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 ); + flag = WRONG_APP_DATA; + } + } + // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0 + if (flag == LFR_SUCCESSFUL) + { + aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0); + if (aux > FLOAT_EQUAL_ZERO) + { + status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 ); + flag = LFR_DEFAULT; + } + } + // sy_lfr_n_cwf_long_f3 + + return flag; +} + +int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int result; + + result = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; + parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; + + return result; +} + +int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int result; + + result = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; + parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; + + return result; +} + +int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int result; + + result = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; + parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; + + return result; +} + +int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; + + return status; +} + +int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; + + return status; +} + +int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC ) +{ + /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; + + return status; +} + +//********************** +// BURST MODE PARAMETERS +int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC) +{ + /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; + + return status; +} + +int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; + + return status; +} + +//********************* +// SBM1 MODE PARAMETERS +int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ]; + + return status; +} + +int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ]; + + return status; +} + +//********************* +// SBM2 MODE PARAMETERS +int set_sy_lfr_s2_bp_p0(ccsdsTelecommandPacket_t *TC) +{ + /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; + + return status; +} + +int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ) +{ + /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1). + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM related to this execution step + * + */ + + int status; + + status = LFR_SUCCESSFUL; + + parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; + + return status; +} + + +//******************* +// TC_LFR_UPDATE_INFO +unsigned int check_update_info_hk_lfr_mode( unsigned char mode ) +{ + unsigned int status; + + if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL) + || (mode == LFR_MODE_BURST) + || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2)) + { + status = LFR_SUCCESSFUL; + } + else + { + status = LFR_DEFAULT; + } + + return status; +} + +unsigned int check_update_info_hk_tds_mode( unsigned char mode ) +{ + unsigned int status; + + if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL) + || (mode == TDS_MODE_BURST) + || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2) + || (mode == TDS_MODE_LFM)) + { + status = LFR_SUCCESSFUL; + } + else + { + status = LFR_DEFAULT; + } + + return status; +} + +unsigned int check_update_info_hk_thr_mode( unsigned char mode ) +{ + unsigned int status; + + if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL) + || (mode == THR_MODE_BURST)) + { + status = LFR_SUCCESSFUL; + } + else + { + status = LFR_DEFAULT; + } + + return status; +} + +//********** +// init dump + +void init_parameter_dump( void ) +{ + /** This function initialize the parameter_dump_packet global variable with default values. + * + */ + + parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; + parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; + parameter_dump_packet.reserved = CCSDS_RESERVED; + parameter_dump_packet.userApplication = CCSDS_USER_APP; + parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8); + parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP; + parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; + parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; + parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8); + parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP; + // DATA FIELD HEADER + parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2; + parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP; + parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP; + parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND; + parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); + parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time); + parameter_dump_packet.sid = SID_PARAMETER_DUMP; + + //****************** + // COMMON PARAMETERS + parameter_dump_packet.unused0 = DEFAULT_SY_LFR_COMMON0; + parameter_dump_packet.bw_sp0_sp1_r0_r1 = DEFAULT_SY_LFR_COMMON1; + + //****************** + // NORMAL PARAMETERS + parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8); + parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L ); + parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8); + parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P ); + parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8); + parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P ); + parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0; + parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1; + parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3; + + //***************** + // BURST PARAMETERS + parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0; + parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1; + + //**************** + // SBM1 PARAMETERS + parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period + parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1; + + //**************** + // SBM2 PARAMETERS + parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0; + parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1; +} + + + + + + + diff --git a/timegen/src/tm_lfr_tc_exe.c b/timegen/src/tm_lfr_tc_exe.c new file mode 100644 --- /dev/null +++ b/timegen/src/tm_lfr_tc_exe.c @@ -0,0 +1,510 @@ +/** Functions to send TM packets related to TC parsing and execution. + * + * @file + * @author P. LEROY + * + * A group of functions to send appropriate TM packets after parsing and execution: + * - TM_LFR_TC_EXE_SUCCESS + * - TM_LFR_TC_EXE_INCONSISTENT + * - TM_LFR_TC_EXE_NOT_EXECUTABLE + * - TM_LFR_TC_EXE_NOT_IMPLEMENTED + * - TM_LFR_TC_EXE_ERROR + * - TM_LFR_TC_EXE_CORRUPTED + * + */ + +#include "tm_lfr_tc_exe.h" + +int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) +{ + /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM + * + * @return RTEMS directive status code: + * - RTEMS_SUCCESSFUL - message sent successfully + * - RTEMS_INVALID_ID - invalid queue id + * - RTEMS_INVALID_SIZE - invalid message size + * - RTEMS_INVALID_ADDRESS - buffer is NULL + * - RTEMS_UNSATISFIED - out of message buffers + * - RTEMS_TOO_MANY - queue s limit has been reached + * + */ + + rtems_status_code status; + Packet_TM_LFR_TC_EXE_SUCCESS_t TM; + unsigned char messageSize; + + TM.targetLogicalAddress = CCSDS_DESTINATION_ID; + TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; + TM.reserved = DEFAULT_RESERVED; + TM.userApplication = CCSDS_USER_APP; + // PACKET HEADER + TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); + TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); + increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); + TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> 8); + TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS ); + // DATA FIELD HEADER + TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + TM.serviceType = TM_TYPE_TC_EXE; + TM.serviceSubType = TM_SUBTYPE_EXE_OK; + TM.destinationID = TC->sourceID; + TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + TM.time[3] = (unsigned char) (time_management_regs->coarse_time); + TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + TM.time[5] = (unsigned char) (time_management_regs->fine_time); + // + TM.telecommand_pkt_id[0] = TC->packetID[0]; + TM.telecommand_pkt_id[1] = TC->packetID[1]; + TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; + TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; + + messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; + + // SEND DATA + status = rtems_message_queue_send( queue_id, &TM, messageSize); + if (status != RTEMS_SUCCESSFUL) { + PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n") + } + + // UPDATE HK FIELDS + update_last_TC_exe( TC, TM.time ); + + return status; +} + +int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, + unsigned char byte_position, unsigned char rcv_value ) +{ + /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM + * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent + * @param rcv_value is the value of the LSB of the parameter that has been deteced as inconsistent + * + * @return RTEMS directive status code: + * - RTEMS_SUCCESSFUL - message sent successfully + * - RTEMS_INVALID_ID - invalid queue id + * - RTEMS_INVALID_SIZE - invalid message size + * - RTEMS_INVALID_ADDRESS - buffer is NULL + * - RTEMS_UNSATISFIED - out of message buffers + * - RTEMS_TOO_MANY - queue s limit has been reached + * + */ + + rtems_status_code status; + Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM; + unsigned char messageSize; + + TM.targetLogicalAddress = CCSDS_DESTINATION_ID; + TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; + TM.reserved = DEFAULT_RESERVED; + TM.userApplication = CCSDS_USER_APP; + // PACKET HEADER + TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); + TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); + increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); + TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> 8); + TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT ); + // DATA FIELD HEADER + TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + TM.serviceType = TM_TYPE_TC_EXE; + TM.serviceSubType = TM_SUBTYPE_EXE_NOK; + TM.destinationID = TC->sourceID; + TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + TM.time[3] = (unsigned char) (time_management_regs->coarse_time); + TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + TM.time[5] = (unsigned char) (time_management_regs->fine_time); + // + TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> 8); + TM.tc_failure_code[1] = (char) (WRONG_APP_DATA ); + TM.telecommand_pkt_id[0] = TC->packetID[0]; + TM.telecommand_pkt_id[1] = TC->packetID[1]; + TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; + TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; + TM.tc_service = TC->serviceType; // type of the rejected TC + TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC + TM.byte_position = byte_position; + TM.rcv_value = (unsigned char) rcv_value; + + messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; + + // SEND DATA + status = rtems_message_queue_send( queue_id, &TM, messageSize); + if (status != RTEMS_SUCCESSFUL) { + PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n") + } + + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + + return status; +} + +int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) +{ + /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM + * + * @return RTEMS directive status code: + * - RTEMS_SUCCESSFUL - message sent successfully + * - RTEMS_INVALID_ID - invalid queue id + * - RTEMS_INVALID_SIZE - invalid message size + * - RTEMS_INVALID_ADDRESS - buffer is NULL + * - RTEMS_UNSATISFIED - out of message buffers + * - RTEMS_TOO_MANY - queue s limit has been reached + * + */ + + rtems_status_code status; + Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM; + unsigned char messageSize; + + TM.targetLogicalAddress = CCSDS_DESTINATION_ID; + TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; + TM.reserved = DEFAULT_RESERVED; + TM.userApplication = CCSDS_USER_APP; + // PACKET HEADER + TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); + TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); + increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); + TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> 8); + TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE ); + // DATA FIELD HEADER + TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + TM.serviceType = TM_TYPE_TC_EXE; + TM.serviceSubType = TM_SUBTYPE_EXE_NOK; + TM.destinationID = TC->sourceID; // default destination id + TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + TM.time[3] = (unsigned char) (time_management_regs->coarse_time); + TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + TM.time[5] = (unsigned char) (time_management_regs->fine_time); + // + TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> 8); + TM.tc_failure_code[1] = (char) (TC_NOT_EXE ); + TM.telecommand_pkt_id[0] = TC->packetID[0]; + TM.telecommand_pkt_id[1] = TC->packetID[1]; + TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; + TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; + TM.tc_service = TC->serviceType; // type of the rejected TC + TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC + TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0]; + TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]; + + messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; + + // SEND DATA + status = rtems_message_queue_send( queue_id, &TM, messageSize); + if (status != RTEMS_SUCCESSFUL) { + PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n") + } + + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + + return status; +} + +int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ) +{ + /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM + * + * @return RTEMS directive status code: + * - RTEMS_SUCCESSFUL - message sent successfully + * - RTEMS_INVALID_ID - invalid queue id + * - RTEMS_INVALID_SIZE - invalid message size + * - RTEMS_INVALID_ADDRESS - buffer is NULL + * - RTEMS_UNSATISFIED - out of message buffers + * - RTEMS_TOO_MANY - queue s limit has been reached + * + */ + + rtems_status_code status; + Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM; + unsigned char messageSize; + + TM.targetLogicalAddress = CCSDS_DESTINATION_ID; + TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; + TM.reserved = DEFAULT_RESERVED; + TM.userApplication = CCSDS_USER_APP; + // PACKET HEADER + TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); + TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); + increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); + TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> 8); + TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED ); + // DATA FIELD HEADER + TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + TM.serviceType = TM_TYPE_TC_EXE; + TM.serviceSubType = TM_SUBTYPE_EXE_NOK; + TM.destinationID = TC->sourceID; // default destination id + TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + TM.time[3] = (unsigned char) (time_management_regs->coarse_time); + TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + TM.time[5] = (unsigned char) (time_management_regs->fine_time); + // + TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> 8); + TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL ); + TM.telecommand_pkt_id[0] = TC->packetID[0]; + TM.telecommand_pkt_id[1] = TC->packetID[1]; + TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; + TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; + TM.tc_service = TC->serviceType; // type of the rejected TC + TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC + + messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; + + // SEND DATA + status = rtems_message_queue_send( queue_id, &TM, messageSize); + if (status != RTEMS_SUCCESSFUL) { + PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n") + } + + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + + return status; +} + +int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) +{ + /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM + * + * @return RTEMS directive status code: + * - RTEMS_SUCCESSFUL - message sent successfully + * - RTEMS_INVALID_ID - invalid queue id + * - RTEMS_INVALID_SIZE - invalid message size + * - RTEMS_INVALID_ADDRESS - buffer is NULL + * - RTEMS_UNSATISFIED - out of message buffers + * - RTEMS_TOO_MANY - queue s limit has been reached + * + */ + + rtems_status_code status; + Packet_TM_LFR_TC_EXE_ERROR_t TM; + unsigned char messageSize; + + TM.targetLogicalAddress = CCSDS_DESTINATION_ID; + TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; + TM.reserved = DEFAULT_RESERVED; + TM.userApplication = CCSDS_USER_APP; + // PACKET HEADER + TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); + TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); + increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); + TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> 8); + TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR ); + // DATA FIELD HEADER + TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + TM.serviceType = TM_TYPE_TC_EXE; + TM.serviceSubType = TM_SUBTYPE_EXE_NOK; + TM.destinationID = TC->sourceID; // default destination id + TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + TM.time[3] = (unsigned char) (time_management_regs->coarse_time); + TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + TM.time[5] = (unsigned char) (time_management_regs->fine_time); + // + TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> 8); + TM.tc_failure_code[1] = (char) (FAIL_DETECTED ); + TM.telecommand_pkt_id[0] = TC->packetID[0]; + TM.telecommand_pkt_id[1] = TC->packetID[1]; + TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; + TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; + TM.tc_service = TC->serviceType; // type of the rejected TC + TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC + + messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; + + // SEND DATA + status = rtems_message_queue_send( queue_id, &TM, messageSize); + if (status != RTEMS_SUCCESSFUL) { + PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") + } + + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + + return status; +} + +int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, + unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV, + unsigned char destinationID ) +{ + /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue. + * + * @param TC points to the TeleCommand packet that is being processed + * @param queue_id is the id of the queue which handles TM + * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand + * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data + * + * @return RTEMS directive status code: + * - RTEMS_SUCCESSFUL - message sent successfully + * - RTEMS_INVALID_ID - invalid queue id + * - RTEMS_INVALID_SIZE - invalid message size + * - RTEMS_INVALID_ADDRESS - buffer is NULL + * - RTEMS_UNSATISFIED - out of message buffers + * - RTEMS_TOO_MANY - queue s limit has been reached + * + */ + + rtems_status_code status; + Packet_TM_LFR_TC_EXE_CORRUPTED_t TM; + unsigned char messageSize; + unsigned int packetLength; + unsigned char *packetDataField; + + packetLength = (TC->packetLength[0] * 256) + TC->packetLength[1]; // compute the packet length parameter + packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field + + TM.targetLogicalAddress = CCSDS_DESTINATION_ID; + TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; + TM.reserved = DEFAULT_RESERVED; + TM.userApplication = CCSDS_USER_APP; + // PACKET HEADER + TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); + TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); + increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); + TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> 8); + TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED ); + // DATA FIELD HEADER + TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + TM.serviceType = TM_TYPE_TC_EXE; + TM.serviceSubType = TM_SUBTYPE_EXE_NOK; + TM.destinationID = destinationID; + TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + TM.time[3] = (unsigned char) (time_management_regs->coarse_time); + TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); + TM.time[5] = (unsigned char) (time_management_regs->fine_time); + // + TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> 8); + TM.tc_failure_code[1] = (unsigned char) (CORRUPTED ); + TM.telecommand_pkt_id[0] = TC->packetID[0]; + TM.telecommand_pkt_id[1] = TC->packetID[1]; + TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; + TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; + TM.tc_service = TC->serviceType; // type of the rejected TC + TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC + TM.pkt_len_rcv_value[0] = TC->packetLength[0]; + TM.pkt_len_rcv_value[1] = TC->packetLength[1]; + TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0]; + TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1]; + TM.rcv_crc[0] = packetDataField[ packetLength - 1 ]; + TM.rcv_crc[1] = packetDataField[ packetLength ]; + TM.computed_crc[0] = computed_CRC[0]; + TM.computed_crc[1] = computed_CRC[1]; + + messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; + + // SEND DATA + status = rtems_message_queue_send( queue_id, &TM, messageSize); + if (status != RTEMS_SUCCESSFUL) { + PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") + } + + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + + return status; +} + +void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id ) +{ + /** This function increment the packet sequence control parameter of a TC, depending on its destination ID. + * + * @param packet_sequence_control points to the packet sequence control which will be incremented + * @param destination_id is the destination ID of the TM, there is one counter by destination ID + * + * If the destination ID is not known, a dedicated counter is incremented. + * + */ + + unsigned short sequence_cnt; + unsigned short segmentation_grouping_flag; + unsigned short new_packet_sequence_control; + unsigned char i; + + switch (destination_id) + { + case SID_TC_GROUND: + i = GROUND; + break; + case SID_TC_MISSION_TIMELINE: + i = MISSION_TIMELINE; + break; + case SID_TC_TC_SEQUENCES: + i = TC_SEQUENCES; + break; + case SID_TC_RECOVERY_ACTION_CMD: + i = RECOVERY_ACTION_CMD; + break; + case SID_TC_BACKUP_MISSION_TIMELINE: + i = BACKUP_MISSION_TIMELINE; + break; + case SID_TC_DIRECT_CMD: + i = DIRECT_CMD; + break; + case SID_TC_SPARE_GRD_SRC1: + i = SPARE_GRD_SRC1; + break; + case SID_TC_SPARE_GRD_SRC2: + i = SPARE_GRD_SRC2; + break; + case SID_TC_OBCP: + i = OBCP; + break; + case SID_TC_SYSTEM_CONTROL: + i = SYSTEM_CONTROL; + break; + case SID_TC_AOCS: + i = AOCS; + break; + case SID_TC_RPW_INTERNAL: + i = RPW_INTERNAL; + break; + default: + i = GROUND; + break; + } + + segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; + sequence_cnt = sequenceCounters_TC_EXE[ i ] & 0x3fff; + + new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ; + + packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8); + packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); + + // increment the sequence counter + if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX ) + { + sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1; + } + else + { + sequenceCounters_TC_EXE[ i ] = 0; + } +} diff --git a/timegen/src/wf_handler.c b/timegen/src/wf_handler.c new file mode 100644 --- /dev/null +++ b/timegen/src/wf_handler.c @@ -0,0 +1,1323 @@ +/** Functions and tasks related to waveform packet generation. + * + * @file + * @author P. LEROY + * + * A group of functions to handle waveforms, in snapshot or continuous format.\n + * + */ + +#include "wf_handler.h" + +//***************** +// waveform headers +// SWF +Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7]; +Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7]; +Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7]; +// CWF +Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[ NB_PACKETS_PER_GROUP_OF_CWF ]; +Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[ NB_PACKETS_PER_GROUP_OF_CWF ]; +Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[ NB_PACKETS_PER_GROUP_OF_CWF ]; +Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[ NB_PACKETS_PER_GROUP_OF_CWF ]; +Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[ NB_PACKETS_PER_GROUP_OF_CWF_LIGHT ]; + +//************** +// waveform ring +ring_node waveform_ring_f0[NB_RING_NODES_F0]; +ring_node waveform_ring_f1[NB_RING_NODES_F1]; +ring_node waveform_ring_f2[NB_RING_NODES_F2]; +ring_node waveform_ring_f3[NB_RING_NODES_F3]; +ring_node *current_ring_node_f0; +ring_node *ring_node_to_send_swf_f0; +ring_node *current_ring_node_f1; +ring_node *ring_node_to_send_swf_f1; +ring_node *ring_node_to_send_cwf_f1; +ring_node *current_ring_node_f2; +ring_node *ring_node_to_send_swf_f2; +ring_node *ring_node_to_send_cwf_f2; +ring_node *current_ring_node_f3; +ring_node *ring_node_to_send_cwf_f3; + +bool extractSWF = false; +bool swf_f0_ready = false; +bool swf_f1_ready = false; +bool swf_f2_ready = false; + +int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET ]; + +//********************* +// Interrupt SubRoutine + +void reset_extractSWF( void ) +{ + extractSWF = false; + swf_f0_ready = false; + swf_f1_ready = false; + swf_f2_ready = false; +} + +rtems_isr waveforms_isr( rtems_vector_number vector ) +{ + /** This is the interrupt sub routine called by the waveform picker core. + * + * This ISR launch different actions depending mainly on two pieces of information: + * 1. the values read in the registers of the waveform picker. + * 2. the current LFR mode. + * + */ + + rtems_status_code status; + rtems_status_code spare_status; + + if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) + { // in modes other than STANDBY and BURST, send the CWF_F3 data + if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full + // (1) change the receiving buffer for the waveform picker + ring_node_to_send_cwf_f3 = current_ring_node_f3; + current_ring_node_f3 = current_ring_node_f3->next; + waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; + // (2) send an event for the waveforms transmission + if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { + spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); + } + rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2); + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111] + } + } + + switch(lfrCurrentMode) + { + //******** + // STANDBY + case(LFR_MODE_STANDBY): + break; + + //****** + // NORMAL + case(LFR_MODE_NORMAL): + if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits + { + spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); + } + if ( (waveform_picker_regs->status & 0x07) == 0x07) // [0111] check the f2, f1, f0 full bits + { + // change F0 ring node + ring_node_to_send_swf_f0 = current_ring_node_f0; + current_ring_node_f0 = current_ring_node_f0->next; + waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; + // change F1 ring node + ring_node_to_send_swf_f1 = current_ring_node_f1; + current_ring_node_f1 = current_ring_node_f1->next; + waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; + // change F2 ring node + ring_node_to_send_swf_f2 = current_ring_node_f2; + current_ring_node_f2 = current_ring_node_f2->next; + waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; + // + if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) + { + spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); + } + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888; // [1000 1000 1000] + } + break; + + //****** + // BURST + case(LFR_MODE_BURST): + if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit + // (1) change the receiving buffer for the waveform picker + ring_node_to_send_cwf_f2 = current_ring_node_f2; + current_ring_node_f2 = current_ring_node_f2->next; + waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; + // (2) send an event for the waveforms transmission + if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { + spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); + } + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0 + } + break; + + //***** + // SBM1 + case(LFR_MODE_SBM1): + if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit + // (1) change the receiving buffer for the waveform picker + ring_node_to_send_cwf_f1 = current_ring_node_f1; + current_ring_node_f1 = current_ring_node_f1->next; + waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; + // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed) + status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 ); + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bits = 0 + } + if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit + swf_f0_ready = true; + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0 + } + if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit + swf_f2_ready = true; + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0 + } + break; + + //***** + // SBM2 + case(LFR_MODE_SBM2): + if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit + // (1) change the receiving buffer for the waveform picker + ring_node_to_send_cwf_f2 = current_ring_node_f2; + current_ring_node_f2 = current_ring_node_f2->next; + waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; + // (2) send an event for the waveforms transmission + status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 ); + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0 + } + if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit + swf_f0_ready = true; + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0 + } + if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit + swf_f1_ready = true; + waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1, f0 bits = 0 + } + break; + + //******** + // DEFAULT + default: + break; + } +} + +//************ +// RTEMS TASKS + +rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP +{ + /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode. + * + * @param unused is the starting argument of the RTEMS task + * + * The following data packets are sent by this task: + * - TM_LFR_SCIENCE_NORMAL_SWF_F0 + * - TM_LFR_SCIENCE_NORMAL_SWF_F1 + * - TM_LFR_SCIENCE_NORMAL_SWF_F2 + * + */ + + rtems_event_set event_out; + rtems_id queue_id; + rtems_status_code status; + + init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 ); + init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 ); + init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 ); + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in WFRM ***\n") + + while(1){ + // wait for an RTEMS_EVENT + rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1 + | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + if (event_out == RTEMS_EVENT_MODE_NORMAL) + { + DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n") + send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); + send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id); + send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id); + } + if (event_out == RTEMS_EVENT_MODE_SBM1) + { + DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n") + send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); + send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F1, headerSWF_F1, queue_id); + send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id); + } + if (event_out == RTEMS_EVENT_MODE_SBM2) + { + DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n") + send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); + send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id); + send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F2, headerSWF_F2, queue_id); + } + } +} + +rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP +{ + /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. + * + * @param unused is the starting argument of the RTEMS task + * + * The following data packet is sent by this task: + * - TM_LFR_SCIENCE_NORMAL_CWF_F3 + * + */ + + rtems_event_set event_out; + rtems_id queue_id; + rtems_status_code status; + + init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 ); + init_header_continuous_cwf3_light_table( headerCWF_F3_light ); + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in CWF3 ***\n") + + while(1){ + // wait for an RTEMS_EVENT + rtems_event_receive( RTEMS_EVENT_0, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + if ( (lfrCurrentMode == LFR_MODE_NORMAL) + || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) + { + if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01) + { + PRINTF("send CWF_LONG_F3\n") + send_waveform_CWF( + (volatile int*) ring_node_to_send_cwf_f3->buffer_address, + SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id ); + } + else + { + PRINTF("send CWF_F3 (light)\n") + send_waveform_CWF3_light( + (volatile int*) ring_node_to_send_cwf_f3->buffer_address, + headerCWF_F3_light, queue_id ); + } + + } + else + { + PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) + } + } +} + +rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 +{ + /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. + * + * @param unused is the starting argument of the RTEMS task + * + * The following data packet is sent by this function: + * - TM_LFR_SCIENCE_BURST_CWF_F2 + * - TM_LFR_SCIENCE_SBM2_CWF_F2 + * + */ + + rtems_event_set event_out; + rtems_id queue_id; + rtems_status_code status; + + init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST ); + init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 ); + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in CWF2 ***\n") + + while(1){ + // wait for an RTEMS_EVENT + rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + if (event_out == RTEMS_EVENT_MODE_BURST) + { + send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id ); + } + if (event_out == RTEMS_EVENT_MODE_SBM2) + { + send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id ); + // launch snapshot extraction if needed + if (extractSWF == true) + { + ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; + // extract the snapshot + build_snapshot_from_ring( ring_node_to_send_swf_f2, 2 ); + // send the snapshot when built + status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); + extractSWF = false; + } + if (swf_f0_ready && swf_f1_ready) + { + extractSWF = true; + swf_f0_ready = false; + swf_f1_ready = false; + } + } + } +} + +rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 +{ + /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. + * + * @param unused is the starting argument of the RTEMS task + * + * The following data packet is sent by this function: + * - TM_LFR_SCIENCE_SBM1_CWF_F1 + * + */ + + rtems_event_set event_out; + rtems_id queue_id; + rtems_status_code status; + + init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 ); + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in CWF1 ***\n") + + while(1){ + // wait for an RTEMS_EVENT + rtems_event_receive( RTEMS_EVENT_MODE_SBM1, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + send_waveform_CWF( (volatile int*) ring_node_to_send_cwf_f1->buffer_address, SID_SBM1_CWF_F1, headerCWF_F1, queue_id ); + // launch snapshot extraction if needed + if (extractSWF == true) + { + ring_node_to_send_swf_f1 = ring_node_to_send_cwf_f1; + // launch the snapshot extraction + status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 ); + extractSWF = false; + } + if (swf_f0_ready == true) + { + extractSWF = true; + swf_f0_ready = false; // this step shall be executed only one time + } + if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction + { + status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 ); + swf_f1_ready = false; + swf_f2_ready = false; + } + } +} + +rtems_task swbd_task(rtems_task_argument argument) +{ + /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. + * + * @param unused is the starting argument of the RTEMS task + * + */ + + rtems_event_set event_out; + + BOOT_PRINTF("in SWBD ***\n") + + while(1){ + // wait for an RTEMS_EVENT + rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + if (event_out == RTEMS_EVENT_MODE_SBM1) + { + build_snapshot_from_ring( ring_node_to_send_swf_f1, 1 ); + swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent + } + else + { + PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) + } + } +} + +//****************** +// general functions + +void WFP_init_rings( void ) +{ + // F0 RING + init_waveform_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_snap_f0 ); + // F1 RING + init_waveform_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_snap_f1 ); + // F2 RING + init_waveform_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_snap_f2 ); + // F3 RING + init_waveform_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_cont_f3 ); + + DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) + DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) + DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) + DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) +} + +void init_waveform_ring(ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] ) +{ + unsigned char i; + + waveform_ring[0].next = (ring_node*) &waveform_ring[ 1 ]; + waveform_ring[0].previous = (ring_node*) &waveform_ring[ nbNodes - 1 ]; + waveform_ring[0].buffer_address = (int) &wfrm[0]; + + waveform_ring[nbNodes-1].next = (ring_node*) &waveform_ring[ 0 ]; + waveform_ring[nbNodes-1].previous = (ring_node*) &waveform_ring[ nbNodes - 2 ]; + waveform_ring[nbNodes-1].buffer_address = (int) &wfrm[ (nbNodes-1) * WFRM_BUFFER ]; + + for(i=1; i > 8); + headerSWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); + headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; + if (i == 6) + { + headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); + headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); + headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); + headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 ); + } + else + { + headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); + headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); + headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); + headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 ); + } + headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; + headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT + headerSWF[ i ].pktNr = i+1; // PKT_NR + // DATA FIELD HEADER + headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type + headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype + headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; + // AUXILIARY DATA HEADER + headerSWF[ i ].time[0] = 0x00; + headerSWF[ i ].time[0] = 0x00; + headerSWF[ i ].time[0] = 0x00; + headerSWF[ i ].time[0] = 0x00; + headerSWF[ i ].time[0] = 0x00; + headerSWF[ i ].time[0] = 0x00; + headerSWF[ i ].sid = sid; + headerSWF[ i ].hkBIA = DEFAULT_HKBIA; + } + + return return_value; +} + +int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) +{ + unsigned int i; + int return_value; + + return_value = LFR_SUCCESSFUL; + + for (i=0; i > 8); + headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); + } + else + { + headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); + headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); + } + headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; + headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); + headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); + headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); + headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF ); + headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; + // DATA FIELD HEADER + headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type + headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype + headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; + // AUXILIARY DATA HEADER + headerCWF[ i ].sid = sid; + headerCWF[ i ].hkBIA = DEFAULT_HKBIA; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + } + + return return_value; +} + +int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) +{ + unsigned int i; + int return_value; + + return_value = LFR_SUCCESSFUL; + + for (i=0; i > 8); + headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); + + headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; + headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); + headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); + headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); + headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); + + headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; + // DATA FIELD HEADER + headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; + headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type + headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype + headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; + // AUXILIARY DATA HEADER + headerCWF[ i ].sid = SID_NORM_CWF_F3; + headerCWF[ i ].hkBIA = DEFAULT_HKBIA; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + headerCWF[ i ].time[0] = 0x00; + } + + return return_value; +} + +int send_waveform_SWF( volatile int *waveform, unsigned int sid, + Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id ) +{ + /** This function sends SWF CCSDS packets (F2, F1 or F0). + * + * @param waveform points to the buffer containing the data that will be send. + * @param sid is the source identifier of the data that will be sent. + * @param headerSWF points to a table of headers that have been prepared for the data transmission. + * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures + * contain information to setup the transmission of the data packets. + * + * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. + * + */ + + unsigned int i; + int ret; + unsigned int coarseTime; + unsigned int fineTime; + rtems_status_code status; + spw_ioctl_pkt_send spw_ioctl_send_SWF; + + spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header + spw_ioctl_send_SWF.options = 0; + + ret = LFR_DEFAULT; + + coarseTime = waveform[0]; + fineTime = waveform[1]; + + for (i=0; i<7; i++) // send waveform + { + spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) + TIME_OFFSET]; + spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ]; + // BUILD THE DATA + if (i==6) { + spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; + } + else { + spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; + } + // SET PACKET SEQUENCE COUNTER + increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid ); + // SET PACKET TIME + compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime ); + // + headerSWF[ i ].time[0] = headerSWF[ i ].acquisitionTime[0]; + headerSWF[ i ].time[1] = headerSWF[ i ].acquisitionTime[1]; + headerSWF[ i ].time[2] = headerSWF[ i ].acquisitionTime[2]; + headerSWF[ i ].time[3] = headerSWF[ i ].acquisitionTime[3]; + headerSWF[ i ].time[4] = headerSWF[ i ].acquisitionTime[4]; + headerSWF[ i ].time[5] = headerSWF[ i ].acquisitionTime[5]; + // SEND PACKET + status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE); + if (status != RTEMS_SUCCESSFUL) { + printf("%d-%d, ERR %d\n", sid, i, (int) status); + ret = LFR_DEFAULT; + } + rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds + } + + return ret; +} + +int send_waveform_CWF(volatile int *waveform, unsigned int sid, + Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id) +{ + /** This function sends CWF CCSDS packets (F2, F1 or F0). + * + * @param waveform points to the buffer containing the data that will be send. + * @param sid is the source identifier of the data that will be sent. + * @param headerCWF points to a table of headers that have been prepared for the data transmission. + * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures + * contain information to setup the transmission of the data packets. + * + * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. + * + */ + + unsigned int i; + int ret; + unsigned int coarseTime; + unsigned int fineTime; + rtems_status_code status; + spw_ioctl_pkt_send spw_ioctl_send_CWF; + + spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header + spw_ioctl_send_CWF.options = 0; + + ret = LFR_DEFAULT; + + coarseTime = waveform[0]; + fineTime = waveform[1]; + + for (i=0; i > 24 ); + localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 ); + localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 ); + localAcquisitionTime[3] = (unsigned char) ( coarseTime ); + localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 ); + localAcquisitionTime[5] = (unsigned char) ( fineTime ); + + acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 ) + + ( (unsigned long long int) localAcquisitionTime[1] << 32 ) + + ( (unsigned long long int) localAcquisitionTime[2] << 24 ) + + ( (unsigned long long int) localAcquisitionTime[3] << 16 ) + + ( (unsigned long long int) localAcquisitionTime[4] << 8 ) + + ( (unsigned long long int) localAcquisitionTime[5] ); + + switch( sid ) + { + case SID_NORM_SWF_F0: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ; + break; + + case SID_NORM_SWF_F1: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ; + break; + + case SID_NORM_SWF_F2: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ; + break; + + case SID_SBM1_CWF_F1: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ; + break; + + case SID_SBM2_CWF_F2: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; + break; + + case SID_BURST_CWF_F2: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; + break; + + case SID_NORM_CWF_F3: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ; + break; + + case SID_NORM_CWF_LONG_F3: + deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ; + break; + + default: + PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid) + deltaT = 0.; + break; + } + + acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; + // + acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40); + acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32); + acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24); + acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16); + acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 ); + acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong ); + +} + +void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel ) +{ + unsigned int i; + unsigned long long int centerTime_asLong; + unsigned long long int acquisitionTimeF0_asLong; + unsigned long long int acquisitionTime_asLong; + unsigned long long int bufferAcquisitionTime_asLong; + unsigned char *ptr1; + unsigned char *ptr2; + unsigned char *timeCharPtr; + unsigned char nb_ring_nodes; + unsigned long long int frequency_asLong; + unsigned long long int nbTicksPerSample_asLong; + unsigned long long int nbSamplesPart1_asLong; + unsigned long long int sampleOffset_asLong; + + unsigned int deltaT_F0; + unsigned int deltaT_F1; + unsigned long long int deltaT_F2; + + deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; + deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384; + deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144; + sampleOffset_asLong = 0x00; + + // (1) get the f0 acquisition time + build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 ); + + // (2) compute the central reference time + centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; + + // (3) compute the acquisition time of the current snapshot + switch(frequencyChannel) + { + case 1: // 1 is for F1 = 4096 Hz + acquisitionTime_asLong = centerTime_asLong - deltaT_F1; + nb_ring_nodes = NB_RING_NODES_F1; + frequency_asLong = 4096; + nbTicksPerSample_asLong = 16; // 65536 / 4096; + break; + case 2: // 2 is for F2 = 256 Hz + acquisitionTime_asLong = centerTime_asLong - deltaT_F2; + nb_ring_nodes = NB_RING_NODES_F2; + frequency_asLong = 256; + nbTicksPerSample_asLong = 256; // 65536 / 256; + break; + default: + acquisitionTime_asLong = centerTime_asLong; + frequency_asLong = 256; + nbTicksPerSample_asLong = 256; + break; + } + + //**************************************************************************** + // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong + for (i=0; i previous; + } + + // (5) compute the number of samples to take in the current buffer + sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16; + nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; + PRINTF2("sampleOffset_asLong = %llx, nbSamplesPart1_asLong = %llx\n", sampleOffset_asLong, nbSamplesPart1_asLong) + + // (6) compute the final acquisition time + acquisitionTime_asLong = bufferAcquisitionTime_asLong + + sampleOffset_asLong * nbTicksPerSample_asLong; + + // (7) copy the acquisition time at the beginning of the extrated snapshot + ptr1 = (unsigned char*) &acquisitionTime_asLong; + ptr2 = (unsigned char*) wf_snap_extracted; + ptr2[0] = ptr1[ 0 + 2 ]; + ptr2[1] = ptr1[ 1 + 2 ]; + ptr2[2] = ptr1[ 2 + 2 ]; + ptr2[3] = ptr1[ 3 + 2 ]; + ptr2[6] = ptr1[ 4 + 2 ]; + ptr2[7] = ptr1[ 5 + 2 ]; + + // re set the synchronization bit + timeCharPtr = (unsigned char*) ring_node_to_send->buffer_address; + ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000] + + if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) + { + nbSamplesPart1_asLong = 0; + } + // copy the part 1 of the snapshot in the extracted buffer + for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) + { + wf_snap_extracted[i + TIME_OFFSET] = + ((int*) ring_node_to_send->buffer_address)[i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) + TIME_OFFSET]; + } + // copy the part 2 of the snapshot in the extracted buffer + ring_node_to_send = ring_node_to_send->next; + for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) + { + wf_snap_extracted[i + TIME_OFFSET] = + ((int*) ring_node_to_send->buffer_address)[(i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) + TIME_OFFSET]; + } +} + +void build_acquisition_time( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node ) +{ + unsigned char *acquisitionTimeCharPtr; + + acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address; + + *acquisitionTimeAslong = 0x00; + *acquisitionTimeAslong = ( (unsigned long long int) (acquisitionTimeCharPtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit + + ( (unsigned long long int) acquisitionTimeCharPtr[1] << 32 ) + + ( (unsigned long long int) acquisitionTimeCharPtr[2] << 24 ) + + ( (unsigned long long int) acquisitionTimeCharPtr[3] << 16 ) + + ( (unsigned long long int) acquisitionTimeCharPtr[6] << 8 ) + + ( (unsigned long long int) acquisitionTimeCharPtr[7] ); +} + +//************** +// wfp registers +void reset_wfp_burst_enable(void) +{ + /** This function resets the waveform picker burst_enable register. + * + * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. + * + */ + + waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 +} + +void reset_wfp_status( void ) +{ + /** This function resets the waveform picker status register. + * + * All status bits are set to 0 [new_err full_err full]. + * + */ + + waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 +} + +void reset_waveform_picker_regs(void) +{ + /** This function resets the waveform picker module registers. + * + * The registers affected by this function are located at the following offset addresses: + * - 0x00 data_shaping + * - 0x04 run_burst_enable + * - 0x08 addr_data_f0 + * - 0x0C addr_data_f1 + * - 0x10 addr_data_f2 + * - 0x14 addr_data_f3 + * - 0x18 status + * - 0x1C delta_snapshot + * - 0x20 delta_f0 + * - 0x24 delta_f0_2 + * - 0x28 delta_f1 + * - 0x2c delta_f2 + * - 0x30 nb_data_by_buffer + * - 0x34 nb_snapshot_param + * - 0x38 start_date + * - 0x3c nb_word_in_buffer + * + */ + + set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW + reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] + waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08 + waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c + waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; // 0x10 + waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; // 0x14 + reset_wfp_status(); // 0x18 + // + set_wfp_delta_snapshot(); // 0x1c + set_wfp_delta_f0_f0_2(); // 0x20, 0x24 + set_wfp_delta_f1(); // 0x28 + set_wfp_delta_f2(); // 0x2c + DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot) + DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0) + DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2) + DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1) + DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2) + // 2688 = 8 * 336 + waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1 + waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples + waveform_picker_regs->start_date = 0x00; // 0x38 + waveform_picker_regs->nb_word_in_buffer = 0x1f82; // 0x3c *** 2688 * 3 + 2 = 8066 +} + +void set_wfp_data_shaping( void ) +{ + /** This function sets the data_shaping register of the waveform picker module. + * + * The value is read from one field of the parameter_dump_packet structure:\n + * bw_sp0_sp1_r0_r1 + * + */ + + unsigned char data_shaping; + + // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register + // waveform picker : [R1 R0 SP1 SP0 BW] + + data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1; + + waveform_picker_regs->data_shaping = + ( (data_shaping & 0x10) >> 4 ) // BW + + ( (data_shaping & 0x08) >> 2 ) // SP0 + + ( (data_shaping & 0x04) ) // SP1 + + ( (data_shaping & 0x02) << 2 ) // R0 + + ( (data_shaping & 0x01) << 4 ); // R1 +} + +void set_wfp_burst_enable_register( unsigned char mode ) +{ + /** This function sets the waveform picker burst_enable register depending on the mode. + * + * @param mode is the LFR mode to launch. + * + * The burst bits shall be before the enable bits. + * + */ + + // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 + // the burst bits shall be set first, before the enable bits + switch(mode) { + case(LFR_MODE_NORMAL): + waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable + waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0 + break; + case(LFR_MODE_BURST): + waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled +// waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2 + waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2 + break; + case(LFR_MODE_SBM1): + waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled + waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 + break; + case(LFR_MODE_SBM2): + waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled + waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 + break; + default: + waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled + break; + } +} + +void set_wfp_delta_snapshot( void ) +{ + /** This function sets the delta_snapshot register of the waveform picker module. + * + * The value is read from two (unsigned char) of the parameter_dump_packet structure: + * - sy_lfr_n_swf_p[0] + * - sy_lfr_n_swf_p[1] + * + */ + + unsigned int delta_snapshot; + unsigned int delta_snapshot_in_T2; + + delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256 + + parameter_dump_packet.sy_lfr_n_swf_p[1]; + + delta_snapshot_in_T2 = delta_snapshot * 256; + waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes +} + +void set_wfp_delta_f0_f0_2( void ) +{ + unsigned int delta_snapshot; + unsigned int nb_samples_per_snapshot; + float delta_f0_in_float; + + delta_snapshot = waveform_picker_regs->delta_snapshot; + nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; + delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.; + + waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); + waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits +} + +void set_wfp_delta_f1( void ) +{ + unsigned int delta_snapshot; + unsigned int nb_samples_per_snapshot; + float delta_f1_in_float; + + delta_snapshot = waveform_picker_regs->delta_snapshot; + nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; + delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.; + + waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); +} + +void set_wfp_delta_f2() +{ + unsigned int delta_snapshot; + unsigned int nb_samples_per_snapshot; + + delta_snapshot = waveform_picker_regs->delta_snapshot; + nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; + + waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2; +} + +//***************** +// local parameters + +void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) +{ + /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. + * + * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. + * @param sid is the source identifier of the packet being updated. + * + * REQ-LFR-SRS-5240 / SSS-CP-FS-590 + * The sequence counters shall wrap around from 2^14 to zero. + * The sequence counter shall start at zero at startup. + * + * REQ-LFR-SRS-5239 / SSS-CP-FS-580 + * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 + * + */ + + unsigned short *sequence_cnt; + unsigned short segmentation_grouping_flag; + unsigned short new_packet_sequence_control; + rtems_mode initial_mode_set; + rtems_mode current_mode_set; + rtems_status_code status; + + //****************************************** + // CHANGE THE MODE OF THE CALLING RTEMS TASK + status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); + + if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) + || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) + || (sid == SID_BURST_CWF_F2) + || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) + || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) + || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) + || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) + || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) + { + sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; + } + else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) + || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) + || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) + || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) + { + sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; + } + else + { + sequence_cnt = (unsigned short *) NULL; + PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) + } + + if (sequence_cnt != NULL) + { + segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; + *sequence_cnt = (*sequence_cnt) & 0x3fff; + + new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; + + packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8); + packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); + + // increment the sequence counter + if ( *sequence_cnt < SEQ_CNT_MAX) + { + *sequence_cnt = *sequence_cnt + 1; + } + else + { + *sequence_cnt = 0; + } + } + + //*********************************** + // RESET THE MODE OF THE CALLING TASK + status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); +}