/*
 * SharedMemoryGlobal.h
 *
 *  Created on: Jun 3, 2025
 *      Author: tummalanr
 */

#ifndef USER_ADDONS_SHAREDMEMORYDATASYNC_SHAREDMEMORYGLOBAL_SHAREDMEMORYGLOBAL_H_
#define USER_ADDONS_SHAREDMEMORYDATASYNC_SHAREDMEMORYGLOBAL_SHAREDMEMORYGLOBAL_H_



#define                 MAX_Emcy_Msgs                   500u

/**
 * MBN CAN /CIP Core POST and Init Err status Bits.
 */
#define             MBN_CANCore_Post_CANMiscErr             (0x01u << 0u)
#define             MBN_CANCore_Post_CANHWErr               (0x01u << 1u)
#define             MBN_CANCore_Post_CANStackErr            (0x01u << 2u)
#define             MBN_CANCore_Post_CANTaskErr             (0x01u << 3u)
#define             MBN_CANCore_DataSynchInitErr            (0x01u << 4u)
#define             MBN_CANCore_CIPSynchInitErr             (0x01u << 5u)
#define             MBN_CANCore_LinuxSynchInitErr           (0x01u << 6u)

#define             MBN_CIPCore_Post_CIPMiscErr             (0x01u << 16u)
#define             MBN_CIPCore_DataSynchInitErr            (0x01u << 20u)
#define             MBN_CIPCore_CANSynchInitErr             (0x01u << 21u)
#define             MBN_CIPCore_EEPROMInitErr               (0x01u << 22u)
#define             MBN_CIPCore_ECatStackInitErr            (0x01u << 24u)

/**
 * @brief
 * Structure used from calls and tasks for passing All Module's Discovery Details to Shared Memory.
 *
 *  ModuleDiscoveryStatus                       :  All Modules Discovery Status                                                                     1 bytes
 *                                                  0 - Discovery Completed success / 1 - Discovery Partial(Not completed IO pin not received)
                                                    2 - Discovery code not matching with configured code / 0xff - Discovery Not completed
 *  DiscoveredIOModuleCnt                       :   IO Modules Discovered Count.                                                                    1 bytes
 *  DiscoveredPZModuleCnt                       :   Pressure Zone Discovered Count.                                                                 1 bytes
 *  IO_Discovered_ModulesType[IO_INSTANCE_MAX]  :   IO Modules Discovered Type.                                                                     9 bytes
 *   Pz_Details[PRESSUREZONES_MAX]              :   PressureZone Modules Discovered Details.                      18 Bytes * PRESSUREZONES_MAX  = 180 bytes
 *   ExtPropPZ_AvailCnt                         :   ExtProp PressureZone Discovered Count.                                                          1 bytes
 *                                                                                                                                        Total = 193 Bytes
 */
typedef struct __attribute__((packed))
{
    uint8_t                 ModuleDiscoveryStatus;
}system_discoverystatusinfo;


/**
 * @brief
 * Structure used from calls and tasks for passing Pressurezone Module Details to Shared Memory.
 *
 *  pzno                    :  Pressure Zone No. 0 - IO Modules [1 -10] PZ's.                           1 bytes
 *  extprop                 :  Emcy is for External Prop if 1 . 0 normal PZ.                            1 bytes
 *  modulepos               :  Module Position.                                                         1 bytes
 *  moduletype              :  Module Type.                                                             1 bytes
 *  errCode                 :  emergency error code.                                                    2 bytes
 *  addErrorCode[5]         :  pointer to 5 bytesCustom error code.                                     5 bytes
 *                                                                                            Total =  11 bytes
 */
typedef struct __attribute__((packed))
{
    uint8_t         pzno;
    uint8_t         extprop;
    uint8_t         modulepos;
    uint8_t         moduletype;
    uint16_t        errCode;
    uint8_t         addErrorCode[5u];

}EmergencyMsg_Info;


/**
 * @brief
 * Structure used from calls and tasks for passing Ecat Application State and Indicators State Details to Shared Memory.
 *
 *  RunLedState             :  Ethercat Application Run Led State.                                      1 bytes
 *  ErrLedState             :  Ethercat Application Error Led State.                                    1 bytes
 *  EcatState               :  Ethercat Application State.                                              1 bytes
 *  RFU                     :  Reserved for Futhure Use.                                                1 bytes
 *                                                                                            Total =   4 bytes
 */
typedef struct __attribute__((packed))
{

    uint8_t             RunLedState;
    uint8_t             ErrLedState;
    uint8_t             EcatState;
    uint8_t             RFU;
}ecat_runstateinfo;


#endif /* USER_ADDONS_SHAREDMEMORYDATASYNC_SHAREDMEMORYGLOBAL_SHAREDMEMORYGLOBAL_H_ */
