void send_pus_packet_tc(void) { uint8_t i, timeout; uint8_t num_transfers = PACKET_LENGTH / 4; tc_transfer_completef = 0; start_tc_transferf = 0; uint8_t data[4]; alert_obc_tcp_ready(); timeout = ssm_ok_go_timeout; while(!start_tc_transferf) // Wait a maximum of 2.5ms for the OBC to respond. { if(!timeout--) { data[0] = ssm_ok_go_timeout; errorREPORT(TC_OK_GO_TIMED_OUT, data); // Let the OBC know that OK-GO timed out. return; } delay_us(10); } start_tc_transferf = 0; for(i = 0; i < num_transfers; i++) { if(tc_transfer_completef == 0xFF) return; send_arr[0] = current_tc[(i * 4)]; send_arr[1] = current_tc[(i * 4) + 1]; send_arr[2] = current_tc[(i * 4) + 2]; send_arr[3] = current_tc[(i * 4) + 3]; send_tc_can_msg(i); // Send a TC message to the OBC. delay_ms(1); // Give the OBC 1ms to process that CAN message. } timeout = ssm_consec_trans_timeout; while(!tc_transfer_completef) // Delay for ~10 ms for the OBC to send final transaction response. { if(!timeout--) { data[0] = ssm_consec_trans_timeout; errorASSERT(TC_CONSEC_TIMED_OUT, data); // Let the OBC know that a consecutive transfer timed out. return; } delay_us(100); } if(tc_transfer_completef != 35) { tc_transfer_completef = 0; return; } else { tc_transfer_completef = 0; tc_packet_readyf = 0; return; } }
static int check_schedule(void) { uint8_t status = 0x01; // This variable is going to contain the status returned uint16_t cID, i; uint8_t command_array[16]; if(!scheduling_on) { return -2; // Scheduling is currently paused. } for (i = 0; i < 16; i++) { command_array[i] = 0; } if(next_command_time <= CURRENT_TIME) // from whatever command needs to be executed below, assume it is used for now. { spimem_read_sch(SCHEDULE_BASE + 4, command_array, 16); cID = ((uint16_t)command_array[7]) << 8; cID += (uint16_t)command_array[8]; // status = exec_k_command(); // Retry for a maximum of 3 tries. //I'm guessing exec_pus_commands() is what we want to repeat? uint8_t tries = 0; while (tries<2 && status == 0xFF){ exec_pus_commands(); tries++; } if(status == 0xFF) // The scheduled command failed. { //is this HIGHSEV or LOWSEV? errorREPORT(SCHEDULING_TASK_ID, SCHED_COMMAND_EXEC_ERROR, &command_array); //FIX: what should the third parameter be? // Still failing: Send a failure message to the FDIR Process and wait for signal from FDIR. FAILURE_RECOVERY // Still failing: (What FDIR should do: ) Send a message to the ground scheduling service letting it know that the command failed. } else { status = 1; generate_command_report(cID, status); // Send a command completion report to the groundstation. } shift_schedule_left(SCHEDULE_BASE + 20); // Shift out the command which was just executed. num_commands--; temp_arr[0] = (uint8_t)num_commands; temp_arr[1] = (uint8_t)(num_commands >> 8); temp_arr[2] = (uint8_t)(num_commands >> 16); temp_arr[3] = (uint8_t)(num_commands >> 24); spimem_write_sch(SCHEDULE_BASE, temp_arr, 4); // update the num_commands within SPI memory. spimem_read_sch(SCHEDULE_BASE+4, temp_arr, 4); next_command_time = ((uint32_t)temp_arr[3]) << 24; // update the next_command_time next_command_time = ((uint32_t)temp_arr[2]) << 16; next_command_time = ((uint32_t)temp_arr[1]) << 8; next_command_time = (uint32_t)temp_arr[0]; }
static void exec_commands(void){ int attempts = 1; //exec_com_success is 1 if successful, current_commands if there is a FIFO error uint16_t exec_com_success = exec_commands_H(); while (attempts<3 && exec_com_success != 1){ exec_com_success = exec_commands_H(); attempts++; } if (exec_com_success != 1) { errorREPORT(HK_TASK_ID,HK_FIFO_RW_ERROR, exec_com_success); } return; }