/*********************************************************/
/* ON Semiconductor                                      */
/* NCV7383 Evaluation Kit                                */
/*                                                       */
/* HOST.C                                                */
/* Host command processor                                */
/*                                                       */
/* Originally created by: Jozef Polak                    */
/* Modified by: Filip Brtan                              */
/* Date: 30.07.2012                                      */
/*********************************************************/

// INSTRUCTIONS:
// 1. Load the RX data array with the received data for the command (header, i.e. the group and command bytes, are NOT part of the data).
// 2. Initialize the TX data pointer to allocated memory buffer for the response. Remember the address, because the pointer will change.
// 2. Call the appropriate function from the host_command[] array. 
//    Index in the array is the group byte, the command byte is the parameter for the function.
// 3. The TX data array will contain the data for the response. The TX data pointer points one byte after the last valid byte.

#pragma DATA_SEG HOST_DATA
#pragma CODE_SEG HOST_CODE

/* General Packet Definitions */
#define CMD_ACK        0x80    // the ACK field of the command byte
#define CMD_QUERY      0x80    // the query bit of the command byte

/* Type definition of the mcu pins output states */
typedef enum
{
    HIGHZ = 0,        // pin is configured as input (High Impedance state, no pullup)
    OUTPUT,           // pin is configured as output (push-pull driver)
} Mcu_pin_config_type;

/* Config all mcu output signals connected to FlexRay bus driver as HIGH-Z or as output  */
void fr_bd_set_mcu_outputs(Mcu_pin_config_type mcu_pin_state);

/* Command Processing Functions */
typedef void THOST_COMMANDGROUP (byte command);   // function that processes a command group

extern THOST_COMMANDGROUP *host_command [];       // table of functions that process command groups

/* Data for the Command Processing */
extern TBUFFER_DATA *host_prxdata;     // received command-specific data (see documentation) for the received command
extern TBUFFER_DATA *host_ptxdata;     // command-specific data (see documentation) for the response
extern byte          host_rxlength;    // length of received command-specific data

extern word voltage_VBAT; // Voltage in mV

void trig_pattern(void);
void trig_scope(void);

void SendCANCommand(byte Group, byte Command, word Data1, word Data2, word Data3, word Data4);
void SendCANCommand_bytes(byte Group, byte Command, byte Data1, byte Data2, byte Data3, byte Data4,
                                                    byte Data5, byte Data6, byte Data7, byte Data8);
/* Measure fr bd supplies */
byte ADC_measure_VCC(word *voltage);
byte ADC_measure_VIO(word *voltage);
byte ADC_measure_VCC_BD(word *voltage);
byte ADC_measure_VIO_BD(word *voltage); 
byte ADC_measure_VBAT(word *voltage);

/* Read parameters received with app test command */
void read_parameters(word *data1, word *data2, word *data3, word *data4);
/* Read parameters received with app test command */
void read_parameters_byte(byte *data1, byte *data2, byte *data3, byte *data4,
                          byte *data5, byte *data6, byte *data7, byte *data8);
                          
                          
                                                    
#pragma CODE_SEG DEFAULT
