Skip to content
/ cbed Public

Frequently used functions, algorithms, data structures ... in embedded C code.

License

Notifications You must be signed in to change notification settings

jks-liu/cbed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cbed

Frequently used functions, algorithms, data structures ... in embedded C code.

In this repo, below things are taken into consideration.

  1. Embedded MCU often has little memory
  2. Data processed by MCU are often time series, which means data are feed one by one
  3. Embedded data structs are often small, so we use uint8_t as the default type for counter purpose instead of using size_t.
    If uint8_t is too small for you, do not hesitate to copy/paste code and then replace the type to what you need.

Code convertions

  • C99
  • Use jks_, Jks ... as the name space
  • Use uint8_t if possible

Config

Remane default-jks-cbed-config.h as jks-cbed-config.h and then dis/enable configs you (not) wanted.

Counter

Cycle counter

  • Increase: 0, 1, 2, ..., n-1, n, 0, 1, ...
  • Decrease: n, n-1, ..., 3, 2, 1, 0, n, n-1, ...

Saturate counter

  • Increase: 0, 1, 2, ..., n-1, n, n, n, ...
  • Decrease: n, n-1, ..., 3, 2, 1, 0, 0, 0, ...

Ring buffer

Ring buffer is very commonly used. But I do not think it is good to hardcode index updating.

Example:

#define N_BUFFER 55
uint8_t g_buffer[N_BUFFER] = {0};
struct jks_ring_buffer g_ring = {0};
void jks_ring_buffer_init(&g_ring, N_BUFFER);


uint8_t add_to_buffer(uint8_t new_value)
{
    uint8_t eldest_value = g_buffer[g_ring.index];
    g_buffer[g_ring.index] = new_value;
    jks_ring_buffer_update_index(&g_ring);
    return eldest_value;
}

Moving average

Moving standard deviation

About

Frequently used functions, algorithms, data structures ... in embedded C code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages