【问题标题】:changing multiple piped values in a variable dynamically in C possible?可以在 C 中动态更改变量中的多个管道值吗?
【发布时间】:2019-08-09 15:37:45
【问题描述】:

我正在想办法改变 SAI 中的活动槽定义 用C语言编写的音频定义块。

#define ACTIVE_TDM_SLOTS 1|2|3|4|5|6|7|8

数字是这个结构中使用的 uint32_t 值,当存在​​时激活微型上的 TDM 音频插槽。

typedef struct{ 
  uint32_t FirstBitOffset;                            
  uint32_t SlotSize;        
  uint32_t SlotNumber;                           
  uint32_t SlotActive;  
}SAI_SlotInitTypeDef;

我正在尝试根据需要激活哪些通道来动态更改 ACTIVE_TDM_SLOTS 的构成。 256 种可能的活动通道组合。 我可以初始化和取消初始化硬件插槽来更改活动插槽的配置。

我假设#define #ifdef/#endef 都是预处理器,所以我需要以某种方式使用变量?

我可以从所需的活动通道为 ACTIVE_TDM_SLOTS 创建一个字符串,但如何将其加载到变量中?我可以使用一组 char *var 并将它们连接到变量中吗?

我不完全确定管道是如何与第一个定义一起工作的!也许只是无法将其加载到变量中?

我的另一个解决方案是在 DMA 流入时过滤活动插槽数据,但激活或停用所需插槽似乎更明智?

如果有用的话,很高兴上传更多代码。

【问题讨论】:

  • 这是在哪里使用的?看起来像按位或,结果将是15?不知道为什么这会有意义...
  • 不应该是#define ACTIVE_TDM_SLOTS ( (1u<<0) | (1u<<1) | (1u<<2)...吗?否则我不知道你想在这里做什么。

标签: c variables pipe definition


【解决方案1】:

好吧,我想我错过了一件显而易见的事情。

SAI_SLOT_NOTACTIVE 0;

我只是将 0 分配给 | uint32_t 变量 |不活跃的。 我在想我必须删除 slotActive 列表中的插槽!

如果这可行,我会回帖,以防让其他尝试的人感到困惑 在 ARM STM32xxx 上动态更改 SAI TDM 音频插槽配置

原定义

     /* SAI_Block_Slot_Active SAI Block Slot Active */
        #define SAI_SLOT_NOTACTIVE           ((uint32_t)0x00000000U)
        #define SAI_SLOTACTIVE_0             ((uint32_t)0x00000001U)
        #define SAI_SLOTACTIVE_1             ((uint32_t)0x00000002U)
        #define SAI_SLOTACTIVE_2             ((uint32_t)0x00000004U)
        #define SAI_SLOTACTIVE_3             ((uint32_t)0x00000008U)
        #define SAI_SLOTACTIVE_4             ((uint32_t)0x00000010U)
        #define SAI_SLOTACTIVE_5             ((uint32_t)0x00000020U)
        #define SAI_SLOTACTIVE_6             ((uint32_t)0x00000040U)
        #define SAI_SLOTACTIVE_7             ((uint32_t)0x00000080U)
        #define SAI_SLOTACTIVE_8             ((uint32_t)0x00000100U)
        #define SAI_SLOTACTIVE_9             ((uint32_t)0x00000200U)
        #define SAI_SLOTACTIVE_10            ((uint32_t)0x00000400U)
        #define SAI_SLOTACTIVE_11            ((uint32_t)0x00000800U)
        #define SAI_SLOTACTIVE_12            ((uint32_t)0x00001000U)
        #define SAI_SLOTACTIVE_13            ((uint32_t)0x00002000U)
        #define SAI_SLOTACTIVE_14            ((uint32_t)0x00004000U)
        #define SAI_SLOTACTIVE_15            ((uint32_t)0x00008000U)
        #define SAI_SLOTACTIVE_ALL           ((uint32_t)0x0000FFFFU)

以 chanel 1 2 3 4 路由到第一个 4 个记录槽的示例和 频道 5 6 7 8 已禁用

频道号更改为使用的插槽数

 /* TDM record slot assign to channel or deactivate any TDMx value 0 to disable slot */ 
        uint32_t TDM1 = SAI_SLOTACTIVE_0; 
        uint32_t TDM2 = SAI_SLOTACTIVE_1;
        uint32_t TDM3 = SAI_SLOTACTIVE_2;
        uint32_t TDM4 = SAI_SLOTACTIVE_3;
        uint32_t TDM5 = SAI_SLOT_NOTACTIVE;
        uint32_t TDM6 = SAI_SLOT_NOTACTIVE;
        uint32_t TDM7 = SAI_SLOT_NOTACTIVE;
        uint32_t TDM8 = SAI_SLOT_NOTACTIVE;

haudio_out_sai.SlotInit.SlotActive = TDM1 | TDM2 | TDM3 | TDM4 | TDM5 | TDM6 | TDM7 | TDM8;

haudio_out_sai.SlotInit.SlotNumber = 4;

【讨论】:

    猜你喜欢
    • 2020-11-26
    • 2018-11-23
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 2022-11-05
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    相关资源
    最近更新 更多