function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
can_decode_ot
|
int8_t can_decode_ot(const uint8_t object_type)
{
switch (object_type)
{
case LC:
return 0;
case MAIN:
#ifdef MAIN_DEC
return 0;
#else
return -1;
#endif
case SSR:
#ifdef SSR_DEC
return 0;
#else
return -1;
#endif
case LTP:
#ifdef LTP_DEC
return 0;
#else
return -1;
#endif
/* ER object types */
#ifdef ERROR_RESILIENCE
case ER_LC:
#ifdef DRM
case DRM_ER_LC:
#endif
return 0;
case ER_LTP:
#ifdef LTP_DEC
return 0;
#else
return -1;
#endif
case LD:
#ifdef LD_DEC
return 0;
#else
return -1;
#endif
#endif
}
return -1;
}
|
/* Returns 0 if an object type is decodable, otherwise returns -1 */
|
Returns 0 if an object type is decodable, otherwise returns -1
|
faad_free
|
void faad_free(void *b)
{
#if 0 // defined(_WIN32) && !defined(_WIN32_WCE)
_aligned_free(b);
#else
free(b);
}
|
/* common free function */
|
common free function
|
ne_rng
|
uint32_t ne_rng(uint32_t *__r1, uint32_t *__r2)
{
uint32_t t1, t2, t3, t4;
t3 = t1 = *__r1; t4 = t2 = *__r2; // Parity calculation is done via table lookup, this is also available
t1 &= 0xF5; t2 >>= 25; // on CPUs without parity, can be implemented in C and avoid unpredictable
t1 = Parity [t1]; t2 &= 0x63; // jumps and slow rotate through the carry flag operations.
t1 <<= 31; t2 = Parity [t2];
return (*__r1 = (t3 >> 1) | t1 ) ^ (*__r2 = (t4 + t4) | t2 );
}
|
/*
* This is a simple random number generator with good quality for audio purposes.
* It consists of two polycounters with opposite rotation direction and different
* periods. The periods are coprime, so the total period is the product of both.
*
* -------------------------------------------------------------------------------------------------
* +-> |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0|
* | -------------------------------------------------------------------------------------------------
* | | | | | | |
* | +--+--+--+-XOR-+--------+
* | |
* +--------------------------------------------------------------------------------------+
*
* -------------------------------------------------------------------------------------------------
* |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| <-+
* ------------------------------------------------------------------------------------------------- |
* | | | | |
* +--+----XOR----+--+ |
* | |
* +----------------------------------------------------------------------------------------+
*
*
* The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481,
* which gives a period of 18.410.713.077.675.721.215. The result is the
* XORed values of both generators.
*/
|
This is a simple random number generator with good quality for audio purposes. It consists of two polycounters with opposite rotation direction and different periods. The periods are coprime, so the total period is the product of both.
------------------------------------------------------------------------------------------------- +-> |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| | ------------------------------------------------------------------------------------------------- | | | | | | | | +--+--+--+-XOR-+--------+ | | +--------------------------------------------------------------------------------------+
------------------------------------------------------------------------------------------------- |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| <-+ ------------------------------------------------------------------------------------------------- | | | | | | +--+----XOR----+--+ | | | +----------------------------------------------------------------------------------------+
The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481, which gives a period of 18.410.713.077.675.721.215. The result is the XORed values of both generators.
|
wl_min_lzc
|
uint32_t wl_min_lzc(uint32_t x)
{
#if 1
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return (ones32(x));
#else
uint32_t count = 0;
while (x >>= 1)
count++;
return (count + 1);
#endif
}
|
/* returns position of first bit that is not 0 from msb,
* starting count at lsb */
|
returns position of first bit that is not 0 from msb, starting count at lsb
|
delta_clip
|
static int8_t delta_clip(int8_t i, int8_t min, int8_t max)
{
if (i < min)
return min;
else if (i > max)
return max;
else
return i;
}
|
/* limits the value i to the range [min,max] */
|
limits the value i to the range [min,max]
|
ps_sqrt
|
static real_t ps_sqrt(real_t value)
{
real_t root = 0;
step( 0); step( 2); step( 4); step( 6);
step( 8); step(10); step(12); step(14);
step(16); step(18); step(20); step(22);
step(24); step(26); step(28); step(30);
if (root < value)
++root;
root <<= (REAL_BITS/2);
return root;
}
|
/* fixed point square root approximation */
|
fixed point square root approximation
|
is_ltp_ot
|
uint8_t is_ltp_ot(uint8_t object_type)
{
#ifdef LTP_DEC
if ((object_type == LTP)
#ifdef ERROR_RESILIENCE
|| (object_type == ER_LTP)
#endif
#ifdef LD_DEC
|| (object_type == LD)
#endif
)
{
return 1;
}
#endif
return 0;
}
|
/* check if the object type is an object type that can have LTP */
|
check if the object type is an object type that can have LTP
|
sbr_log2
|
static int8_t sbr_log2(const int8_t val)
{
int8_t log2tab[] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 4 };
if (val < 10 && val >= 0)
return log2tab[val];
else
return 0;
}
|
/* integer log[2](x): input range [0,10) */
|
integer log[2](x): input range [0,10)
|
NeAACDecAudioSpecificConfig
|
char NEAACDECAPI NeAACDecAudioSpecificConfig(unsigned char *pBuffer,
unsigned long buffer_size,
mp4AudioSpecificConfig *mp4ASC)
{
return AudioSpecificConfig2(pBuffer, buffer_size, mp4ASC, NULL, 0);
}
|
/* Table 1.6.1 */
|
Table 1.6.1
|
huff_dec
|
static int8_t huff_dec(bitfile *ld, drm_ps_huff_tab huff)
{
uint8_t bit;
int16_t index = 0;
while (index >= 0)
{
bit = (uint8_t)faad_get1bit(ld);
index = huff[index][bit];
}
return index + 15;
}
|
/* binary search huffman decoding */
|
binary search huffman decoding
|
huff_data
|
static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par,
ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par)
{
uint8_t n;
if (dt)
{
/* coded in time direction */
for (n = 0; n < nr_par; n++)
{
par[n] = ps_huff_dec(ld, t_huff);
}
} else {
/* coded in frequency direction */
par[0] = ps_huff_dec(ld, f_huff);
for (n = 1; n < nr_par; n++)
{
par[n] = ps_huff_dec(ld, f_huff);
}
}
}
|
/* read huffman data coded in either the frequency or the time direction */
|
read huffman data coded in either the frequency or the time direction
|
ps_huff_dec
|
static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff)
{
uint8_t bit;
int16_t index = 0;
while (index >= 0)
{
bit = (uint8_t)faad_get1bit(ld);
index = t_huff[index][bit];
}
return index + 31;
}
|
/* binary search huffman decoding */
|
binary search huffman decoding
|
error
|
static enum mad_flow error(void *data, struct mad_stream *stream, struct mad_frame *frame) {
printf("dec err 0x%04x (%s)\n", stream->error, mad_stream_errorstr(stream));
return MAD_FLOW_CONTINUE;
}
|
/*Routine to print out an error*/
|
Routine to print out an error
|
set_dac_sample_rate
|
void set_dac_sample_rate(int rate)
{
if(rate == prevRate)
return;
prevRate = rate;
mad_buffer_fmt.sample_rate = rate;
}
|
/* Called by the NXP modifications of libmad. Sets the needed output sample rate. */
|
Called by the NXP modifications of libmad. Sets the needed output sample rate.
|
render_sample_block
|
void render_sample_block(short *sample_buff_ch0, short *sample_buff_ch1, int num_samples, unsigned int num_channels)
{
uint32_t len = num_samples * sizeof(short) * num_channels;
render_samples((char*) sample_buff_ch0, len, &mad_buffer_fmt);
return;
}
|
/* render callback for the libmad synth */
|
render callback for the libmad synth
|
stream_read
|
void stream_read(stream_t *stream, size_t size, void *buf)
{
buf_read(buf, size, 1, stream->buf);
}
|
/* A normal read without any byte-swapping */
|
A normal read without any byte-swapping
|
stream_create
|
void stream_create(stream_t *stream,buffer_t *buf)
{
stream->buf = buf;
stream->eof=0;
}
|
/*
void stream_create(stream_t *stream,struct codec_api* ci)
{
stream->ci=ci;
stream->eof=0;
}
*/
|
void stream_create(stream_t *stream,struct codec_api* ci) { stream->ci=ci; stream->eof=0; }
|
m4a_check_sample_offset
|
int m4a_check_sample_offset(demux_res_t *demux_res, uint32_t frame, uint32_t *start)
{
uint32_t i = *start;
for (i=0; i<demux_res->num_lookup_table; ++i)
{
if (demux_res->lookup_table[i].sample > frame ||
demux_res->lookup_table[i].offset == 0)
return -1;
if (demux_res->lookup_table[i].sample == frame)
break;
}
*start = i;
return demux_res->lookup_table[i].offset;
}
|
/* Check if there is a dedicated byte position contained for the given frame.
* Return this byte position in case of success or return -1. This allows to
* skip empty samples.
* During standard playback the search result (index i) will always increase.
* Therefor we save this index and let the caller set this value again as start
* index when calling m4a_check_sample_offset() for the next frame. This
* reduces the overall loop count significantly. */
|
Check if there is a dedicated byte position contained for the given frame. Return this byte position in case of success or return -1. This allows to skip empty samples. During standard playback the search result (index i) will always increase. Therefor we save this index and let the caller set this value again as start index when calling m4a_check_sample_offset() for the next frame. This reduces the overall loop count significantly.
|
gather_offset
|
static void gather_offset(demux_res_t *demux_res, uint32_t *frame, uint32_t *offset)
{
uint32_t i = 0;
for (i=0; i<demux_res->num_lookup_table; ++i)
{
if (demux_res->lookup_table[i].offset == 0)
break;
if (demux_res->lookup_table[i].sample > *frame)
break;
}
i = (i>0) ? i-1 : 0; /* We want the last chunk _before_ *frame. */
*frame = demux_res->lookup_table[i].sample;
*offset = demux_res->lookup_table[i].offset;
}
|
/* Find the exact or preceding frame in lookup_table[]. Return both frame
* and byte position of this match. */
|
Find the exact or preceding frame in lookup_table[]. Return both frame and byte position of this match.
|
buf_create
|
buffer_t *buf_create(size_t len)
{
buffer_t* buf = calloc(1, sizeof(buffer_t));
buf->len = len;
buf->base = calloc(len, sizeof(uint8_t));
if(buf->base == NULL) {
ESP_LOGE(TAG, "couldn't allocate buffer of size %d", len);
return NULL;
}
buf->read_pos = buf->base;
buf->fill_pos = buf->base;
buf->bytes_consumed = 0;
return buf;
}
|
/* creates a buffer struct and its storage on the heap */
|
creates a buffer struct and its storage on the heap
|
buf_free_capacity
|
size_t buf_free_capacity(buffer_t *buf)
{
if(buf == NULL) return -1;
size_t unused_capacity = (buf->base + buf->len) - buf->fill_pos;
return buf_data_stale(buf) + unused_capacity;
}
|
/* available unused capacity */
|
available unused capacity
|
buf_data_total
|
size_t buf_data_total(buffer_t *buf)
{
if(buf == NULL) return -1;
return buf->fill_pos - buf->base;
}
|
/* amount of bytes unread */
|
amount of bytes unread
|
buf_data_unread
|
size_t buf_data_unread(buffer_t *buf)
{
if(buf == NULL) return -1;
return buf->fill_pos - buf->read_pos;
}
|
/* amount of bytes unread */
|
amount of bytes unread
|
gpio_isr_handler
|
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
uint32_t gpio_num = (uint32_t) arg;
xQueueSendToBackFromISR(gpio_evt_queue, &gpio_num, &xHigherPriorityTaskWoken);
if(xHigherPriorityTaskWoken) {
portYIELD_FROM_ISR();
}
}
|
/* gpio event handler */
|
gpio event handler
|
spiRamFifoInit
|
int spiRamFifoInit() {
fifoRpos=0;
fifoWpos=0;
fifoFill=0;
fifoOvfCnt=0;
fifoUdrCnt=0;
vSemaphoreCreateBinary(semCanRead);
vSemaphoreCreateBinary(semCanWrite);
mux=xSemaphoreCreateMutex();
spiRamInit();
return (spiRamTest());
}
|
/*Initialize the FIFO*/
|
Initialize the FIFO
|
spiRamFifoRead
|
void spiRamFifoRead(char *buff, int len) {
int n;
while (len > 0) {
n = len;
if (n>SPIREADSIZE) n=SPIREADSIZE; //don't read more than SPIREADSIZE
if (n>(SPIRAMSIZE-fifoRpos)) n = SPIRAMSIZE - fifoRpos; //don't read past end of buffer
xSemaphoreTake(mux, portMAX_DELAY);
if (fifoFill < n) {
// printf("FIFO empty.\n");
//Drat, not enough data in FIFO. Wait till there's some written and try again.
fifoUdrCnt++;
xSemaphoreGive(mux);
if (fifoFill < FIFO_LOWMARK) xSemaphoreTake(semCanRead, portMAX_DELAY);
} else {
//Read the data.
spiRamRead(fifoRpos, buff, n);
buff += n;
len -= n;
fifoFill -= n;
fifoRpos += n;
if (fifoRpos>=SPIRAMSIZE) fifoRpos=0;
xSemaphoreGive(mux);
xSemaphoreGive(semCanWrite); //Indicate writer thread there's some free room in the fifo
}
}
}
|
/*Read bytes from the FIFO*/
|
Read bytes from the FIFO
|
spiRamFifoWrite
|
void spiRamFifoWrite(const char *buff, int buffLen) {
int n;
while (buffLen > 0) {
n = buffLen;
// don't read more than SPIREADSIZE
if (n > SPIREADSIZE) n = SPIREADSIZE;
// don't read past end of buffer
if (n > (SPIRAMSIZE - fifoWpos)) {
n = SPIRAMSIZE - fifoWpos;
}
xSemaphoreTake(mux, portMAX_DELAY);
if ((SPIRAMSIZE - fifoFill) < n) {
// printf("FIFO full.\n");
// Drat, not enough free room in FIFO. Wait till there's some read and try again.
fifoOvfCnt++;
xSemaphoreGive(mux);
xSemaphoreTake(semCanWrite, portMAX_DELAY);
taskYIELD();
} else {
// Write the data.
spiRamWrite(fifoWpos, buff, n);
buff += n;
buffLen -= n;
fifoFill += n;
fifoWpos += n;
if (fifoWpos >= SPIRAMSIZE) fifoWpos = 0;
xSemaphoreGive(mux);
xSemaphoreGive(semCanRead); // Tell reader thread there's some data in the fifo.
}
}
}
|
/*Write bytes to the FIFO*/
|
Write bytes to the FIFO
|
spiRamFifoFill
|
int spiRamFifoFill() {
int ret;
xSemaphoreTake(mux, portMAX_DELAY);
ret=fifoFill;
xSemaphoreGive(mux);
return ret;
}
|
/*Get amount of bytes in use*/
|
Get amount of bytes in use
|
mad_header_init
|
void mad_header_init(struct mad_header *header)
{
header->layer = 0;
header->mode = 0;
header->mode_extension = 0;
header->emphasis = 0;
header->bitrate = 0;
header->samplerate = 0;
header->crc_check = 0;
header->crc_target = 0;
header->flags = 0;
header->private_bits = 0;
header->duration = mad_timer_zero;
}
|
/*
* NAME: header->init()
* DESCRIPTION: initialize header struct
*/
|
NAME: header->init() DESCRIPTION: initialize header struct
|
mad_frame_init
|
void mad_frame_init(struct mad_frame *frame)
{
mad_header_init(&frame->header);
frame->options = 0;
frame->overlap = 0;
mad_frame_mute(frame);
}
|
/*
* NAME: frame->init()
* DESCRIPTION: initialize frame struct
*/
|
NAME: frame->init() DESCRIPTION: initialize frame struct
|
mad_frame_finish
|
void mad_frame_finish(struct mad_frame *frame)
{
mad_header_finish(&frame->header);
if (frame->overlap) {
// free(frame->overlap);
frame->overlap = 0;
}
}
|
/*
* NAME: frame->finish()
* DESCRIPTION: deallocate any dynamic memory associated with frame
*/
|
NAME: frame->finish() DESCRIPTION: deallocate any dynamic memory associated with frame
|
unalChar
|
char unalChar(const char *adr) {
int *p=(int *)((int)adr&0xfffffffc);
int v=*p;
int w=((int)adr&3);
if (w==0) return ((v>>0)&0xff);
if (w==1) return ((v>>8)&0xff);
if (w==2) return ((v>>16)&0xff);
if (w==3) return ((v>>24)&0xff);
}
|
/* #include "esp_common.h"*/
|
#include "esp_common.h"
|
mad_timer_compare
|
int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
{
signed long diff;
diff = timer1.seconds - timer2.seconds;
if (diff < 0)
return -1;
else if (diff > 0)
return +1;
diff = timer1.fraction - timer2.fraction;
if (diff < 0)
return -1;
else if (diff > 0)
return +1;
return 0;
}
|
/*
* NAME: timer->compare()
* DESCRIPTION: indicate relative order of two timers
*/
|
NAME: timer->compare() DESCRIPTION: indicate relative order of two timers
|
mad_timer_negate
|
void mad_timer_negate(mad_timer_t *timer)
{
timer->seconds = -timer->seconds;
if (timer->fraction) {
timer->seconds -= 1;
timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction;
}
}
|
/*
* NAME: timer->negate()
* DESCRIPTION: invert the sign of a timer
*/
|
NAME: timer->negate() DESCRIPTION: invert the sign of a timer
|
mad_timer_abs
|
mad_timer_t mad_timer_abs(mad_timer_t timer)
{
if (timer.seconds < 0)
mad_timer_negate(&timer);
return timer;
}
|
/*
* NAME: timer->abs()
* DESCRIPTION: return the absolute value of a timer
*/
|
NAME: timer->abs() DESCRIPTION: return the absolute value of a timer
|
reduce_timer
|
void reduce_timer(mad_timer_t *timer)
{
timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION;
timer->fraction %= MAD_TIMER_RESOLUTION;
}
|
/*
* NAME: reduce_timer()
* DESCRIPTION: carry timer fraction into seconds
*/
|
NAME: reduce_timer() DESCRIPTION: carry timer fraction into seconds
|
gcd
|
unsigned long gcd(unsigned long num1, unsigned long num2)
{
unsigned long tmp;
while (num2) {
tmp = num2;
num2 = num1 % num2;
num1 = tmp;
}
return num1;
}
|
/*
* NAME: gcd()
* DESCRIPTION: compute greatest common denominator
*/
|
NAME: gcd() DESCRIPTION: compute greatest common denominator
|
reduce_rational
|
void reduce_rational(unsigned long *numer, unsigned long *denom)
{
unsigned long factor;
factor = gcd(*numer, *denom);
//assert(factor != 0);
*numer /= factor;
*denom /= factor;
}
|
/*
* NAME: reduce_rational()
* DESCRIPTION: convert rational expression to lowest terms
*/
|
NAME: reduce_rational() DESCRIPTION: convert rational expression to lowest terms
|
scale_rational
|
unsigned long scale_rational(unsigned long numer, unsigned long denom,
unsigned long scale)
{
reduce_rational(&numer, &denom);
reduce_rational(&scale, &denom);
//assert(denom != 0);
if (denom < scale)
return numer * (scale / denom) + numer * (scale % denom) / denom;
if (denom < numer)
return scale * (numer / denom) + scale * (numer % denom) / denom;
return numer * scale / denom;
}
|
/*
* NAME: scale_rational()
* DESCRIPTION: solve numer/denom == ?/scale avoiding overflowing
*/
|
NAME: scale_rational() DESCRIPTION: solve numer/denom == ?/scale avoiding overflowing
|
mad_timer_add
|
void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
{
timer->seconds += incr.seconds;
timer->fraction += incr.fraction;
if (timer->fraction >= MAD_TIMER_RESOLUTION)
reduce_timer(timer);
}
|
/*
* NAME: timer->add()
* DESCRIPTION: add one timer to another
*/
|
NAME: timer->add() DESCRIPTION: add one timer to another
|
mad_timer_multiply
|
void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
{
mad_timer_t addend;
unsigned long factor;
factor = scalar;
if (scalar < 0) {
factor = -scalar;
mad_timer_negate(timer);
}
addend = *timer;
*timer = mad_timer_zero;
while (factor) {
if (factor & 1)
mad_timer_add(timer, addend);
mad_timer_add(&addend, addend);
factor >>= 1;
}
}
|
/*
* NAME: timer->multiply()
* DESCRIPTION: multiply a timer by a scalar value
*/
|
NAME: timer->multiply() DESCRIPTION: multiply a timer by a scalar value
|
mad_timer_fraction
|
unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom)
{
timer = mad_timer_abs(timer);
switch (denom) {
case 0:
return timer.fraction ?
MAD_TIMER_RESOLUTION / timer.fraction : MAD_TIMER_RESOLUTION + 1;
case MAD_TIMER_RESOLUTION:
return timer.fraction;
default:
return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, denom);
}
}
|
/*
* NAME: timer->fraction()
* DESCRIPTION: return fractional part of timer in arbitrary terms
*/
|
NAME: timer->fraction() DESCRIPTION: return fractional part of timer in arbitrary terms
|
mad_decoder_run
|
int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
{
int result;
int (*run)(struct mad_decoder *) = 0;
static struct sync_t decsync; //statically-allocated decoder obj
switch (decoder->mode = mode) {
case MAD_DECODER_MODE_SYNC:
run = run_sync;
break;
case MAD_DECODER_MODE_ASYNC:
# if defined(USE_ASYNC)
run = run_async;
# endif
break;
}
if (run == 0)
return -1;
// decoder->sync = malloc(sizeof(*decoder->sync));
decoder->sync=&decsync;
if (decoder->sync == 0)
return -1;
result = run(decoder);
// free(decoder->sync);
// decoder->sync = 0;
return result;
}
|
/*
* NAME: decoder->run()
* DESCRIPTION: run the decoder thread either synchronously or asynchronously
*/
|
NAME: decoder->run() DESCRIPTION: run the decoder thread either synchronously or asynchronously
|
mad_decoder_message
|
int mad_decoder_message(struct mad_decoder *decoder,
void *message, unsigned int *len)
{
# if defined(USE_ASYNC)
if (decoder->mode != MAD_DECODER_MODE_ASYNC ||
send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE ||
receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE)
return -1;
return 0;
# else
return -1;
# endif
}
|
/*
* NAME: decoder->message()
* DESCRIPTION: send a message to and receive a reply from the decoder process
*/
|
NAME: decoder->message() DESCRIPTION: send a message to and receive a reply from the decoder process
|
mad_stream_init
|
void mad_stream_init(struct mad_stream *stream)
{
stream->buffer = 0;
stream->bufend = 0;
stream->skiplen = 0;
stream->sync = 0;
stream->freerate = 0;
stream->this_frame = 0;
stream->next_frame = 0;
mad_bit_init(&stream->ptr, 0);
mad_bit_init(&stream->anc_ptr, 0);
stream->anc_bitlen = 0;
stream->main_data = 0;
stream->md_len = 0;
stream->options = 0;
stream->error = MAD_ERROR_NONE;
}
|
/*
* NAME: stream->init()
* DESCRIPTION: initialize stream struct
*/
|
NAME: stream->init() DESCRIPTION: initialize stream struct
|
mad_stream_finish
|
void mad_stream_finish(struct mad_stream *stream)
{
if (stream->main_data) {
// free(stream->main_data);
stream->main_data = 0;
}
mad_bit_finish(&stream->anc_ptr);
mad_bit_finish(&stream->ptr);
}
|
/*
* NAME: stream->finish()
* DESCRIPTION: deallocate any dynamic memory associated with stream
*/
|
NAME: stream->finish() DESCRIPTION: deallocate any dynamic memory associated with stream
|
mad_stream_buffer
|
void mad_stream_buffer(struct mad_stream *stream,
unsigned char const *buffer, unsigned long length)
{
stream->buffer = buffer;
stream->bufend = buffer + length;
stream->this_frame = buffer;
stream->next_frame = buffer;
stream->sync = 1;
mad_bit_init(&stream->ptr, buffer);
}
|
/*
* NAME: stream->buffer()
* DESCRIPTION: set stream buffer pointers
*/
|
NAME: stream->buffer() DESCRIPTION: set stream buffer pointers
|
mad_stream_skip
|
void mad_stream_skip(struct mad_stream *stream, unsigned long length)
{
stream->skiplen += length;
}
|
/*
* NAME: stream->skip()
* DESCRIPTION: arrange to skip bytes before the next frame
*/
|
NAME: stream->skip() DESCRIPTION: arrange to skip bytes before the next frame
|
mad_stream_sync
|
int mad_stream_sync(struct mad_stream *stream)
{
register unsigned char const *ptr, *end;
ptr = mad_bit_nextbyte(&stream->ptr);
end = stream->bufend;
while (ptr < end - 1 &&
!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
++ptr;
if (end - ptr < MAD_BUFFER_GUARD)
return -1;
mad_bit_init(&stream->ptr, ptr);
return 0;
}
|
/*
* NAME: stream->sync()
* DESCRIPTION: locate the next stream sync word
*/
|
NAME: stream->sync() DESCRIPTION: locate the next stream sync word
|
mad_f_abs
|
mad_fixed_t mad_f_abs(mad_fixed_t x)
{
return x < 0 ? -x : x;
}
|
/*
* NAME: fixed->abs()
* DESCRIPTION: return absolute value of a fixed-point number
*/
|
NAME: fixed->abs() DESCRIPTION: return absolute value of a fixed-point number
|
mad_bit_init
|
void mad_bit_init(struct mad_bitptr *bitptr, unsigned char const *byte)
{
bitptr->byte = byte;
bitptr->cache = 0;
bitptr->left = CHAR_BIT;
}
|
/*
* NAME: bit->init()
* DESCRIPTION: initialize bit pointer struct
*/
|
NAME: bit->init() DESCRIPTION: initialize bit pointer struct
|
mad_bit_length
|
unsigned int mad_bit_length(struct mad_bitptr const *begin,
struct mad_bitptr const *end)
{
return begin->left +
CHAR_BIT * (end->byte - (begin->byte + 1)) + (CHAR_BIT - end->left);
}
|
/*
* NAME: bit->length()
* DESCRIPTION: return number of bits between start and end points
*/
|
NAME: bit->length() DESCRIPTION: return number of bits between start and end points
|
mad_bit_nextbyte
|
unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *bitptr)
{
return bitptr->left == CHAR_BIT ? bitptr->byte : bitptr->byte + 1;
}
|
/*
* NAME: bit->nextbyte()
* DESCRIPTION: return pointer to next unprocessed byte
*/
|
NAME: bit->nextbyte() DESCRIPTION: return pointer to next unprocessed byte
|
mad_bit_skip
|
void mad_bit_skip(struct mad_bitptr *bitptr, unsigned int len)
{
bitptr->byte += len / CHAR_BIT;
bitptr->left -= len % CHAR_BIT;
if (bitptr->left > CHAR_BIT) {
bitptr->byte++;
bitptr->left += CHAR_BIT;
}
if (bitptr->left < CHAR_BIT)
bitptr->cache = *bitptr->byte;
}
|
/*
* NAME: bit->skip()
* DESCRIPTION: advance bit pointer
*/
|
NAME: bit->skip() DESCRIPTION: advance bit pointer
|
mad_synth_init
|
void mad_synth_init(struct mad_synth *synth)
{
mad_synth_mute(synth);
synth->phase = 0;
synth->pcm.samplerate = 0;
synth->pcm.channels = 0;
synth->pcm.length = 0;
}
|
/*
* NAME: synth->init()
* DESCRIPTION: initialize synth struct
*/
|
NAME: synth->init() DESCRIPTION: initialize synth struct
|
TLx4966_Config
|
void TLx4966_Config(TLx4966_Handle_t *handle,
uint8_t polesPair,
TLx4966_PowerMode_t powMode,
TLx4966_MeasMode_t measMode,
TLx4966_SpeedUnit_t speedUnit,
TLx4966_HwIntf_t *hwIntf)
{
handle->status = TLx4966_UNINITED;
handle->polesPair = polesPair;
handle->powMode = powMode;
handle->measMode = measMode;
handle->speedUnit = speedUnit;
handle->direction = TLx4966_DIR_UNDEF;
handle->speed = 0;
handle->hwIntf = hwIntf;
}
|
/**
* @brief Configures the sensor handle attributes
* Mandatory hw interfaces: dir, speed, timer.
* Optional hw interfaces: power (only for switch mode platform).
*
* @param[in,out] *handle Pointer to the sensor instance handle
* @param[in] polesPair Rotor poles pair number
* @param[in] powMode Power mode
* @param[in] measMode Measuring mode
* @param[in] speedUnit Speed unit
* @param[in] *hwIntf Pointer to hardware interface handle
* @return void
*/
|
@brief Configures the sensor handle attributes Mandatory hw interfaces: dir, speed, timer. Optional hw interfaces: power (only for switch mode platform).
@param[in,out] *handle Pointer to the sensor instance handle @param[in] polesPair Rotor poles pair number @param[in] powMode Power mode @param[in] measMode Measuring mode @param[in] speedUnit Speed unit @param[in] *hwIntf Pointer to hardware interface handle @return void
|
TLx4966_Init
|
TLx4966_Error_t TLx4966_Init(TLx4966_Handle_t *handle)
{
TLx4966_Error_t err = TLx4966_OK;
if(handle->powMode == TLx4966_POWMODE_SWITCH)
{
INTF_ASSERT(handle->hwIntf->power->init());
}
INTF_ASSERT(handle->hwIntf->dir->init());
INTF_ASSERT(handle->hwIntf->speed->init());
INTF_ASSERT(handle->hwIntf->timer->init());
handle->status = TLx4966_INITED;
return err;
}
|
/**
* @brief Initilializes the hardware interfaces
* @param[in] handle Pointer to the sensor entity handle
* @return TLx4966 error code
* @retval TLx4966_OK if success
* @retval TLx4966_INTF_ERROR if hardware interface error
*/
|
@brief Initilializes the hardware interfaces @param[in] handle Pointer to the sensor entity handle @return TLx4966 error code @retval TLx4966_OK if success @retval TLx4966_INTF_ERROR if hardware interface error
|
TLx4966_DirectionCallback
|
STATIC void TLx4966_DirectionCallback(TLx4966_Handle_t *handle)
{
TLx4966_IntEvent_t event = handle->hwIntf->dir->intEvent();
if(event == TLx4966_INT_FALLING_EDGE)
{
handle->direction = TLx4966_DIR_LOW;
}
else if(event == TLx4966_INT_RISING_EDGE)
{
handle->direction = TLx4966_DIR_HIGH;
}
}
|
/**
* @brief Direction interrupt callback
* The sensor instance direction is updated upon interrupt event: rising or falling edge.
*
* @param[in] handle Pointer to the sensor entity handle
* @return void
*/
|
@brief Direction interrupt callback The sensor instance direction is updated upon interrupt event: rising or falling edge.
@param[in] handle Pointer to the sensor entity handle @return void
|
TLx4966_CalculateSpeed
|
STATIC INLINE void TLx4966_CalculateSpeed(TLx4966_Handle_t *handle)
{
handle-> speed = TLx4966_SpeedCoeffient[handle->speedUnit]/((double)handle->polesPair * (double)handle->hwIntf->timer->elapsed());
}
|
/**
* @brief Calculates the speed
* The rising edge of the speed GPIO signal determines the rotating
* period between a pair of poles. The speed is then obtained by applying
* the selected speed unit product coefficient, and dividing between the
* number of poles pairs.
*
* @note To be called upon speed GPIO rising edge.
*
* @param[in] handle Pointer to the sensor entity handle
* @return void
*/
|
@brief Calculates the speed The rising edge of the speed GPIO signal determines the rotating period between a pair of poles. The speed is then obtained by applying the selected speed unit product coefficient, and dividing between the number of poles pairs.
@note To be called upon speed GPIO rising edge.
@param[in] handle Pointer to the sensor entity handle @return void
|
TLx4966_SpeedCallback
|
STATIC void TLx4966_SpeedCallback(TLx4966_Handle_t *handle)
{
TLx4966_IntEvent_t event = handle->hwIntf->speed->intEvent();
if(event == TLx4966_INT_RISING_EDGE)
{
TLx4966_CalculateSpeed(handle);
handle->hwIntf->timer->stop();
handle->hwIntf->timer->start();
}
}
|
/**
* @brief Speed interrupt callback
* The sensor instance instant speed is updated upon rising edge.
*
* @param[in] handle Pointer to the sensor entity handle
* @return void
*/
|
@brief Speed interrupt callback The sensor instance instant speed is updated upon rising edge.
@param[in] handle Pointer to the sensor entity handle @return void
|
TLx4966_Disable
|
TLx4966_Error_t TLx4966_Disable(TLx4966_Handle_t *handle)
{
if(handle->measMode == TLx4966_MEASMODE_INTERRUPT)
{
INTF_ASSERT(handle->hwIntf->dir->disableInt());
INTF_ASSERT(handle->hwIntf->speed->disableInt());
}
if(handle->powMode == TLx4966_POWMODE_SWITCH)
INTF_ASSERT(handle->hwIntf->power->disable());
handle->hwIntf->timer->stop();
handle->status = TLx4966_OFF;
return TLx4966_OK;
}
|
/**
* @brief Disables the sensor
* - If the "Interrupt measuring mode" is configured, the interrupt are enabled.
* - If the "Switch power mode" is configured, the sensor is powered off.
* - The measuring speed timer is stopped.
*
* @param[in] handle Pointer to the sensor entity handle
* @return TLx4966 error code
* @retval TLx4966_OK if success
* @retval TLx4966_INTF_ERROR if hardware interface error
*/
|
@brief Disables the sensor - If the "Interrupt measuring mode" is configured, the interrupt are enabled. - If the "Switch power mode" is configured, the sensor is powered off. - The measuring speed timer is stopped.
@param[in] handle Pointer to the sensor entity handle @return TLx4966 error code @retval TLx4966_OK if success @retval TLx4966_INTF_ERROR if hardware interface error
|
TLx4966_UpdateSpeed
|
void TLx4966_UpdateSpeed(TLx4966_Handle_t *handle)
{
static bool waitingRisingEdge = true;
if(waitingRisingEdge && (handle->hwIntf->speed->read() == TLx4966_GPIO_HIGH))
{
TLx4966_CalculateSpeed(handle);
handle->hwIntf->timer->stop();
handle->hwIntf->timer->start();
waitingRisingEdge = false;
}
else if(!waitingRisingEdge && (handle->hwIntf->speed->read() == TLx4966_GPIO_LOW))
{
waitingRisingEdge = true;
}
}
|
/**
* @brief Updates the sensor speed.
* A rising edge is detected when the gpio voltage level changes from low to high.
*
* @note To be used in super-loop.
* @param[in] handle Pointer to the sensor entity handle
* @return void
*/
|
@brief Updates the sensor speed. A rising edge is detected when the gpio voltage level changes from low to high.
@note To be used in super-loop. @param[in] handle Pointer to the sensor entity handle @return void
|
TLx4966_UpdateDirection
|
INLINE void TLx4966_UpdateDirection(TLx4966_Handle_t *handle)
{
handle->direction = handle->hwIntf->dir->read();
}
|
/**
* @brief Updates the rotation direction
* A rising edge is detected when the gpio voltage level changes from low to high.
*
* @note To be used in super-loop.
* @param[in] handle Pointer to the sensor entity handle
* @return void
*/
|
@brief Updates the rotation direction A rising edge is detected when the gpio voltage level changes from low to high.
@note To be used in super-loop. @param[in] handle Pointer to the sensor entity handle @return void
|
TLx4966_UpdateValues
|
INLINE void TLx4966_UpdateValues(TLx4966_Handle_t *handle)
{
TLx4966_UpdateSpeed(handle);
TLx4966_UpdateDirection(handle);
}
|
/**
* @brief Updates the rotation direction and speed.
* @note To be used in super-loop.
* @param[in] handle Pointer to the sensor entity handle
* @return void
*/
|
@brief Updates the rotation direction and speed. @note To be used in super-loop. @param[in] handle Pointer to the sensor entity handle @return void
|
TLx4966_GetValues
|
INLINE void TLx4966_GetValues(TLx4966_Handle_t *handle, TLx4966_Params_t *params)
{
params->direction = handle->direction;
params->speed = handle->speed;
}
|
/**
* @brief Gets the rotation direction and speed parameters
* @param[in] handle Pointer to the sensor entity handle
* @param[out] *params Pointer to the struct to store the parameter values
* @return void
*/
|
@brief Gets the rotation direction and speed parameters @param[in] handle Pointer to the sensor entity handle @param[out] *params Pointer to the struct to store the parameter values @return void
|
TLx4966_GetStatus
|
INLINE TLx4966_Status_t TLx4966_GetStatus(TLx4966_Handle_t *handle)
{
return handle->status;
}
|
/**
* @brief Gets the sensor status
* @param[in] handle Pointer to the sensor entity handle
* @return TLx4966 status
*/
|
@brief Gets the sensor status @param[in] handle Pointer to the sensor entity handle @return TLx4966 status
|
TLx4966_GetSpeed
|
INLINE double TLx4966_GetSpeed(TLx4966_Handle_t *handle)
{
return handle->speed;
}
|
/**
* @brief Gets the rotation speed
* @param[in] handle Pointer to the sensor entity handle
* @return Speed in the unit specified in the configuration
*/
|
@brief Gets the rotation speed @param[in] handle Pointer to the sensor entity handle @return Speed in the unit specified in the configuration
|
usbBegin
|
void usbBegin()
{
cli();
// fake a disconnect to force the computer to re-enumerate
// Change from Trinket: Pro Trinket uses pins on PORTD
PORTD &= ~(_BV(USB_CFG_DMINUS_BIT) | _BV(USB_CFG_DPLUS_BIT));
usbDeviceDisconnect();
_delay_ms(250);
usbDeviceConnect();
// start the USB driver
usbInit();
sei();
}
|
/* caps/num/scroll lock LEDs*/
|
caps/num/scroll lock LEDs
|
usbFunctionWrite
|
usbMsgLen_t usbFunctionWrite(uint8_t * data, uchar len)
{
led_state = data[0];
return 1; // 1 byte read
}
|
/* see http://vusb.wikidot.com/driver-api*/
|
see http://vusb.wikidot.com/driver-api
|
usbDeviceRead
|
static uchar usbDeviceRead(uchar *data, uchar len)
{
if(len > 0){ /* don't bother app with 0 sized reads */
#if USB_CFG_IMPLEMENT_FN_READ
if(usbMsgFlags & USB_FLG_USE_USER_RW){
len = usbFunctionRead(data, len);
}else
#endif
{
uchar i = len;
usbMsgPtr_t r = usbMsgPtr;
if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */
do{
uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */
*data++ = c;
r++;
}while(--i);
}else{ /* RAM data */
do{
*data++ = *((uchar *)r);
r++;
}while(--i);
}
usbMsgPtr = r;
}
}
return len;
}
|
/* This function is similar to usbFunctionRead(), but it's also called for
* data handled automatically by the driver (e.g. descriptor reads).
*/
|
This function is similar to usbFunctionRead(), but it's also called for data handled automatically by the driver (e.g. descriptor reads).
|
pds_evt_send
|
static void pds_evt_send(pds_evt_t * p_event)
{
for (int i = 0; i < m_pds.n_registrants; i++)
{
m_pds.evt_handlers[i](p_event);
}
}
|
/**@brief Function for dispatching outbound events to all registered event handlers.
*
* @param[in] p_event The event to dispatch.
*/
|
@brief Function for dispatching outbound events to all registered event handlers.
@param[in] p_event The event to dispatch.
|
convert_peer_id_to_instance_id
|
static fds_instance_id_t convert_peer_id_to_instance_id(pm_peer_id_t peer_id)
{
return (fds_instance_id_t)(peer_id + peer_id_to_instance_id);
}
|
/**@brief Function to convert peer id to instance id
*
* @param[in] peer_id Peer id to convert to instance id
*
* @return Value as instance id
*/
|
@brief Function to convert peer id to instance id
@param[in] peer_id Peer id to convert to instance id
@return Value as instance id
|
convert_peer_data_id_to_type_id
|
static fds_type_id_t convert_peer_data_id_to_type_id(pm_peer_data_id_t peer_data_id)
{
return (fds_type_id_t)peer_data_id + (fds_type_id_t)peer_data_id_to_type_id;
}
|
/**@brief Function to convert peer data id to type id
*
* @param[in] peer_data_id Peer data id to convert to type_id
*
* @return Value as type id
*/
|
@brief Function to convert peer data id to type id
@param[in] peer_data_id Peer data id to convert to type_id
@return Value as type id
|
convert_instance_id_to_peer_id
|
static pm_peer_id_t convert_instance_id_to_peer_id(fds_instance_id_t instance_id)
{
return (pm_peer_id_t)(instance_id + instance_id_to_peer_id);
}
|
/**@brief Function to convert peer data id to type id
*
* @param[in] peer_data_id Peer data id to convert to type_id
*
* @return Value as type id
*/
|
@brief Function to convert peer data id to type id
@param[in] peer_data_id Peer data id to convert to type_id
@return Value as type id
|
convert_type_id_to_peer_data_id
|
static pm_peer_data_id_t convert_type_id_to_peer_data_id(fds_type_id_t type_id)
{
return (pm_peer_data_id_t)(type_id + instance_id_to_peer_id);
}
|
/**@brief Function to type id to peer data id
*
* @param[in] type_id Type id to convert to peer data id
*
* @return Value as peer data id
*/
|
@brief Function to type id to peer data id
@param[in] type_id Type id to convert to peer data id
@return Value as peer data id
|
evt_send
|
static void evt_send(im_evt_t * p_event)
{
for (uint32_t i = 0; i < m_im.n_registrants; i++)
{
m_im.evt_handlers[i](p_event);
}
}
|
/**@brief Function for sending an event to all registered event handlers.
*
* @param[in] p_event The event to distribute.
*/
|
@brief Function for sending an event to all registered event handlers.
@param[in] p_event The event to distribute.
|
get_free_connection
|
uint8_t get_free_connection()
{
for (uint32_t i = 0; i < IM_MAX_CONN_HANDLES; i++)
{
// Query the connection state module to check if the connection handle does not belong to a
// valid connection.
if (!ble_conn_state_user_flag_get(m_im.connections[i].conn_handle, m_im.conn_state_user_flag_id))
{
return i;
}
}
// If all connection handles belong to a valid connection, return IM_NO_INVALID_CONN_HANDLES.
return IM_NO_INVALID_CONN_HANDLES;
}
|
/**@brief Function finding a free position in m_im.connections.
*
* @detail All connection handles in the m_im.connections array are checked against the connection
* state module. The index of the first one that is not a connection handle for a current
* connection is returned. This position in the array can safely be used for a new connection.
*
* @return Either the index of a free position in the array or IM_NO_INVALID_CONN_HANDLES if no free
position exists.
*/
|
@brief Function finding a free position in m_im.connections.
@detail All connection handles in the m_im.connections array are checked against the connection state module. The index of the first one that is not a connection handle for a current connection is returned. This position in the array can safely be used for a new connection.
@return Either the index of a free position in the array or IM_NO_INVALID_CONN_HANDLES if no free position exists.
|
get_connection_by_conn_handle
|
uint8_t get_connection_by_conn_handle(uint16_t conn_handle)
{
if (ble_conn_state_user_flag_get(conn_handle, m_im.conn_state_user_flag_id))
{
for (uint32_t i = 0; i < IM_MAX_CONN_HANDLES; i++)
{
if (m_im.connections[i].conn_handle == conn_handle)
{
return i;
}
}
}
// If all connection handles belong to a valid connection, return IM_NO_INVALID_CONN_HANDLES.
return IM_NO_INVALID_CONN_HANDLES;
}
|
/**@brief Function finding a particular connection handle m_im.connections.
*
* @param[in] conn_handle The handle to find.
*
* @return Either the index of the conn_handle in the array or IM_NO_INVALID_CONN_HANDLES if the
* handle was not found.
*/
|
@brief Function finding a particular connection handle m_im.connections.
@param[in] conn_handle The handle to find.
@return Either the index of the conn_handle in the array or IM_NO_INVALID_CONN_HANDLES if the handle was not found.
|
is_valid_irk
|
bool is_valid_irk(ble_gap_irk_t const * irk)
{
for (uint32_t i = 0; i < BLE_GAP_SEC_KEY_LEN; i++)
{
if (irk->irk[i] != 0)
{
return true;
}
}
return false;
}
|
/**@brief Function checking the validity of an IRK
*
* @detail An all-zero IRK is not valid. This function will check if a given IRK is valid.
*
* @param[in] irk The IRK for which the validity is going to be checked.
*
* @retval true The IRK is valid.
* @retval false The IRK is invalid.
*/
|
@brief Function checking the validity of an IRK
@detail An all-zero IRK is not valid. This function will check if a given IRK is valid.
@param[in] irk The IRK for which the validity is going to be checked.
@retval true The IRK is valid. @retval false The IRK is invalid.
|
addr_compare
|
bool addr_compare(ble_gap_addr_t const * p_addr1, ble_gap_addr_t const * p_addr2)
{
if ((p_addr1 == NULL) || (p_addr2 == NULL))
{
return false;
}
// Check that the addr type is identical, return false if it is not
if (p_addr1->addr_type != p_addr2->addr_type)
{
return false;
}
// Check if the addr bytes are is identical
return (memcmp(p_addr1->addr, p_addr2->addr, BLE_GAP_ADDR_LEN) == 0);
}
|
/**@brief Function for comparing two addresses to determine if they are identical
*
* @note The address type need to be identical, as well as every bit in the address itself.
*
* @param[in] p_addr1 The first address to be compared.
* @param[in] p_addr2 The second address to be compared.
*
* @retval true The addresses are identical.
* @retval false The addresses are not identical.
*/
|
@brief Function for comparing two addresses to determine if they are identical
@note The address type need to be identical, as well as every bit in the address itself.
@param[in] p_addr1 The first address to be compared. @param[in] p_addr2 The second address to be compared.
@retval true The addresses are identical. @retval false The addresses are not identical.
|
is_duplicate_bonding_data
|
bool is_duplicate_bonding_data(pm_peer_data_bonding_t const * p_bonding_data1,
pm_peer_data_bonding_t const * p_bonding_data2)
{
bool valid_irk = is_valid_irk(&p_bonding_data1->peer_id.id_info);
bool duplicate_irk = valid_irk &&
(memcmp(p_bonding_data1->peer_id.id_info.irk,
p_bonding_data2->peer_id.id_info.irk,
BLE_GAP_SEC_KEY_LEN) == 0
);
bool duplicate_addr = addr_compare(&p_bonding_data1->peer_id.id_addr_info,
&p_bonding_data2->peer_id.id_addr_info
);
return duplicate_irk || duplicate_addr;
}
|
/**@brief Function to compare two sets of bonding data to check if they belong to the same device.
* @note Invalid irks will never match even though they are identical.
*
* @param[in] p_bonding_data1 First bonding data for comparison
* @param[in] p_bonding_data2 Second bonding data for comparison
*
* @return True if the input matches, false if it does not.
*/
|
@brief Function to compare two sets of bonding data to check if they belong to the same device. @note Invalid irks will never match even though they are identical.
@param[in] p_bonding_data1 First bonding data for comparison @param[in] p_bonding_data2 Second bonding data for comparison
@return True if the input matches, false if it does not.
|
master_id_compare
|
bool master_id_compare(ble_gap_master_id_t const * p_master_id1,
ble_gap_master_id_t const * p_master_id2)
{
if(!im_master_id_is_valid(p_master_id1))
{
return false;
}
if (p_master_id1->ediv != p_master_id2->ediv)
{
return false;
}
return (memcmp(p_master_id1->rand, p_master_id2->rand, BLE_GAP_SEC_RAND_LEN) == 0);
}
|
/**@brief Function for comparing two master ids
* @note Two invalid master IDs will not match.
*
* @param[in] p_master_id1 First master id for comparison
* @param[in] p_master_id2 Second master id for comparison
*
* @return True if the input matches, false if it does not.
*/
|
@brief Function for comparing two master ids @note Two invalid master IDs will not match.
@param[in] p_master_id1 First master id for comparison @param[in] p_master_id2 Second master id for comparison
@return True if the input matches, false if it does not.
|
write_buffer_record_invalidate
|
static void write_buffer_record_invalidate(pdb_buffer_record_t * p_record)
{
p_record->peer_id = PM_PEER_ID_INVALID;
p_record->data_id = PM_PEER_DATA_ID_INVALID;
p_record->buffer_block_id = BUFFER_INVALID_ID;
p_record->store_busy = false;
p_record->store_flash_full = false;
p_record->store_requested = false;
p_record->n_bufs = 0;
p_record->prepare_token = PDS_PREPARE_TOKEN_INVALID;
p_record->store_token = PDS_STORE_TOKEN_INVALID;
}
|
/**@brief Function for invalidating a record of a write buffer allocation.
*
* @param[in] p_record The record to invalidate.
*/
|
@brief Function for invalidating a record of a write buffer allocation.
@param[in] p_record The record to invalidate.
|
write_buffer_record_find
|
static pdb_buffer_record_t * write_buffer_record_find(pm_peer_id_t peer_id,
pm_peer_data_id_t data_id)
{
for (int i = 0; i < N_WRITE_BUFFER_RECORDS; i++)
{
if ((m_pdb.write_buffer_records[i].peer_id == peer_id)
&& (m_pdb.write_buffer_records[i].data_id == data_id))
{
return &m_pdb.write_buffer_records[i];
}
}
return NULL;
}
|
/**@brief Function for finding a record of a write buffer allocation.
*
* @param[in] peer_id The peer ID in the record.
* @param[in] data_id The data ID in the record.
*
* @return A pointer to the matching record, or NULL if none was found.
*/
|
@brief Function for finding a record of a write buffer allocation.
@param[in] peer_id The peer ID in the record. @param[in] data_id The data ID in the record.
@return A pointer to the matching record, or NULL if none was found.
|
write_buffer_record_find_unused
|
static pdb_buffer_record_t * write_buffer_record_find_unused(void)
{
return write_buffer_record_find(PM_PEER_ID_INVALID, PM_PEER_DATA_ID_INVALID);
}
|
/**@brief Function for finding an available record for write buffer allocation.
*
* @return A pointer to the available record, or NULL if none was found.
*/
|
@brief Function for finding an available record for write buffer allocation.
@return A pointer to the available record, or NULL if none was found.
|
write_buffer_record_release
|
static void write_buffer_record_release(pdb_buffer_record_t * p_write_buffer_record)
{
for (int i = 0; i < p_write_buffer_record->n_bufs; i++)
{
pm_buffer_release(&m_pdb.write_buffer, p_write_buffer_record->buffer_block_id + i);
}
write_buffer_record_invalidate(p_write_buffer_record);
}
|
/**@brief Function for gracefully deactivating a write buffer record.
*
* @details This function will first release any buffers, then invalidate the record.
*
* @param[inout] p_write_buffer_record The record to release.
*
* @return A pointer to the matching record, or NULL if none was found.
*/
|
@brief Function for gracefully deactivating a write buffer record.
@details This function will first release any buffers, then invalidate the record.
@param[inout] p_write_buffer_record The record to release.
@return A pointer to the matching record, or NULL if none was found.
|
pdb_evt_send
|
static void pdb_evt_send(pdb_evt_t * p_event)
{
for (int i = 0; i < m_pdb.n_registrants; i++)
{
m_pdb.evt_handlers[i](p_event);
}
}
|
/**@brief Function for dispatching outbound events to all registered event handlers.
*
* @param[in] p_event The event to dispatch.
*/
|
@brief Function for dispatching outbound events to all registered event handlers.
@param[in] p_event The event to dispatch.
|
internal_state_reset
|
static void internal_state_reset(pdb_t * pdb)
{
memset(pdb, 0, sizeof(pdb_t));
for (int i = 0; i < N_WRITE_BUFFER_RECORDS; i++)
{
write_buffer_record_invalidate(&pdb->write_buffer_records[i]);
}
}
|
/**@brief Function for resetting the internal state of the Peer Database module.
*
* @param[out] p_event The event to dispatch.
*/
|
@brief Function for resetting the internal state of the Peer Database module.
@param[out] p_event The event to dispatch.
|
lock_by_mask
|
static bool lock_by_mask(uint8_t * p_mutex, uint8_t mutex_mask)
{
bool success = false;
if ( (*p_mutex & mutex_mask) == 0 )
{
CRITICAL_REGION_ENTER();
if ( (*p_mutex & mutex_mask) == 0 )
{
*p_mutex |= mutex_mask;
success = true;
}
CRITICAL_REGION_EXIT();
}
return ( success );
}
|
/**@brief Locks the mutex defined by the mask.
*
* @param p_mutex pointer to the mutex storage.
* @param mutex_mask the mask identifying the mutex position.
*
* @retval true if the mutex could be locked.
* @retval false if the mutex was already locked.
*/
|
@brief Locks the mutex defined by the mask.
@param p_mutex pointer to the mutex storage. @param mutex_mask the mask identifying the mutex position.
@retval true if the mutex could be locked. @retval false if the mutex was already locked.
|
on_connect
|
static void on_connect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
{
p_dfu->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
}
|
/**@brief Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice.
*
* @param[in] p_dfu DFU Service Structure.
* @param[in] p_ble_evt Pointer to the event received from BLE stack.
*/
|
@brief Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice.
@param[in] p_dfu DFU Service Structure. @param[in] p_ble_evt Pointer to the event received from BLE stack.
|
on_disconnect
|
static void on_disconnect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
{
p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID;
}
|
/**@brief Function for handling the BLE_GAP_EVT_DISCONNECTED event from the S110 SoftDevice.
*
* @param[in] p_dfu DFU Service Structure.
* @param[in] p_ble_evt Pointer to the event received from BLE stack.
*/
|
@brief Function for handling the BLE_GAP_EVT_DISCONNECTED event from the S110 SoftDevice.
@param[in] p_dfu DFU Service Structure. @param[in] p_ble_evt Pointer to the event received from BLE stack.
|
bcs_internal_state_reset
|
void bcs_internal_state_reset(void)
{
memset( &m_bcs, 0, sizeof(ble_conn_state_t) );
}
|
/**@brief Function for resetting all internal memory to the values it had at initialization.
*/
|
@brief Function for resetting all internal memory to the values it had at initialization.
|
record_activate
|
static bool record_activate(uint16_t conn_handle)
{
uint16_t available_index = sdk_mapped_flags_first_key_index_get(~m_bcs.flags.valid_flags);
if (available_index != SDK_MAPPED_FLAGS_INVALID_INDEX)
{
m_bcs.valid_conn_handles[available_index] = conn_handle;
sdk_mapped_flags_update_by_key(m_bcs.valid_conn_handles,
&m_bcs.flags.connected_flags,
conn_handle,
1);
sdk_mapped_flags_update_by_key(m_bcs.valid_conn_handles,
&m_bcs.flags.valid_flags,
conn_handle,
1);
return true;
}
return false;
}
|
/**@brief Function for activating a connection record.
*
* @param p_record The record to activate.
* @param conn_handle The connection handle to copy into the record.
* @param role The role of the connection.
*
* @return whether the record was activated successfully.
*/
|
@brief Function for activating a connection record.
@param p_record The record to activate. @param conn_handle The connection handle to copy into the record. @param role The role of the connection.
@return whether the record was activated successfully.
|
record_invalidate
|
static void record_invalidate(uint16_t conn_handle)
{
sdk_mapped_flags_bulk_update_by_key(m_bcs.valid_conn_handles,
m_bcs.flag_array,
BLE_CONN_STATE_N_FLAGS,
conn_handle,
0);
}
|
/**@brief Function for marking a connection record as invalid and resetting the values.
*
* @param p_record The record to invalidate.
*/
|
@brief Function for marking a connection record as invalid and resetting the values.
@param p_record The record to invalidate.
|
record_set_disconnected
|
static void record_set_disconnected(uint16_t conn_handle)
{
sdk_mapped_flags_update_by_key(m_bcs.valid_conn_handles,
&m_bcs.flags.connected_flags,
conn_handle,
0);
}
|
/**@brief Function for marking a connection as disconnected. See @ref BLE_CONN_STATUS_DISCONNECTED.
*
* @param p_record The record of the connection to set as disconnected.
*/
|
@brief Function for marking a connection as disconnected. See @ref BLE_CONN_STATUS_DISCONNECTED.
@param p_record The record of the connection to set as disconnected.
|
record_purge_disconnected
|
static void record_purge_disconnected()
{
sdk_mapped_flags_key_list_t disconnected_list;
disconnected_list = sdk_mapped_flags_key_list_get(
m_bcs.valid_conn_handles,
(~m_bcs.flags.connected_flags) & (m_bcs.flags.valid_flags));
for (int i = 0; i < disconnected_list.len; i++)
{
record_invalidate(disconnected_list.flag_keys[i]);
}
}
|
/**@brief Function for invalidating records with a @ref BLE_CONN_STATUS_DISCONNECTED
* connection status
*/
|
@brief Function for invalidating records with a @ref BLE_CONN_STATUS_DISCONNECTED connection status
|
user_flag_is_acquired
|
static bool user_flag_is_acquired(ble_conn_state_user_flag_id_t flag_id)
{
return ((m_bcs.acquired_flags & (1 << flag_id)) != 0);
}
|
/**@brief Function for checking if a user flag has been acquired.
*
* @param[in] flag_id Which flag to check.
*
* @return Whether the flag has been acquired.
*/
|
@brief Function for checking if a user flag has been acquired.
@param[in] flag_id Which flag to check.
@return Whether the flag has been acquired.
|
user_flag_acquire
|
static void user_flag_acquire(ble_conn_state_user_flag_id_t flag_id)
{
m_bcs.acquired_flags |= (1 << flag_id);
}
|
/**@brief Function for marking a user flag as acquired.
*
* @param[in] flag_id Which flag to mark.
*/
|
@brief Function for marking a user flag as acquired.
@param[in] flag_id Which flag to mark.
|
update_status_bit_set
|
static __INLINE void update_status_bit_set(uint32_t index)
{
m_peer_addr_update |= (BIT_0 << index);
}
|
/**@brief Function for setting update status for the device identified by 'index'.
*
* @param[in] index Device identifier.
*/
|
@brief Function for setting update status for the device identified by 'index'.
@param[in] index Device identifier.
|
update_status_bit_reset
|
static __INLINE void update_status_bit_reset(uint32_t index)
{
m_peer_addr_update &= (~((uint32_t)BIT_0 << index));
}
|
/**@brief Function for resetting update status for device identified by 'index'.
*
* @param[in] index Device identifier.
*/
|
@brief Function for resetting update status for device identified by 'index'.
@param[in] index Device identifier.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.