//////////////////////////////////////////////////////////////////
//
// new.c - C file
//
// This file was generated using the RTX 7.0.0 Application Wizard.
//
//////////////////////////////////////////////////////////////////
#include "new.h"
PMSGSTR pMsg;
HANDLE hShm,hSemPost,hSemQuit,hSemStart,hSemConfig;
HANDLE hPowerThread,hConfigThread;
LPDWORD lpExitCode;
BYTE nch;
DWORD dwMaximumSizeHigh = 0;
LONG lInitialCount = 0;
LONG lMaximumCount = 1;
void PcmInit()// 采集卡初始化
{
RtWritePortUchar(CT_PORT_BASE+2,0);//读状态 清IQR
RtWritePortUchar(CT_PORT_BASE+12,0x18);//通道选择 第1通道
RtWritePortUchar(CT_PORT_BASE+11,0xB6);//8254控制字,控制定时器
RtWritePortUchar(CT_PORT_BASE+10,0xA0);//8254定时器2 f=8M/4k=2kHz
RtWritePortUchar(CT_PORT_BASE+10,0x0F);
nch=0;
}
void ComuInit()
{
BOOL bInit = FALSE;
HANDLE handle;
if (!bInit)
{
//open shared memory
hShm=RtOpenSharedMemory(PAGE_READWRITE, FALSE, MSGSTR_SHM, (LPVOID *) &pMsg);
// hShm=RtCreateSharedMemory( PAGE_READWRITE, dwMaximumSizeHigh, sizeof(MSGSTR), MSGSTR_SHM, &pMsg);
//open semaphore
hSemPost=RtOpenSemaphore(SYNCHRONIZE, FALSE, MSGSTR_SEM_POST);
//hSemPost = RtOpenSemaphore(NULL, FALSE, MSGSTR_SEM_POST);
// hSemPost=RtCreateSemaphore(NULL, lInitialCount, lMaximumCount,MSGSTR_SEM_POST);
hSemQuit=RtOpenSemaphore(SYNCHRONIZE, FALSE, MSGSTR_SEM_QUIT);
//hSemQuit=RtOpenSemaphore( NULL, FALSE, MSGSTR_SEM_QUIT);
//hSemQuit=RtCreateSemaphore(NULL, lInitialCount, lMaximumCount,MSGSTR_SEM_QUIT);
hSemStart=RtOpenSemaphore(SYNCHRONIZE, FALSE, MSGSTR_SEM_START);
//hSemStart=RtOpenSemaphore(NULL, FALSE, MSGSTR_SEM_START);
// hSemStart=RtCreateSemaphore(NULL, lInitialCount, lMaximumCount,MSGSTR_SEM_START);
hSemConfig=RtOpenSemaphore(SYNCHRONIZE, FALSE, MSGSTR_SEM_CONFIG);
// hSemConfig=RtOpenSemaphore(NULL, FALSE, MSGSTR_SEM_CONFIG);
//create thread
hPowerThread=CreateThread(NULL,0,PowerProc,NULL,0,NULL);
hConfigThread=CreateThread(NULL,0,ConfigProc,NULL,0,NULL);
//ShellExecute(handle, "open","E:\\Project1.exe",NULL,NULL, SW_SHOW);
bInit=TRUE;
}
}
void ReadConfigData()
{
RtWritePortUchar(CT_PORT_BASE+11,0xB6);//8254控制字,控制定时器
/*set sample frequency*/
RtWritePortUchar(CT_PORT_BASE+10,pMsg->pcmCfg.T2InitL);//8254定时器2 f=8M/4k=2kHz
RtWritePortUchar(CT_PORT_BASE+10,pMsg->pcmCfg.T2InitH);//先低后高
pMsg->ReadNum=0;
pMsg->WriteNum=0;
nch=pMsg->pcmCfg.startch;
if(nch>=8)//9-16通道
RtWritePortUchar(CT_PORT_BASE+12,0x18+8+nch);//选择通道
else //1-8通道
RtWritePortUchar(CT_PORT_BASE+12,0x18+nch);//选择通道
RtWritePortUchar(CT_PORT_BASE+2,0);// 清IQR
// RtWritePortUchar(CT_PORT_BASE+12,0x18+nch);//通道选择
}
void
_cdecl
main(int argc,char **argv,char **envp)
{
// for interrupt handler code
HANDLE hInterrupt; // interrupt vector handle
int nContext; // context
//BOOL PowerFlag=DISABLE;
/* Initialize Communicate Argument */
ComuInit();
/* Initialize PCM5113 Card */
PcmInit();
// RTX interrupt handler code
// RtAttachInterruptVector associates a handler routine with
// a hardware interrupt.
// Note: level triggered interrupts are not supported in the
// Win32 environment
hInterrupt = RtAttachInterruptVector(
NULL, // thread attributes
0, // stack size - 0 uses default
InterruptHandler, // handler routine
(void *) &nContext,// context
RT_PRIORITY_MAX, // 1,priorityRT_PRIORITY_MAX
Isa, // interface type
0, // bus number
ISA_BUS_VECTOR, // bus interrupt level
ISA_BUS_VECTOR ); // bus interrupt vector
if (! hInterrupt)
{
//
// TO DO: exception code here
RtWprintf(L"RtAttachInterruptVector error = %d\n",GetLastError());
ExitProcess(1);
}
// RTX port I/O code
// Enable direct I/O access of CT ports from user context
if (! RtEnablePortIo(CT_PORT_BASE,
CT_PORT_RANGE) )
{
//
// TO DO: your exception code here
RtWprintf(L"RtEnablePortIo error = %d\n",GetLastError());
}
//调试
// Use RTX port I/O functions to read and write to port.
// See User's Guide chapter 3, "Using RTX Functionality" for
// description of functions.
//
//RtWprintf(L"Rt error = %d\n");
//
// TO DO: your program code here
//
//RtWprintf(L"Rto\n");
RtWaitForSingleObject(hSemQuit, INFINITE);
RtReleaseInterruptVector(hInterrupt);
//ExitThread(lpExitCode);
// RtWprintf(L"off\n");
ExitProcess(0);
}