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

📄 os_viewc.c

📁 一个测试端口测试程序
💻 C
字号:
/*
*********************************************************************************************************
*                                               uC/OS-View
*
*                           (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
*                                           All Rights Reserved
*
*                                               Nios 32bits
*                                      Farid LEZIAR (fleziar@yahoo.fr)
*
*
*
*    This port is free. you can use it, redistribute it
*    and/or modify it under the following terms:
*
*    1. You are not allowed to remove or modify this copyright notice
*       and License paragraphs, even if parts of the software is used.
*    2. The improvements and/or extentions you make must be available
*       for the community under THIS license, source code included.
*    4. You may NOT distribute this software under another license without
*       explicit permission from farid LEZIAR (fleziar@yahoo.fr).
*    5. This software is free, and distributed in the hope that it will be
*       useful, but WITHOUT ANY WARRANTY.
*    6. Tou have you inform me whenever you use this software.
*
*********************************************************************************************************
*/

#include "includes.h"


/*
*********************************************************************************************************
*                                              CONSTANTS 
*********************************************************************************************************
*/


/*$PAGE*/
/*
*********************************************************************************************************
*                                           EXIT uC/OS-View
*
* Description: 
*
* Note(s)    : 
*********************************************************************************************************
*/

void  OSView_Exit (void)
{
	/* Disable UART interrupt */
	((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uartcontrol = 0;
}

/*
*********************************************************************************************************
*                                           Obtain CPU name 
*********************************************************************************************************
*/

void  OSView_GetCPUName (char *s)
{
    strcpy(s, "Altera Nios 32bits");
}

/*
*********************************************************************************************************
*                                  Obtain Interrupt Stack information
*********************************************************************************************************
*/

INT32U  OSView_GetIntStkBase (void)					  
{
    return (0);										  /* We are not using an ISR stack                 */
}


INT32U  OSView_GetIntStkSize (void)
{
    return (0);										  /* We are not using an ISR stack                 */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                    INITIALISE uC/OS-View COM PORT
*
* Description: Initialize the hardware required for the OS to run. This will work on any target hardware, 
*              but may have to be tailored a little (regarding the clock frequency). Of course the same 
*              holds true if for some reason you choose to use an other timer.
*
*********************************************************************************************************
*/

void  OSView_InitTarget (void)
{
  /* The Uart has a Hardware bauds rate */
  /* Clears the status register */
  ((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uartstatus = 0;

  /* INstalls Rx/Tx interrupt routine */
  if (OSNiosInstallUserISR(NIOS_OSVIEW_UART_IRQ, OSView_RxTxISRHandler))
    ((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uartcontrol = np_uartcontrol_irrdy_mask | np_uartcontrol_itrdy_mask;


}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Rx Interrupts
*********************************************************************************************************
*/

void  OSView_RxIntDis (void)
{
}

/*
*********************************************************************************************************
*                                       Enable Rx Interrupts
*********************************************************************************************************
*/

void  OSView_RxIntEn (void)
{
}

/*
*********************************************************************************************************
*                                 Rx Communication handler for uC/OS-View
*
* Description: This function is not called.
*********************************************************************************************************
*/

void  OSView_RxISRHandler (void)
{

}

/*
*********************************************************************************************************
*                                Rx/Tx Communication handler for uC/OS-View
*
* Description: This function is a uC/OS-II ISR for the uart. it is installed via OSNiosInstallUserISR().
* It is not called from OSView_RxTxISR.
*********************************************************************************************************
*/

void  OSView_RxTxISRHandler (void)
{
	INT8U c;

  if (((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uartstatus & np_uartstatus_rrdy_mask)
  {
	   c = ((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uartrxdata;    // clears the rrdy bit
     OSView_RxHandler(c);
  }

  if (((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uartstatus & np_uartstatus_trdy_mask)
  {
	   ((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uarttxdata = 0;    // clears the trdy bit
     OSView_TxHandler();
  }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                              Tick Hook
*
* This routine is called by uC/OS-II's OSTimeTickHook().
* using CRITICAL macros is not necessary because interrupt is disabled.
*********************************************************************************************************
*/

void  OSView_TickHook (void)
{
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR   cpu_sr;
#endif
    INT32U      timercnt;


    //OS_ENTER_CRITICAL();
    // snap timer counters
    ((np_timer*)NIOS_TIMER_TICKS)->np_timersnaph = 0;

    // then read
    timercnt = (((np_timer*)NIOS_TIMER_TICKS)->np_timersnaph<<16) |
               ((np_timer*)NIOS_TIMER_TICKS)->np_timersnapl;


	  OSView_CyclesCtr += timercnt;
    //OS_EXIT_CRITICAL();


}

/*
*********************************************************************************************************
*                                           Get time [cycles]
*
* This routine is required for task-info via uC/OS-View.
* It returns the system time in clock cycles.
*********************************************************************************************************
*/

INT32U  OSView_TimeGetCycles (void)
{


    return OSView_CyclesCtr;

}

/*
*********************************************************************************************************
*                                      Communication for uC/OS-View
*
* Description: Send 1 character to COM Port
*
*********************************************************************************************************
*/

void  OSView_Tx1 (INT8U c) 
{
   ((np_uart*)NIOS_OSVIEW_UART_ADDRESS)->np_uarttxdata = c;
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntDis (void) 
{
}

/*
*********************************************************************************************************
*                                       Enable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntEn (void) 
{
}

/*
*********************************************************************************************************
*                                 Tx Communication handler for uC/OS-View
*                                            (PORT SPECIFIC)
*
* Description: Handle transmission of a character
*
* This function is not used.
*********************************************************************************************************
*/

void  OSView_TxISRHandler (void) 
{
    //OSView_TxHandler();
}

⌨️ 快捷键说明

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