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

📄 test.c

📁 uCOSII code for Coldfire processor
💻 C
字号:
/********************************************************************/
/**  Program : Test                                                **/
/**                                                                **/
/**  Description : This program is a quick test of the ColdFire    **/
/**  port of Jean Labrosse's uC/OS a simple real time OS. This     **/
/**  progam is intended to run on an Arnewsh SBC5206 eval board    **/
/**  and compile using GNU C for the ColdFire MCF5206.             **/
/**                                                                **/
/**  Credits:                                                      **/
/**    Jean Labrosse - for the original uC/OS                      **/
/**    Barry Braksick - for the Motorola CPU32 port which gave me  **/
/**                     a lot of pointers for the ColdFire         **/
/**    Micahel Garret - for the Hitachi SH1 port which I borrowed  **/
/**                     this test program from and how to write    **/
/**                     simple GNU make files.....                 **/
/**                                                                **/
/**  Version History :                                             **/
/**                                                                **/
/**  A0.01     Initial version started                   15/09/97  **/
/**  A0.02     First Demo release to ColdFire maillist   13/11/97  **/
/**            (ColdFire@wildrice.com)                             **/
/**                                                                **/
/** Copyright (c) 1997 David Fiddes, D.J.Fiddes@hw.ac.uk           **/
/********************************************************************/

#include <stdio.h>
#include "sim5206.h"           /*on-chip register definitions*/
#include "includes.h"

typedef struct
{
  unsigned long table[255];
} vectors;

vectors *vect; //CPU Exception vectors
SIM5206 *sim;  //System integration module

#define TASK_STK_SIZE   512
#define Q1_SIZE 8


#define          OS_MAX_TASKS    10
OS_TCB           OSTCBTbl[OS_MAX_TASKS];

/** Application Stack "variables" including the system IdleTask **/
asm(" .align 4"); //Make sure they're 4 byte aligned to keep the ColdFire happy

ULONG   OSIdleTaskStk[TASK_STK_SIZE];
ULONG   Task1Stk[TASK_STK_SIZE];
ULONG   Task2Stk[TASK_STK_SIZE];
ULONG   Task3Stk[TASK_STK_SIZE];

OS_SEM    MySem;
OS_Q      MyQueue;
void      *Q1[Q1_SIZE];


void DumpTCBs( void )
{
  int index;
  printf("\n");
  OS_ENTER_CRITICAL()
  for ( index = 0; index < OS_MAX_TASKS; index++)
  {
    printf("OSTCBTbl[%i]\n",index);
    printf("  OSTCBStkPtr = %p\n",OSTCBTbl[index].OSTCBStkPtr);
    printf("  OSTCBStat = %i\n",OSTCBTbl[index].OSTCBStat);
    printf("  OSTCBPrio = %i\n",OSTCBTbl[index].OSTCBPrio);
    printf("  OSTCBDly = %i\n",OSTCBTbl[index].OSTCBDly);
  }
  OS_EXIT_CRITICAL()
}
 
/********************************************************************/
/**  The actual multitasked code starts here                       **/

void Task1(void* pdata)
{
    UBYTE err;
    BOOLEAN LedOn;
    
    LedOn = FALSE;
    
    printf("Hi, I'm Task1!\n\n");
    printf("Dumping the OS task control blocks to \"prove\" that we're multitasking!\n");
    DumpTCBs();
    
    for(;;)
    {
        err = OSSemPend(&MySem, 0);
        
        if (LedOn==TRUE)
        {
          printf("Led On\n");
          LedOn = FALSE;
        }
        else
        {
          printf("Led Off\n");
          LedOn = TRUE;
        }  

    }
}

void Task2(void* pdata)
{
    long  qmsg;
    ULONG count;
    UBYTE err;
    count = 0;
    for(;;)
    {
        OSTimeDly(50);
        qmsg = count++;
        err = OSQPost(&MyQueue,(void*)qmsg);

    }
}

void Task3(void* pdata)
{
    long qdata;
    long passed_data;
    UBYTE err;
    passed_data = (long)pdata;

    for(;;)
    {
        qdata = (long)OSQPend(&MyQueue, 0, &err);
        if(qdata >= 100)  /* use data somehow */
        {
            if(passed_data++ == 2000) asm("nop");
        }
        OSSemPost(&MySem);
    }
}

/**  The multitasked code ends here                                **/
/********************************************************************/


void CPUWrtVBR( void )
{
  asm volatile (" 
                  CLR.L	%D0	
	          MOVE.L	%a7,%d1		
	          MOVE.L	%d0,%a7		
	          MOVEC	        %a7,%VBR		
	          MOVE.L	%d1,%a7	

  "); 
}


void DisableCache( void )
{
  asm("	nop						| sync
	move.l	#0x01000000,%d0
	dc.l	0x4e7b0002		| movec d0,cacr
	nop						| sync
	dc.l	0x4e7b0002		| movec d0,cacr
	nop ");
}


void EnableCache( void )
{
  asm(" nop
        move.l  #0x80000000,%d0
	dc.l	0x4e7b0002		| movec d0,cacr
	nop ");
}


void HardwareSetup( void )
{
  vect = (vectors *)0x00000000;
  sim = (SIM5206 *)0x10000000;
  
  printf("Setting Vector Base REgister(VBR) and exception handlers...\n");
  CPUWrtVBR(); //set vbr
  
  vect->table[25+4] = (long)&OSTickISR; //AutoVector 5 - Timer tick
  vect->table[32+14] = (long)&OSCtxSw;  //Trap 14 - Do a context switch
  
  sim->imr = 0x3DFE; //sim->imr&(~0x0200); //enable timer1 interrupts
  
  printf("Reseting Timer...\n");
// Reset Timer

  sim->timer1.tmr = sim->timer1.tmr | 0x0001; // enable timer
  sim->timer1.tmr = sim->timer1.tmr | 0x0000; // reset timer
  sim->timer1.tmr = sim->timer1.tmr | 0x0001; // re-enable timer */
  sim->timer1.tcn = 0; // zero count
  
  printf("Setting up timer mode...\n");
 //Setup Timer
  sim->timer1.tmr = sim->timer1.tmr & 0xFFF9; // input clock bits = 00 to stop timer 
  sim->timer1.tmr = (sim->timer1.tmr & 0x00FF) | 0xFA00; // Set prescale to 1/250
  sim->timer1.tmr = sim->timer1.tmr | 0x0018; //Set ORI and FRR bits
  sim->timer1.trr = 62; //Set refernce count to 62 to give overall 10 msec timeout(roughly)

  printf("Starting Timer...\n");
  sim->timer1.tmr = (sim->timer1.tmr & 0xFFF9) | 0x0004; // Set Master_Clk/16 and start
}


int main()
{
  DisableCache(); //Make things fly!
  EnableCache();
  
  printf("uCOS, The Real Time Kernel - Jean J. Labrosse\n\n");
  printf("Motorola MCF5206 port A0.02 - David Fiddes(D.J.Fiddes@hw.ac.uk)\n\n");
  
  printf("Running OSInit()...\n");
  OSInit(&OSIdleTaskStk[TASK_STK_SIZE], OS_MAX_TASKS);

  printf("Creating a Queue and Semaphore...\n");
  OSQInit(&MyQueue,&Q1[0],Q1_SIZE);
  OSSemInit(&MySem,1);

  printf("Creating the 3 tasks...\n");
  OSTaskCreate(Task1, (void*)0, (void*)&Task1Stk[TASK_STK_SIZE], 50);
  OSTaskCreate(Task2, (void*)0, (void*)&Task2Stk[TASK_STK_SIZE], 51);
  OSTaskCreate(Task3, (void*)1000, (void*)&Task3Stk[TASK_STK_SIZE], 52);

  printf("Starting SBC5206 Hardware setup...\n");
  HardwareSetup();
  OSStart();
    
  return 0; //This will never happen...
}


⌨️ 快捷键说明

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