I’m in the processing of bringing up the dsPIC DSC start kit and I think I have all my bases covered, but apparently that isn’t the case. I’ve already trawled through the discussions for any issue related to this, but it hasn’t helped. I’m loading a simple build that just blinks an LED periodically. The problem is it looks as if something keeps resetting the processor. I’m clearing the watchdog, but it doesn’t seem to have any effect.
Could someone give this a look and tell me where I might be going wrong. I’ve successfully implemented FreeRTOS on NiosII, so I’m not a newbie at this.
~~~~
ifndef FREERTOSCONFIGH
define FREERTOSCONFIGH
define MPLABDSPICPORT
include <p33FJ256GP506.h>
define configUSE_PREEMPTION 1
define configUSEIDLEHOOK 0
define configUSETICKHOOK 0
define configTICKRATEHZ ((TickType_t) 1000)
define configCPUCLOCKHZ ((unsigned long) 12000000) /* Fosc / 2 */
define configMAX_PRIORITIES (4)
define configMINIMALSTACKSIZE (105)
define configTOTALHEAPSIZE (( size_t ) 8192)
define configMAXTASKNAME_LEN (4)
define configUSETRACEFACILITY 0
define configUSE16BIT_TICKS 0
define configIDLESHOULDYIELD 0
/* Co-routine definitions. */
define configUSECOROUTINES 0
define configMAXCOROUTINE_PRIORITIES (2)
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
define INCLUDE_vTaskPrioritySet 1
define INCLUDE_uxTaskPriorityGet 1
define INCLUDE_vTaskDelete 1
define INCLUDE_vTaskCleanUpResources 0
define INCLUDE_vTaskSuspend 1
define INCLUDE_vTaskDelayUntil 1
define INCLUDE_vTaskDelay 1
define configKERNELINTERRUPTPRIORITY 0x01
// FBS
pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment)
pragma config RBS = NO_RAM // Boot Segment RAM Protection (No Boot RAM)
// FSS
pragma config SWRP = WRPROTECT_OFF // Secure Segment Program Write Protect (Secure Segment may be written)
pragma config SSS = NO_FLASH // Secure Segment Program Flash Code Protection (No Secure Segment)
pragma config RSS = NO_RAM // Secure Segment Data RAM Protection (No Secure RAM)
// FGS
pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected)
pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)
// FOSCSEL
pragma config FNOSC = FRC // Oscillator Mode (Internal Fast RC (FRC))
pragma config IESO = OFF // Two-speed Oscillator Start-Up Enable (Start up with user-selected oscillator)
// FOSC
pragma config POSCMD = NONE // Primary Oscillator Source (Primary Oscillator Disabled)
pragma config OSCIOFNC = ON // OSC2 Pin Function (OSC2 pin has digital I/O function)
pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are disabled)
// FWDT
pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768)
pragma config WDTPRE = PR128 // WDT Prescaler (1:128)
pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)
// FPOR
pragma config FPWRT = PWR8 // POR Timer Value (8ms)
// FICD
pragma config ICS = PGD1 // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled)
//————————————————————————-
LED *LED_Init (SYS_INT_t period, SYS_INT_t set_task_priority, SYS_INT_t clr_task_priority) {
//————————————————————————-
// allocate led space
LED *pLED = (LED *)(pvPortMalloc (sizeof(LED)));
// exit if space couldn’t be allocated
if (pLED == NULL) return NULL;
// initialize yellow led port pin
PORT
BITTRI(C,13) = 0;
PORT
BITLAT(C,13) = 0;
// initialize red led port pin
PORT
BITTRI(C,14) = 0;
PORT
BITLAT(C,14) = 0;
// initialize green led port pin
PORT
BITTRI(C,15) = 0;
PORT
BITLAT(C,15) = 0;
// set heart beat period
LED
HEARTBEATPERIOD = period;
// allocate led messeging queue, start task if queue space allocated
LED
QUEUE = xQueueCreate (32, sizeof(LEDMSG));
if (LED
QUEUE != NULL) {
// led gateway clear control task
xTaskCreate (
LEDClr
Task,
“LedClear”,
32,
(void *)pLED,
clrtask_priority,
NULL);
}
return pLED;
}
//————————————————————————-
static void LED
ClrTask (void *pvParam) {
//————————————————————————-
//LED *pLED = (LED *)pvParam;
U32 idx;
portTickType xLastWakeTime;
// get initial wake count, next hearbeat time
xLastWakeTime = xTaskGetTickCount ();
//xHeartBeatTime = xLastWakeTime + (portTickType)LED
HEARTBEATPERIOD;
// task loop
for (;;) {
// wait 100 ticks
vTaskDelay (100);
// clear watchdog timer
ClrWdt();
PORT_BIT_LAT(C,15) = ~PORT_BIT_LAT(C,15); // toggle pin (amber LED on demo board DM330011)
// wait 100 ticks
vTaskDelay (100);
// clear watchdog timer
ClrWdt();
PORT_BIT_LAT(C,15) = ~PORT_BIT_LAT(C,15);
vTaskDelayUntil (&xLastWakeTime, 300);
// clear watchdog timer
ClrWdt();
}
// delete task when complete
vTaskDelete(NULL);
}
~~~~