uint8_t TM_FFT_Init_F32(TM_FFT_F32_t* FFT, uint16_t FFT_Size, uint8_t use_malloc) { uint8_t i; /* Set to zero */ FFT->FFT_Size = 0; FFT->Count = 0; /* Check for proper pointer value */ for (i = 0; i < 9; i++) { /* Check for proper number */ if (FFT_Size == CFFT_Instances[i].fftLen) { /* Set FFT size */ FFT->FFT_Size = FFT_Size; /* Save proper pointer */ FFT->S = &CFFT_Instances[i]; /* Stop for loop */ break; } } /* Check if fft size valid */ if (FFT->FFT_Size == 0) { /* There is not valid input, return */ return 1; } /* If malloc selected for allocation, use it */ if (use_malloc) { /* Allocate input buffer */ FFT->Input = (float32_t *) LIB_ALLOC_FUNC((FFT->FFT_Size * 2) * sizeof(float32_t)); /* Check for success */ if (FFT->Input == NULL) { return 2; } /* Allocate input buffer */ FFT->Output = (float32_t *) LIB_ALLOC_FUNC(FFT->FFT_Size * sizeof(float32_t)); /* Check for success */ if (FFT->Output == NULL) { /* Deallocate input buffer */ LIB_FREE_FUNC(FFT->Input); /* Return error */ return 3; } /* Malloc used, set flag */ FFT->UseMalloc = 1; } /* Return OK */ return 0; }
TM_DELAY_Timer_t* TM_DELAY_TimerCreate(uint32_t ReloadValue, uint8_t AutoReload, uint8_t StartTimer, void (*TM_DELAY_CustomTimerCallback)(void *), void* UserParameters) { TM_DELAY_Timer_t* tmp; /* Check if available */ if (CustomTimers.Count >= DELAY_MAX_CUSTOM_TIMERS) { return NULL; } /* Try to allocate memory for timer structure */ tmp = (TM_DELAY_Timer_t *) LIB_ALLOC_FUNC(sizeof(TM_DELAY_Timer_t)); /* Check if allocated */ if (tmp == NULL) { return NULL; } /* Fill settings */ tmp->ARR = ReloadValue; tmp->CNT = tmp->ARR; tmp->AutoReload = AutoReload; tmp->Enabled = StartTimer; tmp->Callback = TM_DELAY_CustomTimerCallback; tmp->UserParameters = UserParameters; /* Increase number of timers in memory */ CustomTimers.Timers[CustomTimers.Count++] = tmp; /* Return pointer to user */ return tmp; }
uint8_t BUFFER_Init(BUFFER_t* Buffer, uint32_t Size, uint8_t* BufferPtr) { /* Set buffer values to all zeros */ memset(Buffer, 0, sizeof(BUFFER_t)); /* Set default values */ Buffer->Size = Size; Buffer->Buffer = BufferPtr; Buffer->StringDelimiter = '\n'; /* Check if malloc should be used */ if (!Buffer->Buffer) { /* Try to allocate */ Buffer->Buffer = (uint8_t *) LIB_ALLOC_FUNC(Size * sizeof(uint8_t)); /* Check if allocated */ if (!Buffer->Buffer) { /* Reset size */ Buffer->Size = 0; /* Return error */ return 1; } else { /* Set flag for malloc */ Buffer->Flags |= BUFFER_MALLOC; } } /* We are initialized */ Buffer->Flags |= BUFFER_INITIALIZED; /* Initialized OK */ return 0; }
FRESULT TM_FATFS_Search(char* Folder, char* tmp_buffer, uint16_t tmp_buffer_size, TM_FATFS_Search_t* FindStructure) { uint8_t malloc_used = 0; FRESULT res; /* Reset values first */ FindStructure->FilesCount = 0; FindStructure->FoldersCount = 0; /* Check for buffer */ if (tmp_buffer == NULL) { /* Try to allocate memory */ tmp_buffer = (char *) LIB_ALLOC_FUNC(tmp_buffer_size); /* Check for success */ if (tmp_buffer == NULL) { return FR_NOT_ENOUGH_CORE; } } /* Check if there is a lot of memory allocated */ if (strlen(Folder) < tmp_buffer_size) { /* Reset TMP buffer */ tmp_buffer[0] = 0; /* Format path first */ strcpy(tmp_buffer, Folder); /* Call search function */ res = scan_files(tmp_buffer, tmp_buffer_size, FindStructure); } else { /* Not enough memory */ res = FR_NOT_ENOUGH_CORE; } /* Check for malloc */ if (malloc_used) { LIB_FREE_FUNC(tmp_buffer); } /* Return result */ return res; }