mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
Loopback test of HID working. Still a WIP but committing what I have to show progress.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@582 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
7edfaa5f26
commit
0aba12fe1f
@ -114,7 +114,6 @@ SRC += $(MODGPS)/GPS.c $(MODGPS)/buffer.c
|
||||
|
||||
## OPENPILOT:
|
||||
SRC += $(OPSYSTEM)/openpilot.c
|
||||
SRC += $(OPSYSTEM)/op_logging.c
|
||||
SRC += $(OPSYSTEM)/alarms.c
|
||||
SRC += $(OPUAVTALK)/uavtalk.c
|
||||
SRC += $(OPUAVOBJ)/uavobjectmanager.c
|
||||
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file op_logging.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief OpenPilot Logging Functions header.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OP_LOGGING_H
|
||||
#define OP_LOGGING_H
|
||||
|
||||
/* Defines */
|
||||
#define OP_LOGGING_TASK_PRI ( tskIDLE_PRIORITY + 4 )
|
||||
|
||||
/* Type Definitions */
|
||||
typedef enum {FLIGHT_LOG, RC_LOG} LogTypeTypeDef;
|
||||
typedef struct {
|
||||
LogTypeTypeDef Type;
|
||||
char *Message;
|
||||
} LogTypeDef;
|
||||
|
||||
|
||||
/* Function Prototypes */
|
||||
extern void OP_Logging_Init(void);
|
||||
|
||||
|
||||
#endif /* OP_LOGGING_H */
|
@ -33,7 +33,6 @@
|
||||
|
||||
/* OpenPilot Libraries */
|
||||
#include "op_config.h"
|
||||
#include "op_logging.h"
|
||||
#include "utlist.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "eventdispatcher.h"
|
||||
|
@ -1,103 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file op_logging.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief OpenPilot Logging Functions
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OP_LOGGING Logging Functions
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
/* OpenPilot Includes */
|
||||
#include "openpilot.h"
|
||||
|
||||
/* Global Variables */
|
||||
xQueueHandle xLoggingQueue;
|
||||
|
||||
/* Local Variables */
|
||||
static uint8_t FlightLogFilename[128];
|
||||
|
||||
/* Local Functions */
|
||||
static void OP_Logging_MicroSDGateKeeperTask(void *pvParameters);
|
||||
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
void OP_Logging_Init(void)
|
||||
{
|
||||
// uint16_t FileCount;
|
||||
// FILINFO DummyFileInfo;
|
||||
//
|
||||
// /* Create the logging queue */
|
||||
// xLoggingQueue = xQueueCreate(15, sizeof(LogTypeDef));
|
||||
//
|
||||
// /* This is a crude way to file the next avaiable number avaiable */
|
||||
// /* The proper way would be to use folders with dates, we will get to that later */
|
||||
// for(FileCount = 0; FileCount < 65536; FileCount++) {
|
||||
// sprintf((char *)FlightLogFilename, "Flight_Log_%d.txt", FileCount);
|
||||
// if(f_stat((char *)FlightLogFilename, &DummyFileInfo) != FR_OK) {
|
||||
// /* We have come to a file that doesn't extist */
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* Start the gatekeeper task */
|
||||
// xTaskCreate(OP_Logging_MicroSDGateKeeperTask, (signed portCHAR *) "Logging_MicroSDGateKeeperTask", configMINIMAL_STACK_SIZE, NULL, OP_LOGGING_TASK_PRI, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Task to handle the MicroSD log que
|
||||
*/
|
||||
void OP_Logging_MicroSDGateKeeperTask(void *pvParameters)
|
||||
{
|
||||
// FIL File;
|
||||
// LogTypeDef pcMessageToLog;
|
||||
//
|
||||
// for(;;) {
|
||||
// xQueueReceive(xLoggingQueue, &pcMessageToLog, portMAX_DELAY);
|
||||
//
|
||||
// /* We don't want this take to get pre-empted, so enter critical state */
|
||||
// /* If we do get pre-empted we face corrupting the MicroSD filesystem */
|
||||
// taskENTER_CRITICAL();
|
||||
//
|
||||
// /* Open the correct log file */
|
||||
// switch(pcMessageToLog.Type) {
|
||||
// case FLIGHT_LOG:
|
||||
// f_open(&File, (char *)FlightLogFilename, FA_OPEN_EXISTING);
|
||||
// break;
|
||||
// case RC_LOG:
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// /* Write the stuff */
|
||||
// f_puts(pcMessageToLog.Message, &File);
|
||||
//
|
||||
// /* Sync the MicroSD Card */
|
||||
// f_sync(&File);
|
||||
//
|
||||
// /* Close the file */
|
||||
// f_close(&File);
|
||||
//
|
||||
// /* Exit the critical stage */
|
||||
// taskEXIT_CRITICAL();
|
||||
// }
|
||||
}
|
@ -265,7 +265,7 @@ int32_t PIOS_COM_ReceiveBufferUsed(COMPortTypeDef port)
|
||||
return PIOS_USART_RxBufferUsed(USART_3);
|
||||
#endif
|
||||
case COM_USB_HID:
|
||||
return PIOS_USB_HID_DATA_LENGTH;
|
||||
return PIOS_USB_HID_RxBufferUsed();
|
||||
/* To suppress warnings */
|
||||
default:
|
||||
return 0;
|
||||
|
@ -157,16 +157,8 @@ void PIOS_Servo_Set(uint8_t Servo, uint16_t Position)
|
||||
{
|
||||
#ifndef PIOS_ENABLE_DEBUG_PINS
|
||||
/* Make sure servo exists */
|
||||
if (Servo < PIOS_SERVO_NUM_OUTPUTS && Servo >= 0)
|
||||
if (Servo <= PIOS_SERVO_NUM_OUTPUTS && Servo > 0)
|
||||
{
|
||||
/* Clip servo position */
|
||||
if(Position < SERVOS_POSITION_MIN) {
|
||||
Position = SERVOS_POSITION_MIN;
|
||||
}
|
||||
if(Position > SERVOS_POSITION_MAX) {
|
||||
Position = SERVOS_POSITION_MAX;
|
||||
}
|
||||
|
||||
/* Update the position */
|
||||
ServoPosition[Servo] = Position;
|
||||
|
||||
|
@ -83,7 +83,6 @@ static ONE_DESCRIPTOR PIOS_USB_HID_Hid_Descriptor = {(uint8_t*) PIOS_USB_HID_Rep
|
||||
static volatile uint8_t rx_buffer_new_data_ctr = 0;
|
||||
static volatile uint8_t rx_buffer_ix;
|
||||
static uint8_t transfer_possible = 0;
|
||||
|
||||
static uint8_t rx_buffer[PIOS_USB_HID_DATA_LENGTH] = {0};
|
||||
|
||||
/**
|
||||
@ -144,7 +143,7 @@ int32_t PIOS_USB_HID_CheckAvailable(void)
|
||||
int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t *buffer, uint16_t len)
|
||||
{
|
||||
if(len > PIOS_USB_HID_DATA_LENGTH) {
|
||||
/* Cannot get all requested bytes */
|
||||
/* Cannot send all requested bytes */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -183,7 +182,7 @@ int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t *buffer, uint16_t len)
|
||||
* \return >= 0: received byte
|
||||
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
||||
*/
|
||||
int32_t PIOS_USB_HID_RxBufferGet(void)
|
||||
uint8_t PIOS_USB_HID_RxBufferGet(void)
|
||||
{
|
||||
if(!rx_buffer_new_data_ctr) {
|
||||
/* Nothing new in buffer */
|
||||
@ -192,30 +191,45 @@ int32_t PIOS_USB_HID_RxBufferGet(void)
|
||||
|
||||
/* This stops returning bytes after the first occurrence of '\0' */
|
||||
/* We don't need to do this but it does optimise things quite a bit */
|
||||
//if(rx_buffer[rx_buffer_ix] == 0) {
|
||||
if(rx_buffer[rx_buffer_ix] == 0) {
|
||||
/* TODO: Evaluate if this is really needed */
|
||||
/* Clean the buffer */
|
||||
/*for(uint8_t i = 0; i < PIOS_USB_HID_DATA_LENGTH; i++) {
|
||||
for(uint8_t i = 0; i < PIOS_USB_HID_DATA_LENGTH; i++) {
|
||||
rx_buffer[i] = 0;
|
||||
}
|
||||
|
||||
rx_buffer_new_data_ctr = 0;
|
||||
rx_buffer_ix = 0;
|
||||
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
//SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
return -1;
|
||||
}*/
|
||||
}
|
||||
|
||||
/* There is still data in the buffer */
|
||||
uint8_t b = rx_buffer[rx_buffer_ix++];
|
||||
if(!--rx_buffer_new_data_ctr) {
|
||||
rx_buffer_ix = 0;
|
||||
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
//SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
}
|
||||
|
||||
/* Return received byte */
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of used bytes in receive buffer
|
||||
* \return > 0: number of used bytes
|
||||
* \return 0 nothing available
|
||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||
*/
|
||||
int32_t PIOS_USB_HID_RxBufferUsed(void)
|
||||
{
|
||||
if(!rx_buffer_new_data_ctr) {
|
||||
return 0;
|
||||
} else {
|
||||
return PIOS_USB_HID_DATA_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t PIOS_USB_HID_CB_Data_Setup(uint8_t RequestNo)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)( uint16_t) = NULL;
|
||||
@ -302,7 +316,7 @@ static uint8_t *PIOS_USB_HID_GetProtocolValue(uint16_t Length)
|
||||
*/
|
||||
void PIOS_USB_HID_EP1_OUT_Callback(void)
|
||||
{
|
||||
#if 1
|
||||
#if 0
|
||||
uint32_t DataLength = 0;
|
||||
|
||||
/* Get the number of received data on the selected Endpoint */
|
||||
@ -313,28 +327,25 @@ void PIOS_USB_HID_EP1_OUT_Callback(void)
|
||||
|
||||
/* We now have data waiting */
|
||||
rx_buffer_new_data_ctr = PIOS_USB_HID_DATA_LENGTH;
|
||||
|
||||
#else
|
||||
// FOR DEBUGGING USE ONLY
|
||||
|
||||
uint8_t Receive_Buffer[PIOS_USB_HID_DATA_LENGTH];
|
||||
//uint32_t DataLength = 0;
|
||||
uint32_t DataLength = 0;
|
||||
|
||||
/* Read received data (63 bytes) */
|
||||
USB_SIL_Read(EP1_OUT, Receive_Buffer);
|
||||
//USB_SIL_Read(EP1_OUT, Receive_Buffer);
|
||||
|
||||
/* Get the number of received data on the selected Endpoint */
|
||||
//DataLength = GetEPRxCount(ENDP1 & 0x7F);
|
||||
DataLength = GetEPRxCount(ENDP1 & 0x7F);
|
||||
|
||||
/* Use the memory interface function to write to the selected endpoint */
|
||||
//PMAToUserBufferCopy((uint8_t *) Receive_Buffer, GetEPRxAddr(ENDP1 & 0x7F), DataLength);
|
||||
PMAToUserBufferCopy((uint8_t *) Receive_Buffer, GetEPRxAddr(ENDP1 & 0x7F), DataLength);
|
||||
|
||||
/* Send it back */
|
||||
PIOS_COM_SendBuffer(GPS, Receive_Buffer, sizeof(Receive_Buffer));
|
||||
PIOS_COM_SendBuffer(GPS, "\r", 1);
|
||||
PIOS_COM_SendFormattedStringNonBlocking(COM_USB_HID, "Received: %s", Receive_Buffer);
|
||||
#endif
|
||||
|
||||
SetEPRxStatus(ENDP1, EP_RX_VALID);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -42,7 +42,8 @@ extern int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected);
|
||||
extern int32_t PIOS_USB_HID_CheckAvailable(void);
|
||||
extern int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t *buffer, uint16_t len);
|
||||
extern int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t *buffer, uint16_t len);
|
||||
extern int32_t PIOS_USB_HID_RxBufferGet(void);
|
||||
extern uint8_t PIOS_USB_HID_RxBufferGet(void);
|
||||
extern int32_t PIOS_USB_HID_RxBufferUsed(void);
|
||||
extern int32_t PIOS_USB_HID_CB_Data_Setup(uint8_t RequestNo);
|
||||
extern int32_t PIOS_USB_HID_CB_NoData_Setup(uint8_t RequestNo);
|
||||
extern void PIOS_USB_HID_EP1_OUT_Callback(void);
|
||||
|
Loading…
Reference in New Issue
Block a user