首页 > 其他分享 >S32G3任务抢占

S32G3任务抢占

时间:2024-07-31 11:41:56浏览次数:8  
标签:抢占 Clock int STM unsigned 任务 S32G3 os define

通过S32G3 的STM定时器 实现任务任务抢占

1、创建一个空工程

 

2、创建完成后先生成一版代码

 

 3、编译

 

4、添加user文件夹来存放自己的代码

my_os.h

/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "my_os.h"
#include "Platform_Types.h"
#include "IntCtrl_Ip.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
#define    STM_0_CR                *(unsigned int *)0x4011C000
#define    STM_0_CNT               *(unsigned int *)0x4011C004
#define    STM_0_CCR0              *(unsigned int *)0x4011C010
#define    STM_0_CIR0              *(unsigned int *)0x4011C014
#define    STM_0_CMP0              *(unsigned int *)0x4011C018

#define    STM_0_CR_TEN_ENABLED        (1<<0)
#define    STM_0_CR_TEN_DISABLED       (0<<0)

#define    STM_0_CLEAN_CNT             (0<<0)

#define    STM_0_CCR0_ENABLED          (1<<0)
#define    STM_0_CCR0_DISABLED         (0<<0)

#define    STM_0_CIR0_CLEAN_IRQ_FLAG   (1<<0)


#define    STM_1_CR                *(unsigned int *)0x40120000
#define    STM_1_CNT               *(unsigned int *)0x40120004
#define    STM_1_CCR0              *(unsigned int *)0x40120010
#define    STM_1_CIR0              *(unsigned int *)0x40120014
#define    STM_1_CMP0              *(unsigned int *)0x40120018

#define    STM_1_CR_TEN_ENABLED        (1<<0)
#define    STM_1_CR_TEN_DISABLED       (0<<0)

#define    STM_1_CLEAN_CNT             (0<<0)

#define    STM_1_CCR0_ENABLED          (1<<0)
#define    STM_1_CCR0_DISABLED         (0<<0)

#define    STM_1_CIR0_CLEAN_IRQ_FLAG   (1<<0)

uint32 STM_0_ISR_Test_Cnt = 0;
uint32 STM_0_ISR_Test_Flg = 0;
ISR(STM_0_ISR)
{
    STM_0_ISR_Test_Flg = 1;
    /* Disabled STM0 */
    STM_0_CR    = (unsigned int)STM_0_CR_TEN_DISABLED;
    /* Disabled ccr0 */
    STM_0_CCR0    = (unsigned int)STM_0_CCR0_DISABLED;

    /* Clean count */
    STM_0_CNT   = (unsigned int)STM_0_CLEAN_CNT;

    /* Enabled STM0 */
    STM_0_CR    |= (unsigned int)STM_0_CR_TEN_ENABLED;
    /* Enabled ccr0 */
    STM_0_CCR0    |= (unsigned int)STM_0_CCR0_ENABLED;
    STM_0_ISR_Test_Cnt++;
    uint32 cnt_flag_1 = 100000;
    while(cnt_flag_1--)
    {
        uint32 cnt_flag_2 = 10000;
        while(cnt_flag_2--)
        {
            __asm("nop");
        }
    }
    STM_0_ISR_Test_Flg = 0;
    /* Clean flag */
    STM_0_CIR0  |= (unsigned int)STM_0_CIR0_CLEAN_IRQ_FLAG;
}

uint32 STM_1_ISR_Test_Cnt = 0;
uint32 STM_1_ISR_Test_Flg = 0;
ISR(STM_1_ISR)
{
    /* Disabled STM1 */
    STM_1_CR    = (unsigned int)STM_1_CR_TEN_DISABLED;
    /* Disabled ccr0 */
    STM_1_CCR0    = (unsigned int)STM_1_CCR0_DISABLED;

    /* Clean count */
    STM_1_CNT   = (unsigned int)STM_1_CLEAN_CNT;

    /* Enabled STM1 */
    STM_1_CR    |= (unsigned int)STM_1_CR_TEN_ENABLED;
    /* Enabled ccr0 */
    STM_1_CCR0    |= (unsigned int)STM_1_CCR0_ENABLED;
    STM_1_ISR_Test_Cnt++;
    if(1 == STM_0_ISR_Test_Flg)
    {
        STM_1_ISR_Test_Flg++;
    }
    /* Clean flag */
    STM_1_CIR0  |= (unsigned int)STM_1_CIR0_CLEAN_IRQ_FLAG;
}

void my_os_init(void)
{
    /* Interrupt the binding callback function */
    IntCtrl_Ip_InstallHandler(STM0_IRQn, STM_0_ISR, NULL_PTR);
    /* Set the interrupt priority */
    IntCtrl_Ip_SetPriority(STM0_IRQn, 4);
    /* Enable STM0 interrupt */
    IntCtrl_Ip_EnableIrq(STM0_IRQn);

    /* Clean count */
    STM_0_CNT    = (unsigned int)STM_0_CLEAN_CNT;
    /* Clean flag */
    STM_0_CIR0  |= (unsigned int)STM_0_CIR0_CLEAN_IRQ_FLAG;
    /* set cmp data */
    STM_0_CMP0   = (unsigned int)(133333 * 1000);
    /* Enabled STM0 */
    STM_0_CR    |= (unsigned int)STM_0_CR_TEN_ENABLED;
    /* Enabled ccr0 */
    STM_0_CCR0    |= (unsigned int)STM_0_CCR0_ENABLED;


    /* Interrupt the binding callback function */
    IntCtrl_Ip_InstallHandler(STM1_IRQn, STM_1_ISR, NULL_PTR);
    /* Set the interrupt priority */
    IntCtrl_Ip_SetPriority(STM1_IRQn, 3);
    /* Enable STM1 interrupt */
    IntCtrl_Ip_EnableIrq(STM1_IRQn);

    /* Clean count */
    STM_1_CNT    = (unsigned int)STM_1_CLEAN_CNT;
    /* Clean flag */
    STM_1_CIR0  |= (unsigned int)STM_1_CIR0_CLEAN_IRQ_FLAG;
    /* set cmp data */
    STM_1_CMP0   = (unsigned int)(133333);
    /* Enabled STM1 */
    STM_1_CR    |= (unsigned int)STM_1_CR_TEN_ENABLED;
    /* Enabled ccr0 */
    STM_1_CCR0    |= (unsigned int)STM_1_CCR0_ENABLED;
}

my_os.h

#ifndef _MY_OS_H_
#define _MY_OS_H_
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
extern void my_os_init(void);

#endif

 

5、添加头文件路径

6、加时钟初始化

 

int main(void)
{
    /* Write your code here */
    /* Initialize Clock */
    Clock_Ip_StatusType Status_Init_Clock = CLOCK_IP_ERROR;
    Status_Init_Clock = Clock_Ip_Init(Mcu_aClockConfigPB);

    if (Status_Init_Clock != CLOCK_IP_SUCCESS)
    {
        while(1); /* Error during initialization. */
    }

    my_os_init();

    for(;;)
    {
        if(exit_code != 0)
        {
            break;
        }
    }
    return exit_code;
}

 

7、跑起来

看到STM_1_ISR_Test_Flg累加 说明更高中断的任务来了,就会发生抢占。

S32G中中断优先级数值越小中断等级越高。

 

标签:抢占,Clock,int,STM,unsigned,任务,S32G3,os,define
From: https://www.cnblogs.com/JinShanCheShen/p/18334283

相关文章

  • 【YashanDB知识库】ycm纳管主机安装YCM-AGENT时报错“任务提交失败,无法连接主机”
    问题现象执行安装ycm-agent命令纳管主机时报错问题的风险及影响会导致ycm-agent纳管不成功,YCM无法监控主机和数据库问题影响的版本yashandb-cloud-manager-23.2.1.100-linux-aarch64.tar问题发生原因因为10.149.223.121对ycm的主机没有开放端口9070或9071解决方法及规避......
  • Tornado 添加任务的几种方式
    add_callback:功能:将一个普通的回调函数或者同步函数添加到事件循环中执行。特点:适合处理简单的任务,但要注意不要添加会阻塞事件循环的任务。示例:tornado.ioloop.IOLoop.current().add_callback(callback_function)spawn_callback:功能:将一个异步的协程函数(coroutinefu......
  • 前端实现【 批量任务调度管理器 】demo优化
    一、前提介绍我在前文实现过一个【批量任务调度管理器】的demo,能实现简单的任务批量并发分组,过滤等操作。但是还有很多优化空间,所以查找一些优化的库,主要想优化两个方面,上篇提到的:针对3,其实可以自己手写一个,也可以依靠如什么来实现。针对2,最难的是根据【当前系统负......
  • 如何查看Dask计算任务的进度?
    当我使用Dask运行计算任务时,我希望在Jupyter笔记本上看到进度条,我正在计算大型csv文件+4GB中id列的所有值,所以有什么想法吗?importdask.dataframeasdddf=dd.read_csv('data/train.csv')df.id.count().compute()可以使用progress方法来查......
  • 帝国CMS网站定时刷新任务用于定时生成指定页面的功能
    一、定时刷新任务介绍:用于定时生成指定页面的功能。 二、增加定时刷新任务1、登录后台,单击“系统”菜单,选择“管理刷新任务”子菜单,进入管理刷新任务界面:2、进入管理刷新任务界面,点击“增加刷新任务”按钮进入增加刷新任务界面:3、进入增加刷新任务......
  • Ansible忽略任务失败
    在默认情况下,任务失败时会中止剧本任务,不过可以通过忽略失败的任务来覆盖此类行为。在可能出错且不影响全局的段中使用ignore_errors关键词来达到目的。环境:受控主机清单文件:[dev]192.168.10.129[all:vars]ansible_ssh_user=rootansible_ssh_pass=123编写yum文件:以下测试......
  • 在工作线程中找到基于 Celery 类的任务,但在使用时得到 NotRegistered
    我像那样配置CeleryfromceleryimportCeleryfromsettings.configimportsettingscelery_app=Celery(broker=settings.RABBITMQ_URL,backend="rpc://",)celery_app.config_from_object(settings.CELERY_SETTINGS_MODULE)celery_app.autodiscov......
  • @Schedule定时任务和异步注解@Async时推荐自定义线程池
    1.原因@Schedule定时任务和异步注解@Async使用的默认线程池时, 池中允许的最大线程数和最大任务等待队列都是Integer.MAX_VALUE. 2.解决2.1、可以手动异步编排,交给某个线程池来执行。首先我们先向Spring中注入一个我们自己编写的线程池,参数自己设置即可,我这里比较随意。@C......
  • 使用celery进行异步处理和定时任务(django)
    一、celery的作用    celery是一个简单、灵活且可靠的分布式系统,用于处理大量消息,同时为操作提供一致的接口。它专注于实时操作,但支持任务调度。Celery主要用于异步任务处理,特别是在Web应用环境中,用于执行后台任务,如发送电子邮件、处理图片、视频转码、运行复杂的......
  • 在 Django 中构建动态任务和徽章评估系统
    模型任务classQuest(models.Model):name=models.CharField(max_length=255)description=models.TextField(blank=True)criteria=models.JSONField()#StorecriteriaasJSONreward_points=models.IntegerField(default=0)def__str_......