![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ak;jglif;awjd
main.cpp@4:1e5639a2a3ae, 2016-05-20 (annotated)
- Committer:
- awmiller
- Date:
- Fri May 20 17:24:57 2016 +0000
- Revision:
- 4:1e5639a2a3ae
- Parent:
- 1:32eacc4f6beb
sentral tester
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 0:f59179afee57 | 1 | #include "mbed.h" |
awmiller | 4:1e5639a2a3ae | 2 | #include <math.h> |
awmiller | 4:1e5639a2a3ae | 3 | #include <stdio.h> |
awmiller | 4:1e5639a2a3ae | 4 | #include "Sentral.h" |
awmiller | 4:1e5639a2a3ae | 5 | #include "Test_Routines.h" |
awmiller | 4:1e5639a2a3ae | 6 | |
awmiller | 4:1e5639a2a3ae | 7 | Timeout escapez; |
awmiller | 4:1e5639a2a3ae | 8 | |
awmiller | 4:1e5639a2a3ae | 9 | int timeoutz=0; |
awmiller | 4:1e5639a2a3ae | 10 | |
awmiller | 4:1e5639a2a3ae | 11 | |
awmiller | 4:1e5639a2a3ae | 12 | extern DigitalOut SA0; |
awmiller | 4:1e5639a2a3ae | 13 | |
awmiller | 4:1e5639a2a3ae | 14 | typedef char* string; |
awmiller | 4:1e5639a2a3ae | 15 | |
awmiller | 4:1e5639a2a3ae | 16 | #define PI 3.14159f |
awmiller | 4:1e5639a2a3ae | 17 | |
awmiller | 4:1e5639a2a3ae | 18 | PwmOut g(LED_GREEN); |
awmiller | 4:1e5639a2a3ae | 19 | PwmOut r(LED_RED); |
awmiller | 4:1e5639a2a3ae | 20 | PwmOut b(LED_BLUE); |
awmiller | 4:1e5639a2a3ae | 21 | |
awmiller | 4:1e5639a2a3ae | 22 | Serial pc(USBTX,USBRX); |
awmiller | 4:1e5639a2a3ae | 23 | I2C master(PTC9,PTC8); |
awmiller | 4:1e5639a2a3ae | 24 | |
awmiller | 4:1e5639a2a3ae | 25 | AnalogIn VDD_Check(PTE30); |
awmiller | 4:1e5639a2a3ae | 26 | |
awmiller | 4:1e5639a2a3ae | 27 | DigitalIn POWER(PTE29); |
awmiller | 4:1e5639a2a3ae | 28 | |
awmiller | 4:1e5639a2a3ae | 29 | void VDD_read_request() {pc.printf("[*Moudle Voltage: %f *] \r\n",(VDD_Check.read()*3.3f));} |
awmiller | 4:1e5639a2a3ae | 30 | |
emilmont | 0:f59179afee57 | 31 | |
awmiller | 4:1e5639a2a3ae | 32 | |
awmiller | 4:1e5639a2a3ae | 33 | void find_sentral(){ |
awmiller | 4:1e5639a2a3ae | 34 | char inbuff[2],obuff[2]; |
awmiller | 4:1e5639a2a3ae | 35 | obuff[0] = 0x37; |
awmiller | 4:1e5639a2a3ae | 36 | int check[2]; |
awmiller | 4:1e5639a2a3ae | 37 | int addr = SA0 ? AddrSA0_hi : SENTRAL_ADDRESS; |
awmiller | 4:1e5639a2a3ae | 38 | escapez.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 39 | pc.printf("Check1\n"); |
awmiller | 4:1e5639a2a3ae | 40 | check[0] = master.write(addr, obuff, 1); |
awmiller | 4:1e5639a2a3ae | 41 | |
awmiller | 4:1e5639a2a3ae | 42 | pc.printf("Check2\n"); |
awmiller | 4:1e5639a2a3ae | 43 | check[1] = master.read(addr, inbuff, 1); |
awmiller | 4:1e5639a2a3ae | 44 | pc.printf("finding sentral... \r\nwrite %s \r\n",check[0] ? "Fail" : "Pass" ); |
awmiller | 4:1e5639a2a3ae | 45 | |
awmiller | 4:1e5639a2a3ae | 46 | pc.printf("read %s \r\n reading back: %X \r\n",check[1] ? "Fail" : "Pass" , inbuff[0]); |
awmiller | 4:1e5639a2a3ae | 47 | //continue_z: |
awmiller | 4:1e5639a2a3ae | 48 | |
awmiller | 4:1e5639a2a3ae | 49 | if(!check[0] && !check[1]){ |
awmiller | 4:1e5639a2a3ae | 50 | pc.printf("[*{01}Sentral Status: \r\n"); |
awmiller | 4:1e5639a2a3ae | 51 | pc.printf("NEEPROM: %d \r\n", (int)((inbuff[0] & 16)>0)); |
awmiller | 4:1e5639a2a3ae | 52 | pc.printf("StbyState: %d \r\n", (int)((inbuff[0] & 8)>0)); |
awmiller | 4:1e5639a2a3ae | 53 | pc.printf("UploadErr: %d \r\n", (int)((inbuff[0] & 4)>0)); |
awmiller | 4:1e5639a2a3ae | 54 | pc.printf("UploadCPT: %d \r\n", (int)((inbuff[0] & 2)>0)); |
awmiller | 4:1e5639a2a3ae | 55 | pc.printf("EEPROMDTC: %d*] \r\n", (int)((inbuff[0] & 1)>0));} |
awmiller | 4:1e5639a2a3ae | 56 | |
awmiller | 4:1e5639a2a3ae | 57 | |
awmiller | 4:1e5639a2a3ae | 58 | |
awmiller | 4:1e5639a2a3ae | 59 | else pc.printf("[*{00}No Sentral Detected*]"); |
awmiller | 4:1e5639a2a3ae | 60 | escapez.detach(); |
awmiller | 4:1e5639a2a3ae | 61 | //pc.printf("Sentral Status: %X",cmd[0]); |
awmiller | 4:1e5639a2a3ae | 62 | } |
awmiller | 4:1e5639a2a3ae | 63 | |
awmiller | 4:1e5639a2a3ae | 64 | void timeitz() |
awmiller | 4:1e5639a2a3ae | 65 | { |
awmiller | 4:1e5639a2a3ae | 66 | master.stop(); |
awmiller | 4:1e5639a2a3ae | 67 | //goto continue_z; |
awmiller | 4:1e5639a2a3ae | 68 | //timeoutz =1; |
awmiller | 4:1e5639a2a3ae | 69 | } |
awmiller | 4:1e5639a2a3ae | 70 | |
awmiller | 4:1e5639a2a3ae | 71 | |
awmiller | 4:1e5639a2a3ae | 72 | |
awmiller | 4:1e5639a2a3ae | 73 | void RX_int_cb(); |
emilmont | 0:f59179afee57 | 74 | |
emilmont | 0:f59179afee57 | 75 | int main() { |
awmiller | 4:1e5639a2a3ae | 76 | |
awmiller | 4:1e5639a2a3ae | 77 | wait(2); |
awmiller | 4:1e5639a2a3ae | 78 | //RST =0; |
awmiller | 4:1e5639a2a3ae | 79 | pc.attach(&RX_int_cb); |
awmiller | 4:1e5639a2a3ae | 80 | pc.baud(115200); |
awmiller | 4:1e5639a2a3ae | 81 | pc.printf("\nEV0 Test Fixture v1.0\n"); |
awmiller | 4:1e5639a2a3ae | 82 | |
awmiller | 4:1e5639a2a3ae | 83 | r.period(0.020); |
awmiller | 4:1e5639a2a3ae | 84 | g.period(0.020); |
awmiller | 4:1e5639a2a3ae | 85 | b.period(0.020); |
awmiller | 4:1e5639a2a3ae | 86 | |
awmiller | 4:1e5639a2a3ae | 87 | r = 0.990; |
awmiller | 4:1e5639a2a3ae | 88 | b = 0.950; |
awmiller | 4:1e5639a2a3ae | 89 | g = 0.895; |
awmiller | 4:1e5639a2a3ae | 90 | |
awmiller | 4:1e5639a2a3ae | 91 | |
awmiller | 4:1e5639a2a3ae | 92 | SA0_init(); |
awmiller | 4:1e5639a2a3ae | 93 | |
awmiller | 4:1e5639a2a3ae | 94 | pc.printf("SAO Set to %d \r\n",Set_SA0()); |
awmiller | 4:1e5639a2a3ae | 95 | Sentral_Power(0); |
awmiller | 4:1e5639a2a3ae | 96 | wait(0.01); |
awmiller | 4:1e5639a2a3ae | 97 | //VDD_read_request(); |
awmiller | 4:1e5639a2a3ae | 98 | Sentral_Power(); |
awmiller | 4:1e5639a2a3ae | 99 | pc.printf("Sentral Powered on\r\n"); |
awmiller | 4:1e5639a2a3ae | 100 | |
awmiller | 4:1e5639a2a3ae | 101 | //VDD_read_request(); |
awmiller | 4:1e5639a2a3ae | 102 | |
awmiller | 4:1e5639a2a3ae | 103 | //find_sentral(); |
awmiller | 4:1e5639a2a3ae | 104 | |
awmiller | 4:1e5639a2a3ae | 105 | // SentralSetup(); |
emilmont | 0:f59179afee57 | 106 | |
awmiller | 4:1e5639a2a3ae | 107 | //VDD_read_request(); |
awmiller | 4:1e5639a2a3ae | 108 | |
awmiller | 4:1e5639a2a3ae | 109 | while (true){ |
awmiller | 4:1e5639a2a3ae | 110 | |
awmiller | 4:1e5639a2a3ae | 111 | if(POWER==0) |
awmiller | 4:1e5639a2a3ae | 112 | { |
awmiller | 4:1e5639a2a3ae | 113 | //pc.printf("bus init\n"); |
awmiller | 4:1e5639a2a3ae | 114 | //BusOut GPIOS(PTE4,PTE3,PTE2,PTB11,PTB10,PTB9,PTB8); |
awmiller | 4:1e5639a2a3ae | 115 | //pc.printf("i2c remap\n"); |
awmiller | 4:1e5639a2a3ae | 116 | //DigitalOut x(PTC9),y(PTC8); |
awmiller | 4:1e5639a2a3ae | 117 | //pc.printf("delegating\n"); |
awmiller | 4:1e5639a2a3ae | 118 | //x=y=0; |
awmiller | 4:1e5639a2a3ae | 119 | //GPIOS = 0; |
awmiller | 4:1e5639a2a3ae | 120 | //pc.printf("SA0\n"); |
awmiller | 4:1e5639a2a3ae | 121 | Set_SA0(0); |
awmiller | 4:1e5639a2a3ae | 122 | wait_ms(10); |
awmiller | 4:1e5639a2a3ae | 123 | pc.attach(NULL); |
awmiller | 4:1e5639a2a3ae | 124 | while(Sentral_Power(0)); |
awmiller | 4:1e5639a2a3ae | 125 | pc.printf("[*{21}MODULE POWER DISABLED \r\n"); |
awmiller | 4:1e5639a2a3ae | 126 | //VDD_read_request(); |
awmiller | 4:1e5639a2a3ae | 127 | wait_ms(10); |
awmiller | 4:1e5639a2a3ae | 128 | pc.printf("ENABLE POWER TO CONTINUE*] \r\n"); |
awmiller | 4:1e5639a2a3ae | 129 | while(!POWER); |
awmiller | 4:1e5639a2a3ae | 130 | while(!Sentral_Power(1)); |
awmiller | 4:1e5639a2a3ae | 131 | pc.attach(&RX_int_cb); |
awmiller | 4:1e5639a2a3ae | 132 | pc.printf("[*{20}MODULE POWER ENABLED*] \r\n"); |
awmiller | 4:1e5639a2a3ae | 133 | wait(1); |
awmiller | 4:1e5639a2a3ae | 134 | VDD_read_request(); |
awmiller | 4:1e5639a2a3ae | 135 | |
awmiller | 4:1e5639a2a3ae | 136 | } |
awmiller | 4:1e5639a2a3ae | 137 | |
emilmont | 0:f59179afee57 | 138 | } |
emilmont | 0:f59179afee57 | 139 | } |
awmiller | 4:1e5639a2a3ae | 140 | |
awmiller | 4:1e5639a2a3ae | 141 | |
awmiller | 4:1e5639a2a3ae | 142 | void RX_int_cb() { |
awmiller | 4:1e5639a2a3ae | 143 | |
awmiller | 4:1e5639a2a3ae | 144 | switch(pc.getc()) { |
awmiller | 4:1e5639a2a3ae | 145 | |
awmiller | 4:1e5639a2a3ae | 146 | case 'r': |
awmiller | 4:1e5639a2a3ae | 147 | VDD_read_request(); |
awmiller | 4:1e5639a2a3ae | 148 | break; |
awmiller | 4:1e5639a2a3ae | 149 | /* |
awmiller | 4:1e5639a2a3ae | 150 | case 'l': |
awmiller | 4:1e5639a2a3ae | 151 | if(reading){ |
awmiller | 4:1e5639a2a3ae | 152 | if(!hex_read_line(FILE *hexfile)){ |
awmiller | 4:1e5639a2a3ae | 153 | reading =0; |
awmiller | 4:1e5639a2a3ae | 154 | pc.printf("EOF\r\n");} |
awmiller | 4:1e5639a2a3ae | 155 | }else pc.printf("no file open\r\n"); |
awmiller | 4:1e5639a2a3ae | 156 | break; |
awmiller | 4:1e5639a2a3ae | 157 | |
awmiller | 4:1e5639a2a3ae | 158 | case 'h': |
awmiller | 4:1e5639a2a3ae | 159 | if(reading) |
awmiller | 4:1e5639a2a3ae | 160 | { |
awmiller | 4:1e5639a2a3ae | 161 | readhex = 1; |
awmiller | 4:1e5639a2a3ae | 162 | |
awmiller | 4:1e5639a2a3ae | 163 | } |
awmiller | 4:1e5639a2a3ae | 164 | break; |
awmiller | 4:1e5639a2a3ae | 165 | */ |
awmiller | 4:1e5639a2a3ae | 166 | case 'f': |
awmiller | 4:1e5639a2a3ae | 167 | find_sentral(); |
awmiller | 4:1e5639a2a3ae | 168 | break; |
awmiller | 4:1e5639a2a3ae | 169 | |
awmiller | 4:1e5639a2a3ae | 170 | case 's': |
awmiller | 4:1e5639a2a3ae | 171 | pc.printf("Sentral Starting up. \r\n"); |
awmiller | 4:1e5639a2a3ae | 172 | //find_sentral(); |
awmiller | 4:1e5639a2a3ae | 173 | if(!SentralSetup(pc,master)) |
awmiller | 4:1e5639a2a3ae | 174 | //pc.printf("returning to loop\r\n"); |
awmiller | 4:1e5639a2a3ae | 175 | //else |
awmiller | 4:1e5639a2a3ae | 176 | pc.printf("Sentral Start exit failure\r\n"); |
awmiller | 4:1e5639a2a3ae | 177 | break; |
awmiller | 4:1e5639a2a3ae | 178 | |
awmiller | 4:1e5639a2a3ae | 179 | case 't': |
awmiller | 4:1e5639a2a3ae | 180 | pc.printf("Begginng module test...\r\n"); |
awmiller | 4:1e5639a2a3ae | 181 | // pc.printf("Sentral Starting up. \r\n"); |
awmiller | 4:1e5639a2a3ae | 182 | //find_sentral(); |
awmiller | 4:1e5639a2a3ae | 183 | //if(!SentralSetup(pc,master)) |
awmiller | 4:1e5639a2a3ae | 184 | //pc.printf("returning to loop\r\n"); |
awmiller | 4:1e5639a2a3ae | 185 | //else |
awmiller | 4:1e5639a2a3ae | 186 | //pc.printf("Sentral exit failure\r\n"); |
awmiller | 4:1e5639a2a3ae | 187 | // return 0; |
awmiller | 4:1e5639a2a3ae | 188 | //} |
awmiller | 4:1e5639a2a3ae | 189 | //else |
awmiller | 4:1e5639a2a3ae | 190 | if(EV0_test(pc,master)) pc.printf("[*{11}Module PASS*] \r\n"); |
awmiller | 4:1e5639a2a3ae | 191 | break; |
awmiller | 4:1e5639a2a3ae | 192 | |
awmiller | 4:1e5639a2a3ae | 193 | //case '!': |
awmiller | 4:1e5639a2a3ae | 194 | // DigitalOut RST(PTE5); |
awmiller | 4:1e5639a2a3ae | 195 | // RST =0; |
awmiller | 4:1e5639a2a3ae | 196 | // break; |
awmiller | 4:1e5639a2a3ae | 197 | |
awmiller | 4:1e5639a2a3ae | 198 | case '0': |
awmiller | 4:1e5639a2a3ae | 199 | int i = SA0; |
awmiller | 4:1e5639a2a3ae | 200 | pc.printf("SA0: %d",i); |
awmiller | 4:1e5639a2a3ae | 201 | break; |
awmiller | 4:1e5639a2a3ae | 202 | |
awmiller | 4:1e5639a2a3ae | 203 | case 'p': |
awmiller | 4:1e5639a2a3ae | 204 | pc.printf(/*Sentral_pass_through(pc,master)*/ PassThroughTest(pc,master) ? "Passthrough enabled \r\n" : "Passthrough Failure \r\n"); |
awmiller | 4:1e5639a2a3ae | 205 | break; |
awmiller | 4:1e5639a2a3ae | 206 | |
awmiller | 4:1e5639a2a3ae | 207 | default: |
awmiller | 4:1e5639a2a3ae | 208 | pc.printf("[*undefined command*] \r\n"); |
awmiller | 4:1e5639a2a3ae | 209 | break; |
awmiller | 4:1e5639a2a3ae | 210 | } |
awmiller | 4:1e5639a2a3ae | 211 | |
awmiller | 4:1e5639a2a3ae | 212 | } |
awmiller | 4:1e5639a2a3ae | 213 | |
awmiller | 4:1e5639a2a3ae | 214 |