⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spimgr.lst

📁 cc2430应用实例
💻 LST
📖 第 1 页 / 共 3 页
字号:
    229                    /* Allocate memory for the data */
    230                    SPI_Msg = (mtOSALSerialData_t *)osal_msg_allocate( sizeof ( mtOSALSerialData_t ) + 2+1+LEN_Token );
    231          
    232                    if (SPI_Msg)
    233                    {
    234                      /* Fill up what we can */
    235                      SPI_Msg->hdr.event = CMD_SERIAL_MSG;
    236                      SPI_Msg->msg = (uint8*)(SPI_Msg+1);
    237                      SPI_Msg->msg[0] = CMD_Token[0];
    238                      SPI_Msg->msg[1] = CMD_Token[1];
    239                      SPI_Msg->msg[2] = LEN_Token;
    240                    }
    241                    else
    242                    {
    243                      state = SOP_STATE;
    244                      return;
    245                    }
    246          
    247                    break;
    248          
    249                  case DATA_STATE:
    250                      SPI_Msg->msg[3 + tempDataLen++] = ch;
    251                      if ( tempDataLen == LEN_Token )
    252                        state = FCS_STATE;
    253                    break;
    254          
    255                  case FCS_STATE:
    256          
    257                    FSC_Token = ch;
    258          
    259                    /* Make sure it's correct */
    260                    if ((SPIMgr_CalcFCS ((uint8*)&SPI_Msg->msg[0], 2 + 1 + LEN_Token) == FSC_Token))
    261                    {
    262                      osal_msg_send( MT_TaskID, (byte *)SPI_Msg );
    263                    }
    264                    else
    265                    {
    266                      /* deallocate the msg */
    267                      osal_msg_deallocate ( (uint8 *)SPI_Msg);
    268                    }
    269          
    270                    /* Reset the state, send or discard the buffers at this point */
    271                    state = SOP_STATE;
    272          
    273                    break;
    274          
    275                  default:
    276                   break;
    277                }
    278          
    279          
    280              }
    281            }
    282          }
    283          #endif //ZTOOL
    284          
    285          #if defined (ZAPP_P1) || defined (ZAPP_P2)
    286          /***************************************************************************************************
    287           * @fn      SPIMgr_ProcessZAppRxData
    288           *
    289           * @brief   | SOP | CMD  |   Data Length   | FSC  |
    290           *          |  1  |  2   |       1         |  1   |
    291           *
    292           *          Parses the data and determine either is SPI or just simply serial data
    293           *          then send the data to correct place (MT or APP)
    294           *
    295           * @param   pBuffer  - pointer to the buffer that contains the data
    296           *          length   - length of the buffer
    297           *
    298           *
    299           * @return  None
    300           ***************************************************************************************************/
    301          void SPIMgr_ProcessZAppData ( uint8 port, uint8 event )
    302          {
    303          
    304            osal_event_hdr_t  *msg_ptr;
    305            uint16 length = 0;
    306            uint16 rxBufLen  = Hal_UART_RxBufLen(SPI_MGR_DEFAULT_PORT);
    307          
    308            /*
    309               If maxZAppBufferLength is 0 or larger than current length
    310               the entire length of the current buffer is returned.
    311            */
    312            if ((SPIMgr_MaxZAppBufLen != 0) && (SPIMgr_MaxZAppBufLen <= rxBufLen))
    313            {
    314              length = SPIMgr_MaxZAppBufLen;
    315            }
    316            else
    317            {
    318              length = rxBufLen;
    319            }
    320          
    321            /* Verify events */
    322            if (event == HAL_UART_TX_FULL)
    323            {
    324              // Do something when TX if full
    325              return;
    326            }
    327          
    328            if (event & ( HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
    329            {
    330              if ( App_TaskID )
    331              {
    332                /*
    333                   If Application is ready to receive and there is something
    334                   in the Rx buffer then send it up
    335                */
    336                if ((SPIMgr_ZAppRxStatus == SPI_MGR_ZAPP_RX_READY ) && (length != 0))
    337                {
    338                  /* Disable App flow control until it processes the current data */
    339                   SPIMgr_AppFlowControl ( SPI_MGR_ZAPP_RX_NOT_READY );
    340          
    341                  /* 2 more bytes are added, 1 for CMD type, other for length */
    342                  msg_ptr = (osal_event_hdr_t *)osal_msg_allocate( length + sizeof(osal_event_hdr_t) );
    343                  if ( msg_ptr )
    344                  {
    345                    msg_ptr->event = SPI_INCOMING_ZAPP_DATA;
    346                    msg_ptr->status = length;
    347          
    348                    /* Read the data of Rx buffer */
    349                    HalUARTRead( SPI_MGR_DEFAULT_PORT, (uint8 *)(msg_ptr + 1), length );
    350          
    351                    /* Send the raw data to application...or where ever */
    352                    osal_msg_send( App_TaskID, (uint8 *)msg_ptr );
    353                  }
    354                }
    355              }
    356            }
    357          }
    358          
    359          /***************************************************************************************************
    360           * @fn      SPIMgr_ZAppBufferLengthRegister
    361           *
    362           * @brief
    363           *
    364           * @param   maxLen - Max Length that the application wants at a time
    365           *
    366           * @return  None
    367           *
    368           ***************************************************************************************************/
    369          void SPIMgr_ZAppBufferLengthRegister ( uint16 maxLen )
    370          {
    371            /* If the maxLen is larger than the RX buff, something is not right */
    372            if (maxLen <= SPI_MGR_DEFAULT_MAX_RX_BUFF)
    373              SPIMgr_MaxZAppBufLen = maxLen;
    374            else
    375              SPIMgr_MaxZAppBufLen = 1; /* default is 1 byte */
    376          }
    377          
    378          /***************************************************************************************************
    379           * @fn      SPIMgr_AppFlowControl
    380           *
    381           * @brief
    382           *
    383           * @param   status - ready to send or not
    384           *
    385           * @return  None
    386           *
    387           ***************************************************************************************************/
    388          void SPIMgr_AppFlowControl ( bool status )
    389          {
    390          
    391            /* Make sure only update if needed */
    392            if (status != SPIMgr_ZAppRxStatus )
    393            {
    394              SPIMgr_ZAppRxStatus = status;
    395            }
    396          
    397            /* App is ready to read again, ProcessZAppData have to be triggered too */
    398            if (status == SPI_MGR_ZAPP_RX_READY)
    399            {
    400              SPIMgr_ProcessZAppData ( SPI_MGR_DEFAULT_PORT, HAL_UART_RX_TIMEOUT );
    401            }
    402          
    403          }
    404          
    405          #endif //ZAPP
    406          
    407          /***************************************************************************************************
    408          ***************************************************************************************************/

   Maximum stack usage in bytes:

     Function              ISTACK PSTACK XSTACK
     --------              ------ ------ ------
     SPIMgr_CalcFCS            0      0      9
     SPIMgr_Init               2      0      0
     SPIMgr_RegisterTaskID     2      0      0


   Segment part sizes:

     Function/Label        Bytes
     --------------        -----
     App_TaskID               1
     SPIMgr_Init              5
     ?Subroutine0            11
     SPIMgr_RegisterTaskID    7
     SPIMgr_CalcFCS          37

 
 60 bytes in segment BANKED_CODE
  1 byte  in segment XDATA_Z
 
 60 bytes of CODE  memory
  1 byte  of XDATA memory

Errors: none
Warnings: none

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -