Thread 中讨论的其他器件:SysBios、 SysConfig
/*
* File: led_strip.c
*
* Created on: Aug 8, 2023
* Author:
*/
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
/* POSIX Header files */
#include <semaphore.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
/* Driver Configuration */
#include <ti/common/cc26xx/uartlog/UartLog.h>
#include "ti_drivers_config.h"
#define LED_START_FRAME 0x00000000
#define LED_STOP_FRAME 0xFFFFFFFF
#define LED_DEFAULT 0xE70FC008
#define LED_OFF 0xE7000000
//RGB
#define LED_YELLOW 0x414100E7
#define LED_BLUE 0xE7410000
#define LED_GREEN 0xE7006100
#define LED_RED 0xE7000061
#define LED_STRIP_LEN 5
#define LED_FRAME_SIZE (LED_STRIP_LEN + 2) // 1 - start and 1 -stop frame
static SPI_Handle ledSpiHandle;
static SPI_Params ledSpiParams;
static SPI_Transaction transaction;
static bool isCompleted = false;
void led_strip_flush_ua_flag(void);
void led_strip_off(void);
void spiCb(SPI_Handle handle, SPI_Transaction *transaction);
void spiCb(SPI_Handle handle, SPI_Transaction *transaction)
{
if (transaction->status == SPI_TRANSFER_COMPLETED) {
isCompleted = true;
}
}
void led_strip_init(void)
{
SPI_init();
/* Open SPI as controller (default) */
SPI_Params_init(&ledSpiParams);
ledSpiParams.frameFormat = SPI_POL0_PHA0;
ledSpiParams.mode = SPI_CONTROLLER;
/* See device-specific technical reference manual for supported speeds */
ledSpiParams.bitRate = 4000000;
ledSpiParams.dataSize = 8; // bit
ledSpiParams.transferMode = SPI_MODE_BLOCKING;
// ledSpiParams.transferCallbackFxn = spiCb;
ledSpiHandle = SPI_open(CONFIG_SPI_1, &ledSpiParams);
if (ledSpiHandle == NULL)
{
Log_error0("SPI handle NULL");
while(1) {};
}
}
void led_strip_flush_ua_flag(void)
{
if (ledSpiHandle == NULL)
{
Log_error0("SPI handle NULL");
while(1) {};
}
bool transferOK;
uint32_t strip_data[LED_FRAME_SIZE] = {};
// Fill strip
strip_data[0] = LED_START_FRAME;
for (int i = 1; i <= LED_STRIP_LEN/2; i++)
{
strip_data[i] = LED_YELLOW;
}
for (int i = 3; i <= LED_STRIP_LEN; i++)
{
strip_data[i] = LED_BLUE;
}
strip_data[LED_FRAME_SIZE-1] = LED_STOP_FRAME;
// Init transaction
transaction.count = sizeof(strip_data);
transaction.txBuf = (void *)strip_data;
transaction.rxBuf = (void *)NULL;
transferOK = SPI_transfer(ledSpiHandle, &transaction);
if (!transferOK)
{
while(1) {};
}
}
void led_strip_off(void)
{
if (ledSpiHandle == NULL)
{
Log_error0("SPI handle NULL");
while(1) {};
}
uint32_t strip_data[LED_FRAME_SIZE] = {};
// Fill strip
strip_data[0] = LED_START_FRAME;
for (int i = 1; i <= LED_STRIP_LEN; i++)
{
strip_data[i] = LED_OFF;
}
strip_data[LED_FRAME_SIZE-1] = LED_STOP_FRAME;
// Init transaction
transaction.count = sizeof(strip_data);
transaction.txBuf = (void *)strip_data;
transaction.rxBuf = (void *)NULL;
isCompleted = false;
bool transferOK = SPI_transfer(ledSpiHandle, &transaction);
if (!transferOK)
{
while(1) {};
}
// while (!isCompleted) {
//// Task_sleep(10);
// }
}
/////////////////////////////////////////////////////////////
/// USE CASE when it hangs //////////////////////////////////
/// File cr4.cpp
void periphInit()
{
setPinStates();
buttonInit();
setCmdHandlerCb(cmdHandler);
led_strip_init();
led_strip_off(); // Hang here
sleep(1);
flashTest();
}
extern "C" Task_Handle* createMainTask() {
Task_Params taskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = sMainTaskStack;
taskParams.stackSize = 2048;
taskParams.priority = 1;
Task_construct(&sMainTask, (ti_sysbios_knl_Task_FuncPtr)mainTask, &taskParams, NULL);
sMainTaskHandle = Task_handle(&sMainTask);
return &sMainTaskHandle;
}
/*
* ======== mainThread ========
*/
void mainTask(void *arg0)
{
/* Call driver init functions */
periphInit();
m_ext = Extender::getInstance();
while (1) {
handleExtInputs();
handleButton();
Task_sleep(10);
}
}
大家好! 此类设置存在问题:
CCS Studio 版本:12.6.0.00008
SysConfig:v1.16.2
SimpleLink CC13xx SDK:v7.10.2.23
操作系统:TI-RTOS7
编译器:Clang3.2.1 LTS
定做电路板
使用的硬件:
SPI_1 -由 APA102C LED 驱动器使用(4个串联)。 未使用 POCI 引脚、但 SYSCfg 需要该引脚
SPI_2 -由 SPI 串行闪存使用
使用了以下引脚(在 SYSCFG 工具中):
#define CONFIG_GPIO_SPI_2_SCLK 28
#define CONFIG_GPIO_SPI_2_POCI 14
#define CONFIG_GPIO_SPI_2_PICO 15
#define CONFIG_GPIO_SPI_1_SCLK 6
#define CONFIG_GPIO_SPI_1_POCI 30
#define CONFIG_GPIO_SPI_1_PICO 5
SYSCFG 截图: 

即使在轮询中从 SPI_1进行传输时也会出现问题、这会给我这个故障。 当我将实例 SSI0更改为 SSI1时、一个外设(在这种情况下为 LED)开始工作、但另一个在发送时挂起。 
是否有人举过在任务上下文中使用2个单独实例的例子?