/*
 * AppSharedMemory.h
 *
 *  Created on: Dec 1, 2024
 *      Author: tummalanr
 */

#ifndef APPSHAREDMEMORY_H_
#define APPSHAREDMEMORY_H_

#include <kernel/dpl/QueueP.h>





#define     Debug_Verbose               1u

/**
 * @brief App Func Return typedef defines
 */
typedef enum {
    AppRET_OK,                       //< all ok
    AppRET_GenericErr,               //<  Generic Error

    AppExecCore_Err,                 //Execution Core Error
    AppMCan0_DrvErr,                 //MCan0 Driver Init Error
    AppMCan1_DrvErr,                 //MCan1 Driver Init Error
    AppMCan_StackTmrInitErr,         //MCan Stack Timer Init Error
    AppMCan_StackInitErr,            //MCan Stack Init Error
    AppMCan_StackNMTRegErr,          //MCan Stack NMT Register Error
    AppMCan_ErrCtrlRegErr,           //MCan Stack Err Cntrl Register Error
    AppMCan_USDOSrvRdCBRegErr,       //MCan Stack USDO Server RD Register Error
    AppMCan_USDOSrvChkWrCBRegErr,    //MCan Stack USDO Server Check Write Register Error
    AppMCan_USDOSrvWrCBRegErr,       //MCan Stack USDO Server WR Register Error
    AppMCan_PDORecvdCBRegErr,        //MCan Stack PDO Received Register Error
    AppMCan_BusStateCBRegErr,        //MCan Stack Bus  State Register Error
    AppMCan_ComStateCBRegErr,        //MCan Stack Comm  State Register Error
    AppMCan_EmcyConsmStateCBRegErr,  //MCan Stack Emmergency State Register Error
    AppMCan_EmcyStateCBRegErr,       //MCan Stack Emmergency State Register Error
    AppMCan_USDOClntRdCBRegErr,      //MCan Stack USDO Client RD Register Error
    AppMCan_USDOClntWrCBRegErr,      //MCan Stack USDO Client WR Register Error
    AppMCan_PDOUpdateCBRegErr,       //MCan Stack LSS State Register Error
    AppMCan_LSSStateCBRegErr,        //MCan Stack LSS State Register Error
    AppMCan0_DrvEnableErr,           //MCan0 Driver Enable Error
    AppMCan1_DrvEnableErr,           //MCan1 Driver Enable Error

    AppMCan_USDOEventGrpCreateErr,   //MCan USDO Task Event Group Create Error
    AppMCan_USDOQueueCreateErr,      //MCan USDO RW Queue Create Error

    AppMCan_USDOTaskCreateErr,       //MCan Tasks Create Error

    AppMCan_USDORdTimeOutErr,       //MCan USDO Read Timeout Error
    AppMCan_USDORdProcErr,          //MCan USDO Read Process Error
    AppMCan_USDORdRespErr,          //MCan  USDO Read Resp Error
    AppMCan_USDOWrTimeOutErr,       //MCan USDO Read Timeout Error
    AppMCan_USDOWrProcErr,          //MCan USDO Read Process Error
    AppMCan_USDOWrRespErr,          //MCan  USDO Write Resp Error

    AppMCan_ODUpdateErr,            //OD update Error
    AppMCan_ODEventGrpCreateErr,    //MCan OD Task Event Group Create Error
    AppMCan_ODUpdtQueueCreateErr,   //MCan OD Update RW Queue Create Error
    AppMCan_ODUpdtTaskCreateErr,        //MCan Tasks Create Error

    AppMCan_MainTaskCreateErr,       //MCan MainTask Create Error
    AppMCan_LSSTaskCreateErr,        //LSS task Create Error
    AppMCanHBMONTaskCreateErr,       //Node HB MonitorTask Create Error
    AppMCan_NodeOprSetErr,          //Node Set Operational State Error

    AppMCan0_DiscoveryTimeoutErr,    //MCan0 IO Module discovery Timeout Error
    AppMCan0_DiscoveryErr,          //MCan0 IO Module discovery  Error

    AppMCan1_DiscoveryTimeoutErr,    //MCan1 Valve Module discovery Timeout Error
    AppMCan1_DiscoveryErr,          //MCan1 Valve Module discovery  Error

    AppMCan0_SetHBDurErr,           //MCan0 IO Module Set HB Dur  Error
    AppMCan1_SetHBDurErr,           //MCan1 Valve Module Set HB Dur  Error

    AppPZ_GetModuleInfoErr,        //Get PZ Modules Info  Error

    AppValParaIndex_Err,           //Valve parameter index error

    AppSWTimerCreate_Err,           //SW TimerCreate Error

    AppIODiscoveryList_Err,         //IO Modules Discovered List Save Error
    AppIOReqInst_Err,               //Requested IO Modules Instance Error
    AppIOReqBrdId_Err,               //Requested IO Modules Board Id Error

    AppSharedMem_InitErr,           //Error while Creating and Initializing Shared Memory
    App_SHMWRQueueCreateErr,        //SharedMemory Write Queue Create Error
    AppGetSHMLockErr,               //Get Shared Memory Access Lock Error
    AppGetSHMLockTimeOutErr,        //Get Shared Memory Access Lock Timeout Error
    AppSHMUpdateErr,                //Updating IPC shared memory Error

    APPAcyclicDataNotChanged,       //Acyclic Data of the Module Not changed
    APPAcyclicDataChanged,          //Acyclic Data of the Module changed
    APPAcyclicUnknownPara,          //Unknown Acyclic Data requested
    APPAcyclicProcessErr,           //Acyclic ProcessErr

    APPCyclicDataNotChanged,       //Cyclic Data of the Module Not changed
    APPCyclicDataChanged,          //Cyclic Data of the Module changed

    AppIPC_MsgEventGrpCreateErr,    //IPC Msg Process Task Event Group Create Error
    AppIPC_MsgProcessTaskCreateErr,  //IPC Msg process Task Create Error

    AppMainCoreTaskCreateErr,           //Main Core SharedMemory Update Task Creat Error

    AppGetIPCSHMLockErr,               //Get IPC Shared Memory Access Lock Error
    AppGetIPCSHMLockTimeOutErr,     //Get IPC Shared Memory Access Lock Timeout Error
    AppIPCSHMUpdateErr,             //Updating IPC shared memory Error
    AppMCan_HBEMCYEventGrpCreateErr,    //eVENT gROUP FRO hb mONITOR AND eMCY

    //upto 74
    IOCyclicData_InvalidModule = 75,     //Invalide Module while Getting IO Cyclic Data from SHM
    IOCyclicData_NoValidData,       //No valid IO Cyclic Module data

    TemperatureSensorNotFound, //Temperature Sensor not found on i2c0

    EepromTestError,               //Eeprom Test Error used in CIP
    EepromWriteError,               //EepromWrite Error used in CIP
    EepromReadError,               //EepromRead Error used in CIP
    EepromCRCError,               //Eeprom CRC Error used in CIP
    EepromTaskCreateError,               //Eeprom Read/Write Task Error used in CIP

    App_UnknownErr                  //Unknown Error
}AppRET_T;

/*typedef enum {
    AppRET_OK,                       //< all ok
    AppRET_GenericErr,               //<  Generic Error

    AppExecCore_Err,                 //Execution Core Error


    AppPZ_GetModuleInfoErr,        //Get PZ Modules Info  Error


    AppIODiscoveryList_Err,         //IO Modules Discovered List Save Error
    AppIOReqInst_Err,               //Requested IO Modules Instance Error
    AppIOReqBrdId_Err,               //Requested IO Modules Board Id Error

    AppGetIPCSHMLockErr,               //Get IPC Shared Memory Access Lock Error
    AppGetIPCSHMLockTimeOutErr,     //Get IPC Shared Memory Access Lock Timeout Error
    AppIPCSHMUpdateErr,             //Updating IPC shared memory Error

    AppSharedMem_InitErr = 51,       //Error while Creating and Initializing Shared Memory
    AppGetSHMLockErr = 52,               //Get Shared Memory Access Lock Error
    AppGetSHMLockTimeOutErr,        //Get Shared Memory Access Lock Timeout Error
    AppSHMUpdateErr,             //Updating IPC shared memory Error


    IOCyclicData_InvalidModule,     //Invalide Module while Getting IO Cyclic Data from SHM
    IOCyclicData_NoValidData,       //No valid IO Cyclic Module data

    TemperatureSensorNotFound = 75, //Temperature Sensor not found on i2c0

    EepromTestError,               //Eeprom Test Error used in CIP
    EepromWriteError,               //Eeprom Write Error used in CIP
    EepromReadError,               //Eeprom Read Error used in CIP
    EepromCRCError,               //Eeprom CRC Error used in CIP

    App_UnknownErr                  //Unknown Error
}AppRET_T;*/




//********************************************************************************************************************************************
//Instance IDS
//#define             INSTANCE_NONE        0x00u

#define             IO_INSTANCE_1        0x01u
#define             IO_INSTANCE_2        0x02u
#define             IO_INSTANCE_3        0x03u
#define             IO_INSTANCE_4        0x04u
#define             IO_INSTANCE_5        0x05u
#define             IO_INSTANCE_6        0x06u
#define             IO_INSTANCE_7        0x07u
#define             IO_INSTANCE_8        0x08u
#define             IO_INSTANCE_9        0x09u

//#define             IO_INSTANCE_MAX      9u

//********************************************************************************************************************************************



//IO Modules for 1 ~ 9  LockNos*******************************************************************************************

#define SPINLOCKNO_CYCLIC_IOMODULES                     (20u)
#define ACYCLIC_SPINLOCKNO_IOMODULES                    (21u)

#define SPINLOCKNO_CYCLIC_PZx                           (22u)
#define SPINLOCKNO_ACYCLIC_PZx                          (23u)


#define SPINLOCKNO_SYSTEM_INFO                          (60u)

#define SPINLOCKNO_MBN_INFO                             (34u)

/**
 * SpinLock Wait Timeout.
 * 1500 : 1500 * 1.25 ns = 1.875 us
 * 2500 : 2500 * 1.25 ns = 3.125 us
 * 3500 : 3500 * 1.25 ns = 4.375 us
 */
#define     SPINLOCK_GET_TIMEOUT                1500u

//********************************************************************************************************************************************
#define                 SHM_Max_ReqIds              25u


#define             Debug_VerboseSHM        1
//********************************************************************************************************************************************

#define                 SHM_Max_ReqIds              25u

//********************************************************************************************************************************************

//#pragma pack(1)
typedef struct __attribute__((packed))
{
    uint8_t             instanceId;          // 1 ~ 9 : IO Modules
    uint8_t             BoardId;             //BoardId Type of Board
    uint8_t             channelno;           //Used for AO/AI/AIO/Errors sts   channels .For DI it is already 1 byte (for all channels)

}iocyclic_ciptocan_req;
//#pragma pack()



#pragma pack(1)
typedef struct IPCCyclic_Queue_Elem_s
{
    QueueP_Elem lnk;
    uint32_t    msgval;
} IPCCyclic_Queue_Elem;
#pragma pack()





#define APP_SHM_TASK_STACK_SIZE      16384u      //3072U

#define SPINLOCK_BASE_ADDR              (CSL_SPINLOCK0_BASE)

//Data IN SHARED MEMORY******************************************************
//Total Shared Memory Allocated
//USER SHARED MEM       :       32768 Bytes
//LOG  SHARED MEM       :       16384 Bytes             //Can be reduced and added to USER SHARED MEM
//IPC  SHARED MEM       :       16384 Bytes
//Data IN SHARED MEMORY******************************************************




#endif /* APPSHAREDMEMORY_H_ */
