2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
18 File name : _pbSum.cpp
20 Subsystem name : System common functions
21 Title : System APIs Asynchronous Data HDD Backup Processing
22 --------------------------------------------------------------------------------------
23 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25 #include <vehicle_service/positioning_base_library.h>
28 Function prototype declarations
29 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
31 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
33 * ABSTRACT : SUM calculation process
34 * NOTE : Calculate the SUM value for the specified size from the SUM calculation start address.
35 * ARGUMENT : void *p SUM calculation start address
36 * int32 size Size (bytes)
37 * u_int8 type Calculation width Byte :sizeof(u_char)
38 * Word :sizeof(u_int16)
39 * Long-word:sizeof(u_int32)
40 * NOTE : Calculate the SUM value from the SUM calculation start address by the size specified by the calculation width.
41 * RETURN : u_int32 SUM value
42 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 u_int32 Sum(void *p, int32 size, u_int8 type) { // LCOV_EXCL_START 8:dead code
44 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
45 u_int32 sum = 0; /* SUM value */
46 u_int32 loop_cnt; /* Loop counter */
47 u_int32 loop_num; /* Number of loops */
49 /* Pointer size check */
50 if ((p == NULL) || (size == 0)) {
53 /* When the calculation width is "Long word" */
54 if (type == sizeof(int32)) {
55 u_int32 * ptr32 = reinterpret_cast<u_int32 *>(p); /* Long word pointer */
57 /* Calculate the number of processes and loop for the number of Times to compute the Sum value. */
58 loop_num = static_cast<u_int32>(size / sizeof(u_int32));
59 for (loop_cnt = 0; loop_cnt < loop_num; loop_cnt++) {
63 } else if (type == sizeof(int16)) {
65 u_int16 * ptr16 = reinterpret_cast<u_int16 *>(p); /* Word pointer */
67 loop_num = static_cast<u_int32>(size / sizeof(u_int16));
68 for (loop_cnt = 0; loop_cnt < loop_num; loop_cnt++) {
72 } else if (type == sizeof(char)) {
74 u_char * ptr8 = reinterpret_cast<u_char *>(p); /* Byte pointer */
76 loop_num = static_cast<u_int32>(size / sizeof(u_char));
77 for (loop_cnt = 0; loop_cnt < loop_num; loop_cnt++) {
82 /* For other than above */
91 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
93 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *