?? osnios.c
字號:
/*******************************************************************************************
File : OSNios.c
This File implements Nios Initialization functions for uC/OS-II.
Author : Farid LEZIAR (fleziar@yahoo.fr)
Version : 2.0
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"
/**********************************************************************************************
INT8U OSNiosInitContextSwitch(INT8U OSCtxSwIRQ, INT8U OSTickISRIRQ)
This function vectorizes Kernel ISRs.
Must be called before OSStart(), actually in the main().
return : 1 -> OK
0 -> NOK. at least one irq number is not valid.
**********************************************************************************************/
INT8U OSNiosInitContextSwitch (INT8U OSCtxSwIRQ, INT8U OSTickISRIRQ)
{
int *vector;
INT8U i;
if (OSCtxSwIRQ > 63 || OSCtxSwIRQ < 17) return 0;
if (OSTickISRIRQ > 63 || OSTickISRIRQ < 17) return 0;
for (i=0; i<64; i++) OSNiosUserISRTable[i] = (int)OSDefaultISR; /* Initialize UserISR Table */
vector = (int*)nasys_vector_table + OSCtxSwIRQ; /* Depends on your design */
*vector = (int)OSCtxSw; /* Vectorize OSCtxSw at irq OSCtxSwIRQ */
OSNiosUserISRTable[OSCtxSwIRQ] = (int)OSCtxSw;
vector = (int*)nasys_vector_table + OSTickISRIRQ; /* see OSNios.h */
*vector = (int)OSTickISR; /* Vectorize OSTickISR at irq OSTickISRIRQ */
OSNiosUserISRTable[OSTickISRIRQ] = (int)OSTickISR;
return 1;
}
/**********************************************************************************************
INT8U OSNiosStartTicks(void *Timer)
This function initializes and starts the Timer.
Must be called after OSStart() (For example, in a Init Task)
return : 1 -> OK
0 -> NOK. Timer is NULL
**********************************************************************************************/
INT8U OSNiosStartTicks (void *Timer)
{
/* Set interrupt timer frequency to OS_TICKS_PER_SEC */
/* nasys_clock_freq = Processor Frequency (defined in nios.h) */
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
if (Timer == NULL) return 0;
OS_ENTER_CRITICAL();
((np_timer*)Timer)->np_timerperiodl = 0x0000FFFF & (nasys_clock_freq/OS_TICKS_PER_SEC);
((np_timer*)Timer)->np_timerperiodh = 0x0000FFFF & ((nasys_clock_freq/OS_TICKS_PER_SEC)>>16);
((np_timer*)Timer)->np_timercontrol = np_timercontrol_cont_mask + np_timercontrol_start_mask;
OS_EXIT_CRITICAL();
return 1;
}
/**********************************************************************************************
INT8U OSNiosInstallUserISR(INT8U irq, void *UserISR(void))
This function installs a C function as User Interrupt SubRoutine under uC/OS-II.
The user ISR must be in the form 'void userISR(void)'.
return : 1 -> OK. No ISR previously installed.
2 -> OK. old ISR replaced.
0 -> NOK. irq number not valid.
**********************************************************************************************/
INT8U OSNiosInstallUserISR (INT8U irq, void(*UserISR)(void))
{
int *isrvector;
INT8U ret = 1;
if (irq > 63 || irq < 17) return 0;
if (OSNiosUserISRTable[irq] != 0) ret = 2;
OSNiosUserISRTable[irq] = (int)UserISR;
isrvector = (int*)nasys_vector_table + irq;
*isrvector = (int)OSNiosCallISR; /* Installs OSNiosCallISR */
return ret;
}
void OSDefaultISR(void)
{
printf("OSDefaultISR() ! irq = %d\n", getIPRI());
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -