16
16
SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART. */
17
17
18
18
// Programming metrics
19
- let postResetDelay = null ; //Delay after reset and before serial stream; Post-Reset Delay is set by loadPropeller()
20
- let autoAdjust = 30 ; //Amount to adjust postResetDelay upon each failure
21
19
let txData ; //Data to transmit to the Propeller (size/contents created later)
22
20
23
21
const defaultClockSpeed = 80000000 ;
24
22
const defaultClockMode = 0x6F ;
25
23
const maxDataSize = 1392 ; //Max data packet size (for packets sent to running Micro Boot Loader)
26
24
const mblRespSize = 8 ; //Size of Micro Boot Loader Response (and Expected) array buffers
25
+ const postResetDelay = 100 ; //Delay after reset and before serial stream
27
26
28
27
// propComm stage values
29
28
const sgIdle = - 1 ;
@@ -137,8 +136,6 @@ function loadPropeller(sock, portPath, action, payload, debug) {
137
136
let originalBaudrate ;
138
137
139
138
if ( port . isWired ) {
140
- //Set postResetDelay based on platform; ideal Post-Reset Delay = 100 ms; adjust downward according to typically-busy operating systems
141
- postResetDelay = ( ( platform === pfWin ) && ( ! experimentalTiming ) ) ? 60 : 100 ;
142
139
if ( port . connId ) {
143
140
// Connection exists, prep to reuse it
144
141
originalBaudrate = port . baud ;
@@ -150,8 +147,6 @@ function loadPropeller(sock, portPath, action, payload, debug) {
150
147
connect = function ( ) { return openPort ( sock , portPath , initialBaudrate , "programming" ) }
151
148
}
152
149
} else {
153
- //Nearly-clear the postResetDelay (it's controlled by wireless device)
154
- postResetDelay = 1 ;
155
150
//TODO Retrieve actual current baudrate
156
151
originalBaudrate = initialBaudrate ;
157
152
updatePort ( port , { mode : "programming" , bSocket : sock } ) ;
@@ -287,27 +282,22 @@ function talkToProp(sock, port, binImage, toEEPROM) {
287
282
288
283
function sendMBL ( ) {
289
284
return new Promise ( function ( resolve , reject ) {
290
-
291
- function txmit ( ) {
292
- //Prep for expected packetID:transmissionId response (Micro-Boot-Loader's "Ready" signal)
293
- propComm . mblEPacketId [ 0 ] = packetId ;
294
- propComm . mblETransId [ 0 ] = 0 ; //MBL transmission's Id is always 0
295
- //Send Micro Boot Loader package and get response; if wired port, unpause (may be auto-paused by incoming data error); wireless ports, carry on immediately
296
- log ( "Transmitting Micro Boot Loader package" , mDeep ) ;
297
- send ( port , txData , true )
298
- . then ( function ( ) { if ( port . isWired ) { return unPause ( port ) } } ) //Unpause port (if wired)
299
- . then ( function ( ) { return propComm . response } ) //Wait for response (may timeout with rejection)
300
- . then ( function ( ) { log ( notice ( 000 , [ "Found Propeller" ] ) , mUser + mDbug , sock ) } ) //Succeeded!
301
- . then ( function ( ) { return resolve ( ) } )
302
- . catch ( function ( e ) { return reject ( e ) } ) ; //Failed!
303
- }
304
-
305
- if ( ! experimentalTiming ) {
306
- setTimeout ( txmit , postResetDelay ) ;
307
- } else {
285
+ //If wired, actively wait before transmitting Micro Boot Loader; active (vs. passive) wait prevents extended delays in CrOS v67+
286
+ if ( port . isWired ) {
287
+ log ( "Waiting " + Math . trunc ( postResetDelay ) + " ms" , mDeep ) ;
308
288
wait ( postResetDelay ) ;
309
- txmit ( ) ;
310
289
}
290
+ //Prep for expected packetID:transmissionId response (Micro-Boot-Loader's "Ready" signal)
291
+ propComm . mblEPacketId [ 0 ] = packetId ;
292
+ propComm . mblETransId [ 0 ] = 0 ; //MBL transmission's Id is always 0
293
+ //Send Micro Boot Loader package and get response; if wired port, unpause (may be auto-paused by incoming data error); wireless ports, carry on immediately
294
+ log ( "Transmitting Micro Boot Loader package" , mDeep ) ;
295
+ send ( port , txData , true )
296
+ . then ( function ( ) { if ( port . isWired ) { return unPause ( port ) } } ) //Unpause port (if wired)
297
+ . then ( function ( ) { return propComm . response } ) //Wait for response (may timeout with rejection)
298
+ . then ( function ( ) { log ( notice ( 000 , [ "Found Propeller" ] ) , mUser + mDbug , sock ) } ) //Succeeded!
299
+ . then ( function ( ) { return resolve ( ) } )
300
+ . catch ( function ( e ) { return reject ( e ) } ) ; //Failed!
311
301
} ) ;
312
302
}
313
303
@@ -317,20 +307,9 @@ function talkToProp(sock, port, binImage, toEEPROM) {
317
307
. then ( function ( ) { if ( port . isWired ) { return setControl ( port , { dtr : false } ) ; } } ) // Start Propeller Reset Signal
318
308
. then ( function ( ) { if ( port . isWired ) { return flush ( port ) ; } } ) // Flush transmit/receive buffers (during Propeller reset)
319
309
. then ( function ( ) { if ( port . isWired ) { return setControl ( port , { dtr : true } ) ; } } ) // End Propeller Reset
320
- . then ( function ( ) { if ( port . isWired ) { log ( "Waiting " + Math . trunc ( postResetDelay ) + " ms" , mDeep ) ; } } ) // Wait post-reset-delay and...
321
310
. then ( function ( ) { return sendMBL ( ) ; } ) //send comm package, including Micro Boot Loader; verify receipt
322
- . catch ( function ( e ) { //Error!
323
- if ( noticeCode ( e . message ) === nePropellerNotFound && -- attempts ) { // Retry (if "Propeller not found" and more attempts available)
324
- log ( "Propeller not found: retrying..." , mDeep ) ;
325
- if ( platform === pfWin ) { // If Windows platform,
326
- postResetDelay = Math . max ( postResetDelay - autoAdjust , 1 ) ; // Shorten Post Reset Delay upon every attempt (min 1)
327
- }
328
- return sendLoader ( ) ; // note: sendLoader does not return execution below (promises continue at next .then/.catch)
329
- }
330
- return reject ( e ) ; // Or if other error (or out of retry attempts), reject with message
331
- } )
332
- . then ( function ( ) { return resolve ( ) ; } ) //Propeller found? Resolve
333
- . catch ( function ( e ) { return reject ( e ) ; } ) //Error! Reject with message
311
+ . then ( function ( ) { return resolve ( ) ; } ) //Propeller found? Resolve
312
+ . catch ( function ( e ) { return reject ( e ) ; } ) //Error! Reject with message
334
313
} ) ;
335
314
}
336
315
@@ -456,9 +435,6 @@ function talkToProp(sock, port, binImage, toEEPROM) {
456
435
//=((10 [bits per byte] * [max packet size]) / final baud rate) * 1,000 [to scale ms to integer] + 1 [to always round up] + 1500 or 250 [Network or Rx hardware to OS slack time]
457
436
var userDeliveryTime = Math . trunc ( ( ( 10 * maxDataSize ) / finalBaudrate ) * 1000 + 1 + ( ( port . isWired ) ? 250 : 1500 ) ) ;
458
437
459
- //Set for limited retry attempts (multiple when wired; potentially trying various post-reset timing)
460
- var attempts = ( port . isWired ) ? ( ( platform === pfWin ) ? Math . max ( Math . trunc ( postResetDelay / autoAdjust ) , 1 ) : 1 ) : 1 ;
461
-
462
438
Promise . resolve ( )
463
439
. then ( function ( ) { return sendLoader ( ) ; } ) //Get Propeller's attention and send initial application (Micro Boot Loader)
464
440
. then ( function ( ) { return changeBaudrate ( port , finalBaudrate ) ; } ) //Bump up to faster finalBaudrate
0 commit comments