Jump to content
Badejavu

Typedef Struct Boost C Compiler Error

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×