在线时间55 小时
UID2005772
注册时间2013-4-28
NXP金币0
该用户从未签到
高级会员
- 积分
- 748
- 最后登录
- 1970-1-1
|
本帖最后由 安臣 于 2015-11-5 17:07 编辑
看官方例程的时候接触到rtx 。 有例程可以参考,所以自己也试着做一个自己的程序。
一, 搜资料了解了一下trx系统
关于 rtx 的官网 介绍连接。http://www.keil.com/rl-arm/kernel.asp
二、建立自己的工程文件。
三、我自己的代码
- #include "MK64F12.h"
- #include "cmsis_os.h"
- osThreadId tid_phaseA; /* Thread id of thread: phase_a */
- osThreadId tid_phaseB; /* Thread id of thread: phase_b */
- osThreadId tid_clock; /* Thread id of thread: clock */
- uint32_t LEDOn, LEDOff;
- void led_init(void)
- {
- SIM->SCGC5 |= ((1UL << 13) | (1UL << 10)); /* Enable Port B,E Clock */
- PORTB->PCR[22] = (1UL << 8); /* PTB22 is GPIO pin */
-
- PTB->PDOR = (1UL << 22);
- PTB->PDDR = (1UL << 22);
- }
- /*----------------------------------------------------------------------------
- Function that turns on Red LED
- *----------------------------------------------------------------------------*/
- void LEDRed_On (void) {
- PTB->PCOR = 1UL << 22;
- }
- /*----------------------------------------------------------------------------
- Function that turns off Red LED
- *----------------------------------------------------------------------------*/
- void LEDRed_Off (void) {
- PTB->PSOR = 1UL << 22;
- }
- /*----------------------------------------------------------------------------
- * Function 'signal_func' called from multiple threads
- *---------------------------------------------------------------------------*/
- void signal_func (osThreadId tid) {
- osSignalSet(tid_clock, 0x0100); /* set signal to clock thread */
- osDelay(500); /* delay 500ms */
- osSignalSet(tid_clock, 0x0100); /* set signal to clock thread */
- osDelay(500); /* delay 500ms */
- osSignalSet(tid, 0x0001); /* set signal to thread 'thread' */
- osDelay(500); /* delay 500ms */
- }
- /*----------------------------------------------------------------------------
- * Thread 1 'phaseA': Phase A output
- *---------------------------------------------------------------------------*/
- void phaseA (void const *argument) {
- for (;;) {
- osSignalWait(0x0001, osWaitForever); /* wait for an event flag 0x0001 */
- LEDRed_On();
- osDelay(500); /* delay 500ms */
- signal_func(tid_phaseA); /* call common signal function */
- }
- }
- /*----------------------------------------------------------------------------
- * Thread 2 'phaseB': Phase B output
- *---------------------------------------------------------------------------*/
- void phaseB (void const *argument) {
- for (;;) {
- osSignalWait(0x0001, osWaitForever); /* wait for an event flag 0x0001 */
- LEDRed_Off();
- osDelay(500); /* delay 500ms */
- //signal_func(tid_phaseA); /* call common signal function */
- }
- }
- /*----------------------------------------------------------------------------
- * Thread 5 'clock': Signal Clock
- *---------------------------------------------------------------------------*/
- void clock (void const *argument) {
- for (;;) {
- osSignalWait(0x0100, osWaitForever); /* wait for an event flag 0x0100 */
- LEDRed_Off();
- osDelay(200); /* delay 200ms */
- }
- }
- osThreadDef(phaseA, osPriorityNormal, 1, 0);
- //osThreadDef(phaseB, osPriorityNormal, 1, 0);
- osThreadDef(clock, osPriorityNormal, 1, 0);
- int main()
- {
- led_init();
- tid_phaseA = osThreadCreate(osThread(phaseA), NULL);
- //tid_phaseB = osThreadCreate(osThread(phaseB), NULL);
- tid_clock = osThreadCreate(osThread(clock), NULL);
- osSignalSet(tid_phaseA, 0x0001); /* set signal to phaseA thread */
- osDelay(osWaitForever);
- while(1)
- {
- //
- }
- }
复制代码
四。代码打包分享
rtos_led.zip
(582.09 KB, 下载次数: 45)
|
|