uSD P2 FlexBASIC
Rsadeika Posts: 3,693
edited 2021-12-13 17:05 in BASIC (for Propeller)
I am trying to open a file, in a COG, and have something written there. But, in my program, nothing is happening. Not sure what I am missing.
' test2sd.bas OPTION EXPLICIT ' CONST HEAPSIZE = 8192 ' lots of elbow room mount ("/sd", _vfs_open_sdcardx(5,4,3,2)) ' mount the file system at /SD node dim s$ as string dim stack_dlog1(64) dim cpuID_4 as long cpuID_4 = cpu(dataLog(),@stack_dlog1(1)) do pausems 2000 loop end 'COGed datalog sub datalog open "/sd/dlog1.txt" for input as #8 print #8, "Datalog" print "Debug, in datalog" do print #8, "a";chr$(13) pausesec 1 ' Pause for five minutes. loop end sub '''''''''''''''
Only one COG at a time can use any set of pins, including the SD card pins. My recommendation would be to use the main COG for any file I/O, but if you really need to do file I/O in another COG (why??) then you'd have to do the mount in that COG as well.
What I was thinking about is testing the idea of, one COG would be collecting the data, and storing in a file, while another COG would be able to open the file, and do some sort of analysis of the data collected, if at all possible.
I am experimenting with the program below, and in a COG, the values that are being written are not what I am expecting.
Does this mean that when you mount in different COG, the uSD function works differently?
Don't mix this kind of operations between cogs. It can be a source of hard to find bugs.
Another question: can a channel number be 8? The FlexBasic help says this has to be 0 to 7, where 0 and 1 is reserved. Maybe this #8 is the source of the bug.
Edit: I found in the source code that max file# is 9, not 7
Now I know why. My main cog is doing SD "file manager" while another one wants to play .wav This is of course not possible with this architecture - now I need to write a "file access" cog driver with its own mailbox type API
Is there something like "unmount"?