tc_handler.c
942 lines
| 33.4 KiB
| text/x-c
|
CLexer
/ src / tc_handler.c
paul@pc-solar1.lab-lpp.local
|
r5 | #include <tc_handler.h> | ||
#include <fsw_params.h> | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | char *DumbMessages[5] = {"in DUMB *** default", | ||
"in DUMB *** timecode_irq_handler", | ||||
"in DUMB *** waveforms_isr", | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | "", | ||
"" | ||||
}; | ||||
unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field | ||||
unsigned char currentTC_COMPUTED_CRC[2]; | ||||
unsigned int currentTC_LEN_RCV_AsUnsignedInt; | ||||
unsigned int currentTM_length; | ||||
unsigned char currentTC_processedFlag; | ||||
unsigned int lookUpTableForCRC[256]; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r7 | //********************** | ||
// GENERAL USE FUNCTIONS | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | unsigned int Crc_opt( unsigned char D, unsigned int Chk) | ||
{ | ||||
return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | void initLookUpTableForCRC( void ) | ||
paul@pc-solar1.lab-lpp.local
|
r5 | { | ||
paul@pc-solar1.lab-lpp.local
|
r18 | unsigned int i; | ||
unsigned int tmp; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | for (i=0; i<256; i++) | ||
{ | ||||
tmp = 0; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | 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; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | lookUpTableForCRC[i] = tmp; | ||
} | ||||
} | ||||
void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData) | ||||
{ | ||||
unsigned int Chk; | ||||
int j; | ||||
Chk = 0xffff; // reset the syndrom to all ones | ||||
for (j=0; j<sizeOfData; j++) { | ||||
Chk = Crc_opt(data[j], Chk); | ||||
} | ||||
crcAsTwoBytes[0] = (unsigned char) (Chk >> 8); | ||||
crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r7 | //********************* | ||
// ACCEPTANCE FUNCTIONS | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv) | ||
paul@pc-solar1.lab-lpp.local
|
r5 | { | ||
paul@pc-solar1.lab-lpp.local
|
r18 | int ret = 0; | ||
paul@pc-solar1.lab-lpp.local
|
r9 | rtems_status_code status; | ||
spw_ioctl_pkt_send spw_ioctl_send; | ||||
TMHeader_t TM_header; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | unsigned int code = 0; | ||
unsigned char computed_CRC[2]; | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ]; | ||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r9 | GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 ); | ||
code = acceptTM( TC, tc_len_recv ) ; | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | if ( (code == ILLEGAL_APID) | (code == WRONG_LEN_PACKET) | (code == INCOR_CHECKSUM) | ||
| (code == ILL_TYPE) | (code == ILL_SUBTYPE) | (code == WRONG_APP_DATA) ) | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | { // generate TM_LFR_TC_EXE_CORRUPTED | ||
// BUILD HEADER | ||||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header); | ||
paul@pc-solar1.lab-lpp.local
|
r5 | // BUILD DATA | ||
TM_build_data( TC, data, SID_EXE_CORR, computed_CRC); | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | // PREPARE TM SENDING | ||
spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header | ||||
spw_ioctl_send.hdr = (char*) &TM_header; | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | spw_ioctl_send.dlen = 16; | ||
paul@pc-solar1.lab-lpp.local
|
r9 | spw_ioctl_send.data = data; | ||
// SEND PACKET | ||||
write_spw(&spw_ioctl_send); | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | else { // send valid TC to the action launcher | ||
paul@pc-solar1.lab-lpp.local
|
r11 | status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3); | ||
paul@pc-solar1.lab-lpp.local
|
r18 | ret = -1; | ||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
paul@pc-solar1.lab-lpp.local
|
r18 | return ret; | ||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
paul@pc-solar1.lab-lpp.local
|
r18 | unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV) | ||
{ | ||||
unsigned char ret = 0; | ||||
unsigned char pid = 0; | ||||
unsigned char category = 0; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | unsigned int length = 0; | ||
unsigned char packetType = 0; | ||||
unsigned char packetSubtype = 0; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | unsigned char * CCSDSContent = NULL; | ||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r18 | // APID check *** APID on 2 bytes | ||
pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx | ||||
category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210 | ||||
length = (TMPacket->packetLength[0] * 256) + TMPacket->packetLength[1]; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | packetType = TMPacket->dataFieldHeader[1]; | ||
paul@pc-solar1.lab-lpp.local
|
r18 | packetSubtype = TMPacket->dataFieldHeader[2]; | ||
if (pid!=CCSDS_PROCESS_ID) { | ||||
ret = ILLEGAL_APID; | ||||
} | ||||
else if (category!=CCSDS_PACKET_CATEGORY) { | ||||
ret = ILLEGAL_APID; | ||||
} | ||||
else if (length != TC_LEN_RCV ) { // packet length check | ||||
ret = WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD | ||||
} | ||||
else if (length >= CCSDS_TC_PKT_MAX_SIZE) { | ||||
ret = WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
paul@pc-solar1.lab-lpp.local
|
r18 | else if (packetType == TC_TYPE_GEN){ // service type, subtype and packet length check | ||
switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61 | ||||
case TC_SUBTYPE_RESET: | ||||
if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_LOAD_COMM: | ||||
if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_LOAD_NORM: | ||||
if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_LOAD_BURST: | ||||
if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_LOAD_SBM1: | ||||
if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_LOAD_SBM2: | ||||
if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_DUMP: | ||||
if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_ENTER: | ||||
if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_UPDT_INFO: | ||||
if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_EN_CAL: | ||||
if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
case TC_SUBTYPE_DIS_CAL: | ||||
if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
break; | ||||
default: | ||||
ret = ILL_SUBTYPE; | ||||
break; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
paul@pc-solar1.lab-lpp.local
|
r18 | else if (packetType == TC_TYPE_TIME){ | ||
if (packetSubtype!=TC_SUBTYPE_UPDT_TIME) { | ||||
ret = ILL_SUBTYPE; | ||||
} | ||||
else if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) { | ||||
ret = WRONG_LEN_PACKET; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
} | ||||
else { | ||||
ret = ILL_TYPE; | ||||
} | ||||
// source ID check // Source ID not documented in the ICD | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | // packet error control, CRC check | ||
paul@pc-solar1.lab-lpp.local
|
r20 | if ( ret == CCSDS_TM_VALID ) { | ||
CCSDSContent = (unsigned char*) TMPacket->packetID; | ||||
GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC | ||||
if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) { | ||||
ret = INCOR_CHECKSUM; | ||||
} | ||||
else if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) { | ||||
ret = INCOR_CHECKSUM; | ||||
} | ||||
else { | ||||
ret = CCSDS_TM_VALID; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
return ret; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength, | ||
paul@pc-solar1.lab-lpp.local
|
r5 | unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader) | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID; | ||
TMHeader->protocolIdentifier = 0x02; | ||||
TMHeader->reserved = 0x00; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | TMHeader->userApplication = 0x00; | ||
TMHeader->packetID[0] = 0x0c; | ||||
TMHeader->packetSequenceControl[0] = 0xc0; | ||||
TMHeader->packetSequenceControl[1] = 0x00; | ||||
TMHeader->packetLength[0] = (unsigned char) (packetLength>>8); | ||||
TMHeader->packetLength[1] = (unsigned char) packetLength; | ||||
TMHeader->dataFieldHeader[0] = 0x10; | ||||
TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID; | ||||
switch (tm_type){ | ||||
case(TM_LFR_TC_EXE_OK): | ||||
TMHeader->packetID[1] = 0xc1; | ||||
TMHeader->dataFieldHeader[1] = 1; // type | ||||
TMHeader->dataFieldHeader[2] = 7; // subtype | ||||
break; | ||||
case(TM_LFR_TC_EXE_ERR): | ||||
TMHeader->packetID[1] = 0xc1; | ||||
TMHeader->dataFieldHeader[1] = 1; // type | ||||
TMHeader->dataFieldHeader[2] = 8; // subtype | ||||
break; | ||||
case(TM_LFR_HK): | ||||
TMHeader->packetID[1] = 0xc4; | ||||
TMHeader->dataFieldHeader[1] = 3; // type | ||||
TMHeader->dataFieldHeader[2] = 25; // subtype | ||||
break; | ||||
case(TM_LFR_SCI): | ||||
TMHeader->packetID[1] = 0xcc; | ||||
TMHeader->dataFieldHeader[1] = 21; // type | ||||
TMHeader->dataFieldHeader[2] = 3; // subtype | ||||
break; | ||||
case(TM_LFR_SCI_SBM): | ||||
TMHeader->packetID[1] = 0xfc; | ||||
TMHeader->dataFieldHeader[1] = 21; // type | ||||
TMHeader->dataFieldHeader[2] = 3; // subtype | ||||
break; | ||||
case(TM_LFR_PAR_DUMP): | ||||
TMHeader->packetID[1] = 0xc9; | ||||
TMHeader->dataFieldHeader[1] = 181; // type | ||||
TMHeader->dataFieldHeader[2] = 31; // subtype | ||||
break; | ||||
default: | ||||
return 0; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24); | ||
TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16); | ||||
TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8); | ||||
TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time); | ||||
TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8); | ||||
TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time); | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | return 1; | ||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | unsigned char TM_build_header_bis( enum TM_TYPE tm_type, unsigned int packetLength, | ||
unsigned int coarseTime, unsigned int fineTime, Packet_TM_LFR_TC_EXE_t *packet) | ||||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | packet->targetLogicalAddress = CCSDS_DESTINATION_ID; | ||
packet->protocolIdentifier = 0x02; | ||||
packet->reserved = 0x00; | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | packet->userApplication = 0x00; | ||
packet->packetID[0] = 0x0c; | ||||
packet->packetSequenceControl[0] = 0xc0; | ||||
packet->packetSequenceControl[1] = 0x00; | ||||
packet->packetLength[0] = (unsigned char) (packetLength>>8); | ||||
packet->packetLength[1] = (unsigned char) packetLength; | ||||
packet->dataFieldHeader[0] = 0x10; | ||||
packet->dataFieldHeader[3] = CCSDS_DESTINATION_ID; | ||||
switch (tm_type){ | ||||
case(TM_LFR_TC_EXE_OK): | ||||
packet->packetID[1] = 0xc1; | ||||
packet->dataFieldHeader[1] = 1; // type | ||||
packet->dataFieldHeader[2] = 7; // subtype | ||||
break; | ||||
case(TM_LFR_TC_EXE_ERR): | ||||
packet->packetID[1] = 0xc1; | ||||
packet->dataFieldHeader[1] = 1; // type | ||||
packet->dataFieldHeader[2] = 8; // subtype | ||||
break; | ||||
case(TM_LFR_HK): | ||||
packet->packetID[1] = 0xc4; | ||||
packet->dataFieldHeader[1] = 3; // type | ||||
packet->dataFieldHeader[2] = 25; // subtype | ||||
break; | ||||
case(TM_LFR_SCI): | ||||
packet->packetID[1] = 0xcc; | ||||
packet->dataFieldHeader[1] = 21; // type | ||||
packet->dataFieldHeader[2] = 3; // subtype | ||||
break; | ||||
case(TM_LFR_SCI_SBM): | ||||
packet->packetID[1] = 0xfc; | ||||
packet->dataFieldHeader[1] = 21; // type | ||||
packet->dataFieldHeader[2] = 3; // subtype | ||||
break; | ||||
case(TM_LFR_PAR_DUMP): | ||||
packet->packetID[1] = 0xc9; | ||||
packet->dataFieldHeader[1] = 181; // type | ||||
packet->dataFieldHeader[2] = 31; // subtype | ||||
break; | ||||
default: | ||||
return 0; | ||||
} | ||||
packet->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24); | ||||
packet->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16); | ||||
packet->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8); | ||||
packet->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time); | ||||
packet->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8); | ||||
packet->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time); | ||||
return 1; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC) | ||
{ | ||||
unsigned int packetLength; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | packetLength = (TC->packetLength[0] * 256) + TC->packetLength[1]; | ||
paul@pc-solar1.lab-lpp.local
|
r5 | switch (SID){ | ||
case (SID_NOT_EXE): | ||||
break; | ||||
case (SID_NOT_IMP): | ||||
data[0] = 0x9c; | ||||
data[1] = 0x42; | ||||
data[2] = TC->packetID[0]; | ||||
data[3] = TC->packetID[1]; | ||||
data[4] = TC->packetSequenceControl[0]; | ||||
data[5] = TC->packetSequenceControl[1]; | ||||
data[6] = TC->dataFieldHeader[1]; // type | ||||
data[7] = TC->dataFieldHeader[2]; // subtype | ||||
break; | ||||
case (SID_EXE_ERR): | ||||
break; | ||||
case (SID_EXE_CORR): | ||||
data[0] = 0x9c; | ||||
data[1] = 0x45; | ||||
data[2] = TC->packetID[0]; | ||||
data[3] = TC->packetID[1]; | ||||
data[4] = TC->packetSequenceControl[0]; | ||||
data[5] = TC->packetSequenceControl[1]; | ||||
data[6] = TC->dataFieldHeader[1]; // type | ||||
data[7] = TC->dataFieldHeader[2]; // subtype | ||||
data[8] = currentTC_LEN_RCV[0]; | ||||
data[9] = currentTC_LEN_RCV[1]; | ||||
data[10] = TC->packetLength[0]; | ||||
data[11] = TC->packetLength[1]; | ||||
data[12] = TC->dataAndCRC[packetLength]; | ||||
data[13] = TC->dataAndCRC[packetLength+1]; | ||||
data[14] = computed_CRC[0]; | ||||
data[15] = computed_CRC[1]; | ||||
break; | ||||
default: | ||||
return 0; | ||||
} | ||||
return 1; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | int create_message_queue( void ) | ||
paul@pc-solar1.lab-lpp.local
|
r17 | { | ||
rtems_status_code status; | ||||
misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' ); | ||||
status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE, | ||||
RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] ); | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | if (status!=RTEMS_SUCCESSFUL) { | ||
PRINTF("in create_message_queue *** error creating message queue\n") | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | |||
return 0; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r7 | //*********** | ||
// RTEMS TASK | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | rtems_task recv_task( rtems_task_argument unused ) | ||
paul@pc-solar1.lab-lpp.local
|
r18 | { | ||
paul@pc-solar1.lab-lpp.local
|
r5 | int len = 0; | ||
unsigned int i = 0; | ||||
unsigned int data_length = 0; | ||||
ccsdsTelecommandPacket_t currentTC; | ||||
char data[100]; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | for(i=0; i<100; i++) data[i] = 0; | ||
paul@pc-solar1.lab-lpp.local
|
r17 | PRINTF("in RECV *** \n") | ||
paul@pc-solar1.lab-lpp.local
|
r18 | |||
paul@pc-solar1.lab-lpp.local
|
r9 | while(1) | ||
paul@pc-solar1.lab-lpp.local
|
r18 | { | ||
len = read(fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking | ||||
if (len == -1){ // error during the read call | ||||
PRINTF("In RECV *** last read call returned -1\n") | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | if (rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) { | ||
paul@pc-solar1.lab-lpp.local
|
r18 | PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n") | ||
} | ||||
if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) { | ||||
PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n") | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
paul@pc-solar1.lab-lpp.local
|
r18 | else { | ||
paul@pc-solar1.lab-lpp.local
|
r13 | PRINTF1("Got pck of length %d\n", len+1) | ||
paul@pc-solar1.lab-lpp.local
|
r20 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { | ||
PRINTF("In RECV *** packet lenght too short\n") | ||||
} | ||||
else { | ||||
currentTC_LEN_RCV[0] = 0x00; | ||||
currentTC_LEN_RCV[1] = (unsigned char) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // build the corresponding packet size field | ||||
currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes | ||||
// CHECK THE TC AND BUILD THE APPROPRIATE TM | ||||
data_length = TC_checker(¤tTC, currentTC_LEN_RCV_AsUnsignedInt); | ||||
if (data_length!=-1) | ||||
{ | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | } | ||
paul@pc-solar1.lab-lpp.local
|
r9 | rtems_task actn_task( rtems_task_argument unused ) | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | int result = 0; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | unsigned int val; | ||
paul@pc-solar1.lab-lpp.local
|
r9 | 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 = 0; // subtype of the current TC packet | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r17 | PRINTF("in ACTN *** \n") | ||
paul@pc-solar1.lab-lpp.local
|
r11 | |||
paul@pc-solar1.lab-lpp.local
|
r9 | while(1) | ||
{ | ||||
status = rtems_message_queue_receive(misc_id[0], (char*) &TC, &size, | ||||
RTEMS_WAIT, RTEMS_NO_TIMEOUT); | ||||
if (status!=RTEMS_SUCCESSFUL) PRINTF1("in task ACTN *** error receiving a message, code %d \n", status) | ||||
else | ||||
{ | ||||
subtype = TC.dataFieldHeader[2]; | ||||
switch(subtype) | ||||
{ | ||||
case TC_SUBTYPE_RESET: | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
case TC_SUBTYPE_LOAD_COMM: | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | result = action_load_comm( &TC ); | ||
close_action( &TC, result ); | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | break; | ||
// | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_LOAD_NORM: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_load_norm( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | close_action( &TC, result ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_LOAD_BURST: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | close_action( &TC, result ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_LOAD_SBM1: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | close_action( &TC, result ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_LOAD_SBM2: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | close_action( &TC, result ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_DUMP: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | close_action( &TC, result ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_ENTER: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_enter( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | close_action( &TC, result ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_UPDT_INFO: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 | ||
+ housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_EN_CAL: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_DIS_CAL: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_default( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | case TC_SUBTYPE_UPDT_TIME: | ||
paul@pc-solar1.lab-lpp.local
|
r11 | result = action_updt_time( &TC ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 | ||
+ housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | // | ||
paul@pc-solar1.lab-lpp.local
|
r9 | default: | ||
break; | ||||
} | ||||
} | ||||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | rtems_task dumb_task( rtems_task_argument unused ) | ||
paul@pc-solar1.lab-lpp.local
|
r9 | { | ||
paul@pc-solar1.lab-lpp.local
|
r18 | unsigned int coarse_time = 0; | ||
unsigned int fine_time = 0; | ||||
unsigned int indice = 0; | ||||
unsigned int shiftedIndice = 0; | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | rtems_event_set event_out; | ||
PRINTF("in DUMB *** \n") | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | |||
paul@pc-solar1.lab-lpp.local
|
r17 | while(1){ | ||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | RTEMS_EVENT_4, | ||
RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | indice = 0; | ||
shiftedIndice = (unsigned int) event_out; | ||||
while(!(shiftedIndice & 0x0001)) | ||||
{ | ||||
shiftedIndice = shiftedIndice >> 1; | ||||
indice++; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r17 | coarse_time = time_management_regs->coarse_time; | ||
fine_time = time_management_regs->fine_time; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | printf("in DUMB *** time = coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[indice]); | ||
paul@pc-solar1.lab-lpp.local
|
r17 | } | ||
paul@pc-solar1.lab-lpp.local
|
r9 | } | ||
//*********** | ||||
// TC ACTIONS | ||||
paul@pc-solar1.lab-lpp.local
|
r15 | |||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | int action_default(ccsdsTelecommandPacket_t *TC) | ||
paul@pc-solar1.lab-lpp.local
|
r9 | { | ||
paul@pc-solar1.lab-lpp.local
|
r17 | Packet_TM_LFR_TC_EXE_t packet; | ||
paul@pc-solar1.lab-lpp.local
|
r15 | |||
paul@pc-solar1.lab-lpp.local
|
r17 | TM_build_header_bis( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP, | ||
time_management_regs->coarse_time, time_management_regs->fine_time, &packet); | ||||
paul@pc-solar1.lab-lpp.local
|
r15 | |||
paul@pc-solar1.lab-lpp.local
|
r17 | packet.data[0] = 0x9c; | ||
packet.data[1] = 0x42; | ||||
packet.data[2] = TC->packetID[0]; | ||||
packet.data[3] = TC->packetID[1]; | ||||
packet.data[4] = TC->packetSequenceControl[0]; | ||||
packet.data[5] = TC->packetSequenceControl[1]; | ||||
packet.data[6] = TC->dataFieldHeader[1]; // type | ||||
packet.data[7] = TC->dataFieldHeader[2]; // subtype | ||||
paul@pc-solar1.lab-lpp.local
|
r15 | |||
paul@pc-solar1.lab-lpp.local
|
r9 | // SEND DATA | ||
paul@pc-solar1.lab-lpp.local
|
r18 | if (write ( fdSPW, &packet, LEN_TM_LFR_TC_EXE_NOT_IMP)==-1) { | ||
PRINTF("ERR *** in action_default *** send TM packet\n"); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | |||
paul@pc-solar1.lab-lpp.local
|
r21 | return LFR_DEFAULT; | ||
paul@pc-solar1.lab-lpp.local
|
r9 | } | ||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | int action_enter(ccsdsTelecommandPacket_t *TC) | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_status_code status; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | unsigned char lfr_mode = TC->dataAndCRC[1]; | ||
printf("enter mode %d\n", lfr_mode); | ||||
switch(lfr_mode) | ||||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r19 | //******** | ||
// STANDBY | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | case(LFR_MODE_STANDBY): | ||
paul@pc-solar1.lab-lpp.local
|
r21 | status = stop_current_mode(); | ||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF("in action_enter *** error going back to STANDBY mode\n") | ||||
} | ||||
housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_STANDBY << 4) + 0x0d); | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r19 | |||
//****** | ||||
// NORMAL | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | case(LFR_MODE_NORMAL): | ||
paul@pc-solar1.lab-lpp.local
|
r21 | status = stop_current_mode(); | ||
status = enter_normal_mode(); | ||||
if (status == RTEMS_SUCCESSFUL) | ||||
{ | ||||
housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_NORMAL << 4) + 0x0d); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r19 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r18 | |||
paul@pc-solar1.lab-lpp.local
|
r19 | //****** | ||
// BURST | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | case(LFR_MODE_BURST): | ||
paul@pc-solar1.lab-lpp.local
|
r21 | status = stop_current_mode(); | ||
if (status == RTEMS_SUCCESSFUL) | ||||
{ | ||||
housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_BURST << 4) + 0x0d); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r19 | |||
//***** | ||||
// SBM1 | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | case(LFR_MODE_SBM1): | ||
paul@pc-solar1.lab-lpp.local
|
r21 | status = stop_current_mode(); | ||
status = enter_sbm1_mode(); | ||||
if (status == RTEMS_SUCCESSFUL) | ||||
{ | ||||
housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_SBM1 << 4) + 0x0d); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r19 | |||
//***** | ||||
// SBM2 | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | case(LFR_MODE_SBM2): | ||
paul@pc-solar1.lab-lpp.local
|
r21 | status = stop_current_mode(); | ||
if (status == RTEMS_SUCCESSFUL) | ||||
{ | ||||
housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_SBM2 << 4) + 0x0d); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r19 | |||
//******** | ||||
// DEFAULT | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | default: | ||
paul@pc-solar1.lab-lpp.local
|
r21 | status = stop_current_mode(); | ||
if (status == RTEMS_SUCCESSFUL) | ||||
{ | ||||
housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_STANDBY << 4) + 0x0d); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | break; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | } | ||
paul@pc-solar1.lab-lpp.local
|
r21 | return status; | ||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | } | ||
paul@pc-solar1.lab-lpp.local
|
r20 | int stop_current_mode() | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_status_code status; | ||
paul@pc-solar1.lab-lpp.local
|
r20 | // mask all IRQ lines related to signal processing | ||
LEON_Mask_interrupt( IRQ_WF ); // mask waveform interrupt (coming from the timer VHDL IP) | ||||
LEON_Mask_interrupt( IRQ_SM ); // mask spectral matrices interrupt (coming from the timer VHDL IP) | ||||
LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt | ||||
// clear all pending interruptions related to signal processing | ||||
LEON_Clear_interrupt( IRQ_WF ); // clear waveform interrupt (coming from the timer VHDL IP) | ||||
LEON_Clear_interrupt( IRQ_SM ); // clear spectral matrices interrupt (coming from the timer VHDL IP) | ||||
LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt | ||||
// suspend several tasks | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | status = suspend_if_needed( Task_id[TASKID_AVF0] ); | ||
if (status == RTEMS_SUCCESSFUL) { | ||||
status = suspend_if_needed( Task_id[TASKID_BPF0] ); | ||||
if (status == RTEMS_SUCCESSFUL) { | ||||
status = suspend_if_needed( Task_id[TASKID_WFRM] ); | ||||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | |||
// initialize the registers | ||||
waveform_picker_regs->burst_enable = 0x00; // initialize | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | return status; | ||
paul@pc-solar1.lab-lpp.local
|
r20 | } | ||
int enter_normal_mode() | ||||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_status_code status; | ||
paul@pc-solar1.lab-lpp.local
|
r20 | |||
paul@pc-solar1.lab-lpp.local
|
r21 | status = restart_if_needed( Task_id[TASKID_AVF0] ); | ||
if (status == RTEMS_SUCCESSFUL) { | ||||
status = restart_if_needed( Task_id[TASKID_BPF0] ); | ||||
if (status == RTEMS_SUCCESSFUL) { | ||||
status = restart_if_needed( Task_id[TASKID_WFRM] ); | ||||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | |||
#ifdef GSA | ||||
LEON_Unmask_interrupt( IRQ_WF ); | ||||
#else | ||||
LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); | ||||
LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); | ||||
waveform_picker_regs->burst_enable = 0x07; | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | waveform_picker_regs->addr_data_f1 = (int) wf_snap_f1; | ||
paul@pc-solar1.lab-lpp.local
|
r20 | waveform_picker_regs->status = 0x00; | ||
#endif | ||||
LEON_Unmask_interrupt( IRQ_SM ); | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | |||
return status; | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | } | ||
int enter_sbm1_mode() | ||||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_status_code status; | ||
status = restart_if_needed( Task_id[TASKID_AVF0] ); | ||||
if (status == RTEMS_SUCCESSFUL) { | ||||
status = restart_if_needed( Task_id[TASKID_BPF0] ); | ||||
if (status == RTEMS_SUCCESSFUL) { | ||||
status = restart_if_needed( Task_id[TASKID_WFRM] ); | ||||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | |||
#ifdef GSA | ||||
#else | ||||
LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); | ||||
LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); | ||||
waveform_picker_regs->burst_enable = 0x20; // [0010 0000] burst f2, f1, f0 enable f3 f2 f1 f0 | ||||
waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x02; | ||||
waveform_picker_regs->status = 0x00; | ||||
#endif | ||||
//LEON_Unmask_interrupt( IRQ_SM ); | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | return status; | ||
paul@pc-solar1.lab-lpp.local
|
r20 | } | ||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | int action_load_norm(ccsdsTelecommandPacket_t *TC) | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | param_norm.sy_lfr_n_swf_l = (TC->dataAndCRC[0] * 256) + TC->dataAndCRC[1]; | ||
param_norm.sy_lfr_n_swf_p = (TC->dataAndCRC[2] * 256) + TC->dataAndCRC[3]; | ||||
param_norm.sy_lfr_n_asm_p = (TC->dataAndCRC[4] * 256) + TC->dataAndCRC[5]; | ||||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6]; | ||
param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7]; | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | |||
return LFR_SUCCESSFUL; | ||||
} | ||||
int action_load_comm(ccsdsTelecommandPacket_t *TC) | ||||
{ | ||||
param_common.sy_lfr_common0 = TC->dataAndCRC[0]; | ||||
param_common.sy_lfr_common1 = TC->dataAndCRC[1]; | ||||
set_data_shaping_parameters(param_common.sy_lfr_common1); | ||||
return LFR_SUCCESSFUL; | ||||
paul@pc-solar1.lab-lpp.local
|
r11 | } | ||
int action_updt_time(ccsdsTelecommandPacket_t *TC) | ||||
{ | ||||
time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) | ||||
+ (TC->dataAndCRC[1] << 16) | ||||
+ (TC->dataAndCRC[2] << 8) | ||||
+ TC->dataAndCRC[3]; | ||||
paul@pc-solar1.lab-lpp.local
|
r12 | //time_management_regs->ctrl = time_management_regs->ctrl | 1; | ||
paul@pc-solar1.lab-lpp.local
|
r11 | return 0; | ||
} | ||||
int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC) | ||||
{ | ||||
TMHeader_t TM_header; | ||||
char data[4]; | ||||
spw_ioctl_pkt_send spw_ioctl_send; | ||||
TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE, | ||||
time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header); | ||||
data[0] = TC->packetID[0]; | ||||
data[1] = TC->packetID[1]; | ||||
data[2] = TC->packetSequenceControl[0]; | ||||
data[3] = TC->packetSequenceControl[1]; | ||||
// filling the structure for the spacewire transmission | ||||
spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header | ||||
spw_ioctl_send.hdr = (char*) &TM_header; | ||||
spw_ioctl_send.dlen = 3; | ||||
spw_ioctl_send.data = data; | ||||
// SEND DATA | ||||
write_spw(&spw_ioctl_send); | ||||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | return 0; | ||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | |||
paul@pc-solar1.lab-lpp.local
|
r20 | rtems_status_code restart_if_needed(rtems_id id) | ||
{ | ||||
rtems_status_code status; | ||||
status = rtems_task_is_suspended( id ); | ||||
if (status==RTEMS_SUCCESSFUL) { | ||||
status = rtems_task_restart( id, 0 ); | ||||
if (status!=RTEMS_SUCCESSFUL) { | ||||
PRINTF1("in restart_if_needed *** Error restarting with id %d\n", (int) id) | ||||
} | ||||
} | ||||
return status; | ||||
} | ||||
rtems_status_code suspend_if_needed(rtems_id id) | ||||
{ | ||||
rtems_status_code status; | ||||
status = rtems_task_is_suspended( id ); | ||||
if (status!=RTEMS_SUCCESSFUL) { | ||||
status = rtems_task_suspend( id ); | ||||
if (status!=RTEMS_SUCCESSFUL) { | ||||
PRINTF1("in suspend_if_needed *** Error suspending task with id %d\n", (int) id) | ||||
} | ||||
} | ||||
return status; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | void update_last_TC_exe(ccsdsTelecommandPacket_t *TC) | ||
{ | ||||
housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->dataFieldHeader[1]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->dataFieldHeader[2]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[3] = (unsigned char) (time_management_regs->coarse_time); | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8); | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[5] = (unsigned char) (time_management_regs->fine_time); | ||||
} | ||||
void update_last_TC_rej(ccsdsTelecommandPacket_t *TC) | ||||
{ | ||||
housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->dataFieldHeader[1]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->dataFieldHeader[2]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[3] = (unsigned char) (time_management_regs->coarse_time); | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8); | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[5] = (unsigned char) (time_management_regs->fine_time); | ||||
} | ||||
void close_action(ccsdsTelecommandPacket_t *TC, int result) | ||||
{ | ||||
unsigned int val = 0; | ||||
if (result == LFR_SUCCESSFUL) | ||||
{ | ||||
send_tm_lfr_tc_exe_success( TC ); | ||||
update_last_TC_exe( TC ); | ||||
val = housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[0] * 256 + housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[1] = (unsigned char) (val); | ||||
} | ||||
else | ||||
{ | ||||
update_last_TC_rej( TC ); | ||||
val = housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[0] * 256 + housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[1] = (unsigned char) (val); | ||||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r12 | //*************************** | ||
// Interrupt Service Routines | ||||
rtems_isr commutation_isr1( rtems_vector_number vector ) | ||||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
paul@pc-solar1.lab-lpp.local
|
r15 | printf("In commutation_isr1 *** Error sending event to DUMB\n"); | ||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
paul@pc-solar1.lab-lpp.local
|
r12 | } | ||
paul@pc-solar1.lab-lpp.local
|
r9 | |||
paul@pc-solar1.lab-lpp.local
|
r12 | rtems_isr commutation_isr2( rtems_vector_number vector ) | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
paul@pc-solar1.lab-lpp.local
|
r15 | printf("In commutation_isr2 *** Error sending event to DUMB\n"); | ||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
paul@pc-solar1.lab-lpp.local
|
r12 | } | ||