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.
Dependents: UsbHostMAX3421E_Hello
macros.h
00001 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program 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. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 00017 Contact information 00018 ------------------- 00019 00020 Circuits At Home, LTD 00021 Web : http://www.circuitsathome.com 00022 e-mail : support@circuitsathome.com 00023 */ 00024 00025 #if !defined(_usb_h_) || defined(MACROS_H) 00026 #error "Never include macros.h directly; include Usb.h instead" 00027 #else 00028 #define MACROS_H 00029 00030 //////////////////////////////////////////////////////////////////////////////// 00031 // HANDY MACROS 00032 //////////////////////////////////////////////////////////////////////////////// 00033 00034 #define VALUE_BETWEEN(v,l,h) (((v)>(l)) && ((v)<(h))) 00035 #define VALUE_WITHIN(v,l,h) (((v)>=(l)) && ((v)<=(h))) 00036 #define output_pgm_message(wa,fp,mp,el) wa = &mp, fp((char *)pgm_read_pointer(wa), el) 00037 #define output_if_between(v,l,h,wa,fp,mp,el) if(VALUE_BETWEEN(v,l,h)) output_pgm_message(wa,fp,mp[v-(l+1)],el); 00038 00039 #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) 00040 #ifndef __BYTE_GRABBING_DEFINED__ 00041 #define __BYTE_GRABBING_DEFINED__ 1 00042 #ifdef BROKEN_OPTIMIZER_LITTLE_ENDIAN 00043 // Note: Use this if your compiler generates horrible assembler! 00044 #define BGRAB0(__usi__) (((uint8_t *)&(__usi__))[0]) 00045 #define BGRAB1(__usi__) (((uint8_t *)&(__usi__))[1]) 00046 #define BGRAB2(__usi__) (((uint8_t *)&(__usi__))[2]) 00047 #define BGRAB3(__usi__) (((uint8_t *)&(__usi__))[3]) 00048 #define BGRAB4(__usi__) (((uint8_t *)&(__usi__))[4]) 00049 #define BGRAB5(__usi__) (((uint8_t *)&(__usi__))[5]) 00050 #define BGRAB6(__usi__) (((uint8_t *)&(__usi__))[6]) 00051 #define BGRAB7(__usi__) (((uint8_t *)&(__usi__))[7]) 00052 #else 00053 // Note: The cast alone to uint8_t is actually enough. 00054 // GCC throws out the "& 0xff", and the size is no different. 00055 // Some compilers need it. 00056 #define BGRAB0(__usi__) ((uint8_t)((__usi__) & 0xff )) 00057 #define BGRAB1(__usi__) ((uint8_t)(((__usi__) >> 8) & 0xff)) 00058 #define BGRAB2(__usi__) ((uint8_t)(((__usi__) >> 16) & 0xff)) 00059 #define BGRAB3(__usi__) ((uint8_t)(((__usi__) >> 24) & 0xff)) 00060 #define BGRAB4(__usi__) ((uint8_t)(((__usi__) >> 32) & 0xff)) 00061 #define BGRAB5(__usi__) ((uint8_t)(((__usi__) >> 40) & 0xff)) 00062 #define BGRAB6(__usi__) ((uint8_t)(((__usi__) >> 48) & 0xff)) 00063 #define BGRAB7(__usi__) ((uint8_t)(((__usi__) >> 56) & 0xff)) 00064 #endif 00065 #define BOVER1(__usi__) ((uint16_t)(__usi__) << 8) 00066 #define BOVER2(__usi__) ((uint32_t)(__usi__) << 16) 00067 #define BOVER3(__usi__) ((uint32_t)(__usi__) << 24) 00068 #define BOVER4(__usi__) ((uint64_t)(__usi__) << 32) 00069 #define BOVER5(__usi__) ((uint64_t)(__usi__) << 40) 00070 #define BOVER6(__usi__) ((uint64_t)(__usi__) << 48) 00071 #define BOVER7(__usi__) ((uint64_t)(__usi__) << 56) 00072 00073 // These are the smallest and fastest ways I have found so far in pure C/C++. 00074 #define BMAKE16(__usc1__,__usc0__) ((uint16_t)((uint16_t)(__usc0__) | (uint16_t)BOVER1(__usc1__))) 00075 #define BMAKE32(__usc3__,__usc2__,__usc1__,__usc0__) ((uint32_t)((uint32_t)(__usc0__) | (uint32_t)BOVER1(__usc1__) | (uint32_t)BOVER2(__usc2__) | (uint32_t)BOVER3(__usc3__))) 00076 #define BMAKE64(__usc7__,__usc6__,__usc5__,__usc4__,__usc3__,__usc2__,__usc1__,__usc0__) ((uint64_t)((uint64_t)__usc0__ | (uint64_t)BOVER1(__usc1__) | (uint64_t)BOVER2(__usc2__) | (uint64_t)BOVER3(__usc3__) | (uint64_t)BOVER4(__usc4__) | (uint64_t)BOVER5(__usc5__) | (uint64_t)BOVER6(__usc6__) | (uint64_t)BOVER1(__usc7__))) 00077 #endif 00078 00079 /* 00080 * Debug macros: Strings are stored in progmem (flash) instead of RAM. 00081 */ 00082 #define USBTRACE(s) (Notify(PSTR(s), 0x80)) 00083 #define USBTRACE1(s,l) (Notify(PSTR(s), l)) 00084 #define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), D_PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80)) 00085 #define USBTRACE3(s,r,l) (Notify(PSTR(s), l), D_PrintHex((r), l), Notify(PSTR("\r\n"), l)) 00086 00087 00088 #endif /* MACROS_H */ 00089
Generated on Tue Jul 12 2022 18:12:04 by
1.7.2