/*
 * otsu_tctm_man.c
 *
 *  Created on: 24-Nov-2022
 *      Author: Invcuser52
 */

#include "stddef.h"
#include "otsu_tctm_man.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "file_integrity_check.h"
#include "mfcc_tc_tm_sample.h"

void otsu_status_print(uint8_t status);
void print_err_sts(uint8_t err_sts);

void otsu_tc_encode (uint16_t tc_id,s_otsu_tc_encode_def *tc_enc , s_otsu_tctm_info *frame_info)
{
  s_firmware_update_config_parms_def *fw_config_params;
  //s_otsu_memory_layout_conf_def *mem_layout;

  uint32_t gs_contact_waiting_time;

  switch (tc_id)
    {
		case TC_OTSU_GET_VERSION:
			frame_info->tctm_ptr= (uint8_t*)malloc(2*sizeof(uint8_t));
			if(frame_info->tctm_ptr != NULL)
			{
	            printf("Enter ID 1 - Read current running firmware version\n");
	            printf("Enter ID 2 - Read backup firmware version\n");
	            printf("Enter ID 3 - Read downloaded firmware version\n");
	            printf("Enter ID 4 - Read factory firmware version\n");
				scanf("%hhu",&frame_info->tctm_ptr[0]);
				frame_info->tctm_size = 2;
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;


		case TC_OTSU_CURRENT_STATUS: //otsu_tc_firmware_status
			frame_info->tctm_ptr= (uint8_t*)malloc(1*sizeof(uint8_t));
			if(frame_info->tctm_ptr != NULL)
			{
				//frame_info->tctm_ptr[0] = otsu_tc_firmware_status;
				frame_info->tctm_size = 1;
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;



		case TC_OTSU_SEND_FW_UPDATE_BOOT_CFG: //otsu_tc_firmware_update_config
			frame_info->tctm_ptr= (uint8_t*)malloc(sizeof(s_firmware_update_config_parms_def));
			if(frame_info->tctm_ptr != NULL)
			{
				fw_config_params = (s_firmware_update_config_parms_def*)frame_info->tctm_ptr;
//				fw_config_params->otsu_msg_id = otsu_tc_firmware_update_config;
				fw_config_params->boot_type = tc_enc->fw_boot_cfg.boot_operation_ctrl;
				fw_config_params->sft_ver = tc_enc->fw_boot_cfg.sft_version;
				fw_config_params->shutdwn_timeout = tc_enc->fw_boot_cfg.shutdwn_process_timeout;
				fw_config_params->utc_time_to_schboot.hours = tc_enc->fw_boot_cfg.schboot_utc_time.hours;
				fw_config_params->utc_time_to_schboot.min = tc_enc->fw_boot_cfg.schboot_utc_time.min;
				fw_config_params->utc_time_to_schboot.sec = tc_enc->fw_boot_cfg.schboot_utc_time.sec;
				fw_config_params->utc_date_to_schboot.day = tc_enc->fw_boot_cfg.schboot_utc_date.day;
				fw_config_params->utc_date_to_schboot.month = tc_enc->fw_boot_cfg.schboot_utc_date.month;
                fw_config_params->utc_date_to_schboot.year = tc_enc->fw_boot_cfg.schboot_utc_date.year;

                fw_config_params->gs_contact_wait_time = tc_enc->fw_boot_cfg.gs_cont_failure_timeout;

#if 0
                                fw_config_params-> sband_time_sync_out.hours = tc_enc->fw_boot_cfg.sband_sync_utc_time.hours;
                                fw_config_params-> sband_time_sync_out.min = tc_enc->fw_boot_cfg.sband_sync_utc_time.min;
                                fw_config_params-> sband_time_sync_out.sec = tc_enc->fw_boot_cfg.sband_sync_utc_time.sec;
                                fw_config_params-> sband_date_sync_out.day = tc_enc->fw_boot_cfg.sband_sync_utc_date.day;
                                fw_config_params-> sband_date_sync_out.month = tc_enc->fw_boot_cfg.sband_sync_utc_date.month;
                                fw_config_params-> sband_date_sync_out.year = tc_enc->fw_boot_cfg.sband_sync_utc_date.year;
#endif
                                frame_info->tctm_size = sizeof(s_firmware_update_config_parms_def);
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;


		case TC_OTSU_INTEGERATION_TEST_CMD:
			frame_info->tctm_ptr= (uint8_t*)malloc(2*sizeof(uint8_t));
			if(frame_info->tctm_ptr != NULL)
			{
				frame_info->tctm_size = 2;
                                frame_info->tctm_ptr[0] = tc_enc->integ_test_code;
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;

		case TC_OTSU_GET_FW_UPDATE_STS:
			frame_info->tctm_ptr= (uint8_t*)malloc(1*sizeof(uint8_t));
			if(frame_info->tctm_ptr != NULL)
			{
				frame_info->tctm_size = 1;
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;

		case TC_OTSU_GET_BOOT_CFG_INFO:  //otsu_tc_grt_boot_config
			frame_info->tctm_ptr= (uint8_t*)malloc(1*sizeof(uint8_t));
			if(frame_info->tctm_ptr != NULL)
			{
				frame_info->tctm_size = 1;
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;
			
		
		case TC_OTSU_READ_GSCONATCT_WAIT_TIME:
			frame_info->tctm_ptr= (uint8_t*)malloc(1*sizeof(uint8_t));
			if(frame_info->tctm_ptr != NULL)
			{
				frame_info->tctm_size = 1;
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;

			case TC_OTSU_SET_GSCONATCT_WAIT_TIME:
			frame_info->tctm_ptr= (uint8_t*)malloc(5*sizeof(uint8_t));
			if(frame_info->tctm_ptr != NULL)
			{
				printf("Enter GS contact waiting time\n");
                scanf("%u",&gs_contact_waiting_time);
				printf("value entered is=%u",gs_contact_waiting_time);
				memcpy(&frame_info->tctm_ptr[0],&gs_contact_waiting_time,4);
				frame_info->tctm_size = 5;
				
			}
			else
			{
				printf("OTSU TC : malloc error");
			}
			break;

			case TC_OTSU_READ_BOOTABLE_BLT1:
				frame_info->tctm_ptr= (uint8_t*)malloc(1*sizeof(uint8_t));
				if(frame_info->tctm_ptr != NULL)
				{
					frame_info->tctm_size = 1;
				}
				else
				{
					printf("OTSU TC : malloc error");
				}
				break;


			case TC_OTSU_READ_BOOTABLE_BLT2:
				frame_info->tctm_ptr= (uint8_t*)malloc(1*sizeof(uint8_t));
				if(frame_info->tctm_ptr != NULL)
				{
					frame_info->tctm_size = 1;
				}
				else
				{
					printf("OTSU TC : malloc error");
				}
				break;

			case TC_OTSU_GET_NVM_FW_VERSION:
				frame_info->tctm_ptr= (uint8_t*)malloc(2*sizeof(uint8_t));
				if(frame_info->tctm_ptr != NULL)
				{
		            printf("Enter ID 1 - Read NVM Backup data -1\n");
		            printf("Enter ID 2 - Read NVM Backup data -2\n");
		            printf("Enter ID 3 - Read Current Nvm Firmware version\n");
		            printf("Enter ID 4 - Read Backup Nvm Firmware version\n");
		            printf("Enter ID 5 - Read Download Nvm Firmware version\n");
		            printf("Enter ID 6 - Read Factory Nvm Firmware version\n");
		            printf("Enter ID 7 - Read RAM Nvm Storage version\n");
					scanf("%hhu",&frame_info->tctm_ptr[0]);
					frame_info->tctm_size = 2;
				}
				else
				{
					printf("OTSU TC : malloc error");
				}
				break;



		default:
			break;
	}
}







void otsu_tm_decode (uint16_t tm_id,uint8_t *tm_data, uint8_t tm_len)
{
	s_firmware_update_config_parms_def *fw_reboot_config_ptr;
	otsu_firmware_sts *fw_sts;
	fw_sts = (otsu_firmware_sts*)tm_data;
	uint8_t temp;
	uint8_t sw_ver[2];
  uint32_t gscont_waitime;
  s_boot_lut_table_def bootloader_loookup_table;
uint32_t checksum_cal, checksum_read;

	if(tm_data != NULL)
	{
        printf("\r\n[OTSU] Telemetry response received\n");

		switch(tm_id)
		{
				case TM_OTSU_GET_VERSION:

					if(tm_data[0] == 1)
					{
						memcpy(sw_ver,&tm_data[1],2);
						printf("Current FW version : %d.%d\n",sw_ver[1],sw_ver[0]);
					}
					else
					{
						printf("FW Integrity Fail\n");
					}
					break;




				case TM_OTSU_CURRENT_STATUS:
					printf("Current OTSU status : %d\n",tm_data[0]);
                    otsu_status_print(tm_data[0]);
		    		printf("comms ipc receive message status : %x\n",tm_data[1]);

					break;


				case TM_OTSU_GET_BOOT_CFG_INFO:
					printf("Boot Config params received\n");
					fw_reboot_config_ptr =(s_firmware_update_config_parms_def*)(&tm_data[0]);
					printf("1. boot type %d\n",fw_reboot_config_ptr->boot_type);
//					printf("2. reboot_postpond_flag %d\n",fw_reboot_config_ptr->reboot_postpond_flag);
					printf("3. sft_ver %d\n",fw_reboot_config_ptr->sft_ver);
					printf("4. shutdwn_timeout %d\n\n",fw_reboot_config_ptr->shutdwn_timeout);
					printf("5. utc_time_to_schreboot.hours %d\n",fw_reboot_config_ptr->utc_time_to_schboot.hours);
					printf("6. utc_time_to_schreboot.min %d\n",fw_reboot_config_ptr->utc_time_to_schboot.min);
					printf("7. utc_time_to_schreboot.sec %d\n",fw_reboot_config_ptr->utc_time_to_schboot.sec);
					printf("8. utc_date_to_schreboot.day %d\n",fw_reboot_config_ptr->utc_date_to_schboot.day);
					printf("9. utc_date_to_schreboot.month %d\n",fw_reboot_config_ptr->utc_date_to_schboot.month);
					printf("10. utc_date_to_schreboot.year %d\n",fw_reboot_config_ptr->utc_date_to_schboot.year);
					printf("11. gs_contact_wait_time %d\n",fw_reboot_config_ptr->gs_contact_wait_time);

		//			printf("11. sband_time_sync_out.hours %d\n",fw_reboot_config_ptr->sband_time_sync_out.hours);
		//			printf("12. sband_time_sync_out.min %d\n",fw_reboot_config_ptr->sband_time_sync_out.min);
		//			printf("13. sband_time_sync_out.sec %d\n",fw_reboot_config_ptr->sband_time_sync_out.sec);
		//			printf("14. sband_date_sync_out.day %d\n",fw_reboot_config_ptr->sband_date_sync_out.day);
		//			printf("15. sband_date_sync_out.month %d\n",fw_reboot_config_ptr->sband_date_sync_out.month);
		//			printf("16. sband_date_sync_out.year %d\n",fw_reboot_config_ptr->sband_date_sync_out.year);
					break;

				case TM_OTSU_GET_FW_UPDATE_STS:
					if(tm_data[0] == 1)
					{
						printf("Save context available\n");
					}
					else
					{
						printf("Save context unavailable\n");
					}

					if(tm_data[1] == 1)
					{
						printf("New FW available for Boot\n");
					}
					else
					{
						printf("No New FW available for Boot\n");
					}


					if(tm_data[2] == 0x10)
					{
						printf("New FW available for Validation\n");
					}
					else
					{
						printf("No New FW avil for Validation\n");
					}
					break;



				case TM_OTSU_READ_GSCONATCT_WAIT_TIME:
					gscont_waitime = *((uint32_t*)&tm_data[0]);
                    printf("GS contact waittime - %d\n", gscont_waitime & 0xffffff);
				    break;



			case TM_OTSU_READ_BOOTABLE_BLT1:

				printf("\n ### READ BLT 1 as follows\n");

				temp = tm_data[0];
				printf("Buff len - %d\n", temp);
				checksum_cal = calc_checksum_bulkdata(&tm_data[1], temp-4);
				memcpy((uint8_t*)&checksum_read, &tm_data[temp+1-4], 4);
    //    memcpy((uint8_t*)&checksum_read, &tm_data[sizeof(otsu_firmware_sts)+temp+1-4], 4);

//temp+1-4
//				for (int ii = 0; ii < temp+1 ; ii++) printf("%x ",tm_data[sizeof(otsu_firmware_sts)+ii]);

				if(checksum_cal !=  checksum_read)
				{
					printf("Boottable corrupted, read- 0x%x , cal - 0x%x\n", checksum_read, checksum_cal);
				}
				else
				{
					memcpy(&bootloader_loookup_table, &tm_data[1], temp);



					if(bootloader_loookup_table.boot_selection == lut_activate) printf("lut_activate\n");
					else if(bootloader_loookup_table.boot_selection == lut_deactivate) printf("lut_deactivate\n");
					else printf("lut selection invalid\n");

	                printf("total_module  - %d\n", bootloader_loookup_table.table_control_data.total_module);

					if(bootloader_loookup_table.table_control_data.FFS_flag == ffs_set) printf("ffs_set\n");
					else if(bootloader_loookup_table.table_control_data.FFS_flag == ffs_success) printf("ffs_success\n");
					else printf("ffs invalid\n");

	                //printf("FFS_flag - %d\n", bootloader_loookup_table.table_control_data.FFS_flag);
	                printf("single_bin_boot  - 0x%x\n", bootloader_loookup_table.table_control_data.single_bin_boot);
	                printf("new_firmware_update_state  - %d\n", bootloader_loookup_table.table_control_data.new_firmware_update_state);
	                printf("boot_success_state  - 0x%x\n", bootloader_loookup_table.table_control_data.boot_success_state);
	                printf("firmware src address  - 0x%08x\n", bootloader_loookup_table.software_module[0].firmware_header);
	                printf("code_loaded_address  - 0x%08x\n", bootloader_loookup_table.software_module[0].code_loaded_address);
	                printf("module_load_status  - 0x%x\n", bootloader_loookup_table.software_module[0].module_load_status);
	                printf("firmware size  - %d bytes\n", bootloader_loookup_table.software_module[0].bin_size);
	                printf("btable_bank_loc_flag  - 0x%x\n", bootloader_loookup_table.btable_bank_loc_flag);

				}

			    break;



			case TM_OTSU_READ_BOOTABLE_BLT2:

				printf("\n ### READ BLT 2 as follows:\n");

				temp = tm_data[0];
				printf("Buff len - %d\n", temp);
				checksum_cal = calc_checksum_bulkdata(&tm_data[1], temp-4);
				memcpy((uint8_t*)&checksum_read, &tm_data[temp+1-4], 4);
        



//				for (int ii = 0; ii < temp+1 ; ii++) printf("%x ",tm_data[sizeof(otsu_firmware_sts)+ii]);

				if(checksum_cal !=  checksum_read)
				{
					printf("Boottable corrupted, read- 0x%x , cal - 0x%x\n", checksum_read, checksum_cal);
				}
				else
				{
					memcpy(&bootloader_loookup_table, &tm_data[1], temp);



					if(bootloader_loookup_table.boot_selection == lut_activate) printf("lut_activate\n");
					else if(bootloader_loookup_table.boot_selection == lut_deactivate) printf("lut_deactivate\n");
					else printf("lut selection invalid\n");

	                printf("total_module  - %d\n", bootloader_loookup_table.table_control_data.total_module);

					if(bootloader_loookup_table.table_control_data.FFS_flag == ffs_set) printf("ffs_set\n");
					else if(bootloader_loookup_table.table_control_data.FFS_flag == ffs_success) printf("ffs_success\n");
					else printf("ffs invalid\n");

	                //printf("FFS_flag - %d\n", bootloader_loookup_table.table_control_data.FFS_flag);
	                printf("single_bin_boot  - 0x%x\n", bootloader_loookup_table.table_control_data.single_bin_boot);
	                printf("new_firmware_update_state  - %d\n", bootloader_loookup_table.table_control_data.new_firmware_update_state);
	                printf("boot_success_state  - 0x%x\n", bootloader_loookup_table.table_control_data.boot_success_state);
	                printf("firmware src address  - 0x%08x\n", bootloader_loookup_table.software_module[0].firmware_header);
	                printf("code_loaded_address  - 0x%08x\n", bootloader_loookup_table.software_module[0].code_loaded_address);
	                printf("module_load_status  - 0x%x\n", bootloader_loookup_table.software_module[0].module_load_status);
	                printf("firmware size  - %d bytes\n", bootloader_loookup_table.software_module[0].bin_size);
	                printf("btable_bank_loc_flag  - 0x%x\n", bootloader_loookup_table.btable_bank_loc_flag);

				}

			    break;

			case TM_OTSU_GET_NVM_FW_VERSION:

				if(tm_data[0] == 0)
				{
					memcpy(sw_ver,&tm_data[1],2);
					printf("Current FW version : %d.%d\n",sw_ver[0],sw_ver[1]);
				}
				else
				{
					printf("FW Integrity Fail\n");
				}
				break;

			case TM_OTSU_NOTIFICATION:
				switch(tm_data[0])
				{
				case otfs_fallback_boot_initiated:
				printf("Fallback boot initiated\n");
				break;

				case otfs_flash_copy_fail:
				printf("Flash copy to NOR Fail\n");
				break;

				case otfs_ready_for_boot:
				printf("OTSU Reday for Boot/ Wait for GS ACK\n");
				break;

				case otfs_ack:
				printf("TC accepted by OTSU\n");
				break;

				case otfs_nack:
					printf("Warning !!! TC rejected by OTSU\n");
					break;

				case otfs_sft_ver_exists:
					printf("FW already exists\n");
					break;


				case otfs_boot_pass:
					printf("New FW boot Pass\n");
					//printf("FW version : %d.%d\n",sw_ver[0],sw_ver[1]);
					break;

				case otfs_boot_fail:
					printf("New FW boot Fail");
					break;





				}
				break;

			case TM_OTSU_SEND_FW_UPDATE_BOOT_CFG:
				switch(tm_data[0])
					{
				case otfs_boot_immediate:
				printf("FW update immediate request accecpted \n");
				break;

				case otfs_boot_postponed:
						printf("FW update postponed request accecpted \n");
						break;

						case otfs_boot_scheduled:
						printf("FW update scheduled request accecpted \n");
						break;


						case otfs_nvm_fw_integrity_fail:
							printf("nvm firmware intergrity fail\n");
							break;

						case otfs_downaloded_fw_integrity_fail:
							printf("FW update request rejected since downloaded firmware correupted\n");

							break;

						case otfs_sft_version_mismatch:
							printf("sft version mismatched due to unmatched sft ver in input params\n");
							break;

						case otfs_utc_time_invalid:
							fw_sts->ctrl.bit.response_code = otfs_utc_time_invalid;
							printf("Config Time is 0\n");
							break;

					}

					break;

				case TM_OTSU_SET_GSCONATCT_WAIT_TIME:
					printf("GS contact waitime set success\n");
					break;
	 		default:
					printf("Warning !!! Decode code not available for otsu tm reponse");
					break;
		}

	}
	else
	{
		printf("[OTSU] telemetry buffer received is NULL\n");
	}
}





//
//
//
//void otsu_send_tc_boot_config_autoctrl_test(void)
//{
//	s_otsu_tctm_info tctm_info;
//	s_otsu_tc_encode_def otsu_tc;
//	memset(&otsu_tc, 0, sizeof(s_otsu_tc_encode_def));
//
//	/* configure TC */
//	otsu_tc.boot_operation_ctrl = auto_cntrl;
//	otsu_tc.boot_schdule = boot_now;
//	otsu_tc.shutdwn_process_timeout = 15; // seconds
//	otsu_tc_encode(&otsu_tc, &tctm_info);
//	// send tc ();
//}
//
//
//
//void otsu_send_tc_boot_config_gsctrl_test(void)
//{
//	s_otsu_tctm_info tctm_info;
//	s_otsu_tc_encode_def otsu_tc;
//	memset(&otsu_tc, 0, sizeof(s_otsu_tc_encode_def));
//
//	/* configure TC */
//	otsu_tc.boot_operation_ctrl = gs_cntrl;
//	otsu_tc.boot_schdule = boot_postponed;
//	otsu_tc.shutdwn_process_timeout = 20; // seconds
//	otsu_tc.sft_version = 0x1226;
//	otsu_tc.utc_date = 0x123456;
//	otsu_tc.utc_time = 0x123456;
//	otsu_tc_encode(&otsu_tc, &tctm_info);
//}


void otsu_status_print(uint8_t status)
{

    e_otsu_fw_update_man otsu_status = status;
    switch(otsu_status)
    {
        case e_otsu_idle:
             printf("otsu status : e_otsu_idle\n");
             break;

        case e_otsu_new_fw_validate_init:
             printf("otsu status : e_otsu_new_fw_validate_init\n");
             break;

        case e_otsu_new_fw_validate_inprogress:
             printf("otsu status : e_otsu_new_fw_validate_inprogress\n");
             break;

        case e_otsu_new_fw_validated:
             printf("otsu status : e_otsu_new_fw_validated\n");
             break;

        case e_otsu_new_fw_fail_overwrite_locC:
             printf("otsu status : e_otsu_new_fw_fail_overwrite_locC\n");
             break;
        
        case e_otsu_new_fw_pass_overwrite_locB:
             printf("otsu status : e_otsu_new_fw_pass_overwrite_locB\n");
             break;

        case e_otsu_dwld_prepare:
             printf("otsu status : e_otsu_dwld_prepare\n");
             break;

        case e_otsu_dwld_copy:
             printf("otsu status : e_otsu_dwld_copy\n");
             break;

        case e_otsu_dwld_crc_error:
             printf("otsu status : e_otsu_dwld_crc_error\n");
             break;
        case e_otsu_dwld_complete:
             printf("otsu status : e_otsu_dwld_complete\n");
             break;

        case e_otsu_gs_ack_wait_for_boot:
             printf("otsu status : e_otsu_gs_ack_wait_for_boot\n");
             break;

        case e_otsu_auto_boot_enable:
             printf("otsu status : e_otsu_auto_boot_enable\n");
             break;

        case e_otsu_postponed_boot:
             printf("otsu status : e_otsu_postponed_boot\n");
             break;

        case e_otsu_postponed_rtc_config:
             printf("otsu status : e_otsu_postponed_rtc_config\n");
             break;

        case e_otsu_postponed_rtc_ruinning:
             printf("otsu status : e_otsu_postponed_rtc_ruinning\n");
             break;
        
        case e_otsu_shutdown_publish:
             printf("otsu status : e_otsu_shutdown_publish\n");
             break;

        case e_otsu_shutdown_processsing:
             printf("otsu status : e_otsu_shutdown_processsing\n");
             break;

        case e_otsu_shutdown_timeout_expired:
             printf("otsu status : e_otsu_shutdown_timeout_expired\n");
             break;

        case e_otsu_boot_activated:
             printf("otsu status : e_otsu_boot_activated\n");
             break;

        case e_otsu_integ_test_fallback_corrupt:
             printf("otsu status : e_otsu_integ_test_fallback_corrupt\n");
             break;

        case e_otsu_boot_canceled:
             printf("otsu status : e_otsu_boot_canceled\n");
             break;

        case e_otsu_vfb_prepare_loc_c:
             printf("otsu status : e_otsu_vfb_prepare_loc_c\n");
             break;

        case e_otsu_vfb_prepare_loc_d:
             printf("otsu status : e_otsu_vfb_prepare_loc_d\n");
             break;

        case e_otsu_fallback_3_prepare_loc_c:
             printf("otsu status : e_otsu_fallback_3_prepare_loc_c\n");
             break;

        case e_otsu_ftm_saveconext_norcopy_progress:
             printf("otsu status : e_otsu_ftm_saveconext_norcopy_progress\n");
             break;

        case e_otsu_ftm_saveconext_sdramcopy_progress:
             printf("otsu status : e_otsu_ftm_saveconext_sdramcopy_progress\n");
             break;

        case e_otsu_sch_boot_alarm:
             printf("otsu status : e_otsu_sch_boot_alarm\n");
             break;

        case e_otsu_sch_sband_sync_fail_alarm:
             printf("otsu status : e_otsu_sch_sband_sync_fail_alarm\n");
             break;

        case e_otsu_fallback_corrupt_locA:
             printf("otsu status : e_otsu_fallback_corrupt_locA\n");
             break;

        case e_otsu_fallback_corrupt_locB:
             printf("otsu status : e_otsu_fallback_corrupt_locB\n");
             break;

        case e_otsu_fallback_corrupt_locC:
             printf("otsu status : e_otsu_fallback_corrupt_locC\n");
             break;

        case e_otsu_fallback_corrupt_locD:
             printf("otsu status : e_otsu_fallback_corrupt_locD\n");
             break;

        case e_otsu_read_version:
             printf("otsu status : e_otsu_read_version\n");
             break;

        case e_otsu_gscont_waittime_running:
             printf("otsu status : e_otsu_gscont_waittime_running\n");
             break;
        case e_otsu_gscont_waittime_over:
             printf("otsu status : e_otsu_gscont_waittime_over\n");
             break;

        case e_otsu_gscont_waittime_started:
              printf("otsu status : e_otsu_gscont_waittime_started\n");
              break;

        case e_otsu_gscont_waitfor_obc_shutdown:
              printf("otsu status : e_otsu_gscont_waitfor_obc_shutdown\n");
              break;

       case e_otsu_new_fw_pass_overwrite_locB_fail:
              printf("otsu status : e_otsu_new_fw_pass_overwrite_locB_fail\n");
              break;
       case 	e_otsu_new_fw_pass_overwrite_locB_norcopy_fail:
              printf("otsu status :e_otsu_new_fw_pass_overwrite_locB_norcopy_fail\n");
              break;
       case e_otsu_ftm_saveconext_norcopy_fail:
              printf("otsu status : e_otsu_ftm_saveconext_norcopy_fail\n");
              break;
       case e_otsu_ftm_saveconext_norcopy_pass:
              printf("otsu status : e_otsu_ftm_saveconext_norcopy_pass\n");
              break;
       case e_otsu_new_fw_fail:
              printf("otsu status : e_otsu_new_fw_fail\n");
              break;
       case e_otsu_vfb_prepare_loc_c_pass:
              printf("otsu status : e_otsu_vfb_prepare_loc_c_pass\n");
              break;
       case e_otsu_vfb_prepare_loc_c_fail:
              printf("otsu status : e_otsu_vfb_prepare_loc_c_fail\n");
              break;
       case e_otsu_vfb_prepare_loc_d_pass:
              printf("otsu status : e_otsu_vfb_prepare_loc_d_pass\n");
              break;
       case e_otsu_vfb_prepare_loc_d_fail:
              printf("otsu status : e_otsu_vfb_prepare_loc_d_fail\n");
              break;
       case e_otsu_gscontact_comms_request_sent:
              printf("otsu status : e_otsu_gscontact_comms_request_sent\n");
              break;
       case e_otsu_dwnd_cancel_fw_exists:
              printf("otsu status : e_otsu_dwnd_cancel_fw_exists\n");
              break;

       case e_otsu_boot_canceled_sw_version_mismatch:
              printf("otsu status : e_otsu_boot_canceled_sw_version_mismatch\n");
              break;
       case e_otsu_boot_canceled_dwld_sw_integrity_fail:
              printf("otsu status : e_otsu_boot_canceled_dwld_sw_integrity_fail\n");
              break;
       case e_otsu_boot_canceled_nvm_intgrity_fail:
              printf("otsu status : e_otsu_boot_canceled_dwld_sw_integrity_fail\n");
              break;
              
       case   e_otsu_dwld_flash_copy_fail:
             printf("otsu status : e_otsu_dwld_flash_copy_fail\n");
              break;
        


         default:
             printf("Invalid status\n");
}
}

void print_err_sts(uint8_t err_sts)
{
	switch(err_sts)
	{
		case otsu_no_error:
			printf("OTSU ERR - NO ERROR\n");
			break;
		case sct_sdram_err:
			printf("OTSU ERR - SCT SDRAM CPY ERR\n");
			break;
		case sct_nor_copy_err:
			printf("OTSU ERR - SCT NOR FLASH CPY ERR\n");
			break;
		case sct_read_from_nor_err:
			printf("OTSU ERR - SCT READ FROM NOR ERR\n");
			break;
		case sdram_fmc_cpy_err:
			printf("OTSU ERR - FW SDRAM TO NOR CPY ERR\n");
			break;
		case fw_nor_c_copy_err:
			printf("OTSU ERR - FW LOC C CPY ERR\n");
			break;
		case fw_nor_b_copy_err:
			printf("OTSU ERR - FW LOC B CPY ERR\n");
			break;
		case mem_cpy_err:
			printf("OTSU ERR - MEM CPY ERR\n");
			break;
		default:
			printf("Invalid ERR state\n");
	}
}
