mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add mem lock and support download py in pool mode
This commit is contained in:
parent
e25cbbef92
commit
9d16c03311
@ -68,18 +68,8 @@ uint8_t Shell_Ready = 0;
|
||||
* @retval int
|
||||
*/
|
||||
|
||||
#define use_mem_pool
|
||||
|
||||
#ifdef use_mem_pool
|
||||
/* use mem pool */
|
||||
Pool pikaPool;
|
||||
void* __impl_pikaMalloc(size_t size) {
|
||||
void* mem = pool_malloc(&pikaPool, size);
|
||||
return mem;
|
||||
}
|
||||
void __impl_pikaFree(void* ptrm, size_t size) {
|
||||
pool_free(&pikaPool, ptrm, size);
|
||||
}
|
||||
#if use_mem_pool
|
||||
extern Pool pikaPool;
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
@ -93,13 +83,14 @@ int main(void) {
|
||||
SystemClock_Config();
|
||||
MX_GPIO_Init();
|
||||
HARDWARE_PRINTF_Init();
|
||||
|
||||
/* init mem pool */
|
||||
#ifdef use_mem_pool
|
||||
pikaPool = pool_init(0x1B00, 4);
|
||||
#endif
|
||||
printf("stm32 hardware init ok\r\n");
|
||||
printf("[info]: stm32 hardware init ok\r\n");
|
||||
|
||||
/* init mem pool */
|
||||
#if use_mem_pool
|
||||
pikaPool = pool_init(0x1B00, 4);
|
||||
printf("[info]: pika memory poool init ok \r\n");
|
||||
#endif
|
||||
|
||||
/* boot pikaScript */
|
||||
char* code = (char*)FLASH_SCRIPT_START_ADDR;
|
||||
if (code[0] != 0xFF) {
|
||||
|
@ -163,7 +163,25 @@ int32_t __platformSavePikaAsmEOF() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* support mem pool */
|
||||
#if use_mem_pool
|
||||
/* use mem pool */
|
||||
Pool pikaPool;
|
||||
void* __impl_pikaMalloc(size_t size) {
|
||||
void* mem = pool_malloc(&pikaPool, size);
|
||||
return mem;
|
||||
}
|
||||
void __impl_pikaFree(void* ptrm, size_t size) {
|
||||
pool_free(&pikaPool, ptrm, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* support download python script by uart1 */
|
||||
uint8_t pika_memory_lock = 0;
|
||||
uint8_t __isLocked_pikaMemory(void){
|
||||
return pika_memory_lock;
|
||||
}
|
||||
|
||||
CodeHeap codeHeap;
|
||||
void STM32_Code_Init(void) {
|
||||
codeHeap.size = 0;
|
||||
@ -182,16 +200,16 @@ uint8_t STM32_Code_reciveHandler(char* data, uint32_t rxSize) {
|
||||
}
|
||||
}
|
||||
if (1 == codeHeap.ena) {
|
||||
if(!pika_memory_lock){
|
||||
pika_memory_lock = 1;
|
||||
#if use_mem_pool
|
||||
pool_deinit(&pikaPool);
|
||||
#endif
|
||||
}
|
||||
codeHeap.reciveTime = uwTick;
|
||||
codeHeap.oldSize = codeHeap.size;
|
||||
codeHeap.size += rxSize;
|
||||
/* copy old to new content */
|
||||
char* new_content = pikaMalloc(codeHeap.size + 1);
|
||||
memcpy(new_content, codeHeap.content, codeHeap.oldSize + 1);
|
||||
pikaFree(codeHeap.content, codeHeap.oldSize + 1);
|
||||
/* update new content */
|
||||
codeHeap.content = new_content;
|
||||
/* copy append content to new content */
|
||||
codeHeap.content = realloc(codeHeap.content, codeHeap.size + 1);
|
||||
memcpy(codeHeap.content + codeHeap.oldSize, data, rxSize);
|
||||
codeHeap.content[codeHeap.size] = 0;
|
||||
/* reciving code */
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef __STM32G030_PIKA_PORT__H
|
||||
#define __STM32G030_PIKA_PORT__H
|
||||
|
||||
#define use_mem_pool 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include "pikaObj.h"
|
||||
typedef struct _CodeHeap {
|
||||
|
@ -54,6 +54,10 @@ PIKA_WEAK void __impl_pikaFree(void* ptrm, size_t size) {
|
||||
__platformFree(ptrm);
|
||||
}
|
||||
|
||||
PIKA_WEAK uint8_t __isLocked_pikaMemory(void){
|
||||
return 0;
|
||||
}
|
||||
|
||||
PIKA_WEAK void __platformPrintf(char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
@ -46,10 +46,10 @@ void __platformDisableIrqHandle(void);
|
||||
|
||||
void* __impl_pikaMalloc(size_t size);
|
||||
void __impl_pikaFree(void* ptrm, size_t size);
|
||||
uint8_t __isLocked_pikaMemory(void);
|
||||
|
||||
char* __platformLoadPikaAsm(void);
|
||||
int32_t __platformSavePikaAsm(char* PikaAsm);
|
||||
uint8_t __platformAsmIsToFlash(char* pyMultiLine);
|
||||
int32_t __platformSavePikaAsmEOF(void);
|
||||
|
||||
#endif
|
||||
|
@ -32,6 +32,9 @@
|
||||
PikaMemInfo pikaMemInfo = {0};
|
||||
|
||||
void* pikaMalloc(uint32_t size) {
|
||||
/* pika memory lock */
|
||||
while(__isLocked_pikaMemory()){
|
||||
}
|
||||
pikaMemInfo.heapUsed += size;
|
||||
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
||||
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
||||
@ -49,6 +52,9 @@ void* pikaMalloc(uint32_t size) {
|
||||
}
|
||||
|
||||
void pikaFree(void* mem, uint32_t size) {
|
||||
/* pika memory lock */
|
||||
while(__isLocked_pikaMemory()){
|
||||
}
|
||||
__platformDisableIrqHandle();
|
||||
__impl_pikaFree(mem, size);
|
||||
__platformEnableIrqHandle();
|
||||
|
Loading…
x
Reference in New Issue
Block a user