Example #1
0
/////////////////////////////////////////////////////////////////////
//	Retrieve analog calibration data and rewrite to the flash
/////////////////////////////////////////////////////////////////////
void main()
{
    auto unsigned long fileptr, tempPtr, xmemPtr, index;
    auto unsigned long len;
    auto int i;
    auto char serialNumber[64];

    //------------------------------------------------------------------------
    //		Initialize the Controller
    //------------------------------------------------------------------------
    brdInit();
    serXopen(BAUDRATE);	//set baud rates for the serial ports to be used
    serXwrFlush(myport);		//clear Rx and Tx data buffers
    serXrdFlush(myport);

    //------------------------------------------------------------------------
    //		Allocate and Clear XMEM
    //------------------------------------------------------------------------

    // Allocate XMEM memory for the file that will be read in from the PC
    xmemPtr = xalloc(FILEBUFSIZE);

    // Clear the buffer in XMEM
    for(index =0; index < FILEBUFSIZE; index++)
    {
        root2xmem(xmemPtr + index, "\x00", 1);
    }

    //------------------------------------------------------------------------
    //		Download the Data File from the PC
    //------------------------------------------------------------------------
    sprintf(string, "\r\nWaiting...Please Send Data file\n\r");
    serXwrite(myport, string, strlen(string));

    // Get the calibration data file from the PC and put it into XMEM
    if(!(len = getfile(xmemPtr)))
    {
        caldata_error(string, "\r\n\nEncounter an error while reading calibration file");
        exit(1);
    }
    fileptr = xmemPtr;
    sprintf(string, "\r\n\nDownload Complete\n\n\r");
    serXwrite(myport, string, strlen(string));

    //------------------------------------------------------------------------
    //	 Parse data file and write to calibrations to flash
    //------------------------------------------------------------------------
    sprintf(string, "\r\nParsing data file\n\r");
    serXwrite(myport, string, strlen(string));

    tempPtr = find_tag(fileptr, len);

    sprintf(string, "\r\n\nExiting....Calibration data successfully written\n\n\r");
    serXwrite(myport, string, strlen(string));
    while (serXwrFree(myport) != OUTBUFSIZE);
    while((RdPortI(SXSR)&0x08) || (RdPortI(SXSR)&0x04));
    serXclose();
}
Example #2
0
/////////////////////////////////////////////////////////////////////
// Calibration data error handler
/////////////////////////////////////////////////////////////////////
void caldata_error(char *ptr, char *msg)
{
    memset(ptr, 0x20, 80);
    ptr[0]  = '\r';
    ptr[80] = '\0';
    serXwrite(myport, ptr, strlen(ptr));
    sprintf(ptr, msg);
    serXwrite(myport, ptr, strlen(ptr));

    // Make sure all data gets transmitted before exiting the program
    while (serXwrFree(myport) != OUTBUFSIZE);
    while((RdPortI(SXSR)&0x08) || (RdPortI(SXSR)&0x04));
}
Example #3
0
// Interrupt routine
nodebug root interrupt void Tmr_A_isr()
{
    char TMRA_status;                    // This will hold the interrupt flags
    TMRA_status = RdPortI(TACSR);        // Read interrupt flags and store to TMRA_status
    // Timer A demultiplexing
    if (TMRA_status & TMA7_MASK) {       // if Timer A7 has trigered
        count_TMRA7++;
        if (count_TMRA7 == MAX_COUNT) {  // if Timer A7 has interrupted the CPU 100 times
            display_count[2]++;          // increment corresponding display counter
            count_TMRA7 = 0;             // clear Timer A7 counter
            OSSemPost(TimerSem[2]);      // Post a semaphore for Timer A7 counter
        }
    }
    if (TMRA_status & TMA6_MASK) {       // if Timer A6 has trigered
        count_TMRA6++;                   // increment Timer A6 counter
        if (count_TMRA6 == MAX_COUNT) {  // if Timer A6 has interrupted the CPU 100 times
            display_count[1]++;          // increment coressponding display counter
            count_TMRA6 = 0;             // clear Timer A6 counter
            OSSemPost(TimerSem[1]);      // Post a semaphore for Timer A6 Counter
        }
    }
    if (TMRA_status & TMA5_MASK) {       // if Timer A5 has trigered
        count_TMRA5++;                   // increment Timer A5 counter
        if (count_TMRA5 == MAX_COUNT) {  // if Timer A5 has interrupted the CPU 100 times
            display_count[0]++;          // increment corresponding display counter
            count_TMRA5 = 0;             // clear the Timer A5 counter
            OSSemPost(TimerSem[0]);      // Post a semaphore for Timer A5 Counter
        }
    }
    OSIntExit();
}
Example #4
0
///// scan keypad for key press
void keyCol(void)
{
	delay ( 1000 );
	lcdPrintf ( "%c%c%c%c%c%c",
			((RdPortI(PBDR)&0x20)?'.':'*'),
			((RdPortI(PBDR)&0x10)?'.':'*'),
			((RdPortI(PBDR)&0x08)?'.':'*'),
			((RdPortI(PBDR)&0x04)?'.':'*'),
			((RdPortI(PCDR)&0x02)?'.':'*'),
			((RdPortI(PBDR)&0x01)?'.':'*')
		);
}
Example #5
0
// Timer A interrupt service routine
nodebug root interrupt void Tmr_A_isr()
{
    char TMRA_status;              // This will hold the interrupt flags
    TMRA_status = RdPortI(TACSR);  // Read interrupt flags and store to TMRA_status
    /* There are three possible events leading to this service routine being called
    Write code to determine which of the three     timers has triggered the interrupt.
    Note it is possible for more than one timer to expire at the same time, thus your code must service all triggers.
    By testing the interrupt flags in TMRA_status, you can determine which counters have expired.
    Use three count variables count_TMRAX (X is 5, 6 and 7) to count the number of interrupts.
    For each Timer AX interrupt, you must increment the corresponding count variable.
    i.e., if Timer A5 has expired, then increment count_TMRA5. */
    // During your lab session, you will replace the following code to perform as specified above
    if (TMRA_status & TMA5_MASK)
    {
        count_TMRA5++;
        // The following code increment the display array for every 100 interrupts for a respective timer and resets the count variable
        if (count_TMRA5 == MAX_COUNT)    // If Timer A5 has interrupted the CPU 100 times
        {
            display_count[0]++;          // Increment the display counter
            count_TMRA5 = 0;             // Clear the Timer A5 counter
        }
    }
    if (TMRA_status & TMA6_MASK)
    {
        count_TMRA6++;
        // The following code increment the display array for every 100 interrupts for a respective timer and resets the count variable
        if (count_TMRA6 == MAX_COUNT)    // If Timer A6 has interrupted the CPU 100 times
        {
            display_count[1]++;          // Increment the display counter
            count_TMRA6 = 0;             // Clear the Timer A6 counter
        }
    }
    if (TMRA_status & TMA7_MASK)
    {
        count_TMRA7++;
        // The following code increment the display array for every 100 interrupts for a respective timer and resets the count variable
        if (count_TMRA7 == MAX_COUNT)    // If Timer A6 has interrupted the CPU 100 times
        {
            display_count[2]++;          // Increment the display counter
            count_TMRA7 = 0;             // Clear the Timer A6 counter
        }
    }
}
void main()
{
	//temp variable useful for loops
	int i;
   //temp variables for serial communication
   int c;
   unsigned int bytesRead;

   //variables for wifi communication
   int newMode;
   int interfacePacketRecieved;
   int network;


   #GLOBAL_INIT
	{
		setMode(ROBOT_ENABLE);
      rx.state = WAIT;

      /***********************
        Initialization of Packets
      ***********************/
      // Initialize software version
      aPacket[1] = SOFTWARE_VERSION_ID >> 8;
      aPacket[2] = SOFTWARE_VERSION_ID & 0xFF;

      // Initialize UDP response packets
      gPacket[0] = 'G';
      gPacket[1] = ROBOTMODE;
      gPacket[2] = SOFTWARE_VERSION_ID >> 8;
      gPacket[3] = SOFTWARE_VERSION_ID & 0xFF;
      gPacket[4] = 0;	// user version id
      gPacket[5] = 0;
      gPacket[6] = 0;	// battery voltage
      gPacket[7] = 0;

      // Initialize J packet values to 0
      memset(jPacket, 0, J_PACKET_LENGTH);

      // Initialize X default packet (autonomous mode dummy packet) to 0
      memset(xPacketDefaultValues, 0, X_PACKET_LENGTH);
	}


   /////////////////////////////////////////////////////////////////////////
   // Configure Port D -- Leave PD4-PD7 untouched (used for other purposes)
   /////////////////////////////////////////////////////////////////////////
   WrPortI(PDCR,  &PDCRShadow,  RdPortI(PDCR)  & 0xF0);  // clear bits to pclk/2
   WrPortI(PDFR,  &PDFRShadow,  RdPortI(PDFR)  & 0xF0);  // no special functions
   WrPortI(PDDCR, &PDDCRShadow, RdPortI(PDDCR) & 0xF0);  // clear bits to drive
                                                         //  high and low
   WrPortI(PDDR,  &PDDRShadow,  RdPortI(PDDR)  | 0x0D);  // set outputs high
   WrPortI(PDDDR, &PDDDRShadow, RdPortI(PDDDR) | 0x0D);  // set inputs and
                                                         //  outputs

   //Initialize serial communication
   serialInit();

   //Initialize controls as neutral
   //memset(interface.axis, 127, sizeof(interface.axis));
   //memset(interface.btn, 0, sizeof(interface.btn));

   //Decide which router to connect to
	if (BitRdPortI(PDDR, 1) == 1) {
   	//USER settings
   	BitWrPortI(PDDR, &PDDRShadow, 1, 0);	// turn off user LED
      network = USER_ROUTER;
		printf("USER\n");
	} else {
		//COMPETITION Settings
      BitWrPortI(PDDR, &PDDRShadow, 0, 0);   // turn on user LED
      network = COMP_ROUTER;
      setMode(ROBOT_DISABLE);
      printf("COMPETITION\n");
   }
   // */

   printf("Robot Mode: %d \n", ROBOTMODE);

   // Wait for X2 handshake (to learn team #) before attempting connection
   printf("Waiting for X2...\n");
	while (x2Connection != X2_CONN_ESTABLISHED) {
      if ((c = serCgetc()) != -1) {
   		byteReceived(c);
      }
   }
   printf("X2 connection established\n");
   sendPacket('F', F_PACKET_LENGTH, fPacket);
   ConnectToNetwork(network, teamNo);

   //Main Loop
	while(1) {
		// Receive field, interface & X2 reply packets as they come
   	costate {
			//Check to see if we have new field communication
	      if (udpRecieveFieldPacket()) {

	         newMode = ProcessFieldPacket();
	         if (newMode != -1) {

            	// Set robot mode flags
	            setMode(newMode);

            	// If disable flag set: zero motor values
               if (newMode & ROBOT_DISABLE)
               	disableRobot();

               // Send X2 packet with new mode flags
               sendPacket('F', F_PACKET_LENGTH, fPacket);

					// Send back response packet with our robot mode flags
               //  and code versions
               sendFieldSocket(gPacket, G_PACKET_LENGTH);

	            //printf("Robot Mode: %d \n", ROBOTMODE);
	         }
         }

	      //Check to see if we have new field commuication, and we can use it
	      if (udpRecieveInterfacePacket()) {
	         if (interBuf[0] == 'I') {
	            udpNewData = TRUE;
	         }
         }

      	// Receive X2 serial data in bursts of up to X2_RX_BURST_LENGTH
         bytesRead = 0;
			while ((c = serCgetc()) != -1 &&
         			bytesRead <= X2_RX_BURST_LENGTH) {
				byteReceived((unsigned char)c);
            bytesRead += 1;
         }
      }
      // */

      // Time out if no UDP packets received after 500 ms
      //  TODO: Update the interface to send an enable packet. In the meantime
      //  this feature is only activated in competition mode
      costate {
      	if (network == COMP_ROUTER) {
	         waitfor( udpNewData || DelayMs(500) );
	         if (!udpNewData)
	            disableRobot();
         }
      }

      // Send X2 packets
      costate {
      	// FOR TESTING
         // udpNewData = TRUE;
      	waitfor( udpNewData );

         // Check that disable bit is not set
         if (!(ROBOTMODE & ROBOT_DISABLE)) {

	         // If in autonomous mode, send a dummy 'X' packet to keep the
            // motor refreshing, but do not send actual joystick values
            if (ROBOTMODE & ROBOT_AUTON)
            	sendPacket('X', X_PACKET_LENGTH, xPacketDefaultValues);
            // Otherwise in enable mode, send the received joystick values
            else
	         	sendPacket('X', X_PACKET_LENGTH, interBuf+1);
	         x2OkToSend = FALSE;
	         udpNewData = FALSE;

	         // Wait for reply before sending another packet
	         waitfor( x2OkToSend || DelayMs(500) );
	         if (!x2OkToSend) {   // no reply came within 500ms timeout
	            //printf("disable");
	            disableRobot();
	         }
         }
      }

		costate {
			// If auto bit is set, blink the LED fast
         if (ROBOTMODE & ROBOT_AUTON) {
				BitWrPortI(PDDR, &PDDRShadow, 0, 0);   // turn on user LED
	         waitfor (DelayMs(100));
	         BitWrPortI(PDDR, &PDDRShadow, 1, 0);   // turn off user LED
	         waitfor (DelayMs(100));

         // Otherwise if disable bit is set, blink the LED slowly
         } else if (ROBOTMODE & ROBOT_DISABLE) {
	         BitWrPortI(PDDR, &PDDRShadow, 0, 0);   // turn on user LED
	         waitfor (DelayMs(500));
	         BitWrPortI(PDDR, &PDDRShadow, 1, 0);   // turn off user LED
	         waitfor (DelayMs(500));
         }
      }
   } // while(1)

}	// main
Example #7
0
main()
{
	auto int received;
	auto int i;
	auto int txconfig;

	serCopen(baud_rate);
	serDopen(baud_rate);

	serCparity(PARAM_OPARITY);
	serDparity(PARAM_OPARITY);
	txconfig = PARAM_OPARITY;

	printf("Starting...\n");

	while (1)
	{
		costate
		{
	      //send as fast as we can
	      for (i = 0; i < 128; i++)
	      {
	         waitfor(DelayMs(10));   //necessary if we are not using
	                                 //flow control
	         waitfordone{ cof_serCputc(i); }
	      }
	      // wait for data buffer, internal data and shift registers to become
	      // empty
	      waitfor(serCwrFree() == COUTBUFSIZE);
	      waitfor(!((RdPortI(SCSR)&0x08) || (RdPortI(SCSR)&0x04)));
         waitfor(DelayMs(10));   //now wait for last Rx character to "arrive"
	      yield;

	      //toggle between sending parity bits, and not
	      if (txconfig == PARAM_SPARITY)
	      {
	         txconfig = PARAM_NOPARITY;
	         printf("\nParity option set to no parity.\n");
	         printf("Parity errors are expected on some received characters.\n");
	      }
	      else if(txconfig == PARAM_NOPARITY)
	      {
	         txconfig = PARAM_OPARITY;
	         printf("\nParity option set to odd parity.\n");
	         printf("No parity error should occur on any received character.\n");
	      }
	      else if(txconfig == PARAM_OPARITY)
	      {
	         txconfig = PARAM_EPARITY;
	         printf("\nParity option set to even parity.\n");
	         printf("Parity errors are expected on all received characters.\n");
	      }
	      else if(txconfig == PARAM_EPARITY)
	      {
	         txconfig = PARAM_MPARITY;
	         printf("\nParity option set to mark parity.\n");
	         printf("Parity errors are expected on some received characters.\n");
	      }
	      else if(txconfig == PARAM_MPARITY)
	      {
	         txconfig = PARAM_SPARITY;
	         printf("\nParity option set to space parity.\n");
	         printf("Parity errors are expected on some received characters.\n");
	      }
	      serCparity(txconfig);
		}

		costate
		{
			//receive characters in a leisurely fashion
			waitfordone
			{
				received = cof_serDgetc();
			}
			printf("received 0x%x\n", received);
			if (serDgetError() & SER_PARITY_ERROR)
			{
				printf("PARITY ERROR\n");
			}
	   }
	}
}
Example #8
0
main()
{
	auto char received;
	auto int i;
	auto int txconfig;

   #if _USER
   #warns "This sample permanantly disables the RabbitSys serial console."
   #warns "Remove power and the battery to restore serial console operation."   
	if (_sys_con_disable_serial() != 0) {
   	printf("Error: Cannot disable RabbitSys serial port.");
   }
   #endif
	brdInit();				//initialize board for this demo

	serEopen(baud_rate);
	serFopen(baud_rate);

	serEparity(PARAM_OPARITY);
	serFparity(PARAM_OPARITY);
	txconfig = PARAM_OPARITY;

	printf("Starting...\n");

	while (1)
	{
		costate
		{
			//send as fast as we can
			for (i = 0; i < 128; i++)
			{
				waitfor(DelayMs(10)); 	//necessary if we are not using
											 	//flow control
				waitfordone{ cof_serEputc(i); }
			}
			// wait for data buffer, internal data and shift registers to become empty
  			waitfor(serEwrFree() == EOUTBUFSIZE);
  			waitfor(!((RdPortI(SESR)&0x08) || (RdPortI(SESR)&0x04)));
			yield;

			//toggle between sending parity bits, and not
			if (txconfig)
			{
				txconfig = PARAM_NOPARITY;
				printf("\nParity option set to no parity\n");
			}
			else
			{
				txconfig = PARAM_OPARITY;
				printf("\nParity option set to odd parity\n");
			}
			serEparity(txconfig);
		}

		costate
		{
			//receive characters in a leisurely fashion
			waitfordone
			{
				received = cof_serFgetc();
			}
			printf("received 0x%x\n", received);
			if (serFgetError() & SER_PARITY_ERROR)
			{
				printf("PARITY ERROR\n");
			}
	   }
	}
}
Example #9
0
main()
{
	auto int channel, gaincode;
	char tempbuf[64];
	char sendbuf[128];
	int ch,i;

	brdInit();
	serXopen(BAUDRATE);
	serXrdFlush(myport);
	serXwrFlush(myport);

	if (PRINTDEBUG)
	{
		printf("ADC Block size = 0x%x\n", 4096*GetIDBlockSize());

		printf("ADC single-ended address 0x%x\n", ADC_CALIB_ADDRS);		//single-ended address start
		printf("ADC differential address 0x%x\n", ADC_CALIB_ADDRD);		//differential address start
		printf("ADC milli-Amp address 0x%x\n", ADC_CALIB_ADDRM);			//milli-amp address start

		printf("\nRead constants from user block\n");
	}
	anaInEERd(ALLCHAN, SINGLE, gaincode);			//read all single-ended
	anaInEERd(ALLCHAN, DIFF, gaincode);				//read all differential
	anaInEERd(ALLCHAN, mAMP, gaincode);				//read all milli-amp

	memset(sendbuf, '\x0', sizeof(sendbuf));
	while(serXrdFree(myport) != INBUFSIZE) serXgetc(myport);

	// Send data out the serial port to the PC
	serXputs(myport, "Uploading calibration table . . .\n\r\x0");
	serXputs(myport, "Enter the serial number of your controller = \x0");

	ch = 0;
	i=0;
	while (ch != '\r')
	{
		// make sure you have local echo enabled in Tera Term, so that the
	  	// serial number will written to the calibration file.
		while ((ch = serXgetc(myport)) == -1);
		// Check for a BACKSPACE...allow editing of the serial number
		if (ch == '\b' && i > 0)
		{
			--i;
		}
		else
			tempbuf[i++] = ch;
	}

	tempbuf[i] = '\x0';
	sprintf(sendbuf, "\n\r::\n\rSN");
	strcat(sendbuf, tempbuf);
	strcat(sendbuf, "\n\r\x0");
	serXputs(myport, sendbuf);

	////
	if (PRINTDEBUG) {
		printf("\n\nFormatting single-ended channels to transmit\n");
	}

	sprintf(sendbuf, "ADSE\n\r\x0");
	serXputs(myport, sendbuf);

	for(channel = STARTSE; channel <= ENDSE; channel++)
	{
		memset(sendbuf, '\x0', sizeof(sendbuf));
		sprintf(sendbuf, "%d\n\r\x0", channel);
		serXwrite(myport, sendbuf, sizeof(sendbuf));

		for(gaincode = 0; gaincode < 8; gaincode++)
		{
			memset(sendbuf, '\x0', sizeof(sendbuf));
			sprintf(sendbuf, "%9.6f,%9.6f,", _adcCalibS[channel][gaincode].kconst, _adcCalibS[channel][gaincode].offset);
			if (gaincode == 3 || gaincode == 7)
				strcat(sendbuf, "\n\r\x0");
			serXwrite(myport, sendbuf, sizeof(sendbuf));
		}
	}

	////
	if(PRINTDEBUG) {
		printf("\n\nFormatting differential channels to transmit\n");
	}

	sprintf(sendbuf, "ADDF\n\r\x0");
	serXputs(myport, sendbuf);

	for(channel = STARTDIFF; channel <= ENDDIFF; channel+=2)
	{
		memset(sendbuf, '\x0', sizeof(sendbuf));
		sprintf(sendbuf, "%d\n\r\x0", channel);
		serXwrite(myport, sendbuf, sizeof(sendbuf));

		for(gaincode = 0; gaincode < 8; gaincode++)
		{
			memset(sendbuf, '\x0', sizeof(sendbuf));
			sprintf(sendbuf, "%9.6f,%9.6f,", _adcCalibD[channel][gaincode].kconst, _adcCalibD[channel][gaincode].offset);
			if (gaincode == 3 || gaincode == 7) {
				strcat(sendbuf, "\n\r\x0");
			}
			serXwrite(myport, sendbuf, sizeof(sendbuf));
		}
	}

	////
	if (PRINTDEBUG) {
		printf("\n\nFormatting milli-Amp channels to transmit\n");
	}

	sprintf(sendbuf, "ADMA\n\r\x0");
	serXputs(myport, sendbuf);

	for(channel = STARTMA; channel <= ENDMA; channel++)
	{
		memset(sendbuf, '\x0', sizeof(sendbuf));
		sprintf(sendbuf, "%d\n\r\x0", channel);
		serXwrite(myport, sendbuf, sizeof(sendbuf));

		sprintf(sendbuf, "%9.6f,%9.6f,\n\r\x0", _adcCalibM[channel].kconst, _adcCalibM[channel].offset);
		serXwrite(myport, sendbuf, sizeof(sendbuf));
	}

	sprintf(sendbuf, "END\n\r::\n\r\x0");
	serXputs(myport, sendbuf);

	serXputs(myport, "End of table upload\n\n\r\x0");

	// Make sure all data gets transmitted before exiting the program
	while (serXwrFree(myport) != OUTBUFSIZE);
   while((RdPortI(SXSR)&0x08) || (RdPortI(SXSR)&0x04));
	serXclose();
}
Example #10
0
main()
{
	auto int channel, gaincode, ch;
	char tempbuf[64];
	char sendbuf[128];
	char i;

	brdInit();
	seropen(BAUDRATE);
	serrdFlush();
	serwrFlush();

	if (PRINTDEBUG)
	{
		printf("Block size = 0x%x\n", 4096*GetIDBlockSize());

		printf("ADC single-ended address 0x%x\n", ADC_CALIB_ADDRS);		//single-ended address start
		printf("DAC single-ended address 0x%x\n", DAC_CALIB_ADDRS);		//single-ended address start

		printf("\nRead constants from user block\n");
	}
	anaInEERd(ALLCHAN);			//read all single-ended input
	anaOutEERd(ALLCHAN);			//read all single-ended output

	memset(sendbuf, '\x0', sizeof(sendbuf));
	while(serrdFree() != INBUFSIZE) sergetc();

	// Send data out the serial port to the PC
	serputs("Uploading calibration table . . .\n\r\x0");
	serputs("Enter the serial number of your controller = \x0");

	ch = 0;
	i=0;
	while (ch != '\r')
	{
		// make sure you have local echo enabled in Tera Term, so that the
	  	// serial number will written to the calibration file.
		while ((ch = sergetc()) == -1);

		// Check for a BACKSPACE...allow editing of the serial number
		if (ch == '\b' && i > 0)
		{
			--i;
		}
		else
			tempbuf[i++] = ch;
	}

	tempbuf[i] = '\x0';
	sprintf(sendbuf, "\n\r::\n\rSN");
	strcat(sendbuf, tempbuf);
	strcat(sendbuf, "\n\r\x0");
	serputs(sendbuf);

	////
	////
	if (PRINTDEBUG) printf("\n\nFormatting single-ended channels to transmit\n");
	sprintf(sendbuf, "ADSE\n\r\x0");
	serputs(sendbuf);

	for(channel = STARTAD; channel <= ENDAD; channel++)
	{
		memset(sendbuf, '\x0', sizeof(sendbuf));
		sprintf(sendbuf, "%d\n\r\x0", channel);
		sprintf(tempbuf, "%9.6f,%9.6f,", _adcCalibS[channel].kconst, _adcCalibS[channel].offset);
		strcat(sendbuf, tempbuf);
		strcat(sendbuf, "\n\r\x0");
		serwrite(sendbuf, sizeof(sendbuf));
	}

	////
	////
	if (PRINTDEBUG) printf("\n\nFormatting single-ended channels to transmit\n");
	sprintf(sendbuf, "DASE\n\r\x0");
	serputs(sendbuf);

	for(channel = STARTDA; channel <= ENDDA; channel++)
	{
		memset(sendbuf, '\x0', sizeof(sendbuf));
		sprintf(sendbuf, "%d\n\r\x0", channel);
		sprintf(tempbuf, "%9.6f,%9.6f,", _dacCalibS[channel].kconst, _dacCalibS[channel].offset);
		strcat(sendbuf, tempbuf);
		strcat(sendbuf, "\n\r\x0");
		serwrite(sendbuf, sizeof(sendbuf));
	}

	sprintf(sendbuf, "END\n\r::\n\r\x0");
	serputs(sendbuf);

	serEputs("End of table upload\n\n\r\x0");

	// Make sure all data gets transmitted before exiting the program
	while (serwrFree() != OUTBUFSIZE);
   while((RdPortI(SXSR)&0x08) || (RdPortI(SXSR)&0x04));
	serclose();
}
Example #11
0
void main()
{
	auto int received, receive_count;
	auto int i;
	auto int txconfig;

	// Initialize I/O to use PowerCoreFLEX prototyping board
	brdInit();

	serEopen(baud_rate);
   serFopen(baud_rate);

   // Serial mode must be done after opening the serial ports
   serMode(0);

   // Clear serial data buffers
   serErdFlush();
   serFrdFlush();
   serEwrFlush();
   serFwrFlush();

	printf("Start with the parity option set properly\n");
	serEparity(PARAM_OPARITY);
   serFparity(PARAM_OPARITY);

	txconfig = PARAM_OPARITY;

	while (1)
	{
		costate
		{
      	receive_count = 0;
			// Send data value 0 - 127
			for (i = 0; i < 128; i++)
			{
         	yield; // Yield so data can be read from serial port C
				serEputc(i);
			}
         // Wait for data buffer, internal data and shift registers to become empty
   		waitfor(serEwrFree() == EOUTBUFSIZE);
   		waitfor(!((RdPortI(SESR)&0x08) || (RdPortI(SESR)&0x04)));

         // Wait for entire 128 bytes to be processed
         waitfor(receive_count == 128);

			// Toggle between parity options
			if (txconfig)
			{
				txconfig = PARAM_NOPARITY;
				printf("\n\nInproperly set parity option\n");
			}
			else
			{
				txconfig = PARAM_OPARITY;
				printf("\n\nProperly set parity option\n");
			}
			serEparity(txconfig);
		}
		costate
		{
      	// Receive characters in a leisurely fashion
 			if((received = serFgetc()) != -1)
         {
         	receive_count++;
				printf("received 0x%x\n", received);
				if (serFgetError() & SER_PARITY_ERROR)
				{
					printf("PARITY ERROR\n");
				}
	   	}
      }
	}
}
Example #12
0
void main()
{
   auto int c, num_bytes, done;
   auto char *ptr;
	auto int parallel_counter, loop_counter;
	auto char buffer[256];
	auto char s[256];
   

	brdInit();		//required for BL2100 series boards
		
	c = 0;			//initialize variables
	parallel_counter = 0;
	loop_counter	  = 0;
	done				  = FALSE;

	sprintf(s, "Character counter = %d", 0);	//initialize for proper STDIO effects
   DispStr(2, 2, s);

   // display exit message
   DispStr(2, 5, "Press the ESC key in Hyperterminal to exit the program");
   
	serCopen(BAUD_RATE);	//set baud rates for the serial ports to be used
   serBopen(BAUD_RATE);
   
	serCwrFlush();		//clear Rx and Tx data buffers 
	serCrdFlush();

	serBwrFlush();		
	serBrdFlush();
   
   serMode(0);			//required for BL2100 series bds...must be done after serXopen function(s)
 
   while (!done) {
               
   	loophead();			//required for single-user cofunctions
   	
   	costate				//single-user serial cofunctions 
   	{
   		// Wait for char from hyperterminal
	      wfd c = cof_serBgetc(); // yields until successfully getting a character

			//do clean exit from costatement
	      if(c == ESC)
   	   {
   	   	//flag used to exit out of this WHILE loop and other costatements
				done = TRUE;
				
				//abort this costatement
				abort;		
   	   }

	      // send character to serial port C
   	   wfd cof_serBputc(c);    // yields until c successfully put

   	   // wait for char from serial port C
   	   wfd c = cof_serCgetc(); // yields until successfully getting a character

   	   //send character back to hyperterminal
   	   wfd cof_serCputc(c);    // yields until c successfully put

   	   waitfor(serCwrUsed() == 0);
   	   
   	   //demonstrates that the above cofunctions only yields to other costates
   	   //and not to the code within the same costatement section.
   	   sprintf(s, "Character counter = %d", ++loop_counter);
   	   DispStr(2, 2, s);
      }
      costate
      {
      	// Abort this costatement if the done flag has been set
      	if(done)
   	   {
				abort;	//do clean exit of costatement
   	   }
			//execute code while waiting for characters from hyperterminal
			sprintf(s, "Parallel code execution counter = %d\r", parallel_counter++);
			DispStr(2, 3, s);
      }
   }
   
   // send program exit message
   serBputs("\n\n\rProgram Done...exiting");
   
   // wait for memory data buffer, serial holding register, and shift
   // register all to become empty
   while (serBwrFree() != BOUTBUFSIZE);
   while((RdPortI(SBSR)&0x08) || (RdPortI(SBSR)&0x04));

	// read data and send to hyperterminal
   num_bytes = serCread(buffer, sizeof(buffer), 5);
   buffer[num_bytes] = '\0';
	serCwrite(buffer, strlen(buffer));
	
   // wait for memory data buffer, serial holding register, and shift
   // register all to become empty
   while (serCwrFree() != COUTBUFSIZE);
   while((RdPortI(SCSR)&0x08) || (RdPortI(SCSR)&0x04));
 
   //close the serial ports
   serCclose();
   serBclose();
}
Example #13
0
main()
{
	auto char received;
	auto int i;
	auto int txconfig;

	brdInit();				//initialize board for this demo
						
	serBopen(baud_rate);
	serCopen(baud_rate);
	
	serBparity(PARAM_OPARITY);
	serCparity(PARAM_OPARITY);
	txconfig = PARAM_OPARITY;
	
	printf("Starting...\n");
				
	while (1)
	{
		costate
		{
			//send as fast as we can
			for (i = 0; i < 128; i++)
			{
				waitfor(DelayMs(10)); 	//necessary if we are not using
											 	//flow control
				waitfordone{ cof_serBputc(i); }
			}
			// wait for data buffer, internal data and shift registers to become empty
  			waitfor(serBwrFree() == BOUTBUFSIZE);
  			waitfor(!((RdPortI(SBSR)&0x08) || (RdPortI(SBSR)&0x04)));
			yield;
  			
			//toggle between sending parity bits, and not
			if (txconfig)
			{
				txconfig = PARAM_NOPARITY;
				printf("\nParity option set to no parity\n");
			}
			else
			{
				txconfig = PARAM_OPARITY;
				printf("\nParity option set to odd parity\n");
			}
			serBparity(txconfig);
		}
		
		costate
		{
			//receive characters in a leisurely fashion
			waitfordone
			{
				received = cof_serCgetc();
			}
			printf("received 0x%x\n", received);
			if (serCgetError() & SER_PARITY_ERROR)
			{
				printf("PARITY ERROR\n");
			}
	   }
	}
}
Example #14
0
void main()
{
	char packet[51];
	char init_packet[50];
	int packet_size;
	char errors;
	int packet_count;
	char switch_state;
	int i, temp;
	
	pktDinitBuffers(5, 50);
	//uncomment one of the open statements depending on the packet type		
	//pktDopen(19200, PKT_CHARMODE, ':', packet_test);
	//pktDopen(19200, PKT_9BITMODE, PKT_LOWSTARTBYTE, packet_test);
	pktDopen(19200, PKT_GAPMODE, 3, NULL);

	printf("port D opened\n");

	//uncomment to set parity mode
	//pktDsetParity(PKT_OPARITY);
		
	packet_count = 0;
	strcpy(init_packet, ":13Thisisapacketofdata");

	loopinit();
	while (1) {
	
		costate {
			waitfordone {
				packet_size = cof_pktDreceive(packet, 50);
			}
			if(packet_size < 0)
			{
				printf("Error from cof_pktDreceive: %d\n", packet_size);
			}
			else if(packet_size > 50)
			{
				printf("Packet too big:%d\n", packet_size);
			}
			else
			{
				packet[packet_size] = 0; //add null terminator
				printf("Got packet '%s' - size:%d\n", packet, packet_size);
			}
			errors = pktDgetErrors();
			if (errors & PKT_PARITYERROR) {
				printf("Parity error\n");
			}
			if(errors)
				printf("error: 0x%x\n", errors);			
			
			//echo the packet right back
			waitfordone { 
				cof_pktDsend(packet, packet_size, 3);
			}
		}
		costate {
			//send a packet if a button is pressed
			if ( (RdPortI(PBDR) & 0x3c) != 0x3c) {
				waitfordone {
					cof_pktDsend(init_packet, strlen(init_packet), 3);
				}
				printf("Init packet sent\n");
			}
			waitfor(DelayMs(1000));

		}			
	}