⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 嵌入式操作系统EOS(Embedded OperatingSystem)是一种用途广泛的系统软件
💻 C
字号:
#include <XC167.h>
//#include "general_definitions.h"
#include "rtos_services.h"
//#include "system_messages.h"
//#include "synchronization.h"
//#include "queue.h"
//#include "stdio.h"
//#include "usb.h"
#include "trace_buffer.h"

/*static stacktype task1_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task2_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task3_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task4_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task5_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task6_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task7_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)
static stacktype task8_stack[DEFUALT_STACK_SIZE] ; // note: user stack + processor stack (as system stack defined in A66 file * 2)

static int32s m1, m2, m3, t1id, t2id, t3id, t4id, t5id, t6id, t7id, t8id, t9id, t10id, s1 ;
static int32s t1, t2, t3, t4, t5 ;
static int32s rxMsg = 0, txMsg = 0 ;

void ISR0x25callback()
{
	//printf("ISR0x25callback\n") ;
}


void task2()
{
	//int32s msg ;

	while (1)
	{
		//if ( rtos_msg_wait(&msg, SEC_TO_CPU_TICKS(3) ) == ERR_MSG_WAIT_TIMEOUT_ELAPSED)
		//{
			if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
			{
				printf("task2 timed-out\n") ;
				scheduler_task_wait( MILLISECONDS(2000)) ;
				rtos_mutex_unlock(m1) ;
			}
		//}
		//else
		//{
			if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
			{
				printf("task2 received %ld\n", msg) ;

				scheduler_task_wait( MILLISECONDS(2000)) ;
				rtos_mutex_unlock(m1) ;
			}
		//}
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task2\n") ;
			//scheduler_task_wait( MILLISECONDS(1)) ;
			//trace_buffer_insert(2) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
		}
		//scheduler_task_suspend(t1id) ;
	}	  
}

void task1()
{
	//int32s msg = 0 ;

	while (1)
	{
		//rtos_post_task_msg(t2id, msg) ;
		if (rtos_mutex_lock(m1) != ERR_MUTEX_NOT_FOUND)
		{
			printf("task1 sent %ld\n", msg) ;
			scheduler_task_wait( MILLISECONDS(2000)) ;
			rtos_mutex_unlock(m1) ;
		}
		//scheduler_task_wait( MILLISECONDS(10)) ;
		//msg++ ;
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task1\n") ;
			//scheduler_task_wait( MILLISECONDS(1)) ;
			//trace_buffer_insert(1) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
		} 
		//rtos_interrupt_wait(0x25, ISR0x25callback, 0) ;
		//printf("task1\n") ;
		
		scheduler_task_wait( MILLISECONDS(500)) ;
		
	}
}

void task3()
{
	while (1)
	{
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task3\n") ;
			//scheduler_task_wait( MILLISECONDS(1)) ;
			//trace_buffer_insert(3) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
		}
	}
}

void task4()
{
	while (1)
	{
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task4\n") ;
			//trace_buffer_insert(4) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
		}
	}
}

void task5()
{
	while (1)
	{
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task5\n") ;
			//scheduler_task_wait( MILLISECONDS(1)) ;
			//trace_buffer_insert(5) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
		}
	}
}

void task6()
{
	while (1)
	{
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task6\n") ;
			//scheduler_task_wait( MILLISECONDS(1)) ;
			//trace_buffer_insert(6) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
		}
	}
}

void task7()
{
	while (1)
	{
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task7\n") ;
			//scheduler_task_wait( MILLISECONDS(1)) ;
			//trace_buffer_insert(7) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
		}
	}
}

void task8()
{
	while (1)
	{
		if (rtos_mutex_lock(m2) != ERR_MUTEX_NOT_FOUND)
		{
			//printf("task8\n") ;
			//scheduler_task_wait( MILLISECONDS(1)) ;
			//trace_buffer_insert(8) ;
			scheduler_task_wait( SECONDS(1)) ;
			rtos_mutex_unlock(m2) ;
			//software_error("%s %s %d", resolve_system_message(ERR_TASK_NOT_FOUND), __FILE__, __LINE__ ) ;
		}
	}
}

void timer1(int32s param)
{
    param = 0 ;
	//P6 = ( ((P6 & 1) == 1) ? (P6 & 0xFFFE) : (P6 | 1) ) ;
	//scheduler_set_task_priority(t1id, PRIORITY_0) ;
}

void timer2(int32s param)
{
    param = 0 ;
}
*/
void s_system_failure_callback(int32s p)
{
    p = 0 ;
	trace_buffer_transmit() ;
}

void main()
{
 	rtos_init(s_system_failure_callback) ;

	// simulate hardware 'startup' time
	//printf("hardware initializing\n") ;
	//scheduler_////////scheduler_task_wait(SEC_TO_CPU_TICKS(1) ) ;
	//printf("hardware finished initializing\n") ;
	
	/*t1id = scheduler_create_task(task1, DEFAULT_TASK_PRIORITY, task1_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	t2id = scheduler_create_task(task2, DEFAULT_TASK_PRIORITY, task2_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	t3id = scheduler_create_task(task3, DEFAULT_TASK_PRIORITY, task3_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	t4id = scheduler_create_task(task4, DEFAULT_TASK_PRIORITY, task4_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	t5id = scheduler_create_task(task5, DEFAULT_TASK_PRIORITY, task5_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	t6id = scheduler_create_task(task6, DEFAULT_TASK_PRIORITY, task6_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	t7id = scheduler_create_task(task7, DEFAULT_TASK_PRIORITY, task7_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	t8id = scheduler_create_task(task8, DEFAULT_TASK_PRIORITY, task8_stack, DEFUALT_STACK_SIZE, eTaskReady) ;*/
	//t9id = scheduler_create_task(task9, DEFAULT_TASK_PRIORITY, task9_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	//t10id = scheduler_create_task(task10, DEFAULT_TASK_PRIORITY, task10_stack, DEFUALT_STACK_SIZE, eTaskReady) ;
	
	/*GPT12E_T5CON          =  0x0007;      // load timer 5 control register
  	GPT12E_T5             =  0x676A;      // load timer 5 register
  	GPT12E_T5IC           =  IC_IE(1) | IC_ILVL(2) | IC_GLVL(5) ;
  	GPT12E_T5IC_IR  	  =  0;           // timer 5 run bit is set

	m1 = rtos_allocate_mutex() ;
	m2 = rtos_allocate_mutex() ;*/
	//s1 = rtos_allocate_semaphore(2) ;
	
	//t1 = rtos_allocate_timer() ;
	//t2 = rtos_allocate_timer() ;
	//t3 = rtos_allocate_timer() ;
	//t4 = rtos_allocate_timer() ;
	//t5 = rtos_allocate_timer() ;
	
	//rtos_callback_timer_inform_every(t1, SECONDS(1), timer1, 0) ;
	//rtos_callback_timer_inform_every(t2, MILLISECONDS(100), timer2) ;
	//rtos_callback_timer_inform_every(t3, MILLISECONDS(100), timer1) ;
	//rtos_callback_timer_inform_every(t4, MILLISECONDS(100), timer2) ;
	//rtos_callback_timer_inform_every(t5, MILLISECONDS(100), timer1) ;
	scheduler_start() ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -