Most recent activity
-
ok, as promised some sample code to reproduce the second problem when throwing inside a switch statement.
without switch(), everything behaves as expected:
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); /* expect output === achieved output: -D0- -D1- CATCHED ... "simulate crash" -D8- -D9- */ function test( crit){ try{ const arr= new Uint32Array([1,2,3,4]); console.log('-D1-'); if( crit) throw new Error('simulate crash'); // such as thrown by testing Uint32Array.xyz console.log('-D2-'); } catch(err){ console.log('CATCHED',err); } console.log('-D8-'); } console.log('-D0-'); test('crash'); console.log('-D9-');
adding the switch() brings up some fancy extras:
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); function test( crit){ try{ const arr= new Uint32Array([1,2,3,4]); console.log('-C1-'); switch (crit) { case 'ok': console.log('-C2-C3-'); break; default: console.log('-C2-'); if( crit) throw new Error('simulate crash'); // such as thrown by testing Uint32Array.xyz console.log('-C3-'); break; } console.log('-C4-'); } catch(err){ console.log('CATCHED',err); } console.log('-C8-'); } console.log('-C0-'); test('crash'); console.log('-C9-');
expected output (tested on chrome):
-C0- -C1- -C2- CATCHED Error: simulate crash -C8- -C9-
achieved output:
-C0- -C1- -C2- -C4- * should not exist -C8- !!!UNCAUGHTEXCEPTION!!! ... "simulate crash" * should be CATCHED -C9-
-
Some more suspicious things...
This behaves as expected:
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); const arr= new Uint32Array([1,2,3,4]); console.log('-A1-'); if (!!arr.xyz) console.log('-A2-'); console.log('-A3-');
But this
process.on('uncaughtException',(err)=>{ console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); const arr= new Uint32Array([1,2,3,4]); console.log('-B1-'); try{ if (!!arr.xyz) console.log('-B2-'); console.log('-B3-'); } catch(e){ console.log('-B4-',e); } console.log('-B5-');
reports some strange error (see 2nd UNCAUGHTEXCEPTION message):
-B1- !!!UNCAUGHTEXCEPTION!!! Error { "msg": "Field or method \"xyz\" does not already exist, and can't create it on Uint32Array", "type": "Error", "stack": " at line 2 col 12\n if (!!arr.xyz) console.log('-B2-');\n ^\n" } !!!UNCAUGHTEXCEPTION!!! SyntaxError { "msg": "Got catch expected EOF", "type": "SyntaxError", "stack": " at line 1 col 1\ncatch(e){\n^\n" } -B5-
Maybe another topic relates to this: i think that exceptions got lost without any notice when they occured inside a switch statement. i try to come up with some test code for this, too...
-
just a "picture" without words;)
process.on('uncaughtException', function(err) { console.log('!!!UNCAUGHTEXCEPTION!!!',err); }); const arr= new Uint32Array([1,2,3,4]); // or any other ArrayView console.log('test E...'); if (!E.xyz) console.log('E ok'); // works as expected console.log('test arr...'); if (!arr.xyz) console.log('arr ok'); // throws exception - not as expected console.log('done all ok');
EspruinoWIFI 1v96
-
- Take 4bpp (?) data a chunk at a time and unpack it into another buffer with 16 bits.
- Kick off DMA from that buffer
- Take another 4bpp (?) data chunk and unpack it into another buffer with 16 bits.
- Wait for DMA to finish
- Goto 2
As already mentioned - to do a full DMA setup per 16bit is much too slow (because the necessary procedure for setting up, starting and then stopping dma/spi). so i tried it with double buffer (DMA) feature. basically this works nice, but it has some drawbacks:
- with 16bit payload at top speed of 12.5Mbaud we have to feed new data every 1,28us to the DMA buffers; on the EspruinoWIFI (100MHz, 1-2 cycles per instruction) this counts as ~85 instructions. well, it seems that some IRQ out there (timer?) blocks my feeder for longer than that.
- increasing the buffer by 10x (e.g. 10x16 bit) works perfect (6x16 does not), but... in this case we have to waste a lot of (blocking) cpu cycles while waiting for a buffer to get free for next data.
- in fact - a fast palette lookup (i am not talking about E.mapInPlace) - saves a lot of CPU load 'cause it's much faster than the SPI. it's not my intention to waste then these savings with blocking waits for background DMA ;)
the best way of pressing paletted image data seems to me:
- unpalette graphics data (typ. 1/2/4bpp into 16bpp) chunk by chunk with a really fast lookup method
- each chunk as huge as possible (typ. 2..20 kbyte)
- this allows parallel processing of JS code while the last chunk goes over the line
some simple measurements of optimized asm 1/2/4 into 16bit lookup functions show that unpaletting is typ. 3..10 times faster than the net SPI transmission time. e.g. on 10k pixels @1bpp we bring >11ms (12.80-1.44) of cpu time back to JS compared to any blocking method.
test_map1to16 1000 pxls 0.43 1.28 2.9x test_map1to16 10000 pxls 1.44 12.80 8.9x test_map2to16 1000 pxls 0.44 1.28 2.9x test_map2to16 10000 pxls 1.56 12.80 8.2x test_map4to16 1000 pxls 0.48 1.28 2.7x test_map4to16 10000 pxls 1.87 12.80 6.8x
- Take 4bpp (?) data a chunk at a time and unpack it into another buffer with 16 bits.
-
It's tested for the EspruinoWIFI based on STM32F411. Adaption to another board should be quite easy, as long as it is a ARM processor. I think changing the xxx_BASE constants should be all do be done.
Pleae consider, that you will prefer the double buffer mode (DBM) for an audio codec. This feature is not used in the current lib. -
inlining the peek/poke
there seems to sit a little bug - this does not work:
const a = [<address>,<value>]; poke32( a[0], a[1]);
this is fine:
const a = [<address>,<value>]; const x= a[0]; const y= a[1]; poke32( x,y);
this is fine, too:
const a = [<address>,<value>]; poke32( a[0]|0,a[1]|0);
another - similar? - flaw i have seen:
const SPI_CR2_TXDMAEN = 0x0002; function rset16( addr, mask){ "compiled"; console.log( addr.toString(16), mask.toString(16)); // debug output poke16( addr, peek16( addr) | mask); } function foo( qctl, buf_ptr, byte_cnt) { "compiled"; const SPI_CR1= ...; ... rset16( SPI_CR1+4, SPI_CR2_TXDMAEN); }
generates this output: 40013004 [object Object]
expected output: 40013004 2
to achieve the expected behaviour, i have either to
- remove "compiled" directive from foo, or
- do rset16( SPI_CR1+4, SPI_CR2_TXDMAEN|0);
- remove "compiled" directive from foo, or
-
@Gordon: what's the recommended alternative for espruino wifi (when BT is not an option) at the moment? thx!