int hello_rotary2(void) { unsigned int data; int pulses=0, dir=0; //set GPIO input mode XGpio_mSetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 4, 0xffffffff); ///////////////////////////////////// // STATE 1: Get the direction pulse //xil_printf(" \r\nState1 \r\n"); do { // get hold of a pulse that tells one of below // bits[1:0] = 01 Left rotation // bits[1:0] = 10 Right rotation // bit 2 = 1 button press data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if(data & 0x1) { dir = DIR_LEFT; break; } if(data & 0x2) { dir = DIR_RIGHT; break; } } while( (data& 0x3) == 0); ////////////////////////////////////////////// // STATE 2: Get the pulses from both switches //xil_printf(" State2 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); } while( (data& 0x3) != 0x3); ///////////////////////////////////////////////////// // STATE 3: Get the pulses from both switches to NULL //xil_printf(" State3 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); } while( (data& 0x3) != 0); // RESULT TO USER pulses += dir; xil_printf("%s-%d [Exit: press anykey]\r\n", (dir==DIR_RIGHT) ? "Anti-Clockwise" : " Clockwise", abs(pulses) ); return dir; }
void LED_Toggle (INT8U led) { INT32U led_status; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif led_status = XGpio_mGetDataReg(BSP_GPIO_ADDR,1); OS_ENTER_CRITICAL(); switch (led) { case 0: //led_status ^= 0xFFFFFFFF; led_status ^= 0x000001FF;; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 1: led_status ^= 0x00000001; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 2: led_status ^= 0x00000002; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 3: led_status ^= 0x00000004; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 4: led_status ^= 0x00000008; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; default: break; } OS_EXIT_CRITICAL(); }
int hello_rotary(void) { unsigned int data; int pulses=0, dir=0; /*** XUartNs550_SetBaud(UART_BASEADDR, UART_CLOCK, UART_BAUDRATE); XUartNs550_mSetLineControlReg(UART_BASEADDR, XUN_LCR_8_DATA_BITS); ***/ xil_printf("\n\r********************************************************"); xil_printf("\n\r********************************************************"); xil_printf("\n\r** KC705 - Rotary Switch Test **"); xil_printf("\n\r********************************************************"); xil_printf("\n\r********************************************************\r\n"); xil_printf("Watch the ROTARY pulses count:\r\n"); xil_printf("press any key to exit the test\r\n"); XUartNs550_ReadReg(STDIN_BASEADDRESS, XUN_RBR_OFFSET); //set GPIO input mode XGpio_mSetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 4, 0xffffffff); while(1) { ///////////////////////////////////// // STATE 1: Get the direction pulse //xil_printf(" \r\nState1 \r\n"); do { // get hold of a pulse that tells one of below // bits[1:0] = 01 Left rotation // bits[1:0] = 10 Right rotation // bit 2 = 1 button press data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if(data & 0x1) { dir = DIR_LEFT; break; } if(data & 0x2) { dir = DIR_RIGHT; break; } if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; } while( (data& 0x3) == 0); ////////////////////////////////////////////// // STATE 2: Get the pulses from both switches //xil_printf(" State2 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; } while( (data& 0x3) != 0x3); ///////////////////////////////////////////////////// // STATE 3: Get the pulses from both switches to NULL //xil_printf(" State3 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; } while( (data& 0x3) != 0); // PRESS ANY KEY TO EXIT if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; // RESULT TO USER pulses += dir; xil_printf("%s-%d [Exit: press anykey]\r\n", (dir==DIR_RIGHT) ? "Anti-Clockwise" : " Clockwise", abs(pulses) ); } rotary_exit: XUartNs550_ReadReg(STDIN_BASEADDRESS, XUN_RBR_OFFSET); return 0; }