Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 NXP Semiconductors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*!
     18 * \file  phLlcNfc_StateMachine.c
     19 * \brief Llc state machine implemenatation.
     20 *
     21 * Project: NFC-FRI-1.1
     22 *
     23 * $Date: Fri Apr 17 09:17:48 2009 $
     24 * $Author: ing02260 $
     25 * $Revision: 1.8 $
     26 * $Aliases: NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK926_R28_2,NFC_FRI1.1_WK926_R28_3,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
     27 *
     28 */
     29 
     30 /*************************** Includes *******************************/
     31 #include <phNfcTypes.h>
     32 #include <phNfcStatus.h>
     33 #include <phOsalNfc.h>
     34 #include <phNfcInterface.h>
     35 #include <phLlcNfc_DataTypes.h>
     36 #include <phLlcNfc_Frame.h>
     37 
     38 /*********************** End of includes ****************************/
     39 
     40 /***************************** Macros *******************************/
     41 
     42 /************************ End of macros *****************************/
     43 
     44 /*********************** Local functions ****************************/
     45 
     46 /******************** End of Local functions ************************/
     47 
     48 /********************** Global variables ****************************/
     49 
     50 /******************** End of Global Variables ***********************/
     51 
     52 NFCSTATUS
     53 phLlcNfc_H_ChangeState(
     54     phLlcNfc_Context_t  *psLlcCtxt,
     55     phLlcNfc_State_t    changeStateTo
     56 )
     57 {
     58     NFCSTATUS   result = PHNFCSTVAL(CID_NFC_LLC,
     59                                     NFCSTATUS_INVALID_STATE);
     60     if ((NULL != psLlcCtxt) &&
     61         (changeStateTo != phLlcNfc_Uninitialise_State))
     62     {
     63         switch(psLlcCtxt->state)
     64         {
     65             case phLlcNfc_Uninitialise_State:
     66             {
     67                 if (phLlcNfc_Initialising_State == changeStateTo)
     68                 {
     69                     result = NFCSTATUS_SUCCESS;
     70                     psLlcCtxt->state = changeStateTo;
     71                 }
     72                 break;
     73             }
     74             case phLlcNfc_Initialising_State:
     75             {
     76                 if (phLlcNfc_Initialised_State == changeStateTo)
     77                 {
     78                     result = NFCSTATUS_SUCCESS;
     79                     psLlcCtxt->state = changeStateTo;
     80                 }
     81                 break;
     82             }
     83             case phLlcNfc_Initialised_State:
     84             {
     85                 if (changeStateTo > phLlcNfc_Initialising_State)
     86                 {
     87                     result = NFCSTATUS_SUCCESS;
     88                     psLlcCtxt->state = changeStateTo;
     89                 }
     90                 break;
     91             }
     92             case phLlcNfc_ReceiveWait_State:
     93             {
     94                 if (changeStateTo >= phLlcNfc_Initialised_State)
     95                 {
     96                     result = NFCSTATUS_SUCCESS;
     97                     psLlcCtxt->state = changeStateTo;
     98                 }
     99                 break;
    100             }
    101             case phLlcNfc_Sending_State:
    102             {
    103                 if ((phLlcNfc_Initialised_State == changeStateTo) ||
    104                     (phLlcNfc_Sending_State == changeStateTo))
    105                 {
    106                     result = NFCSTATUS_SUCCESS;
    107                     psLlcCtxt->state = changeStateTo;
    108                 }
    109                 break;
    110             }
    111             case phLlcNfc_Receiving_State:
    112             {
    113                 if ((phLlcNfc_Initialised_State == changeStateTo) ||
    114                     (phLlcNfc_Sending_State == changeStateTo))
    115                 {
    116                     result = NFCSTATUS_SUCCESS;
    117                     psLlcCtxt->state = changeStateTo;
    118                 }
    119                 break;
    120             }
    121             case phLlcNfc_Resend_State:
    122             {
    123                 if (phLlcNfc_Initialised_State == changeStateTo)
    124                 {
    125                     result = NFCSTATUS_SUCCESS;
    126                     psLlcCtxt->state = changeStateTo;
    127                 }
    128                 if (phLlcNfc_Sending_State == changeStateTo)
    129                 {
    130                     result = NFCSTATUS_SUCCESS;
    131                     if (0 != psLlcCtxt->s_frameinfo.s_send_store.winsize_cnt)
    132                     {
    133                         psLlcCtxt->state = changeStateTo;
    134                     }
    135                 }
    136                 break;
    137             }
    138             default:
    139             {
    140                 /* Error scenario: There cant be any change in the state,
    141                     while LLC is in these states */
    142                 result = PHNFCSTVAL(CID_NFC_LLC,
    143                                     NFCSTATUS_INVALID_FORMAT);
    144                 break;
    145             }
    146         }
    147     }
    148     if ((NULL != psLlcCtxt) &&
    149         (phLlcNfc_Uninitialise_State == changeStateTo))
    150     {
    151         psLlcCtxt->state = changeStateTo;
    152     }
    153     return result;
    154 }
    155