Exemplo n.º 1
0
void copyMidgToUart2() {
    unsigned char buf[MIDG_CHUNKSIZE];
    
    midgRead(buf);
    
    // add NUL terminator after bytes
    buf[buf[0]+1] = 0;
    
    // should send the bytes as they came in
    //printToUart2("%s", buf[1]);
    
    // send the number of bytes read from the buffer
    printToUart2("%u\n", buf[0]);
}
Exemplo n.º 2
0
void magnetoInit (void){
	//magDebugUartConfig();
	//printToUart2("Starting %s\n\r","sequence");
	
	
	// Configure the I2C bus
	I2C1CONbits.A10M = 0;		// 7 bit address
	I2C1BRG =	363;			// I2CBRG = 363. 100Khz for a 40 Mhz clock
	
	
	
	// Configure the Interrupts
	IFS1bits.MI2C1IF = 0;		// Clear the master interrupt
	IFS1bits.SI2C1IF = 0;		// Clear the slave interrupt

	IEC1bits.MI2C1IE = 1;		// Enable the interrupts
	IPC4bits.MI2C1IP = 7;		// Highest Prority
	
	// turn on the I2C Module
	I2C1CONbits.I2CEN = 1;
	
	// Initialize the state machine
	i2c1State = CONFIG_IDLE;
	// Select the register to configure
	reg2Config = REGISTER_A;
	
	//printToUart2("Starting %s\n\r","I2C");
	
	// Wait 5 mS
	dummyDelay();
	
	// Change the mode to 50 Hz
	// ========================
	// Start The Bus
	i2c1Start();
	// Wait for the bus stop
	// this signal that the whole config went trhough
	while(i2c1State != CONFIG_IDLE){
		printToUart2("Out of Int: %d\n\r",i2c1State);
		//byteRead++;
	}
	
	//printToUart2("Changed To %s\n\r","50 HZ");

	// Wait 5 mS
	dummyDelay();
	
	
	// Change the gain
	// ===============
	// Change the register to config
	reg2Config = REGISTER_B;
	// Start The Bus
	i2c1Start();
	// Wait for the bus stop
	// this signal that the whole config went trhough
	while(i2c1State != CONFIG_IDLE){
		printToUart2("Out of 2nd I: %d\n\r",i2c1State);
	}

	printToUart2("Changed To %s\n\r","0.7 Gain");
	
	// Wait 5 mS
	dummyDelay();
	
	
	
	// Change the mode to continous
	// ============================
	// Change the register to config
	reg2Config = MODE_REGISTER;
	// Start The Bus
	i2c1Start();
	// Wait for the bus stop
	// this signal that the whole config went trhough
	while(i2c1State != READ_IDLE){
		printToUart2("Out of 3rd I: %d\n\r",i2c1State);
		//byteRead++;
	}
	
	//printToUart2("Changed To %s\n\r","Contrinous");

	// Wait 5 mS
	dummyDelay();
	
	// Initialize the variables
	byteRead = 1;
	wordRead = 0;
	byteCount = 0;
}
Exemplo n.º 3
0
void readIpc (unsigned char* bufferedData) {
    // fix the data length so if the interrupt adds data
    // during execution of this block, it will be read
    // until the next readIpc
    unsigned int tmpLen = getLength(protBuffer);


    unsigned int i=0;
    unsigned int availBytes = 0, sendMore = 0;
    unsigned char failureTrue = 0;

    //static unsigned long long timeStamp = 0;


    // Set the output size accordingly
    bufferedData[0] = (tmpLen > MAXLOGLEN)? MAXLOGLEN: tmpLen;

    // TODO: Remove debugging info from readIPC
    //if ((timeStamp % 1000)== 0){
    //	printToUart2("T: %6.0f\n\r\0",(float) timeStamp*0.01);
    //}
    //timeStamp++;

    // write the data
    for(i = 1; i <= bufferedData[0]; i += 1 )
    {
        bufferedData[i] = readFront(protBuffer);
    }


    if (getOverflow(protBuffer)>0) {
        // disable the SPI module
        SPI1STATbits.SPIEN  = 0;

        // Disable the interrupts
        IEC0bits.SPI1IE		= 0;
        IFS0bits.SPI1IF 	= 0;

        printToUart2("\n=== %s =====\n\r\n\r\n\r", "BEGIN DUMP ");
        //printToUart2("Ts: %f\n\r\0",(float) timeStamp*0.01);
        printToUart2("Ovrflw: %d\n\r", getOverflow(protBuffer));
        printToUart2("Head: %d\n\r", readHead(protBuffer));
        printToUart2("Tail: %d\n\r", readTail(protBuffer));
        printToUart2("Len: %d\n\r", getLength(protBuffer));
        printToUart2("Siz: %d\n\r", protBuffer->size);


        for(i = 0; i <BSIZE; i ++ )
        {
            printToUart2("%d ", protBuffer->buffer[i]);
        }

        printToUart2("\n=== %s =====\n\r\n\r\n\r", "END ");

        // Empty the buffer
        makeEmpty(protBuffer);


        // Enable the interrupts
        IFS0bits.SPI1IF 	= 0;
        IEC0bits.SPI1IE		= 1;

        // Enable the SPI module
        SPI1STATbits.SPIEN  = 1;

    }

}