I practice to use vivado 2018.2 to create two AXI GPIOs like the first picture. I could use C program to pass the ON/OFF from switchs to leds;however, the XGpio_DiscreteRead() is always blocked by gets() when i want to use gets() to get cmd,and write data to leds according cmd. The following is my C code.Please introduce me to solve the problem. Thank you a lot.
#include "xparameters.h"
#include "xgpio.h"
#include <stdio.h>
#include <stdlib.h>
#include "sleep.h"
int main(){
XGpio output,input; /* SW &LED Instance */
int button_data=0x00;
int switch_data=0;
int led_value = 0;
int i=0;
char cmd[4];
Question
billgas
hello,
I practice to use vivado 2018.2 to create two AXI GPIOs like the first picture. I could use C program to pass the ON/OFF from switchs to leds;however, the XGpio_DiscreteRead() is always blocked by gets() when i want to use gets() to get cmd,and write data to leds according cmd. The following is my C code.Please introduce me to solve the problem. Thank you a lot.
#include "xparameters.h"
#include "xgpio.h"
#include <stdio.h>
#include <stdlib.h>
#include "sleep.h"
int main(){
XGpio output,input; /* SW &LED Instance */
int button_data=0x00;
int switch_data=0;
int led_value = 0;
int i=0;
char cmd[4];
XGpio_Initialize(&output, XPAR_AXI_GPIO_1_DEVICE_ID);
XGpio_SetDataDirection(&output, 1, 0x0);
XGpio_Initialize(&input, XPAR_AXI_GPIO_0_DEVICE_ID);
XGpio_SetDataDirection(&input, 1, 0xF);
while(1) {
i++;
printf("This the %d time run the while loop\n\r",i);
printf("Enter Command: \n\r");
gets(cmd);
switch_data = XGpio_DiscreteRead(&input, 1);
printf("switch_data = %d\n\r",switch_data);
led_value = switch_data+1;
XGpio_DiscreteWrite(&output, 1, led_value);
printf("data wrtie over");
printf("==========================================");
usleep(20000);
}
return 0;
}
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.