pxt-common-packages 9.3.6 → 9.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P133845(s) {
59
+ function _main___P133949(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___134086 = (undefined);
70
- globals._pollEventQueue___134099 = (undefined);
69
+ globals._intervals___134190 = (undefined);
70
+ globals._pollEventQueue___134203 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P133845.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"colorbuffer.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P133845.continuations = [ ]
75
+ _main___P133949.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"colorbuffer.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P133949.continuations = [ ]
77
77
 
78
- function _main___P133845_mk(s) {
78
+ function _main___P133949_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P133845, depth: s.depth + 1,
81
+ parent: s, fn: _main___P133949, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P133845_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P133845
91
+ return _main___P133949
92
92
  })
@@ -41,7 +41,9 @@ typedef Buffer Sound;
41
41
  typedef struct worker *worker_t;
42
42
  worker_t worker_alloc(const char *id, uint32_t stack_size);
43
43
  int worker_run(worker_t w, TaskFunction_t fn, void *arg);
44
+ int worker_run_wait(worker_t w, TaskFunction_t fn, void *arg);
44
45
  void worker_set_idle(worker_t w, TaskFunction_t fn, void *arg);
46
+ extern worker_t fg_worker;
45
47
 
46
48
  void memInfo();
47
49
 
@@ -240,41 +240,66 @@ int HF2::handlePkt(int sz) {
240
240
  return sendResponse(0);
241
241
  }
242
242
 
243
- void HF2::sendBuffer(uint8_t flag, const void *data, unsigned size, uint32_t prepend) {
244
- if (!connected)
245
- return;
243
+ struct BufferEntry {
244
+ unsigned size;
245
+ uint8_t flag;
246
+ uint8_t data[0];
247
+ };
246
248
 
247
- uint32_t buf[64 / 4]; // aligned
249
+ static void send_buffer_core(void *ent_) {
250
+ auto ent = (BufferEntry *)ent_;
248
251
 
249
- if (prepend + 1)
250
- size += 4;
252
+ uint32_t buf[64 / 4]; // aligned
253
+ auto size = ent->size;
254
+ auto data = ent->data;
251
255
 
252
- while (connected && size > 0) {
256
+ while (hf2.connected && size > 0) {
253
257
  memset(buf + 1, 0, 60);
254
258
  int s = 63;
255
259
  if (size <= 63) {
256
260
  s = size;
257
- buf[0] = flag;
261
+ buf[0] = ent->flag;
258
262
  } else {
259
- buf[0] = flag == HF2_FLAG_CMDPKT_LAST ? HF2_FLAG_CMDPKT_BODY : flag;
263
+ buf[0] = ent->flag == HF2_FLAG_CMDPKT_LAST ? HF2_FLAG_CMDPKT_BODY : ent->flag;
260
264
  }
261
265
  buf[0] |= s;
262
266
  uint8_t *dst = (uint8_t *)buf;
263
267
  dst++;
264
- if (prepend + 1) {
265
- memcpy(dst, &prepend, 4);
266
- prepend = -1;
267
- dst += 4;
268
- s -= 4;
269
- size -= 4;
270
- }
271
268
  memcpy(dst, data, s);
272
- data = (const uint8_t *)data + s;
269
+ data = data + s;
273
270
  size -= s;
274
271
 
275
- tinyusb_cdcacm_write_queue(TINYUSB_CDC_ACM_0, (uint8_t *)buf, sizeof(buf));
272
+ if (tinyusb_cdcacm_write_queue(TINYUSB_CDC_ACM_0, (uint8_t *)buf, sizeof(buf)) <
273
+ sizeof(buf))
274
+ DMESG("CDC write fail");
276
275
  // tinyusb_cdcacm_write_flush(TINYUSB_CDC_ACM_0, 0); - prints warnings
277
276
  }
277
+
278
+ xfree(ent);
279
+ }
280
+
281
+ void HF2::sendBuffer(uint8_t flag, const void *data, unsigned size, uint32_t prepend) {
282
+ if (!connected)
283
+ return;
284
+
285
+ if (prepend + 1)
286
+ size += 4;
287
+
288
+ auto ent = (BufferEntry *)xmalloc(sizeof(BufferEntry) + size);
289
+ ent->size = size;
290
+ ent->flag = flag;
291
+ auto dst = ent->data;
292
+
293
+ if (prepend + 1) {
294
+ memcpy(dst, &prepend, 4);
295
+ dst += 4;
296
+ size -= 4;
297
+ }
298
+
299
+ memcpy(dst, data, size);
300
+
301
+ if (worker_run_wait(fg_worker, send_buffer_core, ent))
302
+ DMESG("HF2 queue full");
278
303
  }
279
304
 
280
305
  int HF2::sendEvent(uint32_t evId, const void *data, int size) {
@@ -48,4 +48,12 @@ int worker_run(worker_t w, TaskFunction_t fn, void *arg) {
48
48
  return -1;
49
49
  }
50
50
 
51
+ int worker_run_wait(worker_t w, TaskFunction_t fn, void *arg) {
52
+ qitem_t evt = {fn, arg};
53
+ if (xQueueSend(w->queue, &evt, 100) == pdPASS)
54
+ return 0;
55
+ return -1;
56
+ }
57
+
58
+
51
59
  }
@@ -155,12 +155,16 @@ void vm_stack_trace() {
155
155
  auto end = vmImg->stackTop;
156
156
  auto ptr = ctx->sp;
157
157
  DMESG(" PC:%x", (ctx->pc - ctx->imgbase) << 1);
158
- while (ptr < end) {
158
+ int max = 30;
159
+ while (ptr < end && max) {
159
160
  auto v = (uintptr_t)*ptr++;
160
161
  if (VM_IS_ENCODED_PC(v)) {
161
162
  DMESG(" PC:%x", VM_DECODE_PC(v) << 1);
163
+ max--;
162
164
  }
163
165
  }
166
+ if (max == 0)
167
+ DMESG(" ...");
164
168
  }
165
169
 
166
170
  //%
@@ -214,18 +218,21 @@ void op_callind(FiberContext *ctx, unsigned arg) {
214
218
  void op_ret(FiberContext *ctx, unsigned arg) {
215
219
  SPLIT_ARG(retNumArgs, numTmps);
216
220
 
217
- // check if we're leaving a function that still has open try blocks
218
- // (this results from invalid code generation)
219
- if (ctx->tryFrame && ctx->tryFrame->registers[0] == (uintptr_t)ctx->currAction) {
220
- DMESG("try frame %p left on return", ctx->tryFrame);
221
- target_panic(PANIC_VM_ERROR);
222
- }
223
-
224
221
  POP(numTmps);
225
222
  auto retaddr = (intptr_t)POPVAL();
226
223
  ctx->currAction = (RefAction *)POPVAL();
227
224
  POP(retNumArgs);
228
225
 
226
+ // check if we're leaving a function that still has open try blocks
227
+ // (this results from invalid code generation)
228
+ if (ctx->tryFrame &&
229
+ ctx->tryFrame->registers[2] < (uint8_t *)ctx->sp - (uint8_t *)vmImg->stackBase) {
230
+ DMESG("try frame %p left on return %d/%d", ctx->tryFrame, ctx->tryFrame->registers[2],
231
+ (uint8_t *)ctx->sp - (uint8_t *)vmImg->stackBase);
232
+ vm_stack_trace();
233
+ target_panic(PANIC_VM_ERROR);
234
+ }
235
+
229
236
  if (retaddr == (intptr_t)TAG_STACK_BOTTOM) {
230
237
  ctx->pc = NULL;
231
238
  } else {