Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sli.c
00001 /* 00002 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall. 00003 # 00004 # This file is part of the PyMite VM. 00005 # The PyMite VM is free software: you can redistribute it and/or modify 00006 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2. 00007 # 00008 # The PyMite VM is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00011 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2 00012 # is seen in the file COPYING in this directory. 00013 */ 00014 00015 00016 #undef __FILE_ID__ 00017 #define __FILE_ID__ 0x11 00018 00019 00020 /** 00021 * \file 00022 * \brief Standard Library Interface 00023 * 00024 * PyMite requires a few functions from a few different 00025 * standard C libraries (memory, string, etc). 00026 */ 00027 00028 00029 #include "pm.h" 00030 00031 00032 /** use Duff's Device or simple for-loop for memcpy. */ 00033 #define USE_DUFFS_DEVICE 0 00034 00035 00036 #if !HAVE_STRING_H 00037 00038 void * 00039 sli_memcpy(unsigned char *to, unsigned char const *from, unsigned int n) 00040 { 00041 unsigned char *tobak; 00042 00043 /* Store init value of to */ 00044 tobak = to; 00045 00046 #if USE_DUFFS_DEVICE 00047 if (n > 0) 00048 { 00049 switch (n & 0x7) 00050 do 00051 { 00052 case 0: 00053 *to++ = *from++; 00054 case 7: 00055 *to++ = *from++; 00056 case 6: 00057 *to++ = *from++; 00058 case 5: 00059 *to++ = *from++; 00060 case 4: 00061 *to++ = *from++; 00062 case 3: 00063 *to++ = *from++; 00064 case 2: 00065 *to++ = *from++; 00066 case 1: 00067 *to++ = *from++; 00068 } 00069 while ((n -= 8) > 0); 00070 } 00071 #else 00072 for (; n > 0; n--) 00073 { 00074 *to = *from; 00075 from++; 00076 to++; 00077 } 00078 #endif /* USE_DUFFS_DEVICE */ 00079 return tobak; 00080 } 00081 00082 00083 int 00084 sli_strlen(char const *s) 00085 { 00086 char const *si = s; 00087 int len = 0; 00088 00089 while (*si++) 00090 { 00091 len++; 00092 } 00093 return len; 00094 } 00095 00096 00097 int 00098 sli_strcmp(char const *s1, char const *s2) 00099 { 00100 /* While not at either strings' end and they're same */ 00101 while ((*s1 != C_NULL) && (*s2 != C_NULL) && (*s1 == *s2)) 00102 { 00103 s1++; 00104 s2++; 00105 } 00106 00107 /* Return string difference */ 00108 return *s1 - *s2; 00109 } 00110 00111 00112 int 00113 sli_strncmp(char const *s1, char const *s2, unsigned int n) 00114 { 00115 unsigned int i = 0; 00116 00117 if (n == 0) 00118 { 00119 return 0; 00120 } 00121 00122 /* Scan n bytes in string */ 00123 for (i = 0; i < n; i++) 00124 { 00125 /* If bytes differ, return difference */ 00126 if (s1[i] != s2[i]) 00127 { 00128 return s1[i] - s2[i]; 00129 } 00130 } 00131 return 0; 00132 } 00133 00134 #endif /* HAVE_STRING_H */ 00135 00136 00137 /* 00138 * This function is moved outside of HAVE_STRING_H because the one in string.h 00139 * will not accept a null value for the second arg 00140 */ 00141 void 00142 sli_memset(unsigned char *dest, char const val, unsigned int n) 00143 { 00144 unsigned int i; 00145 00146 for (i = 0; i < n; i++) 00147 { 00148 *dest = (unsigned char)val; 00149 dest++; 00150 } 00151 }
Generated on Tue Jul 12 2022 17:07:01 by
1.7.2