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
|
* @retval int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define use_mem_pool
|
#if use_mem_pool
|
||||||
|
extern Pool pikaPool;
|
||||||
#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);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
@ -93,13 +83,14 @@ int main(void) {
|
|||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
HARDWARE_PRINTF_Init();
|
HARDWARE_PRINTF_Init();
|
||||||
|
printf("[info]: stm32 hardware init ok\r\n");
|
||||||
/* init mem pool */
|
|
||||||
#ifdef use_mem_pool
|
|
||||||
pikaPool = pool_init(0x1B00, 4);
|
|
||||||
#endif
|
|
||||||
printf("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 */
|
/* boot pikaScript */
|
||||||
char* code = (char*)FLASH_SCRIPT_START_ADDR;
|
char* code = (char*)FLASH_SCRIPT_START_ADDR;
|
||||||
if (code[0] != 0xFF) {
|
if (code[0] != 0xFF) {
|
||||||
|
@ -163,7 +163,25 @@ int32_t __platformSavePikaAsmEOF() {
|
|||||||
return 0;
|
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 */
|
/* support download python script by uart1 */
|
||||||
|
uint8_t pika_memory_lock = 0;
|
||||||
|
uint8_t __isLocked_pikaMemory(void){
|
||||||
|
return pika_memory_lock;
|
||||||
|
}
|
||||||
|
|
||||||
CodeHeap codeHeap;
|
CodeHeap codeHeap;
|
||||||
void STM32_Code_Init(void) {
|
void STM32_Code_Init(void) {
|
||||||
codeHeap.size = 0;
|
codeHeap.size = 0;
|
||||||
@ -182,16 +200,16 @@ uint8_t STM32_Code_reciveHandler(char* data, uint32_t rxSize) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (1 == codeHeap.ena) {
|
if (1 == codeHeap.ena) {
|
||||||
|
if(!pika_memory_lock){
|
||||||
|
pika_memory_lock = 1;
|
||||||
|
#if use_mem_pool
|
||||||
|
pool_deinit(&pikaPool);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
codeHeap.reciveTime = uwTick;
|
codeHeap.reciveTime = uwTick;
|
||||||
codeHeap.oldSize = codeHeap.size;
|
codeHeap.oldSize = codeHeap.size;
|
||||||
codeHeap.size += rxSize;
|
codeHeap.size += rxSize;
|
||||||
/* copy old to new content */
|
codeHeap.content = realloc(codeHeap.content, codeHeap.size + 1);
|
||||||
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 */
|
|
||||||
memcpy(codeHeap.content + codeHeap.oldSize, data, rxSize);
|
memcpy(codeHeap.content + codeHeap.oldSize, data, rxSize);
|
||||||
codeHeap.content[codeHeap.size] = 0;
|
codeHeap.content[codeHeap.size] = 0;
|
||||||
/* reciving code */
|
/* reciving code */
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef __STM32G030_PIKA_PORT__H
|
#ifndef __STM32G030_PIKA_PORT__H
|
||||||
#define __STM32G030_PIKA_PORT__H
|
#define __STM32G030_PIKA_PORT__H
|
||||||
|
|
||||||
|
#define use_mem_pool 1
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "pikaObj.h"
|
#include "pikaObj.h"
|
||||||
typedef struct _CodeHeap {
|
typedef struct _CodeHeap {
|
||||||
|
@ -54,6 +54,10 @@ PIKA_WEAK void __impl_pikaFree(void* ptrm, size_t size) {
|
|||||||
__platformFree(ptrm);
|
__platformFree(ptrm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PIKA_WEAK uint8_t __isLocked_pikaMemory(void){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
PIKA_WEAK void __platformPrintf(char* fmt, ...) {
|
PIKA_WEAK void __platformPrintf(char* fmt, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
@ -46,10 +46,10 @@ void __platformDisableIrqHandle(void);
|
|||||||
|
|
||||||
void* __impl_pikaMalloc(size_t size);
|
void* __impl_pikaMalloc(size_t size);
|
||||||
void __impl_pikaFree(void* ptrm, size_t size);
|
void __impl_pikaFree(void* ptrm, size_t size);
|
||||||
|
uint8_t __isLocked_pikaMemory(void);
|
||||||
|
|
||||||
char* __platformLoadPikaAsm(void);
|
char* __platformLoadPikaAsm(void);
|
||||||
int32_t __platformSavePikaAsm(char* PikaAsm);
|
int32_t __platformSavePikaAsm(char* PikaAsm);
|
||||||
uint8_t __platformAsmIsToFlash(char* pyMultiLine);
|
uint8_t __platformAsmIsToFlash(char* pyMultiLine);
|
||||||
int32_t __platformSavePikaAsmEOF(void);
|
int32_t __platformSavePikaAsmEOF(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
PikaMemInfo pikaMemInfo = {0};
|
PikaMemInfo pikaMemInfo = {0};
|
||||||
|
|
||||||
void* pikaMalloc(uint32_t size) {
|
void* pikaMalloc(uint32_t size) {
|
||||||
|
/* pika memory lock */
|
||||||
|
while(__isLocked_pikaMemory()){
|
||||||
|
}
|
||||||
pikaMemInfo.heapUsed += size;
|
pikaMemInfo.heapUsed += size;
|
||||||
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
||||||
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
||||||
@ -49,6 +52,9 @@ void* pikaMalloc(uint32_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pikaFree(void* mem, uint32_t size) {
|
void pikaFree(void* mem, uint32_t size) {
|
||||||
|
/* pika memory lock */
|
||||||
|
while(__isLocked_pikaMemory()){
|
||||||
|
}
|
||||||
__platformDisableIrqHandle();
|
__platformDisableIrqHandle();
|
||||||
__impl_pikaFree(mem, size);
|
__impl_pikaFree(mem, size);
|
||||||
__platformEnableIrqHandle();
|
__platformEnableIrqHandle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user