/*-------------------------------------------------------------------------------------------------
--
-- File Name    : coaxpressHostGUI.h



-- Description  : This module replicates the CoaXPress Host GUI modules.




-- Targeted device : Microchip FPGAs
-- Author          : India Solutions Team




--
-- COPYRIGHT 2023 BY MICROCHIP
-- THE INFORMATION CONTAINED IN THIS DOCUMENT IS SUBJECT TO LICENSING RESTRICTIONS
-- FROM MICROCHIP CORP.  IF YOU ARE NOT IN POSSESSION OF WRITTEN AUTHORIZATION FROM
-- MICROCHIP FOR USE OF THIS FILE, THEN THE FILE SHOULD BE IMMEDIATELY DESTROYED AND
-- NO BACK-UP OF THE FILE SHOULD BE MADE.
--



-------------------------------------------------------------------------------------------------*/

#ifndef COAXPRESSHOSTGUI_H_
#define COAXPRESSHOSTGUI_H_

#define HOST_CMD_SEL_ADDR     0x70001040
#define HOST_CMD_ADDR_ADDR    0x70001044
#define HOST_CMD_WDATA_ADDR   0x70001048

#define UART_WRITE_ADDRESS    0x70001050
#define UART_READY_ADDRESS    0x70001054

#define HPAN_C1               0x70001070
#define VPAN_C1               0x70001074
#define HPAN_C2               0x70001078
#define VPAN_C2               0x7000107C

#define WRITE_4BYTES          0x01000004
#define READ_4BYTES           0x00000004

#define RESOLUTION_SELECT     0x00100020   //device specific register

#define FHD_WIDTH             1920

enum {

    READ_MAGIC  = 1,
    READ_XML    = 2,
    START_VIDEO = 3,
    STOP_VIDEO  = 4,
    REG_READ    = 5,
    REG_WRITE   = 6,

    DEVICE_TO_HOST_CONNECTION_TEST = 11,
    HOST_TO_DEVICE_CONNECTION_TEST = 12,


    XML_REG_ADDRESS_FETCH = 0,
    XML_URL_FETCH         = 1,
    XML_ZIP_FILE_FETCH    = 2,

    WRITE_DISABLE = 0,
    WRITE_ENABLE  = 1,
    NEW_LINE      = 0x0A,

    WAIT_FOR_NODATA  = 0,
    WAIT_FOR_DATA    = 1,
    WAIT_FOR_XML     = 2,
    WAIT_READ_ACK    = 3,
    WAIT_WRITE_ACK   = 4,

    STREAM_ADDRESS = 0x00100100,

};

#define COAXPRESS_HOST_APB_BASE_ADDRESS        (0x71000000)

enum host_apb_reg
{
    TestModeReg                = 0x20,
    TestPacketCountTxReg       = 0x24,
    TestPacketCountRxReg       = 0x28,
    TestErrorCountReg          = 0x2C,
};

#define MAX_CHUNK_SIZE     256//128//64
#define ACK_CMD_EXEC_OK    0x01010101

#define CONTROL_CMD_WITHOUT_TAG                     0x02020202
#define CONTROL_CMD_WITH_TAG                        0x05050505
#define CONTROL_ACK_WITHOUT_TAG                     0x03030303
#define CONTROL_ACK_WITH_TAG                        0x06060606
#define CONTROL_CMD_READ                            0x00000000
#define CONTROL_CMD_WRITE                           0x01000000
#define ACK_CMD_EXEC_OK_APPEND_REPLY                0x00000000
#define ACK_CMD_EXEC_OK_NO_APPEND_REPLY             0x01010101
#define ACK_CMD_INVALID_DATA_FOR_ADDRESS            0x41414141
#define ACK_CMD_INVALID_CONTROL_OPERATION           0x42424242
#define ACK_CMD_WRITE_ATTEMPT_TO_READONLY_ADDRESS   0x43434343
#define START_OF_THE_PACKET                         0xfbfbfbfb
#define END_OF_THE_PACKET                           0xfdfdfdfd


void CoaxpressHostInit();
void CoaxpressHostMain();
void CoaxpressDeviceToHostMain();
void CoaxpressHostGUIMain();
void CoaxpressVideoStream();
void CoaxpressDefaultVideoStream();

void parse_xml_url(uint32_t crc_buffer[], uint8_t cont_count);
void finding_xml_details();
void reading_xml_from_device();
void DisplayStartVideoSeuenceOnGUI(uint32_t host_command);
void CoaxpressHostWaitCommand();

void device_reset();
void start_video_stream();
void delay();
void coaxpress_device_to_host_connection_test();
void coaxpress_host_to_device_connection_test();

extern uint8_t reset_en;
extern uint8_t device_to_host_connection_test_en;
extern uint8_t host_to_device_connection_test_en;


#endif /* COAXPRESSHOSTGUI_H_ */
