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.
22 * \brief Standard Library Interface
24 * PyMite requires a few functions from a few different
25 * standard C libraries (memory, string, etc).
26 * If your microcontroller has these libraries,
27 * set the constant to 1 for each library available.
28 * This will cause a macro to be defined which wraps
29 * the function for use by PyMite.
30 * Otherwise, leave the constant as 0, and PyMite will
31 * use the function defined in sli.c
32 * Some of the functions in sli.c will need to be ported
33 * to the target system.
38 * If the compiler has string.h, set HAVE_STRING to 1;
39 * otherwise, leave it 0 and the sli functions will be used.
41 #define HAVE_STRING_H 0
45 * This section creates a macro or a function prototype
46 * for each library based on the corresponding constant.
47 * For example, if HAVE_STRING_H is defined to non-zero,
48 * the system <string.h> file will be included,
49 * and a macro "sli_strcmp" will be created to wrap the strcmp()
50 * function. But if HAVE_STRING is zero, the sli_strcmp()
51 * prototype will be declared and sli_strcmp() must be
52 * implemented in sli.c
59 #define sli_memcpy(to, from, n) memcpy((to), (from), (n))
60 #define sli_strcmp(s1, s2) strcmp((s1),(s2))
61 #define sli_strlen(s) strlen(s)
62 #define sli_strncmp(s1, s2, n) strncmp((s1),(s2),(n))
67 * Copies a block of memory in RAM.
69 * @param to The destination address.
70 * @param from The source address.
71 * @param n The number of bytes to copy.
72 * @return The initial pointer value of the destination
75 void *sli_memcpy(unsigned char *to
, unsigned char const *from
, unsigned int n
);
78 * Compares two strings.
80 * @param s1 Ptr to string 1.
81 * @param s2 Ptr to string 2.
82 * @return value that is less then, equal to or greater than 0
83 * depending on whether s1's encoding is
84 * less than, equal to, or greater than s2's.
86 int sli_strcmp(char const *s1
, char const *s2
);
89 * Obtain string length.
91 * @param s ptr to string.
92 * @return number of bytes in string.
94 int sli_strlen(char const *s
);
97 * Compare strings for a specific length.
99 * @param s1 ptr to string 1.
100 * @param s2 ptr to string 2.
101 * @param n number of chars to compare
102 * @return value that is less then, equal to or greater than 0
103 * depending on whether s1's encoding is
104 * less than, equal to, or greater than s2's.
106 int sli_strncmp(char const *s1
, char const *s2
, unsigned int n
);
108 #endif /* HAVE_STRING_H */
111 * Copy a value repeatedly into a block of memory
113 * @param dest the destination address.
114 * @param val the value.
115 * @param n the number of bytes to copy.
119 void sli_memset(unsigned char *dest
, const char val
, unsigned int n
);
121 #endif /* __SLI_H__ */