Norimasa Okamoto
/
pymite
python-on-a-chip online compiler
Embed:
(wiki syntax)
Show/hide line numbers
sli.h
Go to the documentation of this file.
00001 /* 00002 # This file is Copyright 2002 Dean Hall. 00003 # This file is part of the PyMite VM. 00004 # This file is licensed under the MIT License. 00005 # See the LICENSE file for details. 00006 */ 00007 00008 00009 #ifndef __SLI_H__ 00010 #define __SLI_H__ 00011 00012 00013 /** 00014 * \file 00015 * \brief Standard Library Interface 00016 * 00017 * PyMite requires a few functions from a few different 00018 * standard C libraries (memory, string, etc). 00019 * If your microcontroller has these libraries, 00020 * set the constant to 1 for each library available. 00021 * This will cause a macro to be defined which wraps 00022 * the function for use by PyMite. 00023 * Otherwise, leave the constant as 0, and PyMite will 00024 * use the function defined in sli.c 00025 * Some of the functions in sli.c will need to be ported 00026 * to the target system. 00027 */ 00028 00029 00030 /** 00031 * If the compiler has string.h, set HAVE_STRING to 1; 00032 * otherwise, leave it 0 and the sli functions will be used. 00033 */ 00034 #define HAVE_STRING_H 0 00035 00036 00037 /* 00038 * This section creates a macro or a function prototype 00039 * for each library based on the corresponding constant. 00040 * For example, if HAVE_STRING_H is defined to non-zero, 00041 * the system <string.h> file will be included, 00042 * and a macro "sli_strcmp" will be created to wrap the strcmp() 00043 * function. But if HAVE_STRING is zero, the sli_strcmp() 00044 * prototype will be declared and sli_strcmp() must be 00045 * implemented in sli.c 00046 */ 00047 00048 #if HAVE_STRING_H 00049 00050 #include <string.h> 00051 00052 #define sli_memcpy(to, from, n) memcpy((to), (from), (n)) 00053 #define sli_strcmp(s1, s2) strcmp((s1),(s2)) 00054 #define sli_strlen(s) strlen(s) 00055 #define sli_strncmp(s1, s2, n) strncmp((s1),(s2),(n)) 00056 00057 #else 00058 00059 /** 00060 * Copies a block of memory in RAM. 00061 * 00062 * @param to The destination address. 00063 * @param from The source address. 00064 * @param n The number of bytes to copy. 00065 * @return The initial pointer value of the destination 00066 * @see mem_copy 00067 */ 00068 void *sli_memcpy(unsigned char *to, unsigned char const *from, unsigned int n); 00069 00070 /** 00071 * Compares two strings. 00072 * 00073 * @param s1 Ptr to string 1. 00074 * @param s2 Ptr to string 2. 00075 * @return value that is less then, equal to or greater than 0 00076 * depending on whether s1's encoding is 00077 * less than, equal to, or greater than s2's. 00078 */ 00079 int sli_strcmp(char const *s1, char const *s2); 00080 00081 /** 00082 * Obtain string length. 00083 * 00084 * @param s ptr to string. 00085 * @return number of bytes in string. 00086 */ 00087 int sli_strlen(char const *s); 00088 00089 /** 00090 * Compare strings for a specific length. 00091 * 00092 * @param s1 ptr to string 1. 00093 * @param s2 ptr to string 2. 00094 * @param n number of chars to compare 00095 * @return value that is less then, equal to or greater than 0 00096 * depending on whether s1's encoding is 00097 * less than, equal to, or greater than s2's. 00098 */ 00099 int sli_strncmp(char const *s1, char const *s2, unsigned int n); 00100 00101 #endif /* HAVE_STRING_H */ 00102 00103 /** 00104 * Copy a value repeatedly into a block of memory 00105 * 00106 * @param dest the destination address. 00107 * @param val the value. 00108 * @param n the number of bytes to copy. 00109 * @return Nothing 00110 * @see memset 00111 */ 00112 void sli_memset(unsigned char *dest, const char val, unsigned int n); 00113 00114 /** 00115 * Prints a string to stdout (using plat_putByte) 00116 * 00117 * @param s Pointer to the C string to print 00118 */ 00119 void sli_puts(uint8_t * s); 00120 00121 /** 00122 * Formats a 32-bit signed int as a decimal value. 00123 * 00124 * @param value the 32-bit signed value 00125 * @param buf a pointer to where the formatted string goes 00126 * @param buflen the length of the given buffer in bytes 00127 * @return a pointer to the string. 00128 */ 00129 PmReturn_t sli_ltoa10(int32_t value, uint8_t *buf, uint8_t buflen); 00130 00131 /** 00132 * Formats an 8-bit int as a hexadecimal value. 00133 * 00134 * @param value the 8-bit value 00135 * @param buf a pointer to where the formatted string goes 00136 * @param buflen the length of the given buffer in bytes 00137 * @param upperCase when zero, hex chars rendered lowercase, else uppercase 00138 * @return Always PM_RET_OK 00139 */ 00140 PmReturn_t sli_btoa16(uint8_t value, uint8_t *buf, uint8_t buflen, uint8_t upperCase); 00141 00142 /** 00143 * Formats a 32-bit signed int as a hexadecimal value. 00144 * 00145 * @param value the 32-bit signed value 00146 * @param buf a pointer to where the formatted string goes 00147 * @param buflen the length of the given buffer in bytes 00148 * @param upperCase when zero, hex chars rendered lowercase, else uppercase 00149 * @return Always PM_RET_OK 00150 */ 00151 PmReturn_t sli_ltoa16(int32_t value, uint8_t *buf, uint8_t buflen, uint8_t upperCase); 00152 00153 /** 00154 * Formats a pointer as a hexadecimal value. 00155 * 00156 * @param value the pointer 00157 * @param buf a pointer to where the formatted string goes 00158 * @param buflen the length of the given buffer in bytes 00159 * @param upperCase when zero, hex chars rendered lowercase, else uppercase 00160 * @return Always PM_RET_OK 00161 */ 00162 PmReturn_t sli_ptoa16(intptr_t value, uint8_t *buf, uint8_t buflen, uint8_t upperCase); 00163 00164 /** 00165 * Formats a 32-bit (single-precision) float as an ascii string. 00166 * 00167 * @param f the float value 00168 * @param buf a pointer to where the formatted string goes 00169 * @param buflen the size of the buffer 00170 * @return Status 00171 */ 00172 PmReturn_t sli_ftoa(float f, uint8_t *buf, uint8_t buflen); 00173 00174 #endif /* __SLI_H__ */
Generated on Tue Jul 12 2022 23:13:47 by 1.7.2