Jump to content


Photo

Typedef Struct Boost C Compiler Error

typedef struct union

5 replies to this topic

#1 Badejavu

Badejavu

    Regular

  • EstablishedMember
  • Pip
  • 27 posts
  • Gender:Male

Posted 04 October 2012 - 12:30 PM

Hello,
I am trying to port a Hi-tech C source code from microchips website( Real Time Clock) AN1414 to boost C.This bit of code keeps giving a compiler error.Can anyone please help?

//Code:
///////////////////////////

typedef struct{

union{
unsigned char DummyVal; //This will be used when Alarm is to be read
struct{
unsigned Day : 3;
unsigned ALMIF : 1;
unsigned ALMConfig : 3;
unsigned ALMPOL : 1;
};
};
unsigned char Sec;
unsigned char Min;
unsigned char Hour;
unsigned char Date;
unsigned char Month;
}RTCCAlarm;




//Error:
////////////////////////////

RTCC_Driver.c
RTCC_Driver.h(31): error: general error
RTCC_Driver.h(31): error: missing right brace
RTCC_Driver.h(31): error: general error
RTCC_Driver.h(31): error: missing right brace
RTCC_Driver.h(31): error: identifier expected
RTCC_Driver.h(31): error: missing right brace



Thanks
Badejo

#2 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 660 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 04 October 2012 - 06:53 PM

Hi Badejo,

BoostC does not allow bit structures.

You will have to get access to the bits with a byte with a little of extra code.

Cheers

Reynard

#3 JorgeF

JorgeF

    Super Enthusiast

  • EstablishedMember
  • PipPipPip
  • 274 posts
  • Gender:Male
  • Location:ES @ Europe, third rock from the Sun

Posted 05 October 2012 - 06:33 PM

Hi

This is one of the weak points I find in BoostC.
The error messages, they simply suck!
Most of the times we have to "guess" what the error is.


Best regards
Jorge

#4 Badejavu

Badejavu

    Regular

  • EstablishedMember
  • Pip
  • 27 posts
  • Gender:Male

Posted 06 October 2012 - 01:08 PM

Hi Reynard,
Any suggestions.I am new to boost C.

Thanks

#5 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 660 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 06 October 2012 - 02:18 PM

There are several ways to skin a cat. Here's one of them.

#include <system.h>
typedef struct
{
/*
union{
  unsigned char DummyVal; //This will be used when Alarm is to be read
  struct{
   unsigned Day : 3;
   unsigned ALMIF : 1;
   unsigned ALMConfig : 3;
   unsigned ALMPOL : 1;
  };
};
*/
unsigned char Alarm; // Alarm register data.
unsigned char Sec;
unsigned char Min;
unsigned char Hour;
unsigned char Date;
unsigned char Month;
} RTCCAlarm;
#define ALM_DAY2 7
#define ALM_DAY1 6
#define ALM_DAY0 5
#define ALM_IF  4
#define ALM_CONFIG2 3
#define ALM_CONFIG1 2
#define ALM_CONFIG0 1
#define ALM_POL  0
#define ALM_DAY_MASK ((1 << ALM_DAY2) | (1 << ALM_DAY1) | (1 << ALM_DAY0))
#define ALM_CONFIG_MASK ((1 << ALM_CONFIG2) | (1 << ALM_CONFIG1) | (1 << ALM_CONFIG0))
RTCCAlarm xRTC, *pxRTC;
void main()
{
unsigned char ucAlarmDay;
pxRTC = &xRTC;
pxRTC->Alarm = RTC_AlarmRegister; // read RTC chip alarm register.
if (pxRTC->Alarm & (1 << ALM_IF)) // test alarm IF bit.
{
  ucAlarmDay = (pxRTC->Alarm & ALM_DAY_MASK) >> 5; // get day value.
}
}
 

You can access the RTC structure using a pointer or direct addressing.

Cheers Reynard

Edited by Reynard, 06 October 2012 - 02:33 PM.


#6 Badejavu

Badejavu

    Regular

  • EstablishedMember
  • Pip
  • 27 posts
  • Gender:Male

Posted 06 October 2012 - 07:35 PM

Thanks Reynard



Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users