Пример #1
0
/**
 * Configures digital outputs
 */
void setupDigOut() {
	// Set dig out mask
	digOutConfig(0x01F0);

	// Turn off everything
	digOut(LED_0_ID, OFF);
	digOut(LED_1_ID, OFF);
	digOut(LED_2_ID, OFF);
	digOut(LED_3_ID, OFF);
	digOut(ID_BUZZER, OFF);
}
Пример #2
0
/*********************************************************************************
 This function reads/writes the IO and fills the information in the my_inouts
 array, for example:
 	- Analog Inputs
 		read the channel then fill the my_inouts->ain array with the new data
 	- Digital Inputs:
 		read the channel then fill the my_inouts->din array with the new data
 	- Digital Outputs:
 		read the my_inouts->dout array then set the correct digital channel LOW or
 		HIGH depending what is in the array.
********************************************************************************/
void My_IO_Ctrl(My_InOuts_Type *my_inouts)
{
	static int channel;

	// ANALOG INPUTS: this is where we read the analog inputs............
	for(channel=0;channel<ANALOG_INPUTS;channel++)
	{
		my_inouts->ain[channel] = anaInVolts(channel,GAIN_X2);
		if (my_inouts->ain[channel] > 10 ) my_inouts->ain[channel] = 10.000;
		if (my_inouts->ain[channel] < 0 ) my_inouts->ain[channel] = 0.000;
	//	if(my_inouts->ain[channel] < 10)		// DEBUGGING
	//		my_inouts->ain[channel]++;			// DEBUGGING
	//	else											// DEBUGGING
	//		my_inouts->ain[channel] = 0;		// DEBUGGING
	}

	// DIGITAL INPUTS: this is where we read the digital inputs..........
	for(channel=0;channel<DIGITAL_INPUTS;channel++)
	{
		my_inouts->din[channel] = LOW_HIGH[digIn(channel)];

		//if(!strcmp(my_inouts->din[channel],LOW_HIGH[1]))// DEBUGGING
		//	my_inouts->din[channel] = LOW_HIGH[0];			// DEBUGGING
		//else															// DEBUGGING
		//	my_inouts->din[channel] = LOW_HIGH[1];			// DEBUGGING
	}

	// DIGITAL OUTPUTS: this is where we set the digital outputs.........
	for(channel=0;channel<DIGITAL_OUTPUTS;channel++)
	{
		if(!strcmp(my_inouts->dout[channel],LOW_HIGH[0]))
		{

			//my_inouts->dout[channel] = LOW_HIGH[0];		 // DEBUGGING
			digOut(channel,0);
			// at this point the data in the my_inouts->dout array is high so we
			// need to set the digital output to high, for example:
			//	see_digital_output(channel,1);
		}
		else
		{
			//my_inouts->dout[channel] = LOW_HIGH[1];		 // DEBUGGING
			digOut(channel,1);
			// at this point the data in the my_inouts->dout array is low so we
			// need to set the digital output to low, for example:
			//	see_digital_output(channel,0);
		}
	}
}
Пример #3
0
void simulate_encoder(int encoder_state)
{
	if (encoder_state == 0)
   {
     digOut(LED1,0); // encoder pin A
     digOut(LED2,0); // encoder pin B
   }
   else if (1 == encoder_state)
   {
      digOut(LED1,1); // encoder pin A
      digOut(LED2,0); // encoder pin B
   }
   else if (2 == encoder_state)
   {
      digOut(LED1,1); // encoder pin A
      digOut(LED2,1); // encoder pin B
   }
   else
   {
      digOut(LED1,0); // encoder pin A
      digOut(LED2,1); // encoder pin B
 	}
}
Пример #4
0
main()
{
	auto int i, delay, loop;
	
	brdInit();

	// Main loop to control the speaker
	for(loop = 0; loop < 2; loop++)
	{
		// Generate 3 long beeps
		for(i=0; i < 3; i++)
		{
			for(delay = 0; delay < 8000; delay++);
			digOut(0, 0);
			for(delay = 0; delay < 8000; delay++);
			digOut(0, 1);
		
		}

		// Make the speaker go up in pitch
		for(i=0; i < 800; i++)
		{
			for(delay = 800; delay > i; delay--);
			digOut(0, 0);
			for(delay = 800; delay > i; delay--);
			digOut(0, 1);
		}

		// Make the speaker go down in pitch
		for(i=0; i < 1000; i++)
		{
			for(delay = 0; delay < i; delay++);
			digOut(0, 0);
			for(delay = 0; delay < i; delay++);
			digOut(0, 1);
		}
	}
}
Пример #5
0
main()
{
	char	buffer[100];
	longword seq,ping_who,tmp_seq,time_out;
	float mavg_txrate, mavg_rxrate;
	float avg_txrate, avg_rxrate;
	float txrate, rxrate;
	int gather;

	brdInit();				//initialize board for this demo

   // Configure IO channels as digital outputs (sinking type outputs)
   setDigOut (LED1, 1);				// Configure LED1 as sinking type output
   setDigOut (LED2, 1);				// Configure LED2 as sinking type output

   // Set the initial state of the LED's
   digOut(LED1, LEDOFF);
   digOut(LED2, LEDOFF);

	seq=0;

	mavg_txrate = mavg_rxrate = 0.0;
	avg_txrate = avg_rxrate = 0.0;

	// Start network and wait until associated
	sock_init_or_exit(1);


	/*
	 *		Get the binary ip address for the target of our
	 *		pinging.
	 */

#ifdef PING_WHO
	/* Ping a specific IP addr: */
	ping_who=resolve(PING_WHO);
	if(ping_who==0) {
		printf("ERROR: unable to resolve %s\n",PING_WHO);
		exit(2);
	}
#else
	/* Examine our configuration, and ping the default router: */
	tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END );
	if( tmp_seq != 0 ) {
		printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq );
		exit(2);
	}
	if(ping_who==0) {
		printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n");
		exit(2);
	}
#endif

#ifdef VERBOSE
	printf("\n");
	printf("Note: RSSI = Receive Signal Strength Indicator\n");
	printf("The last display line shows a filtered rate estimate.\n");
	printf("Every %u samples (at %u ms intervals) these rates will be\n",
		GATHER_INTERVAL, PING_DELAY);
	printf("  set to the average over the last %u ms, and the next\n",
		GATHER_INTERVAL * PING_DELAY);
	printf("  line is started.\n");
	#ifdef GRAPHICAL
	printf("Bar graphs are * == 1Mbit/sec and # == 4Mbit/sec\n");
	printf("\n\n");
   printf("\tRx rate (Kbit)\t\tTx rate (Kbit)\t\tRSSI (dB)\n");
   printf("Seq\tLast\tFilt.\t\tLast\tFilt.\t\tFilt.\n");
   printf("------- ------- --------------- ------- --------------- -------\n");
   #else
	printf("\n\n");
   printf("\tRx rate (Kbit)\tTx rate (Kbit)\tRSSI (dB)\n");
   printf("Seq\tLast\tFilt.\tLast\tFilt.\tFilt.\n");
   printf("------- ------- ------- ------- ------- -------\n");
   #endif
#endif

	for(;;) {
		/*
		 *		It is important to call tcp_tick here because
		 *		ping packets will not get processed otherwise.
		 *
		 */

		tcp_tick(NULL);

		/*
		 *		Send one ping every PING_DELAY ms.
		 */

		costate {
			waitfor(DelayMs(PING_DELAY));
			_ping(ping_who,seq++);
			pingoutled(LEDON);					// flash transmit LED
			waitfor(DelayMs(50));
			pingoutled(LEDOFF);
		}

		/*
		 *		Has a ping come in?  time_out!=0xfffffff->yes.
		 */

		costate {
			time_out=_chk_ping(ping_who,&tmp_seq);
			if(time_out!=0xffffffff) {

				// Here is where we gather the statistics...
				// Note that if you get a compile error here, it is because you are not running
				// this sample on a Wifi-equipped board.
				ifconfig (IF_WIFI0, IFG_WIFI_STATUS, &wstatus, IFS_END);

				txrate = wstatus.tx_rate * 100.0;	// Convert to Kbit/sec
				rxrate = wstatus.rx_rate * 100.0;

				mavg_txrate = mavg_txrate * ((MOVING_AVERAGE - 1.0)/MOVING_AVERAGE) +
				              txrate * (1.0/MOVING_AVERAGE);
				mavg_rxrate = mavg_rxrate * ((MOVING_AVERAGE - 1.0)/MOVING_AVERAGE) +
				              rxrate * (1.0/MOVING_AVERAGE);

				avg_txrate += txrate;
				avg_rxrate += rxrate;

				gather = tmp_seq % GATHER_INTERVAL == 0;
#ifdef VERBOSE

		 #ifdef GRAPHICAL
				printf("%7lu %7u %15.15s %7u %15.15s %7d       %c",
					tmp_seq,
					(word)rxrate,
					graph(rxgraph, gather ? (word)(avg_rxrate / GATHER_INTERVAL) : (word)mavg_rxrate),
					(word)txrate,
					graph(txgraph, gather ? (word)(avg_txrate / GATHER_INTERVAL) : (word)mavg_txrate),
					wstatus.rx_signal >> _WIFI_RSSI_SCALE_SHIFT,
					gather ? '\n' : '\r'
					);
		 #else
				printf("%7lu %7u %7u %7u %7u %7d       %c",
					tmp_seq,
					(word)rxrate,
					gather ? (word)(avg_rxrate / GATHER_INTERVAL) : (word)mavg_rxrate,
					(word)txrate,
					gather ? (word)(avg_txrate / GATHER_INTERVAL) : (word)mavg_txrate,
					wstatus.rx_signal >> _WIFI_RSSI_SCALE_SHIFT,
					gather ? '\n' : '\r'
					);
		#endif
#endif

				if (gather)
					avg_txrate = avg_rxrate = 0.0;

				pinginled(LEDON);					// flash receive LED
				waitfor(DelayMs(50));
				pinginled(LEDOFF);
			}
		}
	}
Пример #6
0
pinginled(int onoff)
{
   digOut(LED2, onoff);
}
Пример #7
0
pingoutled(int onoff)
{
   digOut(LED1, onoff);
}
Пример #8
0
main()
{
	longword seq,ping_who,tmp_seq,time_out;
	char	buffer[100];

	brdInit();				//initialize board for this demo

   // Configure IO channels as digital outputs (sinking type outputs)
   setDigOut (LED1, 1);				// Configure LED1 as sinking type output
   setDigOut (LED2, 1);				// Configure LED2 as sinking type output

   // Set the initial state of the LED's
   digOut(LED1, LEDOFF);
   digOut(LED2, LEDOFF);

	seq=0;

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);

	/*
	 *		Get the binary ip address for the target of our
	 *		pinging.
	 */

#ifdef PING_WHO
	/* Ping a specific IP addr: */
	ping_who=resolve(PING_WHO);
	if(ping_who==0) {
		printf("ERROR: unable to resolve %s\n",PING_WHO);
		exit(2);
	}
#else
	/* Examine our configuration, and ping the default router: */
	tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END );
	if( tmp_seq != 0 ) {
		printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq );
		exit(2);
	}
	if(ping_who==0) {
		printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n");
		exit(2);
	}
#endif

	for(;;) {
		/*
		 *		It is important to call tcp_tick here because
		 *		ping packets will not get processed otherwise.
		 *
		 */

		tcp_tick(NULL);

		/*
		 *		Send one ping every PING_DELAY ms.
		 */

		costate {
			waitfor(DelayMs(PING_DELAY));
			_ping(ping_who,seq++);
			pingoutled(LEDON);					// flash transmit LED
			waitfor(DelayMs(50));
			pingoutled(LEDOFF);
		}

		/*
		 *		Has a ping come in?  time_out!=0xfffffff->yes.
		 */

		costate {
			time_out=_chk_ping(ping_who,&tmp_seq);
			if(time_out!=0xffffffff) {

#ifdef VERBOSE
				printf("received ping:  %ld\n", tmp_seq);
#endif

				pinginled(LEDON);					// flash receive LED
				waitfor(DelayMs(50));
				pinginled(LEDOFF);
			}
		}
	}
}
Пример #9
0
void main()
{

	auto char s[128];
	auto char display[128];
	auto char channels[16];
	auto int output_status, channel;
	auto int output_level;
	auto unsigned int outputChannel;	

   brdInit();							// Required for controllers
	digOutConfig(DIGOUTCONFIG); 	// Configure high-current outputs
	
	// Display user instructions and channel headings
	DispStr(8, 1, " <<< Sourcing output channel  = OUT0        >>>");
	DispStr(8, 2, " <<< Sinking output channels  = OUT1-OUT7   >>>");
	DispStr(8, 4, "OUT0\tOUT1\tOUT2\tOUT3\tOUT4\tOUT5\tOUT6\tOUT7");
	DispStr(8, 5, "----\t----\t----\t----\t----\t----\t----\t----");
	

	DispStr(8, 8, "Connect the Demo Bd. LED's to the outputs that you want to demo.");
	DispStr(8, 9, "(See instructions in sample program for complete details)");
	DispStr(8, 11, "<-PRESS 'Q' TO QUIT->");

	// Set the channel array to reflect the output channel default value 
	outputChannel = DIGOUTCONFIG;	
	for(channel = 0; channel < 8; channel++)
	{
		// Set the high-current outputs to be OFF, for both sinking
		// and sourcing type outputs. 
		if(outputChannel & 0x01)
		{
			channels[channel] = 0;	// Indicate sourcing type output is OFF
		}
		else
		{
			channels[channel] = 1;	// Indicate sinking type output is OFF
		}
		outputChannel = outputChannel >> 1;
	}
	
	// Loop until user presses the upper/lower case "Q" key
	for(;;)
	{
		// Update high current outputs
		display[0] = '\0';								//initialize for strcat function
		for(channel = 0; channel <= 7; channel++)	//output to channels 0 - 7 
		{
			output_level = channels[channel];		//output logic level to channel
			digOut(channel, output_level);
			sprintf(s, "%d\t", output_level);		//format logic level for display
			strcat(display,s);							//add to display string
		}
		DispStr(8, 6, display);							//update output status 

		
		// Wait for user to make output channel selection or exit program
		sprintf(display, "Select output channel 0 - 7 (Input 0-7) = ");
		DispStr(8, 13, display);
     	do
		{
			channel = getchar();
			if (channel == 'Q' || channel == 'q')		// check if it's the q or Q key        
			{        
      		exit(0);               
     		}
		}while(!isxdigit(channel));

		// Convert the ascii hex value to a interger
		if( channel >= '0' && channel <='7')
		{
			channel = channel - 0x30;
		}

		// Display the channel that ths user has selected 
		sprintf(display, "Select output channel 0 - 7 (Input 0-7) = %d", channel);
		DispStr(8, 13, display);


		// Wait for user to select logic level or exit program
		sprintf(display, "Select logic level (0 or 1) = ");
		DispStr(8, 14, display);
		do
		{
			output_level = getchar();
			if (output_level == 'Q' || output_level == 'q')		// check if it's the q or Q key        
			{        
      		exit(0);               
     		}
     		output_level = output_level - 0x30;
				
		}while(!((output_level >= 0) && (output_level <= 1)));
     	channels[channel] = output_level;

  		// Clear channel and logic level selection prompts 
  		DispStr(8, 13, "                                                  ");
  		DispStr(8, 14, "                                                  ");
   }
}
Пример #10
0
main()
{

	auto char s[128];
	auto char display[128];
	auto char channels[8];
	auto int output_status, channel;
	auto int output_level;
	auto unsigned int outputChannel;	

	brdInit();				//initialize board for this demo
	
	// Display user instructions and channel headings
	DispStr(8, 2, "<<< Proto-board LED's   >>>");
	DispStr(8, 4, "DS1\tDS2");
	DispStr(8, 5, "-----\t-----");
	
	DispStr(8, 10, "From PC keyboard:");
	DispStr(8, 21, "< Press 'Q' To Quit >");
	
	for(channel = DS1; channel <=DS2 ; channel++)
	{
		channels[channel] = 1;		// Indicate output is OFF
		digOut(channel, 1);
	}
	
	// Loop until user presses the upper/lower case "Q" key
	for(;;)
	{
		// Update high current outputs
		display[0] = '\0';								//initialize for strcat function
		for(channel = DS1; channel <= DS2; channel++)	//output to DS1 and DS2 only
		{
			output_level = channels[channel];		//output logic level to channel
			digOut(channel, output_level);
			sprintf(s, "%s\t", output_level?"OFF":"ON");		//format logic level for display
			strcat(display,s);							//add to display string
		}
		DispStr(8, 6, display);							//update output status 

		// Wait for user to make output channel selection or exit program
		sprintf(display, "Select 1=DS1 or 2=DS2 to toggle LED's");
		DispStr(8, 12, display);
     	do
		{
			channel = getchar();
			if (channel == 'Q' || channel == 'q')		// check if it's the q or Q key        
			{        
      		exit(0);               
     		}
     		channel = channel - 0x30;		// convert ascii to integer
		} while (!((channel >= DS1) && (channel <= DS2)));

		// Display the channel that the user has selected
		sprintf(display, "Selected DS%d to toggle               ", channel);
		DispStr(8, 12, display);

		// Wait for user to select logic level or exit program
		sprintf(display, "Select 1=OFF or 0=ON");
		DispStr(8, 13, display);
		do
		{
			output_level = getchar();
			if (output_level == 'Q' || output_level == 'q')		// check if it's the q or Q key        
			{        
      		exit(0);               
     		}
     		output_level = output_level - 0x30;
		} while (!((output_level >= 0) && (output_level <= 1)));
		sprintf(display, "Selected %s         ", output_level?"OFF":"ON");
     	DispStr(8, 13, display);
     	channels[channel] = output_level;

  		// Clear channel and logic level selection prompts 
  		DispStr(8, 12, "                                                  ");
  		DispStr(8, 13, "                                                  ");
   }
}
Пример #11
0
/**
 * Alarm task that handles sounding the alarm and sending 
 * out the alerts
 */
void alarmTask(void *data) {
	// Error reference
	INT8U err;
	
	// Result variables
	char *result;
	auto char realResult;

	// Loop forever
	while(1) {
		//Read MSG Queue, wait forever for message
		result = (char *)OSQPend(msgQueuePtr, 0, &err);
		realResult = *result;

		// Debug
		printf("Alarm Task Run\n");

		// Check for zone 1
		if(realResult == '0') {
			printf("\nZone 1 Tripped!!!!\n");
			digOut(ID_BUZZER, ON);
			digOut(LED_0_ID, ON);

			// Update the current alarm state
			OSSemPend(alarmSem, 0, &err);
				zone0Alarm = ON;
				alarming = ON;
			OSSemPost(alarmSem);

			// Send the alert
			sendEmail(0);
		} else if(realResult == '1') {
			printf("\nZone 12Tripped!!!!\n");
			digOut(ID_BUZZER, ON);
			digOut(LED_1_ID, ON);

			// Update the current alarm state
			OSSemPend(alarmSem, 0, &err);
				zone1Alarm = ON;
				alarming = ON;
			OSSemPost(alarmSem);

			// Send the alert
			sendEmail(1);
		} else if(realResult == '2') {
			printf("\nZone 3 Tripped!!!!\n");
			digOut(ID_BUZZER, ON);
			digOut(LED_2_ID, ON);

			// Update the current alarm state
			OSSemPend(alarmSem, 0, &err);
				zone2Alarm = ON;
				alarming = ON;
			OSSemPost(alarmSem);

			// Send the alert
			sendEmail(2);
		} else if(realResult == '3') {
			printf("\nZone 4 Tripped!!!!\n");
			digOut(ID_BUZZER, ON);
			digOut(LED_3_ID, ON);

			// Update the current alarm state
			OSSemPend(alarmSem, 0, &err);
				zone3Alarm = ON;
				alarming = ON;
			OSSemPost(alarmSem);

			// Send the alert
			sendEmail(3);
		}
	}
}
Пример #12
0
/**
 * This task polls the switches and then 
 * posts a message to the message queue 
 * if an alarm needs to be activated
 */
void switchTask(void *data) {
	// Error Referene
	INT8U err;

	// Local zone status
	auto int localZone0;
	auto int localZone1;
	auto int localZone2;
	auto int localZone3;
	// Local switch state
	auto int sw0State;
	auto int sw1State;
	auto int sw2State;
	auto int sw3State;
	// Result for message queue
	static char result;

	// Initialize zones
	localZone0 = ON;
	localZone1 = ON;
	localZone2 = ON;
	localZone3 = ON;
	// Initialize switch state
	sw0State = OFF;
	sw1State = OFF;
	sw2State = OFF;
	sw3State = OFF;

	// Loop forever
	while(1) {
		// Check switches
		sw0State = digIn(ID_SWITCH_1);
		sw1State = digIn(ID_SWITCH_2);
		sw2State = digIn(ID_SWITCH_3);
		sw3State = digIn(ID_SWITCH_4);

		// Check to see if we have any switches
		if(!sw0State || !sw1State || !sw2State || !sw3State ) {

			// Take a semaphore and get the current zone states
			OSSemPend(zoneSem, 0, &err);
				localZone0 = zone0State;
				localZone1 = zone1State;
				localZone2 = zone2State;
				localZone3 = zone3State;
			OSSemPost(zoneSem);

			// Check to see which zones (if any) have been triggered
			if(!sw0State && localZone0 == ON) {
				// Msg Queue Zone 0
				result = '0';
			}
			else if(!sw1State && localZone1 == ON) {
				// Msg Queue Zone 1
				result = '1';
			}
			else if(!sw2State && localZone2 == ON) {
				// Msg Queue Zone 2
				result = '2';
			}
			else if(!sw3State && localZone3 == ON) {
				// Msg Queue Zone 3
				result = '3';
			}
			else {
				//Nope
				result = 'A';
			}

			// Post the message
			printf("Posting alarm message \n");
			OSQPost(msgQueuePtr, (void *)&result);

		}

		// Update Alarm State (in case web bypassed/disarmed)
		OSSemPend(alarmSem, 0, &err);

			if(alarming == OFF) {
				digOut(ID_BUZZER, OFF);
				digOut(LED_0_ID, OFF);
				digOut(LED_1_ID, OFF);
				digOut(LED_2_ID, OFF);
				digOut(LED_3_ID, OFF);
			}
		OSSemPost(alarmSem);

		//Done
		OSSemPost(switchToHTTP);
		// Try to take a semaphore, this will block us
 		OSSemPend(httpToSwitch, 0, &err);
	}
}