Odd behavior after opening and closing files
Posted: Tue Jun 22, 2010 7:30 pm
Maybe some of you could shed light on something odd... This will take some explanation, so please bear with me.
I have the following tasks (among others) :
ControlTask: highest priority (lowest PRIO value, lower than user main)
SensorTask: (prio less important than user main, more important than Controltask)
UserMain: medium (prio=50)
ProcessCmdInput (55)
ControlTask has three open files on the SD card.
SensorTask has another open file on the SD card.
ControlTask and SensorTask each log data to each file about once a second. On the hour, all the files are automatically closed, and new files are opened to limit the amount of data logged to any one file.
A PIT itimer ISR runs 100X/sec. At varying intervals, and when the ControlTask is enabled, the ISR posts a semaphore to trigger the Control task.
Each time the ControlTask runs, it queries two serial ports for command strings which are parsed into variables used to do some calcs, producing a command ouput sent to a third serial port. The various data streams are logged to SD card in the three SD card files.
The SensorTask is doing a similar job reading a 4th serial port, parsing the data, and logging to a 4th SD card file. The resulting data is used by the Controltask.
All these files (hundreds of them) created over a week or so (>500Mb) can be moved off the SD card by accessing them via the EFFS FTP server. However, with all the task activity, and the likelyhood of at least 4 open files we've found it best to disable the ControlTask and close all the files before attempting to drag them off the SD card. We do this by entering a PAUSE command over another serial port or telnet port that runs a command proccessor (the ProcessCmdTask) to accept some user input. When the PAUSE command is issued, the log files are closed and a flag is set in the PIT ISR preventing the posting of the semaphore triggering the control task. After the files are removed from SD, a RESUME command is given reopening a new (different) set of files & also clearing the flag to once again allow posting the semaphore to the ControlTask. All of this works. However, the ControlTask never receives the posted semaphores. You can see the OSsemCnt for the semaphore increase, but the ControlTask never gets it even though it has the highest task PRIO. All other tasks seem to run. Changing the prio of ControlTask lower or higher does not help. If the PAUSE command just stops the Semaphore to the ControlTask, (but avoids closing the files) things work as expected, so the issue is with either closing or re-opening the files.
One thought is that the SensorTask originally opens one file, while ControlTask opens 3 others. Can these files be closed and opened from other tasks (eg ProcessCmdTask ), or do they need to be opened and closed from that tasks that normally create and use them?
Any ideas? Thanks for reading this far!
I have the following tasks (among others) :
ControlTask: highest priority (lowest PRIO value, lower than user main)
SensorTask: (prio less important than user main, more important than Controltask)
UserMain: medium (prio=50)
ProcessCmdInput (55)
ControlTask has three open files on the SD card.
SensorTask has another open file on the SD card.
ControlTask and SensorTask each log data to each file about once a second. On the hour, all the files are automatically closed, and new files are opened to limit the amount of data logged to any one file.
A PIT itimer ISR runs 100X/sec. At varying intervals, and when the ControlTask is enabled, the ISR posts a semaphore to trigger the Control task.
Each time the ControlTask runs, it queries two serial ports for command strings which are parsed into variables used to do some calcs, producing a command ouput sent to a third serial port. The various data streams are logged to SD card in the three SD card files.
The SensorTask is doing a similar job reading a 4th serial port, parsing the data, and logging to a 4th SD card file. The resulting data is used by the Controltask.
All these files (hundreds of them) created over a week or so (>500Mb) can be moved off the SD card by accessing them via the EFFS FTP server. However, with all the task activity, and the likelyhood of at least 4 open files we've found it best to disable the ControlTask and close all the files before attempting to drag them off the SD card. We do this by entering a PAUSE command over another serial port or telnet port that runs a command proccessor (the ProcessCmdTask) to accept some user input. When the PAUSE command is issued, the log files are closed and a flag is set in the PIT ISR preventing the posting of the semaphore triggering the control task. After the files are removed from SD, a RESUME command is given reopening a new (different) set of files & also clearing the flag to once again allow posting the semaphore to the ControlTask. All of this works. However, the ControlTask never receives the posted semaphores. You can see the OSsemCnt for the semaphore increase, but the ControlTask never gets it even though it has the highest task PRIO. All other tasks seem to run. Changing the prio of ControlTask lower or higher does not help. If the PAUSE command just stops the Semaphore to the ControlTask, (but avoids closing the files) things work as expected, so the issue is with either closing or re-opening the files.
One thought is that the SensorTask originally opens one file, while ControlTask opens 3 others. Can these files be closed and opened from other tasks (eg ProcessCmdTask ), or do they need to be opened and closed from that tasks that normally create and use them?
Any ideas? Thanks for reading this far!