📄 spimgr.s51
字号:
CFI EndBlock cfiBlock3
// 167 }
END
// 168
// 169
// 170 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
// 171 /***************************************************************************************************
// 172 * @fn SPIMgr_ProcessZToolRxData
// 173 *
// 174 * @brief | SOP | CMD | Data Length | FSC |
// 175 * | 1 | 2 | 1 | 1 |
// 176 *
// 177 * Parses the data and determine either is SPI or just simply serial data
// 178 * then send the data to correct place (MT or APP)
// 179 *
// 180 * @param pBuffer - pointer to the buffer that contains the data
// 181 * length - length of the buffer
// 182 *
// 183 *
// 184 * @return None
// 185 ***************************************************************************************************/
// 186 void SPIMgr_ProcessZToolData ( uint8 port, uint8 event )
// 187 {
// 188 uint8 ch;
// 189
// 190 /* Verify events */
// 191 if (event == HAL_UART_TX_FULL)
// 192 {
// 193 // Do something when TX if full
// 194 return;
// 195 }
// 196
// 197 if (event & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
// 198 {
// 199 while (Hal_UART_RxBufLen(SPI_MGR_DEFAULT_PORT))
// 200 {
// 201 HalUARTRead (SPI_MGR_DEFAULT_PORT, &ch, 1);
// 202
// 203 switch (state)
// 204 {
// 205 case SOP_STATE:
// 206 if (ch == SOP_VALUE)
// 207 state = CMD_STATE1;
// 208 break;
// 209
// 210 case CMD_STATE1:
// 211 CMD_Token[0] = ch;
// 212 state = CMD_STATE2;
// 213 break;
// 214
// 215 case CMD_STATE2:
// 216 CMD_Token[1] = ch;
// 217 state = LEN_STATE;
// 218 break;
// 219
// 220 case LEN_STATE:
// 221 LEN_Token = ch;
// 222 if (ch == 0)
// 223 state = FCS_STATE;
// 224 else
// 225 state = DATA_STATE;
// 226
// 227 tempDataLen = 0;
// 228
// 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 ***************************************************************************************************/
//
// 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 + -