コード例 #1
0
ファイル: qssp.cpp プロジェクト: BangBo/OpenPilot
/*!
 * \brief   Sends a data packet and blocks until timeout or ack is received.
 * \param   thisport = which port to use
 * \param	data = pointer to data to send
 * \param	length = number of data bytes to send. Must be less than 254
 * \return  true = ack was received within number of retries
 * \return	false = ack was not received.
 *
 * \note
 *
 */
uint16_t   qssp::ssp_SendDataBlock(uint8_t *data, uint16_t length )
{
    int16_t    packet_status = SSP_TX_WAITING;
    uint16_t   retval = FALSE;

    packet_status = ssp_SendData(data, length );		// send the data
    while( packet_status == SSP_TX_WAITING )  {					// check the status
        (void)ssp_ReceiveProcess();					// process any bytes received.
        packet_status = ssp_SendProcess();			// check the send status
    }
    if( packet_status == SSP_TX_ACKED )  {						// figure out what happened to the packet
        retval = TRUE;
    } else {
        retval = FALSE;
    }
    return retval;
}
コード例 #2
0
ファイル: qssp.cpp プロジェクト: BangBo/OpenPilot
/*!
 * \brief   Attempts to synchronize the sequence numbers with the other end of the connectin.
 * \param   thisport = which port to use
 * \return  true = success
 * \return	false = failed to receive an ACK to our synch request
 *
 * \note
 * A. send a packet with a sequence number equal to zero
 * B. if timed out then:
 * 		send synch packet again
 * 		increment try counter
 * 		if number of tries exceed maximum try limit then exit
 * C. goto A
 */
uint16_t qssp::ssp_Synchronise( )
{
    int16_t     packet_status;
    uint16_t    retval = FALSE;

#ifndef USE_SENDPACKET_DATA
    thisport->txSeqNo = 0;                        // make this zero to cause the other end to re-synch with us
    SETBIT(thisport->flags, SENT_SYNCH);
    // TODO - should this be using ssp_SendPacketData()??
    sf_MakePacket( thisport->txBuf, NULL, 0, thisport->txSeqNo );    // construct the packet
    sf_SendPacket(  );
    sf_SetSendTimeout(  );
    thisport->SendState = SSP_AWAITING_ACK;
    packet_status = SSP_TX_WAITING;
#else
    packet_status = ssp_SendData( NULL, 0 );
#endif
    while( packet_status == SSP_TX_WAITING )  {      	// we loop until we time out.
        (void)ssp_ReceiveProcess(  );			// do the receive process
        packet_status = ssp_SendProcess(  );	// do the send process
    }
    thisport->sendSynch = FALSE;
    switch( packet_status ) {
    case SSP_TX_ACKED:
        retval = TRUE;
        break;
    case SSP_TX_BUSY:         // intentional fall through.
    case SSP_TX_TIMEOUT:      // intentional fall through.
    case SSP_TX_BUFOVERRUN:
        retval = FALSE;
        break;
    default:
        retval = FALSE;
        break;
    };
    return retval;
}
コード例 #3
0
ファイル: main.c プロジェクト: gotosteven/my_OpenPilot_mods
int main() {
	/* NOTE: Do NOT modify the following start-up sequence */
	/* Any new initialization functions should be added in OpenPilotInit() */

	/* Brings up System using CMSIS functions, enables the LEDs. */
	PIOS_SYS_Init();
	if (BSL_HOLD_STATE == 0)
		USB_connected = TRUE;

	PIOS_IAP_Init();

	if (PIOS_IAP_CheckRequest() == TRUE) {
		PIOS_Board_Init();
		PIOS_DELAY_WaitmS(1000);
		User_DFU_request = TRUE;
		PIOS_IAP_ClearRequest();
	}

	GO_dfu = (USB_connected == TRUE) || (User_DFU_request == TRUE);

	if (GO_dfu == TRUE) {
		if (USB_connected)
			ProgPort = Usb;
		else
			ProgPort = Serial;
		PIOS_Board_Init();
		if(User_DFU_request == TRUE)
			DeviceState = DFUidle;
		else
			DeviceState = BLidle;
		STOPWATCH_Init(100,LED_PWM_TIMER);
		if (ProgPort == Serial) {
			fifoBuf_init(&ssp_buffer,rx_buffer,UART_BUFFER_SIZE);
			STOPWATCH_Init(100,SSP_TIMER);//nao devia ser 1000?
			STOPWATCH_Reset(SSP_TIMER);
			ssp_Init(&ssp_port, &SSP_PortConfig);
		}
		PIOS_OPAHRS_ForceSlaveSelected(true);
	} else
		JumpToApp = TRUE;

	STOPWATCH_Reset(LED_PWM_TIMER);
	while (TRUE) {
		if (ProgPort == Serial) {
			ssp_ReceiveProcess(&ssp_port);
			status=ssp_SendProcess(&ssp_port);
			while((status!=SSP_TX_IDLE) && (status!=SSP_TX_ACKED)){
				ssp_ReceiveProcess(&ssp_port);
				status=ssp_SendProcess(&ssp_port);
			}
		}
		if (JumpToApp == TRUE)
			jump_to_app();
		//pwm_period = 50; // *100 uS -> 5 mS
		//pwm_sweep_steps =100; // * 5 mS -> 500 mS

		switch (DeviceState) {
		case Last_operation_Success:
		case uploadingStarting:
		case DFUidle:
			period1 = 50;
			sweep_steps1 = 100;
			PIOS_LED_Off(RED);
			period2 = 0;
			break;
		case uploading:
			period1 = 50;
			sweep_steps1 = 100;
			period2 = 25;
			sweep_steps2 = 50;
			break;
		case downloading:
			period1 = 25;
			sweep_steps1 = 50;
			PIOS_LED_Off(RED);
			period2 = 0;
			break;
		case BLidle:
			period1 = 0;
			PIOS_LED_On(BLUE);
			period2 = 0;
			break;
		default://error
			period1 = 50;
			sweep_steps1 = 100;
			period2 = 50;
			sweep_steps2 = 100;
		}

		if (period1 != 0) {
			if (LedPWM(period1, sweep_steps1, STOPWATCH_ValueGet(LED_PWM_TIMER)))
				PIOS_LED_On(BLUE);
			else
				PIOS_LED_Off(BLUE);
		} else
			PIOS_LED_On(BLUE);

		if (period2 != 0) {
			if (LedPWM(period2, sweep_steps2, STOPWATCH_ValueGet(LED_PWM_TIMER)))
				PIOS_LED_On(RED);
			else
				PIOS_LED_Off(RED);
		} else
			PIOS_LED_Off(RED);

		if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100)
			STOPWATCH_Reset(LED_PWM_TIMER);
		if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState == BLidle))
			JumpToApp = TRUE;

		processRX();
		DataDownload(start);
	}
}