OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [WizC/] [PIC18/] [portmacro.h] - Blame information for rev 572

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 572 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
/*
55
Changes from V3.0.0
56
 
57
Changes from V3.0.1
58
*/
59
#ifndef PORTMACRO_H
60
#define PORTMACRO_H
61
 
62
#if !defined(_SERIES) || _SERIES != 18
63
        #error "WizC supports FreeRTOS on the Microchip PIC18-series only"
64
#endif
65
 
66
#if !defined(QUICKCALL) || QUICKCALL != 1
67
        #error "QuickCall must be enabled (see ProjectOptions/Optimisations)"
68
#endif
69
 
70
#include <stddef.h>
71
#include <pic.h>
72
 
73
#define portCHAR                char
74
#define portFLOAT               float
75
#define portDOUBLE              portFLOAT
76
#define portLONG                long
77
#define portSHORT               short
78
#define portSTACK_TYPE  unsigned char
79
#define portBASE_TYPE   char
80
 
81
#if( configUSE_16_BIT_TICKS == 1 )
82
        typedef unsigned portSHORT portTickType;
83
        #define portMAX_DELAY ( portTickType )  ( 0xFFFF )
84
#else
85
        typedef unsigned portLONG portTickType;
86
        #define portMAX_DELAY ( portTickType )  ( 0xFFFFFFFF )
87
#endif
88
 
89
#define portBYTE_ALIGNMENT                      1
90
 
91
/*-----------------------------------------------------------*/
92
 
93
/*
94
 * Constant used for context switch macro when we require the interrupt
95
 * enable state to be forced when the interrupted task is switched back in.
96
 */
97
#define portINTERRUPTS_FORCED                           (0x01)
98
 
99
/*
100
 * Constant used for context switch macro when we require the interrupt
101
 * enable state to be unchanged when the interrupted task is switched back in.
102
 */
103
#define portINTERRUPTS_UNCHANGED                        (0x00)
104
 
105
/* Initial interrupt enable state for newly created tasks.  This value is
106
 * used when a task switches in for the first time.
107
 */
108
#define portINTERRUPTS_INITIAL_STATE            (portINTERRUPTS_FORCED)
109
 
110
/*
111
 * Macros to modify the global interrupt enable bit in INTCON.
112
 */
113
#define portDISABLE_INTERRUPTS()        \
114
        do                                                              \
115
        {                                                               \
116
                bGIE=0;                                          \
117
        } while(bGIE)   // MicroChip recommends this check!
118
 
119
#define portENABLE_INTERRUPTS()         \
120
        do                                                              \
121
        {                                                               \
122
                bGIE=1;                                         \
123
        } while(0)
124
 
125
/*-----------------------------------------------------------*/
126
 
127
/*
128
 * Critical section macros.
129
 */
130
extern unsigned portCHAR ucCriticalNesting;
131
 
132
#define portNO_CRITICAL_SECTION_NESTING         ( ( unsigned portCHAR ) 0 )
133
 
134
#define portENTER_CRITICAL()                                                                            \
135
        do                                                                                                                              \
136
        {                                                                                                                               \
137
                portDISABLE_INTERRUPTS();                                                                       \
138
                                                                                                                                        \
139
                /*                                                                                                                      \
140
                 * Now interrupts are disabled ucCriticalNesting                        \
141
                 * can be accessed directly. Increment                                          \
142
                 * ucCriticalNesting to keep a count of how                                     \
143
                 * many times portENTER_CRITICAL() has been called.             \
144
                 */                                                                                                                     \
145
                ucCriticalNesting++;                                                                            \
146
        } while(0)
147
 
148
#define portEXIT_CRITICAL()                                                                                     \
149
        do                                                                                                                              \
150
        {                                                                                                                               \
151
                if(ucCriticalNesting > portNO_CRITICAL_SECTION_NESTING)         \
152
                {                                                                                                                       \
153
                        /*                                                                                                              \
154
                         * Decrement the nesting count as we are leaving a              \
155
                         * critical section.                                                                    \
156
                         */                                                                                                             \
157
                        ucCriticalNesting--;                                                                    \
158
                }                                                                                                                       \
159
                                                                                                                                        \
160
                /*                                                                                                                      \
161
                 * If the nesting level has reached zero then                           \
162
                 * interrupts should be re-enabled.                                                     \
163
                 */                                                                                                                     \
164
                if( ucCriticalNesting == portNO_CRITICAL_SECTION_NESTING )      \
165
                {                                                                                                                       \
166
                        portENABLE_INTERRUPTS();                                                                \
167
                }                                                                                                                       \
168
        } while(0)
169
 
170
/*-----------------------------------------------------------*/
171
 
172
/*
173
 * The minimal stacksize is calculated on the first reference of
174
 * portMINIMAL_STACK_SIZE. Some input to this calculation is
175
 * compiletime determined, other input is port-defined (see port.c)
176
 */
177
extern unsigned portSHORT usPortCALCULATE_MINIMAL_STACK_SIZE( void );
178
extern unsigned portSHORT usCalcMinStackSize;
179
 
180
#define portMINIMAL_STACK_SIZE                                  \
181
        ((usCalcMinStackSize == 0)                                       \
182
                ? usPortCALCULATE_MINIMAL_STACK_SIZE()  \
183
                : usCalcMinStackSize )
184
 
185
/*
186
 * WizC uses a downgrowing stack
187
 */
188
#define portSTACK_GROWTH                        ( -1 )
189
 
190
/*-----------------------------------------------------------*/
191
 
192
/*
193
 * Macro's that pushes all the registers that make up the context of a task onto
194
 * the stack, then saves the new top of stack into the TCB. TOSU and TBLPTRU
195
 * are only saved/restored on devices with more than 64kB (32k Words) ROM.
196
 *
197
 * The stackpointer is helt by WizC in FSR2 and points to the first free byte.
198
 * WizC uses a "downgrowing" stack. There is no framepointer.
199
 *
200
 * We keep track of the interruptstatus using ucCriticalNesting. When this
201
 * value equals zero, interrupts have to be enabled upon exit from the
202
 * portRESTORE_CONTEXT macro.
203
 *
204
 * If this is called from an ISR then the interrupt enable bits must have been
205
 * set for the ISR to ever get called.  Therefore we want to save
206
 * ucCriticalNesting with value zero. This means the interrupts will again be
207
 * re-enabled when the interrupted task is switched back in.
208
 *
209
 * If this is called from a manual context switch (i.e. from a call to yield),
210
 * then we want to keep the current value of ucCritialNesting so it is restored
211
 * with its current value. This allows a yield from within a critical section.
212
 *
213
 * The compiler uses some locations at the bottom of RAM for temporary
214
 * storage. The compiler may also have been instructed to optimize
215
 * function-parameters and local variables to global storage. The compiler
216
 * uses an area called LocOpt for this wizC feature.
217
 * The total overheadstorage has to be saved in it's entirety as part of
218
 * a task context. These macro's store/restore from data address 0x0000 to
219
 * (OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE - 1).
220
 * OVERHEADPAGE0, LOCOPTSIZE and MAXLOCOPTSIZE are compiler-generated
221
 * assembler definitions.
222
 */
223
 
224
#define portSAVE_CONTEXT( ucInterruptForced )                                           \
225
        do                                                                                                                              \
226
        {                                                                                                                               \
227
                portDISABLE_INTERRUPTS();                                                                       \
228
                                                                                                                                        \
229
                _Pragma("asm")                                                                                          \
230
                        ;                                                                                                               \
231
                        ; Push the relevant SFR's onto the task's stack                 \
232
                        ;                                                                                                               \
233
                        movff   STATUS,POSTDEC2                                                                 \
234
                        movff   WREG,POSTDEC2                                                                   \
235
                        movff   BSR,POSTDEC2                                                                    \
236
                        movff   PRODH,POSTDEC2                                                                  \
237
                        movff   PRODL,POSTDEC2                                                                  \
238
                        movff   FSR0H,POSTDEC2                                                                  \
239
                        movff   FSR0L,POSTDEC2                                                                  \
240
                        movff   FSR1H,POSTDEC2                                                                  \
241
                        movff   FSR1L,POSTDEC2                                                                  \
242
                        movff   TABLAT,POSTDEC2                                                                 \
243
                        if __ROMSIZE > 0x8000                                                                   \
244
                                movff   TBLPTRU,POSTDEC2                                                        \
245
                        endif                                                                                                   \
246
                        movff   TBLPTRH,POSTDEC2                                                                \
247
                        movff   TBLPTRL,POSTDEC2                                                                \
248
                        if __ROMSIZE > 0x8000                                                                   \
249
                                movff   PCLATU,POSTDEC2                                                         \
250
                        endif                                                                                                   \
251
                        movff   PCLATH,POSTDEC2                                                                 \
252
                        ;                                                                                                               \
253
                        ; Store the compiler-scratch-area as described above.   \
254
                        ;                                                                                                               \
255
                        movlw   OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE                  \
256
                        clrf    FSR0L,ACCESS                                                                    \
257
                        clrf    FSR0H,ACCESS                                                                    \
258
                _rtos_S1:                                                                                                       \
259
                        movff   POSTINC0,POSTDEC2                                                               \
260
                        decfsz  WREG,W,ACCESS                                                                   \
261
                        SMARTJUMP _rtos_S1                                                                              \
262
                        ;                                                                                                               \
263
                        ; Save the pic call/return-stack belonging to the               \
264
                        ; current task by copying it to the task's software-    \
265
                        ; stack. We save the hardware stack pointer (which              \
266
                        ; is the number of addresses on the stack) in the               \
267
                        ; W-register first because we need it later and it              \
268
                        ; is modified in the save-loop by executing pop's.              \
269
                        ; After the loop the W-register is stored on the                \
270
                        ; stack, too.                                                                                   \
271
                        ;                                                                                                               \
272
                        movf    STKPTR,W,ACCESS                                                                 \
273
                        bz              _rtos_s3                                                                                \
274
                _rtos_S2:                                                                                                       \
275
                        if __ROMSIZE > 0x8000                                                                   \
276
                                movff   TOSU,POSTDEC2                                                           \
277
                        endif                                                                                                   \
278
                        movff   TOSH,POSTDEC2                                                                   \
279
                        movff   TOSL,POSTDEC2                                                                   \
280
                        pop                                                                                                             \
281
                        tstfsz  STKPTR,ACCESS                                                                   \
282
                        SMARTJUMP _rtos_S2                                                                              \
283
                _rtos_s3:                                                                                                       \
284
                        movwf   POSTDEC2,ACCESS                                                                 \
285
                        ;                                                                                                               \
286
                        ; Next the value for ucCriticalNesting used by the              \
287
                        ; task is stored on the stack. When                                             \
288
                        ; (ucInterruptForced == portINTERRUPTS_FORCED), we save \
289
                        ; it as 0 (portNO_CRITICAL_SECTION_NESTING).                     \
290
                        ;                                                                                                               \
291
                        if ucInterruptForced == portINTERRUPTS_FORCED                   \
292
                                clrf POSTDEC2,ACCESS                                                            \
293
                        else                                                                                                    \
294
                                movff   ucCriticalNesting,POSTDEC2                                      \
295
                        endif                                                                                                   \
296
                        ;                                                                                                               \
297
                        ; Save the new top of the software stack in the TCB.    \
298
                        ;                                                                                                               \
299
                        movff   pxCurrentTCB,FSR0L                                                              \
300
                        movff   pxCurrentTCB+1,FSR0H                                                    \
301
                        movff   FSR2L,POSTINC0                                                                  \
302
                        movff   FSR2H,POSTINC0                                                                  \
303
                _Pragma("asmend")                                                                                       \
304
        } while(0)
305
 
306
/************************************************************/
307
 
308
/*
309
 * This is the reverse of portSAVE_CONTEXT.
310
 */
311
#define portRESTORE_CONTEXT()                                                                           \
312
        do                                                                                                                              \
313
        {                                                                                                                               \
314
                _Pragma("asm")                                                                                          \
315
                        ;                                                                                                               \
316
                        ; Set FSR0 to point to pxCurrentTCB->pxTopOfStack.              \
317
                        ;                                                                                                               \
318
                        movff   pxCurrentTCB,FSR0L                                                              \
319
                        movff   pxCurrentTCB+1,FSR0H                                                    \
320
                        ;                                                                                                               \
321
                        ; De-reference FSR0 to set the address it holds into    \
322
                        ; FSR2 (i.e. *( pxCurrentTCB->pxTopOfStack ) ). FSR2    \
323
                        ; is used by wizC as stackpointer.                                              \
324
                        ;                                                                                                               \
325
                        movff   POSTINC0,FSR2L                                                                  \
326
                        movff   POSTINC0,FSR2H                                                                  \
327
                        ;                                                                                                               \
328
                        ; Next, the value for ucCriticalNesting used by the             \
329
                        ; task is retrieved from the stack.                                             \
330
                        ;                                                                                                               \
331
                        movff   PREINC2,ucCriticalNesting                                               \
332
                        ;                                                                                                               \
333
                        ; Rebuild the pic call/return-stack. The number of              \
334
                        ; return addresses is the next item on the task stack.  \
335
                        ; Save this number in PRODL. Then fetch the addresses   \
336
                        ; and store them on the hardwarestack.                                  \
337
                        ; The datasheets say we can't use movff here...                 \
338
                        ;                                                                                                               \
339
                        movff   PREINC2,PRODL   // Use PRODL as tempregister    \
340
                        clrf    STKPTR,ACCESS                                                                   \
341
                _rtos_R1:                                                                                                       \
342
                        push                                                                                                    \
343
                        movf    PREINC2,W,ACCESS                                                                \
344
                        movwf   TOSL,ACCESS                                                                             \
345
                        movf    PREINC2,W,ACCESS                                                                \
346
                        movwf   TOSH,ACCESS                                                                             \
347
                        if __ROMSIZE > 0x8000                                                                   \
348
                                movf    PREINC2,W,ACCESS                                                        \
349
                                movwf   TOSU,ACCESS                                                                     \
350
                        else                                                                                                    \
351
                                clrf    TOSU,ACCESS                                                                     \
352
                        endif                                                                                                   \
353
                        decfsz  PRODL,F,ACCESS                                                                  \
354
                        SMARTJUMP _rtos_R1                                                                              \
355
                        ;                                                                                                               \
356
                        ; Restore the compiler's working storage area to page 0  \
357
                        ;                                                                                                               \
358
                        movlw   OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE                  \
359
                        movwf   FSR0L,ACCESS                                                                    \
360
                        clrf    FSR0H,ACCESS                                                                    \
361
                _rtos_R2:                                                                                                       \
362
                        decf    FSR0L,F,ACCESS                                                                  \
363
                        movff   PREINC2,INDF0                                                                   \
364
                        tstfsz  FSR0L,ACCESS                                                                    \
365
                        SMARTJUMP _rtos_R2                                                                              \
366
                        ;                                                                                                               \
367
                        ; Restore the sfr's forming the tasks context.                  \
368
                        ; We cannot yet restore bsr, w and status because               \
369
                        ; we need these registers for a final test.                             \
370
                        ;                                                                                                               \
371
                        movff   PREINC2,PCLATH                                                                  \
372
                        if __ROMSIZE > 0x8000                                                                   \
373
                                movff   PREINC2,PCLATU                                                          \
374
                        else                                                                                                    \
375
                                clrf    PCLATU,ACCESS                                                           \
376
                        endif                                                                                                   \
377
                        movff   PREINC2,TBLPTRL                                                                 \
378
                        movff   PREINC2,TBLPTRH                                                                 \
379
                        if __ROMSIZE > 0x8000                                                                   \
380
                                movff   PREINC2,TBLPTRU                                                         \
381
                        else                                                                                                    \
382
                                clrf    TBLPTRU,ACCESS                                                          \
383
                        endif                                                                                                   \
384
                        movff   PREINC2,TABLAT                                                                  \
385
                        movff   PREINC2,FSR1L                                                                   \
386
                        movff   PREINC2,FSR1H                                                                   \
387
                        movff   PREINC2,FSR0L                                                                   \
388
                        movff   PREINC2,FSR0H                                                                   \
389
                        movff   PREINC2,PRODL                                                                   \
390
                        movff   PREINC2,PRODH                                                                   \
391
                        ;                                                                                                               \
392
                        ; The return from portRESTORE_CONTEXT() depends on              \
393
                        ; the value of ucCriticalNesting. When it is zero,              \
394
                        ; interrupts need to be enabled. This is done via a             \
395
                        ; retfie instruction because we need the                                \
396
                        ; interrupt-enabling and the return to the restored             \
397
                        ; task to be uninterruptable.                                                   \
398
                        ; Because bsr, status and W are affected by the test    \
399
                        ; they are restored after the test.                                             \
400
                        ;                                                                                                               \
401
                        movlb   ucCriticalNesting>>8                                                    \
402
                        tstfsz  ucCriticalNesting,BANKED                                                \
403
                        SMARTJUMP _rtos_R4                                                                              \
404
                _rtos_R3:                                                                                                       \
405
                        movff   PREINC2,BSR                                                                             \
406
                        movff   PREINC2,WREG                                                                    \
407
                        movff   PREINC2,STATUS                                                                  \
408
                        retfie  0                ; Return enabling interrupts                    \
409
                _rtos_R4:                                                                                                       \
410
                        movff   PREINC2,BSR                                                                             \
411
                        movff   PREINC2,WREG                                                                    \
412
                        movff   PREINC2,STATUS                                                                  \
413
                        return  0                ; Return without affecting interrupts   \
414
                _Pragma("asmend")                                                                                       \
415
        } while(0)
416
 
417
/*-----------------------------------------------------------*/
418
 
419
#define portTICK_RATE_MS        ( ( portTickType ) 1000 / configTICK_RATE_HZ )
420
 
421
/*-----------------------------------------------------------*/
422
 
423
extern void vPortYield( void );
424
#define portYIELD()                             vPortYield()
425
 
426
#define portNOP()       _Pragma("asm")                                                                  \
427
                                                nop                                                                                     \
428
                                        _Pragma("asmend")
429
 
430
/*-----------------------------------------------------------*/
431
 
432
#define portTASK_FUNCTION( xFunction, pvParameters )            \
433
        void pointed xFunction( void *pvParameters )            \
434
        _Pragma(asmfunc xFunction)
435
 
436
#define portTASK_FUNCTION_PROTO         portTASK_FUNCTION
437
/*-----------------------------------------------------------*/
438
 
439
 
440
#define volatile
441
#define register
442
 
443
#endif /* PORTMACRO_H */
444
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.