Memory allocation questions
Lets start with I'm probably one of the worst programmers.... :-)
I have not programmed much in spin yet.
I am trying to add 3 programs together here.
None of them shall ever run at the same time.
I have written a small program that reads a rotary switch. This decides which program to run.
The 3 programs are a vga test output,a video output and a wav player.
My problem is that theese programs allocate memory (vga buffer uses almost all memory)
Is there any way in the compiler to define that a subprogram shall not allocate memory until it is called?
Haavard
I have not programmed much in spin yet.
I am trying to add 3 programs together here.
None of them shall ever run at the same time.
I have written a small program that reads a rotary switch. This decides which program to run.
The 3 programs are a vga test output,a video output and a wav player.
My problem is that theese programs allocate memory (vga buffer uses almost all memory)
Is there any way in the compiler to define that a subprogram shall not allocate memory until it is called?
Haavard
Comments
An idea would be to compile your program with BST, it will remove any unused methods from the objects you have in your program. This could save a significant amount of memory, depending on how much is actually being used.
Another idea might be XMM, where the program is actually on an external memory device like an SD card. And code is brought in as it is needed to execute. But I don't think this works with SPIN programs, as far as I understand it, both LMM and XMM are written or (at least) compiled in a very unique way to allow the code to execute properly.
Yet another idea, would be to add a second propeller.
The master program loads when you turn on the Propeller. The master then decides (based on the switch) which of the programs on the SD card to launch.
You ought to search for KyeDos on PropDos.
I personally have modified KyeDos to launch different programs in a touchscreen project I have. I was running out of program space but by having different programs launched based on a menu selection has allowed a very large total program to run by only using a part of the program at a time.
Duane
I have made my selector here but I am having trouble using the boot command from the program.
How do I use it?
Have you used Kye's SD card driver to write and read from a SD card? See the Application Notes for help.
Most of these programs come with some sort of demo that shows how it is used.
Duane
and instead of shellLine(), you could write a new subroutine that reads your rotary switch.
If the switch is the same as last time, do nothing.
If the switch is different to last time, run one of three programs based on the switch position.
So you would need a new global variable old_switch_position
Have you got code working to read the rotary switch via some propeller pins?
I still can't figure out how to boot a file from the sd card :-)
"
repeat
if ina[26] == 0
PrintString(string("Select Video"))
if ina[25] == 0
PrintString(string("Select VGA"))
if ina[27] == 0
PrintString(string("Select Audio"))
Where Myprog is a file called Myprog.exe which you have previously compiled and saved as a .binary file and then renamed to .exe and copied to the sd card.
You will need to detect the change in the switch state somehow otherwise it will keep restarting that program over and over.
if ina[26] == 0
PrintString(string("Select Video"))
result := \shellCommands(string("video"))
if ina[25] == 0
PrintString(string("Select VGA"))
result := \shellCommands(string("vga"))
if ina[27] == 0
PrintString(string("Select Audio"))
result := \shellCommands(string("audio"))
This works a bit. It can't read the switch correctly but I guess thats some hw fault, wrong io's or something. At least it detects difference and boots the different programs if I change input ports.
All the different programs I have goes into an endless loop. To select a new program I would have to turn the switch to off and select a new program.
I can possibly add a second pause to be able to reach to set the switch into the correct position or I need to run a cog to only check the switch and someway give keydos a switch value if possible.
This cpu is really a new way to think !
With the switch, are you sending 3V/0V to the pin, or are you sending 0V and open circuit? If the latter, add a pullup resistor (10k).
I would like a read only mode if it is possible.:-)
A lot less elegent, but .... If the rotary switch was used to select one of a number of EEPROM chips, via their A0-2 lines, that had the individual programs in each. The one that is at A0 would be the active one. The chips could be set, by links, to be write protected too. This requires the system to be rebooted on switch change though.
I am doing a test with the sd card write protect switch set now.
That switch to be used need suport in Yours Hardware and software.
It not have any physical function on SD itself.
That's right, it is just a plastic tag that tells the socket switch ...
But I do not need to be able to writre to the SD card ever ! So if there is a way to force it in software.
I guess the problem is when it is writing the command.txt file as it grows but there is nothing in it.
PRI ProgramCommand(StringPointer) | buffer,i ' look for .exe files (ie .binary files renamed to .exe) and if found, run the program
' fat.listEntries("W")
str.copy(stringpointer,@lineoftext2) ' copy the command to lineoftext2
str.stringConcatenate(@lineoftext2, string(".exe")) ' add extension for executable files to lineoftext2
repeat while(buffer := fat.listEntries("N"))
str.copy(buffer,@LineOfText1) ' copy filename to LineOfText1
str.trimstring(@lineoftext1) ' remove any leading/trailing spaces
ifnot str.stringcompareci(@lineoftext1,@lineoftext2)' does it match? (ignore case)
str.copy(buffer,@lineoftext3) ' can't use "buffer" as it gets overwritten
'printstringcr(string("Saving command line in COMMAND.TXT and running program"))
'printstring(string("Command line: "))
'printstring(@commandline)
' above commented out as 1) about to blank the screen, 2) debugged and 3) if running xmodem don't want any further data on the serial lines
' possibly could put this output back if use the vga screen only.
' result := \fat.newFile(string("COMMAND.TXT")) ' All aborts traps must have "variable := \function" setup.
'if(fat.partitionError == fat#Entry_Already_Exist) ' file already exists
' result := \fat.deleteEntry(string("COMMAND.TXT")) ' delete the old file
' result := \fat.newfile(string("COMMAND.TXT")) ' recreate the file
'result := \fat.openFile(string("COMMAND.TXT"), "W") ' create file and open file
'result := \fat.writestring(@commandline) ' store the command line as it was typed
'result := \fat.closefile ' close the file
result := \fat.bootpartition(@lineoftext3) ' reboot
It's a lot easy to read code if you use the code tags.
Yes, if you use propforth, you can define the kernel to include SD support, and you don't need to load a program until it is call, and you can unload or "forget" programs when finished.
A file of text can be loaded from SD and execute as a script, and "forgot" when finished. Any number of programs can be swapped in and out of memory as needed.
You would have to write the code for your selector switch in forth, but that should be easy if you already have it in spin.
VGA support exists in V3.4, but it will not officially be brought up to the current release till next month or so. But, the advantage is you can develop interactively in the mean time.
Nobody coded a WAV player in propforth to my knowledge, but if you know what the code is doing, it should be at least as easy as in spin.
This is problems other might have and can be solved easily.
To write protect the os change the write protect pin from -1 to some pin with a pullup resistor an d the Os won't write.
Remove the command.txt generation from program execution.
To get rid of the OS resetting when not connected to the computer change the serial receiver and transmitter pin to some pin where nothing happens.
Also set lcd and serial to false.
This will give You a stable os that can be controlled from Your own io's.