?? siclmem.c
字號:
/*
siclmem.c
This example program demonstrates the use of
simple and block memory I/O methods in SICL.
*/
#include <sicl.h>
#include <stdlib.h>
#include <stdio.h>
#define VXI_INST "vxi,24"
void main () {
INST id;
unsigned short *memPtr16;
unsigned short id_reg;
unsigned short devtype_reg;
unsigned short memArray[2];
int err;
/* Open a session to our instrument */
id = iopen(VXI_INST);
/*
==================================================================
======================== Simple memory I/O =======================
= iwpeek()
= direct memory dereference
Note that on many platforms, the ipeek/ipoke operations are
actually macros which expand to direct memory dereferencing.
The notable exception is on Microsoft Windows platforms where
ipeek/ipoke are implemented as functions. This is necessary
because under certain conditions, the compiler will attempt to
optimize a direct dereference and cause a VXI memory access of
the wrong size. For example when masking the results of a 16
bit read in a expression:
data = iwpeek(addr) & 0xff;
the compiler will simplify this to an 8 bit read of the contents
of the addr pointer. This would cause an error when attempting
to read memory on a VXI card that did not support 8 bit access.
===================================================================
*/
/* Map into memory space */
memPtr16 = (unsigned short *)imap(id, I_MAP_VXIDEV, 0, 1, 0);
/* ================== using peek ================================
/* Read instrument id register contents */
id_reg = iwpeek(memPtr16);
/*
Read device type register contents
*/
id_reg = iwpeek(memPtr16+1);
/* Print results */
printf(" iwpeek: ID Register = 0x%4X\n", id_reg);
printf(" iwpeek: Device Type Register = 0x%4X\n", devtype_reg);
/* Use direct memory dereferencing */
id_reg = *memPtr16;
devtype_reg = *(memPtr16+1);
/* Print results */
printf("dereference: ID Register = 0x%4X\n", id_reg);
printf("dereference: Device Type Register = 0x%4X\n", devtype_reg);
/*
==================================================================
======================== block memory I/O ========================
= iwblockcopy
= iwpushfifo
= iwpopfifo
These commands offer the best performance for reading and writing
large data blocks on the VXI backplane. Note that for this
example we are only moving 2 words at a time. Normally these
functions would be used to move much larger blocks of data.
==================================================================
==================================================================
*/
/*
================== Demonstrate block read ========================
Read the instrument id register and device type register into
an array.
*/
err = iwblockcopy(id, memPtr16, memArray, 2, 0);
/* Print results */
printf(" iwblockcopy: ID Register = 0x%4X\n", memArray[0]);
printf(" iwblockcopy: Device Type Register = 0x%4X\n", memArray[1]);
/*
==================== Demonstrate popfifo =========================
*/
/* Do a popfifo of the Id Register */
err = iwpopfifo(id, memPtr16, memArray, 2, 0);
/* Print results */
printf(" iwpopfifo: 1 ID Register = 0x%4X\n", memArray[0]);
printf(" iwpopfifo: 2 ID Register = 0x%4X\n", memArray[1]);
/*
===================== Cleanup and exit ===========================
*/
/* Unmap memory space */
iunmap(id, (char *)memPtr16, I_MAP_VXIDEV, 0, 1);
/* Close instrument session */
iclose(id);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -