unsigned char ReadUART(){ if(UartUnreadCount()!=0){ received++; return UartReadChar(); }else{ return MIDI_NULL; //equivalent no NULL } }
/****************************************************************************** * @brief Sets measurement range. * * @param None. * * @return None. ******************************************************************************/ void ADXL362_SetRange(void) { char rx = 0; char rxReg = 0; xil_printf("\n\r>Select measurement range: \n\r"); xil_printf(" [1] +/- 2g\n\r"); xil_printf(" [2] +/- 4g\n\r"); xil_printf(" [3] +/- 8g\n\r"); xil_printf("Press [1] to [3] to select desired range\n\r"); DisableInterrupts(UART_INTERRUPT); // Check if data is available on the UART rx = UartReadChar(); rxReg = (ADXL362_ReadReg(ADXL362_FILTER_CTL) & 0x3F); switch(rx) { case '1': rxReg = 0x00 | rxReg; xil_printf("> +/- 2g measurement range selected\n\r"); break; case '2': rxReg = 0x40 | rxReg; xil_printf("> +/- 4g measurement range selected\n\r"); break; case '3': rxReg = 0x80 | rxReg; xil_printf("> +/- 8g measurement range selected\n\r"); break; default: xil_printf("> wrong measurement range\n\r"); break; } ADXL362_WriteReg(ADXL362_FILTER_CTL, rxReg); EnableInterrupts(UART_INTERRUPT); rxData = 0; xil_printf("\n\r"); ADXL362_DisplayMenu(); }
/****************************************************************************** * @brief Runs Programmable Ramp Generation Mode Main Menu. * * @param None. * * @return None. ******************************************************************************/ void AD5628_ProgRamp(void) { DisableInterrupts(UART_INTERRUPT); AD5628_DisplayProgRampMenu(); // Check if data is available on the UART rxData = UartReadChar(); switch(rxData) { case 't': AD5628_EnterTimeStep(); break; case 'i': AD5628_EnterIncrStep(); break; case 'd': AD5628_RampDacSel(); break; case 'r': AD5628_RunProgRamp(); break; case 'q': xil_printf("\n\r>Returning to Menu...\n\r"); rxData = 'm'; break; default: xil_printf("\n\rWrong option!"); rxData = 0; break; } if(rxData != 'm') { rxData = 'p'; } EnableInterrupts(UART_INTERRUPT); }
/****************************************************************************** * @brief Runs Programmable Ramp Generation Mode DAC Selection Menu. * * @param None. * * @return None. ******************************************************************************/ void AD5628_RampDacSel(void) { char rx = 0x00; do { AD5628_DisplayDacMenu(); // Check if data is available on UART rx = UartReadChar(); if(rx != 'q') { if(rx == '9') { dacSelected = 0x0F; } else { dacSelected = (rx - 0x31); } switch(dacSelected) { case 0: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC A.\n\r"); break; case 1: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC B.\n\r"); break; case 2: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC C.\n\r"); break; case 3: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC D.\n\r"); break; case 4: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC E.\n\r"); break; case 5: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC F.\n\r"); break; case 6: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC G.\n\r"); break; case 7: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC H.\n\r"); break; case 15: xil_printf("\n\r>You have chosen to update "); xil_printf("All DACs.\n\r"); break; default: xil_printf("\n\rWrong option!\n\r"); break; } } } while (!(((dacSelected >=0) && (dacSelected <=7)) || (dacSelected == 15))); }
/****************************************************************************** * @brief Enters Increment Step Value Set Mode. * * @param None. * * @return None. ******************************************************************************/ void AD5628_EnterIncrStep(void) { char rx = 0; char c[3] = "000"; char *c_ptr; int i = 0; char cnt = 0; char valid = 0; int value = 0; // Disable interrupts in order to use normal polling DisableInterrupts(UART_INTERRUPT); xil_printf("\n\rPlease enter a value between 0x000 and 0xFFF: 0x"); c_ptr = c; // Maximum number of received characters will be 5 (e.g. 5 0 F 0x0D 0x0A) while(i < 5) { // Check if data is available on UART rx = UartReadChar(); xil_printf("%c", rx); // Check if pressed key is [Enter] if(rx == 0x0D) { i = 4; } else if(rx == 0x0A) { i = 4; } else if(((rx > 0x00)&&(rx < 0x30))|| // Not 0 - 9 ((rx > 0x39)&&(rx < 0x41))|| // Not A - F ((rx > 0x46)&&(rx < 0x61))|| // Not a - f (rx > 0x66)) { xil_printf("\n\rCharacters entered must be HEX values (0 to 9 and A B C D E F)"); i = 5; valid = 0; } else { *c_ptr ++= rx; cnt++; valid = 1; } if(cnt == 3) { i = 5; } i++; } xil_printf("\n\r"); // Translate from ASCII to dec for(i = 0; i < cnt; i++) { if(c[i] > 0x60) { value = value * 16 + (c[i] - 0x57); } else if(c[i] > 0x39) { value = value * 16 + (c[i] - 0x37); } else { value = value * 16 + (c[i] - 0x30); } } if(valid == 1) { dacStepValue = value; xil_printf(">Incremented size modified to 0x%x", dacStepValue); xil_printf("\n\r"); } rxData ='p'; }
/****************************************************************************** * @brief Enters Time Step Value Set Mode. * * @param None. * * @return None. ******************************************************************************/ void AD5628_EnterTimeStep(void) { char rx = 0; char c[4] = "0000"; char *c_ptr; int i = 0; char cnt = 0; char valid = 0; int value = 0; int topValue = 4294967295; // Disable interrupts in order to use normal polling DisableInterrupts(UART_INTERRUPT); while(valid == 0) { c_ptr = c; i = 0; cnt = 0; value = 0; xil_printf("\n\rPlease enter a value between 100 and 5000 [ms]: "); // Maximum number of received characters will be 6 (e.g. 5 0 0 0 0x0D 0x0A) while(i < 6) { // Check if data is available on UART rx = UartReadChar(); xil_printf("%c", rx); // Check if pressed key is [Enter] if(rx == 0x0D) { i = 5; } else if(rx == 0x0A) { i = 5; } else if(((rx > 0x00)&&(rx < 0x30))||(rx > 0x39)) { xil_printf("\n\rCharacters must be digits [0] to [9]\n\r"); i = 6; valid = 0; } else { *c_ptr ++= rx; cnt++; valid = 1; } if(cnt == 4) { i = 6; } i++; } xil_printf("\n\r"); // Translate from ASCII to dec for(i = 0; i < cnt; i++) { value = value * 10 + (c[i] - 0x30); } if((value > 5000)||(value < 100)) { xil_printf("\n\r> Incorrect value entered. Value must be between 100 and 5000.\n\r"); valid = 0; } } if(valid == 1) { if(USE_PS7 == 1){ timeStepValue = ((float)6781 / 1000) * value + 1; } else{ timeStepValue = (topValue - (value * 100000)) + 2; } } rxData ='p'; }
/****************************************************************************** * @brief Waveform Generation Mode. * * @param None. * * @return None. ******************************************************************************/ void AD5628_WaveGen(void) { int prevRxData = 0; int i = 0; char valid = 1; char rx = 's'; char dacSel = 0; int repeat = 1; //AD5628_DisplayWaveMenu(); rxData = 's'; xil_printf("\n\r>Waveform Generation Mode Selected\n\r"); while(valid) { repeat = 1; switch(rxData) { case '1': AD5628_WriteUpdateDac(dacSel, (squaretable[i] << 4)); i+=1; break; case '2': AD5628_WriteUpdateDac(dacSel, (triangletable[i] << 4)); i+=1; break; case '3': AD5628_WriteUpdateDac(dacSel, (sawtable[i] << 4)); i+=1; break; case '4': AD5628_WriteUpdateDac(dacSel, (sinetable[i] << 4)); i+=1; break; case 's': break; case 'q': xil_printf("\n\r>Returning to Menu...\n\r"); valid = 0; rxData = 'm'; break; case 'm': break; default: break; } if(rxData != prevRxData) { prevRxData = rxData; switch(rxData) { case '1': xil_printf("\n\r>Square waveform selected\n\r"); break; case '2': xil_printf("\n\r>Triangle waveform selected\n\r"); break; case '3': xil_printf("\n\r>Sawtooth waveform selected\n\r"); break; case '4': xil_printf("\n\r>Sine waveform selected\n\r"); break; case 's': while (repeat == 1) { AD5628_DisplayDacMenu(); DisableInterrupts(UART_INTERRUPT); // Check if data is available on UART rx = UartReadChar(); if(rx != 'q') { if(rx == '9') { dacSel = 0x0F; } else { dacSel = (rx - 0x31); } repeat = 0; switch(dacSel) { case 0: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC A.\n\r"); break; case 1: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC B.\n\r"); break; case 2: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC C.\n\r"); break; case 3: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC D.\n\r"); break; case 4: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC E.\n\r"); break; case 5: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC F.\n\r"); break; case 6: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC G.\n\r"); break; case 7: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC H.\n\r"); break; case 15: xil_printf("\n\r>You have chosen to update "); xil_printf("All DACs.\n\r"); break; default: xil_printf("Wrong option!\n\r"); //xil_printf("\n\r>Returning to DAC Selection...\n\r"); repeat = 1; break; } } else { valid = 0; } if ( (((dacSel >= 0) && (dacSel <= 7)) || (dacSel == 15)) && (valid != 0) ) { AD5628_DisplayWaveMenu(); xil_printf("Press [1] to [4] in order to select the desired output, or [q] to exit\n\r"); } EnableInterrupts(UART_INTERRUPT); } break; case 'q': xil_printf("\n\r>Returning to Menu...\n\r"); valid = 0; rxData = 'm'; break; default: if (valid != 0) { xil_printf("Wrong option!\n\r"); AD5628_DisplayWaveMenu(); xil_printf("Press [1] to [4] in order to select the desired output, or [q] to exit\n\r"); } break; } } if(i > 255) { i = 0; } } }
/****************************************************************************** * @brief Fixed Value Mode. * * @param None. * * @return None. ******************************************************************************/ void AD5628_FixedValue(void) { char rx = 's'; char c[3] = "000"; char *c_ptr; int i = 0; char cnt = 0; char valid = 0; char dacSel = 0; int value = 0; // Disable interrupts in order to use normal polling DisableInterrupts(UART_INTERRUPT); AD5628_DisplayFixedMenu(); while(rx != 'q') { cnt = 0; i = 0; valid = 0; value = 0; c_ptr = c; if(rx == 's') { xil_printf("\n\r"); AD5628_DisplayDacMenu(); // Check if data is available on UART rx = UartReadChar(); if(rx != 'q') { if(rx == '9') { dacSel = 0x0F; } else { dacSel = (rx - 0x31); } switch(dacSel) { case 0: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC A.\n\r"); break; case 1: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC B.\n\r"); break; case 2: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC C.\n\r"); break; case 3: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC D.\n\r"); break; case 4: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC E.\n\r"); break; case 5: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC F.\n\r"); break; case 6: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC G.\n\r"); break; case 7: xil_printf("\n\r>You have chosen to update "); xil_printf("DAC H.\n\r"); break; case 15: xil_printf("\n\r>You have chosen to update "); xil_printf("All DACs.\n\r"); break; case ('s'-0x31): i=5; valid = 0; break; default: xil_printf("Wrong option!"); rx = 's'; i=5; valid = 0; break; } } else { i = 5; valid = 0; } } if(i == 0) { xil_printf("\n\rPlease enter a value between 0x000 and 0xFFF: 0x"); } // Maximum number of received characters will be 5 (e.g. F F F 0x0D 0x0A) while(i < 5) { // Check if data is available on UART rx = UartReadChar(); xil_printf("%c", rx); // Check if pressed key is [Enter] if(rx == 0x0D) { i = 4; } else if(rx == 0x0A) { i = 4; } else if(rx == 'q') { i = 5; valid = 0; } else if(rx == 's') { i = 5; valid = 0; } else if(((rx > 0x00)&&(rx < 0x30))|| // Not 0 - 9 ((rx > 0x39)&&(rx < 0x41))|| // Not A - F ((rx > 0x46)&&(rx < 0x61))|| // Not a - f (rx > 0x66)) { xil_printf("\n\rCharacters entered must be HEX values (0 to 9 and A B C D E F)"); i = 5; valid = 0; } else { *c_ptr++ = rx; cnt = cnt + 1; valid = 1; } if(cnt == 3) { i = 5; } i++; } // Translate from ASCII to hex for(i = 0; i < cnt; i++) { if(c[i] > 0x60) { value = value * 16 + (c[i] - 0x57); } else if(c[i] > 0x39) { value = value * 16 + (c[i] - 0x37); } else { value = value * 16 + (c[i] - 0x30); } } if(valid == 1) { AD5628_WriteUpdateDac(dacSel, value); xil_printf("\n\r>DAC Output modified\n\r"); } } rxData = 'm'; // Enable interrupts EnableInterrupts(UART_INTERRUPT); xil_printf("\n\r\n\r>Returning to Menu\n\r"); }