/************************************************************************************************** * @fn sbResp * * @brief Make the SB response. * * input parameters * * @param sbCmd - the command to respond to * @param rsp - The byte code response to send. * @param payload_len - The data length of the response. * * output parameters * * None. * * @return None. */ static void sbResp(uint8 sbCmd, uint8 rsp, uint32 payload_len) { uint8 fcs = 0; uint8 headerBuf[10]; uint8 * pBuf = headerBuf; uint32 reported_len; // Include the payload len + one byte for rsp uint32 header_len; uint32 i; reported_len = payload_len + 1; *pBuf++ = SB_SOF; if (reported_len < 0xFF) { *pBuf++ = (uint8)(reported_len & 0xFF); } else { *pBuf++ = 0xFF; } *pBuf++ = SB_RPC_SYS_BOOT; // The MSB of the command field is set, to mark that this is a reply *pBuf++ = sbCmd | 0x80; if (reported_len >= 0xFF) { UINT32_TO_BUF_LITTLE_ENDIAN(pBuf, reported_len); } *pBuf++ = rsp; header_len = pBuf - headerBuf; // Caluclate the fcs for (i = 1; i < header_len; i++) // The SOF char is not part of the checksum { fcs ^= headerBuf[i]; } for (i = 0; i < payload_len; i++) { fcs ^= sbBuf[i]; } while (SB_TX(headerBuf, header_len) == 0); if (payload_len > 0) { while (SB_TX(sbBuf, payload_len) == 0); } while (SB_TX(&fcs, 1) == 0); }
/************************************************************************************************** * @fn sbResp * * @brief Make the SB response. * * input parameters * * @param rsp - The byte code response to send. * @param len - The data length of the response. * * output parameters * * None. * * @return None. ************************************************************************************************** */ static void sbResp(uint8 rsp, uint8 len) { int8 idx; sbBuf[SB_CMD2_STATE] |= 0x80; sbBuf[SB_DATA_STATE] = rsp; sbBuf[SB_LEN_STATE] = len; rsp = len ^ SB_RPC_SYS_BOOT; len += SB_FCS_STATE-1; for (idx = SB_CMD2_STATE; idx < len; idx++) { rsp ^= sbBuf[idx]; } sbBuf[idx++] = rsp; SB_TX(sbBuf, idx); }