We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
This is going to be a strange request. I must warn that I am new to embedded programming and therefore what is obvious to you may not be to me. I am trying to implement a real time clock program with the data then being transmitted on CAN. I am getting some warning when I compile my code and cannot understand what I need to do. Any help would be appreciated. I will be posting my code in parts as I cannot exceed a certain character limit.
Main.c
//********************************************* // Demo to TX Real Time Clock Information //Main File //********************************************* #include "main.h" extern void timer1s(void) { unsigned int time_count; T3CON = 0x0007;//initializing timer3 control register while 'counting up' T3 = 0; //setting minimum value for Timer3 counter time_count = T3; T3R = 1; while(1) { extern currentRT(); if (T3>=19532) //1s timer { CAN_NQS_time_date(); T3 = 0; } } } void main(void) { /*initializing the SYSCON registry - xBUS peripherals are made visible - On chip XBUS peripherals are enabled - RSTIN is i/p only - watchdog is disabled - Latched CS mode - WR acts as WRL, BHE acts as WRH - CLKOUT disabled - BHE disabled - Internal memory disabled - Segmentation enabled - ROM area mapped to segment 1 - Stack size 256 words (000h) */ //SYSCON = 0x3CAB; //DP4 = 0x0040; IEN=1; //Projectinit(); CANinit(); }
RTC.c
//*************************************** //SIMPLE RTC IMPLEMENTATION //*************************************** #include "REG164.h" #include "RTC_C16x.h" #include "MATH.H" struct temptime { int daysa; int daysb; int hour; int minute; int seconds; int day; int month; int year1; int year2; }time; static unsigned int RTCvalue; int current_day = 25; int current_month =9 ; int current_year = 2008; union _32bit { unsigned int rtcreg[1]; unsigned int a; } RTC; void RTCinit(void) { RTCL = 0; //clearing lower RTC register RTCH = 0; //clearing higher RTC register RTCvalue = 16*3600 + 0*60+30; // converting time 4:00:30 PM into seconds RTC.a = RTCvalue; RTCL = RTC.rtcreg[0];//storing time value in s into the RTC registers RTCH = RTC.rtcreg[1]; //storing time value in s into the RTC registers T14REL = 0xB3B5; //initializing RTC for 1s increment currentRT(); } int currentRT(void) { double x,y,z; RTC.rtcreg[0] = RTCL; //reading the RTC register value RTC.rtcreg[1] = RTCH; //reading the RTC register value RTCvalue = RTC.a; x = RTCvalue/86400; time.daysa = floor(x); RTCvalue = RTCvalue-(time.daysa*86400);//extracting number of days elapsed since any value over 86400 implies 1 days has passed time.daysb = 0; if(time.daysa>time.daysb) { current_day = current_day+1; } time.daysb = time.daysa; y = RTCvalue/3600; time.hour = floor(y); RTCvalue = RTCvalue-(time.hour*3600);//extracting the hour information z = RTCvalue/60; time.minute = floor(z); RTC_CAN(); } int RTC_CAN(void) { //check for month and then either reset or increment day switch (current_month){ case 1: case 3: case 5: case 7: case 9: case 11: if(current_day == 32) { current_day=1; current_month = current_month+1; } case 4: case 6: case 8: case 10: case 12: if(current_day == 31) { current_day = 1; current_month = current_month+1; if(current_month==13) { current_month=1; current_year=current_year+1; } } case 2: if(current_day == 29) { current_day = 1; current_month = current_month+1; } } //mapping what needs to be transmitted on CAN(BCD value) and it's decimal equivalent. if(time.hour<=9) { time.hour = time.hour; } else if(time.hour>=10 && time.hour<=19) { time.hour = time.hour+6; //hex 10=dec16, hex 11=dec17...hex19=dec25 } else if(time.hour>=20 && time.hour<=24) { time.hour = time.hour+12; //hex 20=dec32....hex 24=dec36 } if(time.minute<=9) { time.minute = time.minute; } else if(time.minute>=10 && time.minute<=19) { time.minute = time.minute+6; } else if(time.minute>=20 && time.minute<=29) { time.minute = time.minute+12; } else if(time.minute>=30 && time.minute<=39) { time.minute = time.minute+18; } else if(time.minute>=40 && time.minute<=49) { time.minute = time.minute+24; } else if(time.minute>=50 && time.minute<=59) { time.minute = time.minute+30; } if(current_day<=9) { time.day=current_day; } else if(current_day >=10 && current_day<=19) { time.day=current_day+6; } else if(current_day >=20 && current_day <=29) { time.day=current_day+12; } else if(current_day >=30 && current_day <=32) { time.day = current_day+18; } if(current_month<=9) { time.month = current_month; } else { time.month = current_month+6; } if(current_year==2008) { time.year1=32; time.year2=8; } else if(current_year==2009) { time.year1=32; time.year2=9; } else if(current_year==2010) { time.year1=32; time.year2=16; } timer1s(); }//end of RTC_CAN
CAN.c
//********************************************* // CAN transmit code //********************************************* #include "main.h" extern struct temptime { int daysa; int daysb; int hour; int minute; int seconds; int day; int month; int year1; int year2; }time; void CANinit(void) { //initializing CAN control registers C1CSR = 0x41; // initializes CAN controller C1BTR = 0x3453; //50Kb baudrate BFLD(DP4,0x0020,0x0000); BFLD(DP4,0x0040,0x0040); //initializing CAN messgae object and registers CAN_OBJ[0].MCR = 0x5695; CAN_OBJ[0].UAR = 0x60D0;//ID=0x683 (NQS_TIME&DATE) CAN_OBJ[0].LAR = 0x0000; CAN_OBJ[0].MCFG = 0x68; //DLC=6,DIR=1(TX), StdId //initializing data for CAN_OBJ[0] CAN_OBJ[0].Data[0] = time.hour; CAN_OBJ[0].Data[1] = time.minute; CAN_OBJ[0].Data[2] = time.day; CAN_OBJ[0].Data[3] = time.month; CAN_OBJ[0].Data[4] = time.year1; CAN_OBJ[0].Data[5] = time.year2; CAN_OBJ[0].Data[6] = 0x00; CAN_OBJ[0].Data[7] = 0x00; //end of data bytes //Following data objects are not used but still must be initialized. byte MSGVAL is set to invalid CAN_OBJ[1].MCR = 0x5555;//message object valid CAN_OBJ[2].MCR = 0x5555;//message object invalid CAN_OBJ[3].MCR = 0x5555;//message object invalid CAN_OBJ[4].MCR = 0x5555;//message object invalid CAN_OBJ[5].MCR = 0x5555;//message object invalid CAN_OBJ[6].MCR = 0x5555;//message object invalid CAN_OBJ[7].MCR = 0x5555;//message object invalid CAN_OBJ[8].MCR = 0x5555;//message object invalid CAN_OBJ[9].MCR = 0x5555;//message object invalid CAN_OBJ[10].MCR = 0x5555;//message object invalid CAN_OBJ[11].MCR = 0x5555;//message object invalid CAN_OBJ[12].MCR = 0x5555;//message object invalid CAN_OBJ[13].MCR = 0x5555;//message object invalid CAN_OBJ[14].MCR = 0x5555;//message object invalid // Resetting the CSR otherwise the module would get into an initialization loop C1CSR = 0x0000; RTCinit(); } void CAN_NQS_time_date(void) { CAN_OBJ[0].Data[0] = time.hour; CAN_OBJ[0].Data[1] = time.minute; CAN_OBJ[0].Data[2] = time.day; CAN_OBJ[0].Data[3] = time.month; CAN_OBJ[0].Data[4] = time.year1; CAN_OBJ[0].Data[5] = time.year2; CAN_OBJ[0].Data[6] = 0x00; CAN_OBJ[0].Data[7] = 0x00; CAN_OBJ[0].MCR = 0xe7ff; }
Warnings
Build target 'Phycore164' compiling RTC.C... RTC.C(43): warning C140: 'currentRT' undefined; assuming 'extern int currentRT()' RTC.C(64): warning C140: 'RTC_CAN' undefined; assuming 'extern int RTC_CAN()' RTC.C(192): warning C140: 'timer1s' undefined; assuming 'extern int timer1s()' RTC.C(65): warning C135: 'currentRT': no return value RTC.C(193): warning C135: 'RTC_CAN': no return value linking... *** WARNING L20: DATA TYPES DIFFERENT SYMBOL: timer1s MODULE: RTC.obj (RTC) creating hex file from "RTC"... "RTC" - 0 Error(s), 6 Warning(s).
Hmm, the warnings have nothing to do with embedded development. This is basic C stuff.
'func' undefined; assuming 'extern int func()' means what it says: the compiler encountered a call to a function which has not been declared yet. Functions should be declared before called, otherwise you are asking for trouble.
'func': no return value means that although the function definition says it returns a value, there is no return statement in the function body.
Time to read up on the C programming language.
Mike, Appreciate your response. However at the end of currentRT and RTC_CAN functions if I insert a return statement I still continue to get the warnings. I tried changing the functions from void to 'int' and it does nothing.
Note that 3 of the 5 warnings have nothing to do with return values anyhow - so you should not expect this to fix those ones!
If "adding a 'return' statement" doesn't fix the other 2 warnings (the ones about return values), then you must be doing it wrong. You would obviously need to post the code for anyone to be able to see exactly what you're doing wrong...
while(1) { extern currentRT(); if (T3>=19532) //1s timer { CAN_NQS_time_date(); T3 = 0; } }
Why your "extern"? Are you trying to declare that there exists a function currentRT(), or are you calling the function?
Similarly for:
extern void timer1s(void) { unsigned int time_count;
As Mike said initially, it looks like time for some "back to basics" with the 'C' textbook...
See also: c-faq.com/.../decldef.html
Per, I am trying to say that a function called currentRT() exists in another module (RTC.c). Anyway I decided to download the program anyway as I had no errors. What I noticed is that after the RTC ticks over to 9:06:09 (i.e 9:06 and 09 seconds) I get garbage values. I have checked it a few times and everytime while transitioning from 9:06:08 to 9:06:09 something happens and I keep getting garbage values. Can anyone tell me what is going on? If there is some overflow issue how do I get around it?
You are trying to say that a function currentRT() exists in another module. But why, unless you where planning on also call the function?
Are you really sure that you have the correct time when you get into troubles?
9:06:08 = 9*3600 + 6*60 + 8 = 32768 = 0x8000. 9:06:07 = 9*3600 + 6*60 + 7 = 32767 = 0x7fff.
How big numbers to you think you can store in a signed 16-bit integer? I would kind of guess at -32768 .. +32767.
If you change to an unsigned integer, you will get 0 .. 65535 which corresponds to 00:00:00 .. 18:12:15.
So it seems like you have to switch to a long 32-bit value to keep track of your time. There are 86400 seconds in 24 hours.
Just a footnote: Old MS-DOS (FAT directory entries) only stored even seconds for the file time stamp, just to get the clock value to fit in a 16-bit unsigned integer.
It makes you think: MS do get some things right :-)
Thanks. Will try it out. I am sure that was my mistake.