1 /**\r
2 * \file tcp3d_utils.c\r
3 *\r
4 * \brief TCP3D Driver utility functions.\r
5 *\r
6 * Copyright (C) Texas Instruments Incorporated 2009\r
7 * \r
8 * Redistribution and use in source and binary forms, with or without \r
9 * modification, are permitted provided that the following conditions \r
10 * are met:\r
11 *\r
12 * Redistributions of source code must retain the above copyright \r
13 * notice, this list of conditions and the following disclaimer.\r
14 *\r
15 * Redistributions in binary form must reproduce the above copyright\r
16 * notice, this list of conditions and the following disclaimer in the \r
17 * documentation and/or other materials provided with the \r
18 * distribution.\r
19 *\r
20 * Neither the name of Texas Instruments Incorporated nor the names of\r
21 * its contributors may be used to endorse or promote products derived\r
22 * from this software without specific prior written permission.\r
23 *\r
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
35 *\r
36 */\r
37 \r
38 /**\r
39 * Include Files\r
40 */\r
41 /* c99 types includes */\r
42 #include <stdint.h>\r
43 #include <stdlib.h>\r
44 \r
45 /**\r
46 * @brief This is a utility function provided as part of TCP3D Driver for\r
47 * converting the local address to the global address using the \r
48 * coreID.\r
49 * The address mapping will be done only if the address falls in\r
50 * the defined local L2 memory area. Otherwise, the address is\r
51 * returned as is.\r
52 */\r
53 uint32_t Tcp3d_glbMap (uint8_t coreID, uint32_t addr)\r
54 {\r
55 uint32_t upcastAddr = 0;\r
56 \r
57 /*\r
58 * Address mapping is done based on the mapping shown below.\r
59 * \r
60 * L2SRAM : org = 0x00800000, len = 0x100000 (local)\r
61 * GEM0_L2_MEM : org = 0x10800000, len = 0x100000 (global)\r
62 * GEM1_L2_MEM : org = 0x11800000, len = 0x100000 (global)\r
63 * GEM2_L2_MEM : org = 0x12800000, len = 0x100000 (global)\r
64 * GEM3_L2_MEM : org = 0x13800000, len = 0x100000 (global)\r
65 *\r
66 * MSMCSRAM : org = 0x0c000000, len = 0x200000 (global)\r
67 */\r
68 \r
69 /* Check if the address is in L2SRAM & a valid coreID */\r
70 if ( ( addr >= 0x00800000 ) && ( addr < 0x00900000 ) )\r
71 {\r
72 upcastAddr = (uint32_t)( (0x10 | ( coreID & 0x3 )) << 24 );\r
73 }\r
74 \r
75 return ( addr | upcastAddr );\r
76 }\r
77 \r
78 /* Division of (a/b) */\r
79 uint32_t Tcp3d_div32by16(uint32_t num, uint16_t den)\r
80 {\r
81 int32_t expn;\r
82 uint32_t normal;\r
83 uint32_t a, b;\r
84 int32_t i;\r
85 int32_t ret;\r
86 \r
87 normal = _norm( den );\r
88 a = ( den << normal ) & 0x7fff0000;\r
89 b = 0x80000000; /* dividend = 1 */\r
90 \r
91 #ifdef _TMS320C6X\r
92 #pragma MUST_ITERATE( 15,15 );\r
93 #endif\r
94 for(i = 15; i > 0; i--)\r
95 {\r
96 b = _subc( b, a ); /* divide */\r
97 }\r
98 b = b & 0x7fff;\r
99 expn = 30 - (int32_t) normal;\r
100 ret = _sshvr( _mpylir( b,num), expn );\r
101 \r
102 return (ret);\r
103 }\r
104 \r
105 /* end of file */\r