int pascalstring() { int i, n, x; x=ReadOneByte(); //if(printMode==1)printf("%02X ", x);else; a_loc++; i_col++; result=x; stringBuf[0]=x; n=x; for(i=1;i<n+1;i++) { x=ReadOneByte(); //if(printMode==1)printf("%02X ", x);else; a_loc++; i_col++; result=x; stringBuf[i]=x;} return 1; }
u8 DecoderTest(u8 type, u8 index, u8 val) { u8 tmp; int nCounter; int nWhichDecoder=1; if (type==1) { if (ReadOneByte(0x42, 0x1f, &tmp)) DEBUG0("Decoder Status Byte (0x1f) = %x",tmp); else DEBUG0("Decoder Status Byte not read"); } else if (type==2) { DEBUG0("PAL decoder Dump:"); for(nCounter=0; nCounter<P7114_Count; nCounter++) { if (ReadOneByte(I2CPort[nWhichDecoder], Phil7114_PAL[nCounter * 2], &tmp)){ DEBUG0("\t\t(%x) = %2x",Phil7114_PAL[nCounter * 2],tmp); } else { DEBUG0("\t\t(%x) = NOT READ FROM I2C",Phil7114_PAL[nCounter * 2]); } } DEBUG0("Go to the pub!"); } else if (type==3) { if (ReadOneByte(0x42, index, &tmp)) DEBUG0("Read from Decoder (%x) = %x",index,tmp); else DEBUG0("Decoder Register %x not read",index); } else if (type==4) { DEBUG0("Writing to Decoder (%x) = %x",index,val); if (SendOneByte(0x42, index, val)) { if (ReadOneByte(0x42, index, &tmp)) { if (tmp==val) DEBUG0("Write to Decoder (%x) = %x (re-read)",index,val); else DEBUG0("Write to Decoder Register %x ko: correct=%x,read=%x",index,val,tmp); } } else DEBUG0("Decoder Register %x not read",index); } return tmp; }
int nullstring() { int i, x; i=0; while(1) { x=ReadOneByte(); //if(printMode==1)printf("%02X ", x);else; a_loc++; i_col++; result=x; stringBuf[i++]=x; if(!isprint(PeekOneByte()))break;} while(getMap(cur_position+i_col)==0x08) { x=ReadOneByte(); //if(printMode==1)printf("%02X ", x);else; stringBuf[i++]=x; a_loc++; i_col++; } stringBuf[i]=-1; return 1; }
int op() { int x; x=ReadOneByte(); if(printMode==1)printf("%02X", x);else; a_loc++; i_col++; result=x; return 1; }
int bytex() { int x; x=ReadOneByte(); m_byte=x; a_loc++; i_col++; result=x; return 1; }
static int AutomaticStartDetection() { char buffer[1000]; char envnum[2]; int fd = open("/dev/mtd0", O_RDONLY); lseek(fd,0xc0000+4,SEEK_SET ); ReadOneByte(fd, envnum); lseek(fd,0x160000+4,SEEK_SET ); ReadOneByte(fd, envnum+1); if(envnum[0] > envnum[1]) { lseek(fd,0xc0000,SEEK_SET ); Readn(fd, buffer, 1000); } else { lseek(fd,0x160000,SEEK_SET ); Readn(fd, buffer, 1000); } int offset = StrMatch(buffer,"appauto=",1000); if(offset == 0) { LOG_ERROR("not find appauto!"); PrintfRed("not find appauto!"); //return -2; } if(*(offset+buffer) != '1') { PrintfRed("appauto=%c",*(offset+buffer)); //return -1; } else { PrintfGreen("AutomaticStart"); } close(fd); return 0; }
void i2cMgr_t::Task() { if (IsError) { Init(); return; } uint8_t IEvt; switch (CmdToRead->State) { case CmdPending: if (SendStart() == I2C_OK) { // Send Start // Send Addr of needed type if (CmdToRead->DataToWrite.Length != 0) { SendAddrTX(); CmdToRead->State = CmdWritingAddrTX; } else { // nothing to write CmdToRead->State = CmdSucceded; StopAndGetNext(); } } // if start else { Uart.Printf("I2C Start failed\r"); CmdToRead->State = CmdFailed; StopAndGetNext(); } break; // ****** Writing Address with TX bit ******* case CmdWritingAddrTX: IEvt = CheckAddrTXSending(); // Check if ok if (IEvt == I2C_OK) { // Addr sent, write data if (CmdToRead->DataToWrite.Length == 1) { // Single byte to write WriteOneByte(); CmdToRead->State = CmdWritingOne; } else { // Many bytes to write WriteMany(); CmdToRead->State = CmdWritingMany; } } else if (IEvt != I2C_WAITING) { // Some error occured if (IEvt == I2C_ERR_TIMEOUT) Uart.Printf("I2C Addr TX timeout\r"); else if (IEvt == I2C_ERR_SLAVE_NACK) Uart.Printf("I2C NACK\r"); CmdToRead->State = CmdFailed; StopAndGetNext(); } break; // Otherwise still sending address case CmdWritingOne: // ****** Writing one byte ******* IEvt = CheckOneByteWriting(); if (IEvt == I2C_OK) { // Byte sent, check if reading needed if (CmdToRead->DataToRead.Length != 0) { // Send RepeatedStart if (SendStart() == I2C_OK) { SendAddrRX(); CmdToRead->State = CmdWritingAddrRX; } else { // Repeated start failed CmdToRead->State = CmdFailed; StopAndGetNext(); Uart.Printf("I2C OneByte RS failed\r"); } } else { // nothing to read CmdToRead->State = CmdSucceded; StopAndGetNext(); Uart.Printf("I2C OneByte no read\r"); } } // else if (IEvt != I2C_WAITING) { // Some error occured CmdToRead->State = CmdFailed; StopAndGetNext(); Uart.Printf("I2C OneByte timeout\r"); } break; // Otherwise still sending byte // ****** Writing Address with RX bit ******* case CmdWritingAddrRX: IEvt = CheckAddrRXSending(); // Check if ok if (IEvt == I2C_OK) { // Addr sent, read data if (CmdToRead->DataToRead.Length == 1) { // Single byte to read ReadOneByte(); CmdToRead->State = CmdReadingOne; } else { // Many bytes to read ReadMany(); CmdToRead->State = CmdReadingMany; } } else if (IEvt != I2C_WAITING) { // Some error occured CmdToRead->State = CmdFailed; StopAndGetNext(); Uart.Printf("I2C Addr RX timeout\r"); } break; // Otherwise still sending address case CmdReadingOne: // ****** Reading one byte ******* IEvt = CheckOneByteReading(); if (IEvt == I2C_OK) { // Byte read CmdToRead->State = CmdSucceded; GetNext(); // No need to send stop as it sent automatically } else if (IEvt != I2C_WAITING) { // Some error occured CmdToRead->State = CmdFailed; StopAndGetNext(); } break; // Otherwise still reading byte case CmdWritingMany: // ****** Writing many bytes ******* IEvt = CheckManyWriting(); if (IEvt == I2C_OK) { // Bytes sent, check if reading needed if (CmdToRead->DataToRead.Length != 0) { // Send RepeatedStart and address RX if (SendStart() == I2C_OK) { // Send Start SendAddrRX(); CmdToRead->State = CmdWritingAddrRX; } else { // Repeated start failed CmdToRead->State = CmdFailed; StopAndGetNext(); } } else { // nothing to read CmdToRead->State = CmdSucceded; StopAndGetNext(); } } // else if (IEvt != I2C_WAITING) { // Some error occured CmdToRead->State = CmdFailed; StopAndGetNext(); } break; // Otherwise still sending bytes case CmdReadingMany: // ****** Reading many bytes ******* IEvt = CheckManyReading(); if (IEvt == I2C_OK) { // Byte read CmdToRead->State = CmdSucceded; StopAndGetNext(); } else if (IEvt != I2C_WAITING) { // Some error occured CmdToRead->State = CmdFailed; StopAndGetNext(); Uart.Printf("I2C ReadMany timeout\r"); } break; // Otherwise still reading bytes case CmdFailed: case CmdSucceded: GetNext(); break; } // switch }
int InitDecoder7114(int nWhichDecoder, int nVideoSys, int nTuner, int nVBI) { u8 bSubAddr = 0x02; // u8 bData; int nCounter; DEBUG0("InitDecoder7114"); InitI2C(); if(DetectI2C(I2CPort[nWhichDecoder])==0) { DEBUG0("DetectI2C failed"); return -1; } if(nVideoSys==NTSC) { if(nWhichDecoder==Philips7114) { for(nCounter=0; nCounter<P7114_Count; nCounter++) { if(nVBI==0) { if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_NTSC[0][nCounter * 2], Phil7114_NTSC[0][nCounter * 2+1]) == 0) { DEBUG0("Failed to initialize Philips 7114(1) decoder"); return -1; } } else { if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_NTSC[1][nCounter * 2], Phil7114_NTSC[1][nCounter * 2+1])==0) { DEBUG0("Failed to initialize Philips 7114(1) decoder"); return -1; } } } if(nTuner==1) SendOneByte(I2CPort[nWhichDecoder], bSubAddr, 0xC0); DEBUG0("Initialized Philips 7114(1) to NTSC mode successfully!"); } else if(nWhichDecoder==Philips7114_40) { for(nCounter=0; nCounter<P7114_Count; nCounter++) { if(nVBI==0) { if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_NTSC[0][nCounter * 2], Phil7114_NTSC[0][nCounter * 2+1])==0) { DEBUG0("Failed to initialize Philips 7114(2) decoder!"); return -1; } } else { if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_NTSC[1][nCounter * 2], Phil7114_NTSC[1][nCounter * 2+1]) == 0) { DEBUG0("Failed to initialize Philips 7114(2) decoder!"); return -1; } } } WriteReg(0x3d4, 0xe1, ReadReg(0x3d4, 0xe1) | 0x0c); DEBUG0("Initialized Philips 7114(2) to NTSC mode successfully!"); } } else { if(nWhichDecoder==Philips7114) { DEBUG0("Initializing Philips 7114(1) to PAL mode ..."); for(nCounter=0; nCounter<P7114_Count; nCounter++) { if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_PAL[nCounter * 2], Phil7114_PAL[nCounter * 2+1])==0) { DEBUG0("Failed to initialize Philips 7114(1) decoder!"); return -1; } // // Read back registers to verify (R.Recalcati) // { u8 tmp; if (ReadOneByte(I2CPort[nWhichDecoder], Phil7114_PAL[nCounter * 2], &tmp)){ if (tmp!=Phil7114_PAL[nCounter * 2+1]){ if (Phil7114_PAL[nCounter * 2]!=0xf) // Is only readable, it doesn't accept modifying and so test fails DEBUG0("Problem configuring Philips 7114(1) at byte %x : read %x, correct %x",Phil7114_PAL[nCounter * 2], tmp, Phil7114_PAL[nCounter * 2+1]); //return -1; } // else // DEBUG0("\t\t(%x) = %x\t\tOK\n",Phil7114_PAL[nCounter * 2],tmp); } else{ DEBUG0("Problem configuring Philips 7114(1) at byte %x : not read",Phil7114_PAL[nCounter * 2]); return -1; } } } if(nVBI==1) SendOneByte(I2CPort[nWhichDecoder], 0x87, 0x01); if(nTuner==1) SendOneByte(I2CPort[nWhichDecoder], bSubAddr, 0xC0); DEBUG0("Initialized Philips 7114(1) to PAL mode successfully!"); } else if(nWhichDecoder==Philips7114_40) { for(nCounter=0; nCounter<P7114_Count; nCounter++) { if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_PAL[nCounter * 2], Phil7114_PAL[nCounter * 2+1])==0) { DEBUG0("Failed to initialize Philips 7114(2) decoder!"); return -1; } } WriteReg(0x3d4, 0xe1, ReadReg(0x3d4, 0xe1) | 0x0c); DEBUG0("Initialized Philips 7114(2) to PAL mode successfully!"); } } // // Alcuni test // { u8 tmp; if (ReadOneByte(0x42, 0x88, &tmp)) DEBUG0("SAA7114: Power Save Control (0x88) = %x",tmp); else DEBUG0("SAA7114: Power Save Control not read"); tmp |= 0x01; SendOneByte(0x42,0x88,tmp); if (ReadOneByte(0x42, 0x88, &tmp)) DEBUG0("SAA7114: Power Save Control (0x88) = %x",tmp); else DEBUG0("SAA7114: Power Save Control not read"); if (ReadOneByte(0x42, 0x8f, &tmp)) DEBUG0("SAA7114: Decoder byte test (0x8f) = %x",tmp); else { DEBUG0("SAA7114: Decoder byte test not read"); DEBUG0("SAA7114: Startup may be failed"); } if (ReadOneByte(0x42, 0x00, &tmp)) DEBUG0("SAA7114: Chip Version (0x00) = %x",tmp); else DEBUG0("SAA7114: Chip Version not read"); if (ReadOneByte(0x42, 0x1f, &tmp)) DEBUG0("SAA7114: Status Byte (0x1f) = %x",tmp); else DEBUG0("SAA7114: Decoder Status Byte not read"); } // // Necessario per avviare le task del SAA7114 // DEBUG0("SAA7114 Task Reset"); SendOneByte(0x42,0x88,0x58); udelay(100000); // 0.1 sec udelay(100000); // 0.1 sec udelay(100000); // 0.1 sec udelay(100000); // 0.1 sec udelay(100000); // 0.1 sec SendOneByte(0x42,0x88,0x78); DEBUG0("SAA7114 GOOO!!!"); return 0; }
static int mysocket_readonebyte(mysocket* const me) { return ReadOneByte(me->fd, me->buffer); }