示例#1
0
文件: Clock3.c 项目: psi46/HDItest
int main (int argc, char *argv[])
{
    float version = 0.0;
    long errorcode;

    long idnum = -1;  //Using first found U12
    long demo = 0;  //Normal operations
    long trisD = 0;  //Directions for D0-D15
    long trisIO = 0;  //Directions for IO0-IO3
    long stateD = 0;  //Output states for D0-D15
    long stateIO = 0;  //Output states for IO0-IO3
    long updateDigital = 0;  //Indicates is tris states will be written
    long outputD = 0;  //Returns of the output registers for D0-D15
    long outputIO = 0;  //Output states of IO0-IO3.  Cannot be read.


    version = GetDriverVersion();
    printf("Driver version: %.3f\n", version);

    version = GetFirmwareVersion(&idnum);
    printf("U12 Firmware version: %.3f\n\n", version);

    /* Setting and reading directions and states */
    trisD = (long)0x4800;  //Setting D0-7 to outputs, D8-15 to inputs (b0000000011111111)
    trisIO = (long)0x0;  //Setting IO0-1 to outputs, IO2-3 to inputs (b0011)
    stateD = (long)0x4800;  //Setting D0-3 to low. D4-7 to high (b0000000011110000)
    stateIO = (long)0x0;  //Setting IO0 to low. IO1 to high (b0010)
    outputIO = trisIO & stateIO;
    updateDigital = 1;  //Updating D and IO lines
    errorcode = DigitalIO(&idnum, demo, &trisD, trisIO, &stateD, &stateIO,
                          updateDigital, &outputD);
    handleError(errorcode, "DigitalIO (update)");

    printf("DigitalIO, updating lines\n");
    printf("D directions (read) = 0x%.4lx, states (read) = 0x%.4lx, output registers (read) = 0x%.4lx\n", trisD, stateD, outputD);
    printf("IO directions (set) = 0x%lx, states (read) = 0x%lx, output (set) = 0x%lx\n\n", trisIO, stateIO, outputIO);

    /* Only reading current directions (D lines only) and states */
    trisD = 0;
    trisIO = 0;
    stateD = 0;
    stateIO = 0;
    updateDigital = 0;  //Only read performed
    errorcode = DigitalIO(&idnum, demo, &trisD, trisIO, &stateD, &stateIO,
                          updateDigital, &outputD);
    handleError(errorcode, "DigitalIO (read)");

    printf("DigitalIO read only:\n");
    printf("D directions = 0x%.4lx, states = 0x%.4lx, output registers = 0x%.4lx\n", trisD, stateD, outputD);
    printf("IO states = 0x%lx\n", stateIO);

    return 0;
}
示例#2
0
int SetPins(long tris_d_arg, long tris_io_arg, long state_d_arg, long state_io_arg) {
    long errorcode;
    
    long id_num         = -1;
    long demo           = 0;
    long tris_d         = 0;
    long tris_io        = 0;
    long state_d        = 0;
    long state_io       = 0;
    long update_digital = 0;
    long output_d       = 0;
    long output_io      = 0;

    tris_d   = (long)tris_d_arg;
    tris_io  = (long)tris_io_arg;
    state_d  = (long)state_d_arg;
    state_io = (long)state_io_arg;

    output_io = tris_io & state_io;

    update_digital = 1;

    errorcode = DigitalIO(&id_num, demo, &tris_d, tris_io, &state_d, &state_io, update_digital, &output_d);

    update_digital = 0;

    return errorcode;
}
示例#3
0
static void *LJ_DOut_setup_thread(void *w)
{
    	t_LJ_DOut *x = (t_LJ_DOut*) w;

    	// Setup the variables we will need.
    	int r = 0; // For checking return values


	long idnum = -1;
	long stateD;
	long stateIO;
	long gains[] = {0, 0, 0, 0};
	long overvoltage;
	long count;
	long outputD;

	long trisD;
	long trisIO;
	long dataD;
	long dataIO;

	int i;

    	while(1) {
    		sem_wait(&x->go); // start working

		sem_wait (&LJ_IO);
		trisD  = LJ_trisD_fantom;
		trisIO = LJ_trisIO_fantom;
		dataD  = LJ_dataD_fantom;
		dataIO = LJ_dataIO_fantom;
		sem_post (&LJ_IO);

		for (i = 0; i < x->nb_ports; i++) {
			dataD &= ~(1 << (x->ports[i]));
			dataD |= ((int) x->data[i]) << (x->ports[i]);
		}

		sem_wait(&LJ_IO);
		LJ_dataD_fantom = dataD;
		sem_post(&LJ_IO);

		sem_wait(&LJ_busy);
		r = DigitalIO (&idnum, 0, &trisD, trisIO, &dataD, &dataIO, 1, &outputD);
		sem_post(&LJ_busy);

    		sem_post(&x->busy);     // on libere le thread
    	}

}
示例#4
0
static void *LJ_IOIn_setup_thread(void *w)
{
    	t_LJ_IOIn *x = (t_LJ_IOIn*) w;

    	// Setup the variables we will need.
    	int r = 0; // For checking return values


	long idnum = -1;
	long stateD;
	long stateIO;
	long gains[] = {0, 0, 0, 0};
	long overvoltage;
	long count;
	long outputD;

	long trisD;
	long trisIO;
	long dataD;
	long dataIO;

	int i;

    	while(1) {
    		sem_wait(&x->go); // start working

		sem_wait (&LJ_IO);
		trisD  = LJ_trisD_fantom;
		trisIO = LJ_trisIO_fantom;
		dataD  = LJ_dataD_fantom;
		dataIO = LJ_dataIO_fantom;
		sem_post (&LJ_IO);

		sem_wait(&LJ_busy);
		r = DigitalIO (&idnum, 0, &trisD, trisIO, &dataD, &dataIO, 1, &outputD);
		sem_post(&LJ_busy);

		x->lasterror = r;

		for (i=0; i<x->nb_ports; i++) {
			x->io_v[i] = (dataIO >> x->ports[i]) & 1;
		}

		sem_post(&x->acquired);
    	}

}