历史上的今天
今天是:2025年01月16日(星期四)
2020年01月16日 | STM8的福利--Atomthreads实时操作系统
2020-01-16 来源:eefocus
Atomthreads是开源的实时操作系统。诞生之初就是给STM8s设计的,而且作者还在不断更新,我看最近的主要修改是加入更多MCU的支持。算法上没有变化。所以我取了1.3的版本,足够用了。
我使用的是STM8S105K4的最小系统。有16Kflash可以使用。这个大小放下原生的atomthreads是够的。
这个实时系统包含了操作系统所有最基本的接口
mutex
semaphore
timer
queue
255级优先级的强占是调度
同优先级时间片轮转
等等。绝对算是完整的操作系统。
并且源代码有所有API调用的例子,这绝对是福利,节约大家时间。要造汽车,绝对不需要每次都从车轮造起。当今世界要站在巨人的肩膀上前进。
回到atomthreads的内部,它需要一个心跳timer,系统默认使用了TIM1这个STM8中功能最强的timer。如果你的系统中要用TIM1做更复杂的事情,那么你可以改用其他的TIM2/TIM3来做心跳。
NO_REG_SAVE void main ( void )
{
int8_t status;
/**
* Note: to protect OS structures and data during initialisation,
* interrupts must remain disabled until the first thread
* has been restored. They are reenabled at the very end of
* the first thread restore, at which point it is safe for a
* reschedule to take place.
*/
/* Initialise the OS before creating our threads */
status = atomOSInit(&idle_thread_stack[IDLE_STACK_SIZE_BYTES - 1], IDLE_STACK_SIZE_BYTES);
if (status == ATOM_OK)
{
/* Enable the system tick timer */
archInitSystemTickTimer();
/* Create an application thread */
status = atomThreadCreate(&main_tcb,
TEST_THREAD_PRIO, main_thread_func, 0,
&main_thread_stack[MAIN_STACK_SIZE_BYTES - 1],
MAIN_STACK_SIZE_BYTES);
if (status == ATOM_OK)
{
/**
* First application thread successfully created. It is
* now possible to start the OS. Execution will not return
* from atomOSStart(), which will restore the context of
* our application thread and start executing it.
*
* Note that interrupts are still disabled at this point.
* They will be enabled as we restore and execute our first
* thread in archFirstThreadRestore().
*/
atomOSStart();
}
}
/* There was an error starting the OS if we reach here */
while (1)
{
}
}
另外内核默认是会打印debug message。提供printf函数。底层是通过UART2实现。所以调试atomthreads,你需要把UART接出来,通过PL2303转接到PC USB。
static void main_thread_func (uint32_t param)
{
uint32_t test_status;
int sleep_ticks;
/* Compiler warnings */
param = param;
/* Initialise UART (9600bps) */
if (uart_init(9600) != 0)
{
/* Error initialising UART */
}
/* Put a message out on the UART */
printf("Gon");
添加自己的中断服务程序 ISR,要注意,在进入和退出时,分别调用atomIntEnter()和atomIntExit(TRUE)。这两个函数时系统调度器要用到的
#if defined(__IAR_SYSTEMS_ICC__)
#pragma vector = 13
#endif
INTERRUPT void TIM1_SystemTickISR (void)
#if defined(__RCSTM8__)
interrupt 11
#endif
{
/* Call the interrupt entry routine */
atomIntEnter();
/* Call the OS system tick handler */
atomTimerTick();
/* Ack the interrupt (Clear TIM1:SR1 register bit 0) */
TIM1->SR1 = (uint8_t)(~(uint8_t)TIM1_IT_UPDATE);
/* Call the interrupt exit routine */
atomIntExit(TRUE);
}
另外atomthreads的底层硬件操作实际是调用意法半导体的标准库函数。只不过作者为了让代码精简,只拿出了用到的函数。

为了对代码管理,本人在Kelvin Lawson的基础上开发了自己的分支。又由于我主要使用IAR编译器,所有所有的修改都基于这个开发环境。
上一篇:stm8L051使用库建工程
史海拾趣
|
模拟信号都好采集,但是有的传感器是BCD码输出的,每个传感器的引脚是24条线输出,有4个,请问怎么设计和选型? 这里面可能要用到数据选择器或者寄存器;还有USB控制器… 查看全部问答> |
|
我的手机有一个摄像头,而且可以以USB接口连接到桌面计算机上,作为摄像头使用。请问怎样在WinCE设备里也可以这样用呢?需要怎样开发相关驱动?… 查看全部问答> |
|
诚聘单片机设计工程师: 1,会msp430,有设计经验 2,有msp430 C语言开发经验 3,懂信号处理,会用matlab 4,最好有工作经验1年以上 电话:010-81504648 公司网站:www.safezx.com 注:工作地点北京… 查看全部问答> |
|
请教,我用ads1.2编译c++程序总是报一些头文件找不到,我把system path加了vc的库,结果有出了“only win32 and Mac supported\"这个问题,请问怎么办?ads1.2上可以编译c++吗?要怎么做? … 查看全部问答> |
|
本人刚刚接触嵌入式开发,遇到一些问题请各位高手赐教: 1.如何通过未定义指令陷阱支持协处理器的软件仿真 2.ARM处理器如何利用未定义指令的中断机制仿真浮点向量运算… 查看全部问答> |
|
#include #include \"sys.h\" #include \"delay.h\" #include \"7279.h\" unsigned char Keynum; /****************************************************************************** 函数名:7279_WriteByte 输 入:dat:一 ...… 查看全部问答> |




