1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef bbs_FUNCTIONS_EM_H
18 #define bbs_FUNCTIONS_EM_H
19 
20 /**
21  * This files contains gerenral purpose functions.
22  */
23 
24 /* ---- includes ----------------------------------------------------------- */
25 /*
26 #include <stdarg.h>
27 #include <stdlib.h>
28 */
29 #include "b_BasicEm/Basic.h"
30 #include "b_BasicEm/String.h"
31 #include "b_BasicEm/Memory.h"
32 
33 /* ---- related objects  --------------------------------------------------- */
34 
35 struct bbs_Context;
36 
37 /* ---- typedefs ----------------------------------------------------------- */
38 
39 /* ---- constants ---------------------------------------------------------- */
40 
41 /* ---- external functions ------------------------------------------------- */
42 
43 /* Memory I/O Functions */
44 
45 /* Memory I/O Operations use the little endian data alignment
46    regardless of platform */
47 
48 /** writes a 32 bit word to memory; returns bbs_SIZEOF16( uint32 ) */
49 uint32 bbs_memWrite32( const void* ptrA,
50 					   uint16* memPtrA );
51 
52 /** reads a 32 bit word from memory; returns bbs_SIZEOF16( uint32 ) */
53 uint32 bbs_memRead32( void* ptrA,
54 					  const uint16* memPtrA );
55 
56 /** reads a 32 bit word from memory and returns it */
57 uint32 bbs_memPeek32( const uint16* memPtrA );
58 
59 /** writes a 16 bit word to memory; returns bbs_SIZEOF16( uint16 ) */
60 uint32 bbs_memWrite16( const void* ptrA,
61 					   uint16* memPtrA );
62 
63 /** reads a 16 bit word from memory; returns bbs_SIZEOF16( uint16 ) */
64 uint32 bbs_memRead16( void* ptrA,
65 					  const uint16* memPtrA );
66 
67 /** writes a 32 bit word array to memory; sizeA specifies number of words in array; returns bbs_SIZEOF16( uint32 ) * sizeA */
68 uint32 bbs_memWrite32Arr( struct bbs_Context* cpA,
69 						  const void* ptrA,
70 						  uint32 sizeA, uint16* memPtrA );
71 
72 /** reads a 32 bit word array from memory; sizeA specifies number of words in array; returns bbs_SIZEOF16( uint32 ) * sizeA */
73 uint32 bbs_memRead32Arr( struct bbs_Context* cpA,
74 						 void* ptrA,
75 						 uint32 sizeA, const uint16* memPtrA );
76 
77 /** writes a 16 bit word array to memory; sizeA specifies number of words in array; returns bbs_SIZEOF16( uint16 ) * sizeA */
78 uint32 bbs_memWrite16Arr( struct bbs_Context* cpA,
79 						  const void* ptrA,
80 						  uint32 sizeA, uint16* memPtrA );
81 
82 /** reads a 16 bit word array from memory; sizeA specifies number of words in array; returns bbs_SIZEOF16( uint16 ) * sizeA */
83 uint32 bbs_memRead16Arr( struct bbs_Context* cpA,
84 						 void* ptrA,
85 						 uint32 sizeA, const uint16* memPtrA );
86 
87 /* Spcial I/O Functions */
88 
89 /** writes a 32 bit value to memory; returns bbs_SIZEOF16( uint32 ) */
90 uint32 bbs_memWriteUInt32( uint32 valA,
91 						   uint16* memPtrA );
92 
93 /** writes a 16 bit values to memory; returns bbs_SIZEOF16( uint16 ) */
94 uint32 bbs_memWriteUInt16( uint16 valA,
95 						   uint16* memPtrA );
96 
97 /** reads a 32 bit version number word from memory.
98  *  Compares the number to refVersionA.
99  *  If refVersionA is lower an error condition is created.
100  *  returns bbs_SIZEOF16( uint32 )
101  */
102 uint32 bbs_memReadVersion32( struct bbs_Context* cpA,
103 							 uint32* versionPtrA,
104 							 uint32 refVersionA,
105 							 const uint16* memPtrA );
106 
107 /** return 16bit check sum of memory area (applies platform specific byte swapps) */
108 uint16 bbs_memCheckSum16( const uint16* memPtrA, uint32 sizeA );
109 
110 #endif /* bbs_FUNCTIONS_EM_H */
111 
112