You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
7.0 KiB
235 lines
7.0 KiB
/*----------------------------------------------------------------------------*/
|
|
/* Company : ADLINK */
|
|
/* Date : 2009/06/09 */
|
|
/* */
|
|
/* This sample performs DI pattern match functionality. */
|
|
/* In PCIe-7350, there are 32 programmable DIO channels. Each 8 channels are */
|
|
/* devided into one port that is the DIO configuration unit. */
|
|
/* You can set a pattern for the set DI channels. Internal interrupt will be */
|
|
/* asserted while the input digital signal is matched to the configured */
|
|
/* pattern. */
|
|
/* AFI port can also be set as the COS event out mode, and the set AFI port */
|
|
/* will generate a pulse while COS occurs. */
|
|
/*----------------------------------------------------------------------------*/
|
|
#include <windows.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <process.h>
|
|
#include <conio.h>
|
|
#include "dask.h"
|
|
|
|
I16 card;
|
|
HANDLE PM_Event = 0;
|
|
BOOLEAN fStopThr = 0;
|
|
BOOLEAN fThrEnded = 0;
|
|
|
|
#define MATCH_PATTERN 0x2f01
|
|
|
|
void wait_pattern_matched(void *arg)
|
|
{
|
|
I16 err;
|
|
U32 PMLData;
|
|
U32 stat;
|
|
|
|
do{
|
|
stat = WaitForSingleObject(PM_Event, INFINITE);
|
|
if(stat!=0){
|
|
printf("WaitForSingleObject Error: %d\n", GetLastError());
|
|
continue;
|
|
}
|
|
if(fStopThr)
|
|
break;
|
|
else{
|
|
err = DIO_GetPMLatchData32(card, 0, &PMLData);
|
|
if(err<0){
|
|
printf("DIO_GetPMLatchData32 Error: %d\n", err);
|
|
}
|
|
printf("Pattern Matched; Latched Data: 0x%x\n", PMLData);
|
|
/*
|
|
* PCI-7350 Pattern Match is a one pulse event, so reconfigure
|
|
* and restart is necessary if you want to match a new pattern.
|
|
*/
|
|
/*Set DI to zero*/
|
|
DO_WritePort(card, P7350_DIO_A, 0);
|
|
DO_WritePort(card, P7350_DIO_C, 0);
|
|
Sleep(1);
|
|
/*restart Pattern Match*/
|
|
err = DIO_PMControl(card, 0, PATMATCH_RESTART, &PM_Event, 0);
|
|
if(err<0){
|
|
printf("DIO_PMControl Error: %d\n", err);
|
|
}
|
|
}
|
|
}while(1);
|
|
|
|
fThrEnded = 1;
|
|
_endthread();
|
|
}
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
I16 err;
|
|
U16 card_num;
|
|
U16 vi;
|
|
U32 DIRead1, DIRead2;
|
|
BOOLEAN fStop;
|
|
U16 pattern = MATCH_PATTERN;
|
|
U16 PM_ChnType;
|
|
U32 PMEventOutLen = 100; //100 system clock - 100 * 8 ns
|
|
|
|
printf("This sample performs pattern match functionality.\n");
|
|
printf("DIO Port A/C are configured as a DO port while Port B/D\n");
|
|
printf("are configured as a DI Port. Signal will be asserted\n");
|
|
printf("and a %d ns pulse will be generated to AFI0 while\n", 8*PMEventOutLen);
|
|
printf("the set pattern is matched.\n");
|
|
printf("This sample will match the pattern: 0x%x from Port B/D.\n", MATCH_PATTERN);
|
|
|
|
printf("Card Number? ");
|
|
scanf(" %hd", &card_num);
|
|
|
|
/*Open and Initialize Device*/
|
|
card = Register_Card(PCI_7350, card_num);
|
|
if(card<0){
|
|
printf("Register_Card Error: %d\n", card);
|
|
exit(1);
|
|
}
|
|
|
|
/*Configure 7350 DIO Port*/
|
|
err = DIO_PortConfig(card, P7350_DIO_A, OUTPUT_PORT);
|
|
if(err<0){
|
|
printf("DIO_PortConfig Port_A Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
err = DIO_PortConfig(card, P7350_DIO_B, INPUT_PORT);
|
|
if(err<0){
|
|
printf("DIO_PortConfig Port_B Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
err = DIO_PortConfig(card, P7350_DIO_C, OUTPUT_PORT);
|
|
if(err<0){
|
|
printf("DIO_PortConfig Port_A Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
err = DIO_PortConfig(card, P7350_DIO_D, INPUT_PORT);
|
|
if(err<0){
|
|
printf("DIO_PortConfig Port_B Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
|
|
DO_WritePort(card, P7350_DIO_A, 0);
|
|
DO_WritePort(card, P7350_DIO_C, 0);
|
|
Sleep(1);
|
|
|
|
/*
|
|
* Configure Pattern Match
|
|
*/
|
|
for(vi=8; vi<16; vi++){
|
|
/*Port B: Channel 8~15*/
|
|
PM_ChnType = ((pattern>>(vi-8))&0x1)? PATMATCH_Level_H:PATMATCH_Level_L;
|
|
err = DIO_PMConfig(card, vi, PATMATCH_CHNEnable, PM_ChnType);
|
|
if(err<0){
|
|
printf("DIO_PMConfig Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
}
|
|
for(vi=24; vi<32; vi++){
|
|
/*Port D: Channel 24~31*/
|
|
PM_ChnType = ((pattern>>(vi-16))&0x1)? PATMATCH_Level_H:PATMATCH_Level_L;
|
|
err = DIO_PMConfig(card, vi, PATMATCH_CHNEnable, PM_ChnType);
|
|
if(err<0){
|
|
printf("DIO_PMConfig Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Start Pattern Match
|
|
*/
|
|
err = DIO_PMControl(card, 0, PATMATCH_START, &PM_Event, 0);
|
|
if(err<0){
|
|
printf("DIO_PMControl Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
|
|
/*
|
|
* Set PM event out to AFI port
|
|
*/
|
|
err = DIO_7350_AFIConfig(card, P7350_AFI_0, 1, P7350_AFI_PMTrigOut, PMEventOutLen);
|
|
if(err<0){
|
|
printf("DIO_7350_AFIConfig Port_A Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
|
|
_beginthread(wait_pattern_matched, 0, NULL);
|
|
|
|
do{
|
|
/*
|
|
* DO output to Port A/C
|
|
*/
|
|
printf("\n\nOutput Data? ");
|
|
scanf(" %x", &vi);
|
|
DO_WritePort(card, P7350_DIO_A, vi&0xff);
|
|
DI_ReadPort(card, P7350_DIO_B, &DIRead1);
|
|
DO_WritePort(card, P7350_DIO_C, (vi>>8)&0xff);
|
|
DI_ReadPort(card, P7350_DIO_D, &DIRead2);
|
|
printf("Write to Port A: 0x%x, Port C: 0x%x; Read from Port B: 0x%x, Port D: 0x%x;\n", vi&0xff, (vi>>8)&0xff, DIRead1, DIRead2);
|
|
printf("Quit? ");
|
|
fStop = getch();
|
|
}while((fStop!='q')&&(fStop!='Q'));
|
|
|
|
fStopThr = 1;
|
|
if(!fThrEnded){
|
|
SetEvent(PM_Event);
|
|
ResetEvent(PM_Event);
|
|
}
|
|
while(!fThrEnded){
|
|
Sleep(1);
|
|
}
|
|
|
|
/*
|
|
* Stop Pattern Match
|
|
*/
|
|
err = DIO_PMControl(card, 0, PATMATCH_STOP, NULL, 0);
|
|
if(err<0){
|
|
printf("DIO_PMControl Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
|
|
for(vi=8; vi<16; vi++){
|
|
/*Port B: Channel 8~15*/
|
|
err = DIO_PMConfig(card, vi, PATMATCH_CHNDisable, 0);
|
|
if(err<0){
|
|
printf("DIO_PMConfig Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
}
|
|
for(vi=24; vi<32; vi++){
|
|
/*Port D: Channel 24~31*/
|
|
err = DIO_PMConfig(card, vi, PATMATCH_CHNDisable, 0);
|
|
if(err<0){
|
|
printf("DIO_PMConfig Error: %d\n", err);
|
|
Release_Card(card);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
err = DIO_7350_AFIConfig(card, P7350_AFI_0, 0, 0, 0);
|
|
if(err<0){
|
|
printf("DIO_7350_AFIConfig Error: %d\n", err);
|
|
}
|
|
|
|
printf("\n\nPress any key to exit...\n");
|
|
getch();
|
|
Release_Card(card);
|
|
return 0;
|
|
}
|
|
|