硬汉嵌入式论坛

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

[STM32H7] RTX5中自定义使用SVC中断方法

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107157
QQ
发表于 2019-12-2 12:38:41 | 显示全部楼层 |阅读模式

2020-04-15升级版发此贴:

烧脑子,分享RTX5的自定义SVC软中断两种实现方法,直接调用__svc_indirect弹了一天的bug,折磨死人
http://www.armbbs.cn/forum.php?mod=viewthread&tid=97322




SVC 的0号系统服务被 RTX5 系统占用,即 SVC 0,当前列出的SVC0_X都是用的SVC 0中断。
而用户可以使用从 1 开始的服务号。使用的时候要保证从 1 开始,连续递增使用,范围 1 – 255。

#define SVC1_0N(f,t)                                                           \
__SVC_INDIRECT(1) t    svc##f (t(*)());                                        \
__attribute__((always_inline))                                                 \
__STATIC_INLINE   t  __svc##f (void) {                                         \
  svc##f(svcUser##f);                                                           \
}

void * const osRtxUserSVC[1] = { 此处写入函数名 };
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107157
QQ
 楼主| 发表于 2019-12-2 12:39:00 | 显示全部楼层
【已更新】RTX5中SVC软中断和C连接符##的高级玩法
http://www.armbbs.cn/forum.php?m ... 3396&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

5

主题

179

回帖

194

积分

初级会员

积分
194
发表于 2019-12-2 13:35:20 | 显示全部楼层
CMSIS帮助手册中有说明

To implement SVC functions in your Keil RTX5 project, you need to:

Add the SVC User Table file svc_user.c to your project folder and include it into your project. This file is available as a user code template.
Write a function implementation. Example:
uint32_t svc_atomic_inc32 (uint32_t *mem) {
  // A protected function to increment a counter.
  uint32_t val;
   
  __disable_irq();
  val  = *mem;
  (*mem) = val + 1U;
  __enable_irq();
   
  return (val);
}
Add the function to the SVC function table in the svc_user.c module:
void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
  (void *)USER_SVC_COUNT,
  (void *)svc_atomic_inc32,
};
Increment the number of user SVC functions:
#define USER_SVC_COUNT  1       // Number of user SVC functions
Declare a function wrapper to be called by the user to execute the SVC call.
Code Example (Arm Compiler 6)

__STATIC_FORCEINLINE uint32_t atomic_inc32 (uint32_t *mem) {
  register uint32_t val;
      
  __ASM volatile (
    "svc 1" : "=l" (val) : "l" (mem) : "cc", "memory"
  );
  return (val);
}
Code Example (Arm Compiler 5 using __svc(x) attribute)

uint32_t atomic_inc32 (uint32_t *mem) __svc(1);
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107157
QQ
 楼主| 发表于 2019-12-2 16:06:03 | 显示全部楼层
soga238 发表于 2019-12-2 13:35
CMSIS帮助手册中有说明

To implement SVC functions in your Keil RTX5 project, you need to:

谢谢,楼主位的也挺方便,实测可用。
回复

使用道具 举报

3

主题

11

回帖

20

积分

新手上路

积分
20
发表于 2020-4-12 15:24:36 | 显示全部楼层
soga238 发表于 2019-12-2 13:35
CMSIS帮助手册中有说明

To implement SVC functions in your Keil RTX5 project, you need to:

你好,我使用这种总是出错,可不可以发一份模板?谢谢了
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-21 07:45 , Processed in 0.154490 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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