This is the DDRO software we write to operate the chip

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "power_up.h"
00002 #include "scan.h"
00003 #include "master_i2c.h"
00004 #include "JTAG.h"
00005 using namespace std;
00006 
00007 #define FILE_OUTPUT
00008 
00009 DigitalOut RESET (p21);
00010 
00011 Serial s(USBTX, USBRX);
00012 DigitalOut finish_flag (LED3);
00013 
00014 /*
00015 int main()
00016 {
00017 
00018     PLL clk;
00019     JTAG jtag;
00020 
00021     powerReset();
00022     powerUp(1);
00023     wait_us(10);
00024     RESET=1;
00025     wait_us(10);
00026     RESET=0;
00027     wait_us(10);
00028     RESET=1;
00029     clk.setPLL(100);
00030     RESET=0;
00031     wait_us(10);
00032     RESET=1;
00033     jtag.DAP_enable();
00034     unsigned int address, value;
00035     jtag.loadProgram();
00036     address = 0x44000008;
00037     value = 0x00000001;
00038     jtag.writeMemory(address, value);
00039 
00040     address = 0x44000004;
00041     jtag.writeMemory(address, value);
00042     //core is running......
00043 
00044 
00045     int* ro_readings = new int [70]; //0-63: Oscillator (DDRO), 64-65: SRAM/Core Power, 66-69: Leakage
00046     master_write();
00047     master_read(ro_readings);
00048 
00049     if( some GPIO != 0) {powerDown();}
00050 }
00051 */
00052 
00053 int main()
00054 {
00055     s.printf("DDRO_software starts ...\r\n");
00056     double voltage = 1;
00057     PLL clk;
00058     JTAG jtag;
00059     int* ro_readings = new int [68];
00060 #ifdef FILE_OUTPUT
00061     FILE *outFile = fopen("/local/test.out", "a");
00062 #endif
00063     for (int i=0; i<1; i++) {
00064         voltage = 1 - 0.05*i;
00065         powerReset();
00066         powerUp(voltage);
00067 #ifdef FILE_OUTPUT
00068         fprintf(outFile, "Voltage: %f\n", voltage);
00069 #endif
00070         RESET = 0;
00071         wait_us(10);
00072         RESET = 1;
00073         for(int iii=0; iii<1; iii++) {
00074             master_write();
00075             master_read(ro_readings);
00076             for (int ii=0; ii<64; ii++) {
00077 #ifdef FILE_OUTPUT
00078                 fprintf(outFile, "RO %d %d\n", ii, ro_readings[ii]);
00079 #endif
00080             }
00081             double core_meas = 3.3*ro_readings[64]/0x10000;
00082             double sram_meas = 3.3*ro_readings[65]/0x10000;
00083 #ifdef FILE_OUTPUT
00084             fprintf(outFile, "CORE %f\nSRAM %f\n", core_meas,sram_meas);
00085 #endif
00086             double hvtp_meas = 1.8*0.33/ro_readings[66]/0.001;
00087             double hvtn_meas = 1.5*0.33/ro_readings[67]/0.001;
00088 #ifdef FILE_OUTPUT
00089             fprintf(outFile, "HVTP %f\nHVTN %f\n", hvtp_meas, hvtn_meas);
00090 #endif
00091         }
00092         int fmax;
00093         int lower = 51;
00094         int higher = 199;
00095         int frequency = (lower+higher)/2;
00096         clk.setPLL(frequency);
00097         clk.setPLL(frequency);
00098         RESET = 0;
00099         wait_us(10);
00100         RESET = 1;
00101 
00102         while (higher - lower >1) {
00103             s.printf("testing %d\n", frequency);
00104             if(jtag.JTAG_test()) {
00105                 lower = frequency;
00106                 frequency = (lower+higher)/2;
00107                 clk.setPLL(frequency);
00108                 clk.setPLL(frequency);
00109                 RESET = 0;
00110                 wait_us(10);
00111                 RESET = 1;
00112             } else {
00113                 higher = frequency;
00114                 frequency = (lower+higher)/2;
00115                 clk.setPLL(frequency);
00116                 clk.setPLL(frequency);
00117                 RESET = 0;
00118                 wait_us(10);
00119                 RESET = 1;
00120             }
00121         }
00122         
00123 
00124 #ifdef FILE_OUTPUT
00125         fprintf(outFile, "fmax %d\n", lower*5);
00126 #endif
00127         powerDown();
00128     }
00129 #ifdef FILE_OUTPUT
00130     fclose(outFile);
00131 #endif
00132     s.printf("DDRO_software ends.\r\n");
00133     while(1) {
00134         finish_flag = !finish_flag;
00135         wait(1);
00136     }
00137 }