标签:lag length ret kde 编译 允许 文件 queue 存储
1 在块中使用static修饰变量
#include <stdio.h>
void trystat(void);
int main(void)
{
int count;
for (count = 1; count <= 3; count++)
{
printf("Here comes iteration %d:\n", count);
trystat();
}
return 0;
}
void trystat(void)
{
int fade = 1;
static int stay = 1;
printf("fade = %d and stay = %d\n", fade++, stay++);
}
程序执行结果:
Here comes iteration 1:
fade = 1 and stay = 1
Here comes iteration 2:
fade = 1 and stay = 2
Here comes iteration 3:
fade = 1 and stay = 3
(1) 这里变量stay
,它从程序加载时开始存在,直到程序终止。但是它的范围仅限于trystat()
函数块。只有当这个函数执行时,程序才能使用stay
访问它指定的对象.
(2) 变量stay
记得它的值增加了1,但是变量fade每次都会重新开始。这指出了初始化的不同之处:fade
在trystat()
每次调用都从新初始化,而stay
变量只初始化一次。
(3) 静态变量在程序加载到内存之后就已经就位了。将语句static int stay = 1;
放在trystat()函数中告诉编译器,只允许trystat()
函数查看变量;它不是在运行时执行的语句。
2 在任何函数外部使用static修饰变量
static BOOL wavTaskCreated = FALSE;
static QueueHandle_t wav_msg_queue = NULL;
static WAV_PLAY_QUEUE_t wavPlayQueue;
static bool wav_get_version_flag = false;
static char wav_version[32];
static uint8_t *Wav_GetFileName(WAV_TYPE_t wav_type)
{
}
static bool Wav_GetFileInfo(WAV_FILE_INFO_t *pFileInfo, uint8_t *pFileName)
{
}
static bool Wav_GetVersion_Internal(WAV_FILE_INFO_t *pFileInfo)
{
}
static bool Wav_ReadFile(uint8_t *pData, uint32_t offset, uint32_t size)
{
}
static bool Wav_SendToDA(uint8_t *pFile, uint32_t size, uint32_t volume)
{
}
static BOOL Wav_Put_Queue(WAV_TYPE_t wav_type, BOOL fromISR)
{
}
static BOOL Wav_Get_Queue(WAV_TYPE_t *pWavType)
{
}
static bool Wav_Play_Inernal(WAV_TYPE_t wav_type)
{
}
void Wav_Init(void)
{
DA_Init(16000);
if (!wavTaskCreated)
{
wavTaskCreated = TRUE;
xTaskCreate(wav_task, "WAV", STACK_SIZE_TASK_WAV, NULL, PRIORITY_TASK_WAV, NULL);
wav_msg_queue = xQueueCreate(WAV_MSG_QUEUE_LENGTH, sizeof(WAV_MESSAGE_t));
wavPlayQueue.pWavTypeTable = malloc(WAV_PALY_QUEUE_MAX * sizeof(WAV_TYPE_t));
}
wavPlayQueue.front = 0;
wavPlayQueue.end = 0;
wavPlayQueue.sizeNow = 0;
wavPlayQueue.totalSize = WAV_PALY_QUEUE_MAX;
}
bool Wav_Play(WAV_TYPE_t wav_type, bool force)
{
if (!wavTaskCreated)
{
return false;
}
if (force)
{
vPortEnterCritical();
watchdog_feed();
Wav_Play_Inernal(wav_type);
vPortExitCritical();
return true;
}
bool rv = Wav_Put_Queue(wav_type, false);
vTaskDelay(30);
return rv;
}
上述为某平台使用DA播放wav的程序片段,
static uint8_t *Wav_GetFileName(WAV_TYPE_t wav_type);
static bool Wav_GetFileInfo(WAV_FILE_INFO_t *pFileInfo, uint8_t *pFileName);
static bool Wav_GetVersion_Internal(WAV_FILE_INFO_t *pFileInfo);
static bool Wav_ReadFile(uint8_t *pData, uint32_t offset, uint32_t size);
static bool Wav_SendToDA(uint8_t *pFile, uint32_t size, uint32_t volume);
static BOOL Wav_Put_Queue(WAV_TYPE_t wav_type, BOOL fromISR);
static BOOL Wav_Get_Queue(WAV_TYPE_t *pWavType);
static bool Wav_Play_Inernal(WAV_TYPE_t wav_type);
上述函数为内部函数使用static
修饰。
void Wav_Init(void);
bool Wav_Play(WAV_TYPE_t wav_type, bool force);
上述两个函数为模块接口(初始化DA和播放wav功能)供外部调用,没有使用static修饰。
标签:lag length ret kde 编译 允许 文件 queue 存储
原文地址:https://www.cnblogs.com/sky1blue/p/11260164.html