mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
update package/Arm2DqemuBooter/main.c.
This commit is contained in:
parent
40108b39d6
commit
59f365c9fd
@ -24,37 +24,17 @@ static rt_device_t serial; /* 串口设备句柄 */
|
||||
static struct rt_semaphore rx_sem; /* 用于接收消息的信号量 */
|
||||
|
||||
#define RX_Buff_SIZE 256
|
||||
char rxBuff[RX_Buff_SIZE] = { 0 };
|
||||
Args *rxArgs;
|
||||
uint8_t isRxOk = 0;
|
||||
PikaObj *pikaMain;
|
||||
|
||||
void rx_single_line_handle(char *line) {
|
||||
Args * resArgs = obj_runDirect(pikaMain, line);
|
||||
char * sysOut = args_getSysOut(resArgs);
|
||||
rt_kprintf("\r\n");
|
||||
|
||||
if (!strEqu(sysOut, "")) {
|
||||
rt_kprintf("%s\r\n", sysOut);
|
||||
}
|
||||
args_deinit(resArgs);
|
||||
|
||||
rt_kprintf(">>>");
|
||||
}
|
||||
|
||||
/* 接收数据回调函数 */
|
||||
static rt_err_t uart_input_callback(rt_device_t dev, rt_size_t size) {
|
||||
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
|
||||
char inputChar;
|
||||
rt_device_read(serial, -1, &inputChar, 1);
|
||||
rt_device_write(serial, 0, &inputChar, 1);
|
||||
if (inputChar != '\r' && inputChar != '\n') {
|
||||
strAppendWithSize(rxBuff, &inputChar, 1);
|
||||
}
|
||||
if (inputChar == '\r') {
|
||||
isRxOk = 1;
|
||||
}
|
||||
return RT_EOK;
|
||||
|
||||
}
|
||||
|
||||
static void clearBuff(char *buff, uint32_t size) {
|
||||
@ -79,14 +59,9 @@ static void uart_init() {
|
||||
int main(void) {
|
||||
uart_init();
|
||||
pikaMain = pikaScriptInit();
|
||||
clearBuff(rxBuff, RX_Buff_SIZE);
|
||||
rt_kprintf(">>>");
|
||||
|
||||
while (1) {
|
||||
if (isRxOk) {
|
||||
isRxOk = 0;
|
||||
rx_single_line_handle(rxBuff);
|
||||
clearBuff(rxBuff, RX_Buff_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user