Skip to content

dsPIC33CK port #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
#ifndef INC_FREERTOS_H
#define INC_FREERTOS_H

/*
* On Microchip xc16 target there will be undefined reference to _Nop
* xc.h is supplied by Microchip and defines Nop
*/
#include <xc.h>

/*
* Include the generic headers required for the FreeRTOS port being used.
*/
Expand Down
42 changes: 41 additions & 1 deletion portable/MPLAB/PIC24_dsPIC/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,41 @@ UBaseType_t uxCriticalNesting = 0xef;

#endif /* defined( __dsPIC30F__ ) || defined( __dsPIC33F__ ) */

#if defined( __dsPIC33C__ )

#define portRESTORE_CONTEXT() \
asm volatile( "MOV _pxCurrentTCB, W0 \n" /* Restore the stack pointer for the task. */ \
"MOV [W0], W15 \n" \
"POP W0 \n" /* Restore the critical nesting counter for the task. */ \
"MOV W0, _uxCriticalNesting \n" \
"POP DSWPAG \n" /* See https://forums.freertos.org/t/i-have-a-problem-in-using-freertosv10-1-1-the-mcu-is-iteratively-rebooting-and-not-executing-task-function/7551 */ \
"POP DSRPAG \n" \
"POP CORCON \n" \
"POP DOENDH \n" \
"POP DOENDL \n" \
"POP DOSTARTH \n" \
"POP DOSTARTL \n" \
"POP DCOUNT \n" \
"POP ACCBU \n" \
"POP ACCBH \n" \
"POP ACCBL \n" \
"POP ACCAU \n" \
"POP ACCAH \n" \
"POP ACCAL \n" \
"POP TBLPAG \n" \
"POP RCOUNT \n" /* Restore the registers from the stack. */ \
"POP W14 \n" \
"POP.D W12 \n" \
"POP.D W10 \n" \
"POP.D W8 \n" \
"POP.D W6 \n" \
"POP.D W4 \n" \
"POP.D W2 \n" \
"POP.D W0 \n" \
"POP SR " );

#endif /* defined( __dsPIC33C__ ) */

#ifndef portRESTORE_CONTEXT
#error Unrecognised device selected

Expand Down Expand Up @@ -185,7 +220,7 @@ const StackType_t xInitialStack[] =
0xabac, /* TBLPAG */

/* dsPIC specific registers. */
#if defined( __dsPIC30F__ ) || defined( __dsPIC33F__ )
#if defined( __dsPIC30F__ ) || defined( __dsPIC33F__ ) || defined( __dsPIC33C__ )
0x0202, /* ACCAL */
0x0303, /* ACCAH */
0x0404, /* ACCAU */
Expand Down Expand Up @@ -295,8 +330,13 @@ const uint32_t ulCompareMatch = ( ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) /
IEC0bits.T1IE = 1;

/* Setup the prescale value. */
#if defined( __dsPIC33C__ )
/* Microchip's header file p33CK128MP505.h does not have separate TCKPSx */
T1CONbits.TCKPS = 1; /* Value of 1 simply copied over from old code */
#else
T1CONbits.TCKPS0 = 1;
T1CONbits.TCKPS1 = 0;
#endif /* if defined( __dsPIC33C__ ) */

/* Start the timer. */
T1CONbits.TON = 1;
Expand Down
81 changes: 81 additions & 0 deletions portable/MPLAB/PIC24_dsPIC/portasm_dsPIC.S
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,84 @@ _vPortYield:
.end

#endif /* defined( __dsPIC30F__ ) || defined( __dsPIC33F__ ) */

#if defined( __dsPIC33C__ )

.global _vPortYield
.extern _vTaskSwitchContext
.extern uxCriticalNesting

_vPortYield:

PUSH SR /* Save the SR used by the task.... */
PUSH W0 /* ....then disable interrupts. */
MOV #32, W0
MOV W0, SR
PUSH W1 /* Save registers to the stack. */
PUSH.D W2
PUSH.D W4
PUSH.D W6
PUSH.D W8
PUSH.D W10
PUSH.D W12
PUSH W14
PUSH RCOUNT
PUSH TBLPAG
PUSH ACCAL
PUSH ACCAH
PUSH ACCAU
PUSH ACCBL
PUSH ACCBH
PUSH ACCBU
PUSH DCOUNT
PUSH DOSTARTL
PUSH DOSTARTH
PUSH DOENDL
PUSH DOENDH


PUSH CORCON
PUSH DSRPAG /* See https://forums.freertos.org/t/i-have-a-problem-in-using-freertosv10-1-1-the-mcu-is-iteratively-rebooting-and-not-executing-task-function/7551 */
PUSH DSWPAG
MOV _uxCriticalNesting, W0 /* Save the critical nesting counter for the task. */
PUSH W0
MOV _pxCurrentTCB, W0 /* Save the new top of stack into the TCB. */
MOV W15, [W0]

call _vTaskSwitchContext

MOV _pxCurrentTCB, W0 /* Restore the stack pointer for the task. */
MOV [W0], W15
POP W0 /* Restore the critical nesting counter for the task. */
MOV W0, _uxCriticalNesting
POP DSWPAG
POP DSRPAG /* See https://forums.freertos.org/t/i-have-a-problem-in-using-freertosv10-1-1-the-mcu-is-iteratively-rebooting-and-not-executing-task-function/7551 */
POP CORCON
POP DOENDH
POP DOENDL
POP DOSTARTH
POP DOSTARTL
POP DCOUNT
POP ACCBU
POP ACCBH
POP ACCBL
POP ACCAU
POP ACCAH
POP ACCAL
POP TBLPAG
POP RCOUNT /* Restore the registers from the stack. */
POP W14
POP.D W12
POP.D W10
POP.D W8
POP.D W6
POP.D W4
POP.D W2
POP.D W0
POP SR

return

.end

#endif /* defined( __dsPIC33C__ ) */
3 changes: 3 additions & 0 deletions portable/MPLAB/PIC24_dsPIC/portmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
#define portSTACK_TYPE uint16_t
#define portBASE_TYPE short
#define portPOINTER_SIZE_TYPE size_t
#ifndef SIZE_MAX
/* Microchip xc16 and xc-dsc compilers already define SIZE_MAX in stdint.h */
#define SIZE_MAX ( ( size_t ) -1 )
#endif

typedef portSTACK_TYPE StackType_t;
typedef short BaseType_t;
Expand Down
Loading