硬汉嵌入式论坛

 找回密码
 立即注册
查看: 726|回复: 7
收起左侧

[Lua] 使用Lua实现uCOS-II任务调度器计算

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106649
QQ
发表于 2023-6-12 03:24:53 | 显示全部楼层 |阅读模式
Lua获取当前等待信号量,消息队列,消息邮箱等通信组件的任务和任务个数,含等待的最高优先级任务

[Lua] 纯文本查看 复制代码
        if(OSLowestPrio <= 63) then
                OSEventCnt = pg_read16(pcb + 8)
                OSEventGrp = pg_read8(pcb + 0x0a)
                for i=0, OS_EVENT_TBL_SIZE, 1 do
                        off = (OSEventGrp & (1<<i) ) >> i
                        if(off == 1) then
                                for j=0, 7, 1 do
                                        OSEventTbl1 = pg_read8(pcb + 0x0b + i)
                                        off = (OSEventTbl1 & (1<<j) ) >> j
                                        if(off == 1) then
                                                TaskCount = TaskCount + 1
                                                TaskBuffer[TaskCount] = j + i*8
                                        end
                                end
                        end
                end
        else
                OSEventCnt = pg_read16(pcb + 8)
                OSEventGrp = pg_read16(pcb + 0x0a)
                OSEventTbl1 = pg_read16(pcb + 0x0c)

                for i=0, OS_EVENT_TBL_SIZE, 1 do
                        off = (OSEventGrp & (1<<i) ) >> i
                        if(off == 1) then
                                for j=0, 15, 1 do
                                        OSEventTbl1 = pg_read16(pcb + 0x0b + 2*i)
                                        off = (OSEventTbl1 & (1<<j) ) >> j
                                        if(off == 1) then
                                                TaskCount = TaskCount + 1
                                                TaskBuffer[TaskCount] = j + i*8
                                        end
                                end
                        end
                end
        end




C获取就绪的最高优先级任务:

[C] 纯文本查看 复制代码
/*
*********************************************************************************************************
*                           MAKE TASK READY TO RUN BASED ON EVENT OCCURING
*
* Description: This function is called by other uC/OS-II services and is used to ready a task that was
*              waiting for an event to occur.
*
* Arguments  : pevent      is a pointer to the event control block corresponding to the event.
*
*              pmsg        is a pointer to a message.  This pointer is used by message oriented services
*                          such as MAILBOXEs and QUEUEs.  The pointer is not used when called by other
*                          service functions.
*
*              msk         is a mask that is used to clear the status byte of the TCB.  For example,
*                          OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
*
*              pend_stat   is used to indicate the readied task's pending status:
*
*                          OS_STAT_PEND_OK      Task ready due to a post (or delete), not a timeout or
*                                               an abort.
*                          OS_STAT_PEND_ABORT   Task ready due to an abort.
*
* Returns    : none
*
* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
*********************************************************************************************************
*/
#if (OS_EVENT_EN)
INT8U  OS_EventTaskRdy (OS_EVENT  *pevent,
                        void      *pmsg,
                        INT8U      msk,
                        INT8U      pend_stat)
{
    OS_TCB   *ptcb;
    INT8U     y;
    INT8U     x;
    INT8U     prio;
#if OS_LOWEST_PRIO > 63u
    OS_PRIO  *ptbl;
#endif


#if OS_LOWEST_PRIO <= 63u
    y    = OSUnMapTbl[pevent->OSEventGrp];              /* Find HPT waiting for message                */
    x    = OSUnMapTbl[pevent->OSEventTbl[y]];
    prio = (INT8U)((y << 3u) + x);                      /* Find priority of task getting the msg       */
#else
    if ((pevent->OSEventGrp & 0xFFu) != 0u) {           /* Find HPT waiting for message                */
        y = OSUnMapTbl[ pevent->OSEventGrp & 0xFFu];
    } else {
        y = OSUnMapTbl[(OS_PRIO)(pevent->OSEventGrp >> 8u) & 0xFFu] + 8u;
    }
    ptbl = &pevent->OSEventTbl[y];
    if ((*ptbl & 0xFFu) != 0u) {
        x = OSUnMapTbl[*ptbl & 0xFFu];
    } else {
        x = OSUnMapTbl[(OS_PRIO)(*ptbl >> 8u) & 0xFFu] + 8u;
    }
    prio = (INT8U)((y << 4u) + x);                      /* Find priority of task getting the msg       */
#endif

    ptcb                  =  OSTCBPrioTbl[prio];        /* Point to this task's OS_TCB                 */
    ptcb->OSTCBDly        =  0u;                        /* Prevent OSTimeTick() from readying task     */
#if ((OS_Q_EN > 0u) && (OS_MAX_QS > 0u)) || (OS_MBOX_EN > 0u)
    ptcb->OSTCBMsg        =  pmsg;                      /* Send message directly to waiting task       */
#else
    pmsg                  =  pmsg;                      /* Prevent compiler warning if not used        */
#endif
    ptcb->OSTCBStat      &= (INT8U)~msk;                /* Clear bit associated with event type        */
    ptcb->OSTCBStatPend   =  pend_stat;                 /* Set pend status of post or abort            */
                                                        /* See if task is ready (could be susp'd)      */
    if ((ptcb->OSTCBStat &   OS_STAT_SUSPEND) == OS_STAT_RDY) {
        OSRdyGrp         |=  ptcb->OSTCBBitY;           /* Put task in the ready to run list           */
        OSRdyTbl[y]      |=  ptcb->OSTCBBitX;
        OS_TRACE_TASK_READY(ptcb);
    }

    OS_EventTaskRemove(ptcb, pevent);                   /* Remove this task from event   wait list     */
#if (OS_EVENT_MULTI_EN > 0u)
    if (ptcb->OSTCBEventMultiPtr != (OS_EVENT **)0) {   /* Remove this task from events' wait lists    */
        OS_EventTaskRemoveMulti(ptcb, ptcb->OSTCBEventMultiPtr);
        ptcb->OSTCBEventMultiPtr  = (OS_EVENT **)0;     /* No longer pending on multi list             */
        ptcb->OSTCBEventMultiRdy  = (OS_EVENT  *)pevent;/* Return event as first multi-pend event ready*/
    }
#endif

    return (prio);
}
#endif

回复

使用道具 举报

0

主题

67

回帖

67

积分

初级会员

积分
67
发表于 2023-6-12 09:41:20 | 显示全部楼层
可以也用位图表方式获取优先级吧,不知道Lua实现是否方便
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106649
QQ
 楼主| 发表于 2023-6-12 10:27:27 | 显示全部楼层
Vxworks 发表于 2023-6-12 09:41
可以也用位图表方式获取优先级吧,不知道Lua实现是否方便

LUA也可以做位图调度检索。楼主位这种,我改成手动计算了,代码还少点。
回复

使用道具 举报

0

主题

19

回帖

19

积分

新手上路

积分
19
发表于 2023-6-15 18:35:40 | 显示全部楼层
楼主,您好!
之前测试过microPython+RTT+stm32+vscode(RT-thread官方的例子), 即:在vscode上就可以实现对stm32上的microPython程序进行调试(通过串口下载程序)。
想问一下,lua是否类似的操作方式啊?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106649
QQ
 楼主| 发表于 2023-6-16 01:42:25 | 显示全部楼层
hijkstra 发表于 2023-6-15 18:35
楼主,您好!
之前测试过microPython+RTT+stm32+vscode(RT-thread官方的例子), 即:在vscode上就可以实 ...

LUA和Python一样,都是脚本语言,自然玩法也是差不多。

对于我们TOOL来说,支持在线加载Lua使用,也支持例子离线加载LUA使用,对于在线方式,支持USB, WiFi和以太网加载,同时也支持内网和外网使用。

像TOOL的脱机烧录,RTOS Trace,CANFD Trace等都是基于LUA实现的。
回复

使用道具 举报

0

主题

19

回帖

19

积分

新手上路

积分
19
发表于 2023-6-16 10:52:58 | 显示全部楼层
非常感谢
还有个问题哈,如何实现在电脑上对stm32上运行的lua进行调试啊?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106649
QQ
 楼主| 发表于 2023-6-16 11:11:50 | 显示全部楼层
hijkstra 发表于 2023-6-16 10:52
非常感谢
还有个问题哈,如何实现在电脑上对stm32上运行的lua进行调试啊?

这里有简单的例子,可以了解下

STM32-V6 LUA简单移植
https://www.armbbs.cn/forum.php? ... 4757&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

0

主题

19

回帖

19

积分

新手上路

积分
19
发表于 2023-7-4 09:54:35 | 显示全部楼层
好的,多谢啦
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-27 22:05 , Processed in 0.175002 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表