π
<-
Chat plein-écran
[^]

ndless memory map

C, C++, ASM...

Re: ndless memory map

Message non lude Ti64CLi++ » 03 Juil 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
Avatar de l’utilisateur
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 32.3%
 
Messages: 3441
Images: 75
Inscription: 04 Juil 2014, 14:40
Localisation: Clermont-Ferrand 63
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: ENS Rennes
GitHub: Ti64CLi

Re: ndless memory map

Message non lude parisse » 03 Juil 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: Tout sélectionner
    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).
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude Ti64CLi++ » 03 Juil 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
Avatar de l’utilisateur
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 32.3%
 
Messages: 3441
Images: 75
Inscription: 04 Juil 2014, 14:40
Localisation: Clermont-Ferrand 63
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: ENS Rennes
GitHub: Ti64CLi

Re: ndless memory map

Message non lude parisse » 03 Juil 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.
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude Ti64CLi++ » 03 Juil 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
Avatar de l’utilisateur
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 32.3%
 
Messages: 3441
Images: 75
Inscription: 04 Juil 2014, 14:40
Localisation: Clermont-Ferrand 63
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: ENS Rennes
GitHub: Ti64CLi

Re: ndless memory map

Message non lude nspiredev500 » 03 Juil 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: Tout sélectionner
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
Avatar de l’utilisateur
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Prochain niv.: 16%
 
Messages: 17
Inscription: 03 Juil 2020, 12:22
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile
GitHub: nspiredev500

Re: ndless memory map

Message non lude parisse » 03 Juil 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: Tout sélectionner
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;
...
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude nspiredev500 » 03 Juil 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.
Avatar de l’utilisateur
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Prochain niv.: 16%
 
Messages: 17
Inscription: 03 Juil 2020, 12:22
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile
GitHub: nspiredev500

Re: ndless memory map

Message non lude parisse » 03 Juil 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.
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude nspiredev500 » 04 Juil 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.
Avatar de l’utilisateur
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Prochain niv.: 16%
 
Messages: 17
Inscription: 03 Juil 2020, 12:22
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile
GitHub: nspiredev500

PrécédenteSuivante

Retourner vers Native: Ndless, Linux, ...

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 5 invités

-
Rechercher
-
Social TI-Planet
-
Sujets à la une
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
Faire un don / Premium
Pour plus de concours, de lots, de tests, nous aider à payer le serveur et les domaines...
Faire un don
Découvrez les avantages d'un compte donateur !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partenaires et pub
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1246 utilisateurs:
>1207 invités
>34 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Autres sites intéressants
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)