Esempio n. 1
0
int main(void) {
	mode = 0;
	ui32SetTempValueC = 25;
	uint32_t ui32ADC0Value[4]; // Storing the data read from FIFO of Sequencer 1

	setup();
	adcSequencerConfigure();
	setTimer();
	setUART();

	while (1) {
		// Enable Sequencer 1
		ADCSequenceEnable(ADC0_BASE, 1);

		ADCIntClear(ADC0_BASE, 1); // Clear ADC Interrupt Flag
		ADCProcessorTrigger(ADC0_BASE, 1); // Trigger ADC Processor

		// Waiting until AD conversion is complete
		// TODO: Use interrupts instead of while loop
		while (!ADCIntStatus(ADC0_BASE, 1, false)) {
		}

		ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);// Reads the data from Sequencer 1 to memory

		ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2]
				+ ui32ADC0Value[3] + 2) / 4; // Averaging temperature data and using 2 for rounding
		ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096) / 10; // Calculate the Celsius value of the temperature

		ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; // Celsius to fahrenheit conversion
		if (ui32SetTempValueC >= ui32TempValueC) {
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
					8); //blink LED
		} else {
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
					2); //blink LED
		}
	}
}
Esempio n. 2
0
/**
 * Parses a line of data given to a control channel.
 * @param pClient the client of the channel
 * @param argIx array with start index of each argument
 * @param argCount number of arguments
 * @return 0 on success, a negative value otherwise
 */
static int ctrlParse(ClientElem_t *pClient, int *argIx, int argCount, int cmdlen) {
	int res = -1;
	char *pCmd = pClient->cmdbuf;

	switch (pCmd[0]) {
		 /* Identify this control channel */
		case 'I': {
			SEND("%i", getIndexByElement(pClient))
			res = 0;
			break;
		}
		/* Attach this channel to given control channel and make it a data channel */
		case 'A': {
			int ix = atoi(&pCmd[argIx[1]]);
			ClientElem_t *pOtherClient = getElementByIndex(ix);
			if (pOtherClient == NULL) {
				SEND("ERROR no such channel")
			} else if (pClient == pOtherClient) {
				SEND("ERROR cannot attach to self")
			} else if (pOtherClient->portNumerator == -1) {
				SEND("ERROR channel not connected to device")
			} else {
				pClient->serialHdl = pOtherClient->serialHdl;
				pClient->portNumerator = pOtherClient->portNumerator;
				pClient->type = TYPE_DATA;
				res = 0;
			}
			break;
		}
		/* List devices */
		case 'L': {
			res = listDevices(pClient);
			break;
		}
		/* Open device */
		case 'O': {
			if (openDevice(pClient, argIx, argCount, cmdlen) >= 0) {
				res = 0;
			}
			break;
		}
		/* Configure UART */
		case 'U': {
			res = setUART(pClient, argIx, argCount);
			break;
		}
		/* Kill client, close device */
		case 'C': {
			DBG_PRINT("Killing client");
			pClient->running = 0;
			res = 0;
			break;
		}
		/* Kill server */
		case 'X': {
			DBG_PRINT("Killing server");
			g_serverRunning = 0;
			res = 0;
			break;
		}
		default: {
			SEND("ERROR unkown command: %s", pCmd)
		}
	}
	if (res == 0) {
		SEND("OK")
	}
	return res;
}