Sampling(Input)/Generating(Output) by using Bus Master Transfer function is explained as follows.
Set the conditions of Sampling/Generating
after initialization and mode setting,.
The condition of Sampling/Generating contains 3 types: Start Condition
Setting which is the condition (Software Start, External Start) set to
start Input/Output by DioDmSetStartTrigger,
Clock Condition Setting which is the timing (Internal Clock, External
Clock and so on) set to perform Input/Output by DioDmSetClockTrigger,
and Stop Condition Setting which is the condition (Software Stop, Specification
Number Stop and so on ) set to stop Input/Output by DioDmSetStopTrigger.
And, for each setting there are additional condition setting function (for example: set the stop number for the Specification Number Stop and so on).
In the case that data is input/ouput at the same conditions, after the initialization, those Sampling/Generating condition settings are set for one time, thereafter conditions will not be set before input/ouput. In the case that data is transferred by different conditions for each time, the conditions should be modified before transferring.
The FIFO substance of the last transfer is reset by Reset function (DioDmFifoReset).
Sampling: input
Bus master transfer is, the memory address of transfer target is specified
in board, and as the transfer is started, data is transferred from
board to the memory address.
Therefore, before transferring, the buffer stored the input data must
be specified in the board (DioDmSetBuffer).
The specified buffer should be locked to make that it can not be moved
to the other physical address. The locked buffer will be unlocked
after the transfer has completed. Because it is dangerous that data
is transferred to unlocked buffer, whenever transfer is performed,
before that, buffer must be specified.
In the case that buffer is heaped or stacked, the buffer should not
be opened until transferring to the buffer is complete. After the
transfer has completed and the buffer has been opened, the buffer
will be used by the other process.
If data is transferred
to the buffer used by the other process, exception error will be occurred
in program.
To make sure about the safety of program, the buffer used for bus master
transfer should be set to be global.
The motion of transferring provides 1 Time Transfer which is all of the
data in the buffer has been transferred completely and Infinite Transfer
which is data is transferred repeatedly to the same buffer for infinite
times.
Generating: output
Bus master transfer is, the memory address of transfer target is specified
in hardware, and before Generating, data is transferred from the memory
address to the FIFO in board.
In the case of output, the buffer stored the output data must be specified
in hardware (DioDmSetBuffer).
The specified buffer should be locked to make it can not be moved to
the other physical address. The locked buffer will be unlocked after
the transfer has completed. whenever transfer is performed, before
that, buffer must be specified.
In the case that buffer is heaped or stacked, the buffer should not
be opened until transferring to the buffer is complete. After the
transfer has completed and the buffer has been opened, the buffer
will be used by the other process. And the buffer will be write with
the other data except for the output data. At this time, if transfer
is performed, it is possible that unexpected data will be output.
To make sure about the safety of program, the buffer used for bus master
transfer should be set to be global.
The motion of transferring provides 1 Time Transfer which is all of
the data in the buffer has been transferred completely and Infinite
Transfer which is transferred the data repeatedly from the same buffer
for infinite times.
In the case that the same data is transferred repeatedly for the specified
times, the buffer size of the data for specified times should be prepared,
and data in the buffer is transferred for 1 time.
After the conditions of
Sampling/Generating is set and buffer is specified, start the motion by
DioDmTransferStart.
As the motion is started, if the start condition is satisfied then Sampling/Generating
will be started, if the stop condition is satisfied then Sampling/Generating
will be stopped. In the case of Software Start, Sampling/Generating is
started with the timing when the function DioDmTransferStart
is called.
Input data is saved in the FIFO of board, and the data is transferred to
memory of application by the timing when bus is free.
Output data is sent to FIFO of board directly, and as the Clock Condition
is satisfied, the data is output to external.
After it is satisfied the
Stop Condition which defines with DioDmSetStopTrigger
function, Sampling/Generating will be stopped.
Sampling/Generating will be stopped after the number of transferring is
reach for Length which defines with DioDmSetBuffer
function as well.
And also, Sampling/Generating will be stopped when you call DioDmTransferStop function or it occurs the unexpected error during Bus Master Transfer.
There are 3 kinds of method to catch the stop motion from application as below:
- To confirm stop
by message (DioDmSetStopEvent)
- To confirm stop by callback (DioDmSetStopCallBackProc)
- To monitor the status (DioDmGetStatus)
The basic notification method is message or callback.
To monitor the status, DIODM_STATUS_BMSTOP
and DIODM_STATUS_PIOSTOP should be
monitored.
However, this method does I/O to the device to check the status, so the
transfer rate of the bus master may decrease.
Before starting sampling data processing or preparing for the next transfer,
be sure to use one of these methods to confirm
that transfer has been completed before starting the next process.
(The same applies when using DioDmTransferStop.)
During the transfer motion, the transferred number can be confirmed (DioDmSetCountEvent).
After transfer, (DioDmGetStatus)
is used to confirm whether the bus master transfer has completed normally.
And, accessing the device during bus master transfer will hinder bus master
transfer.
Therefore, if you call (DioDmGetStatus)
frequently or notify by (DioDmSetCountEvent),
the transfer rate may be adversely affected.
If the bus master buffer
is set using (DioDmSetBuffer)
in the thread, when the thread ends, the memory lock is released and the
bus master transfer is forcibly stopped. Therefore, do not terminate the
thread until the bus master transfer is completed.
When using the bus master transfer function, normal digital input/output
functions cannot be used.