/*
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; All Rights Reserved
;
; TI C6414 DSP Specific Functions
; Little Endian Mode
;
; Code Composer Studio V3.1
;
; File : DSP_C6x_Vectors.H
;********************************************************************************************************
*/
#ifdef OS_CPU_GLOBALS
#define DSP_C6x_EXT
#else
#define DSP_C6x_EXT extern
#endif
void DSP_C6x_TimerInit(void); // Inintial the Timer0 for OSTickISR
void DSP_C6x_SystemInit(void); // Initial the whole system
void DSP_C6x_Save(void); // Save all register context, used in ISR
void DSP_C6x_Resume(void); // Resume all register context, used in ISR
int DSP_C6x_GetCurrentSP(void); // It's used in OSTaskStkInit function
int DSP_C6x_GetCurrentDP(void); // It's used in any ISR function
void DSP_C6x_Int4Init(void); //for EthernetCard
DSP_C6x_Vectors.C源程序
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; All Rights Reserved
;
; TI C6414 DSP Specific Functions
; Little Endian Mode
;
; Code Composer Studio V3.1
;
; File : DSP_C6x_Vectors.C
;********************************************************************************************************
;********************************************************************************************************
; PUBLIC and EXTERNAL REFERENCES
;********************************************************************************************************
FP .set A15
DP .set B14
SP .set B15
.global $bss
MUXH .set 0x019C0000 ;Interrupt Multiplexer High Register
MUXL .set 0x019C0004 ;Interrupt Multiplexer Low Register
EXTPOL .set 0x019C0008 ;External Interrupt Polarity Register
T0_CTL .set 0x01940000 ;Timer Control Register of Timer-0
T0_PRD .set 0x01940004 ;Timer Period Register of Timer-0
T0_CNT .set 0x01940008 ;Timer Counter Register of Timer-0
EMIF_CE2 .set 0x01800010
_StartAddress .set 0+4 ;structrue of task/int stack
_A0 .set 4 +4
_A1 .set 8 +4
_A2 .set 12 +4
_A3 .set 16 +4
_A4 .set 20 +4
_A5 .set 24 +4
_A6 .set 28 +4
_A7 .set 32 +4
_A8 .set 36 +4
_A9 .set 40 +4
_A10 .set 44 +4
_A11 .set 48 +4
_A12 .set 52 +4
_A13 .set 56 +4
_A14 .set 60 +4
_A15 .set 64 +4
_A16 .set 68 +4
_A17 .set 72 +4
_A18 .set 76 +4
_A19 .set 80 +4
_A20 .set 84 +4
_A21 .set 88 +4
_A22 .set 92 +4
_A23 .set 96 +4
_A24 .set 100 +4
_A25 .set 104 +4
_A26 .set 108 +4
_A27 .set 112 +4
_A28 .set 116 +4
_A29 .set 120 +4
_A30 .set 124 +4
_A31 .set 128 +4
_B0 .set 132 +4
_B1 .set 136 +4
_B2 .set 140 +4
_B3 .set 144 +4
_B4 .set 148 +4
_B5 .set 152 +4
_B6 .set 156 +4
_B7 .set 160 +4
_B8 .set 164 +4
_B9 .set 168 +4
_B10 .set 172 +4
_B11 .set 176 +4
_B12 .set 180 +4
_B13 .set 184 +4
_B14 .set 188 +4
_B15 .set 192 +4
_B16 .set 196 +4
_B17 .set 200 +4
_B18 .set 204 +4
_B19 .set 208 +4
_B20 .set 212 +4
_B21 .set 216 +4
_B22 .set 220 +4
_B23 .set 224 +4
_B24 .set 228 +4
_B25 .set 232 +4
_B26 .set 236 +4
_B27 .set 240 +4
_B28 .set 244 +4
_B29 .set 248 +4
_B30 .set 252 +4
_B31 .set 256 +4
_AMR .set 260 +4
_CSR .set 264 +4
_IER .set 268 +4
_IRP .set 272 +4
_DUMMY .set 276 +4
_Framesize .set 276 +4
.global _DSP_C6x_TimerInit ; Inintial the Timer0 for OSTickISR
.global _DSP_C6x_SystemInit ; Initial the whole system
.global _DSP_C6x_Save ; Save all register context, used in ISR
.global _DSP_C6x_Resume ; Resume all register context, used in ISR
.global _DSP_C6x_GetCurrentDP ; It's used in OSTaskStkInit function
.global _DSP_C6x_GetCurrentSP ; It's used in any ISR function
.ref _c_int00 ; entry of C language
.ref _OSTickISR ; OSTickISR for uC/OS-II, as the ISR of Timer0
.global _DSP_C6x_Int4Init ;for EthernetDaughterCard
.ref _ne2k_isr
;.ref _int4;
; /*$PAGE*/
;******************************************************************************
; Vector Table
;
; ====== vectors in use ========
; Plug in the entry point at the ISR function in the interrupt vector table
;
; ====== unused ========
; plug inifinite loop -- with nested branches to
; disable interrupts -- for all undefined vectors
;
;******************************************************************************
unused .macro id
.global unused:id:
unused:id:
b unused:id: ; nested branches to block interrupts
nop 4
b unused:id:
nop
nop
nop
nop
nop
.endm
.align 32*8*4 ; must be aligned on 256 word boundary
RESET: ; reset vector
mvkl _c_int00,b0 ; load destination function address to b0
mvkh _c_int00,b0
b b0 ; start branch to destination function
mvc PCE1,b0 ; address of interrupt vectors
mvc b0,ISTP ; set table to point here
nop 3 ; fill delay slot
nop
nop
;------------------------------------------------
unused 1 ;NMI ; plug unused interrupts with infinite loops to
unused 2 ;Reserved ; catch stray interrupts
unused 3 ;Reserved ;------------------------------------------------
INT4:
nop
nop
b _ne2k_isr
nop
nop
nop
nop
nop
;unused 4 ;INT4
unused 5 ;INT5
unused 6 ;INT6
unused 7 ;INT7
unused 8 ;INT8
unused 9 ;INT9
unused 10 ;INT10
unused 11 ;INT11
unused 12 ;INT12
unused 13 ;INT13
INT14:
nop
nop
b _OSTickISR
nop
nop
nop
nop
nop
unused 15 ;INT15
; /*$PAGE*/ ;
;***********************************************************************
; Inintial the Int4
;
;***********************************************************************
;
_DSP_C6x_Int4Init:
mvc IER,B0
set B0,1,1,B0 ;
set B0,4,4,B0 ; set IER enable INT4
mvc B0,IER
mvk 0x0,B0 ; clear ICR/IFR
mvc B0,ICR
mvc CSR,B4 ; Set GIE bit in CSR , enable global interrupt
SET B4,0,0,B4
mvc B4,CSR
B B3
NOP 5
; /*$PAGE*/ ;
;***********************************************************************
; Inintial the Timer0 for OSTickISR
;
;***********************************************************************
;
_DSP_C6x_TimerInit: ; Inintial the Timer0 for OSTickISR
;set time cycle; Timer clk = SysClk / 8 (DSK6414 SysClk = 600MHz)
mvkl T0_PRD,B4 ; Set Timer to 100Hz
mvkh T0_PRD,B4 ; Timer Period Register of Timer-0
mvkl 0xB71B0,B5
mvkh 0xB71B0,B5
stw B5,*B4
mvkl T0_CTL,B4 ; Timer Control Register of Timer-0
mvkh T0_CTL,B4
ldw *B4,B5
nop 4
; set B5,9,9,B5
set B5,6,9,B5
stw B5,*B4
;enable Timer in IER & GIE
mvk 0x0,B0 ; clear ICR/IFR
mvc B0,ICR
mvc IER,B0
set B0,14,14,B0 ; set IER enable INT14(Timer0)
mvc B0,IER
mvc CSR,B4 ; Set GIE bit in CSR , enable global interrupt
SET B4,0,0,B4
mvc B4,CSR
B B3
NOP 5
; /*$PAGE*/ ;
;***********************************************************************
; Initial the whole system
;
;***********************************************************************
;
_DSP_C6x_SystemInit: ; Initial the whole system
MVK 0x0,B0
mvc B0,AMR
mvc B0,ISR
mvc B0,ICR
mvc B0,IER
mvc B0,IRP
mvc B0,ICR
mvc B0,NRP
MVK 0x0100,B0
mvc B0,CSR
mvkl RESET,B0
mvkh RESET,B0
mvc B0,ISTP
;for uC/OS-II
MVK 0x0A0,A0
MVK 0x0A1,A1
MVK 0x0A2,A2
MVK 0x0A3,A3
MVK 0x0A4,A4
MVK 0x0A5,A5
MVK 0x0A6,A6
MVK 0x0A7,A7
MVK 0x0A8,A8
MVK 0x0A9,A9
MVK 0x0A10,A10
MVK 0x0A11,A11
MVK 0x0A12,A12
MVK 0x0A13,A13
MVK 0x0A14,A14
; MVK 0x0,A15 ; Frame pointer
MVK 0x0A16,A16
MVK 0x0A17,A17
MVK 0x0A18,A18
MVK 0x0A19,A19
MVK 0x0A20,A20
MVK 0x0A21,A21
MVK 0x0A22,A22
MVK 0x0A23,A23
MVK 0x0A24,A24
MVK 0x0A25,A25
MVK 0x0A26,A26
MVK 0x0A27,A27
MVK 0x0A28,A28
MVK 0x0A29,A29
MVK 0x0A30,A30
MVK 0x0A31,A31
MVK .S2 0x0B0,B0
MVK .S2 0x0B1,B1
MVK .S2 0x0B2,B2
; MVK 0x0B3,B3 Return address
MVK .S2 0x0B4,B4
MVK .S2 0x0B5,B5
MVK .S2 0x0B6,B6
MVK .S2 0x0B7,B7
MVK .S2 0x0B8,B8
MVK .S2 0x0B9,B9
MVK .S2 0x0B10,B10
MVK .S2 0x0B11,B11
MVK .S2 0x0B12,B12
MVK .S2 0x0B13,B13
; MVK 0xA140,B14 ; data pointer
; MVK 0x0,B15 ; Stack pointer
MVK .S2 0x0B16,B16
MVK .S2 0x0B17,B17
MVK .S2 0x0B18,B18
MVK .S2 0x0B19,B19
MVK .S2 0x0B20,B20
MVK .S2 0x0B21,B21
MVK .S2 0x0B22,B22
MVK .S2 0x0B23,B23
MVK .S2 0x0B24,B24
MVK .S2 0x0B25,B25
MVK .S2 0x0B26,B26
MVK .S2 0x0B27,B27
MVK .S2 0x0B28,B28
MVK .S2 0x0B29,B29
MVK .S2 0x0B30,B30
MVK .S2 0x0B31,B31
B B3
NOP 5
; /*$PAGE*/ ;
;***********************************************************************
; Save all register context, used in ISR
;
;***********************************************************************
;
_DSP_C6x_Save: ; Save all register context, used in ISR
addk (8-_Framesize),SP ; Push one Frame
STW B0,*+SP(_B0) ; ; Save B0
|| mvc AMR,B0 ; B0 = AMR
STW B1,*+SP(_B1) ; ; Save B1
|| mvc CSR,B1 ; B1 = CSR
STW B2,*+SP(_B2) ; ; Save B2
|| mvc IER,B2 ; B2 = IER
STW B0,*+SP(_AMR) ; ; Save AMR
STW B1,*+SP(_CSR) ; ; Save CSR
STW B2,*+SP(_IER) ; ; Save IER
STW B4,*+SP(_B4) ; ; Save B4
|| mvc IRP,B4 ; The return address in the interrupted environment
STW B4,*+SP (_StartAddress) ; Save return address in interrupt handler start address
STW B4,*+SP (_IRP)
STW B5,*+SP(_B5) ; Save B5
STW B6,*+SP(_B6) ;
STW B7 ,*+SP(_B7 ) ;
STW B8 ,*+SP(_B8 ) ;
STW B9 ,*+SP(_B9 ) ;
STW B10,*+SP(_B10) ;
STW B11,*+SP(_B11) ;
STW B12,*+SP(_B12) ;
STW B13,*+SP(_B13) ;
STW B14,*+SP(_B14) ;
STW B16,*+SP(_B16) ;
STW B17 ,*+SP(_B17 ) ;
STW B18 ,*+SP(_B18 ) ;
STW B19 ,*+SP(_B19 ) ;
STW B20,*+SP(_B20) ;
STW B21,*+SP(_B21) ;
STW B22,*+SP(_B22) ;
STW B23,*+SP(_B23) ;
STW B24,*+SP(_B24) ;
STW B25,*+SP(_B25) ;
STW B26,*+SP(_B26) ;
STW B27 ,*+SP(_B27 ) ;
STW B28 ,*+SP(_B28 ) ;
STW B29 ,*+SP(_B29 ) ;
STW B30,*+SP(_B30) ;
STW B31,*+SP(_B31) ;
STW A0,*+SP(_A0) ; Save A0
LDW *+SP(_DUMMY),A0 ;Get the outside B3
STW A1,*+SP(_A1) ; Save A1
STW A2,*+SP(_A2) ; Save A2
STW A3,*+SP(_A3) ; Save A3
STW A4,*+SP(_A4) ; Save A4
STW A0,*+SP(_B3) ; Save B3
STW A5,*+SP(_A5) ;
STW A6,*+SP(_A6) ;
STW A7,*+SP(_A7) ;
STW A8,*+SP(_A8) ;
STW A9,*+SP(_A9) ;
|| MV SP,A0 ; A0 = SP
STW A10,*+SP(_A10) ;
|| addk (_Framesize),A0 ; A0 = SP + FRAME Correct SP for POP of TCB
STW A0,*+SP(_B15) ; B15 = A0 = SP + FRAME
|| B b3 ; Branch to continue in the interrupt handler
STW A11,*+SP(_A11) ;
STW A12,*+SP(_A12) ;
STW A13,*+SP(_A13) ;
STW A14,*+SP(_A14) ;
STW A15,*+SP(_A15) ;
STW A16,*+SP(_A16) ;
STW A17,*+SP(_A17) ;
STW A18,*+SP(_A18) ;
STW A19,*+SP(_A19) ;
STW A20,*+SP(_A20) ;
STW A21,*+SP(_A21) ;
STW A22,*+SP(_A22) ;
STW A23,*+SP(_A23) ;
STW A24,*+SP(_A24) ;
STW A25,*+SP(_A25) ;
STW A26,*+SP(_A26) ;
STW A27,*+SP(_A27) ;
STW A28,*+SP(_A28) ;
STW A29,*+SP(_A29) ;
STW A30,*+SP(_A30) ;
STW A31,*+SP(_A31) ;
; /*$PAGE*/ ;
;***********************************************************************
; Resume all register context, used in ISR
;
;***********************************************************************
;
_DSP_C6x_Resume: ; Resume all register context, used in ISR
LDW *+SP(_StartAddress),B3 ; b3 start address
LDW *+SP(_AMR),B10 ; B10 = AMR
LDW *+SP(_CSR),B9 ; B9 = CSR
LDW *+SP(_IER),B8 ; B8 = IER
LDW *+SP(_IRP),B7 ; B7 = IRP
mvk 0,B13
mvc B13,IER
LDW *+SP(_A0),A0 ;
LDW *+SP(_A1),A1 ;
LDW *+SP(_A2),A2 ;
LDW *+SP(_A3),A3 ;
LDW *+SP(_A4),A4 ;
LDW *+SP(_A5),A5 ;
LDW *+SP(_A6),A6 ;
LDW *+SP(_A7),A7 ;
LDW *+SP(_A8),A8 ;
LDW *+SP(_A9),A9 ;
LDW *+SP(_A10),A10 ;
LDW *+SP(_A11),A11 ;
LDW *+SP(_A12),A12 ;
LDW *+SP(_A13),A13 ;
LDW *+SP(_A14),A14 ;
LDW *+SP(_A15),A15 ;
LDW *+SP(_A16),A16 ;
LDW *+SP(_A17),A17 ;
LDW *+SP(_A18),A18 ;
LDW *+SP(_A19),A19 ;
LDW *+SP(_A20),A20 ;
LDW *+SP(_A21),A21 ;
LDW *+SP(_A22),A22 ;
LDW *+SP(_A23),A23 ;
LDW *+SP(_A24),A24 ;
LDW *+SP(_A25),A25 ;
LDW *+SP(_A26),A26 ;
LDW *+SP(_A27),A27 ;
LDW *+SP(_A28),A28 ;
LDW *+SP(_A29),A29 ;
LDW *+SP(_A30),A30 ;
LDW *+SP(_A31),A31 ;
LDW *+SP(_B0),B0 ;
LDW *+SP(_B1),B1 ;
LDW *+SP(_B2),B2 ;
LDW *+SP(_B4),B4 ;
LDW *+SP(_B5),B5 ;
LDW *+SP(_B6),B6 ;
LDW *+SP(_B11),B11 ;
LDW *+SP(_B12),B12 ;
LDW *+SP(_B13),B13 ;
LDW *+SP(_B14),B14 ;
LDW *+SP(_B16),B16 ;
LDW *+SP(_B17),B17 ;
LDW *+SP(_B18),B18 ;
LDW *+SP(_B19),B19 ;
LDW *+SP(_B20),B20 ;
LDW *+SP(_B21),B21 ;
LDW *+SP(_B22),B22 ;
LDW *+SP(_B23),B23 ;
LDW *+SP(_B24),B24 ;
LDW *+SP(_B25),B25 ;
LDW *+SP(_B26),B26 ;
LDW *+SP(_B27),B27 ;
LDW *+SP(_B28),B28 ;
LDW *+SP(_B29),B29 ;
LDW *+SP(_B30),B30 ;
LDW *+SP(_B31),B31 ;
mvc B7,IRP ; Restore IRP
or 3,b9,B9 ; Set GIE
mvc B9,CSR ; set csr if IRP did not put a GIE
mvc B10,AMR ; Restore AMR
LDW *+SP(_B7),B7 ;
LDW *+SP(_B9),B9 ;
LDW *+SP(_B10),B10 ;
LDW *+SP(_B3),B3 ;
LDW *+SP(_B8),B8 ;
LDW *+SP(_B15),B15 ;
B b3 ;
mvc B8,IER ;
nop 5
; /*$PAGE*/
;******************************************************************************
;* FUNCTION NAME: _DSP_C6x_GetCurrentDP (It's used in OSTaskStkInit function) *
;* *
;* Regs Modified : A4 *
;* Regs Used : A4,B3 *
;* Local Frame Size : 0 Args + 0 Auto + 0 Save = 0 byte *
;******************************************************************************
;.align 32
_DSP_C6x_GetCurrentDP:
mv DP,A4
B B3
NOP 5
; /*$PAGE*/
;******************************************************************************
;* FUNCTION NAME: _DSP_C6x_GetCurrentSP (It's used in any ISR function) *
;* *
;* Regs Modified : A4 *
;* Regs Used : A4,B3 *
;* Local Frame Size : 0 Args + 0 Auto + 0 Save = 0 byte *
;******************************************************************************
;.align 32
_DSP_C6x_GetCurrentSP:
mv SP,A4
B B3
NOP 5
.end
主程序如下:
程序中包含三个任务:一个任务只是输出一串字符,一个任务是等待信号量,得到信号量之后,任务结束;最后一个是post信号量,post之后,任务结束。
在主程序中create这三个任务和信号量。
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* Ported to TIC6414 DSP
*
* Main Code for porting
*********************************************************************************************************
*/
#include ".\includes.h"
OS_STK TaskStartStk[100];//task stacks
OS_STK Task_1stk[100];
OS_STK TaskStartStk_2[100];
OS_EVENT *RandomSem;
INT8U *err;
void TaskStart(void *pdata);
void TaskStart_2(void *pdata);
void Task_1(void *pParam);
void main(void)
{
DSP_C6x_SystemInit();//Initialize the DSK & Timer
OSInit(); //uC/OS-II init
RandomSem = OSSemCreate(0);
OSTaskCreate(Task_1,(void *)0,&Task_1stk[99],0);
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[99],1);
OSTaskCreate(TaskStart_2,(void *)0,&TaskStartStk_2[99],2);
puts("let's begin\n");
OSStart();
}
void TaskStart(void *pdata)
{
pdata=pdata;
puts("taskstart....");
puts("taskstart over.");
OSTaskDel(OS_PRIO_SELF);
}
void TaskStart_2(void *pdata)
{
pdata=pdata;
puts("creat sempore....");
OSSemPost(RandomSem);
puts("post sempore.");
OSTaskDel(OS_PRIO_SELF);
}
void Task_1(void *pdata)
{
pdata=pdata;
puts("pend sempore.");
OSSemPend(RandomSem,0,err);
puts("get sempore.");
OSTaskDel(OS_PRIO_SELF);
}
void ne2k_isr()//中断服务程序
{
}