Skip to content

Commit e92330f

Browse files
committed
updated with API details
1 parent 50d21cf commit e92330f

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ The sparkfun_pico library supports the following functions:
108108
### PSRAM detection
109109

110110
> [!NOTE]
111-
> SparkFun RP2350 boards the PSRAM IC detailed [here](https://cdn.sparkfun.com/assets/0/a/3/d/e/APS6404L_3SQR_Datasheet.pdf)
111+
> The SparkFun RP2350 boards the PSRAM IC is detailed [here](https://cdn.sparkfun.com/assets/0/a/3/d/e/APS6404L_3SQR_Datasheet.pdf)
112112
113113
These functions are exported from the file [sfe_psram.h](sparkfun_pico/sfe_psram.h)
114114

115+
#### Setup
116+
115117
```C
116118
size_t sfe_setup_psram(uint32_t psram_cs_pin);
117119
```
@@ -124,6 +126,108 @@ This function is used to detect the presence of PSRAM on the board and return th
124126
125127
Additionally, if PSRAM is detected, it is setup correctly for use by the RP2350.
126128
129+
#### Update Timing
130+
131+
```C
132+
void sfe_psram_update_timing(void);
133+
```
134+
135+
This function is used to update the timing settings used by the pico-sdk to communicate with the PSRAM IC. These values are set during the PSRAM setup process based on the system clock. If the system clock value is changed (overclocking!) calling this method will adjust the PSRAM settings for use with the new clock frequency values.
136+
137+
### Memory Allocation Functions
138+
139+
The following functions are available when using the sparkfun_pico memory allocator with PSRAM. They mimic the standard C memory allocation functions and are defined i n the include file [sfe_pico_alloc.h](sparkfun_pico/sfe_pico_alloc.h)
140+
141+
#### Initialization
142+
143+
```C
144+
bool sfe_pico_alloc_init();
145+
```
146+
147+
The function detect available PSRAM and initializes the allocator. If the system is setup for also using SRAM as part of the wrapping of the built in allocation functions, the available heap is added to the allocator also.
148+
149+
> [!NOTE]
150+
> Calling this function is optional - it is called by default on the first call to a memory allocation function.
151+
152+
#### Memory Allocation
153+
154+
```C
155+
void *sfe_mem_malloc(size_t size);
156+
```
157+
158+
Allocate a block of memory of the requested size.
159+
160+
|Parameter|Description|
161+
|---|---|
162+
|size| The number of bytes to allocate|
163+
|return | void pointer to the allocated memory. NULL if allocation failed|
164+
165+
#### Memory De-allocation
166+
167+
```C
168+
void sfe_mem_free(void *ptr);
169+
```
170+
171+
Free a block of memory.
172+
173+
|Parameter|Description|
174+
|---|---|
175+
|ptr| The pointer to the memory to free|
176+
177+
#### Memory Re-allocation
178+
179+
```C
180+
void *sfe_mem_realloc(void *ptr, size_t size);
181+
```
182+
183+
Re-allocate a block of memory to the given size using the following methodology:
184+
185+
* Expanding or contracting the existing area pointed to by ptr, if possible. The contents of the area remain unchanged up to the lesser of the new and old sizes. If the area is expanded, the contents of the new part of the array are undefined.
186+
* Allocating a new memory block of size size bytes, copying memory area with size equal the lesser of the new and the old sizes, and freeing the old block.
187+
188+
|Parameter|Description|
189+
|---|---|
190+
| ptr | A previously allocated block of memory. If NULL, this methods behaves like standard malloc|
191+
|size| The number of bytes to re-allocate to|
192+
|return | void pointer to the allocated memory. NULL if allocation failed|
193+
194+
#### Memory Allocation and Clear
195+
196+
```C
197+
void *sfe_mem_calloc(size_t num, size_t size);
198+
```
199+
200+
Allocate a block of memory of the requested size and zero/clear it out
201+
202+
|Parameter|Description|
203+
|---|---|
204+
|size| The number of bytes to allocate|
205+
|return | void pointer to the allocated memory. NULL if allocation failed|
206+
207+
#### Maximum Free Block Size
208+
209+
```C
210+
size_t sfe_mem_max_free_size(void);
211+
```
212+
213+
This function returns the maximum free block size available for allocation.
214+
215+
#### Total Memory Pool Size
216+
217+
```C
218+
size_t sfe_mem_size(void);
219+
```
220+
221+
This function returns the total size of the available memory across all memory pools available to the allocator.
222+
223+
#### Total Memory Used
224+
225+
```C
226+
size_t sfe_mem_used(void);
227+
```
228+
229+
This function returns the total size of memory used.
230+
127231
## The Examples
128232
129233
This repository contains the following examples:

0 commit comments

Comments
 (0)