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.
src/vm/sli.h@0:14e5e829dffe, 2010-07-21 (annotated)
- Committer:
- dadaista
- Date:
- Wed Jul 21 12:50:41 2010 +0000
- Revision:
- 0:14e5e829dffe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dadaista | 0:14e5e829dffe | 1 | /* |
dadaista | 0:14e5e829dffe | 2 | # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall. |
dadaista | 0:14e5e829dffe | 3 | # |
dadaista | 0:14e5e829dffe | 4 | # This file is part of the PyMite VM. |
dadaista | 0:14e5e829dffe | 5 | # The PyMite VM is free software: you can redistribute it and/or modify |
dadaista | 0:14e5e829dffe | 6 | # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2. |
dadaista | 0:14e5e829dffe | 7 | # |
dadaista | 0:14e5e829dffe | 8 | # The PyMite VM is distributed in the hope that it will be useful, |
dadaista | 0:14e5e829dffe | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
dadaista | 0:14e5e829dffe | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
dadaista | 0:14e5e829dffe | 11 | # A copy of the GNU GENERAL PUBLIC LICENSE Version 2 |
dadaista | 0:14e5e829dffe | 12 | # is seen in the file COPYING in this directory. |
dadaista | 0:14e5e829dffe | 13 | */ |
dadaista | 0:14e5e829dffe | 14 | |
dadaista | 0:14e5e829dffe | 15 | |
dadaista | 0:14e5e829dffe | 16 | #ifndef __SLI_H__ |
dadaista | 0:14e5e829dffe | 17 | #define __SLI_H__ |
dadaista | 0:14e5e829dffe | 18 | |
dadaista | 0:14e5e829dffe | 19 | |
dadaista | 0:14e5e829dffe | 20 | /** |
dadaista | 0:14e5e829dffe | 21 | * \file |
dadaista | 0:14e5e829dffe | 22 | * \brief Standard Library Interface |
dadaista | 0:14e5e829dffe | 23 | * |
dadaista | 0:14e5e829dffe | 24 | * PyMite requires a few functions from a few different |
dadaista | 0:14e5e829dffe | 25 | * standard C libraries (memory, string, etc). |
dadaista | 0:14e5e829dffe | 26 | * If your microcontroller has these libraries, |
dadaista | 0:14e5e829dffe | 27 | * set the constant to 1 for each library available. |
dadaista | 0:14e5e829dffe | 28 | * This will cause a macro to be defined which wraps |
dadaista | 0:14e5e829dffe | 29 | * the function for use by PyMite. |
dadaista | 0:14e5e829dffe | 30 | * Otherwise, leave the constant as 0, and PyMite will |
dadaista | 0:14e5e829dffe | 31 | * use the function defined in sli.c |
dadaista | 0:14e5e829dffe | 32 | * Some of the functions in sli.c will need to be ported |
dadaista | 0:14e5e829dffe | 33 | * to the target system. |
dadaista | 0:14e5e829dffe | 34 | */ |
dadaista | 0:14e5e829dffe | 35 | |
dadaista | 0:14e5e829dffe | 36 | |
dadaista | 0:14e5e829dffe | 37 | /** |
dadaista | 0:14e5e829dffe | 38 | * If the compiler has string.h, set HAVE_STRING to 1; |
dadaista | 0:14e5e829dffe | 39 | * otherwise, leave it 0 and the sli functions will be used. |
dadaista | 0:14e5e829dffe | 40 | */ |
dadaista | 0:14e5e829dffe | 41 | #define HAVE_STRING_H 0 |
dadaista | 0:14e5e829dffe | 42 | |
dadaista | 0:14e5e829dffe | 43 | |
dadaista | 0:14e5e829dffe | 44 | /* |
dadaista | 0:14e5e829dffe | 45 | * This section creates a macro or a function prototype |
dadaista | 0:14e5e829dffe | 46 | * for each library based on the corresponding constant. |
dadaista | 0:14e5e829dffe | 47 | * For example, if HAVE_STRING_H is defined to non-zero, |
dadaista | 0:14e5e829dffe | 48 | * the system <string.h> file will be included, |
dadaista | 0:14e5e829dffe | 49 | * and a macro "sli_strcmp" will be created to wrap the strcmp() |
dadaista | 0:14e5e829dffe | 50 | * function. But if HAVE_STRING is zero, the sli_strcmp() |
dadaista | 0:14e5e829dffe | 51 | * prototype will be declared and sli_strcmp() must be |
dadaista | 0:14e5e829dffe | 52 | * implemented in sli.c |
dadaista | 0:14e5e829dffe | 53 | */ |
dadaista | 0:14e5e829dffe | 54 | |
dadaista | 0:14e5e829dffe | 55 | #if HAVE_STRING_H |
dadaista | 0:14e5e829dffe | 56 | |
dadaista | 0:14e5e829dffe | 57 | #include <string.h> |
dadaista | 0:14e5e829dffe | 58 | |
dadaista | 0:14e5e829dffe | 59 | #define sli_memcpy(to, from, n) memcpy((to), (from), (n)) |
dadaista | 0:14e5e829dffe | 60 | #define sli_strcmp(s1, s2) strcmp((s1),(s2)) |
dadaista | 0:14e5e829dffe | 61 | #define sli_strlen(s) strlen(s) |
dadaista | 0:14e5e829dffe | 62 | #define sli_strncmp(s1, s2, n) strncmp((s1),(s2),(n)) |
dadaista | 0:14e5e829dffe | 63 | |
dadaista | 0:14e5e829dffe | 64 | #else |
dadaista | 0:14e5e829dffe | 65 | |
dadaista | 0:14e5e829dffe | 66 | /** |
dadaista | 0:14e5e829dffe | 67 | * Copies a block of memory in RAM. |
dadaista | 0:14e5e829dffe | 68 | * |
dadaista | 0:14e5e829dffe | 69 | * @param to The destination address. |
dadaista | 0:14e5e829dffe | 70 | * @param from The source address. |
dadaista | 0:14e5e829dffe | 71 | * @param n The number of bytes to copy. |
dadaista | 0:14e5e829dffe | 72 | * @return The initial pointer value of the destination |
dadaista | 0:14e5e829dffe | 73 | * @see mem_copy |
dadaista | 0:14e5e829dffe | 74 | */ |
dadaista | 0:14e5e829dffe | 75 | void *sli_memcpy(unsigned char *to, unsigned char const *from, unsigned int n); |
dadaista | 0:14e5e829dffe | 76 | |
dadaista | 0:14e5e829dffe | 77 | /** |
dadaista | 0:14e5e829dffe | 78 | * Compares two strings. |
dadaista | 0:14e5e829dffe | 79 | * |
dadaista | 0:14e5e829dffe | 80 | * @param s1 Ptr to string 1. |
dadaista | 0:14e5e829dffe | 81 | * @param s2 Ptr to string 2. |
dadaista | 0:14e5e829dffe | 82 | * @return value that is less then, equal to or greater than 0 |
dadaista | 0:14e5e829dffe | 83 | * depending on whether s1's encoding is |
dadaista | 0:14e5e829dffe | 84 | * less than, equal to, or greater than s2's. |
dadaista | 0:14e5e829dffe | 85 | */ |
dadaista | 0:14e5e829dffe | 86 | int sli_strcmp(char const *s1, char const *s2); |
dadaista | 0:14e5e829dffe | 87 | |
dadaista | 0:14e5e829dffe | 88 | /** |
dadaista | 0:14e5e829dffe | 89 | * Obtain string length. |
dadaista | 0:14e5e829dffe | 90 | * |
dadaista | 0:14e5e829dffe | 91 | * @param s ptr to string. |
dadaista | 0:14e5e829dffe | 92 | * @return number of bytes in string. |
dadaista | 0:14e5e829dffe | 93 | */ |
dadaista | 0:14e5e829dffe | 94 | int sli_strlen(char const *s); |
dadaista | 0:14e5e829dffe | 95 | |
dadaista | 0:14e5e829dffe | 96 | /** |
dadaista | 0:14e5e829dffe | 97 | * Compare strings for a specific length. |
dadaista | 0:14e5e829dffe | 98 | * |
dadaista | 0:14e5e829dffe | 99 | * @param s1 ptr to string 1. |
dadaista | 0:14e5e829dffe | 100 | * @param s2 ptr to string 2. |
dadaista | 0:14e5e829dffe | 101 | * @param n number of chars to compare |
dadaista | 0:14e5e829dffe | 102 | * @return value that is less then, equal to or greater than 0 |
dadaista | 0:14e5e829dffe | 103 | * depending on whether s1's encoding is |
dadaista | 0:14e5e829dffe | 104 | * less than, equal to, or greater than s2's. |
dadaista | 0:14e5e829dffe | 105 | */ |
dadaista | 0:14e5e829dffe | 106 | int sli_strncmp(char const *s1, char const *s2, unsigned int n); |
dadaista | 0:14e5e829dffe | 107 | |
dadaista | 0:14e5e829dffe | 108 | #endif /* HAVE_STRING_H */ |
dadaista | 0:14e5e829dffe | 109 | |
dadaista | 0:14e5e829dffe | 110 | /** |
dadaista | 0:14e5e829dffe | 111 | * Copy a value repeatedly into a block of memory |
dadaista | 0:14e5e829dffe | 112 | * |
dadaista | 0:14e5e829dffe | 113 | * @param dest the destination address. |
dadaista | 0:14e5e829dffe | 114 | * @param val the value. |
dadaista | 0:14e5e829dffe | 115 | * @param n the number of bytes to copy. |
dadaista | 0:14e5e829dffe | 116 | * @return Nothing |
dadaista | 0:14e5e829dffe | 117 | * @see memset |
dadaista | 0:14e5e829dffe | 118 | */ |
dadaista | 0:14e5e829dffe | 119 | void sli_memset(unsigned char *dest, const char val, unsigned int n); |
dadaista | 0:14e5e829dffe | 120 | |
dadaista | 0:14e5e829dffe | 121 | #endif /* __SLI_H__ */ |