/*
 * Ethercat_AppCode.h
 *
 *  Created on: Apr 20, 2025
 *      Author: tummalanr
 */

#ifndef ETHERCAT_APPCODE_ETHERCAT_APPCODE_H_
#define ETHERCAT_APPCODE_ETHERCAT_APPCODE_H_


#include <inttypes.h>
#include <kernel/dpl/DebugP.h>
#include <kernel/dpl/ClockP.h>
#include <kernel/dpl/EventP.h>






//custom headers


#include "SystemStsConfig.h"
#include "AppSharedMemory.h"
#include "IPCDataSyncGlobal.h"
#include    "SharedMemoryExterns.h"

#define         ModuleIndexIncrement                    0x10u              //refer to xls sheet used in SSC tool
#define         MaximumNoofmodules                      0x50u                //74 required max 80 allocated



extern system_discoverystatusinfo  app_sys_discvrystsinfo;


extern uint16_t      dop_frameindx;


extern volatile uint16_t ecip_ioframebuf[350u];     //later check and adjust as per DIP size
extern volatile uint16_t ecop_ioframebuf[350u];     //later check and adjust as per DIP size


extern OBJCONST TOBJECT OBJMEM * COE_GetObjectDictionary(void);
extern UINT16 COE_AddObjectToDic(TOBJECT OBJMEM * pNewObjEntry);
extern void COE_RemoveDicEntry(UINT16 index);

extern void common_main();



extern void  Generate_Slot_Module_Map(void);

extern UINT8  MBNInformationRead(UINT16 index, UINT8 subindex, UINT32 dataSize, UINT16 *pData, UINT8 bCompleteAccess);
extern UINT8 MBNOperationalReadIndex2000( UINT16  index, UINT8 subindex,UINT32 dataSize, UINT16 *pData, UINT8 bCompleteAccess);
extern UINT8  MBNDiagnosticRead(UINT16 index, UINT8 subindex, UINT32 dataSize, UINT16 MBXMEM * pData, UINT8 bCompleteAccess);


//Module Ident from XL sheet used in SSC
#define         MBN_ModuleIdent                     0x000F9701u     //0x00000010u
#define         DIM8_ModuleIdent                    0x000F9702u     //0x00000001u
#define         DIM12_ModuleIdent                   0x000F9703u     //0x0000000Cu
#define         DO_ModuleIdent                      0x000F9704u     //0x00000002u
#define         DOM12_ModuleIdent                   0x000F9705u     //0x00000011u
#define         DIOM8_ModuleIdent                   0x000F9706u     //0x00000003u
#define         DIOM12_ModuleIdent                  0x000F9707u     //0x0000000Du
#define         AI_ModuleIdent                      0x000F9708u     //0x00000004u
#define         AO_ModuleIdent                      0x000F9709u     //0x00000005u
#define         AIO_ModuleIdent                     0x000F970Au     //0x00000006u
#define         ISEMBASIC_ModuleIdent               0x000F970Bu     //0x0000000Fu
#define         ISEMDIAG_ModuleIdent                0x000F970Cu     //0x00000007u
#define         DIAGVALVE_ModuleIdent               0x000F970Du     //0x00000009u
#define         STNDSTATION_ModuleIdent             0x000F970Eu     //0x00000008u
#define         INTRPROP_ModuleIdent                0x000F970Fu     //0x0000000Au
#define         EXTRPROP_ModuleIdent                0x000F9710u     //0x0000000Bu
#define         FAULTSTATION_ModuleIdent            0x000F9711u     //0x0000000Eu




typedef struct  __attribute__((packed))
{
    UINT8                   SlotNo;
    UINT32                  ModuleIdent;
    UINT8                   PressureZoneId;
    UINT8                   DVposition;
}slot_modules_map;
//

typedef union  __attribute__((packed))
{
    UINT8     onebyte[4u];
    UINT16    twobyte[2u];
    UINT32    fourbyte;
      //uint8_t     str[20];
}datatypeconv;

extern slot_modules_map        slotmodulemap[MaximumNoofmodules];

extern UINT8    slotmoduleassignedcount;

#endif /* ETHERCAT_APPCODE_ETHERCAT_APPCODE_H_ */
