Permalink
Browse files

maybe soon?

Now the code results in no errors being thrown anywhere!

It still doesn't work, and I suspect there is an infinite loop or
something somewhere, but yeah. I should finish this up by the end of the
weekend.
  • Loading branch information...
1 parent 67f1349 commit 295fe8ca581d11781d2f311a96781822d1be6d6c Gene Jones committed Oct 4, 2013
Showing with 35 additions and 36 deletions.
  1. +30 −31 flashChip.c
  2. +5 −5 server.c
View
@@ -50,7 +50,6 @@ agent.on("programModeBegin", function(t){
class ArduinoProgrammer {
resetPin = hardware.pin7;
- serial = hardware.uart12.configure(PROGRAM_SERIAL_SPEED, 8, PARITY_NONE, 1, NO_CTSRTS);
statusLEDPin = hardware.pin8;
progLEDPin = hardware.pin9;
@@ -62,6 +61,8 @@ class ArduinoProgrammer {
hardware.pin8.configure(DIGITAL_OUT) //this will be our LED pin
hardware.pin9.configure(DIGITAL_OUT) //this will be our LED pin
+ hardware.uart12.configure(PROGRAM_SERIAL_SPEED, 8, PARITY_NONE, 1, NO_CTSRTS); //setup the serial lines...
+
//blank out the LEDs to start with...
progLEDPin.write(0);
statusLEDPin.write(0);
@@ -74,18 +75,22 @@ class ArduinoProgrammer {
resetAVR();
enable_programming();
//verify_signature();
- program();
+ requestFirstChunk();
server.log("Successfully programmed AVR with new .hex file");
}
catch (error) {
server.log("ERROR. Programming failed due to "+error);
attempt++;
if (attempt<3){
- program(); //attempt to program again, but only if this is our second or less attempt
+ requestFirstChunk(); //attempt to program again, but only if this is our second or less attempt
}
}
}
+ function requestFirstChunk(){
+ agent.send("next_chunk", "please");
+ }
+
function resetAVR(){
progLEDPin.write(1); //let the user know a program is in progress
resetPin.write(0); //pull pin7 low to reset the system
@@ -94,22 +99,9 @@ class ArduinoProgrammer {
imp.sleep(0.05); //wait 50ms to allow the AVR to wake back up
}
- function send_command(){
- serial.write(command + STK_CRC_EOP);
- serial.flush();
- local b = serial.read();
- response = blob(1);
- while( b!= STK_OK){
- if(b >= 0){
- response.writen(b);
- }
- local b = serial.read();
- }
- return response;
- }
function enable_programming(){
- response = send_command(PROG_ENABLE);
+ response = send_command([STK_ENTER_PROGMODE]);
if (response[2] != STK_OK){
//we expect the third byte recieved to be the same as the second byte we sent; if not, we are not in sync
throw "Error in programming enable: not in sync";
@@ -118,7 +110,7 @@ class ArduinoProgrammer {
}
function exit_programming(){
- response = send_command(STK_LEAVE_PROGMODE);
+ response = send_command([STK_LEAVE_PROGMODE]);
if (response[2] != STK_OK){
//we expect the third byte recieved to be the same as the second byte we sent; if not, we are not in sync
throw "Error in programming enable: not in sync";
@@ -130,7 +122,7 @@ class ArduinoProgrammer {
function program(chunk){
statusLEDPin.write(1);
local finished = 0;
- for (local i=0; i<len(chunk); i++){
+ for (local i=0; i<chunk.len(); i++){
local progResult = progLine(chunk[i]);
if(progResult == "exitProgMode"){
finished = 1;
@@ -146,26 +138,33 @@ class ArduinoProgrammer {
}
}
- function verify_signature(){
- //we need to see if the device signature is correct
- //we DO NOT want to program an ATTiny8 as if it was an ATMega328
- observed_sig = send_command(SIGNATURE_CHECK);
- observed_sig = observed_sig.slice(0, 3);
- if (target.SIG != observed_sig){
- throw "Target device signature was incorrect. Expected "+target.SIG+" but recieved "+observed_sig;
+ function send_command(command_array){
+ foreach (command in command_array){
+ hardware.uart12.write(command);
}
- return 1;
- //everything checked out!
+ hardware.uart12.write(STK_CRC_EOP);
+ hardware.uart12.flush();
+ local b = hardware.uart12.read();
+ local response = blob(1);
+ while( b!= STK_OK){
+ if(b >= 0){
+ response.writen(b);
+ }
+ local b = hardware.uart12.read();
+ }
+ return response;
}
+
+
function progLine(hexLine){
//program each individual line of the code with this!
if (hexLine.recordType = '0'){
//record is data, program chip...
- send_command(STK_LOAD_ADDRESS + hexLine.address);
+ send_command([STK_LOAD_ADDRESS, hexLine.address]);
//#55#00#00#20 STK_LOAD_ADDRESS, 0װ000(address location)
//now write the data to the address...
- send_command(STK_PROGRAM_PAGE + byteCount + 'F' + hexLine.dataPayload);
- //STK_PROGRAM_PAGE, 0װ080 (page size), ҆Ҩflash memory), data bytesŬSYNC_CRC_EOP
+ send_command([STK_PROGRAM_PAGE, byteCount, 'F', hexLine.dataPayload]);
+ //STK_PROGRAM_PAGE, 0װ080 (page size), ҆Ҩflash memory), data bytes SYNC_CRC_EOP
imp.sleep(0.045); //wait 4.5ms until the flash location has been written to
return 1;
}
View
@@ -61,15 +61,15 @@ function splitHex(hexString){
programPosition <- 0;
function chunkLines(t){
server.log("chunk requested by device");
- local chunk_size = 64; //64 lines at a time works out to be 1024 data bytes at a time, plus addresses...
- if (len(programData) > programPosition + chunk_size){
+ local chunk_size = 64; //64 lines at a time works out to be 1024 data bytes at a time, plus addresses and overhead...still plenty of space in RAM
+ if ( programData.len() > programPosition + chunk_size){
local chunkTable = [];
for (local i=0; i < programPosition + chunk_size; i++){
- chunkTable[i] = programData[i + programPosition]
+ chunkTable.append(programData[i + programPosition]);
}
device.send("next_chunk", chunkTable);
programPosition = programPosition + chunk_size;
- server.log(format("sent chunk, at position %s of %s" %programPosition, len(programData)));
+ server.log(format("sent chunk, at position %3d of %3d" programPosition, programData.len()));
}
else {
//we don't have a full 64 lines, so give the remaining lines as our chunk
@@ -131,7 +131,7 @@ function hexItUp(raw_hex_file){
server.log("hexItUp");
foreach (i,raw_line in raw_lines){
local result = understandHex(raw_line);
- server.log(format("parsed line %04d", i));
+ //server.log(format("parsed line %04d", i));
programData.append(result);
}
//instruct the device to begin downloading our data...

0 comments on commit 295fe8c

Please sign in to comment.