Exemplo n.º 1
0
void CWiiSaveCrypted::ExportAllSaves()
{
	std::string titleFolder = File::GetUserPath(D_WIIUSER_IDX) + "title";
	std::vector<u64> titles;
	u32 pathMask = 0x00010000;
	for (int i = 0; i < 8; ++i)
	{
		File::FSTEntry FST_Temp;
		std::string folder = StringFromFormat("%s/%08x/", titleFolder.c_str(), pathMask | i);
		File::ScanDirectoryTree(folder, FST_Temp);

		for (const File::FSTEntry& entry : FST_Temp.children)
		{
			if (entry.isDirectory)
			{
				u32 gameid;
				if (AsciiToHex(entry.virtualName, gameid))
				{
					std::string bannerPath = StringFromFormat("%s%08x/data/banner.bin", folder.c_str(), gameid);
					if (File::Exists(bannerPath))
					{
						u64 titleID = (((u64)pathMask | i) << 32) | gameid;
						titles.push_back(titleID);
					}
				}
			}
		}
	}
	SuccessAlertT("Found %x save files", (unsigned int) titles.size());
	for (const u64& title : titles)
	{
		CWiiSaveCrypted* exportSave = new CWiiSaveCrypted("", title);
		delete exportSave;
	}
}
Exemplo n.º 2
0
int ProcessCODFile(char * File, DWORD FileLen) {
	char * CurrentPos = File;
	char Label[40];
	DWORD Address;
	int Length;

	while ( CurrentPos < File + FileLen ) {
		if (*CurrentPos != '0') { return FALSE; }
		CurrentPos += 1;
		if (*CurrentPos != 'x') { return FALSE; }
		CurrentPos += 1;
	
		if (strchr(CurrentPos,',') - CurrentPos != 8) { return FALSE; }
		Address = AsciiToHex (CurrentPos);
		CurrentPos += 9;


		if (strchr(CurrentPos,'\r') == NULL) {
			Length = strchr(CurrentPos,'\n') - CurrentPos;
		} else {
			Length = strchr(CurrentPos,'\r') - CurrentPos;
			if (Length > (strchr(CurrentPos,'\n') - CurrentPos)) {
				Length = strchr(CurrentPos,'\n') - CurrentPos;
			}
		}

		if (Length > 40) { Length = 40; }
		memcpy(Label,CurrentPos,Length);
		Label[Length] = '\0';

		AddMapEntry (Address, Label);
		CurrentPos = strchr(CurrentPos,'\n') + 1;
	}
	return TRUE;
}
Exemplo n.º 3
0
void MemoryCheckDlg::OnOK(wxCommandEvent& event)
{
  wxString StartAddressString;
  wxString EndAddressString;
  if (m_radioAddress->GetValue())
  {
    StartAddressString = m_pEditAddress->GetLineText(0);
    EndAddressString = m_pEditAddress->GetLineText(0);
  }
  else
  {
    StartAddressString = m_pEditStartAddress->GetLineText(0);
    EndAddressString = m_pEditEndAddress->GetLineText(0);
  }
  bool OnRead = m_radioRead->GetValue() || m_radioReadWrite->GetValue();
  bool OnWrite = m_radioWrite->GetValue() || m_radioReadWrite->GetValue();
  bool Log = m_radioLog->GetValue() || m_radioBreakLog->GetValue();
  bool Break = m_radioBreak->GetValue() || m_radioBreakLog->GetValue();

  u32 StartAddress, EndAddress;
  bool EndAddressOK =
      EndAddressString.Len() && AsciiToHex(WxStrToStr(EndAddressString), EndAddress);

  if (AsciiToHex(WxStrToStr(StartAddressString), StartAddress) && (OnRead || OnWrite) &&
      (Log || Break))
  {
    TMemCheck MemCheck;

    if (!EndAddressOK)
      EndAddress = StartAddress;

    MemCheck.StartAddress = StartAddress;
    MemCheck.EndAddress = EndAddress;
    MemCheck.bRange = StartAddress != EndAddress;
    MemCheck.OnRead = OnRead;
    MemCheck.OnWrite = OnWrite;
    MemCheck.Log = Log;
    MemCheck.Break = Break;

    PowerPC::memchecks.Add(MemCheck);
    m_parent->NotifyUpdate();
    Close();
  }

  event.Skip();
}
Exemplo n.º 4
0
void MemoryCheckDlg::OnOK(wxCommandEvent& event)
{
	wxString StartAddressString;
	wxString EndAddressString;
	if (m_radioAddress->GetValue())
	{
		StartAddressString = m_pEditAddress->GetLineText(0);
		EndAddressString = m_pEditAddress->GetLineText(0);
	}
	else
	{
		StartAddressString = m_pEditStartAddress->GetLineText(0);
		EndAddressString = m_pEditEndAddress->GetLineText(0);
	}
	bool OnRead = m_radioRead->GetValue() || m_radioReadWrite->GetValue();
	bool OnWrite = m_radioWrite->GetValue() || m_radioReadWrite->GetValue();
	bool Log = m_radioLog->GetValue() || m_radioBreakLog->GetValue();
	bool Break = m_radioBreak->GetValue() || m_radioBreakLog->GetValue();

	u32 StartAddress, EndAddress;
	bool EndAddressOK =
		EndAddressString.Len() && AsciiToHex(WxStrToStr(EndAddressString), EndAddress);

	if (AsciiToHex(WxStrToStr(StartAddressString), StartAddress) && (OnRead || OnWrite) &&
		(Log || Break))
	{
		TMemCheck MemCheck;

		if (!EndAddressOK)
			EndAddress = StartAddress;

		MemCheck.start_address = StartAddress;
		MemCheck.end_address = EndAddress;
		MemCheck.is_ranged = StartAddress != EndAddress;
		MemCheck.is_break_on_read = OnRead;
		MemCheck.is_break_on_write = OnWrite;
		MemCheck.log_on_hit = Log;
		MemCheck.break_on_hit = Break;

		PowerPC::memchecks.Add(MemCheck);
		EndModal(wxID_OK);
	}

	event.Skip();
}
Exemplo n.º 5
0
void Add_BPoint ( void ) {
	char Title[10];

	GetWindowText(hRSPLocation,Title,sizeof(Title));
	if (!AddRSP_BPoint(AsciiToHex(Title),TRUE )) {
		SendMessage(hRSPLocation,EM_SETSEL,(WPARAM)0,(LPARAM)-1);
		SetFocus(hRSPLocation);	
	}
}
Exemplo n.º 6
0
void BreakPointDlg::OnOK(wxCommandEvent& event)
{
	wxString AddressString = m_pEditAddress->GetLineText(0);
	u32 Address = 0;
	if (AsciiToHex(AddressString.mb_str(), Address))
	{
		PowerPC::breakpoints.Add(Address);
		Parent->NotifyUpdate();
		Close();		
	}
	else
		PanicAlert("The address %s is invalid.", (const char *)AddressString.ToUTF8());

	event.Skip();
}
Exemplo n.º 7
0
void RefreshRSPCommands ( void ) {
	DWORD location, LinesUsed;
	char AsciiAddress[20];
	int count;

	if (InRSPCommandsWindow == FALSE) { return; }

	GetWindowText(hAddress,AsciiAddress,sizeof(AsciiAddress));
	location = AsciiToHex(AsciiAddress) & ~3;

	if (location > 0xF88) { location = 0xF88; }
	for (count = 0 ; count < RSP_MaxCommandLines; count += LinesUsed ){
		LinesUsed = DisplayRSPCommand ( location, count );
		location += 4;
	}
}
Exemplo n.º 8
0
void BreakPointDlg::OnOK(wxCommandEvent& event)
{
  wxString AddressString = m_pEditAddress->GetLineText(0);
  u32 Address = 0;
  if (AsciiToHex(WxStrToStr(AddressString), Address))
  {
    PowerPC::breakpoints.Add(Address);
    EndModal(wxID_OK);
  }
  else
  {
    WxUtils::ShowErrorDialog(
        wxString::Format(_("The address %s is invalid."), WxStrToStr(AddressString).c_str()));
  }

  event.Skip();
}
Exemplo n.º 9
0
//this is only my debug  tool
void Terminal(char cmd)
{  
  char h,l;
  unsigned char tmp;
  int i;
  struct list_entry *ptr;
  char *values;

  switch(cmd)
  {   
    case 'i':
      USBNStart();   
    break;
    // write to usb register
    case 'w':
      //UARTWrite("write to USB reg:");
      //USBNDEBUGPRINT("write to USB reg:");
      h = UARTGetChar();
      l = UARTGetChar();
      SendHex(AsciiToHex(h,l));
      tmp = AsciiToHex(h,l);
      UARTWrite("value:");
      h = UARTGetChar();
      l = UARTGetChar();
      SendHex(AsciiToHex(h,l));
      //USBNWrite(tmp,AsciiToHex(h,l));
      UARTWrite("result:");
      SendHex(USBNRead(tmp));
      UARTWrite("\r\n");
    break;

    // read from usb register
    case 'r':
      UARTWrite("read USB reg:");
      h = UARTGetChar();
      l = UARTGetChar();
      SendHex(AsciiToHex(h,l));
      UARTWrite("->");
      SendHex(USBNRead(AsciiToHex(h,l)));
      UARTWrite("\r\n");
    break;
    case 'h':
      UARTWrite("i usbn init procedure\r\n");
      UARTWrite("w write USBN Register <h,l>(address) <h,l> (value) e.g 05 00\r\n");
      UARTWrite("r read USBN Register <h,l> e.g. 02 ( RID)\r\n");
      UARTWrite("s show all USBN Registers\r\n");
      UARTWrite("b send test data from func to host\r\n");
      UARTWrite("d show descriptors\r\n");
    break;
    // show all registers
    case 's':
      for(i=0;i<=63;i++)
      {
        SendHex(i);
        UARTWrite("->");
        SendHex(USBNRead(i));
        UARTWrite("\r\n");
      }
    break;

    case 'd':
      USBNDebug("\r\nDescriptor List\r\n");
      ptr = DescriptorList;
      while(ptr != NULL) {
	values = (char*)ptr->data;
	SendHex(ptr->type);
	SendHex(ptr->len);
	SendHex(ptr->conf);
	SendHex(ptr->interf);
	USBNDebug("  ");
	for(i=0;i<ptr->len;i++)
	  SendHex(values[i]);
	USBNDebug("\r\n");

	ptr=ptr->next;
      }
    break;

    case 'b':
      UARTWrite("send test data from fifo1\r\n");
      int j,i;
      char stat;

      USBNWrite(TXC1,FLUSH);
      USBNWrite(TXD1,0x01);
      for(j=0;j<63;j++)
	USBNBurstWrite((unsigned char)j);

      USBNWrite(TXC1,TX_LAST+TX_EN);

      //USBNWrite(TXC1,TX_LAST+TX_EN+TX_TOGL);
    break;
    
    case 'p':
      USBNWrite(TXC1,TX_LAST+TX_EN);
    break;
    default:
      UARTWrite("unknown command\r\n");
  }
}
Exemplo n.º 10
0
int main(void)
{
	// init all needed services
	cli();
	timer_init();
	USART_init();
	ADC_init();
	sei(); 
	
	// set up enable port
	ENA_DDR = /*(1 << ENA_LED) |*/ (1 << ENA_PIN);
//	ENA_PORT = (1 << ENA_LED);
	
	// init condition is receiving
	driverReceive();
	
	// string, char and ascii buffers for serial comm.
	uint8_t read_buf = 0x00, ascii_bufh = 0x00, ascii_bufl = 0x00;
	char str_buf[10];
	
	// send own address on startup
	HexToAscii(str_buf, 3, own_addr);
	sendString(str_buf);
	sendString(EOM);
	
    while(1) {
		// check if there is something to be read (non blocking...)
		if ( USART_dataAvaliable() ){
			read_buf = 0x00;
			read_buf = USART_readByte();
			switch(MPPC_status){
				
				/* no start delimiter, awaits start delimiter */
				
				case IDLE:
				if (read_buf == '<'){
					MPPC_status = LISTENING;
				} else {
					MPPC_status = IDLE;
					sleep_ms(2);
				}
				break;
	
				/* received a start delimiter, awaits adress */
				
				case LISTENING:
				// check wether there are characters or ASCII numbers beeing send
				if ( ((read_buf >= '0') && (read_buf <= '9')) ||
				((read_buf >= 'A') && (read_buf <= 'F')) ) {
					// a ASCII number has been sent, we need another digit
					str_buf[0] = read_buf;
					str_buf[1] = USART_receiveByte();
					// convert both ascii numbers into a 'real' hex number
					read_buf = AsciiToHex(str_buf, 2);
					HexToAscii(str_buf, 3, read_buf);
				} else {
					// in this stage we need an address; if there are no numbers beeing sent, we are not interested anymore!
					MPPC_status = IDLE;
					break;
				}
				// We received an address, converted it to hex and now want to check, if it is our's
				if (read_buf == own_addr){
					MPPC_status = ADDRESSED;
					// SEL_LED on -> module has been selected + echo
					sendString(str_buf);
//					ENA_PORT&= ~(1 << ENA_LED);
					// echo in ASCII
				} else {
					MPPC_status = IDLE;
				}
				break;

				/* received it's own address, awaits command */
				
				case ADDRESSED:
				if (read_buf == '>'){	// stop delimiter
					MPPC_status = IDLE;
//					ENA_PORT |= (1 << ENA_LED);	// SEL_LED off -> module has been deselected
				} else {
					command_handler(read_buf);	// yet another switch/case stucture...
				}
				break;

			} // end switch

		} // end if
		
		// apply bias voltages
		setBiasVoltage();
	}
}
Exemplo n.º 11
0
void command_handler(uint8_t command){
	uint16_t wbuf;
	uint8_t bufh, bufl;
	float fbuf;
	char sbuf[10];
	switch(command){

		/* read temperature in human readable form */

		case READ_TEMP:
		sendByte(command);
		fbuf = getTemperature( ADC_read() );
		floatToString(fbuf, sbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* read temperature in raw ADC counts */
		case READ_TEMP_RAW:
		sendByte(command);
		wbuf = ADC_read();
		HexToAscii(sbuf, 4, wbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* set operational voltage @25°C */

		case SET_UBIAS_A:
		// echo the command
		sendByte(command);
		// waiting for a 4 character string
		receiveString(sbuf, 4);
		sendString(EOM);
		// set ADC register to given value
		wbuf = AsciiToHex(sbuf, 4);
		// max 0x7FF
		ADC_REG = 0x7FF & wbuf;
		break;

		/* set the temperature progression coefficient */

		case SET_COEFF:
		// echo...
		sendByte(command);
		// waiting for a 2 character string
		receiveString(sbuf, 2);
		sendString(EOM);
//		Vcoef = AsciiToHex(sbuf, 2);
		// max value = 0x7F
//		Vcoef &= 0x7F;		
		break;

		/* read the calculated adjusted operational voltage */

		case READ_UADJ_A:
		sendByte(command);
		// get temperature
		fbuf = getTemperature( ADC_read() );
		// calculate temperature adjusted voltage
		wbuf = calcAdjustedBiasVoltage(fbuf);
		// create string
		HexToAscii(sbuf, 5, wbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* read temperature coefficient */

		case READ_COEFF:
		sendByte(command);
		sendString(EOM);
		break;

		/* print help */

		case PRINT_HELP:
		sendByte(command);
		sendString("HW Version x.x SW Version 2.0");
		sendString(EOM);
		break;

		/* print sipm info of module */
		case SIPM_INFO:
		sendByte(command);
		sendString(EOM);
		break;
		
		case DAC_CAL:
		sendByte(command);
		sendString(EOM);
		break;
	
		default:
		MPPC_status = ADDRESSED;
	}


}
//------------------------------------------
void WebDS18B20Buses::InitWebServer(AsyncWebServer &server) {

  server.on("/getList", HTTP_GET, [this](AsyncWebServerRequest * request) {

    //check DS18B20Buses is initialized
    if (!_initialized) {
      request->send(400, F("text/html"), F("Buses not Initialized"));
      return;
    }

    //check bus param is there
    if (!request->hasParam(F("bus"))) {
      request->send(400, F("text/html"), F("Missing parameter"));
      return;
    }
    //convert busNumber
    int busNumber = request->getParam(F("bus"))->value().toInt();
    //check value found
    if ((busNumber == 0 && request->getParam(F("bus"))->value() != "0") || busNumber >= _nbOfBuses) {
      request->send(400, F("text/html"), F("Incorrect bus number"));
      return;
    }

#if ESP01_PLATFORM
    Serial.flush();
    delay(5);
    Serial.end();
#endif

    //list OneWire Temperature sensors
    request->send(200, F("text/json"), DS18B20Bus(_owBusesPins[busNumber][0], _owBusesPins[busNumber][1]).GetRomCodeListJSON());

#if ESP01_PLATFORM
    Serial.begin(SERIAL_SPEED);
#endif
  });

  server.on("/getTemp", HTTP_GET, [this](AsyncWebServerRequest * request) {

    //check DS18B20Buses is initialized
    if (!_initialized) {
      request->send(400, F("text/html"), F("Buses not Initialized"));
      return;
    }

    //check bus param
    if (!request->hasParam(F("bus"))) {
      request->send(400, F("text/html"), F("Missing parameter"));
      return;
    }
    //convert busNumber
    int busNumber = request->getParam(F("bus"))->value().toInt();
    //check value found
    if ((busNumber == 0 && request->getParam(F("bus"))->value() != "0") || busNumber >= _nbOfBuses) {
      request->send(400, F("text/html"), F("Incorrect bus number"));
      return;
    }


    //check ROMCode param
    if (!request->hasParam(F("ROMCode"))) {
      request->send(400, F("text/html"), F("Missing ROMCode"));
      return;
    }

    const char* ROMCodeA = request->getParam(F("ROMCode"))->value().c_str();

    if (!isROMCodeString(ROMCodeA)) {
      request->send(400, F("text/html"), F("Incorrect ROMCode"));
      return;
    }

    //Parse ROMCode
    byte romCode[8];
    for (byte i = 0; i < 8; i++) {
      romCode[i] = (AsciiToHex(ROMCodeA[i * 2]) * 0x10) + AsciiToHex(ROMCodeA[(i * 2) + 1]);
    }

#if ESP01_PLATFORM
    Serial.flush();
    delay(5);
    Serial.end();
#endif

    //Read Temperature
    String temperatureJSON = DS18B20Bus(_owBusesPins[busNumber][0], _owBusesPins[busNumber][1]).GetTempJSON(romCode);

    if (temperatureJSON.length() > 0) request->send(200, F("text/json"), temperatureJSON);
    else request->send(500, F("text/html"), F("Read sensor failed"));

#if ESP01_PLATFORM
    Serial.begin(SERIAL_SPEED);
#endif
  });

  server.on("/gs1", HTTP_GET, [this](AsyncWebServerRequest * request) {
    request->send(200, F("text/json"), GetStatus());
  });
}
Exemplo n.º 13
0
LRESULT CALLBACK RSP_Commands_Proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_INITDIALOG:
		RSPCommandshWnd = hDlg;
		RSP_Commands_Setup( hDlg );
		break;
	case WM_MOVE:
		//StoreCurrentWinPos("RSP Commands",hDlg);
		break;
	case WM_DRAWITEM:
		if (wParam == IDC_LIST)
		{
			DrawRSPCommand (lParam);
		}
		break;
	case WM_PAINT:
		Paint_RSP_Commands( hDlg );
		RedrawWindow(hScrlBar,NULL,NULL, RDW_INVALIDATE |RDW_ERASE);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_LIST:
			if (HIWORD(wParam) == LBN_DBLCLK )
			{
				LRESULT Selected;
				DWORD Location;

				Selected = SendMessage(hList, LB_GETCURSEL, 0, 0);
				Location = RSPCommandLine[Selected].Location;
				if (Location != (DWORD)-1)
				{
					if (CheckForRSPBPoint(Location))
					{
						RemoveRSPBreakPoint(Location);
					}
					else
					{
						AddRSP_BPoint(Location, FALSE);
					}
					RefreshRSPCommands();
				}
			}
			break;
		case IDC_ADDRESS:
			if (HIWORD(wParam) == EN_CHANGE )
			{
				RefreshRSPCommands();
			}
			break;
		case IDC_GO_BUTTON:
			SetRSPCommandToRunning();
			break;
		case IDC_BREAK_BUTTON:	
			SetRSPCommandToStepping();
			break;
		case IDC_STEP_BUTTON:			
			WaitingForStep = FALSE;
			break;
		/*case IDC_SKIP_BUTTON:
			SkipNextRSPOpCode = TRUE;
			WaitingFor_RSPStep   = FALSE;
			break;*/
		case IDC_BP_BUTTON:	
			if (DebugInfo.Enter_BPoint_Window != NULL)
			{
				DebugInfo.Enter_BPoint_Window();
			}
			break;
		case IDC_RSP_REGISTERS_BUTTON:
			Enter_RSP_Register_Window();
			break;
		case IDC_R4300I_DEBUGGER_BUTTON: 
			if (DebugInfo.Enter_R4300i_Commands_Window != NULL)
			{
				DebugInfo.Enter_R4300i_Commands_Window();
			}
			break;
		case IDC_R4300I_REGISTERS_BUTTON:
			if (DebugInfo.Enter_R4300i_Register_Window != NULL)
			{
				DebugInfo.Enter_R4300i_Register_Window();
			}
			break;
		case IDC_MEMORY_BUTTON:
			if (DebugInfo.Enter_Memory_Window != NULL)
			{
				DebugInfo.Enter_Memory_Window();
			}
			break;
		case IDCANCEL:			
			EndDialog( hDlg, IDCANCEL );
			break;
		}
		break;
	case WM_VSCROLL:
		if ((HWND)lParam == hScrlBar)
		{
			DWORD location;
			char Value[20];
			SCROLLINFO si;

			GetWindowText(hAddress,Value,sizeof(Value));
			location = AsciiToHex(Value) & ~3;

			switch (LOWORD(wParam))
			{
			case SB_THUMBTRACK:
				sprintf(Value,"%03X",((short int)HIWORD(wParam) << 2 ));
				SetWindowText(hAddress,Value);
				si.cbSize = sizeof(si);
				si.fMask  = SIF_POS;
				si.nPos   = (short int)HIWORD(wParam);
				SetScrollInfo(hScrlBar,SB_CTL,&si,TRUE);
				break;
			case SB_LINEDOWN:
				if (location < 0xF88)
				{
					sprintf(Value,"%03X",location + 0x4);
					SetWindowText(hAddress,Value);
					si.cbSize = sizeof(si);
					si.fMask  = SIF_POS;
					si.nPos   = ((location + 0x4) >> 2);
					SetScrollInfo(hScrlBar,SB_CTL,&si,TRUE);
				}
				else
				{
					sprintf(Value,"%03X",0xF88);
					SetWindowText(hAddress,Value);
					si.cbSize = sizeof(si);
					si.fMask  = SIF_POS;
					si.nPos   = (0xFFC >> 2);
					SetScrollInfo(hScrlBar,SB_CTL,&si,TRUE);
				}
				break;
			case SB_LINEUP:
				if (location > 0x4 )
				{
					sprintf(Value,"%03X",location - 0x4);
					SetWindowText(hAddress,Value);
					si.cbSize = sizeof(si);
					si.fMask  = SIF_POS;
					si.nPos   = ((location - 0x4) >> 2);
					SetScrollInfo(hScrlBar,SB_CTL,&si,TRUE);
				}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
		int input=6, output=6;
		char octal_buff[SIZE];
		char hexa_buff[SIZE];
		char ascii_buff[SIZE];
		char char_buff[SIZE];
		char buffer[SIZE];
		while (input > 5)
		{
			puts("-------------------------------------------------------");
			puts("\tSelect input:\t");
			puts("\t\t1 - Octal");
			puts("\t\t2 - Hexadecimal");
			puts("\t\t3 - ASCII Char");
			puts("\t\t4 - Char\n");
			puts("-------------------------------------------------------");
		
			printf("Choice Input: ");
			scanf("%d",&input);
			EmptyBuffer();
		}
		while (output > 5)
		{
			puts("-------------------------------------------------------");
			puts("\tSelect output:\t");
			puts("\t\t1 - Octal");
			puts("\t\t2 - Hexadecimal");
			puts("\t\t3 - ASCII Char");
			puts("\t\t4 - Char\n");
			puts("-------------------------------------------------------");
		
			printf("Choice Output: ");
			scanf("%d",&output);
			EmptyBuffer();
		
		}
		
		//Octal Input
		if(input ==1)
		{
			if(output == 1)
			{
				puts("Bitche I do not convert it !");
			}
			
			printf("Input octal: ");
			read(buffer);
			strcpy(octal_buff,buffer);
			if(output==2)
			{
				OcToHex(octal_buff,hexa_buff);
			}
			if(output==3)
			{
				OcToAscii(octal_buff,ascii_buff);
			}
			if(output==4)
			{
				OcToChar(octal_buff,char_buff);
			}
		}
		//Hexadecimal Input
		if(input == 2)
		{
			if(output==2)
			{
				puts("You want to suck ?");
			}
			
			printf("Input Hexadecimal: ");
			read(buffer);
			strcpy(hexa_buff,buffer);
			if(output==1)
			{
				HexToOct(hexa_buff,octal_buff);
			}
			if(output==3)
			{
				HexToAscii(hexa_buff,ascii_buff);
			}
			if(output==4)
			{
				HexToChar(hexa_buff,char_buff);
			}
		}
		//Ascii Input
		if(input == 3)
		{
			if(output==3)
			{
				puts("Kill yourself -->[-]");
			}
			
			printf("Input Ascii: ");
			read(buffer);
			strcpy(ascii_buff,buffer);
			
			if(output==1)
			{
				AsciiToOct(ascii_buff,octal_buff);
			}
			if(output==2)
			{
				AsciiToHex(ascii_buff,hexa_buff);
			}
			if(output==4)
			{
				AsciiToChar(ascii_buff,char_buff);
			}
		}
		//Char Input
		if(input == 4)
		{
			if(output==4)
			{
				puts("Exile you in /dev/null !!!");
			}
			
			printf("Input Char: ");
			read(buffer);
			strcpy(char_buff,buffer);
			
			if(output==1)
			{
				CharToOct(char_buff,octal_buff);
			}
			if(output==2)
			{
				CharToHex(char_buff,hexa_buff);
			}
			if(output==3)
			{
				CharToAscii(char_buff,ascii_buff);
			}
		}

	return 0;
}	
Exemplo n.º 15
0
int main()
{
unsigned char  buffer[INPUT_BUFFER];
unsigned char  *TmRegArea,*I2CArea,*TEMAC0Area,*TEMAC1Area,*TEMAC2Area,*BdArea,*ptr,EthControllerState=0;;
int            i,fd,Exit=0;
unsigned       rc,Address,Data,Offset,I2C_slave_address,tmp1;
struct termios oldt, newt;
int            ch;

tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;

newt.c_cc[VMIN] = 0;
newt.c_cc[VTIME] = 1;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );

fd = open("/dev/mem",O_RDWR|O_SYNC);
if(fd < 0){
  printf("Can't open /dev/mem\n");
  return 1;
  }
TmRegArea = (unsigned char *) mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x44000000);
if(TmRegArea == NULL){
  printf("Can't mmap\n");
  return 1;
  }
printf("\nTmRegArea %08X",TmRegArea);     //edo

TEMAC0Area = (unsigned char *) mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x47000000);
if(TEMAC0Area == NULL){
  printf("Can't mmap\n");
  return 1;
  }
printf("\nTEMAC0Area %08X",TEMAC0Area);     //edo

TEMAC1Area = (unsigned char *) mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x48000000);
if(TEMAC1Area == NULL){
  printf("Can't mmap\n");
  return 1;
  }
printf("\nTEMAC1Area %08X",TEMAC1Area);     //edo

TEMAC2Area = (unsigned char *) mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x49000000);
if(TEMAC2Area == NULL){
  printf("Can't mmap\n");
  return 1;
  }
printf("\nTEMAC2Area %08X",TEMAC2Area);     //edo

BdArea = (unsigned char *) mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x45000000);
if(BdArea == NULL){
  printf("Can't mmap\n");
  return 1;
  }
printf("\nBdArea %08X",BdArea);     //edo

printf("Tm>\n");
i = 0;
do{
/*----------------------------------------------------------------------------*/
/* Ethernet Rx frame management.                                              */
/*----------------------------------------------------------------------------*/
  if (EthControllerState != 0)
    Ethernet_GetRxFrameManagement();

  buffer[i] = getchar();
  if (buffer[i] != 0xFF){
    printf("%c",buffer[i]);
    if (buffer[i] == CHAR_LF){
      printf("\n");
      buffer[i] = 0;
      rc = 0;

      switch (buffer[0]){

/*----------------------------------------------------------------------------*/  
/* I2C                                                                        */
/*----------------------------------------------------------------------------*/ 
		case 'c':
			if (buffer[1]=='1')
			{
				*(unsigned *) (TEMAC0Area+0x0404) = 0xD0000000;
				*(unsigned *) (TEMAC0Area+0x0408) = 0xD0000000;
				*(unsigned *) (TEMAC0Area+0x0500) = 0x58;
				*(unsigned *) (TEMAC0Area+0x0508) = 0x1140;
				*(unsigned *) (TEMAC0Area+0x0504) = 0x4800;
				delay(0x1000000);
				while (( ((*(unsigned *) (TEMAC0Area+0x050C)) & 0x10000) != 0x10000));
				*(unsigned *) (TEMAC0Area+0x0508) = 0x1340;
				*(unsigned *) (TEMAC0Area+0x0504) = 0x4800;
				delay(0x1000000);
				while (( ((*(unsigned *) (TEMAC0Area+0x050C)) & 0x10000) != 0x10000));

				*(unsigned *) (TEMAC0Area+0x0504) = 0x18800;
				delay(0x1000000);
				while (( ((*(unsigned *) (TEMAC0Area+0x050C)) & 0x10000) != 0x10000));
				printf("\n\rStatus register: ");
				printf("%08X",((*(unsigned *) (TEMAC0Area+0x050C)) & 0xFFFF));

				*(unsigned *) (TEMAC0Area+0x0504) = 0x18800;
				delay(0x1000000);
				while (( ((*(unsigned *) (TEMAC0Area+0x050C)) & 0x10000) != 0x10000));
				printf("\n\rStatus register: ");
				printf("%08X",((*(unsigned *) (TEMAC0Area+0x050C)) & 0xFFFF));
				
				*(unsigned *) (TmRegArea+0x1004) = 0x1;
				*(unsigned *) (TmRegArea+0x1204) = 0x1;
				*(unsigned *) (TmRegArea+0x1304) = 0x1;
				*(unsigned *) (TmRegArea+0x0010) = 0x1;

				*(unsigned *) (TmRegArea+0xC000) = 0x00010203;
				*(unsigned *) (TmRegArea+0xC004) = 0x04060000;
				*(unsigned *) (TmRegArea+0xC008) = 0xFFFFFFFF;
				*(unsigned *) (TmRegArea+0xC00C) = 0xFFFF0000;
				*(unsigned *) (TmRegArea+0xC010) = 0x15;

			}
			else if (buffer[1]=='2')
			{
				
			}
			else if (buffer[1]=='3')
			{
				
			}
			else
				rc = ERROR_SYNTAX;
			break;

/*----------------------------------------------------------------------------*/
/* Ethernet statistics command.                                               */
/*----------------------------------------------------------------------------*/
        case 'e':
            break;

/*----------------------------------------------------------------------------*/
/* Ethernet controller initialization command.                                */
/*----------------------------------------------------------------------------*/
        case 'E':
            rc = EthernetControllerInit(TmRegArea,BdArea);
            EthControllerState = 1;
            break;

/*----------------------------------------------------------------------------*/
/* Help panel command.                                                        */
/*----------------------------------------------------------------------------*/
        case 'h':
            PrintHelpPanel();
            rc = 0;
            break;

/*----------------------------------------------------------------------------*/
/* Memory Dump.                                                               */
/*----------------------------------------------------------------------------*/
        case 'm':
          rc = 0;
          if (buffer[1] == 'd'){
            ptr = AsciiToHex(&buffer[2],&Address);
            Data = 0x40;
            if ((ptr != 0)&&(*ptr == ',')){
              ptr = AsciiToHex(++ptr,&Data);
              if (Data == 0)
                Data = 0x40;
              }
            if ((Address & 0xFFF00000) == 0x83C00000){
              Offset = Address - 0x83C00000;
              DumpData(TmRegArea+Offset,Address,Data);
              }
            else if ((Address & 0xFF000000) == 0x84000000){
              Offset = Address - 0x84000000;
              DumpData(BdArea+Offset,Address,Data);
              }
            }
          else if (buffer[1] == 'w'){
            ptr = AsciiToHex(&buffer[2],&Address);
            if ((ptr == 0)||(*ptr != ','))
              rc = ERROR_SYNTAX;
            else{
              ptr = AsciiToHex(++ptr,&Data);
              if ((Address & 0xFFF00000) == 0x83C00000){
                Address = Address - 0x83C00000;
                *(unsigned *)(TmRegArea+Address) = Data;
                }
              else if ((Address & 0xFF000000) == 0x84000000){
                Address = Address - 0x84000000;
                *(unsigned *)(BdArea+Address) = Data;
                }
              }
            }
          else
            rc = ERROR_SYNTAX;
          break;

/*----------------------------------------------------------------------------*/
/* Exit command.                                                              */
/*----------------------------------------------------------------------------*/
        case 'q':
            Exit = 1;
            rc = 0;
            break;

/*----------------------------------------------------------------------------*/
/* Error in case commands are not found.                                      */
/*----------------------------------------------------------------------------*/
        default:
          rc = ERROR_SYNTAX;
          printf("\n\rSyntax Error in last command");
          break;
        }

      i = 0;
      if (rc != 0)
        printf("\n\rERROR: %08X",rc);
      else
        printf("\n\rOK\n\r");
        
      printf("\n\rTm>");
      }
    else
      if (buffer[i] == CHAR_BS){
        if (i > 0)
          i--;
        }
    else
      if (++i > INPUT_BUFFER - 1)
        i = INPUT_BUFFER - 1;
    }
  } while (Exit == 0);

tcsetattr( STDIN_FILENO, TCSANOW, &oldt );

}