mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-14 04:18:56 +00:00
Guard const addr fifo functions with TUP_MEM_CONST_ADDR.
This commit is contained in:
parent
bf1540af4c
commit
c303b5d81d
@ -62,7 +62,9 @@ TU_ATTR_ALWAYS_INLINE static inline void _ff_unlock(osal_mutex_t mutex)
|
||||
typedef enum
|
||||
{
|
||||
TU_FIFO_COPY_INC, ///< Copy from/to an increasing source/destination address - default mode
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
TU_FIFO_COPY_CST_FULL_WORDS, ///< Copy from/to a constant source/destination address - required for e.g. STM32 to write into USB hardware FIFO
|
||||
#endif
|
||||
} tu_fifo_copy_mode_t;
|
||||
|
||||
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
|
||||
@ -92,6 +94,7 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
|
||||
// Pull & Push
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
// Intended to be used to read from hardware USB FIFO in e.g. STM32 where all data is read from a constant address
|
||||
// Code adapted from dcd_synopsys.c
|
||||
// TODO generalize with configurable 1 byte or 4 byte each read
|
||||
@ -140,6 +143,7 @@ static void _ff_pull_const_addr(void * app_buf, const uint8_t * ff_buf, uint16_t
|
||||
*reg_tx = tmp32;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// send one item to fifo WITHOUT updating write pointer
|
||||
static inline void _ff_push(tu_fifo_t* f, void const * app_buf, uint16_t rel)
|
||||
@ -179,7 +183,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
|
||||
memcpy(f->buffer, ((uint8_t const*) app_buf) + lin_bytes, wrap_bytes);
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
case TU_FIFO_COPY_CST_FULL_WORDS:
|
||||
// Intended for hardware buffers from which it can be read word by word only
|
||||
if(n <= lin_count)
|
||||
@ -224,6 +228,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
|
||||
if (wrap_bytes > 0) _ff_push_const_addr(ff_buf, app_buf, wrap_bytes);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -265,7 +270,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
|
||||
memcpy((uint8_t*) app_buf + lin_bytes, f->buffer, wrap_bytes);
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
case TU_FIFO_COPY_CST_FULL_WORDS:
|
||||
if ( n <= lin_count )
|
||||
{
|
||||
@ -310,6 +315,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
|
||||
// Read data wrapped part
|
||||
if (wrap_bytes > 0) _ff_pull_const_addr(app_buf, ff_buf, wrap_bytes);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@ -727,10 +733,29 @@ uint16_t tu_fifo_read_n(tu_fifo_t* f, void * buffer, uint16_t n)
|
||||
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_INC);
|
||||
}
|
||||
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief This function will read n elements from the array index specified by
|
||||
the read pointer and increment the read index.
|
||||
This function checks for an overflow and corrects read pointer if required.
|
||||
The dest address will not be incremented which is useful for writing to registers.
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] buffer
|
||||
The pointer to data location
|
||||
@param[in] n
|
||||
Number of element that buffer can afford
|
||||
|
||||
@returns number of items read from the FIFO
|
||||
*/
|
||||
/******************************************************************************/
|
||||
uint16_t tu_fifo_read_n_const_addr_full_words(tu_fifo_t* f, void * buffer, uint16_t n)
|
||||
{
|
||||
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_CST_FULL_WORDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@ -839,6 +864,7 @@ uint16_t tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n)
|
||||
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_INC);
|
||||
}
|
||||
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief This function will write n elements into the array index specified by
|
||||
@ -858,6 +884,7 @@ uint16_t tu_fifo_write_n_const_addr_full_words(tu_fifo_t* f, const void * data,
|
||||
{
|
||||
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_CST_FULL_WORDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
|
@ -156,11 +156,15 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
|
||||
|
||||
bool tu_fifo_write (tu_fifo_t* f, void const * p_data);
|
||||
uint16_t tu_fifo_write_n (tu_fifo_t* f, void const * p_data, uint16_t n);
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
uint16_t tu_fifo_write_n_const_addr_full_words (tu_fifo_t* f, const void * data, uint16_t n);
|
||||
#endif
|
||||
|
||||
bool tu_fifo_read (tu_fifo_t* f, void * p_buffer);
|
||||
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
||||
#ifdef TUP_MEM_CONST_ADDR
|
||||
uint16_t tu_fifo_read_n_const_addr_full_words (tu_fifo_t* f, void * buffer, uint16_t n);
|
||||
#endif
|
||||
|
||||
bool tu_fifo_peek (tu_fifo_t* f, void * p_buffer);
|
||||
uint16_t tu_fifo_peek_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
||||
|
@ -448,4 +448,8 @@
|
||||
#define TUP_DCD_EDPT_ISO_ALLOC
|
||||
#endif
|
||||
|
||||
#if defined(TUP_USBIP_DWC2)
|
||||
#define TUP_MEM_CONST_ADDR
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user