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

📄 68hc16.txt

📁 ucos在摩托罗拉16位微控制器68hc16上的移植
💻 TXT
📖 第 1 页 / 共 2 页
字号:
*	void tick16_isr(void)
*
*       FUNCTION:
*           This is an interrupt handler that is used by uCOS kernal
*           for the real-time clock.
*
*	CREATED:
*           March 15, 1994 by Gary Schneider
*
*       INPUTS:
*            None
*
*       OUTPUTS:
*            None
*
*       REGISTERS MODIFIED:
*            None - all registers saved on stack
*-------------------------------------------------------------------------


	lib	   bankmac.mac	  * bank macros

        import     CPU16_GPT_START
	import     CPU16_TFLG1_OFF
	import     CPU16_TOC2_OFF
        import     OSIntEnter
        import     OSTimeTick
        import     OSIntExit
	export     tick16_isr

        section		.text

tick16_isr:
        PSHM   D,E,X,Y,Z,K       * Save Acc D,E and all index regs. 
        ORP    #$0E0             * don't allow interrupts until we clear flag
	ldxxk  CPU16_GPT_START
	LDD    <CPU16_TFLG1_OFF,x
        ANDD   #$0EFFF		 * clear OC2 interrupt flag bit
	STD    <CPU16_TFLG1_OFF,x
	LDD    <CPU16_TOC2_OFF,x
        ADDD   #$0CCD		 * adjust for next tick
	STD    <CPU16_TOC2_OFF,x
        ANDP   #$01F             * allow interrupt nesting
	LDAB   #$0		 * clear XK for the following function calls
	TBXK
        JSR    OSIntEnter        * Notify uC/OS about ISR
        JSR    OSTimeTick        * Handle system tick
        JSR    OSIntExit         * Exit uC/OS through scheduler if HPT ready

	PULM   D,E,X,Y,Z,K

	RTI			 * return to interrupted task


/*
 *	MAIN.C - Test uCOS kernal on M68HC16Z1 BDM using INTROL16 compiler
 *          The kernal services tested are:
 *	                            OSInit()
 *                             OSIntEnter()
 *                             OSIntExit()
 *                             OSTimeTick()
 *	                            OSTaskCreate()
 *	                            OSStart()
 *	                            OSTimeDly()
 *	                            OSSemCreate()
 *	                            OSSemPend()
 *                             OSSemPost()
 *                             OSTimeSet()
 *                             OSTimeGet()
 *
 *
*/

#ifdef __CC16__
#include "c:\introl\incl16\proto.h"
#include "c:\introl\incl16\h16reg.h"
#endif

#include <math.h>
#include "defs.h"
#include "UCOS.H"

/****************************** DEFINES **********************************/
#define  TASK_STK_SIZE	 1024
#define  NUM_TASKS       3

/****************************** GLOBALS **********************************/
UBYTE num_task_stk[TASK_STK_SIZE];
UBYTE test_func_stk[TASK_STK_SIZE];
UBYTE test_ucos_stk[TASK_STK_SIZE];
UBYTE test_array[50];
OS_EVENT *TestSem;

/********************** FUNCTION PROTOTYPES ******************************/
void main( void );
void num_task( void );
void enable_tick_int( void );
void test_func( void );
void test_ucos( void );
/*************************************************************************/

void main()
{
	int i_rc;

	OSInit();			 /* initialize uCOS kernal */

	                   /* allocate storage for tasks and create the tasks */  
	i_rc = OSTaskCreate( num_task, (void *)&num_task_stk[TASK_STK_SIZE], 2);
   if( i_rc != OS_NO_ERR )
		return;
	i_rc = OSTaskCreate( test_ucos, (void *)&test_ucos_stk[TASK_STK_SIZE], 4);
   if( i_rc != OS_NO_ERR )
		return;
	i_rc = OSTaskCreate( test_func, (void *)&test_func_stk[TASK_STK_SIZE], 6);
   if( i_rc != OS_NO_ERR )
		return;

	TestSem = OSSemCreate(0); /* Tasks will wait for each other to initialize */

   OSTimeSet(0L);          /* Reset System Clock */
	OSStart();					/* start multitasking - won't return to main() */
}


/* PRIORITY = 2 */
void num_task(void)
{
	int i=0;
	UBYTE sem_err;

	  /* start (OC2) timer for system tick - enable OC2 interrupt  */
	  /* prescaler - system CLK (16.777216 MHz) / 256              */
   enable_tick_int();                 /* OC2 will toggle every time tick */
	for(i=0;i<50;i++)
	  test_array[i] = 2;
	OSSemPend(TestSem, 0, &sem_err);   /* Wait for all tasks to init */
	if( sem_err != OS_NO_ERR )
	  return;

	while(1)
		{
	    i=i+2;
	    i=i-2;
		 OSTimeDly(400);		 /* Delay for 20 seconds */
		}
}

/* PRIORITY = 4 */
void test_ucos(void)
{
	int i=0;
	UBYTE sem_err;

	i=i+4;
	i=i-4;
	OSSemPend(TestSem, 0, &sem_err);   /* Wait for all tasks to init */
	if( sem_err != OS_NO_ERR )
	  return;

	while(1)
	 {
	    i=i+4;
	    i=i-4;
       CPU16_GPTPDR |= 0x20;    /* set a general purpose I/O pin (OC3)    */
                           /* this takes 18 clocks = 1 uSec at 16.777 MHz */
       OSTimeDly(100);          /* Delay for 5 sec  */
       CPU16_GPTPDR &= 0x0DF;   /* clear a general purpose I/O pin (OC3) */
    }
}

/* PRIORITY = 6 */
void test_func(void)
{
	int i=0;
   unsigned long ul_clk;

	i=i+6;
	i=i-6;
   for(i=0; i<NUM_TASKS-1;i++)
	   OSSemPost(TestSem);             /*  All tasks may continue */

	while(1)
	 {
      ul_clk = OSTimeGet();
	   i=i+6;
	   i=i-6;
		 for(i=0;i<50;i++)
		   test_array[i] = 4;
    }
}


#if 0

                              This is the MAKEFILE



# must have a blank line between definitions because polymake gets confused
# with the escape\ and the \ at the end of a line meaning continue line.

INTROL_PATH = c:\introl

C_SRCS = MAIN UCOS TASK16 

ASM_SRCS = start cpu16 tasksw16 tick16 

ASM_OBJS = $[f,"",$(ASM_SRCS),"o16"]
C_OBJS = $[f,"",$(C_SRCS),"o16"]

C_HEADERS = DEFS.H UCOS.H 

HEAD : A.OUT

.c.o16 :
# Ignore whatever is returned by programs which polymake interprets as
# error codes use -command operation line modifier
# Set the search paths in environment variables; note \escape so that polymake
# won't think it's calling for line continuation.

        %setenv INTROL=$(INTROL_PATH)

	cc16 $< -gg -i=$(INTROL_PATH)\include -l -w9 > $*.cer
        type $*.cer

.s.o16 :
# Set the search paths in environment variables; note \escape so that polymake
# won't think it's calling for line continuation.

        %setenv INTROL=$(INTROL_PATH)

        as16 $< -l

$(C_OBJS) : $(C_HEADERS)
$(ASM_OBJS) : UCOS.H 
A.OUT: $(ASM_OBJS) $(C_OBJS) 

    ild16 $(ASM_OBJS) $(C_OBJS) -d c:\introl\lib16 -f a.map -gc:\syndev\m6816\c
    IHEX A.OUT 
<
#endif

⌨️ 快捷键说明

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