// Receive full frame int SerialIntrf::Rx(int DevAddr, uint8_t *pBuff, int BuffLen) { int count = 0; if (pBuff && StartRx(DevAddr)) { count = RxData(pBuff, BuffLen); StopRx(); } return count; }
/* ------------------------------------------------------------------------- */ Srv_TSession* Servant_Create(Reg_TRegistry* reg, int connection) { TServant *const servant = Mem_Alloc(sizeof(TServant)); if (!servant) { LOG0_ERROR("servant", "failed to create a new servant: out of memory"); return NULL; } memset(servant, 0, sizeof(*servant)); Srv_InitSession(&servant->m_session, connection, OnIoEvent, (Srv_TTerminateSessionHandler)OnTerminate); servant->m_reg = reg; StopTx(servant); StartRx(servant); return (Srv_TSession*)servant; }
/* ------------------------------------------------------------------------- */ static int OnRxBody(TServant *const servant) { TRxControl *const ctrl = &servant->m_rx; if (GetRxData(servant->m_session.m_connection, ctrl)) return -EXIT_FAILURE; if (ctrl->m_n_to_receive) return -EXIT_SUCCESS; /* continue receiving */ /* body is received */ { ezxml_t xml; const char* body; size_t len; body = GetBody(ctrl, &len); assert(len > 0 && body); xml = ezxml_parse_str_d(body, len); if (!xml) { LOG1_ERROR("servant", "the session (%u) received an invalid " "formated message", servant->m_session.m_id); return -EXIT_FAILURE; } if (OnMessageReceived(servant, xml)) return -EXIT_FAILURE; } StartRx(servant); return -EXIT_SUCCESS; }
/* * UEFI Reset () function * */ EFI_STATUS EFIAPI SnpReset ( IN EFI_SIMPLE_NETWORK_PROTOCOL* Snp, IN BOOLEAN Verification ) { UINT32 PmConf; UINT32 HwConf; UINT32 ResetFlags; EFI_STATUS Status; PmConf = 0; HwConf = 0; ResetFlags = 0; // Check Snp Instance if (Snp == NULL) { return EFI_INVALID_PARAMETER; } // First check that driver has not already been initialized if (Snp->Mode->State == EfiSimpleNetworkStarted) { DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not yet initialized\n")); return EFI_DEVICE_ERROR; } else if (Snp->Mode->State == EfiSimpleNetworkStopped) { DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not started\n")); return EFI_NOT_STARTED; } // Initiate a PHY reset Status = PhySoftReset (PHY_RESET_PMT, Snp); if (EFI_ERROR (Status)) { Snp->Mode->State = EfiSimpleNetworkStopped; return EFI_NOT_STARTED; } // Initiate a software reset ResetFlags |= SOFT_RESET_CHECK_MAC_ADDR_LOAD | SOFT_RESET_CLEAR_INT; if (Verification) { ResetFlags |= SOFT_RESET_SELF_TEST; } Status = SoftReset (ResetFlags, Snp); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_WARN, "Warning: Soft Reset Failed: Hardware Error\n")); return EFI_DEVICE_ERROR; } // Read the PM register PmConf = MmioRead32 (LAN9118_PMT_CTRL); // MPTCTRL_WOL_EN: Allow Wake-On-Lan to detect wake up frames or magic packets // MPTCTRL_ED_EN: Allow energy detection to allow lowest power consumption mode // MPTCTRL_PME_EN: Allow Power Management Events PmConf |= (MPTCTRL_WOL_EN | MPTCTRL_ED_EN | MPTCTRL_PME_EN); // Write the current configuration to the register MmioWrite32 (LAN9118_PMT_CTRL, PmConf); gBS->Stall (LAN9118_STALL); // Check that a buffer size was specified in SnpInitialize if (gTxBuffer != 0) { HwConf = MmioRead32 (LAN9118_HW_CFG); // Read the HW register HwConf &= ~HW_CFG_TX_FIFO_SIZE_MASK; // Clear buffer bits first HwConf |= HW_CFG_TX_FIFO_SIZE(gTxBuffer); // assign size chosen in SnpInitialize MmioWrite32 (LAN9118_HW_CFG, HwConf); // Write the conf gBS->Stall (LAN9118_STALL); } // Enable the receiver and transmitter and clear their contents StartRx (START_RX_CLEAR, Snp); StartTx (START_TX_MAC | START_TX_CFG | START_TX_CLEAR, Snp); // Now acknowledge all interrupts MmioWrite32 (LAN9118_INT_STS, ~0); return EFI_SUCCESS; }
/** \if INCLUDE_IN_HTML_ONLY \fn void StartResource(uint8_t e_StreamResource) \brief Low level function to handle starting of a resource \param e_StreamResource : The resource which is to be started, possible values are StreamResource_e_Sensor and StreamResource_e_Rx \return None \ingroup Stream \callgraph \callergraph \endif */ void StartResource( uint8_t e_StreamResource) { if (StreamResource_e_Rx == e_StreamResource) { // In case of CSI2, Rx is started before sensor to enable grabbing of the first frame. // This is done in the context of StartResource for sensor. // But the stream state machine still follows the following order, start sensor --> start Rx // As a result in case of normal start streming sequence(RUN command from user), Rx is already // started when the code hits this point. But in case of RUN command after ISP_STOP command, // sensor is not restarted, only Rx is started. This check is added to start Rx in such condition. if(SystemConfig_IsInputInterfaceCCP() || (!Is_ISP_SMIARX_ISP_SMIARX_STATUS_rx_state_GEN_RUNNING())) { OstTraceInt0(TRACE_FLOW, "SystemConfig_IsInputInterfaceCCP : StartRx()"); StartRx(); } else if(g_Stream_InputStatus.e_StreamResourceStatus_Sensor == StreamResourceStatus_e_Running) { StartRx(); } } else if (StreamResource_e_Sensor == e_StreamResource) { if (SystemConfig_IsInputInterfaceCCP()) { // Disable Interrupts in CRM ITM_Disable_Clock_Detect_LOSS_Interrupt_CRM(); // For CCP sensor, after starting sensor, wait for some time so that the clocks // available from the sensor are good. StartSensor(); //GPIOManager_Toggle_GPIO_Pin(); GPIOManager_Delay_us(g_SystemSetup.f_SensorStartDelay_us); if (SystemConfig_IPPSetupRequired()) { // enable IPP_SD_STATIC_CCP_EN Set_IPP_IPP_SD_STATIC_CCP_EN(STATIC_SD_CCP_EN_B_0x1); // enable the IPP_DPHY_TOP_IF Set_IPP_IPP_DPHY_TOP_IF_EN(1); // enable IPP internal CCP clock Set_IPP_IPP_INTERNAL_EN_CLK_CCP(INTERNAL_EN_CLK_CCP_B_0x1); } // switch to real sensor clocks as sensor has started & clocks are good. CRM_SwitchToRealSensorClocks(); // set sensor clock available in the Clock Manager. CRM_SetSensorClockAvailable(); } else { #if CRM_CSI2_CLOCK_DETECTION CRM_PreRunUpdate(); g_CRM_Status.e_Flag_StartEnabled = Flag_e_TRUE; // Rx start can be done before starting Sensor for CSI2 sensor // Reference : section 7.2 of "x500 start and stop sequence" document OstTraceInt0(TRACE_FLOW, "calling StartRx()"); StartRx(); #endif // For CSI sensor, after starting sensor, no need to wait for // before enabling the IPP_DPHY if (SystemConfig_IPPSetupRequired()) { // enable the IPP_DPHY_TOP_IF Set_IPP_IPP_DPHY_TOP_IF_EN(1); } StartSensor(); #if CRM_CSI2_CLOCK_DETECTION OstTraceInt0(TRACE_FLOW, "Waiting for clocks to be available"); while(CRM_GetIsSensorClockUnavailable()); #else //GPIOManager_Toggle_GPIO_Pin(); GPIOManager_Delay_us(g_SystemSetup.f_SensorStartDelay_us); // switch to real sensor clocks as sensor has started & clocks are good. CRM_SwitchToRealSensorClocks(); // set sensor clock available in the Clock Manager. CRM_SetSensorClockAvailable(); #endif } } return; }