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

📄 uc_zsp_c.c

📁 ucosii for zsp400
💻 C
字号:
/*********************************************** MODULE HEADER *********
*
*  PROCESS NAME:  KERNEL
*
*
*  FILENAME:
*
*     UC_ZSP_C.C
*
*  DESCRIPTION
*  -----------
*
*     Contains 'C'-based uC/OS-II porting code for LIS Logic ZSP
*
*
*  REVISION HISTORY
*  ----------------
*
*  DATE        NAME        REASON/CHANGE ID
*  ----        ----        ----------------
*  02/22/01    S.Wright    Originator -- LSI Logic, Baseband DSP Applications
*
*
*
*                                   Copyright LSI Logic, 2001
*
***********************************************************************/

#include "includes.h"

/*
'C'-ASM macros for manipulating timer registers from 'C'
*/

#define SET_TIMER0(count) \
   asm volatile ("mov %%timer0, %0 \n\t" \
         : \
         : "r"(count))

#define SET_TIMER1(count) \
   asm volatile ("mov %%timer1, %0 \n\t" \
         : \
         : "r"(count))

#define SET_TC(count) \
   asm volatile ("mov %%tc, %0 \n\t" \
         : \
         : "r"(count))

#define SET_IP1(count) \
   asm volatile ("mov %%ip1, %0 \n\t" \
         : \
         : "r"(count))

/*
*********************************************************************************************************
*                                        INITIALIZE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
*              stack frame of the task being created.  This function is highly processor specific.
*
* Arguments  : task          is a pointer to the task code
*
*              pdata         is a pointer to a user supplied data area that will be passed to the task
*                            when the task first executes.
*
*              ptos          is a pointer to the top of stack.  It is assumed that 'ptos' points to
*                            a 'free' entry on the task stack.  If OS_STK_GROWTH is set to 1 then
*                            'ptos' will contain the HIGHEST valid address of the stack.  Similarly, if
*                            OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
*                            of the stack.
*
*              opt           specifies options that can be used to alter the behavior of OSTaskStkInit().
*                            (see uCOS_II.H for OS_TASK_OPT_???).
*
* Returns    : Always returns the location of the new top-of-stack' once the processor registers have
*              been placed on the stack in the proper order.
*
* Note(s)    : Interrupts are enabled when your task starts executing. You can change this by setting the
*              PSW to 0x0002 instead.  In this case, interrupts would be disabled upon task startup.  The
*              application code would be responsible for enabling interrupts at the beginning of the task
*              code.  You will need to modify OSTaskIdle() and OSTaskStat() so that they enable
*              interrupts.  Failure to do this will make your system crash!
*********************************************************************************************************
*/

OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
   {
   INT16U *stk;
   INT8U err;

   stk = (INT16U *) --ptos;   /* pre-decrement since the ASM-level stack-ops are post-dec */

   opt = opt;                 /* 'opt' is not used, prevent warning */

   *stk-- = 0;                /* R00 */
   *stk-- = 0;                /* R01 */
   *stk-- = 0;                /* R02 */
   *stk-- = 0;                /* R03 */
   *stk-- = 0;                /* %FMODE */
   *stk-- = 0;                /* %AMODE */
   *stk-- = 0;                /* %HWFLAG */
   *stk-- = 0;                /* R05 */
   *stk-- = (INT16U) pdata;   /* R04 */
   *stk-- = (INT16U) task;    /* %TPC */
   *stk-- = 0;                /* %RPC */
   *stk-- = ZSP_IMASK;        /* %IMASK -- just upper 2 bits */
   *stk-- = ZSP_IP0;          /* %IP0 -- just upper 4 bits */
   *stk-- = 0;                /* R15 */
   *stk-- = 0;                /* R14 */
   *stk-- = 0;                /* R13 */
   *stk-- = 0;                /* R11 */
   *stk-- = 0;                /* R10 */
   *stk-- = 0;                /* R09 */
   *stk-- = 0;                /* R08 */
   *stk-- = 0;                /* R07 */
   *stk-- = 0;                /* R06 */
   *stk-- = 0;                /* %CB1_END */
   *stk-- = 0;                /* %CB0_END */
   *stk-- = 0;                /* %CB1_BEG */
   *stk-- = 0;                /* %CB0_BEG */
   *stk-- = 0;                /* %LOOP3 */
   *stk-- = 0;                /* %LOOP2 */
   *stk-- = 0;                /* %LOOP1 */
   *stk-- = 0;                /* %LOOP0 */
   *stk-- = 0;                /* %VITR */
   *stk-- = 0;                /* %GUARD */
   *stk-- = ZSP_SMODE;        /* %SMODE -- make sure the vector table stays re-mapped!! */

   return ((OS_STK *)stk);
   }


/*********************************************** GLOBAL FUNCTION *******
*
*  FUNCTION:
*
*     void OSInitTimer (void)
*
*  PARAMETERS:
*
*     none
*
*  RETURN VALUES:
*
*     none
*
*  DESCRIPTION:
*
*     Initializes TIMER1 for use as uC/OS-II system timer
*
*  ERROR HANDLING:
*
*     none
*
*  NOTES:
*
***********************************************************************/

void OSInitTimer (void)
   {
   /*
   set up the rollover count
   */

   SET_TIMER1 (ROLLOVER_COUNT_VAL);
#ifdef PROFILER_SUPPORT
   SET_TIMER0 (39000);  /* for 38400 baud @ 150 MHz*/
#endif

   /*
   set up the divisor
   */

#ifndef PROFILER_SUPPORT
   SET_TC (TIMER_DIV_CONST << 8);
#else
   SET_TC (0x3F3F);
#endif

   /*
   enable the autoreload feature
   */

   asm (" bits %tc, 14");
#ifdef PROFILER_SUPPORT
   asm (" bits %tc, 6");
#endif

   /*
   start the timer
   */

   asm (" bits %tc, 15");
#ifdef PROFILER_SUPPORT
   asm (" bits %tc, 7");
#endif

   /*
   enable the interrupt
   */

   asm (" bits %imask, 6");
#ifdef PROFILER_SUPPORT
   asm (" bits %imask, 5");
#endif

   return;
   }


/*
*********************************************************************************************************
*                                       OSPrioQuery()
*
* Description: Returns the priority of the calling task
*
* Arguments  : none
*
* Note(s)    : LSI-added -- not part of Micrium distribution
*********************************************************************************************************
*/

INT8U OSPrioQuery (void)
   {
   return (OSTCBCur->OSTCBPrio);
   }


/*
*********************************************************************************************************
*                                        NUMBER OF QUEUE MESSAGES
*
* Description: This function returns the number of messages on a message queue.
*
* Arguments  : Queue is a pointer to the event control block associated with the desired queue
*
* Note(s)    : LSI-added -- not part of Micrium distribution
*********************************************************************************************************
*/

INT8U OSQNMsgs (void *Queue)
   {
   OS_EVENT *LocalQueue;
   OS_Q *QueuePointer;
   INT8U NMsgs;

   OS_ENTER_CRITICAL ();
   LocalQueue = (OS_EVENT *) Queue;
   QueuePointer = LocalQueue->OSEventPtr;
   NMsgs = QueuePointer->OSQEntries;
   OS_EXIT_CRITICAL ();

   return (NMsgs);
   }


/*
*********************************************************************************************************
*                                       OSPrioQuery()
*
* Description: Returns the index into the TCB table of the task at priority "Priority"
*
* Arguments  : INT8U Priority (priority of desired task)
*
* Note(s)    : LSI-added -- not part of Micrium distribution
*********************************************************************************************************
*/

INT8S OSTCBIndex (INT8U Priority)
   {
   INT8S Loop;
   BOOLEAN Found;

   Found = FALSE;
   for (Loop = 0; ((Loop < OSTaskCtr) && ( ! Found)); )
      {
      if (OSTCBTbl[Loop].OSTCBPrio == Priority)
         Found = TRUE;
      else
         Loop++;
      }

   if ( ! Found)
      Loop = -1;

   return (Loop);
   }


/*********************************************** GLOBAL FUNCTION *******
*
*  FUNCTION:
*
*     INT32U usToTicks (INT32U MicroSeconds)
*
*  PARAMETERS:
*
*     INT32U MicroSeconds: desired number of uS to convert
*
*  RETURN VALUES:
*
*     INT32U: number of system ticks equivalent to MicroSeconds argument
*
*  DESCRIPTION:
*
*     Converts MicrosSeconds to the number of system ticks.  Will not return 0.
*
*  ERROR HANDLING:
*
*     checks for divide by zero at compile time
*
*  NOTES:
*
*     LSI-added -- not part of Micrium distribution
*
***********************************************************************/

INT32U usToTicks (INT32U MicroSeconds)
   {
   INT32U Ticks;

#if MICROSECONDS_PER_TICK == 0

   !! MAKE THE COMPILER FAIL ON A DIVIDE-BY-ZERO !!

#else

   Ticks = MicroSeconds / MICROSECONDS_PER_TICK;

#endif


   /*
   return at least one tick...
   */

   if ( ! Ticks)
      Ticks = 1;

   return (Ticks);
   }


#if OS_CPU_HOOKS_EN

/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*                                            (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_INIT_HOOK_BEGIN_EN
#if OS_VERSION >= 204
void OSInitHookBegin (void)
{
}
#endif
#endif

/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*                                               (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_INIT_HOOK_END_EN
#if OS_VERSION >= 204
void OSInitHookEnd (void)
{
}
#endif
#endif

/*
*********************************************************************************************************
*                                           OSTimeTick() HOOK
*
* Description: This function is called by OSTimeTick().
*
* Arguments  : none
*
* Note(s)    :
*********************************************************************************************************
*/
#if OS_TIME_TICK_HOOK_EN
#if OS_VERSION >= 204
void OSTimeTickHook (void)
{
}
#endif
#endif

/*
*********************************************************************************************************
*                                           OS_TaskIdle() HOOK
*
* Description: This function is called by OS_TaskIdle().
*
* Arguments  : none
*
* Note(s)    :
*********************************************************************************************************
*/
#if OS_TASK_IDLE_HOOK_EN
#if OS_VERSION >= 204
void OSTaskIdleHook (void)
{
}
#endif
#endif

/*
*********************************************************************************************************
*                                           STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task.  This allows your
*              application to add functionality to the statistics task.
*
* Arguments  : none
*********************************************************************************************************
*/
#if OS_TASK_STAT_HOOK_EN
#if OS_VERSION >= 204
void OSTaskStatHook (void)
{
}
#endif
#endif

/*
*********************************************************************************************************
*                                           OSTCBInit() HOOK
*
* Description: This function is called by OSTCBInit() after setting up most of the TCB.
*
* Arguments  : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_TCB_INIT_HOOK_EN
#if OS_VERSION >= 204
void OSTCBInitHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                                           /* Prevent Compiler warning                 */
}
#endif
#endif

/*
*********************************************************************************************************
*                                           OSTaskCreate() HOOK
*
* Description: This function is called by OSTCBInit() after setting up most of the TCB.
*
* Arguments  : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_TASK_CREATE_HOOK_EN
#if OS_VERSION >= 204
void OSTaskCreateHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                                           /* Prevent Compiler warning                 */
}
#endif
#endif


/*
*********************************************************************************************************
*                                           TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments  : ptcb   is a pointer to the task control block of the task being deleted.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_TASK_DELETE_HOOK_EN
void OSTaskDelHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}
#endif

/*
*********************************************************************************************************
*                                           TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed.  This allows you to perform other
*              operations during a context switch.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts are disabled during this call.
*              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
*                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
*                 task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if OS_TASK_SW_HOOK_EN
void OSTaskSwHook (void)
{
}
#endif

#endif   /* OS_CPU_HOOKS_EN */

⌨️ 快捷键说明

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