Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / libraries / PyMite / vm / mem.h
blob840cbde4f7b99060a1cf0fb63567b0f7abe38f3d
1 /*
2 # This file is Copyright 2003, 2006, 2007, 2009, 2010 Dean Hall.
4 # This file is part of the PyMite VM.
5 # The PyMite VM is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
8 # The PyMite VM is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
12 # is seen in the file COPYING in this directory.
16 #ifndef __MEM_H__
17 #define __MEM_H__
20 /**
21 * \file
22 * \brief VM Memory
24 * VM memory header.
28 /**
29 * Memory Space enum.
31 * Defines the different addressable areas of the system.
33 typedef enum PmMemSpace_e
35 MEMSPACE_RAM = 0,
36 MEMSPACE_PROG,
37 MEMSPACE_EEPROM,
38 MEMSPACE_SEEPROM,
39 MEMSPACE_OTHER0,
40 MEMSPACE_OTHER1,
41 MEMSPACE_OTHER2,
42 MEMSPACE_OTHER3
43 } PmMemSpace_t, *pPmMemSpace_t;
46 /**
47 * Returns the byte at the given address in memspace.
49 * Increments the address (just like getc and read(1))
50 * to make image loading work (recursive).
52 * @param memspace memory space/type
53 * @param paddr ptr to address
54 * @return byte from memory.
55 * paddr - points to the next byte
57 #define mem_getByte(memspace, paddr) plat_memGetByte((memspace), (paddr))
59 /**
60 * Returns the 2-byte word at the given address in memspace.
62 * Word obtained in LITTLE ENDIAN order (per Python convention).
63 * afterward, addr points one byte past the word.
65 * @param memspace memory space
66 * @param paddr ptr to address
67 * @return word from memory.
68 * addr - points one byte past the word
70 uint16_t mem_getWord(PmMemSpace_t memspace, uint8_t const **paddr);
72 /**
73 * Returns the 4-byte int at the given address in memspace.
75 * Int obtained in LITTLE ENDIAN order (per Python convention).
76 * afterward, addr points one byte past the int.
78 * @param memspace memory space
79 * @param paddr ptr to address
80 * @return int from memory.
81 * addr - points one byte past the word
83 uint32_t mem_getInt(PmMemSpace_t memspace, uint8_t const **paddr);
85 #ifdef HAVE_FLOAT
86 /**
87 * Returns the 4-byte float at the given address in memspace.
89 * Float obtained in LITTLE ENDIAN order (per Python convention).
90 * afterward, addr points one byte past the float.
92 * @param memspace memory space
93 * @param paddr ptr to address
94 * @return float from memory.
95 * addr - points one byte past the word
97 float mem_getFloat(PmMemSpace_t memspace, uint8_t const **paddr);
98 #endif /* HAVE_FLOAT */
101 * Copies count number of bytes from src in memspace to dest in RAM.
102 * Leaves dest and src pointing one byte past end of the data.
104 * @param memspace memory space/type of source
105 * @param pdest ptr to destination address
106 * @param psrc ptr to source address
107 * @param count number of bytes to copy
108 * @return nothing.
109 * src, dest - point 1 past end of data
110 * @see sli_memcpy
112 void mem_copy(PmMemSpace_t memspace,
113 uint8_t **pdest, uint8_t const **psrc, uint16_t count);
116 * Returns the number of bytes in the C string pointed to by pstr.
117 * Does not modify pstr
119 * @param memspace memory space/type of source
120 * @param pstr ptr to source C string
121 * @return Number of bytes in the string.
123 uint16_t mem_getStringLength(PmMemSpace_t memspace,
124 uint8_t const *const pstr);
127 * Compares a byte array in RAM to a byte array in the given memory space
129 * @param cname Pointer to byte array in RAM
130 * @param cnamelen Length of byte array to compare
131 * @param memspace Memory space of other byte array
132 * @param paddr Pointer to address of other byte array
133 * @return PM_RET_OK if all bytes in both arrays match; PM_RET_NO otherwise
135 PmReturn_t mem_cmpn(uint8_t *cname, uint8_t cnamelen, PmMemSpace_t memspace,
136 uint8_t const **paddr);
138 #endif /* __MEM_H__ */