Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

uC/OS-II port for the Freescale MC9S12XEP100

Status
Not open for further replies.

peustace

Newbie level 1
Joined
Oct 28, 2007
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,290
ucos-ii mc9s12xep100

Hi,
I'm writing a uC/OS-II port for the MC9S12XEP100 microcontroller. This a port for this chip isnt listed on the micrium website. Can anyone suggest a similar port to work with?

And I'd really appreciate any tips for writing this port! I've been reading Labrosse's book but its not making much sense to me. I understand all the concepts behind RTOSs but the code is alluding me at the moment.

Thanks again
Pat
 

amraldo

Advanced Member level 4
Joined
Aug 29, 2004
Messages
1,185
Helped
144
Reputation
288
Reaction score
40
Trophy points
1,328
Location
Egypt
Activity points
5,880
os_cpu_a.s s3c2440

AA,
I had a similar project. My goal was to write ucos-ii port on S3C2440. I did not find it on ucos-ii website. I picked up a processor near mine S3C2410. I started from there. My changes were as follows:
1. Changing some initialization code
2. Changing some interrupt vectors
3. Changing Ports initializations
4. Changing registers used in the already exisiting modules.
I noticed that there are two processors, similar to yours. You can start from there as I did.
BR,
Amr Ali.
 

buncha

Newbie level 2
Joined
Nov 29, 2007
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,287
ucos-ii mc9s12xep100 下载

Thank you sir.
 

zhiliang

Newbie level 1
Joined
Jan 26, 2008
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
freescale ucos

I wrote uC/OS-II port for MC9S12XA256 recently.
Here is two most important files. I have the whole test project, please email me if you want.
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1998, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
*
*
* M68HC12XA256 Specific code
* (MetroWerks CodeWarrior C/C++ V4.5)
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
* Port Version : V1.0
* Ported to MC68HC12XA256: Zhiliang Xu
*********************************************************************************************************
*/

#include "INCLUDES.H"
/*
*********************************************************************************************************
* 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) : 1) XIRQ interrupts are disabled when your task starts executing. You can change this by
* clearing BIT6 in the CCR.
* 2) The STOP instruction is disabled when your task starts executing. You can change this
* by clearing BIT7 in the CCR.
* 3) The other interrupts (i.e. maskable interrupts) are enabled when your task starts
* executing. You can change this by setting BIT4 in the CCR.
* 4) You can change pass the above options in the 'opt' argument. You MUST only use the
* upper 8 bits of 'opt' because the lower bits are reserved by uC/OS-II. If you make
* changes to the code below, you will need to ensure that it doesn't affect the behaviour
* of OSTaskIdle() and OSTaskStat().
* 5) Registers are initialized to make them easy to differentiate with a debugger.
*********************************************************************************************************
*/
//OS_STK *OSTaskStkInit(void (*task)(void *pd), void *pdata, void *ptos, INT16U opt);
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, void *ptos, INT16U opt)
{
INT16U *wstk;
INT8U *bstk;

INT32U temp;
temp = (INT32U)task;

opt = opt; /* 'opt' is not used, prevent warning */
wstk = (INT16U *)ptos; /* Load stack pointer */
*--wstk = (INT16U)pdata; /* Simulate call to function with argument */
*--wstk = (INT16U)(temp>>8);
*--wstk = (INT16U)(temp>>8); /* Put pointer to task on top of stack */
*--wstk = (INT16U)0x2222; /* Y Register */
*--wstk = (INT16U)0x1111; /* X Register */
*--wstk = (INT16U)0xBBAA; /* D Register */
bstk = (INT8U *)wstk; /* Convert WORD ptr to BYTE ptr to set CCR */
*--bstk = 0xC0; /* CCR Register (Disable STOP instruction) */
*--bstk = 0x00; /* CCR Register (Disable STOP instruction) */
return ((void *)bstk); /* Return pointer to new top-of-stack */
}

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


/*
*********************************************************************************************************
* 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.
*********************************************************************************************************
*/

void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}


/*
*********************************************************************************************************
* 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).
*********************************************************************************************************
*/

void OSTaskSwHook (void)
{
}

/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/

void OSTaskStatHook (void)
{

}

/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/

void OSTimeTickHook (void)
{
}

#endif

#if OS_VERSION >= 251
void OSTCBInitHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent Compiler warning */
}
#endif

#if OS_VERSION >= 251
void OSInitHookBegin (void)
{
}
#endif


#if OS_VERSION >= 251
void OSTaskIdleHook (void)
{

}

#endif


#if OS_VERSION >= 251
void OSInitHookEnd (void)
{
}
#endif

;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1998, Jean J. Labrosse, Plantation, FL
; All Rights Reserved
;
;
; M68HC12XA256 Specific code
; (CodeWarrior C/C++ V4.5)
;
; File : OS_CPU_A.S
; By : Jean J. Labrosse
; Port Version : V1.02
; Ported to MC68HC12XA256 : Zhiliang Xu
;********************************************************************************************************

;********************************************************************************************************
; CONFIGURATION CONSTANTS
;********************************************************************************************************

OS_TICK_OC: equ 7 ; We will use Output Compare #7 to generate tick interrupts
OS_TICK_OC_CNTS: equ 461 ; 1000 Hz tick rate (assumes Free Running Timer runs at 460.8 KHz)
; OS_TICK_OC_CNTS = CPU_FRT_FREQ / OS_TICKS_PER_SEC

;********************************************************************************************************
; I/O PORT ADDRESSES
;********************************************************************************************************

TFLG1: equ $004E ; I/O port addresses. Assumes all 68HC12 I/Os start at 0x0000
TC0: equ $0050
TC1: equ $0052
TC2: equ $0054
TC3: equ $0056
TC4: equ $0058
TC5: equ $005A
TC6: equ $005C
TC7: equ $005E

;********************************************************************************************************
; PUBLIC DECLARATIONS
;********************************************************************************************************
xdef OSStartHighRdy
xdef OSCtxSw
xdef OSIntCtxSw
xdef OSTickISR
xdef _Null
;********************************************************************************************************
; EXTERNAL DECLARATIONS
;********************************************************************************************************

xref OSIntExit
xref OSIntNesting
xref OSPrioCur
xref OSPrioHighRdy
xref OSRunning
xref OSTaskSwHook
xref OSTCBCur
xref OSTCBHighRdy
xref OSTimeTick

;********************************************************************************************************
; START HIGHEST PRIORITY TASK READY-TO-RUN
;
; Description : This function is called by OSStart() to start the highest priority task that was created
; by your application before calling OSStart().
;
; Arguments : none
;
; Note(s) : 1) The stack frame is assumed to look as follows:
;
; OSTCBHighRdy->OSTCBStkPtr + 0 --> CCR(H)
; + 1 CCR(L)
; + 2 B
; + 3 A
; + 4 X (H)
; + 5 X (L)
; + 6 Y (H)
; + 7 Y (L)
; + 8 PC(H)
; + 9 PC(L)
;
; 2) OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;********************************************************************************************************
NON_BANKED: SECTION
OSStartHighRdy:
call OSTaskSwHook ; 4~, Invoke user defined context switch hook
inc OSRunning ; 4~, Indicate that we are multitasking

ldx OSTCBHighRdy ; 3~, Point to TCB of highest priority task ready to run
lds 0,x ; 3~, Load SP into 68HC12

rti ; 8~, Run task

;********************************************************************************************************
; TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority task ready-to-run.
;
; Arguments : none
;
; Note(s) : 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; SP + 0 --> CCR(H)
; + 1 CCR(L)
; + 2 B
; + 3 A
; + 4 X (H)
; + 5 X (L)
; + 6 Y (H)
; + 7 Y (L)
; + 8 PC(H)
; + 9 PC(L)
;
; 3) The stack frame of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr + 0 --> CCR(H)
; + 1 CCR(L)
; + 2 B
; + 3 A
; + 4 X (H)
; + 5 X (L)
; + 6 Y (H)
; + 7 Y (L)
; + 8 PC(H)
; + 9 PC(L)
;********************************************************************************************************

OSCtxSw:
ldx OSTCBCur ; 3~, Point to current task's TCB
sts 0,x ; 3~, Save stack pointer in preempted task's TCB

call OSTaskSwHook ; 4~, Call user task switch hook

ldx OSTCBHighRdy ; 3~, OSTCBCur = OSTCBHighRdy
stx OSTCBCur ; 3~

ldab OSPrioHighRdy ; 3~, OSPrioCur = OSPrioHighRdy
stab OSPrioCur ; 3~

lds 0,x ; 3~, Load SP into 68HC12

rti ; 8~, Run task

;********************************************************************************************************
; INTERRUPT LEVEL CONTEXT SWITCH
;
; Description : This function is called by OSIntExit() to perform a context switch to a task that has
; been made ready-to-run by an ISR.
;
; Arguments : none
;
; Note(s) : 1) Stack frame upon entry (Assuming OS_CRITICAL_METHOD is 1):
;
; ---- SP + 0 -> Page \ Return address from call to OSIntCtxSw()
; | SP + 1 -> PC(H) \ Return address from call to OSIntCtxSw()
; SP Adjustment | SP + 2 -> PC(L) /
; ---- SP + 3 -> Page \ Return address from call to OSIntCtxSw()
; (+6) | SP + 4 -> PC(H) \ Return address from call to OSIntExit()
; --> SP + 5 -> PC(L) /
; SP + 6 -> CCR(H) \
; SP + 7 -> CCR(L) |
; SP + 7 -> B |
; SP + 8 -> A |
; SP + 9 -> X(H) | Stack frame from interrupt stacking.
; SP + 10 -> X(L) |
; SP + 11 -> Y(H) |
; SP + 12 -> Y(L) |
; SP + 13 -> PC(H) |
; SP + 14 -> PC(L) /
;********************************************************************************************************

OSIntCtxSw:
leas 6,sp ; 2~, Clean up stack (Uncomment if OS_CRITICAL_METHOD is 1)

ldy OSTCBCur ; 3~, OSTCBCur->OSTCBStkPtr = Stack Pointer
sts 0,y ; 3~,

call OSTaskSwHook ; 4~, Call user task switch hook

ldx OSTCBHighRdy ; 3~, OSTCBCur = OSTCBHighRdy
stx OSTCBCur ; 3~

ldab OSPrioHighRdy ; 3~, OSPrioCur = OSPrioHighRdy
stab OSPrioCur ; 3~

lds 0,x ; 3~, Load SP into 68HC12

rti ; 8~, Run task

;********************************************************************************************************
; SYSTEM TICK ISR
;
; Description : This function is the ISR used to notify uC/OS-II that a system tick has occurred. You
; must setup the 68HC12's interrupt vector table so that an OUTPUT COMPARE interrupt
; vectors to this function.
;
; Arguments : none
;
; Notes : 1) The 'tick ISR' assumes the we are using the Output Compare specified by OS_TICK_OC
; (see OS_CFG.H and this file) to generate a tick that occurs every OS_TICK_OC_CNTS
; (see OS_CFG.H and this file) which corresponds to the number of FRT (Free Running
; Timer) counts to the next interrupt.
;
; 2) You must specify which output compare will be used by the tick ISR as follows:
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 0 to use OUTPUT COMPARE #0
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 1 to use OUTPUT COMPARE #1
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 2 to use OUTPUT COMPARE #2
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 3 to use OUTPUT COMPARE #3
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 4 to use OUTPUT COMPARE #4
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 5 to use OUTPUT COMPARE #5
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 6 to use OUTPUT COMPARE #6
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 7 to use OUTPUT COMPARE #7
;
; 3) TFLG1, TC0 ... TC7 are defined in this file.
;********************************************************************************************************

OSTickISR:
inc OSIntNesting ; 4~, Notify uC/OS-II about ISR


; if OS_TICK_OC == 7
ldab #$80 ; 2~, Clear C7F interrupt flag (bit 7)
stab TFLG1 ; 4~
ldd TC7 ; 5~, Set TC7 to present time + desired counts to next ISR
addd #OS_TICK_OC_CNTS ; 4~
std TC7 ; 5~
; endif

cli ; 2~, Enable interrupts to allow interrupt nesting

call OSTimeTick ; 6~+, Call uC/OS-II's tick updating function

call OSIntExit ; 6~+, Notify uC/OS-II about end of ISR

rti ; 12~, Return from interrupt, no higher priority tasks ready.
_Null
stop
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top