Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

Code optimization problem with IAR (version 5.10.1.50144) MSP430 compiler.

Status
Not open for further replies.

ammamon

Newbie level 4
Joined
Jun 28, 2006
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,327
I have written an rtc module for MSP430 device which captures date/time every one minute. This module uses freertos queue for sending the date/time event to another task. Though the time date-time details are captured every one minute, one or more of the details (either year, month, hour or ..) are getting corrupted depending upon whether the code optimization is set or not and whether the event object (ui_queue_event variable in the code below into which RTC time details are loaded ) is declared static or local in the interrupt function.

Actually there are 4 test cases.
1. Optimization set to none and time receiving event object declared local.
2. Optimization set to a value and time receiving event object declared local.
3. Optimization set to none and time receiving event object declared static.
4. Optimization set to a value and time receiving event object declared static.

The time data is corrupted consistently for each of the above 4 cases. In one case, it may be year corruption, in another case it may be hour corruption and so on. All the time details may be consistently correct for one of the cases. The pattern of corruption remained the same as long as the code is IAR compiled on a particular system. But if I compile the code in another system, the pattern of corruption for the above 4 cases differs. I tried compiling the code on 3 different systems running version 5.10.1.50144 of IAR MSP430 compiler.

Another point is the I am getting the "second" always as zero even when if I set it to a value during initialization of RTC module.

Can this be a stack problem? I am not getting any stack overflow error messages while debugging. Or is FreeRTOS creating problems here? Please help.

I am listing below the rtc code and the test code.

RTC Module code

Code:
#include "rtc.h"
#include "FreeRTOS.h"
#include "queue.h"

extern xQueueHandle ui_queue;

void rtc_set_date(rtc_date_struct_t *new_date)
{
    RTCCTL01 = RTCMODE + RTCHOLD + RTCTEVIE + RTCTEV_0;
    RTCYEAR = new_date->year;
    RTCDOW = new_date->dow;
    RTCMON = new_date->month;
    RTCDAY = new_date->dom;
    RTCHOUR = new_date->hour;
    RTCMIN = new_date->min;
    RTCSEC = new_date->sec;
    RTCCTL01 &= ~RTCHOLD;
    __enable_interrupt(); /* Sets GIE in status register */
}

#pragma vector=RTC_VECTOR
__interrupt void handle_rtc_interrupt(void) 
{
    ui_event_struct_t ui_queue_event;   
    __disable_interrupt();
    switch(RTCIV)
    {
        case 2U:  /* RTC Ready Event */
        {
            portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

            ui_queue_event.event_type = UI_QUEUE_EVENT_ONE_MIN_RTC;
            ui_queue_event.year = RTCYEAR;
            ui_queue_event.month = RTCMON;
            ui_queue_event.dom = RTCDAY;
            ui_queue_event.dow = RTCDOW;
            ui_queue_event.hour = RTCHOUR;
            ui_queue_event.minute = RTCMIN;
            ui_queue_event.sec = RTCSEC;
            RTCCTL01 |= RTCHOLD;
            RTCCTL01 &= ~RTCRDYIE;
            RTCCTL01 &= ~RTCHOLD;
            __enable_interrupt(); 
            xQueueSendFromISR(ui_queue, (void *) &ui_queue_event, &xHigherPriorityTaskWoken);
            if (xHigherPriorityTaskWoken)
            {
                portYIELD();
            }
            break;
        }
        case 4U:        /* RTC Minute Interval Event */
        {
            RTCCTL01 |= RTCHOLD;
            RTCCTL01 |= RTCRDYIE;  /* Enable Ready Flag Interrupt */
            RTCCTL01 &= ~RTCHOLD;
            break;
        }
        default:
        {
            __no_operation();                         /* For debugger */
            break;
        }
    }
    RTCIV &= 0x00U;
    __enable_interrupt(); 
}

Test Code:

Code:
#include "msp430F5419.h"
#include "global.h"
#include "rtc.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include <stdio.h>
#include <assert.h>

xQueueHandle ui_queue;
static void event_listener_ui_task (void * params);
static void ui_client_requests_task(void * params);


int16_t main(void)
{
    WDTCTL = WDTPW + WDTHOLD;
    ui_queue = xQueueCreate( 10, sizeof(ui_event_struct_t) );
    xTaskCreate (ui_client_requests_task, (const signed portCHAR * const) "UI Client Requests Task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
    xTaskCreate (event_listener_ui_task, (const signed portCHAR * const) "Event Listener UI Task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
    vTaskStartScheduler();
    return 0;
   
}

static void ui_client_requests_task( void *  pvParameters )
{
    static rtc_date_struct_t date;
    date.year = 2011U;
    date.month = 2U;
    date.dom = 8U;
    date.dow = 2U;
    date.hour = 11U;
    date.min = 16U;
    date.sec = 30U;  
    rtc_set_date(&date);
    while (1==1)
    {
      //infinite loop
    }
}

static void event_listener_ui_task( void * pvParameters)
{
    static ui_event_struct_t ui_queue_event;
    while( 1==1)
    {
        portBASE_TYPE receive_status =  xQueueReceive(ui_queue, &ui_queue_event, portMAX_DELAY);
        assert(pdPASS == receive_status);
        assert(ui_queue_event.event_type == UI_QUEUE_EVENT_ONE_MIN_RTC);
        printf("%i,", ui_queue_event.year);
        printf("%i,", ui_queue_event.dom);
        printf("%i,", ui_queue_event.dow);
        assert(ui_queue_event.year == 2011U);
        assert(ui_queue_event.month == 2U);
        assert(ui_queue_event.dom == 8U);
        assert(ui_queue_event.dow == 2U);
        printf("%i,", ui_queue_event.hour);
        printf("%i,", ui_queue_event.minute);
        printf("%i\n", ui_queue_event.sec);
    }

}


Regards,
Ammamon
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top