using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace PACNET
{
/// Backplane timer API
public class BPTimer
{
/// TIMEROUT
public const int TIMEROUT = 0;
/// TIMER1
public const int TIMER1 = 1;
/// TIMER2
public const int TIMER2 = 2;
//10.1. PAC_API DWORD pac_GetBPTimerTimeTick_ms(void)
///
/// This function returns the number of milliseconds since the device booted, excluding any
/// time that the system was suspended.
///
/// The number of milliseconds indicates success.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetBPTimerTimeTick_ms")]
public extern static uint GetBPTimerTimeTick_ms();
//10.2. PAC_API WORD pac_GetBPTimerTimeTick_us(void)
///
/// This function returns the number of microsecond since the device booted, excluding any
/// time that the system was suspended.
///
/// The number of microseconds indicates success.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetBPTimerTimeTick_us")]
public extern static ushort GetBPTimerTimeTick_us();
//10.3. PAC_API void pac_KillBPTimer(int type)
///
/// This function kills the timer event identified by type, set by an earlier call to
/// pac_SetBPTimer.
///
/// [in] Two type timer, 1 microsecond timer and 10 microsecond timer
[DllImport("PACSDK.dll", EntryPoint = "pac_KillBPTimer")]
public extern static void KillBPTimer(int type);
//10.4. PAC_API bool pac_SetBPTimer(int type, unsigned int uElapse, PAC_TIMEROUT_CALLBACK_FUNC f)
///
/// This function installs a hardware timer. A time-out value is specified, and every time a
/// time-out occurs, the system posts an interrupt signal to the system and the pass the
/// message to an application-defined callback function.
///
/// [in] Two type timer, 1 microsecond timer and 10 microseconds timer
/// [in] Timer 1: Specifies the elapses time value for a timerout signal 0~65535, in microseconds.
/// Timer 2: Specifies the elapses time value for a timerout signal 0~65535, in 10 microseconds.
/// Specifies the address of the application-supplied f callback function.
/// The value is true if the function was installed successfully. It is zero and the function
/// cannot be installed.
[DllImport("PACSDK.dll", EntryPoint = "pac_SetBPTimer")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool SetBPTimer(int type, uint uElapse, PAC_CALLBACK_FUNC f);
//10.5. PAC_API bool pac_SetBPTimerOut(unsigned int uHighElapse, unsigned int uLOwElapse, PAC_TIMEROUT_CALLBACK_FUNC f)
///
/// The timerout pin on each slot will be triggered while a timerout signal has been outputted.
/// The timeourput pin can be used to acquire the synchronized data on each slot.
///
/// [in] Specifies the elapses time value for a high wave of the timerout signal 0~65535, in microseconds.
/// [in] Specifies the elapses time value for a low wave of the timerout signal 0~65535, in microseconds.
/// Specifies the address of the application-supplied f callback function.
/// The value is true if the function was installed successfully. It is zero and the function
/// cannot be installed.
[DllImport("PACSDK.dll", EntryPoint = "pac_SetBPTimerOut")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool SetBPTimerOut(uint uHighElapse, uint uLOwElapse, PAC_CALLBACK_FUNC f);
//10.6. PAC_API bool pac_SetBPTimerInterruptPriority(int type, int nPriority)
///
/// This function sets the priority for a real-time thread of the backplane timer
///
/// [in] Specifies the backplane timer type. 0: Timerout, 1: Timer 1, 2: Timer 2
/// [in] Return true if success, otherwise false.This value can range from 0 through 255, with 0 as the highest priority.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_SetBPTimerInterruptPriority")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool SetBPTimerInterruptPriority(int type, int nPriority);
}
}