Andrew Miller
/
FRDM_Serial
ak;jglif;awjd
Revision 4:1e5639a2a3ae, committed 2016-05-20
- Comitter:
- awmiller
- Date:
- Fri May 20 17:24:57 2016 +0000
- Parent:
- 3:eea88312499a
- Commit message:
- sentral tester
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sentral.cpp Fri May 20 17:24:57 2016 +0000 @@ -0,0 +1,203 @@ +//STM32 Tracler ports +#include "mbed.h" + +#define SENTRAL_DI02 + +#define TRUE 1 +#define FALSE !TRUE + +#include "Sentral.h" + +DigitalOut SentralPower(PTA5); +DigitalOut SA0(PTA4); + +void SA0_init() +{ + // SA0.mode(PullDown); + Set_SA0(0); +} + +int Set_SA0(int val){ + + SA0 = (val > 0); + return SA0; +} + +int Sentral_Power(int val){ + + SentralPower = (val > 0); + return SentralPower; +} + +void Sentral_Reset(){ + + Sentral_Power(0); + wait(1); + Sentral_Power(1); + +} +int Sentral_pass_through(Serial &pc,I2C &master,int recursion) +{ + if(recursion > 20) + { + pc.printf("Recursion limit reached \r\n"); + return 0; + } + + char cmd[3]; + char chk[3]; + + + //Serial_PutString("Sentral Reset Reg", 20); + cmd[0] = PASSTHROUGH_CONFIG_REG; + cmd[1]=0x01; + int check = master.write(SA0 ? AddrSA0_hi : SENTRAL_ADDRESS,cmd,2); + + //cmd[0] = 0; + + if(check) + pc.printf("Pass through request fail, I2C write fail \r\n",check); + else + { + check = master.write(SA0 ? AddrSA0_hi : SENTRAL_ADDRESS,cmd,1); + check = master.read(SA0 ? AddrSA0_hi : SENTRAL_ADDRESS,chk,1); + + if(check) + pc.printf("Pass through register read fail. \r\n"); + else + { + if(chk[0] == 0x01) + { + pc.printf("Pass through Success \r\n"); + return 1; + } + else + { + pc.printf("Recursion %d failed \r\n", recursion); + return Sentral_pass_through(pc,master,++recursion); + } + } + + + + } +} + + +//I2C master(p28, p27); +//Serial pc(USBTX,USBRX); + + +/******************************************************************************* +* Function Name : SentralSetup +* Description : code snippet for setting up sentral +* to run. +* Return : None +*******************************************************************************/ +unsigned int SentralSetup(Serial &pc,I2C &master){ + + + Sentral_Reset(); + pc.printf("Reset"); + + unsigned char /*temp[1],*/boot_timeout=0,count=0x00; + //unsigned char test = 0, ReturnedByte=0x00; + //int ret_status= 0x00; + + char cmd[10]; + + + //Serial_PutString("Sentral Reset Reg", 20); + cmd[0] = RESET_REQ_REG; + cmd[1]=0x01; + int check = master.write(SA0 ? AddrSA0_hi : SENTRAL_ADDRESS,cmd,2); + + cmd[0] = 0; + + if(check) + pc.printf("I2C Reset Request Fail, Check pull-ups and Reset \r\n",check); + else + pc.printf("Reset Request Pass \r\n"); + + pc.printf("Status Check: "); + //while(((ReturnedByte & 0x06) != 2)&&(boot_timeout==0)){ + while(((cmd[0] & 0x06) != 2)&&(boot_timeout==0)){ + + //test=SentralRead(SENTRAL_STATUS_REG,&ReturnedByte); + cmd[0] = SENTRAL_STATUS_REG; + //cmd[1]= 0x01; + check = master.write(SA0 ? AddrSA0_hi : SENTRAL_ADDRESS, cmd, 1); + if(check) + pc.printf("i2c write fail %d \r\n",check); + cmd[0] = 0; + master.read(SA0 ? AddrSA0_hi : SENTRAL_ADDRESS, cmd, 1); + if(check) + pc.printf("i2c read fail %d \r\n",check); + + //pc.printf(" %d,%X",count,cmd[0]); + + count++; + if(count==30) + boot_timeout=1; + + wait_ms(100); + + } + if(check) + pc.printf("[*I2C Bus Failure, try repositioning the module*] \r\n",check); + + if(boot_timeout){ + //PrintChars("Timeout occured, sentral not present or took too long to boot from the EEPROM\n\r"); + pc.printf("Timeout occured, sentral not present or took too long to boot from the EEPROM\n\r"); + + //SerialPutChars("ReturnByte: 0x"); + pc.printf("Timeout ReturnByte: %X \r\n", cmd[0]); + //char testbuff[5]; + //snprintf(testbuff, 5, "%x,", ReturnedByte); + //SerialPutString(testbuff,5); + //SerialPutChars("Force it"); + //SerialPutChar('\n'); + //SerialPutChar('\r'); + + return RETURN_FAILURE; + } + + pc.printf("Success ReturnByte: %X \r\n", cmd[0]); + // SerialPutChars("ReturnByte: 0x"); + // char testbuff[5]; + // snprintf(testbuff, 5, "%x,", ReturnedByte); + // SerialPutString(testbuff,5); + // //SerialPutChars("Force it"); + // SerialPutChar('\n'); + // SerialPutChar('\r'); + + //force a times out after 3 seconds + //count = 0; + //boot_timeout = FALSE; + //while(boot_timeout==FALSE){ + //count++; + //if(count==30) + // boot_timeout=TRUE; + + wait(1); + //} + + + //SentralWrite(ENABLE_EVENTS_REG,0x20); // enable gyro event only (for data logging function) + //SentralWrite(MAG_RATE_REG,0x64); //set mag rate + //SentralWrite(ACCEL_RATE_REG,0x0a); //set accel rate + //SentralWrite(GYRO_RATE_REG,0x46); //set gyro rate + //SentralWrite(ALGORITHM_CONTROL,0x02); //update registers with RAW sensor data + //SentralWrite(ALGORITHM_CONTROL,0x00); //update registers with Scaled sensor data + + //SentralWrite(HOST_CONTROL_REG,0x01); //Request CPU to run + cmd[0] = HOST_CONTROL_REG; + cmd[1]=0x01; + master.write(SA0 ? AddrSA0_hi : SENTRAL_ADDRESS,cmd,2); + pc.printf("Sentral Startup Success. \r\n"); + + return 1; +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sentral.h Fri May 20 17:24:57 2016 +0000 @@ -0,0 +1,59 @@ +#ifndef __SENTRAL_H +#define __SENTRAL_H + +#define SENTRAL_DI02 + +typedef struct { + unsigned long AXIS_X; + unsigned long AXIS_Y; + unsigned long AXIS_Z; + unsigned long AXIS_W; +} QuaternionData; + +#define SENTRAL_EEPROM_ADDRESS 0xa0 +#define SENTRAL_ADDRESS 0x50 +#define SENTRAL_ACC_ADDRESS 0x1a +#define SENTRAL_Q_ADDRESS 0x00 + +void Setup_Sentral_EEPROM(); +int SentralGetQData(QuaternionData* buff); + +#define SentralAddress 0x50 + + +#ifdef SENTRAL_DI02 +#define RETURN_SUCCESS 1 +#define RETURN_FAILURE 0 +#define ENABLE_EVENTS_REG 0x33 +#define MAG_RATE_REG 0x55 +#define ACCEL_RATE_REG 0x56 +#define GYRO_RATE_REG 0x57 +#define HOST_CONTROL_REG 0x34 +#define SENTRAL_STATUS_REG 0x37 +#define PASSTHROUGH_CONFIG_REG 0xa0 +#define RESET_REQ_REG 0x9b +#define REVISION_ID_REG 0x91 +#define HOST_STATUS_REG 0x92 +#define ALGORITHM_CONTROL 0x54 + +#define DEFAULT_I2C_SPEED_KHZ 100 + +//M_BED PORTS +//int ResetSentral(UInt8 NewByte); +//int Setup_Sentral(void); +unsigned int SentralSetup(Serial &pc,I2C &master); + +//M_BED ROUTINES +#define AddrSA0_hi 0x52 +int Sentral_Power(int val =1); +int Set_SA0(int val =0); +void Sentral_Reset(); +void SA0_init(); +int Sentral_pass_through(Serial &pc,I2C &master, int recursion =0); + + + + +#endif + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test_Routines.cpp Fri May 20 17:24:57 2016 +0000 @@ -0,0 +1,274 @@ +#include "mbed.h" +#include "Sentral.h" +#include "Test_Routines.h" + +BusIn GPIOS(PTE4,PTE3,PTE2,PTB11,PTB10,PTB9,PTB8); +Timeout escape; + +int timeout=0; + +void timeit() +{ + timeout =1; + } + +int EV0_test(Serial &pc,I2C &master) +{ + + //Set SA0 to 1 + pc.printf("SA0 set to %d \r\n", Set_SA0(1)); + wait(0.1); + //Startup Sentral at SA0 = 1; + if(!SentralSetup(pc,master)){ + pc.printf("[*{10}Sentral Start-up Failure*] SA1 Failed\r\n"); + return 0; + } + int P=0 , trig =0 ; + //Wait for any pin to fire + do + { + P = GPIOS; + + if(P&&0x40) + trig = 0x40; + if(P&&0x01) + trig = 0x01; + if(P&&0x02) + trig = 0x02; + if(P&&0x04) + trig = 0x04; + if(P&&0x08) + trig = 0x08; + if(P&&0x10) + trig = 0x10; + if(P&&0x20) + trig = 0x20; + } while((!(GPIOS) && (timeout++ < 1000))); + + //Wait for pin to go low again + while(GPIOS & trig); + + if(timeout < 1000) + pc.printf("Trigger: Pin %d \r\n",trig); + else + { + pc.printf("[*{10}GPIO Timeout*] \r\n"); + return 0; + } + + //reset timeout + timeout=0; + + //Check for simultaneity + while( ( GPIOS < 0x7F ) && (timeout < 1000) ) + timeout++; + + if(timeout < 100) + pc.printf("Notice: Pins are simultaneous, check continuity \r\n"); + + //reset triger and timeout + timeout=0; + trig =0; + + //start a timer + escape.attach(&timeit, 10.0); + + //wait for each pin to fire********** + while(!(GPIOS&&0x40))//6 + if(timeout) { trig = -7; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x01))//0 + if(timeout) { trig = -1; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x02))//1 + if(timeout) { trig = -2; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x04))//2 + if(timeout) { trig = -3; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x08))//3 + if(timeout){ trig = -4; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x10))//4 + if(timeout) { trig = -5; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x20))//5 + if(timeout) { trig = -6; break; } + //END SINGLE PIN TEST + + if(!timeout){ + pc.printf("All Pins Fired\r\n"); + //return 1; + } + else + { + pc.printf("Timeout on %d, [*{10}Test FAILED*] \r\n GPIO Failure at SA0 = 1 \r\n", ( trig * (-1) ) - 1 ); + return 0; + } + + + //Set SA0 to 0 + pc.printf("SA0 set to %d \r\n", Set_SA0(0)); + wait(0.1); + //Startup Sentral at SA0 = 0; + if(!SentralSetup(pc,master)){ + pc.printf("[*{10}Sentral Start-up Failure*] SA0 Failed\r\n"); + return 0; + } + + //Wait for any pin to fire + do + { + P = GPIOS; + + if(P&&0x40) + trig = 0x40; + if(P&&0x01) + trig = 0x01; + if(P&&0x02) + trig = 0x02; + if(P&&0x04) + trig = 0x04; + if(P&&0x08) + trig = 0x08; + if(P&&0x10) + trig = 0x10; + if(P&&0x20) + trig = 0x20; + } while((!(GPIOS) && (timeout++ < 1000))); + + //Wait for pin to go low again + while(GPIOS & trig); + + if(timeout < 1000) + pc.printf("Trigger: Pin%d \r\n",trig); + else + { + pc.printf("[*{10}GPIO Timeout*] \r\n"); + return 0; + } + + //reset timeout + timeout=0; + + //Check for simultaneity + while( ( GPIOS < 0x7F ) && (timeout < 1000) ) + timeout++; + + if(timeout < 100) + pc.printf("Notice: Pins are simultaneous, check continuity \r\n"); + + //reset triger and timeout + timeout=0; + trig =0; + + //start a timer + escape.attach(&timeit, 10.0); + + //wait for each pin to fire********** + while(!(GPIOS&&0x40))//6 + if(timeout) { trig = -7; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x01))//0 + if(timeout) { trig = -1; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x02))//1 + if(timeout) { trig = -2; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x04))//2 + if(timeout) { trig = -3; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x08))//3 + if(timeout){ trig = -4; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x10))//4 + if(timeout) { trig = -5; break; } + escape.detach(); + escape.attach(&timeit, 10.0); + + while(!(GPIOS&&0x20))//5 + if(timeout) { trig = -6; break; } + //END SINGLE PIN TEST + + if(!timeout){ + pc.printf("All Pins Fired\r\n"); + //return 1; + } + else + { + pc.printf("Timeout on %d, [*{10}Test FAILED*] \r\n GPIO Failure at SA0 = 0 \r\n", ( trig * (-1) ) - 1 ); + return 0; + } + + + + + //FINALLY, Test pass through mode + + + return 1; + + + +} + +int PassThroughTest(Serial &pc,I2C &master) +{ + if( !Sentral_pass_through(pc,master) ) + { + return 0; + } + + char cmd[3]; + char chk[3]; + + cmd[0] = 0x00; + cmd[1] = 0x00; + cmd[2] = 0x00; + for(int i = 0xA0; i < 0xB0; i += 2) + { + int check = master.write(i,cmd,2); + + if(check) + pc.printf("."); + //break;//return 0; + else + { + check = master.read(i,chk,3); + + if(check) + pc.printf(".");//break;//return 0; + else + { + pc.printf("\r\n%X,%X,%X \r\n",chk[0],chk[1],chk[2]); + return 1; + } + } + } + return 0; +} + +//EOF +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test_Routines.h Fri May 20 17:24:57 2016 +0000 @@ -0,0 +1,12 @@ +#ifndef TESTH +#define TESTH + +#define EEPROM_A 0xA0 + +void timeit(); +int EV0_test(Serial &pc,I2C &master); +int PassThroughTest(Serial &pc,I2C &master); + +#endif +//EOF +
--- a/main.cpp Tue Feb 19 23:48:41 2013 +0000 +++ b/main.cpp Fri May 20 17:24:57 2016 +0000 @@ -1,16 +1,214 @@ #include "mbed.h" +#include <math.h> +#include <stdio.h> +#include "Sentral.h" +#include "Test_Routines.h" + +Timeout escapez; + +int timeoutz=0; + + +extern DigitalOut SA0; + +typedef char* string; + +#define PI 3.14159f + +PwmOut g(LED_GREEN); +PwmOut r(LED_RED); +PwmOut b(LED_BLUE); + +Serial pc(USBTX,USBRX); +I2C master(PTC9,PTC8); + +AnalogIn VDD_Check(PTE30); + +DigitalIn POWER(PTE29); + +void VDD_read_request() {pc.printf("[*Moudle Voltage: %f *] \r\n",(VDD_Check.read()*3.3f));} + -DigitalOut myled(LED_GREEN); -Serial pc(USBTX,USBRX); + +void find_sentral(){ + char inbuff[2],obuff[2]; + obuff[0] = 0x37; + int check[2]; + int addr = SA0 ? AddrSA0_hi : SENTRAL_ADDRESS; + escapez.attach(&timeit, 10.0); + pc.printf("Check1\n"); + check[0] = master.write(addr, obuff, 1); + + pc.printf("Check2\n"); + check[1] = master.read(addr, inbuff, 1); + pc.printf("finding sentral... \r\nwrite %s \r\n",check[0] ? "Fail" : "Pass" ); + + pc.printf("read %s \r\n reading back: %X \r\n",check[1] ? "Fail" : "Pass" , inbuff[0]); +//continue_z: + + if(!check[0] && !check[1]){ + pc.printf("[*{01}Sentral Status: \r\n"); + pc.printf("NEEPROM: %d \r\n", (int)((inbuff[0] & 16)>0)); + pc.printf("StbyState: %d \r\n", (int)((inbuff[0] & 8)>0)); + pc.printf("UploadErr: %d \r\n", (int)((inbuff[0] & 4)>0)); + pc.printf("UploadCPT: %d \r\n", (int)((inbuff[0] & 2)>0)); + pc.printf("EEPROMDTC: %d*] \r\n", (int)((inbuff[0] & 1)>0));} + + + + else pc.printf("[*{00}No Sentral Detected*]"); + escapez.detach(); + //pc.printf("Sentral Status: %X",cmd[0]); +} + +void timeitz() +{ + master.stop(); + //goto continue_z; + //timeoutz =1; + } + + + +void RX_int_cb(); int main() { - int i=0; - pc.printf("\nHello World!\n"); + + wait(2); + //RST =0; + pc.attach(&RX_int_cb); + pc.baud(115200); + pc.printf("\nEV0 Test Fixture v1.0\n"); + + r.period(0.020); + g.period(0.020); + b.period(0.020); + + r = 0.990; + b = 0.950; + g = 0.895; + + + SA0_init(); + + pc.printf("SAO Set to %d \r\n",Set_SA0()); + Sentral_Power(0); + wait(0.01); + //VDD_read_request(); + Sentral_Power(); + pc.printf("Sentral Powered on\r\n"); + + //VDD_read_request(); + + //find_sentral(); + + // SentralSetup(); - while (true) { - wait(0.5); - pc.printf("%d\n",i); - i++; - myled = !myled; + //VDD_read_request(); + + while (true){ + + if(POWER==0) + { + //pc.printf("bus init\n"); + //BusOut GPIOS(PTE4,PTE3,PTE2,PTB11,PTB10,PTB9,PTB8); + //pc.printf("i2c remap\n"); + //DigitalOut x(PTC9),y(PTC8); + //pc.printf("delegating\n"); + //x=y=0; + //GPIOS = 0; + //pc.printf("SA0\n"); + Set_SA0(0); + wait_ms(10); + pc.attach(NULL); + while(Sentral_Power(0)); + pc.printf("[*{21}MODULE POWER DISABLED \r\n"); + //VDD_read_request(); + wait_ms(10); + pc.printf("ENABLE POWER TO CONTINUE*] \r\n"); + while(!POWER); + while(!Sentral_Power(1)); + pc.attach(&RX_int_cb); + pc.printf("[*{20}MODULE POWER ENABLED*] \r\n"); + wait(1); + VDD_read_request(); + + } + } } + + +void RX_int_cb() { + + switch(pc.getc()) { + + case 'r': + VDD_read_request(); + break; + /* + case 'l': + if(reading){ + if(!hex_read_line(FILE *hexfile)){ + reading =0; + pc.printf("EOF\r\n");} + }else pc.printf("no file open\r\n"); + break; + + case 'h': + if(reading) + { + readhex = 1; + + } + break; + */ + case 'f': + find_sentral(); + break; + + case 's': + pc.printf("Sentral Starting up. \r\n"); + //find_sentral(); + if(!SentralSetup(pc,master)) + //pc.printf("returning to loop\r\n"); + //else + pc.printf("Sentral Start exit failure\r\n"); + break; + + case 't': + pc.printf("Begginng module test...\r\n"); + // pc.printf("Sentral Starting up. \r\n"); + //find_sentral(); + //if(!SentralSetup(pc,master)) + //pc.printf("returning to loop\r\n"); + //else + //pc.printf("Sentral exit failure\r\n"); + // return 0; + //} + //else + if(EV0_test(pc,master)) pc.printf("[*{11}Module PASS*] \r\n"); + break; + + //case '!': + // DigitalOut RST(PTE5); + // RST =0; + // break; + + case '0': + int i = SA0; + pc.printf("SA0: %d",i); + break; + + case 'p': + pc.printf(/*Sentral_pass_through(pc,master)*/ PassThroughTest(pc,master) ? "Passthrough enabled \r\n" : "Passthrough Failure \r\n"); + break; + + default: + pc.printf("[*undefined command*] \r\n"); + break; + } + + } + + \ No newline at end of file