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

#ifndef USER_ADDONS_SHAREDMEMORYDATASYNC_SHAREDMEMORYEXTERNS_H_
#define USER_ADDONS_SHAREDMEMORYDATASYNC_SHAREDMEMORYEXTERNS_H_

#include <kernel/dpl/SemaphoreP.h>
#include <kernel/dpl/EventP.h>

#include "SharedMemoryGlobal.h"

#include "AppSharedMemory.h"
#include "MainCoreGlobal.h"

#define             CANDiscoveryComplete_EVENT_BIT          (0x000001u)
#define             CIPModule_Running_EVENT_BIT             (0x000002u)

extern volatile    system_discoverystatusinfo      system_discovery_status;
//extern volatile    system_discoverystatusinfo      system_discovery_status __attribute__((aligned(1), section(".bss.user_shared_mem")));

extern volatile    mbn_servicedata                  MBN_Service_info;


extern uint8_t  CAN_ModuleDiscovery_Finished;

//SHMDataSynchTasks.c
extern uint32_t   SystemStatusConfigReqIDs[SHM_Max_ReqIds];
extern uint8_t    sysstscnfgreqidindex;

//SHMDataSynchInit.c
extern AppRET_T App_ShrdMem_Init(void);
extern EventP_Object       gSysConfigSts_DataRDWRSynchEvent;
extern void APP_SHM_SysConfigStsRDWRTask(void* pArgs_p);

extern SemaphoreP_Object gSemCyclic_IOModule_RDSynch;
extern char App_IPC_ShrdMem_Init(void);
extern  EventP_Object   gACyclic_IOModule_SynchEvent;
extern EventP_Object   gACyclic_PZxModule_SynchEvent;

extern SemaphoreP_Object   Cyclic_IOModules_mutexObj;
extern SemaphoreP_Object   ACyclic_IOModules_mutexObj;

extern SemaphoreP_Object   System_Info_mutexObj;
extern EventP_Object gCAN_ModuleStatusSynchEvent;

extern AppRET_T sysinfo_sharemem_lock(void);
extern void sysinfo_sharemem_unlock(void);



extern ecat_runstateinfo curecatstate;
extern ecat_runstateinfo prevecatstate;

extern  uint16_t MBN_IPC_ClientId;

extern  uint32_t    mbnreqrecvd;

extern SemaphoreP_Object   mbn_datasyncObj;
extern SemaphoreP_Object   mbn_mutexObj;

extern SemaphoreP_Object   Cyclic_PZx_mutexObj;
extern SemaphoreP_Object   ACyclic_PZx_mutexObj;


extern  EventP_Object   gACyclic_IOModule_SynchEvent;
extern  EventP_Object   gACyclic_IOModule_RDRespEvent;
extern  EventP_Object   gIOModuleAcyclicWriteEvent;
extern  EventP_Object   gPZxModuleAcyclicWriteEvent;
extern EventP_Object   gACyclic_PZxModule_RDRespEvent;


extern uint32_t            spinlockBaseAddr;

extern void APP_SHM_IOCyclicRDTask(void* pArgs_p);
extern void APP_SHM_IOACyclicWRTask(void* pArgs_p);

extern void APP_SHM_IOACyclicUpdateTask(void* pArgs_p);
extern void APP_SHM_PZxACyclicUpdateTask(void* pArgs_p);

extern void APP_SHM_IOPZCyclicWRTask(void* pArgs_p);
extern void APP_SHM_PZxACyclicWRTask(void* pArgs_p);
extern void APP_SHM_MBNTask(void* pArgs_p);

//extern QueueP_Handle   gIOCyclicQueuehandle;



extern  SemaphoreP_Object gSemCyclic_IOPZModule_WRSynch;

extern void PZx_ModulesPDO_ObjectUpdate(uint8_t pzno, uint32_t *MsgVal);
extern void IO_ModulesPDO_ObjectUpdate(uint32_t *MsgVal);

extern AppRET_T Get_PZxModule_CyclicInputData(uint8_t posid);

extern void Get_SHMEmergencyMsgs(void);
extern void SendEmcyMsg(void);

extern AppRET_T TemperatureSensor_probe(void);
extern uint8_t tempemcycheck;
extern uint8_t vavbemcycheck;

#endif /* USER_ADDONS_SHAREDMEMORYDATASYNC_SHAREDMEMORYEXTERNS_H_ */
