實驗目的:
1. 掌握ucos/II作業系統在ARM平臺上的移植
本次實驗使用ADS 集成開發環境,將uC/OS-II作業系統移植到我們的目標板上
1. 中斷服務程式在作業系統下的應用
2. 掌握ucos/II下中斷服務程式的流程和IPC的方法
本次實驗編寫一個串口中斷程式和一個應用程式,兩程式通過消息佇列通訊,串口中斷每接受到一個字元就發送一個消息給應用程式,應用 程 式每接受到一個消息,應用程式在串口列印一行字元。
#include "../ucos-ii/includes.h" /* uC/OS interface */
#include "../target/option.h"
#include "../target/2410lib.h"
#include "../drv/driver.h"
//task stack size
#ifdef SEMIHOSTED
#define TASK_STACK_SIZE (64+SEMIHOSTED_STACK_NEEDS)
#else
#define TASK_STACK_SIZE 10*1024
#endif
//Can task message queue
OS_EVENT *pCan_MsgQueue=0;
#define CAN_MSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan_MsgQueueTbl[CAN_MSG_QUEUE_SIZE];
#define SPIDMA_MSG_QUEUE_SIZE (1)
//Can task message queue
OS_EVENT *pSpiDma1Recv_MsgQueue=0;
void *paSpiDma1Recv_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pSpiDma1Send_MsgQueue=0;
void *paSpiDma1Send_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pSpiDma3Recv_MsgQueue=0;
void *paSpiDma3Recv_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pSpiDma3Send_MsgQueue=0;
void *paSpiDma3Send_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pCan_SendMsgQueue=0;
#define CAN_SENDMSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan_SendMsgQueueTbl[CAN_MSG_QUEUE_SIZE];
OS_EVENT *pCan1_SendMsgQueue=0;
#define CAN1_SENDMSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan1_SendMsgQueueTbl[CAN_MSG_QUEUE_SIZE];
OS_EVENT *pCan2_SendMsgQueue=0;
#define CAN2_SENDMSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan2_SendMsgQueueTbl[CAN_MSG_QUEUE_SIZE];
//can1 task QUEUE
OS_EVENT *g_pOS_MsgQ_CHANNEL1=0;
#define CANCHANNEL1_MSG_QUEUE_SIZE (256*4*5)
void *paCANCHANNEL1_MsgQueueTbl[CANCHANNEL1_MSG_QUEUE_SIZE];
//can2 task QUEUE
OS_EVENT *g_pOS_MsgQ_CHANNEL2=0;
#define CANCHANNEL2_MSG_QUEUE_SIZE (256*4*5)
void *paCANCHANNEL2_MsgQueueTbl[CANCHANNEL2_MSG_QUEUE_SIZE];
//LCD task QUEUE
OS_EVENT *pLcdTask_MsgQueue=0;
#define LCDTASK_MSG_QUEUE_SIZE (256*4*5)
void *paLCD_MsgQueueTbl[LCDTASK_MSG_QUEUE_SIZE];
OS_STK Uart_Stack[TASK_STACK_SIZE];
extern void Uart_Task(void *Id);
#define UART_PRIO 18
OS_EVENT *pUart_MsgQueue=0;
#define Uart_MSG_QUEUE_SIZE (256 )
void *paUart_MsgQueueTbl[Uart_MSG_QUEUE_SIZE];
//Main Task
OS_STK Main_Stack[TASK_STACK_SIZE]= {0, };
extern void Main_Task(void *Id);
#define Main_PRIO 8
//Lcd Task
OS_STK LcdTask_Stack[TASK_STACK_SIZE]= {0, };
extern void Lcd_Task(void *Id);
#define LcdTask_PRIO 19
//Task1
OS_STK Task1_Stack[TASK_STACK_SIZE]= {0, };
extern void Task1_Task(void *Id);
#define Task1_PRIO 20
//Task2
OS_STK Task2_Stack[TASK_STACK_SIZE]= {0, };
extern void Task2_Task(void *Id);
#define Task2_PRIO 21
//Task3
OS_STK Task3_Stack[TASK_STACK_SIZE]= {0, };
extern void Task3_Task(void *Id);
#define Task3_PRIO 22
//Task definition
//Can task
void Task1_Task(void *Id)
{
int i;
while(1)
{
i++;
Uart_Printf("This is task 1.\n");
OSTimeDly(10);
}
}
void Task2_Task(void *Id)
{
int i;
while(1)
{
i++;
Uart_Printf("This is task 2.\n");
OSTimeDly(20);
}
}
void Task3_Task(void *Id)
{
int i;
while(1)
{
i++;
Uart_Printf("This is task 3.\n");
OSTimeDly(30);
}
}
STRU_TOUCH_MSG StruMsg_Uart;
void Uart_Task(void *Id)
{
// static INT32U ulTimes = 0;
INT8U err;
void *pMsg;
STRU_UART_MSG* uartmsg;
char c;
while(1)
{
Uart_Printf("Please input char:\n");
pMsg = OSQPend(pUart_MsgQueue, 0, &err);
uartmsg=(STRU_UART_MSG*)pMsg;
c=uartmsg->ulPara1;
Uart_Printf("We get %d\n",c);
}
}
void Main_Task(void *Id)
{
//OSStatInit();
/* Start the S3C44B0X BSP Running */
ARMTargetStart();
OSTaskCreate(Task1_Task, (void *)0, (OS_STK *)&Task1_Stack[TASK_STACK_SIZE-1],
Task1_PRIO);
OSTaskCreate(Task2_Task, (void *)0, (OS_STK *)&Task2_Stack[TASK_STACK_SIZE-1],
Task2_PRIO);
OSTaskCreate(Task3_Task, (void *)0, (OS_STK *)&Task3_Stack[TASK_STACK_SIZE-1],
Task3_PRIO);
OSTaskCreate(Uart_Task, (void *)0, (OS_STK *)&Uart_Stack[TASK_STACK_SIZE-1],
UART_PRIO);
OSTaskCreate(Uart_Task, (void *)0, (OS_STK *)&Uart_Stack[TASK_STACK_SIZE-1],
UART_PRIO);
while (1)
{
Uart_Printf("This is Main task.\n");
OSTimeDly(40);
}
}
//===================================================================
void Main(void)
{
Led_Display(15);
// MMU_Init();
#if ADS10
__rt_lib_init(); //for ADS 1.x
#endif
ChangeClockDivider(1,1); // 1:2:4
ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
ARMTargetInit();
// Init uCOS-II
OSInit();
pUart_MsgQueue = OSQCreate(&paUart_MsgQueueTbl[0], Uart_MSG_QUEUE_SIZE);
OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[TASK_STACK_SIZE-1],
Main_PRIO);
OSStart();
}
void PrintfBanner()
{
Uart_Printf("(1)Start CAN1 Send\n");
Uart_Printf("(2)Stop CAN1 Send\n");
Uart_Printf("(3)Start CAN2 Send\n");
Uart_Printf("(4)Stop CAN2 Send\n");
}
#include "../ucos-ii/includes.h" /* uC/OS interface */
#include "../target/option.h"
#include "../target/2410lib.h"
#include "../drv/driver.h"
//task stack size
#ifdef SEMIHOSTED
#define TASK_STACK_SIZE (64+SEMIHOSTED_STACK_NEEDS)
#else
#define TASK_STACK_SIZE 10*1024
#endif
//Can task message queue
OS_EVENT *pCan_MsgQueue=0;
#define CAN_MSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan_MsgQueueTbl[CAN_MSG_QUEUE_SIZE];
#define SPIDMA_MSG_QUEUE_SIZE (1)
//Can task message queue
OS_EVENT *pSpiDma1Recv_MsgQueue=0;
void *paSpiDma1Recv_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pSpiDma1Send_MsgQueue=0;
void *paSpiDma1Send_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pSpiDma3Recv_MsgQueue=0;
void *paSpiDma3Recv_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pSpiDma3Send_MsgQueue=0;
void *paSpiDma3Send_MsgQueueTbl[SPIDMA_MSG_QUEUE_SIZE];
//Can task message queue
OS_EVENT *pCan_SendMsgQueue=0;
#define CAN_SENDMSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan_SendMsgQueueTbl[CAN_MSG_QUEUE_SIZE];
OS_EVENT *pCan1_SendMsgQueue=0;
#define CAN1_SENDMSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan1_SendMsgQueueTbl[CAN_MSG_QUEUE_SIZE];
OS_EVENT *pCan2_SendMsgQueue=0;
#define CAN2_SENDMSG_QUEUE_SIZE (256 * 4 * 2)
void *paCan2_SendMsgQueueTbl[CAN_MSG_QUEUE_SIZE];
//can1 task QUEUE
OS_EVENT *g_pOS_MsgQ_CHANNEL1=0;
#define CANCHANNEL1_MSG_QUEUE_SIZE (256*4*5)
void *paCANCHANNEL1_MsgQueueTbl[CANCHANNEL1_MSG_QUEUE_SIZE];
//can2 task QUEUE
OS_EVENT *g_pOS_MsgQ_CHANNEL2=0;
#define CANCHANNEL2_MSG_QUEUE_SIZE (256*4*5)
void *paCANCHANNEL2_MsgQueueTbl[CANCHANNEL2_MSG_QUEUE_SIZE];
//LCD task QUEUE
OS_EVENT *pLcdTask_MsgQueue=0;
#define LCDTASK_MSG_QUEUE_SIZE (256*4*5)
void *paLCD_MsgQueueTbl[LCDTASK_MSG_QUEUE_SIZE];
OS_STK Uart_Stack[TASK_STACK_SIZE]= {0, };
extern void Uart_Task(void *Id);
#define UART_PRIO 18
OS_EVENT *pUart_MsgQueue=0;
#define Uart_MSG_QUEUE_SIZE (256 )
void *paUart_MsgQueueTbl[Uart_MSG_QUEUE_SIZE];
//Main Task
OS_STK Main_Stack[TASK_STACK_SIZE]= {0, };
extern void Main_Task(void *Id);
#define Main_PRIO 8
//Lcd Task
OS_STK LcdTask_Stack[TASK_STACK_SIZE]= {0, };
extern void Lcd_Task(void *Id);
#define LcdTask_PRIO 19
//Task1
OS_STK Task1_Stack[TASK_STACK_SIZE]= {0, };
extern void Task1_Task(void *Id);
#define Task1_PRIO 20
//Task2
OS_STK Task2_Stack[TASK_STACK_SIZE]= {0, };
extern void Task2_Task(void *Id);
#define Task2_PRIO 21
//Task3
OS_STK Task3_Stack[TASK_STACK_SIZE]= {0, };
extern void Task3_Task(void *Id);
#define Task3_PRIO 22
//Task definition
//Can task
void Task1_Task(void *Id)
{
int i;
while(1)
{
i++;
Uart_Printf("This is task 1.\n");
OSTimeDlyHMSM(0,0,1,0);
}
}
void Task2_Task(void *Id)
{
int i;
while(1)
{
i++;
Uart_Printf("This is task 2.\n");
OSTimeDlyHMSM(0,0,4,0);
}
}
void Task3_Task(void *Id)
{
int i;
while(1)
{
i++;
Uart_Printf("This is task 3.\n");
OSTimeDlyHMSM(0,0,6,0);
}
}
STRU_TOUCH_MSG StruMsg_Uart;
void
Uart_Task(void *Id)
{
// static INT32U ulTimes = 0;
INT8U err;
void *pMsg;
STRU_UART_MSG* uartmsg;
char c;
while(1)
{
Uart_Printf("Please input char:\n");
pMsg = OSQPend(pUart_MsgQueue, 0, &err);
uartmsg=(STRU_UART_MSG*)pMsg;
c=uartmsg->ulPara1;
Uart_Printf("We get %c\n",c);
}
}
void Main_Task(void *Id)
{
//OSStatInit();
/* Start the S3C44B0X BSP Running */
ARMTargetStart();
OSTaskCreate(Task1_Task, (void *)0, (OS_STK *)&Task1_Stack[TASK_STACK_SIZE-1],
Task1_PRIO);
OSTaskCreate(Task2_Task, (void *)0, (OS_STK *)&Task2_Stack[TASK_STACK_SIZE-1],
Task2_PRIO);
OSTaskCreate(Task3_Task, (void *)0, (OS_STK *)&Task3_Stack[TASK_STACK_SIZE-1],
Task3_PRIO);
OSTaskCreate(Uart_Task, (void *)0, (OS_STK *)&Uart_Stack[TASK_STACK_SIZE-1],
UART_PRIO);
//OSTaskCreate(Uart_Task, (void *)0, (OS_STK *)&Uart_Stack[TASK_STACK_SIZE-1],
UART_PRIO);
while (1)
{
Uart_Printf("This is Main task.\n");
OSTimeDlyHMSM(0,0,14,0);
}
}
//===================================================================
void Main(void)
{
Led_Display(15);
// MMU_Init();
#if ADS10
__rt_lib_init(); //for ADS 1.x
#endif
ChangeClockDivider(1,1); // 1:2:4
ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
ARMTargetInit();
// Init uCOS-II
OSInit();
pUart_MsgQueue = OSQCreate(&paUart_MsgQueueTbl[0], Uart_MSG_QUEUE_SIZE);
OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[TASK_STACK_SIZE-1],
Main_PRIO);
OSStart();
}
void PrintfBanner()
{
Uart_Printf("(1)Start CAN1 Send\n");
Uart_Printf("(2)Stop CAN1 Send\n");
Uart_Printf("(3)Start CAN2 Send\n");
Uart_Printf("(4)Stop CAN2 Send\n");
}