implemented uart transmit function

This commit is contained in:
2017-02-01 17:44:14 +08:00
parent ccab78c245
commit 26ee789fd6
11 changed files with 218 additions and 304 deletions

Binary file not shown.

View File

@@ -46,7 +46,7 @@ extern "C" {
#include "../../npi/inc/npi_tl_uart.h"
#define uint8 unsigned char
#define UART_BUFFER_SIZE 128
extern void Uart_Init(npiCB_t npiCBack);
@@ -54,6 +54,13 @@ extern void UART_WriteTransport (uint8 *str, uint8 len);
extern uint8 *UART_GetRxBufferAddress();
#if defined UART_DEBUG
extern void PrintString(uint8 *str);
extern void PrintValue(char *title, uint32 value, uint8 format);
#endif
extern void UART_DLY_ms(unsigned int ms);
#ifdef __cplusplus

View File

@@ -48,6 +48,7 @@
#include "board_lcd.h"
#include "board_uart.h"
#include "Board.h"
#include "utils.h"
/*********************************************************************
* TYPEDEFS
@@ -332,95 +333,6 @@ unsigned char BMP[] =
void Draw_BMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]);
static void _itoa(unsigned int uiNum, unsigned char *buf, unsigned char uiRadix)
{
unsigned char c, i;
unsigned char *p, rst[32];
p = rst;
for (i = 0; i < 32; i++, p++)
{
/* Isolate a digit */
c = uiNum % uiRadix;
/* Convert to Ascii */
*p = c + ((c < 10) ? '0' : '7');
uiNum /= uiRadix;
if (!uiNum)
break;
}
for (c = 0; c <= i; c++)
{
/* Reverse character order */
*buf++ = *p--;
}
*buf = '\0';
}
static unsigned char * _ltoa(unsigned long l, unsigned char *buf, unsigned char radix)
{
#if defined (__TI_COMPILER_VERSION)
return ( (unsigned char*)ltoa( l, (char *)buf ) );
#elif defined( __GNUC__ )
return ( (char*)ltoa( l, buf, radix ) );
#else
unsigned char tmp1[10] = "", tmp2[10] = "", tmp3[10] = "";
unsigned short num1, num2, num3;
unsigned char i;
buf[0] = '\0';
if ( radix == 10 )
{
num1 = l % 10000;
num2 = (l / 10000) % 10000;
num3 = (unsigned short)(l / 100000000);
if (num3) _itoa(num3, tmp3, 10);
if (num2) _itoa(num2, tmp2, 10);
if (num1) _itoa(num1, tmp1, 10);
if (num3)
{
strcpy((char*)buf, (char const*)tmp3);
for (i = 0; i < 4 - strlen((char const*)tmp2); i++)
strcat((char*)buf, "0");
}
strcat((char*)buf, (char const*)tmp2);
if (num3 || num2)
{
for (i = 0; i < 4 - strlen((char const*)tmp1); i++)
strcat((char*)buf, "0");
}
strcat((char*)buf, (char const*)tmp1);
if (!num3 && !num2 && !num1)
strcpy((char*)buf, "0");
}
else if ( radix == 16 )
{
num1 = l & 0x0000FFFF;
num2 = l >> 16;
if (num2) _itoa(num2, tmp2, 16);
if (num1) _itoa(num1, tmp1, 16);
if (num2)
{
strcpy((char*)buf,(char const*)tmp2);
for (i = 0; i < 4 - strlen((char const*)tmp1); i++)
strcat((char*)buf, "0");
}
strcat((char*)buf, (char const*)tmp1);
if (!num2 && !num1)
strcpy((char*)buf, "0");
}
else
return NULL;
return buf;
#endif
}
void LCD_DLY_ms(unsigned int ms)
{
unsigned int a;

View File

@@ -75,12 +75,15 @@
#include "Board.h"
#include "osal.h"
#include "board_uart.h"
#include "board_LCD.h"
#include "utils.h"
#include "../../npi/inc/npi_tl_uart.h"
#ifdef NPI_USE_UART
#if defined NPI_USE_UART
static char tRxBuf[256] = { 0 };
static char tTxBuf[256] = { 0 };
@@ -126,6 +129,30 @@ void UART_DLY_ms(unsigned int ms)
}
#if defined UART_DEBUG
void PrintString(uint8 *str)
{
UART_WriteTransport(str, (strlen((char*)str)));
}
void PrintValue(char *content, uint32 value, uint8 format)
{
uint8 tmpLen;
uint8 buf[UART_BUFFER_SIZE];
uint32 err;
tmpLen = (uint8)strlen((char*)content);
memcpy(buf, content, tmpLen);
err = (uint32)(value);
_ltoa(err, &buf[tmpLen], format);
PrintString(buf);
}
#endif
#endif

View File

@@ -1,100 +0,0 @@
#include "bcomdef.h"
#include "util.h"
#include "stdio.h"
#include "string.h"
#if 1
#define SEND_BUF_MAX_SIZE 320
static char sendBufForUsart[SEND_BUF_MAX_SIZE] = {0}; //usart send buffer.
static unsigned short sendWrite = 0; //usart send buffer write position.
static unsigned short sendRead = 0; //usart send buffer read position.
bool qq_write(uint8 *WrBuf, unsigned short WrLen)
{
unsigned short emptyLen;
unsigned short tmpAddr;
unsigned short tmpLen;
emptyLen = (sendRead+SEND_BUF_MAX_SIZE-(sendWrite+1)) % SEND_BUF_MAX_SIZE;
if (emptyLen >= WrLen)
{
tmpAddr = (sendWrite+WrLen) % SEND_BUF_MAX_SIZE;
if (tmpAddr <= sendWrite) //If Circular array have inverse to begin.
{
tmpLen =WrLen - tmpAddr;
memcpy(&sendBufForUsart[sendWrite], WrBuf, tmpLen); //bug place
memcpy(&sendBufForUsart[0], WrBuf+tmpLen, tmpAddr);
}
else
{
memcpy(&sendBufForUsart[sendWrite], WrBuf, WrLen);
}
sendWrite = tmpAddr;
return TRUE;
}
return FALSE;
}
unsigned short qq_read(uint8 *RdBuf, unsigned short RdLen)
{
unsigned short validLen;
unsigned short tmpAddr;
unsigned short tmpLen;
validLen = (sendWrite+SEND_BUF_MAX_SIZE-sendRead) % SEND_BUF_MAX_SIZE;
if(validLen == 0)
return 0;
if (validLen < RdLen)
RdLen = validLen;
if (validLen >= RdLen)
{
tmpAddr = (sendRead+RdLen) % SEND_BUF_MAX_SIZE;
if (tmpAddr <= sendRead) //If Circular array have inverse to begin.
{
tmpLen =RdLen - tmpAddr;
memcpy(RdBuf, &sendBufForUsart[sendRead], tmpLen);
memcpy(RdBuf+tmpLen, &sendBufForUsart[0], tmpAddr);
}
else
{
memcpy(RdBuf, &sendBufForUsart[sendRead], RdLen);
}
sendRead = tmpAddr;
}
return RdLen;
}
unsigned short qq_total()
{
unsigned short validLen;
validLen = (sendWrite+SEND_BUF_MAX_SIZE-sendRead) % SEND_BUF_MAX_SIZE;
return validLen;
}
void qq_clear()
{
sendWrite = 0; //usart send buffer write position.
sendRead = 0; //usart send buffer read position.
}
#endif
/*********************************************************************
*********************************************************************/

View File

@@ -1,32 +0,0 @@
#ifndef AMOMCU_BUFFER_H
#define AMOMCU_BUFFER_H
#ifdef __cplusplus
extern "C"
{
#endif
//写 WrLen 个字节数据到 缓冲区 RdBuf 返回 true 表示成功, 返回false表示剩余缓冲区放不下这段数据了
extern bool qq_write(uint8 *WrBuf, unsigned short WrLen);
// 读 RdLen 个字节数据到 缓冲区 RdBuf 返回读取到的有效数据长度
extern unsigned short qq_read(uint8 *RdBuf, unsigned short RdLen);
// 读出缓冲区中有效数据的大小,一般用于判断有没有数据可读
extern unsigned short qq_total();
// 清除缓冲区
extern void qq_clear();
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,42 +1,14 @@
/*******************************************************************************
Filename: buffer.c
Revised: $Date: 2016-01-07 16:59:59 -0800 (Thu, 07 Jan 2016) $
Revision: $Revision: 44594 $
/**************************************************************************************
Filename: buffer.c
Revised: Date: 2017-01-01
Revision: Revision: 1.0
Description: This file contains the Simple BLE Peripheral sample
application for use with the CC2650 Bluetooth Low Energy
Protocol Stack.
Description: This file provides basic buffer support for queue
Copyright 2013 - 2015 Texas Instruments Incorporated. All rights reserved.
Revision log:
* 2017-01-01: created by strawmanbobi
**************************************************************************************/
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED “AS IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
*******************************************************************************/
#include "bcomdef.h"
#include "util.h"
@@ -60,7 +32,7 @@ bool queue_write(uint8 *WrBuf, unsigned short WrLen)
tmpAddr = (sendWrite + WrLen) % SEND_BUF_MAX_SIZE;
if (tmpAddr <= sendWrite)
{
tmpLen =WrLen - tmpAddr;
tmpLen = WrLen - tmpAddr;
memcpy(&sendBufForUsart[sendWrite], WrBuf, tmpLen);
memcpy(&sendBufForUsart[0], WrBuf+tmpLen, tmpAddr);
}

View File

@@ -1,42 +1,14 @@
/*******************************************************************************
Filename: buffer.h
Revised: $Date: 2016-01-07 16:59:59 -0800 (Thu, 07 Jan 2016) $
Revision: $Revision: 44594 $
/**************************************************************************************
Filename: buffer.h
Revised: Date: 2017-01-01
Revision: Revision: 1.0
Description: This file contains the Simple BLE Peripheral sample
application for use with the CC2650 Bluetooth Low Energy
Protocol Stack.
Description: This file provides basic buffer support for queue
Copyright 2013 - 2015 Texas Instruments Incorporated. All rights reserved.
Revision log:
* 2017-01-01: created by strawmanbobi
**************************************************************************************/
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED “AS IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
*******************************************************************************/
#ifndef BUFFER_H
#define BUFFER_H

View File

@@ -171,6 +171,10 @@
static ir_type_t ir_type = IR_TYPE_NONE;
static ir_state_t ir_state = IR_STATE_NONE;
static int32_t uart_recv_length = 0;
static int32_t uart_recv_expected_length = 0;
static int32_t uart_recv_started = 0;
// sample source code
static uint8_t source_tv[1024] =
{
@@ -308,16 +312,31 @@ static void IRext_processKey(uint8_t ir_type, uint8_t ir_key, char* key_display)
static void IRext_processUartMsg(uint8_t* data, uint16_t len)
{
uint16_t index = 0;
char debug[8] = { 0 };
#if UART_DEBUG
for (index = 0; index < len; index++)
{
memset(debug, 0x00, 8);
sprintf(debug, "%02X,", data[index]);
UART_WriteTransport((uint8_t*)debug, strlen(debug));
PrintValue(" ", data[index], 16);
UART_DLY_ms(10);
}
UART_WriteTransport("\n", 1);
PrintString("\n");
#endif
if (0 == uart_recv_started && len == 4)
{
uart_recv_expected_length = *(int *)data;
PrintValue("payload length = ", uart_recv_expected_length, 10);
uart_recv_started = 1;
}
else
{
uart_recv_length += len;
if (uart_recv_length >= uart_recv_expected_length)
{
PrintString("all data are received\n");
uart_recv_started = 0;
}
}
}
/* IREXT - end */
@@ -1112,11 +1131,10 @@ static void SimpleBLEPeripheral_processAppMsg(sbpEvt_t *pMsg)
case SBP_UART_CHANGE_EVT:
{
uint8_t valueToCopy[SIMPLEPROFILE_CHAR6_LEN] = {0};
uint8 len = queue_read(valueToCopy, SIMPLEPROFILE_CHAR6_LEN);
uint8_t valueToCopy[UART_BUFFER_SIZE] = {0};
uint8 len = queue_read(valueToCopy, UART_BUFFER_SIZE);
if(len > 0)
{
// SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR6, len, valueToCopy);
IRext_processUartMsg(valueToCopy, len);
}
if(queue_total() > 0)

View File

@@ -0,0 +1,110 @@
/**************************************************************************************
Filename: utils.c
Revised: Date: 2017-02-01
Revision: Revision: 1.0
Description: This file contains utilities for irext sample on CC26XX
Revision log:
* 2017-02-01: created by strawmanbobi
**************************************************************************************/
#include <string.h>
#include <stdlib.h>
#include "utils.h"
static void _itoa(unsigned int uiNum, unsigned char *buf, unsigned char uiRadix);
static void _itoa(unsigned int uiNum, unsigned char *buf, unsigned char uiRadix)
{
unsigned char c, i;
unsigned char *p, rst[32];
p = rst;
for (i = 0; i < 32; i++, p++)
{
/* Isolate a digit */
c = uiNum % uiRadix;
/* Convert to Ascii */
*p = c + ((c < 10) ? '0' : '7');
uiNum /= uiRadix;
if (!uiNum)
break;
}
for (c = 0; c <= i; c++)
{
/* Reverse character order */
*buf++ = *p--;
}
*buf = '\0';
}
unsigned char * _ltoa(unsigned long l, unsigned char *buf, unsigned char radix)
{
#if defined (__TI_COMPILER_VERSION)
return ( (unsigned char*)ltoa( l, (char *)buf ) );
#elif defined( __GNUC__ )
return ( (char*)ltoa( l, buf, radix ) );
#else
unsigned char tmp1[10] = "", tmp2[10] = "", tmp3[10] = "";
unsigned short num1, num2, num3;
unsigned char i;
buf[0] = '\0';
if ( radix == 10 )
{
num1 = l % 10000;
num2 = (l / 10000) % 10000;
num3 = (unsigned short)(l / 100000000);
if (num3) _itoa(num3, tmp3, 10);
if (num2) _itoa(num2, tmp2, 10);
if (num1) _itoa(num1, tmp1, 10);
if (num3)
{
strcpy((char*)buf, (char const*)tmp3);
for (i = 0; i < 4 - strlen((char const*)tmp2); i++)
strcat((char*)buf, "0");
}
strcat((char*)buf, (char const*)tmp2);
if (num3 || num2)
{
for (i = 0; i < 4 - strlen((char const*)tmp1); i++)
strcat((char*)buf, "0");
}
strcat((char*)buf, (char const*)tmp1);
if (!num3 && !num2 && !num1)
strcpy((char*)buf, "0");
}
else if ( radix == 16 )
{
num1 = l & 0x0000FFFF;
num2 = l >> 16;
if (num2) _itoa(num2, tmp2, 16);
if (num1) _itoa(num1, tmp1, 16);
if (num2)
{
strcpy((char*)buf,(char const*)tmp2);
for (i = 0; i < 4 - strlen((char const*)tmp1); i++)
strcat((char*)buf, "0");
}
strcat((char*)buf, (char const*)tmp1);
if (!num2 && !num1)
strcpy((char*)buf, "0");
}
else
return NULL;
return buf;
#endif
}

View File

@@ -0,0 +1,28 @@
/**************************************************************************************
Filename: utils.h
Revised: Date: 2017-02-01
Revision: Revision: 1.0
Description: This file contains utilities for irext sample on CC26XX
Revision log:
* 2017-02-01: created by strawmanbobi
**************************************************************************************/
#ifndef UTILS_H
#define UTILS_H
#ifdef __cplusplus
extern "C"
{
#endif
extern unsigned char * _ltoa(unsigned long l, unsigned char *buf, unsigned char radix);
#ifdef __cplusplus
}
#endif
#endif