//This file was generated by the LASAL2 CodeGenerator  -- 
//Please, do not edit this file (it might be overwritten by the next generator run)
//{{LSL_DECLARATION

(*!
<Class
	Name               = "_OSKernel"
	Revision           = "0.5"
	GUID               = "{4294CD82-628C-11D6-8832-0048545E88BC}"
	RealtimeTask       = "false"
	CyclicTask         = "false"
	BackgroundTask     = "false"
	Sigmatek           = "true"
	OSInterface        = "true"
	HighPriority       = "false"
	Automatic          = "false"
	UpdateMode         = "Prescan"
	SharedCommandTable = "true"
	Objectsize         = "(284,120)"
	Comment            = "provides kernel functions and low-level routines from the OS">
	<Channels>
		<Server Name="Server0" GUID="{4294CD83-628C-11D6-8832-0048545E88BC}" Visualized="true" Initialize="false" WriteProtected="true" Retentive="false"/>
	</Channels>
	<Dependencies>
		<Files>
			<File Path=".\Source\code\OsiBaseNew.h" Include="false"/>
			<File Path=".\Source\code\OsiBaseNew.st"/>
			<File Path=".\SystemTypes.h" Include="false"/>
		</Files>
	</Dependencies>
	<RevDoku>
		<Owner Company="Sigmatek GmbH &amp; Co KG"/>
		<Dokumentation Revision="0.5" Date="2019-07-24" Author="hauale" Company="Sigmatek GmbH &amp; Co KG" Description="Added new function ReadDateTime"/>
		<Dokumentation Revision="0.4" Date="2012-01-01" Author="kiltob" Company="Sigmatek GmbH &amp; Co KG" Description="Some minor fixes"/>
		<Dokumentation Revision="0.3" Date="2012-03-28" Author="kiltob" Company="Sigmatek GmbH &amp; Co KG" Description="Added new function ResetRunApp"/>
	</RevDoku>
</Class>
*)
_OSKernel : CLASS
	TYPE
	  OS_SSR : STRUCT
	    InstallIRQ : pVoid;
	    InstallIRQObject : pVoid;
	    CreateMailbox : pVoid;
	    MailboxGet : pVoid;
	    MailboxPut : pVoid;
	    MailboxDelete : pVoid;
	    CreateSemaphore : pVoid;
	    SemSignal : pVoid;
	    SemPulse : pVoid;
	    SemWait : pVoid;
	    SemWaitCond : pVoid;
	    SemDelete : pVoid;
	    OutW : pVoid;
	    OutB : pVoid;
	    InpW : pVoid;
	    InpB : pVoid;
	    MemoryAccess : pVoid;
	    CanTxObj : pVoid;
	    AddCanObj : pVoid;
	    Malloc : pVoid;
	    Free : pVoid;
	    SetSysTime : pVoid;
	    SetSysDate : pVoid;
	    GetSysTime : pVoid;
	    GetSysDate : pVoid;
	    Realloc : pVoid;
	    InstallIRQLasal : pVoid;
	    Memmove : pVoid;
	    Memcpy : pVoid;
	    memset : pVoid;
	    Memcmp : pVoid;
	    LoginIntoCANNew : pVoid;
	    GetObjectInfo : pVoid;
	    dummy1 : pVoid;
	    dummy2 : pVoid;
	    dummy3 : pVoid;
	    dummy4 : pVoid;
	    OSDelaay : pVoid;
	    InstallDiasHandler : pVoid;
	    AddToServiceProvider : pVoid;
	    dummy11 : pVoid;
	    dummy12 : pVoid;
	    EE_read : pVoid;
	    EE_write : pVoid;
	    ButtonPressed : pVoid;
	    SetTimerIntVal : pVoid;
	    GetTimerIntVal : pVoid;
	    dummy20 : pVoid;
	    dummy21 : pVoid;
	    dummy22 : pVoid;
	    PROMGetInfo_socket : pVoid;
	    PROMSetData_Socket : pVoid;
	    PROMGetData_Socket : pVoid;
	    PROMGetInfo_Modul : pVoid;
	    PROMSetData_Modul : pVoid;
	    PROMGetData_Modul : pVoid;
	    PROMGetInfo_Flash : pVoid;
	    PROMSetDataFlash : pVoid;
	    PROMGetData_Flash : pVoid;
	    dummy30 : pVoid;
	    dummy31 : pVoid;
	    dummy32 : pVoid;
	    SSR_MallocV1 : pVoid;
	    SSR_ReallocV1 : pVoid;
	    mallocV1 : pVoid;
	    reallocV1 : pVoid;
	    SSR_Reboot : pVoid;
	    ReadDateTime : pVoid;
	    dummy34 : pVoid;
	    dummy35 : pVoid;
	    dummy36 : pVoid;
	    dummy37 : pVoid;
	    dummy38 : pVoid;
	    dummy39 : pVoid;
	    dummy40 : pVoid;
	    dummy41 : pVoid;
	    dummy42 : pVoid;
	    SSR_Reset : pVoid;
	    SSR_ResetApp : pVoid;
	    SSR_SetDIASError : pVoid;
	    dummy43 : pVoid;
	    dummy44 : pVoid;
	    dummy45 : pVoid;
	    dummy46 : pVoid;
	    dummy47 : pVoid;
	    dummy48 : pVoid;
	    SSR_ResetRunApp : pVoid;
	  END_STRUCT;
	END_TYPE
  //Servers:
	Server0 	: SvrChCmd_DINT;
  //Clients:
  //Variables:
  //Functions:
	
	FUNCTION _OSKernel
		VAR_OUTPUT
			ret_code 	: ConfStates;
		END_VAR;
				//! <Function Comment="This function sends a word value (16-Bit) to a given Port-Address." Name="OutWord"/>
	FUNCTION __CDECL VIRTUAL GLOBAL OutWord
		VAR_INPUT
			Portnumber 	: UINT;
			value 	: UINT;
		END_VAR;
				//! <Function Comment="This function sends a byte value to a given Port-Address. Note that the lower 8 bits of the Parameter Value are written to the port." Name="OutByte"/>
	FUNCTION __CDECL VIRTUAL GLOBAL OutByte
		VAR_INPUT
			Portnumber 	: UINT;
			value 	: UINT;
		END_VAR;
				//! <Function Comment="This function reads a word value (16-Bit) from a given Port-Address." Name="InWord"/>
	FUNCTION __CDECL VIRTUAL GLOBAL InWord
		VAR_INPUT
			Portnumber 	: UINT;
		END_VAR
		VAR_OUTPUT
			retval (AX) 	: UINT;
		END_VAR;
				//! <Function Comment="This function reads a byte value from a given Port-Address. Note that the value is returned in the lower 8 bits of the retval." Name="InByte"/>
	FUNCTION __CDECL VIRTUAL GLOBAL InByte
		VAR_INPUT
			Portnumber 	: UINT;
		END_VAR
		VAR_OUTPUT
			retval (AX) 	: UINT;
		END_VAR;
				//! <Function Comment="This function can give the User(Application) rights for READ/WRITE access on a given memory space." Name="MemoryAccess"/>
	FUNCTION __CDECL VIRTUAL GLOBAL MemoryAccess
		VAR_INPUT
			addr 	: UDINT;			//! <Variable Comment="Parameter Addr points to the space in memory." Name="MemoryAccess.addr"/>
			length 	: UDINT;			//! <Variable Comment="Parameter Length specifies the length of the memory block, that has to be accessed." Name="MemoryAccess.length"/>
		END_VAR
		VAR_OUTPUT
			retval (EAX) 	: DINT;			//! <Variable Comment="If the function succeeds, it returns 0. &#10;If the function fails, it returns -1." Name="MemoryAccess.retval"/>
		END_VAR;
				//! <Function Comment="This function reads the system current time." Name="GetSystemTime"/>
	FUNCTION __CDECL VIRTUAL GLOBAL GetSystemTime
		VAR_INPUT
			timestruct 	: ^SYSTIME;			//! <Variable Comment="Parameter TimeStruct points to an SYSTIME structure. If it succeeds, the structure is filled with the actual time values." Name="GetSystemTime.timestruct"/>
		END_VAR;
				//! <Function Comment="This function reads the system current date." Name="GetSystemDate"/>
	FUNCTION __CDECL VIRTUAL GLOBAL GetSystemDate
		VAR_INPUT
			datestruct 	: ^SYSDATE;			//! <Variable Comment="Parameter DateStruct points to an SYSDATE structure. If it succeeds, the structure is filled with the actual date values." Name="GetSystemDate.datestruct"/>
		END_VAR;
				//! <Function Comment="This function writes a new system-time." Name="SetSystemTime"/>
	FUNCTION __CDECL VIRTUAL GLOBAL SetSystemTime
		VAR_INPUT
			newtime 	: ^SYSTIME;			//! <Variable Comment="Parameter NewTime points to an SYSTIME structure, which has to be filled with the new time values." Name="SetSystemTime.newtime"/>
		END_VAR;
				//! <Function Comment="This function writes a new system-date." Name="SetSystemDate"/>
	FUNCTION __CDECL VIRTUAL GLOBAL SetSystemDate
		VAR_INPUT
			newdate 	: ^SYSDATE;			//! <Variable Comment="Parameter NewDate points to an SYSDATE structure, which has to be filled with the new date values." Name="SetSystemDate.newdate"/>
		END_VAR;
				//! <Function Comment="This method is called to install a user-defined function to service an IRQ. The function is passed the number of the IRQ to trap, the function pointer of the user&apos;s service-routine and the this pointer of the Lasal class object." Name="InstallIRQLasal"/>
	FUNCTION __CDECL VIRTUAL GLOBAL InstallIRQLasal
		VAR_INPUT
			IRQnumber 	: UINT;
			IRQFunction 	: pVoid;
			thispointer 	: pVoid;
		END_VAR
		VAR_OUTPUT
			retval (EAX) 	: DINT;
		END_VAR;
				//! <Function Comment="This method is called to install an object to service an IRQ. The function is passed the number of the IRQ to trap and the this pointer of the Lasal class object." Name="InstallIRQObject"/>
	FUNCTION __CDECL VIRTUAL GLOBAL InstallIRQObject
		VAR_INPUT
			IRQNumber 	: UINT;
			IRQFunction 	: pVoid;
		END_VAR
		VAR_OUTPUT
			retval (EAX) 	: DINT;
		END_VAR;
				//! <Function Comment="This function passes a string to the LasalOS SYSTEM-KERNEL." Name="AddToServiceProvider"/>
	FUNCTION __CDECL VIRTUAL GLOBAL AddToServiceProvider
		VAR_INPUT
			command 	: ^CHAR;			//! <Variable Comment="Parameter Command points to the commando string to execute, which must not be longer than 127 characters. The command string can be a valid CLI (Command Line Interface) command and the string &apos;EXEC &apos; must be put in front of the command string." Name="AddToServiceProvider.command"/>
			immediatly 	: UDINT;			//! <Variable Comment="If Parameter Immediately is set to a positive value, the command is executed AT ONCE, otherwise it is executed the next time the kernel loops through (on a 10ms period)." Name="AddToServiceProvider.immediatly"/>
		END_VAR
		VAR_OUTPUT
			retval (EAX) 	: DINT;
		END_VAR;
				//! <Function Comment="Reboot CPU." Name="Reboot"/>
	FUNCTION __CDECL VIRTUAL GLOBAL Reboot;
				//! <Function Comment="Reset CPU (stop application!)." Name="Reset"/>
	FUNCTION __CDECL VIRTUAL GLOBAL Reset;
				//! <Function Comment="Enable/Disable DIAS Error." Name="SetDIASError"/>
	FUNCTION __CDECL VIRTUAL GLOBAL SetDIASError
		VAR_INPUT
			enable 	: DINT;			//! <Variable Comment="1 = enable &#10;0 = disable" Name="SetDIASError.enable"/>
		END_VAR
		VAR_OUTPUT
			retcode (EAX) 	: DINT;			//! <Variable Comment="Return Values: &#10;  0   if OK" Name="SetDIASError.retcode"/>
		END_VAR;
				//! <Function Comment="Reset and Run the application" Name="ResetRunApp"/>
	FUNCTION __CDECL VIRTUAL GLOBAL ResetRunApp;
				//! <Function Comment="This function reads the system current date and time" Name="ReadDateTime"/>
	FUNCTION __CDECL VIRTUAL GLOBAL ReadDateTime
		VAR_INPUT
			Time_LSL 	: ^SYSDATETIMEMS;			//! <Variable Comment="Parameter DateStruct points to an SYSTIMEMS structure. If it succeeds, the structure is filled with the actual values." Name="ReadDateTime.Time_LSL"/>
		END_VAR;
  //Tables:
	FUNCTION @STD
		VAR_OUTPUT
			ret_code	: CONFSTATES;
		END_VAR;
	FUNCTION GLOBAL TAB @CT_;
END_CLASS;

//}}LSL_DECLARATION


FUNCTION GLOBAL TAB _OSKernel::@CT_
0$UINT,
2#0100000000001000$UINT, //TY__OSKERNEL
0$UINT, 5$UINT, (SIZEOF(::_OSKernel))$UINT, 
1$UINT, 0$UINT, 0$UINT, 
TO_UDINT(3045737964), "_OSKernel", //Class
TO_UDINT(0), 0, 0$UINT, 0$UINT, //Baseclass
//Servers:
(::_OSKernel.Server0.pMeth)$UINT, _CH_CMD$UINT, 2#0000000000000000$UINT, TO_UDINT(2759080719), "Server0", 
//Clients:
END_FUNCTION


#define USER_CNT__OSKernel 17

TYPE
	_LSL_STD_VMETH	: STRUCT
			CmdTable	: CMDMETH;
			UserFcts	: ARRAY[0..USER_CNT__OSKernel] OF ^Void;
	END_STRUCT;
END_TYPE



//{{LSL_IMPLEMENTATION


//*********************Inserted from <.\OS Interface\code\OSKernel_00_00.st>*********************



 



#include <Rtos_interfaces.h> // we need this for the SysCIL functions
#include "..\..\Source\code\OsiBaseNew.h"


// Dummy Functions, if OS is too old
#pragma warning (disable:73)

FUNCTION __CDECL DummyParam0Ret0

END_FUNCTION
FUNCTION __CDECL DummyParam1DINTRet1DINT
VAR_INPUT
	param1	: DINT;
END_VAR
VAR_OUTPUT
	ret1	: DINT;
END_VAR

	ret1 := -1;

END_FUNCTION

#pragma warning (default:73)


FUNCTION  _OSKernel::_OSKernel
VAR_OUTPUT
	ret_code		: CONFSTATES;
END_VAR
VAR
    pSSR    : ^OS_SSR;
	aMeths	: ARRAY[0..USER_CNT__OSKernel] OF ^void;
	retv    : SYS_ERROR;
END_VAR;

	retv := OS_CILGet("SSR", #pSSR$void);

	if retv <> SYS_ERR_NONE then

		TRACE("ERROR: Kernel Interface not available with this version/platform!");
		ret_code	:= C_UNKNOWN_CONSTR;
    else
		
		// low-level
		aMeths [0]	:= pSSR^.OutW;
		aMeths [1]  := pSSR^.OutB;
		aMeths [2]	:= pSSR^.InpW;
		aMeths [3]	:= pSSR^.InpB;
		aMeths [4]	:= pSSR^.MemoryAccess;

		// time & date
		aMeths [5]	:= pSSR^.GetSysTime;
		aMeths [6]	:= pSSR^.GetSysDate;
		aMeths [7]	:= pSSR^.SetSysTime;
		aMeths [8]	:= pSSR^.SetSysDate;

		// misc
		aMeths [9]	:= pSSR^.InstallIRQLasal;
		aMeths [10]	:= pSSR^.InstallIRQObject;
		aMeths [11]	:= pSSR^.AddToServiceProvider;

		// Reboot, requires OS >= 01.01.080
		if _RtOSversion >= 16#1150 then
		  aMeths [12] := pSSR^.SSR_Reboot;
		else
		  aMeths [12] := #DummyParam0Ret0();
		end_if;

		if _RtOSversion >= 16#1160 then			// requires >= 01.01.096
		  aMeths [13] := pSSR^.SSR_ResetApp;
		  aMeths [14] := pSSR^.SSR_SetDIASError;
		else
		  aMeths [13] := #DummyParam0Ret0();
		  aMeths [14] := #DummyParam1DINTRet1DINT();
		end_if;
    
    if _RtOSversion >= 16#12C2 then	
      aMeths [15] := pSSR^.SSR_ResetRunApp;
    else
      aMeths [15] := #DummyParam0Ret0();
    end_if;
    
      aMeths [16] := pSSR^.ReadDateTime;

		ret_code	:= InitOsiM_new(#aMeths[0]$void, USER_CNT__OSKernel);
	end_if;

END_FUNCTION //  OSKernel::OSKernel
//		aMeths [0]	:= pSSR^.CanTxObj
//		aMeths [0]	:= pSSR^.AddCanObj
//		aMeths [0]	:= pSSR^.Malloc
//		aMeths [0]	:= pSSR^.Free
//		aMeths [0]	:= pSSR^.dummy20
//		aMeths [0]	:= pSSR^.dummy21
//		aMeths [0]	:= pSSR^.dummy22
//		aMeths [0]	:= pSSR^.PROMGetInfo_socket
//		aMeths [0]	:= pSSR^.PROMSetData_Socket
//		aMeths [0]	:= pSSR^.PROMGetData_Socket
//		aMeths [0]	:= pSSR^.PROMGetInfo_Modul
//		aMeths [0]	:= pSSR^.PROMSetData_Modul
//		aMeths [0]	:= pSSR^.PROMGetData_Modul
//		aMeths [0]	:= pSSR^.PROMGetInfo_Flash
//		aMeths [0]	:= pSSR^.PROMSetDataFlash
//		aMeths [0]	:= pSSR^.PROMGetData_Flash
//		aMeths [0]	:= pSSR^.dummy30
//		aMeths [0]	:= pSSR^.dummy31
//		aMeths [0]	:= pSSR^.dummy32
//		aMeths [0]	:= pSSR^.Realloc
//		aMeths [0]	:= pSSR^.InstallIRQ
//		aMeths [0]	:= pSSR^.Memmove
//		aMeths [0]	:= pSSR^.Memcpy
//		aMeths [0]	:= pSSR^.memset
//		aMeths [0]	:= pSSR^.Memcmp
//		aMeths [0]	:= pSSR^.LoginIntoCANNew
//		aMeths [0]	:= pSSR^.GetObjectInfo
//		aMeths [0]	:= pSSR^.dummy1
//		aMeths [0]	:= pSSR^.dummy2
//		aMeths [0]	:= pSSR^.dummy3
//		aMeths [0]	:= pSSR^.dummy4
//		aMeths [0]	:= pSSR^.InstallDiasHandler
//		aMeths [0]	:= pSSR^.dummy11
//		aMeths [0]	:= pSSR^.dummy12
//		aMeths [0]	:= pSSR^.EE_read
//		aMeths [0]	:= pSSR^.EE_write
//		aMeths [0]	:= pSSR^.ButtonPressed