Interfacing two codes together

I have a problem assembling two separate codes together, One of them is using a serial wireless module to control a DC motor from another Arduino which works pretty fine alone, the other one is a GPS module code to get data from it which works fine as well alone.
I want to mix both codes together but somehow when I do this, Arduino executes GPS code only and doesn't respond to the orders I give to the DC motor. I need your help to solve this programming problem.

DC motor code:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
const int pwm =  6; 
char x;

void setup() {
 
  pinMode(pwm, OUTPUT); 
  mySerial.begin(9600);
  Serial.begin(57600);
  analogWrite(pwm, 255); 
  }

void loop() {  
    
  if(mySerial.available()){
  x=mySerial.read();
  Serial.print(x);
  if (x=='a') {     
        
    analogWrite(pwm, 128);
 } 
  if (x=='b'){
    
    analogWrite(pwm, 255); 
  }    
   
  if (x=='c'){
    
    analogWrite(pwm, 0); 
  }    
   if (x=='d'){
    
    analogWrite(pwm, 0); 
  } 
  delay(2);                     
}
}

GPS module code:

/*
This Sketch will run with the SkyNav SKM53 GPS 
 RXD Arduino Pin 3
 TXD Arduino Pin 2
 RST Leave Open 
 NC Leave Open
 GND Ground
 VCC +5
 Make sure you download and save to your Arduino/Libraries folder TinyGPS.h
 and NewSoftSerial.h files.
*/

#include <TinyGPS.h>
#include <SoftwareSerial.h>

unsigned long fix_age;

SoftwareSerial GPS(2,3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;

void setup(){
  GPS.begin(9600);
  Serial.begin(9600);
}

void loop(){
  long lat, lon;
  unsigned long fix_age, time, date, speed, course;
  unsigned long chars;
  unsigned short sentences, failed_checksum;

  // retrieves +/- lat/long in 100000ths of a degree
  gps.get_position(&lat, &lon, &fix_age);

  getGPS();
  Serial.write(Serial.print("Latitude : "));
  Serial.write(Serial.print(LAT/100000,7));
  Serial.write(Serial.print(" :: Longitude : "));
  Serial.write(Serial.println(LON/100000,7));
}

void getGPS(){
  bool newdata = false;
  unsigned long start = millis();
  // Every 1 seconds we print an update
  while (millis() - start < 1000)
  {
    if (feedgps ()){
      newdata = true;
    }
  }
  if (newdata)
  {
    gpsdump(gps);
  }
}

bool feedgps(){
  while (GPS.available())
  {
    if (gps.encode(GPS.read()))
      return true;
  }
  return 0;
}

void gpsdump(TinyGPS &gps)
{
  //byte month, day, hour, minute, second, hundredths;
  gps.get_position(&lat, &lon);
  LAT = lat;
  LON = lon;
  {
    feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
  }
}

Both code together:

#include <SoftwareSerial.h>
#include <TinyGPS.h>


unsigned long fix_age;

SoftwareSerial mySerial(10, 11); // RX, TX
SoftwareSerial GPS(2,3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;
const int pwm =  6; 
char x;

void setup() {
 
  pinMode(pwm, OUTPUT); 
  mySerial.begin(9600);
  GPS.begin(57600);
  Serial.begin(57600);
  analogWrite(pwm, 255); 
  }

void loop() {  
   
 if(mySerial.available()){
  x=mySerial.read();
  Serial.print(x);
  if (x=='a') {     
        
    analogWrite(pwm, 128);
 } 
  if (x=='b'){
    
    analogWrite(pwm, 255); 
  }    
   
  if (x=='c'){
    
    analogWrite(pwm, 0); 
  }    
   if (x=='d'){
    
    analogWrite(pwm, 0); 
  } 
  delay(2);                     
  }
  long lat, lon;
  unsigned long fix_age, time, date, speed, course;
  unsigned long chars;
  unsigned short sentences, failed_checksum;

  // retrieves +/- lat/long in 100000ths of a degree
  gps.get_position(&lat, &lon, &fix_age);

  getGPS();  
  Serial.print("Latitude : ");
  Serial.print(LAT/100000,7);
  Serial.print(" :: Longitude : ");
  Serial.println(LON/100000,7);
  
}
void getGPS(){
  bool newdata = false;
  unsigned long start = millis();
  // Every 1 seconds we print an update
  while (millis() - start < 1000)
  {
    if (feedgps ()){
      newdata = true;
    }
  }
  if (newdata)
  {
    gpsdump(gps);
  }
}

bool feedgps(){
  while (GPS.available())
  {
    if (gps.encode(GPS.read()))
      return true;
  }
  return 0;
}

void gpsdump(TinyGPS &gps)
{
  //byte month, day, hour, minute, second, hundredths;
  gps.get_position(&lat, &lon);
  LAT = lat;
  LON = lon;
  {
    feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
  }
}

Your getGPS() function is blocking. Nothing will happen while that function twiddles it's thumbs waiting for GPS data.

While the GPS instance is listening, the mySerial instance isn't. So, data that arrives for the mySerial instance is discarded. Then, when the getGPS function finally ends, and loop() ends and starts again, there is no data in the mySerial instance's incoming buffer, so getGPS() is called again.

You really need multiple hardware serial ports to enable this code to work on one Arduino.

PaulS:
Your getGPS() function is blocking. Nothing will happen while that function twiddles it's thumbs waiting for GPS data.

While the GPS instance is listening, the mySerial instance isn't. So, data that arrives for the mySerial instance is discarded. Then, when the getGPS function finally ends, and loop() ends and starts again, there is no data in the mySerial instance's incoming buffer, so getGPS() is called again.

You really need multiple hardware serial ports to enable this code to work on one Arduino.

I'm sorry but I can't understand what do you mean by multiple hardware serial ports?

I'm sorry but I can't understand what do you mean by multiple hardware serial ports?

The UNO, for instance, has one hardware serial port. The Mega has 4 hardware serial ports.

Each hardware serial port uses interrupts (different for each port) to collect and buffer serial data.

Each software serial port uses interrupts (the same for all ports) to collect and buffer serial data

It is the fact that the same interrupt fires when data arrives for the software serial port that means that only one instance can listen at a time.

Bottom line: You need a Mega.

PaulS:

I'm sorry but I can't understand what do you mean by multiple hardware serial ports?

The UNO, for instance, has one hardware serial port. The Mega has 4 hardware serial ports.

Each hardware serial port uses interrupts (different for each port) to collect and buffer serial data.

Each software serial port uses interrupts (the same for all ports) to collect and buffer serial data

It is the fact that the same interrupt fires when data arrives for the software serial port that means that only one instance can listen at a time.

Bottom line: You need a Mega.

Oops, I see.
One last question, can I send and receive serial data wirelessly between Uno and Mega or do I need two new Megas?
Thanks for your help.
EDIT: Can I use the software serial in series, I mean to receive data from GPS once in the loop and then listen to mySerial?

One last question, can I send and receive serial data wirelessly between Uno and Mega or do I need two new Megas?

You can send data wirelessly between a Uno and a Mega.

Can I use the software serial in series, I mean to receive data from GPS once in the loop and then listen to mySerial?

Yes, but... If data arrives for the instance that is not listening, it will be discarded.