mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Moved memory() to process.memory() - added more info too
This commit is contained in:
parent
ed3cb7f661
commit
f45d6b975d
@ -5,6 +5,7 @@
|
||||
Fix digitalPulse length (properly!) - fix #154
|
||||
Making sure that undefined gets cast to NaN
|
||||
Fix Array.indexOf() returns undefined instead of -1 - fix #155
|
||||
Moved memory() to process.memory() - added more info too
|
||||
|
||||
1v44 : Modified build system to store binary names in the python definition
|
||||
Fix nasty regression involving losing code at the end of Strings
|
||||
|
||||
@ -209,8 +209,14 @@ else:
|
||||
codeOut("#define JSVAR_CACHE_SIZE "+str(variables)+" // Number of JavaScript variables in RAM")
|
||||
codeOut("#define FLASH_AVAILABLE_FOR_CODE "+str(flash_available_for_code))
|
||||
codeOut("#define FLASH_PAGE_SIZE "+str(flash_page_size))
|
||||
codeOut("#define FLASH_PAGES "+str(flash_pages))
|
||||
codeOut("#define FLASH_SAVED_CODE_PAGES "+str(flash_pages))
|
||||
codeOut("#define FLASH_START "+str(0x08000000))
|
||||
if has_bootloader: codeOut("#define BOOTLOADER_SIZE "+str(common.get_bootloader_size()))
|
||||
codeOut("")
|
||||
codeOut("#define FLASH_SAVED_CODE_LENGTH (FLASH_PAGE_SIZE*FLASH_SAVED_CODE_PAGES)")
|
||||
codeOut("#define FLASH_SAVED_CODE_START (FLASH_START + FLASH_TOTAL - FLASH_SAVED_CODE_LENGTH)")
|
||||
codeOut("#define FLASH_MAGIC_LOCATION (FLASH_SAVED_CODE_START + FLASH_SAVED_CODE_LENGTH - 4)")
|
||||
codeOut("#define FLASH_MAGIC 0xDEADBEEF")
|
||||
codeOut("");
|
||||
codeOut("#define USARTS "+str(board.chip["usart"]))
|
||||
codeOut("#define SPIS "+str(board.chip["spi"]))
|
||||
|
||||
@ -117,55 +117,6 @@ void jswrap_interface_print(JsVar *v) {
|
||||
jsiConsolePrint("\n");
|
||||
}
|
||||
|
||||
|
||||
/*JSON{ "type":"function", "name" : "memory",
|
||||
"description" : ["Run a Garbage Collection pass, and return an object containing information on memory usage.",
|
||||
"free : Memory that is available to be used",
|
||||
"usage : Memory that has been used",
|
||||
"total : Total memory",
|
||||
"history : Memory used for command history - that is freed if memory is low. Note that this is INCLUDED in the figure for 'free'.",
|
||||
"On ARM, stackEndAddress is the address (that can be used with peek/poke/etc) of the END of the stack. The stack grows down, so unless you do a lot of recursion, the bytes above this can be used."],
|
||||
"generate" : "jswrap_interface_memory",
|
||||
"return" : ["JsVar", "Information about memory usage"]
|
||||
}*/
|
||||
#ifdef ARM
|
||||
extern int _end;
|
||||
#endif
|
||||
JsVar *jswrap_interface_memory() {
|
||||
jsvGarbageCollect();
|
||||
JsVar *obj = jsvNewWithFlags(JSV_OBJECT);
|
||||
if (obj) {
|
||||
unsigned int history = 0;
|
||||
JsVar *historyVar = jsvObjectGetChild(jsiGetParser()->root, JSI_HISTORY_NAME, 0);
|
||||
if (historyVar) {
|
||||
history = (unsigned int)jsvCountJsVarsUsed(historyVar); // vars used to store history
|
||||
jsvUnLock(historyVar);
|
||||
}
|
||||
unsigned int usage = jsvGetMemoryUsage() - history;
|
||||
unsigned int total = jsvGetMemoryTotal();
|
||||
JsVar *v;
|
||||
v = jsvNewFromInteger(total-usage);
|
||||
jsvUnLock(jsvAddNamedChild(obj, v, "free"));
|
||||
jsvUnLock(v);
|
||||
v = jsvNewFromInteger(usage);
|
||||
jsvUnLock(jsvAddNamedChild(obj, v, "usage"));
|
||||
jsvUnLock(v);
|
||||
v = jsvNewFromInteger(total);
|
||||
jsvUnLock(jsvAddNamedChild(obj, v, "total"));
|
||||
jsvUnLock(v);
|
||||
v = jsvNewFromInteger(history);
|
||||
jsvUnLock(jsvAddNamedChild(obj, v, "history"));
|
||||
jsvUnLock(v);
|
||||
|
||||
#ifdef ARM
|
||||
v = jsvNewFromInteger((JsVarInt)(unsigned int)&_end);
|
||||
jsvUnLock(jsvAddNamedChild(obj, v, "stackEndAddress"));
|
||||
jsvUnLock(v);
|
||||
#endif
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*JSON{ "type":"function", "name" : "edit",
|
||||
"description" : ["Fill the console with the contents of the given function, so you can edit it.",
|
||||
"NOTE: This is a convenience function - it will not edit 'inner functions'. For that, you must edit the 'outer function' and re-execute it."],
|
||||
|
||||
@ -19,7 +19,6 @@ void jswrap_interface_setSleepIndicator(JsVar *pinVar);
|
||||
void jswrap_interface_setDeepSleep(bool sleep);
|
||||
void jswrap_interface_trace(JsVar *root);
|
||||
void jswrap_interface_print(JsVar *v);
|
||||
JsVar *jswrap_interface_memory();
|
||||
void jswrap_interface_edit(JsVar *funcName);
|
||||
void jswrap_interface_echo(bool echoOn);
|
||||
JsVar *jswrap_interface_getSerial();
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
#include "jswrap_process.h"
|
||||
#include "jsinteractive.h"
|
||||
|
||||
/*JSON{ "type":"class",
|
||||
"class" : "process",
|
||||
@ -47,3 +48,47 @@ JsVar *jswrap_process_env() {
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/*JSON{ "type":"staticmethod",
|
||||
"class" : "process", "name" : "memory",
|
||||
"description" : ["Run a Garbage Collection pass, and return an object containing information on memory usage.",
|
||||
"free : Memory that is available to be used",
|
||||
"usage : Memory that has been used",
|
||||
"total : Total memory",
|
||||
"history : Memory used for command history - that is freed if memory is low. Note that this is INCLUDED in the figure for 'free'.",
|
||||
"On ARM, stackEndAddress is the address (that can be used with peek/poke/etc) of the END of the stack. The stack grows down, so unless you do a lot of recursion, the bytes above this can be used."],
|
||||
"generate" : "jswrap_process_memory",
|
||||
"return" : ["JsVar", "Information about memory usage"]
|
||||
}*/
|
||||
#ifdef ARM
|
||||
extern int _end; // end of ram used (variables)
|
||||
extern int _etext; // end of flash text (binary) section
|
||||
#endif
|
||||
JsVar *jswrap_process_memory() {
|
||||
jsvGarbageCollect();
|
||||
JsVar *obj = jsvNewWithFlags(JSV_OBJECT);
|
||||
if (obj) {
|
||||
unsigned int history = 0;
|
||||
JsVar *historyVar = jsvObjectGetChild(jsiGetParser()->root, JSI_HISTORY_NAME, 0);
|
||||
if (historyVar) {
|
||||
history = (unsigned int)jsvCountJsVarsUsed(historyVar); // vars used to store history
|
||||
jsvUnLock(historyVar);
|
||||
}
|
||||
unsigned int usage = jsvGetMemoryUsage() - history;
|
||||
unsigned int total = jsvGetMemoryTotal();
|
||||
jsvUnLock(jsvObjectSetChild(obj, "free", jsvNewFromInteger(total-usage)));
|
||||
jsvUnLock(jsvObjectSetChild(obj, "usage", jsvNewFromInteger(usage)));
|
||||
jsvUnLock(jsvObjectSetChild(obj, "total", jsvNewFromInteger(total)));
|
||||
jsvUnLock(jsvObjectSetChild(obj, "history", jsvNewFromInteger(history)));
|
||||
|
||||
#ifdef ARM
|
||||
jsvUnLock(jsvObjectSetChild(obj, "stackEndAddress", jsvNewFromInteger((JsVarInt)(unsigned int)&_end)));
|
||||
jsvUnLock(jsvObjectSetChild(obj, "flash_start", jsvNewFromInteger((JsVarInt)FLASH_START)));
|
||||
jsvUnLock(jsvObjectSetChild(obj, "flash_binary_end", jsvNewFromInteger((JsVarInt)(unsigned int)&_etext)));
|
||||
jsvUnLock(jsvObjectSetChild(obj, "flash_code_start", jsvNewFromInteger((JsVarInt)FLASH_SAVED_CODE_START)));
|
||||
jsvUnLock(jsvObjectSetChild(obj, "flash_length", jsvNewFromInteger((JsVarInt)FLASH_TOTAL)));
|
||||
#endif
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -16,3 +16,4 @@
|
||||
#include "jsvar.h"
|
||||
|
||||
JsVar *jswrap_process_env();
|
||||
JsVar *jswrap_process_memory();
|
||||
|
||||
@ -72,7 +72,7 @@ void sysfs_read(const char *path, char *data, unsigned int len) {
|
||||
JsVarInt sysfs_read_int(const char *path) {
|
||||
char buf[20];
|
||||
sysfs_read(path, buf, sizeof(buf));
|
||||
return stringToIntWithRadix(buf, 10);
|
||||
return stringToIntWithRadix(buf, 10, 0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@ -50,15 +50,6 @@
|
||||
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
|
||||
#endif
|
||||
|
||||
#define FLASH_LENGTH (FLASH_PAGE_SIZE*FLASH_PAGES)
|
||||
|
||||
#if FLASH_LENGTH < 4+JSVAR_CACHE_SIZE*JSVAR_SIZE
|
||||
#error NOT ENOUGH ROOM IN FLASH - FLASH_PAGES pages at FLASH_PAGE_SIZE bytes
|
||||
#endif
|
||||
|
||||
#define FLASH_START (0x08000000 + FLASH_TOTAL - FLASH_LENGTH)
|
||||
#define FLASH_MAGIC_LOCATION (FLASH_START+FLASH_LENGTH-4)
|
||||
#define FLASH_MAGIC 0xDEADBEEF
|
||||
|
||||
// see jshPinWatch/jshGetWatchedPinState
|
||||
Pin watchedPins[16];
|
||||
@ -1973,8 +1964,8 @@ void jshSaveToFlash() {
|
||||
FLASH_EraseSector(FLASH_Sector_11, VoltageRange_3);
|
||||
#else
|
||||
/* Erase the FLASH pages */
|
||||
for(i=0;i<FLASH_PAGES;i++) {
|
||||
FLASH_ErasePage((uint32_t)(FLASH_START + (FLASH_PAGE_SIZE * i)));
|
||||
for(i=0;i<FLASH_SAVED_CODE_PAGES;i++) {
|
||||
FLASH_ErasePage((uint32_t)(FLASH_SAVED_CODE_START + (FLASH_PAGE_SIZE * i)));
|
||||
jsiConsolePrint(".");
|
||||
}
|
||||
#endif
|
||||
@ -1988,14 +1979,14 @@ void jshSaveToFlash() {
|
||||
jsvUnLock(firstData);
|
||||
#if defined(STM32F2) || defined(STM32F4)
|
||||
for (i=0;i<dataSize;i+=4) {
|
||||
while (FLASH_ProgramWord((uint32_t)(FLASH_START+i), basePtr[i>>2]) != FLASH_COMPLETE);
|
||||
while (FLASH_ProgramWord((uint32_t)(FLASH_SAVED_CODE_START+i), basePtr[i>>2]) != FLASH_COMPLETE);
|
||||
if ((i&1023)==0) jsiConsolePrint(".");
|
||||
}
|
||||
while (FLASH_ProgramWord(FLASH_MAGIC_LOCATION, FLASH_MAGIC) != FLASH_COMPLETE);
|
||||
#else
|
||||
/* Program Flash Bank */
|
||||
for (i=0;i<dataSize;i+=4) {
|
||||
FLASH_ProgramWord((uint32_t)(FLASH_START+i), basePtr[i>>2]);
|
||||
FLASH_ProgramWord((uint32_t)(FLASH_SAVED_CODE_START+i), basePtr[i>>2]);
|
||||
if ((i&1023)==0) jsiConsolePrint(".");
|
||||
}
|
||||
FLASH_ProgramWord(FLASH_MAGIC_LOCATION, FLASH_MAGIC);
|
||||
@ -2014,7 +2005,7 @@ void jshSaveToFlash() {
|
||||
|
||||
int errors = 0;
|
||||
for (i=0;i<dataSize;i+=4)
|
||||
if ((*(uint32_t*)(FLASH_START+i)) != basePtr[i>>2])
|
||||
if ((*(uint32_t*)(FLASH_SAVED_CODE_START+i)) != basePtr[i>>2])
|
||||
errors++;
|
||||
|
||||
if (FLASH_MAGIC != *(unsigned int*)FLASH_MAGIC_LOCATION) {
|
||||
@ -2036,10 +2027,10 @@ void jshSaveToFlash() {
|
||||
// int *basePtr = jsvGetVarDataPointer();
|
||||
//
|
||||
// int page;
|
||||
// for(page=0;page<FLASH_PAGES;page++) {
|
||||
// for(page=0;page<FLASH_SAVED_CODE_PAGES;page++) {
|
||||
// jsPrint("Flashing Page ");jsPrintInt(page);jsPrint("...\n");
|
||||
// size_t pageOffset = (FLASH_PAGE_SIZE * page);
|
||||
// size_t pagePtr = FLASH_START + pageOffset;
|
||||
// size_t pagePtr = FLASH_SAVED_CODE_START + pageOffset;
|
||||
// size_t pageSize = varDataSize-pageOffset;
|
||||
// if (pageSize>FLASH_PAGE_SIZE) pageSize = FLASH_PAGE_SIZE;
|
||||
// jsPrint("Offset ");jsPrintInt(pageOffset);jsPrint(", Size ");jsPrintInt(pageSize);jsPrint(" bytes\n");
|
||||
@ -2047,7 +2038,7 @@ void jshSaveToFlash() {
|
||||
// int errors = 0;
|
||||
// int i;
|
||||
// for (i=pageOffset;i<pageOffset+pageSize;i+=4)
|
||||
// if ((*(int*)(FLASH_START+i)) != basePtr[i>>2])
|
||||
// if ((*(int*)(FLASH_SAVED_CODE_START+i)) != basePtr[i>>2])
|
||||
// errors++;
|
||||
// while (errors && !jspIsInterrupted()) {
|
||||
// if (!first) { jsPrintInt(errors);jsPrint(" errors - retrying...\n"); }
|
||||
@ -2056,7 +2047,7 @@ void jshSaveToFlash() {
|
||||
// FLASH_ErasePage(pagePtr);
|
||||
// /* Program Flash Bank1 */
|
||||
// for (i=pageOffset;i<pageOffset+pageSize;i+=4)
|
||||
// FLASH_ProgramWord(FLASH_START+i, basePtr[i>>2]);
|
||||
// FLASH_ProgramWord(FLASH_SAVED_CODE_START+i, basePtr[i>>2]);
|
||||
// FLASH_WaitForLastOperation(0x20000);
|
||||
// }
|
||||
// }
|
||||
@ -2078,7 +2069,7 @@ void jshLoadFromFlash() {
|
||||
uint32_t *basePtr = (uint32_t *)firstData;
|
||||
jsvUnLock(firstData);
|
||||
|
||||
memcpy(basePtr, (int*)FLASH_START, dataSize);
|
||||
memcpy(basePtr, (int*)FLASH_SAVED_CODE_START, dataSize);
|
||||
jsiConsolePrint(" Done!\n>");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user