| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include "FreeRTOS.h"
- #include "board.h"
- #include "mailbox_message.h"
- #include "mailbox_update/mailbox_update_demo.h"
- #ifdef MAILBOX_UPDATE_SUPPORT
- static MailboxUpdateFrame *MailboxUpdateHandleMsg(mb_rxmsg_t *msg)
- {
- MailboxUpdateFrame *rx_frame;
- if (!msg)
- return NULL;
- if (msg->dl != sizeof(MailboxUpdateFrame)) {
- printf("%s, mailbox rev msg length err.\n", __func__);
- return NULL;
- }
- rx_frame = (MailboxUpdateFrame *)msg->data;
- if (!rx_frame) {
- printf("%s, mailbox update data abnormal.\n", __func__);
- return NULL;
- }
- if (rx_frame->FrameRspStatus == MUFRS_ACK_OK) {
- return rx_frame;
- } else if (rx_frame->FrameRspStatus == MUFRS_ACK_FSAME) {
- printf("checksum is the same as now, don't update.\n");
- return rx_frame;
- } else if (rx_frame->FrameRspStatus == MUFRS_ACK_FNOSPACE) {
- printf("%s, The file is too large, not enough space to save.\n", __func__);
- } else if (rx_frame->FrameRspStatus == MUFRS_ACK_FNOSUP) {
- printf("%s, This file does not support mailbox upgrade.\n", __func__);
- } else if (rx_frame->FrameRspStatus == MUFRS_ACK_FCHECKE) {
- printf("%s, file crc check fail, don't update.\n", __func__);
- } else if (rx_frame->FrameRspStatus == MUFRS_ACK_FBURNE) {
- printf("%s, file burn fail, don't update.\n", __func__);
- } else {
- printf("%s, unknown error.\n", __func__);
- }
- return NULL;
- }
- int MailboxUpdateSendFrame(mb_msg_type_t msg_type, MailboxUpdateFrame *frame)
- {
- int retry = 3;
- while (retry--) {
- if (!mailbox_msg_send(msg_type, (uint8_t *)frame, sizeof(MailboxUpdateFrame), pdMS_TO_TICKS(50))) {
- return 0;
- }
- printf("%s, mailbox send frame fail, retry %d.\n", __func__, 3 - retry);
- }
- return -1;
- }
- MailboxUpdateFrame * MailboxUpdateReceiveFrame(mb_msg_type_t type, mb_rxmsg_t *msg, uint32_t timeout)
- {
- memset(msg, 0, sizeof(mb_rxmsg_t));
- if (mailbox_msg_receive(type, msg, timeout) != pdTRUE) {
- printf("%s, mailbox rx timeout.\n", __func__);
- return NULL;
- }
- return MailboxUpdateHandleMsg(msg);
- }
- #endif /* MAILBOX_UPDATE_SUPPORT */
|