DVBCore  20.3.0
DVBCore Documentation
stbcsum.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
25 //---includes for this file----------------------------------------------------
26 // compiler library header files
27 
28 // third party header files
29 
30 // Ocean Blue Software header files
31 
32 #include <techtype.h>
33 #include <dbgfuncs.h>
34 
35 //---constant definitions for this file----------------------------------------
36 
37 //---local typedef structs for this file---------------------------------------
38 
39 //---local (static) variable declarations for this file------------------------
40 // (internal variables declared static to make them local)
41 
42 //---local function prototypes for this file-----------------------------------
43 // (internal functions declared static to make them local)
44 
45 //---local function definitions------------------------------------------------
46 
47 
48 //---global function definitions-----------------------------------------------
49 
62 U8BIT STB_CalcChecksum(U8BIT *data_ptr, U32BIT data_size)
63 {
64  U8BIT cs;
65  U32BIT i;
66 
67 // FUNCTION_START(STB_CalcChecksum);
68 
69  ASSERT(data_ptr != NULL);
70  ASSERT(data_size > 0);
71 
72  cs = 0;
73  for (i = 0; i < (data_size - 1); i++)
74  {
75  cs += *(data_ptr + i);
76  }
77  cs = (0xff - cs + 1);
78 
79 // FUNCTION_FINISH(STB_CalcChecksum);
80 
81  return(cs);
82 }
83 
96 BOOLEAN STB_CheckChecksum(U8BIT *data_ptr, U32BIT data_size)
97 {
98  U8BIT cs;
99  U32BIT i;
100  BOOLEAN ret_val;
101 
102 // FUNCTION_START(STB_CheckChecksum);
103 
104  ASSERT(data_ptr != NULL);
105  ASSERT(data_size > 0);
106 
107  cs = 0;
108  for (i = 0; i < data_size; i++)
109  {
110  cs += *(data_ptr + i);
111  }
112 
113  if (cs == 0)
114  {
115  ret_val = TRUE;
116  }
117  else
118  {
119  ret_val = FALSE;
120  }
121 
122 // FUNCTION_FINISH(STB_CheckChecksum);
123 
124  return(ret_val);
125 }
126 
138 U16BIT STB_GetBE16Bit(U16BIT *addr)
139 {
140  U16BIT ret_val;
141 
142  FUNCTION_START(STB_GetBE16Bit);
143 
144  ASSERT(addr != NULL);
145 
146  ret_val = (U16BIT)((U8BIT *)addr)[0];
147  ret_val <<= 8;
148  ret_val |= (U16BIT)((U8BIT *)addr)[1];
149 
150  FUNCTION_FINISH(STB_GetBE16Bit);
151 
152  return(ret_val);
153 }
154 
167 void STB_SetBE16Bit(U16BIT *addr, U16BIT value)
168 {
169  FUNCTION_START(STB_SetBE16Bit);
170 
171  ASSERT(addr != NULL);
172 
173  ((U8BIT *)addr)[0] = (U8BIT)(value >> 8);
174  ((U8BIT *)addr)[1] = (U8BIT)(value & 0x00ff);
175 
176  FUNCTION_FINISH(STB_SetBE16Bit);
177 }
178 
179 //*****************************************************************************
180 // End of file
181 //*****************************************************************************
182 
void STB_SetBE16Bit(U16BIT *addr, U16BIT value)
Stores 16bit int in address, forcing value to be stored in Big endian format.
Definition: stbcsum.c:167
U8BIT STB_CalcChecksum(U8BIT *data_ptr, U32BIT data_size)
Calculates the checksum to zero for the data block provided.
Definition: stbcsum.c:62
U16BIT STB_GetBE16Bit(U16BIT *addr)
Returns 16bit int from address, assuming value is stored in Big endian format.
Definition: stbcsum.c:138
Debug functions header file.
System Wide Global Technical Data Type Definitions.
BOOLEAN STB_CheckChecksum(U8BIT *data_ptr, U32BIT data_size)
Validates the checksum to zero for the block pointer provided.
Definition: stbcsum.c:96