📄 peripheral_test.c
字号:
#include "excalibur.h"#include "i2c.h"//#define ADC_PRESENT//send 8 bits to the memory#ifdef ADC_PRESENTvoid adc_txchar (Uint16 data){ while (!(na_adc->np_spistatus & np_spistatus_trdy_mask)); na_adc->np_spitxdata = data;}//receive 8 bits from the memoryUint16 adc_rxchar (){ while (!(na_adc->np_spistatus & np_spistatus_rrdy_mask)); return (na_adc->np_spirxdata);}#elsevoid adc_txchar(Uint16 data){ return;}Uint16 adc_rxchar(){ return 1;}#endifint main(){ volatile Uint8 answer; volatile Uint8 data[10]; volatile Uint32 x; volatile Uint32 y; volatile Uint32 time; T_i2c *psti2c = (T_i2c *) na_i2c; /* Initialize I2C Verilog module */ i2c_init(psti2c); printf("Peripheral test executing from %X\n",nasys_program_mem); ///////////////////////////////////////////////////// printf("Press 'a' for SPI ADC test\n"); printf("Press 'b' for Button->LED test\n"); printf("Press 'c' to view RTC time\n"); printf("Press 'l' for 5VIO test\n"); printf("Press 's' to set RTC time to 0 and enable\n"); printf("Press 't' to view Temperature\n"); printf("Press 'x' to EXIT\n"); while (1) { if (na_uart_dbg->np_uartstatus & np_uartstatus_rrdy_mask) { answer = na_uart_dbg->np_uartrxdata; switch (answer) { case 'a': /* SPI ADC test */ printf("Displaying ADC Channel 1+2 on LED's...\n"); while (1) { adc_txchar(0x7800); x = adc_rxchar() >> 2; adc_txchar(0x6800); x += (adc_rxchar() >> 2); na_led_port->np_piodata = (x) & 0xff; } break; case 'b': /* Push-button test */ printf("Displaying push-buttons on LED's...\n"); while (1) { na_led_port->np_piodata = na_pb->np_piodata; } break; case 'c': /* Read RTC time */ rtc_inttotime(i2c_rtc_gettime(psti2c), data); printf("H: %d M: %d S: %d\n",data[0],data[1],data[2]); printf("Please make another selection\n"); break; case 'l': printf("Running 5VIO test...\n"); //na_led_port->np_piodata = na_hv_in->np_piodata; printf("5V Input port reads %X\n",na_hv_in->np_piodata); na_hv_out->np_piodata = 0xAA; printf("5V Input port reads %X\n",na_hv_in->np_piodata); na_hv_out->np_piodata = 0x55; printf("5V Input port reads %X\n",na_hv_in->np_piodata); break; case 's': /* Sets RTC time to 0 and enables */ printf("Setting time\n"); time = rtc_timetoint(0, 0, 0); printf("Return code: %d\n",i2c_rtc_settime(psti2c,time)); printf("Please make another selection\n"); break; case 't': /* Gets Temperature */ x = i2c_get_temp(psti2c); printf("Get temperature returned: %d\n",x); printf("Please make another selection\n"); break; case 'x': exit(0); break; default: printf("Invalid\n"); break; } /* End switch/case */ } /* End rxchar test */ } /* end while loop */ return 0; } /* end main */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -