Created
April 24, 2018 03:53
-
-
Save brentru/b314d94e03e7abe0cfa7e66d93f3a300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* | |
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved. | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* Use of the Software is limited solely to applications: | |
* (a) running on a Xilinx device, or | |
* (b) that interact with a Xilinx device through a bus or interconnect. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF | |
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
* SOFTWARE. | |
* | |
* Except as contained in this notice, the name of the Xilinx shall not be used | |
* in advertising or otherwise to promote the sale, use or other dealings in | |
* this Software without prior written authorization from Xilinx. | |
* | |
******************************************************************************/ | |
/* | |
* helloworld.c: simple test application | |
* | |
* This application configures UART 16550 to baud rate 9600. | |
* PS7 UART (Zynq) is not initialized by this application, since | |
* bootrom/bsp configures it to baud rate 115200 | |
* | |
* ------------------------------------------------ | |
* | UART TYPE BAUD RATE | | |
* ------------------------------------------------ | |
* uartns550 9600 | |
* uartlite Configurable only in HW design //115200 | |
* ps7_uart 115200 (configured by bootrom/bsp) | |
*/ | |
/***************************** Include Files *********************************/ | |
#include <stdio.h> | |
#include "platform.h" | |
#include "xil_printf.h" | |
#include "PmodHYGRO.h" | |
#include "PmodALS.h" | |
#include "xgpio.h" | |
#include "sleep.h" | |
#include "xil_cache.h" | |
#include "xil_types.h" | |
#include "xparameters.h" | |
/************************** Constant Definitions *****************************/ | |
#define LEDONE 0x01 | |
/************************** Function Prototypes ******************************/ | |
void hardwareSetup(); | |
void cleanup_caches(); | |
int pollALS(int lightVal); | |
/************************** Variable Definitions *****************************/ | |
/* | |
* The following are declared globally so they are zeroed and so they are | |
* easily accessible from a debugger | |
*/ | |
PmodALS ALS; | |
PmodHYGRO hygro; | |
XGpio Gpio; | |
int main() | |
{ | |
init_platform(); | |
hardwareSetup(); | |
xil_printf("Plant Monitoring System\n\r"); | |
// HYGRO | |
float temp_degc, hum_perrh, temp_degf; | |
// ALS | |
int printLight = 0; | |
while(1) | |
{ | |
temp_degc = HYGRO_getTemperature(&hygro); | |
temp_degf = HYGRO_tempC2F(temp_degc); | |
hum_perrh = HYGRO_getHumidity(&hygro); | |
xil_printf( | |
"Temperature: %d.%02d deg F Humidity: %d.%02d RH\n\r", | |
(int) temp_degf, | |
((int) (temp_degf * 100)) % 100, | |
(int) hum_perrh, | |
((int) (hum_perrh * 100)) % 100 | |
); | |
// ALS | |
printLight = pollALS(printLight); | |
xil_printf("Light = %d\n\r", printLight); | |
} | |
cleanup_platform(); | |
return 0; | |
} | |
// polls the ALS pmod 5 times, averages runs, and rets an int | |
int pollALS(int lightVal) { | |
int alsArr[5]; | |
// poll the als 5 times | |
for(int i = 0; i < 6; i++) { | |
alsArr[i] = ALS_read(&ALS); | |
} | |
// and average em together & ret | |
lightVal = (alsArr[0] + alsArr[1] + alsArr[2] + alsArr[3] + alsArr[4]) / 5; | |
return lightVal; | |
} | |
void hardwareSetup() | |
{ | |
xil_printf("starting HYGRO\n\r"); | |
HYGRO_begin(&hygro,XPAR_PMODHYGRO_0_AXI_LITE_IIC_BASEADDR, | |
0x40, | |
XPAR_PMODHYGRO_0_AXI_LITE_TMR_BASEADDR, | |
XPAR_PMODHYGRO_0_DEVICE_ID, | |
XPAR_CPU_M_AXI_DP_FREQ_HZ);//start hygro with axi addr of base and timer, address 40(from IC), AXI speed. | |
// ALS // | |
xil_printf("starting ALS\n\r"); | |
ALS_begin(&ALS, XPAR_PMODALS_0_AXI_LITE_SPI_BASEADDR); | |
// GPIO // | |
int Status; | |
Status = XGpio_Initialize(&Gpio, XPAR_GPIO_1_DEVICE_ID); | |
if (Status != XST_SUCCESS) { | |
xil_printf("Gpio Initialization Failed\r\n"); | |
} | |
xil_printf("GPIO started\r\n"); | |
XGpio_SetDataDirection(&Gpio, 1, 3); | |
XGpio_SetDataDirection(&Gpio, 1, 4); | |
XGpio_SetDataDirection(&Gpio, 1, 5); | |
XGpio_SetDataDirection(&Gpio, 1, 6); | |
XGpio_SetDataDirection(&Gpio, 1, 7); | |
XGpio_SetDataDirection(&Gpio, 1, 8); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment