这个实时系统包含了操作系统所有最基本的接口
等等。绝对算是完整的操作系统。
并且源代码有所有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("Go\n");
添加自己的中断服务程序 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); }
参考链接