#154067 - sverx - Thu Apr 10, 2008 12:17 pm
Hi there,
it's my first post so, first of all, I greet everyone in here :)
I've been searching this forum but I didn't find an answer so I decided to post the question directly ;)
I wrote my own arm7 code to communicate with the RTC. I can read the current time, I can read & set the alarm1 and the alarm2, everything it's done using the ndslib function
Then I said the SIO to trigger the RTC IRQ
and of course I enabled the IRQ_NETWORK flag.
Did I forgot something? I can't get the IRQ request when the time I've set into the alarm1 comes...
I'm using no$gba... because AFAIK it's the only emulator that emulates the RTC.
Every help will be appreciated. And excuse my not so perfect english...
Ciao! :)
#154072 - silent_code - Thu Apr 10, 2008 3:14 pm
hi! greets and welcome! :^)
one short hint: are you really using the deprecated ndslib or did you mean libnds? ;^)
don't rely on emulators. if it seems to not work, test it on hw. until now, all my clock readings were wrong in emus, but the code worked flawlessly on the hw.
as to your specific problem, i am not much of a help. sure some others will respond soon.
happy coding!
#154075 - sverx - Thu Apr 10, 2008 3:58 pm
silent_code wrote: |
are you really using the deprecated ndslib or did you mean libnds? ;^) |
right, it's libnds... installed.ini says:
Code: |
[libnds]
Version=20070503 |
and it makes me think: where can I check which is the current version? (not for downloading it, actually, just to check...)
#154076 - silent_code - Thu Apr 10, 2008 4:11 pm
on devkitPro's sourceforge page. :^)
there's a more recent version out!
#154116 - sverx - Fri Apr 11, 2008 11:28 am
Thanks :) There's even one more release today! :)
By the way... no idea about the "main" question?
#154452 - sverx - Wed Apr 16, 2008 4:00 pm
It's not working even on a real hardware... so there's something wrong I guess :|
Following this: http://nocash.emubase.de/gbatek.htm#dsrealtimeclockrtc
I made a little function to set the alarm n.1 at a specified time. I'm quite sure it works (I made a little function to read the alarm and it confirmed me the time has been set...)
Of course to access the alarm n.1 I first had to change the value of the status register 2, doing that:
Code: |
newvalue = ((oldvalue & 0xF0) | 0x04) |
well... nothing, no IRQ :|
mmm... I guess there's also a little mistake in clock.h... it says
Code: |
#define READ_INT_REG2 0x6A
#define WRITE_INT_REG2 0x6B |
aren't them swapped?
#154481 - Cydrak - Wed Apr 16, 2008 9:44 pm
Can you post source/commands you're sending?
Notably, values are BCD, and each alarm field has a bit that determines what values need to match. If clear, they act as sort of a wildcard.
Another thing to check, the SI interrupt is edge triggered. I guess you might try to disable both alarms first, since they share the same line. You can also read status1 to see if the INT1/2 flags are showing up.
#154523 - sverx - Thu Apr 17, 2008 9:22 am
Cydrak wrote: |
Can you post source/commands you're sending?
Notably, values are BCD, and each alarm field has a bit that determines what values need to match. If clear, they act as sort of a wildcard.
Another thing to check, the SI interrupt is edge triggered. I guess you might try to disable both alarms first, since they share the same line. You can also read status1 to see if the INT1/2 flags are showing up. |
Thanks for your reply... well, I know values are BCD and I know about that MSB that set/cleared means different comparison. Here's the function I wrote to set the alarm (I always work in 24hrs mode)
Code: |
void RTCWriteAlarm (Alarm_Type* as) {
uint8 command[4];
switch (as->alarm) {
case 1: command[0] = WRITE_INT_REG1;
break;
case 2: command[0] = WRITE_INT_REG2;
break;
}
command[1]= (as->day & 0x07);
// check if it's NOT everyday
if (as->everyday==0)
command[1] |= 0x80;
command[2]= as->hours;
command[3]= as->minutes;
integerToBCD(&command[2],2);
// set the compare enable bits, so that the IRQ got fired ONLY when it's the right hour:minute
command[2] |= 0x80;
command[3] |= 0x80;
rtcTransaction (&command[0], 4, 0, 0);
} |
I'm quite sure it works smooth, I've got a similar function to read the alarm and it confirms me that the alarm gets written :|
Of course I also disable both the alarms at the beginning of the program
Code: |
// reset BOTH alarms
RTCWriteStatus2 (RTCReadStatus2() & 0xB0); |
and I also enable the alarm I want to use (following code is for alarm 1)
Code: |
RTCWriteStatus2 ((RTCReadStatus2() & 0xF0) | 0x04); |
... finally also the SIO has been set to trigger the interrupt
Code: |
REG_RCNT = 0x8100; // general purpose mode (0x8000) , interrupt enabled (0x0100) |
and the IRQ it's working, I know it because if I set the alarm1 to trigger every minute
Code: |
RTCWriteStatus2 ((RTCReadStatus2() & 0xF0) | 0x02); |
it works, I receive the IRQ every 60 seconds.
Ideas? :|
#155018 - HyperHacker - Wed Apr 23, 2008 11:07 pm
So it works if you set it to go off every minute, but not if you set it to go off just once? Are you specifying the same time in both cases? If so, I'd look closer at whatever bits you're specifying differently to choose single/repeated alarms.
_________________
I'm a PSP hacker now, but I still <3 DS.
#155023 - Cydrak - Thu Apr 24, 2008 12:50 am
Here's essentially what I'm doing. Looks a lot like yours:
Code: |
// reg: alarm register to set.
// time: a value of 0xWWHHMMSS (weekday, hour, min, sec)
// Values are binary; seconds field is ignored.
// Default is to set hour/minute.
// Otherwise, set bit 7 for the chosen fields.
//
u32 clockSetAlarmReg(int reg, u32 time)
{
u8 cmd[4] = { reg, 0, 0, 0 };
IRQGuard gu(0);
// Default to setting hour and minute if not specified
if(time && !(time & (setTime|setDate)))
time |= setTime;
// Even in 24-hour mode, AM/PM bits are still updated,
// ...so apparently the alarm must match.
int pm = (time>>16 & 0x1f) >= 12? 0x40 : 0x00;
// Fix up for 12 hour mode
if(pm && (~g_mode & STATUS_24HRS))
time -= 12 << 16;
if(time & setWeekday) cmd[1] = 0x80 | toBcd(time>>24 & 0x07);
if(time & setHour) cmd[2] = 0x80 | toBcd(time>>16 & 0x1f) | pm;
if(time & setMinute) cmd[3] = 0x80 | toBcd(time>> 8 & 0x3f);
rtcTransaction(cmd, 4, 0, 0);
return time | alarmEnabled;
}
u32 clockSetAlarm2(u32 time)
{
clockClearMode(STATUS_INT2AE);
if(!time) return g_alarm2 &= ~alarmEnabled;
clockSetMode(STATUS_INT2AE);
g_alarm2 = clockSetAlarmReg(WRITE_INT_REG2, time);
g_alarm2 |= time & alarmFlagsMask;
return g_alarm2;
} |
I noticed a couple more things, though. First is that I couldn't get RTC interrupts under NO$GBA at all, although reading the time worked. And I think you're right, some of the #defines were swapped...
The other is that 24-hour mode still updates the AM/PM flag. If the alarm hour is set for 12..23, but missing the PM (0x40), it's not going to fire.
If this still doesn't fix it, I trimmed out my somewhat lightly-tested RTC code. (Mind the naive FIFO stuff... it's months old, but anyway not hard to replace.)
#155043 - sverx - Thu Apr 24, 2008 11:58 am
Cydrak wrote: |
I noticed a couple more things, though. First is that I couldn't get RTC interrupts under NO$GBA at all, although reading the time worked. |
I can get the IRQ under NO$GBA only when Alarm1 type is 'Per-minute edge interrupt' (0x02) ... :|
Cydrak wrote: |
The other is that 24-hour mode still updates the AM/PM flag. If the alarm hour is set for 12..23, but missing the PM (0x40), it's not going to fire. |
Yes, I also realized it -a couple of days ago- reading the datasheets, so I added this line to my function (command[2] is where I store the alarm 'hour', in BCD)
Code: |
// set the AM/PM bit
command[2] |= ((as->hours>=12)?0x40:0x00); |
... still no IRQ. :|
Cydrak wrote: |
If this still doesn't fix it, I trimmed out my somewhat lightly-tested RTC code. |
I gave a look at your code one minute ago... but still didn't find something so different from mine :|
Thanks once more... I'll keep on comparing your code to mine until something comes out. Your code works, right? :)
#155044 - sverx - Thu Apr 24, 2008 12:00 pm
HyperHacker wrote: |
So it works if you set it to go off every minute, but not if you set it to go off just once? Are you specifying the same time in both cases? If so, I'd look closer at whatever bits you're specifying differently to choose single/repeated alarms. |
No, I mean it works when I use 'Per-minute edge interrupt' mode (0x02) ... but NO, it's not working when I reset the 'compare bits' (the MSB) in the day-of-week and hour and minute registers...
#155053 - shash - Thu Apr 24, 2008 2:48 pm
If anyone has handy a sample of the RTC alarm with interrupts and such, I'll fix it on DesMuME as soon as I can.
_________________
http://shashemudev.blogspot.com
#155054 - sverx - Thu Apr 24, 2008 3:07 pm
shash wrote: |
If anyone has handy a sample of the RTC alarm with interrupts and such, I'll fix it on DesMuME as soon as I can. |
if you mean 'a .nds that works on hardware' I found one here.
If you mean something else, sorry, I didn't get what you need. Explain me and I'll help you as much as possible.
Thanks :)
#155062 - shash - Thu Apr 24, 2008 6:00 pm
sverx wrote: |
shash wrote: | If anyone has handy a sample of the RTC alarm with interrupts and such, I'll fix it on DesMuME as soon as I can. |
if you mean 'a .nds that works on hardware' I found one here.
If you mean something else, sorry, I didn't get what you need. Explain me and I'll help you as much as possible.
Thanks :) |
I basically meant a simple ".nds" that works on hardware and doesn't on emulators, I don't know if that link you posted is what you're looking to be fixded on emulators. I don't have much time lately, so a concise sample would be the best towards fixing this fast :)
_________________
http://shashemudev.blogspot.com
#155065 - sverx - Thu Apr 24, 2008 6:20 pm
shash wrote: |
I basically meant a simple ".nds" that works on hardware and doesn't on emulators |
mmm... no, then it's wrong. :(
That one works on hardware and also works on NO$GBA emulator. At the moment it's my code that doesn't work on the emulator... and unfortunatly I can do only few tests on hardware. The few I've done, it wasn't working. I guess anyway it's a problem of my code, even if I don't know where the problem is. The last problem is that when I'll find the mistake and correct it, I'm not sure I'll notice it (on the emulator...) :|
Thanks anyway!
Ciao :)
#155086 - Cydrak - Thu Apr 24, 2008 9:21 pm
sverx wrote: |
Thanks once more... I'll keep on comparing your code to mine until something comes out. Your code works, right? :) |
Er, yes, it should... The posted code was a summary, mind. The *.zip is what I tested. Certain settings like 12-hour or the clock correction weren't really tested, but IRQs work for my DSLite. On NO$GBA though, it never sees an IRQ and the status bits stay clear, although all the registers appear to be set.
sverx wrote: |
That one works on hardware and also works on NO$GBA emulator. |
Hm, are there sources to that? How do you know it's using the RTC interrupt, and not something else? (Vblank, timers... really, the main appeal of the RTC is that you can go entirely to sleep and still wake up, whereas most hardware and interrupts would be paused.)
shash wrote: |
If anyone has handy a sample of the RTC alarm with interrupts and such, I'll fix it on DesMuME as soon as I can. |
What I posted covers the main IRQs at least. I should probably beef up the example so one can fool with things like 12-hour, setting the time, etc...
sverx wrote: |
At the moment it's my code that doesn't work on the emulator... and unfortunatly I can do only few tests on hardware. |
I found it well worth my time to get a wifi solution working. Doubly so when I can soft-reboot, which brings the testing time well under a minute, under 10 sec in some cases. As a result, I almost never test on emulators...
(Unfortunately the tool I use doesn't seem supported now, I heavily modified it anyway, and the original link is broken, so I'm not sure what to suggest for that. :/)
#155328 - sverx - Mon Apr 28, 2008 10:13 am
Cydrak wrote: |
sverx wrote: | That one works on hardware and also works on NO$GBA emulator. |
Hm, are there sources to that? How do you know it's using the RTC interrupt, and not something else? (Vblank, timers... really, the main appeal of the RTC is that you can go entirely to sleep and still wake up, whereas most hardware and interrupts would be paused.) |
Well ... :| You're right, I don't know about that :|
(I'm still working on it... but there could be some news... )
#155413 - sverx - Tue Apr 29, 2008 11:23 am
It's working now! :) Well, I'm not really sure what was exactly that made it... (maybe it's that you need to reset the alarm status to 'disable' before setting it again ON and setting a new alarm time? mmm... still not sure...) but now, on a real NDS -I mean hardware- it works. It's not working on any emulator... so maybe shash can try to fix DesMuME ?
Thanks everybody (well, especially Cydrak!) for the help.
See you soon with new problems ;)
Ciao! :D
#155460 - shash - Tue Apr 29, 2008 8:51 pm
I will have a some free time the following days, so if you can send me or upload it elsewhere I'll spend a few hours trying to fix it.
_________________
http://shashemudev.blogspot.com
#155506 - sverx - Wed Apr 30, 2008 8:35 am
shash wrote: |
if you can send me or upload it elsewhere |
I sent you a PM right now :) Thanks :)