DSPLIB User Guide
DSPLIB_debugPrintMatrix.cpp
Go to the documentation of this file.
1 /******************************************************************************/
5 /* Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************/
36 
37 /*******************************************************************************
38  *
39  * INCLUDES
40  *
41  ******************************************************************************/
42 
43 #include "../DSPLIB_bufParams.h"
44 #include "../DSPLIB_types.h"
45 #include "../DSPLIB_utility.h"
46 
47 //----------------------------------------------------------------------------------
48 
49 template <typename dataType> void DSPLIB_debugPrintMatrix_helper(dataType *matrix, const DSPLIB_bufParams2D_t *params)
50 {
51  uint32_t x, y;
52  dataType *xPtr;
53  dataType *yPtr = matrix;
54 
55  // stride_y is stored in bytes, but easier to use in elements
56  uint32_t stride_y_elements = params->stride_y / DSPLIB_sizeof(params->data_type);
57 
58  for (y = 0; y < params->dim_y; y++) {
59  xPtr = yPtr;
60  DSPLIB_PRINTF("%p |", xPtr);
61  for (x = 0; x < params->dim_x; x++) {
62  DSPLIB_PRINTF("%3d ", *(xPtr));
63  xPtr++;
64  }
65  DSPLIB_PRINTF("%s", "|\n");
66  yPtr += stride_y_elements;
67  }
68 
69  return;
70 }
71 
72 template void DSPLIB_debugPrintMatrix_helper<int8_t>(int8_t *matrix, const DSPLIB_bufParams2D_t *params);
73 template void DSPLIB_debugPrintMatrix_helper<uint8_t>(uint8_t *matrix, const DSPLIB_bufParams2D_t *params);
74 template void DSPLIB_debugPrintMatrix_helper<int16_t>(int16_t *matrix, const DSPLIB_bufParams2D_t *params);
75 template void DSPLIB_debugPrintMatrix_helper<uint16_t>(uint16_t *matrix, const DSPLIB_bufParams2D_t *params);
76 template void DSPLIB_debugPrintMatrix_helper<int32_t>(int32_t *matrix, const DSPLIB_bufParams2D_t *params);
77 
78 /******************************************************************************/
79 
80 /******************************************************************************/
87 /******************************************************************************/
88 
89 // want this function to have C-linkage in library...
90 #ifdef __cplusplus
91 extern "C" {
92 #endif /* __cplusplus */
93 
94 void DSPLIB_debugPrintMatrix(void *matrix, const DSPLIB_bufParams2D_t *params)
95 {
96  switch (params->data_type) {
97  case DSPLIB_INT32:
98  DSPLIB_debugPrintMatrix_helper<int32_t>((int32_t *) matrix, params);
99  break;
100  case DSPLIB_INT16:
101  DSPLIB_debugPrintMatrix_helper<int16_t>((int16_t *) matrix, params);
102  break;
103  case DSPLIB_UINT16:
104  DSPLIB_debugPrintMatrix_helper<uint16_t>((uint16_t *) matrix, params);
105  break;
106  case DSPLIB_INT8:
107  DSPLIB_debugPrintMatrix_helper<int8_t>((int8_t *) matrix, params);
108  break;
109  case DSPLIB_UINT8:
110  DSPLIB_debugPrintMatrix_helper<uint8_t>((uint8_t *) matrix, params);
111  break;
112  default:
113  DSPLIB_PRINTF("\nERROR: Unrecognized data type in %s.\n", __FUNCTION__);
114  }
115 
116  return;
117 }
118 #ifdef __cplusplus
119 }
120 #endif /* __cplusplus */
template void DSPLIB_debugPrintMatrix_helper< int32_t >(int32_t *matrix, const DSPLIB_bufParams2D_t *params)
template void DSPLIB_debugPrintMatrix_helper< int16_t >(int16_t *matrix, const DSPLIB_bufParams2D_t *params)
template void DSPLIB_debugPrintMatrix_helper< uint8_t >(uint8_t *matrix, const DSPLIB_bufParams2D_t *params)
void DSPLIB_debugPrintMatrix_helper(dataType *matrix, const DSPLIB_bufParams2D_t *params)
void DSPLIB_debugPrintMatrix(void *matrix, const DSPLIB_bufParams2D_t *params)
template void DSPLIB_debugPrintMatrix_helper< uint16_t >(uint16_t *matrix, const DSPLIB_bufParams2D_t *params)
template void DSPLIB_debugPrintMatrix_helper< int8_t >(int8_t *matrix, const DSPLIB_bufParams2D_t *params)
#define DSPLIB_PRINTF(fmt,...)
Definition: DSPLIB_types.h:84
static int32_t DSPLIB_sizeof(uint32_t type)
Inline function returns number of bytes per element given a type of DSPLIB_data_type_e.
@ DSPLIB_UINT8
@ DSPLIB_UINT16
@ DSPLIB_INT32
@ DSPLIB_INT16
@ DSPLIB_INT8
A structure for a 2 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.
int32_t stride_y
Stride in Y dimension in bytes.
uint32_t dim_x
Width of buffer in X dimension in elements.
uint32_t dim_y
Height of buffer in Y dimension in elements.