Interface usage of GPIF state machine

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
haxu_299926
Level 3
Level 3
10 replies posted 5 replies posted 5 questions asked

I want to know how to use the api of CyU3PGpifSMSwitch.I found when I use the api ,the state machine will become strange.When I use this interface and then use the state acquisition interface to get the state immediately, it is not the state I want yo jump.

pastedImage_1.png

for example,I want to jump to the state10(19),and the let the statemachine go to state17.

CyU3PGpifSMSwitch(257,10,10,0,2);

and use the CyU3PGpifControlSWInput(Cytrue);CyU3PGpifControlSWInput(Cyfalse);

but when I printf the state,it isn't go to the state17

Is there any problem with the use of the interface? Can I use it like this. When I jump, the sensor is in capture statement.

0 Likes
11 Replies
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

Please confirm that you want to move to state 10 from an invalid state.

Also, please let me know what is your application. That is why do you want the state machine to switch to state 10?

Also, please let me know which firmware you are using? Is it same as that of AN75779?

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

I tested the state switch from an invalid state to the state PARTIAL_BUF_IN_SCK0 in AN75779 firmware assuming that you are trying to do the same thing. The API CyU3PGpifSMSwitch was used inside CyFxUvcApplnStart() function in AN75779 firmware. I found that the state transition was successful and the state machine switched to the state PARTIAL_BUF_IN_SCK0 perfectly.

Please note that even if you try to call the API CyU3PGpifGetSMState() immediately after the API CyU3PGpifSMSwitch(), you may not be able to get the expected state. This is because the API CyU3PGpifGetSMState() will read the bits 31:24 from the register GPIF_WAVEFORM_CTRL_STAT which indicates the current state. These bits are changed always when the state machine undergoes a transition from one state to another. As, the state machine runs continuously and might have switched to another state when the API is called, there are chances that you get some states ahead of the desired state when you try to read the state using the API CyU3PGpifGetSMState().

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Hello ayakrishna,

        I test this on the FX3,and the state machine is modified base on the  AN75779.I want to know how do you know the state transition was successful and the state machine switched to the state PARTIAL_BUF_IN_SCK0 perfectly?

0 Likes
lock attach
Attachments are accessible only for community members.

Hello,

I tested with the default state machine that comes along with AN75779 project. I have attached the modified AN75779 project which I used for testing along with this response. The changes made to the firmware are listed below:

1. Inside CyFxUvcApplnStart(), the API CyU3PGpifSMSwitch()  to switch to PARTIAL_BUF_IN_SCK0 was used. If the API returned success, then a global variable switch_now was set to True.

2. When the state machine switches to PARTIAL_BUF_IN_SCK0, GPIF callback function CyFxGpifCB(0) will be triggered. Inside this, for the case PARTIAL_BUF_IN_SCK0, the following was added.

            if(switch_now)

            {

            CyU3PGpifGetSMState(&SMState);

            now = CyTrue;

            switch_now = CyFalse;

            }

Please not that now is another global variable.

3. Inside the infinite for loop, in UVCAppThread_Entry(), just before Getting the events, the following ,modifications were made:

    if (now)

    {

    CyU3PDebugPrint (4, "\n\rAplnStrt:SMState = 0x%x",SMState);

    now = CyFalse;

    }

By doing the modifications mentioned above, whenever the host application was started for streaming the video, the API CyU3PGpifSMSwitch() will be used to switch to PARTIAL_BUF_IN_SCK0. If the API returned success, then switch_now will be set and this switch_now will be checked inside the case for PARTIAL_BUF_IN_SCK0 in GPIF callback function. If the variable switch_now is set, then we can understand that the state machine changed to PARTIAL_BUF_IN_SCK0 because the API CyU3PGpifSMSwitch() was called. Then, the API CyU3PGpifGetSMState() is used to get the state. Note that here, you will get the state PARTIAL_BUF_IN_SCK0 itself while using the API CyU3PGpifGetSMState(). This is because once the state machine reaches this state, the transition will happen only when the following statements are used.

CyU3PGpifControlSWInput (CyTrue);

CyU3PGpifControlSWInput (CyFalse);

The project was built and Tera Term was used for getting the debug logs. I found that the state machine reached state 14 which is PARTIAL_BUF_IN_SCK0. The snapshot of TeraTerm logs is shown below:

pastedImage_2.png

You can try the same at your end using the project attached. Please let me know if you have any queries on this.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Hello,

Thank you for your reply

I have another question: if the sensor is in the capture mode, will this state machine jump lead to confusion of sensor acquisition and state machine cooperation? Do I need to stop capture and then switch state machine

0 Likes

Hello,

Please answer my following questions:

1. What is the need for a state switch when the device is capturing data from the sensor?

2. Starting state and Destination state of the state switch?

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Hello,

I want to make some judgment when receiving the last packet. If there is data loss, I need to send some independent short packets.So I want to jump to the state machine,the state17 can get a buffer,and I can use it send the short packets

0 Likes

Hello,

       The code you have provided do the switch in the start,when the sensor is capturing ,the state must will go to the  PARTIAL_BUF_IN_SCK0,I think it can't prove that switch successfully

0 Likes

Hello,

Please find my comments below:

1. Yes, the project that I shared in response 4 was to switch to state machine before starting the video streaming. We have not tested switching the state machine while streaming the video data because this can break the video stream and is not desired usually.

2. Please let me know how are you planning to understand that there was a data loss while streaming.

3. Also, I see that the transition equation for state 17 is LOGIC ONE which means that the state machine will switch to the next state upon reception of the next clock edge. Therefore, you may not get enough time to get a buffer and commit a short packet to host. Instead you can try implementing the same mechanism in the GPIF II callback. But when you try to do this, the FW_TRIG will be delayed and at times can cause the video stream to break.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
haxu_299926
Level 3
Level 3
10 replies posted 5 replies posted 5 questions asked

I want to judge whether there are some exceptions at the end of the packet(the state16). When there are exceptions, I hope to get 0-length buffer multiple times, and then send multiple 4-byte packets. Can I do this by use function CyU3PGpifSMSwitch .

like this :

send leader state18->send image data packet........->send four bytes packet->send four bytes packet->send trailer packet

pastedImage_0.png

0 Likes

Hello,

It is not possible to implement a SMSwitch while streaming. You need to disable the GPIF using the API CyU3PGpifDisable(); and then try switching using the API for switch. But again, this cannot be implemented in the callback functions. So, what you can do is:

1. Set a global variable when you want to switch the state machine.

2. Immediately disable the GPIF using the API CyU3PGpifDisable();

3. Check whether the global variable in step 1 is set in the infinite for loop.

4. If the variable is set, then use the API CyU3PGpifSMSwitch() to switch to the desired state.

But there are chances that this can cause loss of incoming data.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes