π
<-
Chat plein-écran
[^]

ndless memory map

C, C++, ASM...

Re: ndless memory map

Unread postby Ti64CLi++ » 03 Jul 2020, 14:11

You could always add a timer with the RTC for example which will turn the contrast back to its normal value if a certain time has elapsed ;)
Image
User avatar
Ti64CLi++Modo
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Level up: 91.3%
 
Posts: 3262
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender: Male
Calculator(s):
Class: Maths Sup
GitHub: Ti64CLi

Re: ndless memory map

Unread postby parisse » 03 Jul 2020, 15:10

Perhaps I was not clear enough, but this is not a problem, as you can see by looking at the code
Code: Select all
    if (allow_suspend && (autosuspend || (nspire_ctrl && on_key_pressed()))){
      nspire_ctrl=nspire_shift=false;
      while (!autosuspend && on_key_pressed())
   msleep(10);
      // somewhat OFF by setting LCD to 0
      unsigned NSPIRE_CONTRAST_ADDR=0x900f0020;
      unsigned oldval=*(volatile unsigned *)NSPIRE_CONTRAST_ADDR;
      *(volatile unsigned *)NSPIRE_CONTRAST_ADDR=0x100;
      while (!on_key_pressed()){
   msleep(100);
   idle();
      }
      *(volatile unsigned *)NSPIRE_CONTRAST_ADDR=oldval;
      statusline(0);
      sync_screen();
      lastt=* (volatile unsigned *) NSPIRE_RTC_ADDR;
      continue;
    }

The problem is the batteries drain, if you keep the calc in KhiCAS off mode, I think they will last 1 or 2 days. Therefore you must remember to leave KhiCAS after your math class. Or plugin the calc every evening (like a smartphone), but this might shorten your batteries life (and perhaps the LCD screen too because it's not really off).
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 4.1%
 
Posts: 2071
Joined: 13 Dec 2013, 16:35
Gender: Not specified

Re: ndless memory map

Unread postby Ti64CLi++ » 03 Jul 2020, 15:58

Then perhaps, when you set the contrast to 0x100, you could use a timer to quit KhiCAS after, I don't know, 4 hours of "sleep".
By doing so, the calc will automatically shutdown by herself.
And I think 4 hours is a good duration . People won't use it but for an exam or a class, so if they forgot to quit KhiCAS, it will do it on its own.
Image
User avatar
Ti64CLi++Modo
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Level up: 91.3%
 
Posts: 3262
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender: Male
Calculator(s):
Class: Maths Sup
GitHub: Ti64CLi

Re: ndless memory map

Unread postby parisse » 03 Jul 2020, 17:26

Indeed, that's an interesting idea, but I must find a way to save all unsaved data before leaving, because I can't interact with the user.
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 4.1%
 
Posts: 2071
Joined: 13 Dec 2013, 16:35
Gender: Not specified

Re: ndless memory map

Unread postby Ti64CLi++ » 03 Jul 2020, 17:53

You mean save the context, like calculs history, or opened script ?
I'm sure it won't be too hard for you, you could always save that in a file inside the KhiCAS folder ;)
Image
User avatar
Ti64CLi++Modo
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Level up: 91.3%
 
Posts: 3262
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender: Male
Calculator(s):
Class: Maths Sup
GitHub: Ti64CLi

Online

Re: ndless memory map

Unread postby nspiredev500 » 03 Jul 2020, 18:40

The lcd controller has a power down and power up sequence. It's described in the reference manual. My implementation is:
Code: Select all
static volatile uint32_t *backlight = (volatile uint32_t*) 0x900F0020;
static volatile uint32_t *lcd_controller = (volatile uint32_t*) 0xC0000000;
void lcd_power_down()
{
   old_backlight_value = *backlight;
   *backlight = 0x100;
   lcd_controller[6] &= ~(0b1 << 11);
   msleep(20);
   lcd_controller[6] &= ~ 0b1;
}
void lcd_power_up()
{
   lcd_controller[6] |= 0b1;
   msleep(20);
   lcd_controller[6]|= 0b1 << 11;
   *remapped_backlight = old_backlight_value;
}

It seems to work. When I don't disable the backlight the screen goes completely black, and after powering up again everything is there.
The msleep is there because the manual says to continue "when the signals have stabilized", and I don't know how long it takes.
Here is the reference manual, you can read it yourself if you want.
https://developer.arm.com/documentation/ddi0293/c
User avatar
nspiredev500
Niveau 5: MO (Membre Overclocké)
Niveau 5: MO (Membre Overclocké)
Level up: 0%
 
Posts: 10
Joined: 03 Jul 2020, 12:22
Gender: Not specified
Calculator(s):
GitHub: nspiredev500

Re: ndless memory map

Unread postby parisse » 03 Jul 2020, 19:13

I still guess that the LCD is not fully off after adapting your code. I inserted an auto-shutdown, after 2 hours, this will display a Press ON to cancel auto-shutdown message for a few seconds, if ON is not pressed, it will save the current session and exit.
I'm however afraid the exit(1) call is not full clean (memory ressources not released) because after running a few times khicas, it will not run until I reset.
Current code is now
Code: Select all
void (*shutdown)()=0;
...
      // somewhat OFF by setting LCD to 0
      unsigned NSPIRE_CONTRAST_ADDR=0x900f0020;
      unsigned oldval=*(volatile unsigned *)NSPIRE_CONTRAST_ADDR;
      *(volatile unsigned *)NSPIRE_CONTRAST_ADDR=0x100;
      static volatile uint32_t *lcd_controller = (volatile uint32_t*) 0xC0000000;
      lcd_controller[6] &= ~(0b1 << 11);
      msleep(20);
      lcd_controller[6] &= ~ 0b1;
      unsigned offtime=* (volatile unsigned *) NSPIRE_RTC_ADDR;
      for (int n=0;!on_key_pressed();++n){
   msleep(100);
   idle();
   if (shutdown
       // && n&0xff==0
       ){
     unsigned curtime=* (volatile unsigned *) NSPIRE_RTC_ADDR;
     if (curtime-offtime>7200){
       // after 2 hours, leave KhiCAS
       // that way the OS will really shutdown the calc
       lcd_controller[6] |= 0b1;
       msleep(20);
       lcd_controller[6]|= 0b1 << 11;
       *(volatile unsigned *)NSPIRE_CONTRAST_ADDR=oldval;
       statuslinemsg("Press ON to disable KhiCAS auto shutdown");
       //os_fill_rect(0,0,320,222,0xffff);
       sync_screen();
       int m=0,mmax=150;
       for (;m<mmax;++m){
         if (on_key_pressed())
      break;
         msleep(100);
         idle();
       }
       if (m==mmax)
         shutdown();
       else
         break;
     }
   }
      }
      lcd_controller[6] |= 0b1;
      msleep(20);
      lcd_controller[6]|= 0b1 << 11;
      *(volatile unsigned *)NSPIRE_CONTRAST_ADDR=oldval;
...
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 4.1%
 
Posts: 2071
Joined: 13 Dec 2013, 16:35
Gender: Not specified

Online

Re: ndless memory map

Unread postby nspiredev500 » 03 Jul 2020, 20:09

I cannot find your full C source code on the forum. Do you use malloc somewhere, or a C library function that wants you to free the memory? Otherwise exit should be clean.
User avatar
nspiredev500
Niveau 5: MO (Membre Overclocké)
Niveau 5: MO (Membre Overclocké)
Level up: 0%
 
Posts: 10
Joined: 03 Jul 2020, 12:22
Gender: Not specified
Calculator(s):
GitHub: nspiredev500

Re: ndless memory map

Unread postby parisse » 03 Jul 2020, 21:14

new is called in many parts of the code to create objects, strings, vectors etc. The problem is that the off/on code is called from a getkey call and I have no way to give getkey a parameter describing all the objects that were created with new. I have no idea how the heap is allocated in a ndless application, I fear exit will not be able to free this memory.
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 4.1%
 
Posts: 2071
Joined: 13 Dec 2013, 16:35
Gender: Not specified

Online

Re: ndless memory map

Unread postby nspiredev500 » 04 Jul 2020, 13:06

Unfortunately, the C library assumes it's on a real OS that will just delete the address space, so it won't free the memory for you.
I don't know much about C++.
Maybe you could throw an exception up the call stack and free all local variables in a catch block in every function.
Maybe you could wrapp new so it puts every object in a list, and before the call to exit just free everything in the list.
But you would somehow have to remove the objects that were already freed.
I think you could go a little deeper and let the linker rename malloc and free, and make you own malloc and free that record every allocation.
Then you just call the real malloc and free. The list itself could even be resized and allocated with malloc, you just have to free the list itself at the end.
User avatar
nspiredev500
Niveau 5: MO (Membre Overclocké)
Niveau 5: MO (Membre Overclocké)
Level up: 0%
 
Posts: 10
Joined: 03 Jul 2020, 12:22
Gender: Not specified
Calculator(s):
GitHub: nspiredev500

PreviousNext

Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: No registered users and 1 guest

-
Search
-
Featured topics
L'OS 5.5 de la TI-83 Premium CE / 84 Plus CE supprime l'assembleur - la plupart des jeux et certains programme ne fonctionneront plus
Omega, le fork étendant les capacités de ta NumWorks, même en mode examen !
Découvre les nouvelles fonctionnalités en Python de l'OS 5.5 pour la 83PCE/84+C-T Python Edition
Comparaisons des meilleurs prix pour acheter sa calculatrice !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...

Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
417 utilisateurs:
>403 invités
>9 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)