Embedded Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsComputer HardwareEmbedded Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 11th, 2011, 07:26 AM
ammamon ammamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 2 ammamon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 32 sec
Reputation Power: 0
Code optimization problem with IAR (version 5.10.1.50144) MSP430 compiler.

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);
    }

}

Reply With Quote
Reply

Viewing: Dev Shed ForumsComputer HardwareEmbedded Programming > Code optimization problem with IAR (version 5.10.1.50144) MSP430 compiler.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap