Created
November 17, 2018 18:26
-
-
Save kvablack/ed227e397148a8afa940fce17ecc0520 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) 2015, | |
* National Instruments Corporation. | |
* All rights reserved. | |
*/ | |
#include <stdio.h> | |
#include <time.h> | |
#include "MyRio.h" | |
#define delay 1 // how long, in seconds, to blink to LED | |
#define ledBit 0 // LED number to blink | |
// global session variable, defined in myRIO.c | |
extern NiFpga_Session myrio_session; | |
// blinks LED0 off and on | |
int main(int argc, char **argv) | |
{ | |
printf("LED Blink\n"); | |
NiFpga_Status status; | |
/* | |
* Open the myRIO NiFpga Session. | |
* This function MUST be called before all other functions. After this call | |
* is complete the myRIO target will be ready to be used. | |
*/ | |
status = MyRio_Open(); | |
if (MyRio_IsNotSuccess(status)) | |
{ | |
printf("Failed to initialize NiFpga session\n"); | |
return status; | |
} | |
// read in current LED register bank value | |
uint8_t ledValue; | |
NiFpga_MergeStatus(&status, | |
NiFpga_ReadU8(myrio_session, DOLED30, &ledValue)); | |
if (MyRio_IsNotSuccess(status)) { | |
printf("Failed to read from LED register\n"); | |
return status; | |
} | |
// begin blink loop | |
time_t currentTime; | |
time_t finalTime; | |
uint8_t ledState = 1; | |
while (1) { | |
// set LED to current value | |
if (ledState == 1) { | |
printf("Turning LED on\n"); | |
ledValue = ledValue | (1 << ledBit); | |
} else { | |
printf("Turning LED off\n"); | |
ledValue = ledValue & ~(1 << ledBit); | |
} | |
// write register value | |
NiFpga_MergeStatus(&status, | |
NiFpga_WriteU8(myrio_session, DOLED30, ledValue)); | |
if (MyRio_IsNotSuccess(status)) { | |
printf("Failed to write to LED register\n"); | |
return status; | |
} | |
ledState = ~ledState; | |
// delay | |
time(¤tTime); | |
finalTime = currentTime + delay; | |
while (currentTime < finalTime) time(¤tTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment