1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-31 16:52:10 +01:00

OP-22 Flight/PiOS: first tests done with spektrum satellite, I can read binded receiver serial stream

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@629 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
sambas 2010-05-16 08:35:38 +00:00 committed by sambas
parent 56f1e8b547
commit 76cd72915d
3 changed files with 14 additions and 51 deletions

View File

@ -143,7 +143,7 @@ static void TaskTesting(void *pvParameters)
portTickType xDelay = 250 / portTICK_RATE_MS; portTickType xDelay = 250 / portTICK_RATE_MS;
portTickType xTimeout = 10 / portTICK_RATE_MS; portTickType xTimeout = 10 / portTICK_RATE_MS;
PIOS_BMP085_Init(); //PIOS_BMP085_Init();
for(;;) for(;;)
{ {
@ -161,9 +161,9 @@ static void TaskTesting(void *pvParameters)
*/ */
#if defined(PIOS_INCLUDE_SPEKTRUM) #if defined(PIOS_INCLUDE_SPEKTRUM)
int32_t len = PIOS_SPEKTRUM_RxBufferUsed(COM_USART3); int32_t len = PIOS_SPEKTRUM_RxBufferUsed();
for(int32_t i = 0; i < len; i++) { for(int32_t i = 0; i < len; i++) {
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "%c", PIOS_SPEKTRUM_RxBufferGet(USART_3)); PIOS_COM_SendFormattedString(COM_DEBUG_USART, "%02X ", PIOS_SPEKTRUM_RxBufferGet());
} }
#endif #endif
#if defined(PIOS_INCLUDE_PWM) #if defined(PIOS_INCLUDE_PWM)

View File

@ -50,7 +50,6 @@ static volatile uint8_t spektrum_buffer_size;
*/ */
void PIOS_SPEKTRUM_Init(void) void PIOS_SPEKTRUM_Init(void)
{ {
#if (PIOS_SPEKTRUM_ENABLED)
/* Clear buffer counters */ /* Clear buffer counters */
spektrum_buffer_tail = spektrum_buffer_head = spektrum_buffer_size = 0; spektrum_buffer_tail = spektrum_buffer_head = spektrum_buffer_size = 0;
@ -97,8 +96,6 @@ void PIOS_SPEKTRUM_Init(void)
/* Enable USART */ /* Enable USART */
USART_Cmd(PIOS_USART3_USART, ENABLE); USART_Cmd(PIOS_USART3_USART, ENABLE);
#endif
} }
/** /**
@ -108,13 +105,9 @@ void PIOS_SPEKTRUM_Init(void)
* \return 1: USART available * \return 1: USART available
* \return 0: USART not available * \return 0: USART not available
*/ */
int32_t PIOS_SPEKTRUM_RxBufferFree(USARTNumTypeDef usart) int32_t PIOS_SPEKTRUM_RxBufferFree()
{ {
if(usart >= PIOS_USART_NUM) {
return 0;
} else {
return PIOS_USART_RX_BUFFER_SIZE - spektrum_buffer_size; return PIOS_USART_RX_BUFFER_SIZE - spektrum_buffer_size;
}
} }
/** /**
@ -124,13 +117,9 @@ int32_t PIOS_SPEKTRUM_RxBufferFree(USARTNumTypeDef usart)
* \return 0 if USART not available * \return 0 if USART not available
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions * \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
*/ */
int32_t PIOS_SPEKTRUM_RxBufferUsed(USARTNumTypeDef usart) int32_t PIOS_SPEKTRUM_RxBufferUsed()
{ {
if(usart >= PIOS_USART_NUM) {
return 0;
} else {
return spektrum_buffer_size; return spektrum_buffer_size;
}
} }
/** /**
@ -141,12 +130,8 @@ int32_t PIOS_SPEKTRUM_RxBufferUsed(USARTNumTypeDef usart)
* \return >= 0: number of received bytes * \return >= 0: number of received bytes
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions * \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
*/ */
int32_t PIOS_SPEKTRUM_RxBufferGet(USARTNumTypeDef usart) int32_t PIOS_SPEKTRUM_RxBufferGet()
{ {
if(usart >= PIOS_USART_NUM) {
/* USART not available */
return -1;
}
if(!spektrum_buffer_size) { if(!spektrum_buffer_size) {
/* nothing new in buffer */ /* nothing new in buffer */
return -2; return -2;
@ -173,13 +158,8 @@ int32_t PIOS_SPEKTRUM_RxBufferGet(USARTNumTypeDef usart)
* \return >= 0: number of received bytes * \return >= 0: number of received bytes
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions * \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
*/ */
int32_t PIOS_SPEKTRUM_RxBufferPeek(USARTNumTypeDef usart) int32_t PIOS_SPEKTRUM_RxBufferPeek()
{ {
if(usart >= PIOS_USART_NUM) {
/* USART not available */
return -1;
}
if(!spektrum_buffer_size) { if(!spektrum_buffer_size) {
/* Nothing new in buffer */ /* Nothing new in buffer */
return -2; return -2;
@ -203,13 +183,8 @@ int32_t PIOS_SPEKTRUM_RxBufferPeek(USARTNumTypeDef usart)
* \return -2 if buffer full (retry) * \return -2 if buffer full (retry)
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions * \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
*/ */
int32_t PIOS_SPEKTRUM_RxBufferPut(USARTNumTypeDef usart, uint8_t b) int32_t PIOS_SPEKTRUM_RxBufferPut(uint8_t b)
{ {
if(usart >= PIOS_USART_NUM) {
/* USART not available */
return -1;
}
if(spektrum_buffer_size >= PIOS_USART_RX_BUFFER_SIZE) { if(spektrum_buffer_size >= PIOS_USART_RX_BUFFER_SIZE) {
/* Buffer full (retry) */ /* Buffer full (retry) */
return -2; return -2;
@ -229,7 +204,6 @@ int32_t PIOS_SPEKTRUM_RxBufferPut(USARTNumTypeDef usart, uint8_t b)
return 0; return 0;
} }
#if (PIOS_SPEKTRUM_ENABLED)
/* Interrupt handler for USART3 */ /* Interrupt handler for USART3 */
PIOS_USART3_IRQHANDLER_FUNC PIOS_USART3_IRQHANDLER_FUNC
{ {
@ -237,26 +211,15 @@ PIOS_USART3_IRQHANDLER_FUNC
if(PIOS_USART3_USART->SR & (1 << 5)) { if(PIOS_USART3_USART->SR & (1 << 5)) {
uint8_t b = PIOS_USART3_USART->DR; uint8_t b = PIOS_USART3_USART->DR;
if(PIOS_USART_RxBufferPut(USART_3, b) < 0) { if(PIOS_SPEKTRUM_RxBufferPut(b) < 0) {
/* Here we could add some error handling */ /* Here we could add some error handling */
} }
} }
if(PIOS_USART3_USART->SR & (1 << 7)) { // check if TXE flag is set if(PIOS_USART3_USART->SR & (1 << 7)) { // check if TXE flag is set
if(PIOS_USART_TxBufferUsed(USART_3) > 0) {
int b = PIOS_USART_TxBufferGet(USART_3);
if(b < 0) {
/* Here we could add some error handling */
PIOS_USART3_USART->DR = 0xff;
} else {
PIOS_USART3_USART->DR = b;
}
} else {
/* Disable TXE interrupt (TXEIE=0) */ /* Disable TXE interrupt (TXEIE=0) */
PIOS_USART3_USART->CR1 &= ~(1 << 7); PIOS_USART3_USART->CR1 &= ~(1 << 7);
} }
}
} }
#endif
#endif #endif

View File

@ -33,10 +33,10 @@
/* Public Functions */ /* Public Functions */
extern void PIOS_SPEKTRUM_Init(void); extern void PIOS_SPEKTRUM_Init(void);
extern int32_t PIOS_SPEKTRUM_RxBufferFree(USARTNumTypeDef uart); extern int32_t PIOS_SPEKTRUM_RxBufferFree();
extern int32_t PIOS_SPEKTRUM_RxBufferUsed(USARTNumTypeDef uart); extern int32_t PIOS_SPEKTRUM_RxBufferUsed();
extern int32_t PIOS_SPEKTRUM_RxBufferGet(USARTNumTypeDef uart); extern int32_t PIOS_SPEKTRUM_RxBufferGet();
extern int32_t PIOS_SPEKTRUM_RxBufferPeek(USARTNumTypeDef uart); extern int32_t PIOS_SPEKTRUM_RxBufferPeek();
extern int32_t PIOS_SPEKTRUM_RxBufferPut(USARTNumTypeDef uart, uint8_t b); extern int32_t PIOS_SPEKTRUM_RxBufferPut(uint8_t b);
#endif /* PIOS_SPEKTRUM_H */ #endif /* PIOS_SPEKTRUM_H */