ArduinoAm29F010

Changeset

30:c3fae781613c
2015-08-23 Paul Boddie raw files shortlog changelog graph Increased the input buffer size, propagated the number of read/expected characters so that erase and program sequences have their command lengths described.
ArduinoAm29F010.cpp (file)
     1.1 --- a/ArduinoAm29F010.cpp	Sun Aug 09 19:51:29 2015 +0200
     1.2 +++ b/ArduinoAm29F010.cpp	Sun Aug 23 19:20:03 2015 +0200
     1.3 @@ -21,7 +21,7 @@
     1.4            DQ0 = 7, DQ1 = 6, DQ2 = 5, DQ3 = 4,
     1.5            DQ4 = 8, DQ5 = 9, DQ6 = 10, DQ7 = 11;
     1.6  
     1.7 -const int BUFSIZE = 8;
     1.8 +const int BUFSIZE = 9;
     1.9  char inbuffer[BUFSIZE];
    1.10  int nread = 0;
    1.11  
    1.12 @@ -160,7 +160,7 @@
    1.13      digitalWrite(CE, HIGH);
    1.14  }
    1.15  
    1.16 -int readCommand(const char buffer[])
    1.17 +int readCommand(const char buffer[], int nread)
    1.18  {
    1.19      int high, low, i;
    1.20  
    1.21 @@ -181,7 +181,7 @@
    1.22      return readOp(high, low);
    1.23  }
    1.24  
    1.25 -bool writeCommand(const char buffer[])
    1.26 +bool writeCommand(const char buffer[], int nread)
    1.27  {
    1.28      int high, low, data, i;
    1.29  
    1.30 @@ -234,7 +234,7 @@
    1.31  {
    1.32      for (int i = 0; i < 5; i++)
    1.33      {
    1.34 -        writeCommand(ERASE[i]);
    1.35 +        writeCommand(ERASE[i], 7);
    1.36      }
    1.37      writeOp(0x55, 0x55, 0x30);
    1.38      return waitForCompletion(0, 0, 0xff);
    1.39 @@ -251,7 +251,7 @@
    1.40  
    1.41      for (int i = 0; i < 5; i++)
    1.42      {
    1.43 -        writeCommand(ERASE[i]);
    1.44 +        writeCommand(ERASE[i], 7);
    1.45      }
    1.46      writeOp(high, 0, 0x30);
    1.47  
    1.48 @@ -260,7 +260,7 @@
    1.49      return waitForCompletion(high, 0, 0xff);
    1.50  }
    1.51  
    1.52 -bool program(const char buffer[])
    1.53 +bool program(const char buffer[], int nread)
    1.54  {
    1.55      int high, low, data, i;
    1.56  
    1.57 @@ -281,7 +281,7 @@
    1.58  
    1.59      for (int i = 0; i < 3; i++)
    1.60      {
    1.61 -        writeCommand(PROGRAM[i]);
    1.62 +        writeCommand(PROGRAM[i], 7);
    1.63      }
    1.64      writeOp(high, low, data);
    1.65  
    1.66 @@ -325,7 +325,7 @@
    1.67              case 'R':
    1.68              if (nread >= 5)
    1.69              {
    1.70 -                Serial.println(readCommand(inbuffer), HEX);
    1.71 +                Serial.println(readCommand(inbuffer, nread), HEX);
    1.72                  nread = 0;
    1.73              }
    1.74              break;
    1.75 @@ -333,7 +333,7 @@
    1.76              case 'W':
    1.77              if (nread >= 7)
    1.78              {
    1.79 -                if (writeCommand(inbuffer))
    1.80 +                if (writeCommand(inbuffer, nread))
    1.81                      Serial.println("W");
    1.82                  else
    1.83                      Serial.println("C");
    1.84 @@ -363,7 +363,7 @@
    1.85              case 'P':
    1.86              if (nread >= 7)
    1.87              {
    1.88 -                if (program(inbuffer))
    1.89 +                if (program(inbuffer, nread))
    1.90                      Serial.println("P");
    1.91                  else
    1.92                      Serial.println("C");