请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:CC2340R5 工具与软件:
您好!
我有一个基于 basic_ble_LP_EM_CC2340R5_freertos_ticlang 示例(Central)的应用程序。 当我从 UART 接收到命令字符串 AT+SCAN\r\n 时、启动扫描之后、程序将跳转到 iCall_abort?
参考文章:
SDK:simplelink_lowpower_f3_sdk_7_40_00_64
我的代码
/*
* ======== callbackFxn ========
*/
void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
if (status != UART2_STATUS_SUCCESS)
{
/* RX error occured in UART2_read() */
while (1) {}
}
numBytesRead = count;
if(scan_state == 0)
sem_post(&sem);
}
/*
* ======== start_scan ========
*/
void start_scan(void)
{
bStatus_t status;
const BLEAppUtil_ScanStart_t centralScanStartParams =
{
/*! Zero for continuously scanning */
.scanPeriod = DEFAULT_SCAN_PERIOD, /* Units of 1.28sec */
/*! Scan Duration shall be greater than to scan interval,*/
/*! Zero continuously scanning. */
.scanDuration = DEFAULT_SCAN_DURATION, /* Units of 10ms */
/*! If non-zero, the list of advertising reports will be */
/*! generated and come with @ref GAP_EVT_SCAN_DISABLED. */
.maxNumReport = APP_MAX_NUM_OF_ADV_REPORTS
};
status = BLEAppUtil_scanStart(¢ralScanStartParams);
if(status == FAILURE)
{
while(1){}
}
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
char input;
const char echoPrompt[] = "Echoing characters:\r\n";
UART2_Handle uart;
UART2_Params uartParams;
int32_t semStatus;
uint32_t status = UART2_STATUS_SUCCESS;
/* Call driver init functions */
GPIO_init();
/* Configure the LED pin */
//GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Create semaphore */
semStatus = sem_init(&sem, 0, 0);
if (semStatus != 0)
{
/* Error creating semaphore */
while (1) {}
}
/* Create a UART in CALLBACK read mode */
UART2_Params_init(&uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.readCallback = callbackFxn;
uartParams.baudRate = 115200;
uart = UART2_open(CONFIG_DISPLAY_UART, &uartParams);
if (uart == NULL)
{
/* UART2_open() failed */
while (1) {}
}
/* Turn on user LED to indicate successful initialization */
//GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
/* Pass NULL for bytesWritten since it's not used in this example */
UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);
/* Loop forever echoing */
while (1)
{
switch(scan_state)
{
case 0:
numBytesRead = 0;
/* Pass NULL for bytesRead since it's not used in this example */
status = UART2_read(uart, &input, 1, NULL);
if (status != UART2_STATUS_SUCCESS)
{
/* UART2_read() failed */
while (1) {}
}
/* Do not write until read callback executes */
sem_wait(&sem);
if (numBytesRead > 0)
{
ch_buffer[ch_cnt++] = (uint8_t)input;
if(strstr((const char *)ch_buffer,(const char *)"\r\n" ) != 0)
{
if(strcmp((const char *)ch_buffer,(const char *)"AT+SCAN\r\n") == 0 )
{
scan_state = 1;
status = UART2_write(uart, (const char *)"Msg:success:", strlen((const char *)"Msg:success:"), NULL);
}
else{
status = UART2_write(uart, (const char *)"ack:", strlen((const char *)"ack:"), NULL);
}
status = UART2_write(uart, (const char *)ch_buffer, strlen((const char *)ch_buffer), NULL);
if (status != UART2_STATUS_SUCCESS)
{
/* UART2_write() failed */
while (1) {}
}
void *ptr = (void *)ch_buffer;
memset(ptr,0,100);
ch_cnt = 0;
}
}
break;
case 1:
start_scan();
scan_state = 2;
break;
}
}
}
ICall 中断
/**
* Aborts.
*
* This is preferred over C runtime abort() function,
* in an external image since the C runtime abort() is only
* guaranteed in a root image which contains the C runtime
* entry function that is executed upon startup.
*/
ICall_Errno
ICall_abort(void)
{
#ifdef HALNODEBUG
#elif defined(EXT_HAL_ASSERT)
HAL_ASSERT(HAL_ASSERT_CAUSE_ICALL_ABORT);
#else
{
volatile uint8_t j=1;
while(j);
}
#endif /* EXT_HAL_ASSERT */
ICALL_HOOK_ABORT_FUNC();
return(ICALL_ERRNO_SUCCESS);
}