xref: /nrf52832-nimble/rt-thread/libcpu/blackfin/bf53x/cpuport.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * File      : cpuport.c
3  * This file is part of RT-Thread RTOS
4  * COPYRIGHT (C) 2012, RT-Thread Development Team
5  *
6  * The license and distribution terms for this file may be
7  * found in the file LICENSE in this distribution or at
8  * http://www.rt-thread.org/license/LICENSE
9  *
10  * Change Logs:
11  * Date			Author		Notes
12  * 2012-02-13 	mojingxian 	first version
13  */
14 
15 #include <rtthread.h>
16 
17 /* flag in interrupt handling */
18 rt_uint32_t rt_interrupt_from_thread;
19 rt_uint32_t rt_interrupt_to_thread;
20 rt_uint32_t rt_thread_switch_interrupt_flag;
21 
22 /**
23  * initializes stack of thread
24  */
rt_hw_stack_init(void * tentry,void * parameter,rt_uint8_t * stack_addr,void * texit)25 rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
26 	rt_uint8_t *stack_addr, void *texit)
27 {
28     unsigned char i;
29 	unsigned long *stk;
30 
31     stk    = (unsigned long *)stack_addr;     /* Load stack pointer                                    */
32 
33                                               /* Simulate a function call to the task with an argument */
34     stk   -= 3;                               /* 3 words assigned for incoming args (R0, R1, R2)       */
35 
36                                               /* Now simulating vectoring to an ISR                    */
37     *--stk = (unsigned long)parameter;        /* R0 value - caller's incoming argument #1              */
38     *--stk = (unsigned long)0;                /* P1 value - value irrelevant                           */
39 
40     *--stk = (unsigned long)texit;            /* RETS value - NO task should return with RTS.          */
41                                               /* however OS_CPU_Invalid_Task_Return is a safety        */
42                                               /* catch-allfor tasks that return with an RTS            */
43 
44     *--stk = (unsigned long)parameter;        /* R1 value - caller's incoming argument #2              */
45                                               /* (not relevant in current test example)                */
46     *--stk = (unsigned long)parameter;        /* R2 value - caller's incoming argument #3              */
47                                               /* (not relevant in current test example)                */
48     *--stk = (unsigned long)0;                /* P0 value - value irrelevant                           */
49     *--stk = (unsigned long)0;                /* P2 value - value irrelevant                           */
50     *--stk = (unsigned long)0;                /* ASTAT value - caller's ASTAT value - value            */
51                                               /* irrelevant                                            */
52 
53     *--stk = (unsigned long)tentry;           /* RETI value- pushing the start address of the task     */
54 
55     for (i = 0; i < 35; i++)                  /* remaining reg values - R7:3, P5:3,                    */
56     {                                         /* 4 words of A1:0(.W,.X), LT0, LT1,                     */
57         *--stk = (unsigned long)0;            /* LC0, LC1, LB0, LB1,I3:0, M3:0, L3:0, B3:0,            */
58     }                                         /* All values irrelevant                                 */
59 
60     return (rt_uint8_t *)stk;                 /* Return top-of-stack                                   */
61 }
62 
rt_hw_context_switch(rt_uint32_t from,rt_uint32_t to)63 void rt_hw_context_switch(rt_uint32_t from, rt_uint32_t to)
64 {
65     if (rt_thread_switch_interrupt_flag != 1)
66     {
67         rt_thread_switch_interrupt_flag = 1;
68         rt_interrupt_from_thread = from;
69     }
70 
71     rt_interrupt_to_thread = to;
72     asm("raise 14;");                     // Raise Interrupt 14 (trap)
73 }
74 
rt_hw_context_switch_interrupt(rt_uint32_t from,rt_uint32_t to)75 void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_uint32_t to)
76 {
77     if (rt_thread_switch_interrupt_flag != 1)
78     {
79         rt_thread_switch_interrupt_flag = 1;
80         rt_interrupt_from_thread = from;
81     }
82 
83     rt_interrupt_to_thread = to;
84     asm("raise 14;");                     // Raise Interrupt 14 (trap)
85 }
86 
rt_hw_context_switch_to(rt_uint32_t to)87 void rt_hw_context_switch_to(rt_uint32_t to)
88 {
89     rt_thread_switch_interrupt_flag = 1;
90     rt_interrupt_from_thread = 0;
91     rt_interrupt_to_thread = to;
92     asm("raise 14;");                     // Raise Interrupt 14 (trap)
93 }
94