/*============================================================================ * Name : BitBangSPI_Send_Message * ------------------------------------------------------------------------------ * Purpose : Send and Read one frame using BitBangSPI Interface * Input : n/a * Output : n/a * Notes : Called from Send_Message in QDebugTransport.c * ============================================================================*/ void BitBangSPI_Send_Message(void) { unsigned int i; uint8_t FrameInProgress; /* Send our message upstream */ for (i = 0; i <= TX_index; i++) { FrameInProgress = RxHandler(BitBangSPI_Send_Byte(TX_Buffer[i])); } /* Do we need to receive even more bytes? */ while (FrameInProgress) { FrameInProgress = RxHandler(BitBangSPI_Send_Byte(0)); } }
/*============================================================================ Name : SPI_Send_Message ------------------------------------------------------------------------------ Purpose : Send and Read one frame using SPI Interface Input : n/a Output : n/a Notes : Called from Send_Message in QDebugTransport.c ============================================================================*/ void SPI_Send_Message(void) { unsigned int i; volatile uint8_t FrameInProgress; // Send our message upstream for (i=0; i <= TX_index; i++) { FrameInProgress = RxHandler(SPI_Send_Byte(TX_Buffer[i])); } // Do we need to receive even more bytes? while (FrameInProgress) FrameInProgress = RxHandler(SPI_Send_Byte(0)); }
/*! \brief Send and Read one frame using SPI Interface.. * \note Called from Send_Message in QDebugTransport.c */ void SPI_Send_Message(void) { unsigned int i; uint8_t FrameInProgress; /* Disable interrupts. */ cpu_irq_disable(); /* Send our message upstream */ for (i = 0; i <= TX_index; i++) { FrameInProgress = RxHandler(SPI_Send_Byte(TX_Buffer[i])); } /* Do we need to receive even more bytes? */ while (FrameInProgress) { FrameInProgress = RxHandler(SPI_Send_Byte(0)); } /* Enable interrupts. */ cpu_irq_enable(); }
/*============================================================================ Name : TWI_MasterReadHandler ------------------------------------------------------------------------------ Purpose : Handles TWI Input : n/a Output : n/a Notes : Called from TWI Interrupt routine ============================================================================*/ void TWI_MasterReadHandler(void) { uint8_t FrameInProgress; uint8_t data = twiMaster.interface->MASTER.DATA; FrameInProgress = RxHandler(data); // If more bytes to read, issue ACK and start a byte read. if (FrameInProgress) { twiMaster.interface->MASTER.CTRLC = TWI_MASTER_CMD_RECVTRANS_gc; } else// If transaction finished, issue NACK and STOP condition. { twiMaster.interface->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc; TWI_MasterTransactionFinished(TWIM_RESULT_OK); } }
void vendor_data_ind(uint8_t PairingRef, profile_id_t ProfileId, uint16_t VendorId, uint8_t nsduLength, uint8_t *nsdu, uint8_t RxLinkQuality, uint8_t RxFlags) { /* Check if vendor id matches. Handle here only vendor data from same vendor */ uint16_t v_id = PGM_READ_WORD(&VendorIdentifier); if ((VendorId == v_id) && (RxFlags & RX_FLAG_WITH_SEC)) { switch (nsdu[0]) // vendor-specific command id { #ifdef _DEBUG_INTERFACE_ case 0x1B: { int i; for (i = 0; i < nsduLength;) { RxHandler(nsdu[i++]); } RX_index = 4; // Next GetChar() will get the command id /* Call QDebug_Process */ QDebug_ProcessCommands(); return; } break; #endif #ifdef TFA_BAT_MON case BATTERY_STATUS_REQ: { uint16_t voltage = tfa_get_batmon_voltage(); nsdu[0] = BATTERY_STATUS_RESP; nsdu[1] = (uint8_t)voltage; // LSB nsdu[2] = (uint8_t)(voltage >> 8); // MSB nsduLength = 3; } break; #endif case ALIVE_REQ: /* Alive request */ vendor_app_alive_req(); /* Send alive response */ nsdu[0] = ALIVE_RESP; nsduLength = 1; break; case FW_VERSION_REQ: { /* Send alive response */ nsdu[0] = FW_VERSION_RESP; nsdu[1] = FW_VERSION_MAJOR; // major version number nsdu[2] = FW_VERSION_MINOR; // minor version number nsdu[3] = FW_VERSION_REV; // revision version number nsduLength = 4; } break; case RX_ON_REQ: { uint32_t duration = 0; memcpy(&duration, &nsdu[1], 3); if (!nlme_rx_enable_request(duration)) { /* * RX enable could not been added to the queue. * Therefore do not send response message. */ return; } /* Send response */ nsdu[0] = RX_ON_RESP; nsduLength = 1; } break; #ifdef FLASH_SUPPORT case FW_DATA_REQ: { fw_data_frame_t *fw_frame; vendor_status_t status = VD_SUCCESS; fw_frame = (fw_data_frame_t *)nsdu; /* Verify data chunk size */ uint8_t fw_data_size = nsduLength - 5; // 5 = header len if (fw_data_size > 64) { status = VD_UNSUPPORTED_SIZE; } else { /* Fill temporary page buffer */ uint16_t start_addr = (fw_frame->frame_cnt - 1) % 4; flash_fill_page_buffer(start_addr * (SPM_PAGESIZE / 4), fw_data_size, &fw_frame->fw_data[0]); /* Write flash page */ if ((fw_frame->frame_cnt % 4) == 0) { uint32_t page_start_addr; page_start_addr = IMAGE_START_ADDR + ((uint32_t)SPM_PAGESIZE * ((fw_frame->frame_cnt / 4) - 1)); flash_program_page(page_start_addr); } else if (fw_frame->frame_cnt == fw_frame->total_num_frames) { uint32_t page_start_addr; page_start_addr = IMAGE_START_ADDR + ((uint32_t)SPM_PAGESIZE * (fw_frame->frame_cnt / 4)); flash_program_page(page_start_addr); } } /* Send response */ nsdu[0] = FW_DATA_RESP; nsdu[1] = status; nsduLength = 2; } break; #endif /* #ifdef FLASH_SUPPORT */ #ifdef FLASH_SUPPORT case FW_SWAP_REQ: flash_swap(IMAGE_START_ADDR, IMAGE_SIZE); /* Do not send response message */ return; #endif /* #ifdef FLASH_SUPPORT */ default: { /* Send response */ nsdu[0] = FW_DATA_RESP; nsdu[1] = VD_NOT_SUPPORTED_ATTRIBUTE; nsduLength = 2; } break; } /* Transmit response message */ nlde_data_request(PairingRef, PROFILE_ID_VENDOR_DATA, VendorId, nsduLength, nsdu, TXO_UNICAST | TXO_DST_ADDR_NET | TXO_ACK_REQ | TXO_SEC_REQ | TXO_MULTI_CH | TXO_CH_NOT_SPEC | TXO_VEND_SPEC); /* Keep compiler happy */ UNUSED(ProfileId); UNUSED(RxLinkQuality); UNUSED(RxFlags); } }