code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
/* The standard CSS for doxygen */ body, table, div, p, dl { font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif; font-size: 12px; } /* @group Heading Levels */ h1 { font-size: 150%; } h2 { font-size: 120%; } h3 { font-size: 100%; } dt { font-weight: bold; } div.multicol { -moz-column-gap: 1em; -webkit-column-gap: 1em; -moz-column-count: 3; -webkit-column-count: 3; } p.startli, p.startdd, p.starttd { margin-top: 2px; } p.endli { margin-bottom: 0px; } p.enddd { margin-bottom: 4px; } p.endtd { margin-bottom: 2px; } /* @end */ caption { font-weight: bold; } span.legend { font-size: 70%; text-align: center; } h3.version { font-size: 90%; text-align: center; } div.qindex, div.navtab{ background-color: #EBEFF6; border: 1px solid #A3B4D7; text-align: center; margin: 2px; padding: 2px; } div.qindex, div.navpath { width: 100%; line-height: 140%; } div.navtab { margin-right: 15px; } /* @group Link Styling */ a { color: #3D578C; font-weight: normal; text-decoration: none; } .contents a:visited { color: #4665A2; } a:hover { text-decoration: underline; } a.qindex { font-weight: bold; } a.qindexHL { font-weight: bold; background-color: #9CAFD4; color: #ffffff; border: 1px double #869DCA; } .contents a.qindexHL:visited { color: #ffffff; } a.el { font-weight: bold; } a.elRef { } a.code { color: #4665A2; } a.codeRef { color: #4665A2; } /* @end */ dl.el { margin-left: -1cm; } .fragment { font-family: monospace, fixed; font-size: 105%; } pre.fragment { border: 1px solid #C4CFE5; background-color: #FBFCFD; padding: 4px 6px; margin: 4px 8px 4px 2px; overflow: auto; word-wrap: break-word; font-size: 9pt; line-height: 125%; } div.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px; padding: 0.2em; border: solid thin #333; border-radius: 0.5em; -webkit-border-radius: .5em; -moz-border-radius: .5em; box-shadow: 2px 2px 3px #999; -webkit-box-shadow: 2px 2px 3px #999; -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444)); background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000); } div.groupHeader { margin-left: 16px; margin-top: 12px; font-weight: bold; } div.groupText { margin-left: 16px; font-style: italic; } body { background: white; color: black; margin: 0; } div.contents { margin-top: 10px; margin-left: 10px; margin-right: 10px; } td.indexkey { background-color: #EBEFF6; font-weight: bold; border: 1px solid #C4CFE5; margin: 2px 0px 2px 0; padding: 2px 10px; } td.indexvalue { background-color: #EBEFF6; border: 1px solid #C4CFE5; padding: 2px 10px; margin: 2px 0px; } tr.memlist { background-color: #EEF1F7; } p.formulaDsp { text-align: center; } img.formulaDsp { } img.formulaInl { vertical-align: middle; } div.center { text-align: center; margin-top: 0px; margin-bottom: 0px; padding: 0px; } div.center img { border: 0px; } address.footer { text-align: right; padding-right: 12px; } img.footer { border: 0px; vertical-align: middle; } /* @group Code Colorization */ span.keyword { color: #008000 } span.keywordtype { color: #604020 } span.keywordflow { color: #e08000 } span.comment { color: #800000 } span.preprocessor { color: #806020 } span.stringliteral { color: #002080 } span.charliteral { color: #008080 } span.vhdldigit { color: #ff00ff } span.vhdlchar { color: #000000 } span.vhdlkeyword { color: #700070 } span.vhdllogic { color: #ff0000 } /* @end */ /* .search { color: #003399; font-weight: bold; } form.search { margin-bottom: 0px; margin-top: 0px; } input.search { font-size: 75%; color: #000080; font-weight: normal; background-color: #e8eef2; } */ td.tiny { font-size: 75%; } .dirtab { padding: 4px; border-collapse: collapse; border: 1px solid #A3B4D7; } th.dirtab { background: #EBEFF6; font-weight: bold; } hr { height: 0px; border: none; border-top: 1px solid #4A6AAA; } hr.footer { height: 1px; } /* @group Member Descriptions */ table.memberdecls { border-spacing: 0px; padding: 0px; } .mdescLeft, .mdescRight, .memItemLeft, .memItemRight, .memTemplItemLeft, .memTemplItemRight, .memTemplParams { background-color: #F9FAFC; border: none; margin: 4px; padding: 1px 0 0 8px; } .mdescLeft, .mdescRight { padding: 0px 8px 4px 8px; color: #555; } .memItemLeft, .memItemRight, .memTemplParams { border-top: 1px solid #C4CFE5; } .memItemLeft, .memTemplItemLeft { white-space: nowrap; } .memTemplParams { color: #4665A2; white-space: nowrap; } /* @end */ /* @group Member Details */ /* Styles for detailed member documentation */ .memtemplate { font-size: 80%; color: #4665A2; font-weight: normal; margin-left: 9px; } .memnav { background-color: #EBEFF6; border: 1px solid #A3B4D7; text-align: center; margin: 2px; margin-right: 15px; padding: 2px; } .memitem { padding: 0; margin-bottom: 10px; } .memname { white-space: nowrap; font-weight: bold; margin-left: 6px; } .memproto { border-top: 1px solid #A8B8D9; border-left: 1px solid #A8B8D9; border-right: 1px solid #A8B8D9; padding: 6px 0px 6px 0px; color: #253555; font-weight: bold; text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); /* opera specific markup */ box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); border-top-right-radius: 8px; border-top-left-radius: 8px; /* firefox specific markup */ -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; -moz-border-radius-topright: 8px; -moz-border-radius-topleft: 8px; /* webkit specific markup */ -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); -webkit-border-top-right-radius: 8px; -webkit-border-top-left-radius: 8px; background-image:url('nav_f.png'); background-repeat:repeat-x; background-color: #E2E8F2; } .memdoc { border-bottom: 1px solid #A8B8D9; border-left: 1px solid #A8B8D9; border-right: 1px solid #A8B8D9; padding: 2px 5px; background-color: #FBFCFD; border-top-width: 0; /* opera specific markup */ border-bottom-left-radius: 8px; border-bottom-right-radius: 8px; box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); /* firefox specific markup */ -moz-border-radius-bottomleft: 8px; -moz-border-radius-bottomright: 8px; -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; background-image: -moz-linear-gradient(center top, #FFFFFF 0%, #FFFFFF 60%, #F7F8FB 95%, #EEF1F7); /* webkit specific markup */ -webkit-border-bottom-left-radius: 8px; -webkit-border-bottom-right-radius: 8px; -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); background-image: -webkit-gradient(linear,center top,center bottom,from(#FFFFFF), color-stop(0.6,#FFFFFF), color-stop(0.60,#FFFFFF), color-stop(0.95,#F7F8FB), to(#EEF1F7)); } .paramkey { text-align: right; } .paramtype { white-space: nowrap; } .paramname { color: #602020; white-space: nowrap; } .paramname em { font-style: normal; } .params, .retval, .exception, .tparams { border-spacing: 6px 2px; } .params .paramname, .retval .paramname { font-weight: bold; vertical-align: top; } .params .paramtype { font-style: italic; vertical-align: top; } .params .paramdir { font-family: "courier new",courier,monospace; vertical-align: top; } /* @end */ /* @group Directory (tree) */ /* for the tree view */ .ftvtree { font-family: sans-serif; margin: 0px; } /* these are for tree view when used as main index */ .directory { font-size: 9pt; font-weight: bold; margin: 5px; } .directory h3 { margin: 0px; margin-top: 1em; font-size: 11pt; } /* The following two styles can be used to replace the root node title with an image of your choice. Simply uncomment the next two styles, specify the name of your image and be sure to set 'height' to the proper pixel height of your image. */ /* .directory h3.swap { height: 61px; background-repeat: no-repeat; background-image: url("yourimage.gif"); } .directory h3.swap span { display: none; } */ .directory > h3 { margin-top: 0; } .directory p { margin: 0px; white-space: nowrap; } .directory div { display: none; margin: 0px; } .directory img { vertical-align: -30%; } /* these are for tree view when not used as main index */ .directory-alt { font-size: 100%; font-weight: bold; } .directory-alt h3 { margin: 0px; margin-top: 1em; font-size: 11pt; } .directory-alt > h3 { margin-top: 0; } .directory-alt p { margin: 0px; white-space: nowrap; } .directory-alt div { display: none; margin: 0px; } .directory-alt img { vertical-align: -30%; } /* @end */ div.dynheader { margin-top: 8px; } address { font-style: normal; color: #2A3D61; } table.doxtable { border-collapse:collapse; } table.doxtable td, table.doxtable th { border: 1px solid #2D4068; padding: 3px 7px 2px; } table.doxtable th { background-color: #374F7F; color: #FFFFFF; font-size: 110%; padding-bottom: 4px; padding-top: 5px; text-align:left; } .tabsearch { top: 0px; left: 10px; height: 36px; background-image: url('tab_b.png'); z-index: 101; overflow: hidden; font-size: 13px; } .navpath ul { font-size: 11px; background-image:url('tab_b.png'); background-repeat:repeat-x; height:30px; line-height:30px; color:#8AA0CC; border:solid 1px #C2CDE4; overflow:hidden; margin:0px; padding:0px; } .navpath li { list-style-type:none; float:left; padding-left:10px; padding-right: 15px; background-image:url('bc_s.png'); background-repeat:no-repeat; background-position:right; color:#364D7C; } .navpath a { height:32px; display:block; text-decoration: none; outline: none; } .navpath a:hover { color:#6884BD; } div.summary { float: right; font-size: 8pt; padding-right: 5px; width: 50%; text-align: right; } div.summary a { white-space: nowrap; } div.header { background-image:url('nav_h.png'); background-repeat:repeat-x; background-color: #F9FAFC; margin: 0px; border-bottom: 1px solid #C4CFE5; } div.headertitle { padding: 5px 5px 5px 10px; }
1137519-player
lib/CMSIS/Documentation/DSP_Lib/html/doxygen.css
CSS
lgpl
10,556
/**************************************************************************//** * @file core_cmInstr.h * @brief CMSIS Cortex-M Core Instruction Access Header File * @version V2.10 * @date 19. July 2011 * * @note * Copyright (C) 2009-2011 ARM Limited. All rights reserved. * * @par * ARM Limited (ARM) is supplying this software for use with Cortex-M * processor based microcontrollers. This file can be freely distributed * within development tools that are supporting such ARM based processors. * * @par * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * ******************************************************************************/ #ifndef __CORE_CMINSTR_H #define __CORE_CMINSTR_H /* ########################## Core Instruction Access ######################### */ /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface Access to dedicated instructions @{ */ #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ /* ARM armcc specific functions */ #if (__ARMCC_VERSION < 400677) #error "Please use ARM Compiler Toolchain V4.0.677 or later!" #endif /** \brief No Operation No Operation does nothing. This instruction can be used for code alignment purposes. */ #define __NOP __nop /** \brief Wait For Interrupt Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. */ #define __WFI __wfi /** \brief Wait For Event Wait For Event is a hint instruction that permits the processor to enter a low-power state until one of a number of events occurs. */ #define __WFE __wfe /** \brief Send Event Send Event is a hint instruction. It causes an event to be signaled to the CPU. */ #define __SEV __sev /** \brief Instruction Synchronization Barrier Instruction Synchronization Barrier flushes the pipeline in the processor, so that all instructions following the ISB are fetched from cache or memory, after the instruction has been completed. */ #define __ISB() __isb(0xF) /** \brief Data Synchronization Barrier This function acts as a special kind of Data Memory Barrier. It completes when all explicit memory accesses before this instruction complete. */ #define __DSB() __dsb(0xF) /** \brief Data Memory Barrier This function ensures the apparent order of the explicit memory operations before and after the instruction, without ensuring their completion. */ #define __DMB() __dmb(0xF) /** \brief Reverse byte order (32 bit) This function reverses the byte order in integer value. \param [in] value Value to reverse \return Reversed value */ #define __REV __rev /** \brief Reverse byte order (16 bit) This function reverses the byte order in two unsigned short values. \param [in] value Value to reverse \return Reversed value */ static __INLINE __ASM uint32_t __REV16(uint32_t value) { rev16 r0, r0 bx lr } /** \brief Reverse byte order in signed short value This function reverses the byte order in a signed short value with sign extension to integer. \param [in] value Value to reverse \return Reversed value */ static __INLINE __ASM int32_t __REVSH(int32_t value) { revsh r0, r0 bx lr } #if (__CORTEX_M >= 0x03) /** \brief Reverse bit order of value This function reverses the bit order of the given value. \param [in] value Value to reverse \return Reversed value */ #define __RBIT __rbit /** \brief LDR Exclusive (8 bit) This function performs a exclusive LDR command for 8 bit value. \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) /** \brief LDR Exclusive (16 bit) This function performs a exclusive LDR command for 16 bit values. \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) /** \brief LDR Exclusive (32 bit) This function performs a exclusive LDR command for 32 bit values. \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) /** \brief STR Exclusive (8 bit) This function performs a exclusive STR command for 8 bit values. \param [in] value Value to store \param [in] ptr Pointer to location \return 0 Function succeeded \return 1 Function failed */ #define __STREXB(value, ptr) __strex(value, ptr) /** \brief STR Exclusive (16 bit) This function performs a exclusive STR command for 16 bit values. \param [in] value Value to store \param [in] ptr Pointer to location \return 0 Function succeeded \return 1 Function failed */ #define __STREXH(value, ptr) __strex(value, ptr) /** \brief STR Exclusive (32 bit) This function performs a exclusive STR command for 32 bit values. \param [in] value Value to store \param [in] ptr Pointer to location \return 0 Function succeeded \return 1 Function failed */ #define __STREXW(value, ptr) __strex(value, ptr) /** \brief Remove the exclusive lock This function removes the exclusive lock which is created by LDREX. */ #define __CLREX __clrex /** \brief Signed Saturate This function saturates a signed value. \param [in] value Value to be saturated \param [in] sat Bit position to saturate to (1..32) \return Saturated value */ #define __SSAT __ssat /** \brief Unsigned Saturate This function saturates an unsigned value. \param [in] value Value to be saturated \param [in] sat Bit position to saturate to (0..31) \return Saturated value */ #define __USAT __usat /** \brief Count leading zeros This function counts the number of leading zeros of a data value. \param [in] value Value to count the leading zeros \return number of leading zeros in value */ #define __CLZ __clz #endif /* (__CORTEX_M >= 0x03) */ #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ /* IAR iccarm specific functions */ #include <cmsis_iar.h> #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ /* GNU gcc specific functions */ /** \brief No Operation No Operation does nothing. This instruction can be used for code alignment purposes. */ __attribute__( ( always_inline ) ) static __INLINE void __NOP(void) { __ASM volatile ("nop"); } /** \brief Wait For Interrupt Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. */ __attribute__( ( always_inline ) ) static __INLINE void __WFI(void) { __ASM volatile ("wfi"); } /** \brief Wait For Event Wait For Event is a hint instruction that permits the processor to enter a low-power state until one of a number of events occurs. */ __attribute__( ( always_inline ) ) static __INLINE void __WFE(void) { __ASM volatile ("wfe"); } /** \brief Send Event Send Event is a hint instruction. It causes an event to be signaled to the CPU. */ __attribute__( ( always_inline ) ) static __INLINE void __SEV(void) { __ASM volatile ("sev"); } /** \brief Instruction Synchronization Barrier Instruction Synchronization Barrier flushes the pipeline in the processor, so that all instructions following the ISB are fetched from cache or memory, after the instruction has been completed. */ __attribute__( ( always_inline ) ) static __INLINE void __ISB(void) { __ASM volatile ("isb"); } /** \brief Data Synchronization Barrier This function acts as a special kind of Data Memory Barrier. It completes when all explicit memory accesses before this instruction complete. */ __attribute__( ( always_inline ) ) static __INLINE void __DSB(void) { __ASM volatile ("dsb"); } /** \brief Data Memory Barrier This function ensures the apparent order of the explicit memory operations before and after the instruction, without ensuring their completion. */ __attribute__( ( always_inline ) ) static __INLINE void __DMB(void) { __ASM volatile ("dmb"); } /** \brief Reverse byte order (32 bit) This function reverses the byte order in integer value. \param [in] value Value to reverse \return Reversed value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __REV(uint32_t value) { uint32_t result; __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) ); return(result); } /** \brief Reverse byte order (16 bit) This function reverses the byte order in two unsigned short values. \param [in] value Value to reverse \return Reversed value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __REV16(uint32_t value) { uint32_t result; __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) ); return(result); } /** \brief Reverse byte order in signed short value This function reverses the byte order in a signed short value with sign extension to integer. \param [in] value Value to reverse \return Reversed value */ __attribute__( ( always_inline ) ) static __INLINE int32_t __REVSH(int32_t value) { uint32_t result; __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) ); return(result); } #if (__CORTEX_M >= 0x03) /** \brief Reverse bit order of value This function reverses the bit order of the given value. \param [in] value Value to reverse \return Reversed value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __RBIT(uint32_t value) { uint32_t result; __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); return(result); } /** \brief LDR Exclusive (8 bit) This function performs a exclusive LDR command for 8 bit value. \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ __attribute__( ( always_inline ) ) static __INLINE uint8_t __LDREXB(volatile uint8_t *addr) { uint8_t result; __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) ); return(result); } /** \brief LDR Exclusive (16 bit) This function performs a exclusive LDR command for 16 bit values. \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ __attribute__( ( always_inline ) ) static __INLINE uint16_t __LDREXH(volatile uint16_t *addr) { uint16_t result; __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) ); return(result); } /** \brief LDR Exclusive (32 bit) This function performs a exclusive LDR command for 32 bit values. \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __LDREXW(volatile uint32_t *addr) { uint32_t result; __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) ); return(result); } /** \brief STR Exclusive (8 bit) This function performs a exclusive STR command for 8 bit values. \param [in] value Value to store \param [in] ptr Pointer to location \return 0 Function succeeded \return 1 Function failed */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) { uint32_t result; __ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); return(result); } /** \brief STR Exclusive (16 bit) This function performs a exclusive STR command for 16 bit values. \param [in] value Value to store \param [in] ptr Pointer to location \return 0 Function succeeded \return 1 Function failed */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) { uint32_t result; __ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); return(result); } /** \brief STR Exclusive (32 bit) This function performs a exclusive STR command for 32 bit values. \param [in] value Value to store \param [in] ptr Pointer to location \return 0 Function succeeded \return 1 Function failed */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) { uint32_t result; __ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); return(result); } /** \brief Remove the exclusive lock This function removes the exclusive lock which is created by LDREX. */ __attribute__( ( always_inline ) ) static __INLINE void __CLREX(void) { __ASM volatile ("clrex"); } /** \brief Signed Saturate This function saturates a signed value. \param [in] value Value to be saturated \param [in] sat Bit position to saturate to (1..32) \return Saturated value */ #define __SSAT(ARG1,ARG2) \ ({ \ uint32_t __RES, __ARG1 = (ARG1); \ __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ __RES; \ }) /** \brief Unsigned Saturate This function saturates an unsigned value. \param [in] value Value to be saturated \param [in] sat Bit position to saturate to (0..31) \return Saturated value */ #define __USAT(ARG1,ARG2) \ ({ \ uint32_t __RES, __ARG1 = (ARG1); \ __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ __RES; \ }) /** \brief Count leading zeros This function counts the number of leading zeros of a data value. \param [in] value Value to count the leading zeros \return number of leading zeros in value */ __attribute__( ( always_inline ) ) static __INLINE uint8_t __CLZ(uint32_t value) { uint8_t result; __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) ); return(result); } #endif /* (__CORTEX_M >= 0x03) */ #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ /* TASKING carm specific functions */ /* * The CMSIS functions have been implemented as intrinsics in the compiler. * Please use "carm -?i" to get an up to date list of all intrinsics, * Including the CMSIS ones. */ #endif /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ #endif /* __CORE_CMINSTR_H */
1137519-player
lib/CMSIS/Include/core_cmInstr.h
C
lgpl
16,108
/**************************************************************************//** * @file core_cm3.h * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File * @version V2.10 * @date 19. July 2011 * * @note * Copyright (C) 2009-2011 ARM Limited. All rights reserved. * * @par * ARM Limited (ARM) is supplying this software for use with Cortex-M * processor based microcontrollers. This file can be freely distributed * within development tools that are supporting such ARM based processors. * * @par * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * ******************************************************************************/ #if defined ( __ICCARM__ ) #pragma system_include /* treat file as system include file for MISRA check */ #endif #ifdef __cplusplus extern "C" { #endif #ifndef __CORE_CM3_H_GENERIC #define __CORE_CM3_H_GENERIC /** \mainpage CMSIS Cortex-M3 This documentation describes the CMSIS Cortex-M Core Peripheral Access Layer. It consists of: - Cortex-M Core Register Definitions - Cortex-M functions - Cortex-M instructions The CMSIS Cortex-M3 Core Peripheral Access Layer contains C and assembly functions that ease access to the Cortex-M Core */ /** \defgroup CMSIS_MISRA_Exceptions CMSIS MISRA-C:2004 Compliance Exceptions CMSIS violates following MISRA-C2004 Rules: - Violates MISRA 2004 Required Rule 8.5, object/function definition in header file.<br> Function definitions in header files are used to allow 'inlining'. - Violates MISRA 2004 Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br> Unions are used for effective representation of core registers. - Violates MISRA 2004 Advisory Rule 19.7, Function-like macro defined.<br> Function-like macros are used to allow more efficient code. */ /******************************************************************************* * CMSIS definitions ******************************************************************************/ /** \defgroup CMSIS_core_definitions CMSIS Core Definitions This file defines all structures and symbols for CMSIS core: - CMSIS version number - Cortex-M core - Cortex-M core Revision Number @{ */ /* CMSIS CM3 definitions */ #define __CM3_CMSIS_VERSION_MAIN (0x02) /*!< [31:16] CMSIS HAL main version */ #define __CM3_CMSIS_VERSION_SUB (0x10) /*!< [15:0] CMSIS HAL sub version */ #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */ #define __CORTEX_M (0x03) /*!< Cortex core */ #if defined ( __CC_ARM ) #define __ASM __asm /*!< asm keyword for ARM Compiler */ #define __INLINE __inline /*!< inline keyword for ARM Compiler */ #elif defined ( __ICCARM__ ) #define __ASM __asm /*!< asm keyword for IAR Compiler */ #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ #elif defined ( __GNUC__ ) #define __ASM __asm /*!< asm keyword for GNU Compiler */ #define __INLINE inline /*!< inline keyword for GNU Compiler */ #elif defined ( __TASKING__ ) #define __ASM __asm /*!< asm keyword for TASKING Compiler */ #define __INLINE inline /*!< inline keyword for TASKING Compiler */ #endif /*!< __FPU_USED to be checked prior to making use of FPU specific registers and functions */ #define __FPU_USED 0 #if defined ( __CC_ARM ) #if defined __TARGET_FPU_VFP #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif #elif defined ( __ICCARM__ ) #if defined __ARMVFP__ #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif #elif defined ( __GNUC__ ) #if defined (__VFP_FP__) && !defined(__SOFTFP__) #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif #elif defined ( __TASKING__ ) /* add preprocessor checks */ #endif #include <stdint.h> /*!< standard types definitions */ #include "core_cmInstr.h" /*!< Core Instruction Access */ #include "core_cmFunc.h" /*!< Core Function Access */ #endif /* __CORE_CM3_H_GENERIC */ #ifndef __CMSIS_GENERIC #ifndef __CORE_CM3_H_DEPENDANT #define __CORE_CM3_H_DEPENDANT /* check device defines and use defaults */ #if defined __CHECK_DEVICE_DEFINES #ifndef __CM3_REV #define __CM3_REV 0x0200 #warning "__CM3_REV not defined in device header file; using default!" #endif #ifndef __MPU_PRESENT #define __MPU_PRESENT 0 #warning "__MPU_PRESENT not defined in device header file; using default!" #endif #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 4 #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" #endif #ifndef __Vendor_SysTickConfig #define __Vendor_SysTickConfig 0 #warning "__Vendor_SysTickConfig not defined in device header file; using default!" #endif #endif /* IO definitions (access restrictions to peripheral registers) */ #ifdef __cplusplus #define __I volatile /*!< defines 'read only' permissions */ #else #define __I volatile const /*!< defines 'read only' permissions */ #endif #define __O volatile /*!< defines 'write only' permissions */ #define __IO volatile /*!< defines 'read / write' permissions */ /*@} end of group CMSIS_core_definitions */ /******************************************************************************* * Register Abstraction ******************************************************************************/ /** \defgroup CMSIS_core_register CMSIS Core Register Core Register contain: - Core Register - Core NVIC Register - Core SCB Register - Core SysTick Register - Core Debug Register - Core MPU Register */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CORE CMSIS Core Type definitions for the Cortex-M Core Registers @{ */ /** \brief Union type to access the Application Program Status Register (APSR). */ typedef union { struct { #if (__CORTEX_M != 0x04) uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */ #else uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ #endif uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ uint32_t N:1; /*!< bit: 31 Negative condition code flag */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } APSR_Type; /** \brief Union type to access the Interrupt Program Status Register (IPSR). */ typedef union { struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } IPSR_Type; /** \brief Union type to access the Special-Purpose Program Status Registers (xPSR). */ typedef union { struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ #if (__CORTEX_M != 0x04) uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ #else uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ #endif uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ uint32_t N:1; /*!< bit: 31 Negative condition code flag */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } xPSR_Type; /** \brief Union type to access the Control Registers (CONTROL). */ typedef union { struct { uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } CONTROL_Type; /*@} end of group CMSIS_CORE */ /** \ingroup CMSIS_core_register \defgroup CMSIS_NVIC CMSIS NVIC Type definitions for the Cortex-M NVIC Registers @{ */ /** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). */ typedef struct { __IO uint32_t ISER[8]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ uint32_t RESERVED0[24]; __IO uint32_t ICER[8]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ uint32_t RSERVED1[24]; __IO uint32_t ISPR[8]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ uint32_t RESERVED2[24]; __IO uint32_t ICPR[8]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ uint32_t RESERVED3[24]; __IO uint32_t IABR[8]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ uint32_t RESERVED4[56]; __IO uint8_t IP[240]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ uint32_t RESERVED5[644]; __O uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ } NVIC_Type; /* Software Triggered Interrupt Register Definitions */ #define NVIC_STIR_INTID_Pos 0 /*!< STIR: INTLINESNUM Position */ #define NVIC_STIR_INTID_Msk (0x1FFUL << NVIC_STIR_INTID_Pos) /*!< STIR: INTLINESNUM Mask */ /*@} end of group CMSIS_NVIC */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SCB CMSIS SCB Type definitions for the Cortex-M System Control Block Registers @{ */ /** \brief Structure type to access the System Control Block (SCB). */ typedef struct { __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ __IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ __IO uint8_t SHP[12]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ __IO uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ __IO uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ __IO uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ __IO uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ __IO uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ __IO uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ __I uint32_t PFR[2]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ __I uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ __I uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ __I uint32_t MMFR[4]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ __I uint32_t ISAR[5]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ uint32_t RESERVED0[5]; __IO uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ } SCB_Type; /* SCB CPUID Register Definitions */ #define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */ #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ #define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */ #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ #define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */ #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ #define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */ #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ #define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */ #define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */ /* SCB Interrupt Control State Register Definitions */ #define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */ #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ #define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */ #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ #define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */ #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ #define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */ #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ #define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */ #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ #define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */ #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ #define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */ #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ #define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */ #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ #define SCB_ICSR_RETTOBASE_Pos 11 /*!< SCB ICSR: RETTOBASE Position */ #define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */ #define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */ #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */ /* SCB Vector Table Offset Register Definitions */ #define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */ #define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ /* SCB Application Interrupt and Reset Control Register Definitions */ #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */ #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ #define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */ #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ #define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */ #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ #define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */ #define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */ #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ #define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */ #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ #define SCB_AIRCR_VECTRESET_Pos 0 /*!< SCB AIRCR: VECTRESET Position */ #define SCB_AIRCR_VECTRESET_Msk (1UL << SCB_AIRCR_VECTRESET_Pos) /*!< SCB AIRCR: VECTRESET Mask */ /* SCB System Control Register Definitions */ #define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */ #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ #define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */ #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ #define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */ #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ /* SCB Configuration Control Register Definitions */ #define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */ #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ #define SCB_CCR_BFHFNMIGN_Pos 8 /*!< SCB CCR: BFHFNMIGN Position */ #define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ #define SCB_CCR_DIV_0_TRP_Pos 4 /*!< SCB CCR: DIV_0_TRP Position */ #define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */ #define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */ #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ #define SCB_CCR_USERSETMPEND_Pos 1 /*!< SCB CCR: USERSETMPEND Position */ #define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ #define SCB_CCR_NONBASETHRDENA_Pos 0 /*!< SCB CCR: NONBASETHRDENA Position */ #define SCB_CCR_NONBASETHRDENA_Msk (1UL << SCB_CCR_NONBASETHRDENA_Pos) /*!< SCB CCR: NONBASETHRDENA Mask */ /* SCB System Handler Control and State Register Definitions */ #define SCB_SHCSR_USGFAULTENA_Pos 18 /*!< SCB SHCSR: USGFAULTENA Position */ #define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ #define SCB_SHCSR_BUSFAULTENA_Pos 17 /*!< SCB SHCSR: BUSFAULTENA Position */ #define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ #define SCB_SHCSR_MEMFAULTENA_Pos 16 /*!< SCB SHCSR: MEMFAULTENA Position */ #define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ #define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */ #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ #define SCB_SHCSR_BUSFAULTPENDED_Pos 14 /*!< SCB SHCSR: BUSFAULTPENDED Position */ #define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ #define SCB_SHCSR_MEMFAULTPENDED_Pos 13 /*!< SCB SHCSR: MEMFAULTPENDED Position */ #define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ #define SCB_SHCSR_USGFAULTPENDED_Pos 12 /*!< SCB SHCSR: USGFAULTPENDED Position */ #define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ #define SCB_SHCSR_SYSTICKACT_Pos 11 /*!< SCB SHCSR: SYSTICKACT Position */ #define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ #define SCB_SHCSR_PENDSVACT_Pos 10 /*!< SCB SHCSR: PENDSVACT Position */ #define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ #define SCB_SHCSR_MONITORACT_Pos 8 /*!< SCB SHCSR: MONITORACT Position */ #define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ #define SCB_SHCSR_SVCALLACT_Pos 7 /*!< SCB SHCSR: SVCALLACT Position */ #define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ #define SCB_SHCSR_USGFAULTACT_Pos 3 /*!< SCB SHCSR: USGFAULTACT Position */ #define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ #define SCB_SHCSR_BUSFAULTACT_Pos 1 /*!< SCB SHCSR: BUSFAULTACT Position */ #define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ #define SCB_SHCSR_MEMFAULTACT_Pos 0 /*!< SCB SHCSR: MEMFAULTACT Position */ #define SCB_SHCSR_MEMFAULTACT_Msk (1UL << SCB_SHCSR_MEMFAULTACT_Pos) /*!< SCB SHCSR: MEMFAULTACT Mask */ /* SCB Configurable Fault Status Registers Definitions */ #define SCB_CFSR_USGFAULTSR_Pos 16 /*!< SCB CFSR: Usage Fault Status Register Position */ #define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ #define SCB_CFSR_BUSFAULTSR_Pos 8 /*!< SCB CFSR: Bus Fault Status Register Position */ #define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ #define SCB_CFSR_MEMFAULTSR_Pos 0 /*!< SCB CFSR: Memory Manage Fault Status Register Position */ #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL << SCB_CFSR_MEMFAULTSR_Pos) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* SCB Hard Fault Status Registers Definitions */ #define SCB_HFSR_DEBUGEVT_Pos 31 /*!< SCB HFSR: DEBUGEVT Position */ #define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ #define SCB_HFSR_FORCED_Pos 30 /*!< SCB HFSR: FORCED Position */ #define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ #define SCB_HFSR_VECTTBL_Pos 1 /*!< SCB HFSR: VECTTBL Position */ #define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ /* SCB Debug Fault Status Register Definitions */ #define SCB_DFSR_EXTERNAL_Pos 4 /*!< SCB DFSR: EXTERNAL Position */ #define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ #define SCB_DFSR_VCATCH_Pos 3 /*!< SCB DFSR: VCATCH Position */ #define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ #define SCB_DFSR_DWTTRAP_Pos 2 /*!< SCB DFSR: DWTTRAP Position */ #define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ #define SCB_DFSR_BKPT_Pos 1 /*!< SCB DFSR: BKPT Position */ #define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ #define SCB_DFSR_HALTED_Pos 0 /*!< SCB DFSR: HALTED Position */ #define SCB_DFSR_HALTED_Msk (1UL << SCB_DFSR_HALTED_Pos) /*!< SCB DFSR: HALTED Mask */ /*@} end of group CMSIS_SCB */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SCnSCB CMSIS System Control and ID Register not in the SCB Type definitions for the Cortex-M System Control and ID Register not in the SCB @{ */ /** \brief Structure type to access the System Control and ID Register not in the SCB. */ typedef struct { uint32_t RESERVED0[1]; __I uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ #if ((defined __CM3_REV) && (__CM3_REV >= 0x200)) __IO uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ #else uint32_t RESERVED1[1]; #endif } SCnSCB_Type; /* Interrupt Controller Type Register Definitions */ #define SCnSCB_ICTR_INTLINESNUM_Pos 0 /*!< ICTR: INTLINESNUM Position */ #define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL << SCnSCB_ICTR_INTLINESNUM_Pos) /*!< ICTR: INTLINESNUM Mask */ /* Auxiliary Control Register Definitions */ #define SCnSCB_ACTLR_DISFOLD_Pos 2 /*!< ACTLR: DISFOLD Position */ #define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ #define SCnSCB_ACTLR_DISDEFWBUF_Pos 1 /*!< ACTLR: DISDEFWBUF Position */ #define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */ #define SCnSCB_ACTLR_DISMCYCINT_Pos 0 /*!< ACTLR: DISMCYCINT Position */ #define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL << SCnSCB_ACTLR_DISMCYCINT_Pos) /*!< ACTLR: DISMCYCINT Mask */ /*@} end of group CMSIS_SCnotSCB */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SysTick CMSIS SysTick Type definitions for the Cortex-M System Timer Registers @{ */ /** \brief Structure type to access the System Timer (SysTick). */ typedef struct { __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ } SysTick_Type; /* SysTick Control / Status Register Definitions */ #define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */ #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ #define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */ #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ #define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */ #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ #define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */ #define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */ /* SysTick Reload Register Definitions */ #define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */ #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */ /* SysTick Current Register Definitions */ #define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */ #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */ /* SysTick Calibration Register Definitions */ #define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */ #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ #define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */ #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ #define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */ #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */ /*@} end of group CMSIS_SysTick */ /** \ingroup CMSIS_core_register \defgroup CMSIS_ITM CMSIS ITM Type definitions for the Cortex-M Instrumentation Trace Macrocell (ITM) @{ */ /** \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). */ typedef struct { __O union { __O uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ __O uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ __O uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ } PORT [32]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ uint32_t RESERVED0[864]; __IO uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ uint32_t RESERVED1[15]; __IO uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ uint32_t RESERVED2[15]; __IO uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ } ITM_Type; /* ITM Trace Privilege Register Definitions */ #define ITM_TPR_PRIVMASK_Pos 0 /*!< ITM TPR: PRIVMASK Position */ #define ITM_TPR_PRIVMASK_Msk (0xFUL << ITM_TPR_PRIVMASK_Pos) /*!< ITM TPR: PRIVMASK Mask */ /* ITM Trace Control Register Definitions */ #define ITM_TCR_BUSY_Pos 23 /*!< ITM TCR: BUSY Position */ #define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ #define ITM_TCR_TraceBusID_Pos 16 /*!< ITM TCR: ATBID Position */ #define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */ #define ITM_TCR_GTSFREQ_Pos 10 /*!< ITM TCR: Global timestamp frequency Position */ #define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ #define ITM_TCR_TSPrescale_Pos 8 /*!< ITM TCR: TSPrescale Position */ #define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */ #define ITM_TCR_SWOENA_Pos 4 /*!< ITM TCR: SWOENA Position */ #define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ #define ITM_TCR_TXENA_Pos 3 /*!< ITM TCR: TXENA Position */ #define ITM_TCR_TXENA_Msk (1UL << ITM_TCR_TXENA_Pos) /*!< ITM TCR: TXENA Mask */ #define ITM_TCR_SYNCENA_Pos 2 /*!< ITM TCR: SYNCENA Position */ #define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ #define ITM_TCR_TSENA_Pos 1 /*!< ITM TCR: TSENA Position */ #define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ #define ITM_TCR_ITMENA_Pos 0 /*!< ITM TCR: ITM Enable bit Position */ #define ITM_TCR_ITMENA_Msk (1UL << ITM_TCR_ITMENA_Pos) /*!< ITM TCR: ITM Enable bit Mask */ /*@}*/ /* end of group CMSIS_ITM */ #if (__MPU_PRESENT == 1) /** \ingroup CMSIS_core_register \defgroup CMSIS_MPU CMSIS MPU Type definitions for the Cortex-M Memory Protection Unit (MPU) @{ */ /** \brief Structure type to access the Memory Protection Unit (MPU). */ typedef struct { __I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ __IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ __IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ __IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ __IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ __IO uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ __IO uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ __IO uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ __IO uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ __IO uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ __IO uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ } MPU_Type; /* MPU Type Register */ #define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */ #define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ #define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */ #define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ #define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */ #define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */ /* MPU Control Register */ #define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */ #define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ #define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */ #define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ #define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */ #define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */ /* MPU Region Number Register */ #define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */ #define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */ /* MPU Region Base Address Register */ #define MPU_RBAR_ADDR_Pos 5 /*!< MPU RBAR: ADDR Position */ #define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ #define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */ #define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ #define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */ #define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */ /* MPU Region Attribute and Size Register */ #define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */ #define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ #define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */ #define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ #define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */ #define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ #define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */ #define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos) /*!< MPU RASR: Region enable bit Disable Mask */ /*@} end of group CMSIS_MPU */ #endif /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug CMSIS Core Debug Type definitions for the Cortex-M Core Debug Registers @{ */ /** \brief Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { __IO uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ __O uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IO uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IO uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register */ #define CoreDebug_DHCSR_DBGKEY_Pos 16 /*!< CoreDebug DHCSR: DBGKEY Position */ #define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ #define CoreDebug_DHCSR_S_RESET_ST_Pos 25 /*!< CoreDebug DHCSR: S_RESET_ST Position */ #define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ #define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24 /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ #define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ #define CoreDebug_DHCSR_S_LOCKUP_Pos 19 /*!< CoreDebug DHCSR: S_LOCKUP Position */ #define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ #define CoreDebug_DHCSR_S_SLEEP_Pos 18 /*!< CoreDebug DHCSR: S_SLEEP Position */ #define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ #define CoreDebug_DHCSR_S_HALT_Pos 17 /*!< CoreDebug DHCSR: S_HALT Position */ #define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ #define CoreDebug_DHCSR_S_REGRDY_Pos 16 /*!< CoreDebug DHCSR: S_REGRDY Position */ #define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ #define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5 /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ #define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ #define CoreDebug_DHCSR_C_MASKINTS_Pos 3 /*!< CoreDebug DHCSR: C_MASKINTS Position */ #define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ #define CoreDebug_DHCSR_C_STEP_Pos 2 /*!< CoreDebug DHCSR: C_STEP Position */ #define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ #define CoreDebug_DHCSR_C_HALT_Pos 1 /*!< CoreDebug DHCSR: C_HALT Position */ #define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ #define CoreDebug_DHCSR_C_DEBUGEN_Pos 0 /*!< CoreDebug DHCSR: C_DEBUGEN Position */ #define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL << CoreDebug_DHCSR_C_DEBUGEN_Pos) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register */ #define CoreDebug_DCRSR_REGWnR_Pos 16 /*!< CoreDebug DCRSR: REGWnR Position */ #define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ #define CoreDebug_DCRSR_REGSEL_Pos 0 /*!< CoreDebug DCRSR: REGSEL Position */ #define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL << CoreDebug_DCRSR_REGSEL_Pos) /*!< CoreDebug DCRSR: REGSEL Mask */ /* Debug Exception and Monitor Control Register */ #define CoreDebug_DEMCR_TRCENA_Pos 24 /*!< CoreDebug DEMCR: TRCENA Position */ #define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ #define CoreDebug_DEMCR_MON_REQ_Pos 19 /*!< CoreDebug DEMCR: MON_REQ Position */ #define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ #define CoreDebug_DEMCR_MON_STEP_Pos 18 /*!< CoreDebug DEMCR: MON_STEP Position */ #define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ #define CoreDebug_DEMCR_MON_PEND_Pos 17 /*!< CoreDebug DEMCR: MON_PEND Position */ #define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ #define CoreDebug_DEMCR_MON_EN_Pos 16 /*!< CoreDebug DEMCR: MON_EN Position */ #define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ #define CoreDebug_DEMCR_VC_HARDERR_Pos 10 /*!< CoreDebug DEMCR: VC_HARDERR Position */ #define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ #define CoreDebug_DEMCR_VC_INTERR_Pos 9 /*!< CoreDebug DEMCR: VC_INTERR Position */ #define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ #define CoreDebug_DEMCR_VC_BUSERR_Pos 8 /*!< CoreDebug DEMCR: VC_BUSERR Position */ #define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ #define CoreDebug_DEMCR_VC_STATERR_Pos 7 /*!< CoreDebug DEMCR: VC_STATERR Position */ #define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ #define CoreDebug_DEMCR_VC_CHKERR_Pos 6 /*!< CoreDebug DEMCR: VC_CHKERR Position */ #define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ #define CoreDebug_DEMCR_VC_NOCPERR_Pos 5 /*!< CoreDebug DEMCR: VC_NOCPERR Position */ #define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ #define CoreDebug_DEMCR_VC_MMERR_Pos 4 /*!< CoreDebug DEMCR: VC_MMERR Position */ #define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ #define CoreDebug_DEMCR_VC_CORERESET_Pos 0 /*!< CoreDebug DEMCR: VC_CORERESET Position */ #define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL << CoreDebug_DEMCR_VC_CORERESET_Pos) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ /*@} end of group CMSIS_CoreDebug */ /** \ingroup CMSIS_core_register @{ */ /* Memory mapping of Cortex-M3 Hardware */ #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ #define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */ #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ #if (__MPU_PRESENT == 1) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ #endif /*@} */ /******************************************************************************* * Hardware Abstraction Layer ******************************************************************************/ /** \defgroup CMSIS_Core_FunctionInterface CMSIS Core Function Interface Core Function Interface contains: - Core NVIC Functions - Core SysTick Functions - Core Debug Functions - Core Register Access Functions */ /* ########################## NVIC functions #################################### */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_NVICFunctions CMSIS Core NVIC Functions @{ */ /** \brief Set Priority Grouping This function sets the priority grouping field using the required unlock sequence. The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. Only values from 0..7 are used. In case of a conflict between priority grouping and available priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. \param [in] PriorityGroup Priority grouping field */ static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) { uint32_t reg_value; uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */ reg_value = SCB->AIRCR; /* read old register configuration */ reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) | (PriorityGroupTmp << 8)); /* Insert write key and priorty group */ SCB->AIRCR = reg_value; } /** \brief Get Priority Grouping This function gets the priority grouping from NVIC Interrupt Controller. Priority grouping is SCB->AIRCR [10:8] PRIGROUP field. \return Priority grouping field */ static __INLINE uint32_t NVIC_GetPriorityGrouping(void) { return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */ } /** \brief Enable External Interrupt This function enables a device specific interrupt in the NVIC interrupt controller. The interrupt number cannot be a negative value. \param [in] IRQn Number of the external interrupt to enable */ static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) { NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */ } /** \brief Disable External Interrupt This function disables a device specific interrupt in the NVIC interrupt controller. The interrupt number cannot be a negative value. \param [in] IRQn Number of the external interrupt to disable */ static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) { NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */ } /** \brief Get Pending Interrupt This function reads the pending register in the NVIC and returns the pending bit for the specified interrupt. \param [in] IRQn Number of the interrupt for get pending \return 0 Interrupt status is not pending \return 1 Interrupt status is pending */ static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) { return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */ } /** \brief Set Pending Interrupt This function sets the pending bit for the specified interrupt. The interrupt number cannot be a negative value. \param [in] IRQn Number of the interrupt for set pending */ static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) { NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */ } /** \brief Clear Pending Interrupt This function clears the pending bit for the specified interrupt. The interrupt number cannot be a negative value. \param [in] IRQn Number of the interrupt for clear pending */ static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) { NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */ } /** \brief Get Active Interrupt This function reads the active register in NVIC and returns the active bit. \param [in] IRQn Number of the interrupt for get active \return 0 Interrupt status is not active \return 1 Interrupt status is active */ static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) { return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */ } /** \brief Set Interrupt Priority This function sets the priority for the specified interrupt. The interrupt number can be positive to specify an external (device specific) interrupt, or negative to specify an internal (core) interrupt. Note: The priority cannot be set for every core interrupt. \param [in] IRQn Number of the interrupt for set priority \param [in] priority Priority to set */ static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) { if(IRQn < 0) { SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M System Interrupts */ else { NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */ } /** \brief Get Interrupt Priority This function reads the priority for the specified interrupt. The interrupt number can be positive to specify an external (device specific) interrupt, or negative to specify an internal (core) interrupt. The returned priority value is automatically aligned to the implemented priority bits of the microcontroller. \param [in] IRQn Number of the interrupt for get priority \return Interrupt Priority */ static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) { if(IRQn < 0) { return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M system interrupts */ else { return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */ } /** \brief Encode Priority This function encodes the priority for an interrupt with the given priority group, preemptive priority value and sub priority value. In case of a conflict between priority grouping and available priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set. The returned priority value can be used for NVIC_SetPriority(...) function \param [in] PriorityGroup Used priority group \param [in] PreemptPriority Preemptive priority value (starting from 0) \param [in] SubPriority Sub priority value (starting from 0) \return Encoded priority for the interrupt */ static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) { uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */ uint32_t PreemptPriorityBits; uint32_t SubPriorityBits; PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp; SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS; return ( ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) | ((SubPriority & ((1 << (SubPriorityBits )) - 1))) ); } /** \brief Decode Priority This function decodes an interrupt priority value with the given priority group to preemptive priority value and sub priority value. In case of a conflict between priority grouping and available priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set. The priority value can be retrieved with NVIC_GetPriority(...) function \param [in] Priority Priority value \param [in] PriorityGroup Used priority group \param [out] pPreemptPriority Preemptive priority value (starting from 0) \param [out] pSubPriority Sub priority value (starting from 0) */ static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority) { uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */ uint32_t PreemptPriorityBits; uint32_t SubPriorityBits; PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp; SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS; *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1); *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1); } /** \brief System Reset This function initiate a system reset request to reset the MCU. */ static __INLINE void NVIC_SystemReset(void) { __DSB(); /* Ensure all outstanding memory accesses included buffered write are completed before reset */ SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */ __DSB(); /* Ensure completion of memory access */ while(1); /* wait until reset */ } /*@} end of CMSIS_Core_NVICFunctions */ /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_SysTickFunctions CMSIS Core SysTick Functions @{ */ #if (__Vendor_SysTickConfig == 0) /** \brief System Tick Configuration This function initialises the system tick timer and its interrupt and start the system tick timer. Counter is in free running mode to generate periodical interrupts. \param [in] ticks Number of ticks between two interrupts \return 0 Function succeeded \return 1 Function failed */ static __INLINE uint32_t SysTick_Config(uint32_t ticks) { if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */ NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */ SysTick->VAL = 0; /* Load the SysTick Counter Value */ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ return (0); /* Function successful */ } #endif /*@} end of CMSIS_Core_SysTickFunctions */ /* ##################################### Debug In/Output function ########################################### */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_core_DebugFunctions CMSIS Core Debug Functions @{ */ extern volatile int32_t ITM_RxBuffer; /*!< external variable to receive characters */ #define ITM_RXBUFFER_EMPTY 0x5AA55AA5 /*!< value identifying ITM_RxBuffer is ready for next character */ /** \brief ITM Send Character This function transmits a character via the ITM channel 0. It just returns when no debugger is connected that has booked the output. It is blocking when a debugger is connected, but the previous character send is not transmitted. \param [in] ch Character to transmit \return Character to transmit */ static __INLINE uint32_t ITM_SendChar (uint32_t ch) { if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && /* Trace enabled */ (ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */ (ITM->TER & (1UL << 0) ) ) /* ITM Port #0 enabled */ { while (ITM->PORT[0].u32 == 0); ITM->PORT[0].u8 = (uint8_t) ch; } return (ch); } /** \brief ITM Receive Character This function inputs a character via external variable ITM_RxBuffer. It just returns when no debugger is connected that has booked the output. It is blocking when a debugger is connected, but the previous character send is not transmitted. \return Received character \return -1 No character received */ static __INLINE int32_t ITM_ReceiveChar (void) { int32_t ch = -1; /* no character available */ if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) { ch = ITM_RxBuffer; ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ } return (ch); } /** \brief ITM Check Character This function checks external variable ITM_RxBuffer whether a character is available or not. It returns '1' if a character is available and '0' if no character is available. \return 0 No character available \return 1 Character available */ static __INLINE int32_t ITM_CheckChar (void) { if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) { return (0); /* no character available */ } else { return (1); /* character available */ } } /*@} end of CMSIS_core_DebugFunctions */ #endif /* __CORE_CM3_H_DEPENDANT */ #endif /* __CMSIS_GENERIC */ #ifdef __cplusplus } #endif
1137519-player
lib/CMSIS/Include/core_cm3.h
C
lgpl
69,722
/* ---------------------------------------------------------------------- * Copyright (C) 2010 ARM Limited. All rights reserved. * * $Date: 15. July 2011 * $Revision: V1.0.10 * * Project: CMSIS DSP Library * Title: arm_math.h * * Description: Public header file for CMSIS DSP Library * * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 * * Version 1.0.10 2011/7/15 * Big Endian support added and Merged M0 and M3/M4 Source code. * * Version 1.0.3 2010/11/29 * Re-organized the CMSIS folders and updated documentation. * * Version 1.0.2 2010/11/11 * Documentation updated. * * Version 1.0.1 2010/10/05 * Production release and review comments incorporated. * * Version 1.0.0 2010/09/20 * Production release and review comments incorporated. * -------------------------------------------------------------------- */ /** \mainpage CMSIS DSP Software Library * * <b>Introduction</b> * * This user manual describes the CMSIS DSP software library, * a suite of common signal processing functions for use on Cortex-M processor based devices. * * The library is divided into a number of modules each covering a specific category: * - Basic math functions * - Fast math functions * - Complex math functions * - Filters * - Matrix functions * - Transforms * - Motor control functions * - Statistical functions * - Support functions * - Interpolation functions * * The library has separate functions for operating on 8-bit integers, 16-bit integers, * 32-bit integer and 32-bit floating-point values. * * <b>Processor Support</b> * * The library is completely written in C and is fully CMSIS compliant. * High performance is achieved through maximum use of Cortex-M4 intrinsics. * * The supplied library source code also builds and runs on the Cortex-M3 and Cortex-M0 processor, * with the DSP intrinsics being emulated through software. * * * <b>Toolchain Support</b> * * The library has been developed and tested with MDK-ARM version 4.21. * The library is being tested in GCC and IAR toolchains and updates on this activity will be made available shortly. * * <b>Using the Library</b> * * The library installer contains prebuilt versions of the libraries in the <code>Lib</code> folder. * - arm_cortexM4lf_math.lib (Little endian and Floating Point Unit on Cortex-M4) * - arm_cortexM4bf_math.lib (Big endian and Floating Point Unit on Cortex-M4) * - arm_cortexM4l_math.lib (Little endian on Cortex-M4) * - arm_cortexM4b_math.lib (Big endian on Cortex-M4) * - arm_cortexM3l_math.lib (Little endian on Cortex-M3) * - arm_cortexM3b_math.lib (Big endian on Cortex-M3) * - arm_cortexM0l_math.lib (Little endian on Cortex-M0) * - arm_cortexM0b_math.lib (Big endian on Cortex-M3) * * The library functions are declared in the public file <code>arm_math.h</code> which is placed in the <code>Include</code> folder. * Simply include this file and link the appropriate library in the application and begin calling the library functions. The Library supports single * public header file <code> arm_math.h</code> for Cortex-M4/M3/M0 with little endian and big endian. Same header file will be used for floating point unit(FPU) variants. * Define the appropriate pre processor MACRO ARM_MATH_CM4 or ARM_MATH_CM3 or * ARM_MATH_CM0 depending on the target processor in the application. * * <b>Examples</b> * * The library ships with a number of examples which demonstrate how to use the library functions. * * <b>Building the Library</b> * * The library installer contains project files to re build libraries on MDK Tool chain in the <code>CMSIS\DSP_Lib\Source\ARM</code> folder. * - arm_cortexM0b_math.uvproj * - arm_cortexM0l_math.uvproj * - arm_cortexM3b_math.uvproj * - arm_cortexM3l_math.uvproj * - arm_cortexM4b_math.uvproj * - arm_cortexM4l_math.uvproj * - arm_cortexM4bf_math.uvproj * - arm_cortexM4lf_math.uvproj * * Each library project have differant pre-processor macros. * * <b>ARM_MATH_CMx:</b> * Define macro ARM_MATH_CM4 for building the library on Cortex-M4 target, ARM_MATH_CM3 for building library on Cortex-M3 target * and ARM_MATH_CM0 for building library on cortex-M0 target. * * <b>ARM_MATH_BIG_ENDIAN:</b> * Define macro ARM_MATH_BIG_ENDIAN to build the library for big endian targets. By default library builds for little endian targets. * * <b>ARM_MATH_MATRIX_CHECK:</b> * Define macro for checking on the input and output sizes of matrices * * <b>ARM_MATH_ROUNDING:</b> * Define macro for rounding on support functions * * <b>__FPU_PRESENT:</b> * Initialize macro __FPU_PRESENT = 1 when building on FPU supported Targets. Enable this macro for M4bf and M4lf libraries * * * The project can be built by opening the appropriate project in MDK-ARM 4.21 chain and defining the optional pre processor MACROs detailed above. * * <b>Copyright Notice</b> * * Copyright (C) 2010 ARM Limited. All rights reserved. */ /** * @defgroup groupMath Basic Math Functions */ /** * @defgroup groupFastMath Fast Math Functions * This set of functions provides a fast approximation to sine, cosine, and square root. * As compared to most of the other functions in the CMSIS math library, the fast math functions * operate on individual values and not arrays. * There are separate functions for Q15, Q31, and floating-point data. * */ /** * @defgroup groupCmplxMath Complex Math Functions * This set of functions operates on complex data vectors. * The data in the complex arrays is stored in an interleaved fashion * (real, imag, real, imag, ...). * In the API functions, the number of samples in a complex array refers * to the number of complex values; the array contains twice this number of * real values. */ /** * @defgroup groupFilters Filtering Functions */ /** * @defgroup groupMatrix Matrix Functions * * This set of functions provides basic matrix math operations. * The functions operate on matrix data structures. For example, * the type * definition for the floating-point matrix structure is shown * below: * <pre> * typedef struct * { * uint16_t numRows; // number of rows of the matrix. * uint16_t numCols; // number of columns of the matrix. * float32_t *pData; // points to the data of the matrix. * } arm_matrix_instance_f32; * </pre> * There are similar definitions for Q15 and Q31 data types. * * The structure specifies the size of the matrix and then points to * an array of data. The array is of size <code>numRows X numCols</code> * and the values are arranged in row order. That is, the * matrix element (i, j) is stored at: * <pre> * pData[i*numCols + j] * </pre> * * \par Init Functions * There is an associated initialization function for each type of matrix * data structure. * The initialization function sets the values of the internal structure fields. * Refer to the function <code>arm_mat_init_f32()</code>, <code>arm_mat_init_q31()</code> * and <code>arm_mat_init_q15()</code> for floating-point, Q31 and Q15 types, respectively. * * \par * Use of the initialization function is optional. However, if initialization function is used * then the instance structure cannot be placed into a const data section. * To place the instance structure in a const data * section, manually initialize the data structure. For example: * <pre> * <code>arm_matrix_instance_f32 S = {nRows, nColumns, pData};</code> * <code>arm_matrix_instance_q31 S = {nRows, nColumns, pData};</code> * <code>arm_matrix_instance_q15 S = {nRows, nColumns, pData};</code> * </pre> * where <code>nRows</code> specifies the number of rows, <code>nColumns</code> * specifies the number of columns, and <code>pData</code> points to the * data array. * * \par Size Checking * By default all of the matrix functions perform size checking on the input and * output matrices. For example, the matrix addition function verifies that the * two input matrices and the output matrix all have the same number of rows and * columns. If the size check fails the functions return: * <pre> * ARM_MATH_SIZE_MISMATCH * </pre> * Otherwise the functions return * <pre> * ARM_MATH_SUCCESS * </pre> * There is some overhead associated with this matrix size checking. * The matrix size checking is enabled via the #define * <pre> * ARM_MATH_MATRIX_CHECK * </pre> * within the library project settings. By default this macro is defined * and size checking is enabled. By changing the project settings and * undefining this macro size checking is eliminated and the functions * run a bit faster. With size checking disabled the functions always * return <code>ARM_MATH_SUCCESS</code>. */ /** * @defgroup groupTransforms Transform Functions */ /** * @defgroup groupController Controller Functions */ /** * @defgroup groupStats Statistics Functions */ /** * @defgroup groupSupport Support Functions */ /** * @defgroup groupInterpolation Interpolation Functions * These functions perform 1- and 2-dimensional interpolation of data. * Linear interpolation is used for 1-dimensional data and * bilinear interpolation is used for 2-dimensional data. */ /** * @defgroup groupExamples Examples */ #ifndef _ARM_MATH_H #define _ARM_MATH_H #define __CMSIS_GENERIC /* disable NVIC and Systick functions */ #if defined (ARM_MATH_CM4) #include "core_cm4.h" #elif defined (ARM_MATH_CM3) #include "core_cm3.h" #elif defined (ARM_MATH_CM0) #include "core_cm0.h" #else #include "ARMCM4.h" #warning "Define either ARM_MATH_CM4 OR ARM_MATH_CM3...By Default building on ARM_MATH_CM4....." #endif #undef __CMSIS_GENERIC /* enable NVIC and Systick functions */ #include "string.h" #include "math.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Macros required for reciprocal calculation in Normalized LMS */ #define DELTA_Q31 (0x100) #define DELTA_Q15 0x5 #define INDEX_MASK 0x0000003F #define PI 3.14159265358979f /** * @brief Macros required for SINE and COSINE Fast math approximations */ #define TABLE_SIZE 256 #define TABLE_SPACING_Q31 0x800000 #define TABLE_SPACING_Q15 0x80 /** * @brief Macros required for SINE and COSINE Controller functions */ /* 1.31(q31) Fixed value of 2/360 */ /* -1 to +1 is divided into 360 values so total spacing is (2/360) */ #define INPUT_SPACING 0xB60B61 /** * @brief Error status returned by some functions in the library. */ typedef enum { ARM_MATH_SUCCESS = 0, /**< No error */ ARM_MATH_ARGUMENT_ERROR = -1, /**< One or more arguments are incorrect */ ARM_MATH_LENGTH_ERROR = -2, /**< Length of data buffer is incorrect */ ARM_MATH_SIZE_MISMATCH = -3, /**< Size of matrices is not compatible with the operation. */ ARM_MATH_NANINF = -4, /**< Not-a-number (NaN) or infinity is generated */ ARM_MATH_SINGULAR = -5, /**< Generated by matrix inversion if the input matrix is singular and cannot be inverted. */ ARM_MATH_TEST_FAILURE = -6 /**< Test Failed */ } arm_status; /** * @brief 8-bit fractional data type in 1.7 format. */ typedef int8_t q7_t; /** * @brief 16-bit fractional data type in 1.15 format. */ typedef int16_t q15_t; /** * @brief 32-bit fractional data type in 1.31 format. */ typedef int32_t q31_t; /** * @brief 64-bit fractional data type in 1.63 format. */ typedef int64_t q63_t; /** * @brief 32-bit floating-point type definition. */ typedef float float32_t; /** * @brief 64-bit floating-point type definition. */ typedef double float64_t; /** * @brief definition to read/write two 16 bit values. */ #define __SIMD32(addr) (*(int32_t **) & (addr)) #if defined (ARM_MATH_CM3) || defined (ARM_MATH_CM0) /** * @brief definition to pack two 16 bit values. */ #define __PKHBT(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0x0000FFFF) | \ (((int32_t)(ARG2) << ARG3) & (int32_t)0xFFFF0000) ) #endif /** * @brief definition to pack four 8 bit values. */ #ifndef ARM_MATH_BIG_ENDIAN #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v0) << 0) & (int32_t)0x000000FF) | \ (((int32_t)(v1) << 8) & (int32_t)0x0000FF00) | \ (((int32_t)(v2) << 16) & (int32_t)0x00FF0000) | \ (((int32_t)(v3) << 24) & (int32_t)0xFF000000) ) #else #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v3) << 0) & (int32_t)0x000000FF) | \ (((int32_t)(v2) << 8) & (int32_t)0x0000FF00) | \ (((int32_t)(v1) << 16) & (int32_t)0x00FF0000) | \ (((int32_t)(v0) << 24) & (int32_t)0xFF000000) ) #endif /** * @brief Clips Q63 to Q31 values. */ static __INLINE q31_t clip_q63_to_q31( q63_t x) { return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ? ((0x7FFFFFFF ^ ((q31_t) (x >> 63)))) : (q31_t) x; } /** * @brief Clips Q63 to Q15 values. */ static __INLINE q15_t clip_q63_to_q15( q63_t x) { return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ? ((0x7FFF ^ ((q15_t) (x >> 63)))) : (q15_t) (x >> 15); } /** * @brief Clips Q31 to Q7 values. */ static __INLINE q7_t clip_q31_to_q7( q31_t x) { return ((q31_t) (x >> 24) != ((q31_t) x >> 23)) ? ((0x7F ^ ((q7_t) (x >> 31)))) : (q7_t) x; } /** * @brief Clips Q31 to Q15 values. */ static __INLINE q15_t clip_q31_to_q15( q31_t x) { return ((q31_t) (x >> 16) != ((q31_t) x >> 15)) ? ((0x7FFF ^ ((q15_t) (x >> 31)))) : (q15_t) x; } /** * @brief Multiplies 32 X 64 and returns 32 bit result in 2.30 format. */ static __INLINE q63_t mult32x64( q63_t x, q31_t y) { return ((((q63_t) (x & 0x00000000FFFFFFFF) * y) >> 32) + (((q63_t) (x >> 32) * y))); } #if defined (ARM_MATH_CM0) && defined ( __CC_ARM ) #define __CLZ __clz #endif #if defined (ARM_MATH_CM0) && ((defined (__ICCARM__)) ||(defined (__GNUC__)) || defined (__TASKING__) ) static __INLINE uint32_t __CLZ(q31_t data); static __INLINE uint32_t __CLZ(q31_t data) { uint32_t count = 0; uint32_t mask = 0x80000000; while((data & mask) == 0) { count += 1u; mask = mask >> 1u; } return(count); } #endif /** * @brief Function to Calculates 1/in(reciprocal) value of Q31 Data type. */ static __INLINE uint32_t arm_recip_q31( q31_t in, q31_t * dst, q31_t * pRecipTable) { uint32_t out, tempVal; uint32_t index, i; uint32_t signBits; if(in > 0) { signBits = __CLZ(in) - 1; } else { signBits = __CLZ(-in) - 1; } /* Convert input sample to 1.31 format */ in = in << signBits; /* calculation of index for initial approximated Val */ index = (uint32_t) (in >> 24u); index = (index & INDEX_MASK); /* 1.31 with exp 1 */ out = pRecipTable[index]; /* calculation of reciprocal value */ /* running approximation for two iterations */ for (i = 0u; i < 2u; i++) { tempVal = (q31_t) (((q63_t) in * out) >> 31u); tempVal = 0x7FFFFFFF - tempVal; /* 1.31 with exp 1 */ //out = (q31_t) (((q63_t) out * tempVal) >> 30u); out = (q31_t) clip_q63_to_q31(((q63_t) out * tempVal) >> 30u); } /* write output */ *dst = out; /* return num of signbits of out = 1/in value */ return (signBits + 1u); } /** * @brief Function to Calculates 1/in(reciprocal) value of Q15 Data type. */ static __INLINE uint32_t arm_recip_q15( q15_t in, q15_t * dst, q15_t * pRecipTable) { uint32_t out = 0, tempVal = 0; uint32_t index = 0, i = 0; uint32_t signBits = 0; if(in > 0) { signBits = __CLZ(in) - 17; } else { signBits = __CLZ(-in) - 17; } /* Convert input sample to 1.15 format */ in = in << signBits; /* calculation of index for initial approximated Val */ index = in >> 8; index = (index & INDEX_MASK); /* 1.15 with exp 1 */ out = pRecipTable[index]; /* calculation of reciprocal value */ /* running approximation for two iterations */ for (i = 0; i < 2; i++) { tempVal = (q15_t) (((q31_t) in * out) >> 15); tempVal = 0x7FFF - tempVal; /* 1.15 with exp 1 */ out = (q15_t) (((q31_t) out * tempVal) >> 14); } /* write output */ *dst = out; /* return num of signbits of out = 1/in value */ return (signBits + 1); } /* * @brief C custom defined intrinisic function for only M0 processors */ #if defined(ARM_MATH_CM0) static __INLINE q31_t __SSAT( q31_t x, uint32_t y) { int32_t posMax, negMin; uint32_t i; posMax = 1; for (i = 0; i < (y - 1); i++) { posMax = posMax * 2; } if(x > 0) { posMax = (posMax - 1); if(x > posMax) { x = posMax; } } else { negMin = -posMax; if(x < negMin) { x = negMin; } } return (x); } #endif /* end of ARM_MATH_CM0 */ /* * @brief C custom defined intrinsic function for M3 and M0 processors */ #if defined (ARM_MATH_CM3) || defined (ARM_MATH_CM0) /* * @brief C custom defined QADD8 for M3 and M0 processors */ static __INLINE q31_t __QADD8( q31_t x, q31_t y) { q31_t sum; q7_t r, s, t, u; r = (char) x; s = (char) y; r = __SSAT((q31_t) (r + s), 8); s = __SSAT(((q31_t) (((x << 16) >> 24) + ((y << 16) >> 24))), 8); t = __SSAT(((q31_t) (((x << 8) >> 24) + ((y << 8) >> 24))), 8); u = __SSAT(((q31_t) ((x >> 24) + (y >> 24))), 8); sum = (((q31_t) u << 24) & 0xFF000000) | (((q31_t) t << 16) & 0x00FF0000) | (((q31_t) s << 8) & 0x0000FF00) | (r & 0x000000FF); return sum; } /* * @brief C custom defined QSUB8 for M3 and M0 processors */ static __INLINE q31_t __QSUB8( q31_t x, q31_t y) { q31_t sum; q31_t r, s, t, u; r = (char) x; s = (char) y; r = __SSAT((r - s), 8); s = __SSAT(((q31_t) (((x << 16) >> 24) - ((y << 16) >> 24))), 8) << 8; t = __SSAT(((q31_t) (((x << 8) >> 24) - ((y << 8) >> 24))), 8) << 16; u = __SSAT(((q31_t) ((x >> 24) - (y >> 24))), 8) << 24; sum = (u & 0xFF000000) | (t & 0x00FF0000) | (s & 0x0000FF00) | (r & 0x000000FF); return sum; } /* * @brief C custom defined QADD16 for M3 and M0 processors */ /* * @brief C custom defined QADD16 for M3 and M0 processors */ static __INLINE q31_t __QADD16( q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (short) x; s = (short) y; r = __SSAT(r + s, 16); s = __SSAT(((q31_t) ((x >> 16) + (y >> 16))), 16) << 16; sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } /* * @brief C custom defined SHADD16 for M3 and M0 processors */ static __INLINE q31_t __SHADD16( q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (short) x; s = (short) y; r = ((r >> 1) + (s >> 1)); s = ((q31_t) ((x >> 17) + (y >> 17))) << 16; sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } /* * @brief C custom defined QSUB16 for M3 and M0 processors */ static __INLINE q31_t __QSUB16( q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (short) x; s = (short) y; r = __SSAT(r - s, 16); s = __SSAT(((q31_t) ((x >> 16) - (y >> 16))), 16) << 16; sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } /* * @brief C custom defined SHSUB16 for M3 and M0 processors */ static __INLINE q31_t __SHSUB16( q31_t x, q31_t y) { q31_t diff; q31_t r, s; r = (short) x; s = (short) y; r = ((r >> 1) - (s >> 1)); s = (((x >> 17) - (y >> 17)) << 16); diff = (s & 0xFFFF0000) | (r & 0x0000FFFF); return diff; } /* * @brief C custom defined QASX for M3 and M0 processors */ static __INLINE q31_t __QASX( q31_t x, q31_t y) { q31_t sum = 0; sum = ((sum + clip_q31_to_q15((q31_t) ((short) (x >> 16) + (short) y))) << 16) + clip_q31_to_q15((q31_t) ((short) x - (short) (y >> 16))); return sum; } /* * @brief C custom defined SHASX for M3 and M0 processors */ static __INLINE q31_t __SHASX( q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (short) x; s = (short) y; r = ((r >> 1) - (y >> 17)); s = (((x >> 17) + (s >> 1)) << 16); sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } /* * @brief C custom defined QSAX for M3 and M0 processors */ static __INLINE q31_t __QSAX( q31_t x, q31_t y) { q31_t sum = 0; sum = ((sum + clip_q31_to_q15((q31_t) ((short) (x >> 16) - (short) y))) << 16) + clip_q31_to_q15((q31_t) ((short) x + (short) (y >> 16))); return sum; } /* * @brief C custom defined SHSAX for M3 and M0 processors */ static __INLINE q31_t __SHSAX( q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (short) x; s = (short) y; r = ((r >> 1) + (y >> 17)); s = (((x >> 17) - (s >> 1)) << 16); sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } /* * @brief C custom defined SMUSDX for M3 and M0 processors */ static __INLINE q31_t __SMUSDX( q31_t x, q31_t y) { return ((q31_t)(((short) x * (short) (y >> 16)) - ((short) (x >> 16) * (short) y))); } /* * @brief C custom defined SMUADX for M3 and M0 processors */ static __INLINE q31_t __SMUADX( q31_t x, q31_t y) { return ((q31_t)(((short) x * (short) (y >> 16)) + ((short) (x >> 16) * (short) y))); } /* * @brief C custom defined QADD for M3 and M0 processors */ static __INLINE q31_t __QADD( q31_t x, q31_t y) { return clip_q63_to_q31((q63_t) x + y); } /* * @brief C custom defined QSUB for M3 and M0 processors */ static __INLINE q31_t __QSUB( q31_t x, q31_t y) { return clip_q63_to_q31((q63_t) x - y); } /* * @brief C custom defined SMLAD for M3 and M0 processors */ static __INLINE q31_t __SMLAD( q31_t x, q31_t y, q31_t sum) { return (sum + ((short) (x >> 16) * (short) (y >> 16)) + ((short) x * (short) y)); } /* * @brief C custom defined SMLADX for M3 and M0 processors */ static __INLINE q31_t __SMLADX( q31_t x, q31_t y, q31_t sum) { return (sum + ((short) (x >> 16) * (short) (y)) + ((short) x * (short) (y >> 16))); } /* * @brief C custom defined SMLSDX for M3 and M0 processors */ static __INLINE q31_t __SMLSDX( q31_t x, q31_t y, q31_t sum) { return (sum - ((short) (x >> 16) * (short) (y)) + ((short) x * (short) (y >> 16))); } /* * @brief C custom defined SMLALD for M3 and M0 processors */ static __INLINE q63_t __SMLALD( q31_t x, q31_t y, q63_t sum) { return (sum + ((short) (x >> 16) * (short) (y >> 16)) + ((short) x * (short) y)); } /* * @brief C custom defined SMLALDX for M3 and M0 processors */ static __INLINE q63_t __SMLALDX( q31_t x, q31_t y, q63_t sum) { return (sum + ((short) (x >> 16) * (short) y)) + ((short) x * (short) (y >> 16)); } /* * @brief C custom defined SMUAD for M3 and M0 processors */ static __INLINE q31_t __SMUAD( q31_t x, q31_t y) { return (((x >> 16) * (y >> 16)) + (((x << 16) >> 16) * ((y << 16) >> 16))); } /* * @brief C custom defined SMUSD for M3 and M0 processors */ static __INLINE q31_t __SMUSD( q31_t x, q31_t y) { return (-((x >> 16) * (y >> 16)) + (((x << 16) >> 16) * ((y << 16) >> 16))); } #endif /* (ARM_MATH_CM3) || defined (ARM_MATH_CM0) */ /** * @brief Instance structure for the Q7 FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ q7_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ } arm_fir_instance_q7; /** * @brief Instance structure for the Q15 FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ } arm_fir_instance_q15; /** * @brief Instance structure for the Q31 FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ } arm_fir_instance_q31; /** * @brief Instance structure for the floating-point FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ } arm_fir_instance_f32; /** * @brief Processing function for the Q7 FIR filter. * @param[in] *S points to an instance of the Q7 FIR filter structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_q7( const arm_fir_instance_q7 * S, q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q7 FIR filter. * @param[in,out] *S points to an instance of the Q7 FIR structure. * @param[in] numTaps Number of filter coefficients in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of samples that are processed. * @return none */ void arm_fir_init_q7( arm_fir_instance_q7 * S, uint16_t numTaps, q7_t * pCoeffs, q7_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q15 FIR filter. * @param[in] *S points to an instance of the Q15 FIR structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_q15( const arm_fir_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Processing function for the fast Q15 FIR filter for Cortex-M3 and Cortex-M4. * @param[in] *S points to an instance of the Q15 FIR filter structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_fast_q15( const arm_fir_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 FIR filter. * @param[in,out] *S points to an instance of the Q15 FIR filter structure. * @param[in] numTaps Number of filter coefficients in the filter. Must be even and greater than or equal to 4. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of samples that are processed at a time. * @return The function returns ARM_MATH_SUCCESS if initialization was successful or ARM_MATH_ARGUMENT_ERROR if * <code>numTaps</code> is not a supported value. */ arm_status arm_fir_init_q15( arm_fir_instance_q15 * S, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR filter. * @param[in] *S points to an instance of the Q31 FIR filter structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_q31( const arm_fir_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Processing function for the fast Q31 FIR filter for Cortex-M3 and Cortex-M4. * @param[in] *S points to an instance of the Q31 FIR structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_fast_q31( const arm_fir_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR filter. * @param[in,out] *S points to an instance of the Q31 FIR structure. * @param[in] numTaps Number of filter coefficients in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of samples that are processed at a time. * @return none. */ void arm_fir_init_q31( arm_fir_instance_q31 * S, uint16_t numTaps, q31_t * pCoeffs, q31_t * pState, uint32_t blockSize); /** * @brief Processing function for the floating-point FIR filter. * @param[in] *S points to an instance of the floating-point FIR structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_f32( const arm_fir_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point FIR filter. * @param[in,out] *S points to an instance of the floating-point FIR filter structure. * @param[in] numTaps Number of filter coefficients in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of samples that are processed at a time. * @return none. */ void arm_fir_init_f32( arm_fir_instance_f32 * S, uint16_t numTaps, float32_t * pCoeffs, float32_t * pState, uint32_t blockSize); /** * @brief Instance structure for the Q15 Biquad cascade filter. */ typedef struct { int8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ q15_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */ q15_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */ int8_t postShift; /**< Additional shift, in bits, applied to each output sample. */ } arm_biquad_casd_df1_inst_q15; /** * @brief Instance structure for the Q31 Biquad cascade filter. */ typedef struct { uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ q31_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */ q31_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */ uint8_t postShift; /**< Additional shift, in bits, applied to each output sample. */ } arm_biquad_casd_df1_inst_q31; /** * @brief Instance structure for the floating-point Biquad cascade filter. */ typedef struct { uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ float32_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */ float32_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */ } arm_biquad_casd_df1_inst_f32; /** * @brief Processing function for the Q15 Biquad cascade filter. * @param[in] *S points to an instance of the Q15 Biquad cascade structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_biquad_cascade_df1_q15( const arm_biquad_casd_df1_inst_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 Biquad cascade filter. * @param[in,out] *S points to an instance of the Q15 Biquad cascade structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format * @return none */ void arm_biquad_cascade_df1_init_q15( arm_biquad_casd_df1_inst_q15 * S, uint8_t numStages, q15_t * pCoeffs, q15_t * pState, int8_t postShift); /** * @brief Fast but less precise processing function for the Q15 Biquad cascade filter for Cortex-M3 and Cortex-M4. * @param[in] *S points to an instance of the Q15 Biquad cascade structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_biquad_cascade_df1_fast_q15( const arm_biquad_casd_df1_inst_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Processing function for the Q31 Biquad cascade filter * @param[in] *S points to an instance of the Q31 Biquad cascade structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_biquad_cascade_df1_q31( const arm_biquad_casd_df1_inst_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Fast but less precise processing function for the Q31 Biquad cascade filter for Cortex-M3 and Cortex-M4. * @param[in] *S points to an instance of the Q31 Biquad cascade structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_biquad_cascade_df1_fast_q31( const arm_biquad_casd_df1_inst_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 Biquad cascade filter. * @param[in,out] *S points to an instance of the Q31 Biquad cascade structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format * @return none */ void arm_biquad_cascade_df1_init_q31( arm_biquad_casd_df1_inst_q31 * S, uint8_t numStages, q31_t * pCoeffs, q31_t * pState, int8_t postShift); /** * @brief Processing function for the floating-point Biquad cascade filter. * @param[in] *S points to an instance of the floating-point Biquad cascade structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_biquad_cascade_df1_f32( const arm_biquad_casd_df1_inst_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point Biquad cascade filter. * @param[in,out] *S points to an instance of the floating-point Biquad cascade structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @return none */ void arm_biquad_cascade_df1_init_f32( arm_biquad_casd_df1_inst_f32 * S, uint8_t numStages, float32_t * pCoeffs, float32_t * pState); /** * @brief Instance structure for the floating-point matrix structure. */ typedef struct { uint16_t numRows; /**< number of rows of the matrix. */ uint16_t numCols; /**< number of columns of the matrix. */ float32_t *pData; /**< points to the data of the matrix. */ } arm_matrix_instance_f32; /** * @brief Instance structure for the Q15 matrix structure. */ typedef struct { uint16_t numRows; /**< number of rows of the matrix. */ uint16_t numCols; /**< number of columns of the matrix. */ q15_t *pData; /**< points to the data of the matrix. */ } arm_matrix_instance_q15; /** * @brief Instance structure for the Q31 matrix structure. */ typedef struct { uint16_t numRows; /**< number of rows of the matrix. */ uint16_t numCols; /**< number of columns of the matrix. */ q31_t *pData; /**< points to the data of the matrix. */ } arm_matrix_instance_q31; /** * @brief Floating-point matrix addition. * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_add_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix addition. * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_add_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix addition. * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_add_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix transpose. * @param[in] *pSrc points to the input matrix * @param[out] *pDst points to the output matrix * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_trans_f32( const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix transpose. * @param[in] *pSrc points to the input matrix * @param[out] *pDst points to the output matrix * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_trans_q15( const arm_matrix_instance_q15 * pSrc, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix transpose. * @param[in] *pSrc points to the input matrix * @param[out] *pDst points to the output matrix * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_trans_q31( const arm_matrix_instance_q31 * pSrc, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix multiplication * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix multiplication * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst, q15_t * pState); /** * @brief Q15 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4 * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @param[in] *pState points to the array for storing intermediate results * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_fast_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst, q15_t * pState); /** * @brief Q31 matrix multiplication * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Q31 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4 * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_fast_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix subtraction * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_sub_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix subtraction * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_sub_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix subtraction * @param[in] *pSrcA points to the first input matrix structure * @param[in] *pSrcB points to the second input matrix structure * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_sub_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix scaling. * @param[in] *pSrc points to the input matrix * @param[in] scale scale factor * @param[out] *pDst points to the output matrix * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_scale_f32( const arm_matrix_instance_f32 * pSrc, float32_t scale, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix scaling. * @param[in] *pSrc points to input matrix * @param[in] scaleFract fractional portion of the scale factor * @param[in] shift number of bits to shift the result by * @param[out] *pDst points to output matrix * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_scale_q15( const arm_matrix_instance_q15 * pSrc, q15_t scaleFract, int32_t shift, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix scaling. * @param[in] *pSrc points to input matrix * @param[in] scaleFract fractional portion of the scale factor * @param[in] shift number of bits to shift the result by * @param[out] *pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_scale_q31( const arm_matrix_instance_q31 * pSrc, q31_t scaleFract, int32_t shift, arm_matrix_instance_q31 * pDst); /** * @brief Q31 matrix initialization. * @param[in,out] *S points to an instance of the floating-point matrix structure. * @param[in] nRows number of rows in the matrix. * @param[in] nColumns number of columns in the matrix. * @param[in] *pData points to the matrix data array. * @return none */ void arm_mat_init_q31( arm_matrix_instance_q31 * S, uint16_t nRows, uint16_t nColumns, q31_t *pData); /** * @brief Q15 matrix initialization. * @param[in,out] *S points to an instance of the floating-point matrix structure. * @param[in] nRows number of rows in the matrix. * @param[in] nColumns number of columns in the matrix. * @param[in] *pData points to the matrix data array. * @return none */ void arm_mat_init_q15( arm_matrix_instance_q15 * S, uint16_t nRows, uint16_t nColumns, q15_t *pData); /** * @brief Floating-point matrix initialization. * @param[in,out] *S points to an instance of the floating-point matrix structure. * @param[in] nRows number of rows in the matrix. * @param[in] nColumns number of columns in the matrix. * @param[in] *pData points to the matrix data array. * @return none */ void arm_mat_init_f32( arm_matrix_instance_f32 * S, uint16_t nRows, uint16_t nColumns, float32_t *pData); /** * @brief Instance structure for the Q15 PID Control. */ typedef struct { q15_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */ #ifdef ARM_MATH_CM0 q15_t A1; q15_t A2; #else q31_t A1; /**< The derived gain A1 = -Kp - 2Kd | Kd.*/ #endif q15_t state[3]; /**< The state array of length 3. */ q15_t Kp; /**< The proportional gain. */ q15_t Ki; /**< The integral gain. */ q15_t Kd; /**< The derivative gain. */ } arm_pid_instance_q15; /** * @brief Instance structure for the Q31 PID Control. */ typedef struct { q31_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */ q31_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */ q31_t A2; /**< The derived gain, A2 = Kd . */ q31_t state[3]; /**< The state array of length 3. */ q31_t Kp; /**< The proportional gain. */ q31_t Ki; /**< The integral gain. */ q31_t Kd; /**< The derivative gain. */ } arm_pid_instance_q31; /** * @brief Instance structure for the floating-point PID Control. */ typedef struct { float32_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */ float32_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */ float32_t A2; /**< The derived gain, A2 = Kd . */ float32_t state[3]; /**< The state array of length 3. */ float32_t Kp; /**< The proportional gain. */ float32_t Ki; /**< The integral gain. */ float32_t Kd; /**< The derivative gain. */ } arm_pid_instance_f32; /** * @brief Initialization function for the floating-point PID Control. * @param[in,out] *S points to an instance of the PID structure. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. * @return none. */ void arm_pid_init_f32( arm_pid_instance_f32 * S, int32_t resetStateFlag); /** * @brief Reset function for the floating-point PID Control. * @param[in,out] *S is an instance of the floating-point PID Control structure * @return none */ void arm_pid_reset_f32( arm_pid_instance_f32 * S); /** * @brief Initialization function for the Q31 PID Control. * @param[in,out] *S points to an instance of the Q15 PID structure. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. * @return none. */ void arm_pid_init_q31( arm_pid_instance_q31 * S, int32_t resetStateFlag); /** * @brief Reset function for the Q31 PID Control. * @param[in,out] *S points to an instance of the Q31 PID Control structure * @return none */ void arm_pid_reset_q31( arm_pid_instance_q31 * S); /** * @brief Initialization function for the Q15 PID Control. * @param[in,out] *S points to an instance of the Q15 PID structure. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. * @return none. */ void arm_pid_init_q15( arm_pid_instance_q15 * S, int32_t resetStateFlag); /** * @brief Reset function for the Q15 PID Control. * @param[in,out] *S points to an instance of the q15 PID Control structure * @return none */ void arm_pid_reset_q15( arm_pid_instance_q15 * S); /** * @brief Instance structure for the floating-point Linear Interpolate function. */ typedef struct { uint32_t nValues; float32_t x1; float32_t xSpacing; float32_t *pYData; /**< pointer to the table of Y values */ } arm_linear_interp_instance_f32; /** * @brief Instance structure for the floating-point bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ float32_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_f32; /** * @brief Instance structure for the Q31 bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ q31_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_q31; /** * @brief Instance structure for the Q15 bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ q15_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_q15; /** * @brief Instance structure for the Q15 bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ q7_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_q7; /** * @brief Q7 vector multiplication. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_mult_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); /** * @brief Q15 vector multiplication. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_mult_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector multiplication. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_mult_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); /** * @brief Floating-point vector multiplication. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_mult_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); /** * @brief Instance structure for the Q15 CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ q15_t *pTwiddle; /**< points to the twiddle factor table. */ uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ } arm_cfft_radix4_instance_q15; /** * @brief Instance structure for the Q31 CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ q31_t *pTwiddle; /**< points to the twiddle factor table. */ uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ } arm_cfft_radix4_instance_q31; /** * @brief Instance structure for the floating-point CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ float32_t *pTwiddle; /**< points to the twiddle factor table. */ uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ float32_t onebyfftLen; /**< value of 1/fftLen. */ } arm_cfft_radix4_instance_f32; /** * @brief Processing function for the Q15 CFFT/CIFFT. * @param[in] *S points to an instance of the Q15 CFFT/CIFFT structure. * @param[in, out] *pSrc points to the complex data buffer. Processing occurs in-place. * @return none. */ void arm_cfft_radix4_q15( const arm_cfft_radix4_instance_q15 * S, q15_t * pSrc); /** * @brief Initialization function for the Q15 CFFT/CIFFT. * @param[in,out] *S points to an instance of the Q15 CFFT/CIFFT structure. * @param[in] fftLen length of the FFT. * @param[in] ifftFlag flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLen</code> is not a supported value. */ arm_status arm_cfft_radix4_init_q15( arm_cfft_radix4_instance_q15 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /** * @brief Processing function for the Q31 CFFT/CIFFT. * @param[in] *S points to an instance of the Q31 CFFT/CIFFT structure. * @param[in, out] *pSrc points to the complex data buffer. Processing occurs in-place. * @return none. */ void arm_cfft_radix4_q31( const arm_cfft_radix4_instance_q31 * S, q31_t * pSrc); /** * @brief Initialization function for the Q31 CFFT/CIFFT. * @param[in,out] *S points to an instance of the Q31 CFFT/CIFFT structure. * @param[in] fftLen length of the FFT. * @param[in] ifftFlag flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLen</code> is not a supported value. */ arm_status arm_cfft_radix4_init_q31( arm_cfft_radix4_instance_q31 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /** * @brief Processing function for the floating-point CFFT/CIFFT. * @param[in] *S points to an instance of the floating-point CFFT/CIFFT structure. * @param[in, out] *pSrc points to the complex data buffer. Processing occurs in-place. * @return none. */ void arm_cfft_radix4_f32( const arm_cfft_radix4_instance_f32 * S, float32_t * pSrc); /** * @brief Initialization function for the floating-point CFFT/CIFFT. * @param[in,out] *S points to an instance of the floating-point CFFT/CIFFT structure. * @param[in] fftLen length of the FFT. * @param[in] ifftFlag flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLen</code> is not a supported value. */ arm_status arm_cfft_radix4_init_f32( arm_cfft_radix4_instance_f32 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /*---------------------------------------------------------------------- * Internal functions prototypes FFT function ----------------------------------------------------------------------*/ /** * @brief Core function for the floating-point CFFT butterfly process. * @param[in, out] *pSrc points to the in-place buffer of floating-point data type. * @param[in] fftLen length of the FFT. * @param[in] *pCoef points to the twiddle coefficient buffer. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. * @return none. */ void arm_radix4_butterfly_f32( float32_t * pSrc, uint16_t fftLen, float32_t * pCoef, uint16_t twidCoefModifier); /** * @brief Core function for the floating-point CIFFT butterfly process. * @param[in, out] *pSrc points to the in-place buffer of floating-point data type. * @param[in] fftLen length of the FFT. * @param[in] *pCoef points to twiddle coefficient buffer. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. * @param[in] onebyfftLen value of 1/fftLen. * @return none. */ void arm_radix4_butterfly_inverse_f32( float32_t * pSrc, uint16_t fftLen, float32_t * pCoef, uint16_t twidCoefModifier, float32_t onebyfftLen); /** * @brief In-place bit reversal function. * @param[in, out] *pSrc points to the in-place buffer of floating-point data type. * @param[in] fftSize length of the FFT. * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table. * @param[in] *pBitRevTab points to the bit reversal table. * @return none. */ void arm_bitreversal_f32( float32_t *pSrc, uint16_t fftSize, uint16_t bitRevFactor, uint16_t *pBitRevTab); /** * @brief Core function for the Q31 CFFT butterfly process. * @param[in, out] *pSrc points to the in-place buffer of Q31 data type. * @param[in] fftLen length of the FFT. * @param[in] *pCoef points to twiddle coefficient buffer. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. * @return none. */ void arm_radix4_butterfly_q31( q31_t *pSrc, uint32_t fftLen, q31_t *pCoef, uint32_t twidCoefModifier); /** * @brief Core function for the Q31 CIFFT butterfly process. * @param[in, out] *pSrc points to the in-place buffer of Q31 data type. * @param[in] fftLen length of the FFT. * @param[in] *pCoef points to twiddle coefficient buffer. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. * @return none. */ void arm_radix4_butterfly_inverse_q31( q31_t * pSrc, uint32_t fftLen, q31_t * pCoef, uint32_t twidCoefModifier); /** * @brief In-place bit reversal function. * @param[in, out] *pSrc points to the in-place buffer of Q31 data type. * @param[in] fftLen length of the FFT. * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table * @param[in] *pBitRevTab points to bit reversal table. * @return none. */ void arm_bitreversal_q31( q31_t * pSrc, uint32_t fftLen, uint16_t bitRevFactor, uint16_t *pBitRevTab); /** * @brief Core function for the Q15 CFFT butterfly process. * @param[in, out] *pSrc16 points to the in-place buffer of Q15 data type. * @param[in] fftLen length of the FFT. * @param[in] *pCoef16 points to twiddle coefficient buffer. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. * @return none. */ void arm_radix4_butterfly_q15( q15_t *pSrc16, uint32_t fftLen, q15_t *pCoef16, uint32_t twidCoefModifier); /** * @brief Core function for the Q15 CIFFT butterfly process. * @param[in, out] *pSrc16 points to the in-place buffer of Q15 data type. * @param[in] fftLen length of the FFT. * @param[in] *pCoef16 points to twiddle coefficient buffer. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. * @return none. */ void arm_radix4_butterfly_inverse_q15( q15_t *pSrc16, uint32_t fftLen, q15_t *pCoef16, uint32_t twidCoefModifier); /** * @brief In-place bit reversal function. * @param[in, out] *pSrc points to the in-place buffer of Q15 data type. * @param[in] fftLen length of the FFT. * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table * @param[in] *pBitRevTab points to bit reversal table. * @return none. */ void arm_bitreversal_q15( q15_t * pSrc, uint32_t fftLen, uint16_t bitRevFactor, uint16_t *pBitRevTab); /** * @brief Instance structure for the Q15 RFFT/RIFFT function. */ typedef struct { uint32_t fftLenReal; /**< length of the real FFT. */ uint32_t fftLenBy2; /**< length of the complex FFT. */ uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */ uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */ uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ q15_t *pTwiddleAReal; /**< points to the real twiddle factor table. */ q15_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */ arm_cfft_radix4_instance_q15 *pCfft; /**< points to the complex FFT instance. */ } arm_rfft_instance_q15; /** * @brief Instance structure for the Q31 RFFT/RIFFT function. */ typedef struct { uint32_t fftLenReal; /**< length of the real FFT. */ uint32_t fftLenBy2; /**< length of the complex FFT. */ uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */ uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */ uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ q31_t *pTwiddleAReal; /**< points to the real twiddle factor table. */ q31_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */ arm_cfft_radix4_instance_q31 *pCfft; /**< points to the complex FFT instance. */ } arm_rfft_instance_q31; /** * @brief Instance structure for the floating-point RFFT/RIFFT function. */ typedef struct { uint32_t fftLenReal; /**< length of the real FFT. */ uint16_t fftLenBy2; /**< length of the complex FFT. */ uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */ uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */ uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ float32_t *pTwiddleAReal; /**< points to the real twiddle factor table. */ float32_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */ arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */ } arm_rfft_instance_f32; /** * @brief Processing function for the Q15 RFFT/RIFFT. * @param[in] *S points to an instance of the Q15 RFFT/RIFFT structure. * @param[in] *pSrc points to the input buffer. * @param[out] *pDst points to the output buffer. * @return none. */ void arm_rfft_q15( const arm_rfft_instance_q15 * S, q15_t * pSrc, q15_t * pDst); /** * @brief Initialization function for the Q15 RFFT/RIFFT. * @param[in, out] *S points to an instance of the Q15 RFFT/RIFFT structure. * @param[in] *S_CFFT points to an instance of the Q15 CFFT/CIFFT structure. * @param[in] fftLenReal length of the FFT. * @param[in] ifftFlagR flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported value. */ arm_status arm_rfft_init_q15( arm_rfft_instance_q15 * S, arm_cfft_radix4_instance_q15 * S_CFFT, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag); /** * @brief Processing function for the Q31 RFFT/RIFFT. * @param[in] *S points to an instance of the Q31 RFFT/RIFFT structure. * @param[in] *pSrc points to the input buffer. * @param[out] *pDst points to the output buffer. * @return none. */ void arm_rfft_q31( const arm_rfft_instance_q31 * S, q31_t * pSrc, q31_t * pDst); /** * @brief Initialization function for the Q31 RFFT/RIFFT. * @param[in, out] *S points to an instance of the Q31 RFFT/RIFFT structure. * @param[in, out] *S_CFFT points to an instance of the Q31 CFFT/CIFFT structure. * @param[in] fftLenReal length of the FFT. * @param[in] ifftFlagR flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported value. */ arm_status arm_rfft_init_q31( arm_rfft_instance_q31 * S, arm_cfft_radix4_instance_q31 * S_CFFT, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag); /** * @brief Initialization function for the floating-point RFFT/RIFFT. * @param[in,out] *S points to an instance of the floating-point RFFT/RIFFT structure. * @param[in,out] *S_CFFT points to an instance of the floating-point CFFT/CIFFT structure. * @param[in] fftLenReal length of the FFT. * @param[in] ifftFlagR flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported value. */ arm_status arm_rfft_init_f32( arm_rfft_instance_f32 * S, arm_cfft_radix4_instance_f32 * S_CFFT, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag); /** * @brief Processing function for the floating-point RFFT/RIFFT. * @param[in] *S points to an instance of the floating-point RFFT/RIFFT structure. * @param[in] *pSrc points to the input buffer. * @param[out] *pDst points to the output buffer. * @return none. */ void arm_rfft_f32( const arm_rfft_instance_f32 * S, float32_t * pSrc, float32_t * pDst); /** * @brief Instance structure for the floating-point DCT4/IDCT4 function. */ typedef struct { uint16_t N; /**< length of the DCT4. */ uint16_t Nby2; /**< half of the length of the DCT4. */ float32_t normalize; /**< normalizing factor. */ float32_t *pTwiddle; /**< points to the twiddle factor table. */ float32_t *pCosFactor; /**< points to the cosFactor table. */ arm_rfft_instance_f32 *pRfft; /**< points to the real FFT instance. */ arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */ } arm_dct4_instance_f32; /** * @brief Initialization function for the floating-point DCT4/IDCT4. * @param[in,out] *S points to an instance of floating-point DCT4/IDCT4 structure. * @param[in] *S_RFFT points to an instance of floating-point RFFT/RIFFT structure. * @param[in] *S_CFFT points to an instance of floating-point CFFT/CIFFT structure. * @param[in] N length of the DCT4. * @param[in] Nby2 half of the length of the DCT4. * @param[in] normalize normalizing factor. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported transform length. */ arm_status arm_dct4_init_f32( arm_dct4_instance_f32 * S, arm_rfft_instance_f32 * S_RFFT, arm_cfft_radix4_instance_f32 * S_CFFT, uint16_t N, uint16_t Nby2, float32_t normalize); /** * @brief Processing function for the floating-point DCT4/IDCT4. * @param[in] *S points to an instance of the floating-point DCT4/IDCT4 structure. * @param[in] *pState points to state buffer. * @param[in,out] *pInlineBuffer points to the in-place input and output buffer. * @return none. */ void arm_dct4_f32( const arm_dct4_instance_f32 * S, float32_t * pState, float32_t * pInlineBuffer); /** * @brief Instance structure for the Q31 DCT4/IDCT4 function. */ typedef struct { uint16_t N; /**< length of the DCT4. */ uint16_t Nby2; /**< half of the length of the DCT4. */ q31_t normalize; /**< normalizing factor. */ q31_t *pTwiddle; /**< points to the twiddle factor table. */ q31_t *pCosFactor; /**< points to the cosFactor table. */ arm_rfft_instance_q31 *pRfft; /**< points to the real FFT instance. */ arm_cfft_radix4_instance_q31 *pCfft; /**< points to the complex FFT instance. */ } arm_dct4_instance_q31; /** * @brief Initialization function for the Q31 DCT4/IDCT4. * @param[in,out] *S points to an instance of Q31 DCT4/IDCT4 structure. * @param[in] *S_RFFT points to an instance of Q31 RFFT/RIFFT structure * @param[in] *S_CFFT points to an instance of Q31 CFFT/CIFFT structure * @param[in] N length of the DCT4. * @param[in] Nby2 half of the length of the DCT4. * @param[in] normalize normalizing factor. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length. */ arm_status arm_dct4_init_q31( arm_dct4_instance_q31 * S, arm_rfft_instance_q31 * S_RFFT, arm_cfft_radix4_instance_q31 * S_CFFT, uint16_t N, uint16_t Nby2, q31_t normalize); /** * @brief Processing function for the Q31 DCT4/IDCT4. * @param[in] *S points to an instance of the Q31 DCT4 structure. * @param[in] *pState points to state buffer. * @param[in,out] *pInlineBuffer points to the in-place input and output buffer. * @return none. */ void arm_dct4_q31( const arm_dct4_instance_q31 * S, q31_t * pState, q31_t * pInlineBuffer); /** * @brief Instance structure for the Q15 DCT4/IDCT4 function. */ typedef struct { uint16_t N; /**< length of the DCT4. */ uint16_t Nby2; /**< half of the length of the DCT4. */ q15_t normalize; /**< normalizing factor. */ q15_t *pTwiddle; /**< points to the twiddle factor table. */ q15_t *pCosFactor; /**< points to the cosFactor table. */ arm_rfft_instance_q15 *pRfft; /**< points to the real FFT instance. */ arm_cfft_radix4_instance_q15 *pCfft; /**< points to the complex FFT instance. */ } arm_dct4_instance_q15; /** * @brief Initialization function for the Q15 DCT4/IDCT4. * @param[in,out] *S points to an instance of Q15 DCT4/IDCT4 structure. * @param[in] *S_RFFT points to an instance of Q15 RFFT/RIFFT structure. * @param[in] *S_CFFT points to an instance of Q15 CFFT/CIFFT structure. * @param[in] N length of the DCT4. * @param[in] Nby2 half of the length of the DCT4. * @param[in] normalize normalizing factor. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length. */ arm_status arm_dct4_init_q15( arm_dct4_instance_q15 * S, arm_rfft_instance_q15 * S_RFFT, arm_cfft_radix4_instance_q15 * S_CFFT, uint16_t N, uint16_t Nby2, q15_t normalize); /** * @brief Processing function for the Q15 DCT4/IDCT4. * @param[in] *S points to an instance of the Q15 DCT4 structure. * @param[in] *pState points to state buffer. * @param[in,out] *pInlineBuffer points to the in-place input and output buffer. * @return none. */ void arm_dct4_q15( const arm_dct4_instance_q15 * S, q15_t * pState, q15_t * pInlineBuffer); /** * @brief Floating-point vector addition. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_add_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); /** * @brief Q7 vector addition. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_add_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); /** * @brief Q15 vector addition. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_add_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector addition. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_add_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); /** * @brief Floating-point vector subtraction. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_sub_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); /** * @brief Q7 vector subtraction. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_sub_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); /** * @brief Q15 vector subtraction. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_sub_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector subtraction. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in each vector * @return none. */ void arm_sub_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); /** * @brief Multiplies a floating-point vector by a scalar. * @param[in] *pSrc points to the input vector * @param[in] scale scale factor to be applied * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_scale_f32( float32_t * pSrc, float32_t scale, float32_t * pDst, uint32_t blockSize); /** * @brief Multiplies a Q7 vector by a scalar. * @param[in] *pSrc points to the input vector * @param[in] scaleFract fractional portion of the scale value * @param[in] shift number of bits to shift the result by * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_scale_q7( q7_t * pSrc, q7_t scaleFract, int8_t shift, q7_t * pDst, uint32_t blockSize); /** * @brief Multiplies a Q15 vector by a scalar. * @param[in] *pSrc points to the input vector * @param[in] scaleFract fractional portion of the scale value * @param[in] shift number of bits to shift the result by * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_scale_q15( q15_t * pSrc, q15_t scaleFract, int8_t shift, q15_t * pDst, uint32_t blockSize); /** * @brief Multiplies a Q31 vector by a scalar. * @param[in] *pSrc points to the input vector * @param[in] scaleFract fractional portion of the scale value * @param[in] shift number of bits to shift the result by * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_scale_q31( q31_t * pSrc, q31_t scaleFract, int8_t shift, q31_t * pDst, uint32_t blockSize); /** * @brief Q7 vector absolute value. * @param[in] *pSrc points to the input buffer * @param[out] *pDst points to the output buffer * @param[in] blockSize number of samples in each vector * @return none. */ void arm_abs_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Floating-point vector absolute value. * @param[in] *pSrc points to the input buffer * @param[out] *pDst points to the output buffer * @param[in] blockSize number of samples in each vector * @return none. */ void arm_abs_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Q15 vector absolute value. * @param[in] *pSrc points to the input buffer * @param[out] *pDst points to the output buffer * @param[in] blockSize number of samples in each vector * @return none. */ void arm_abs_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector absolute value. * @param[in] *pSrc points to the input buffer * @param[out] *pDst points to the output buffer * @param[in] blockSize number of samples in each vector * @return none. */ void arm_abs_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Dot product of floating-point vectors. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] *result output result returned here * @return none. */ void arm_dot_prod_f32( float32_t * pSrcA, float32_t * pSrcB, uint32_t blockSize, float32_t * result); /** * @brief Dot product of Q7 vectors. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] *result output result returned here * @return none. */ void arm_dot_prod_q7( q7_t * pSrcA, q7_t * pSrcB, uint32_t blockSize, q31_t * result); /** * @brief Dot product of Q15 vectors. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] *result output result returned here * @return none. */ void arm_dot_prod_q15( q15_t * pSrcA, q15_t * pSrcB, uint32_t blockSize, q63_t * result); /** * @brief Dot product of Q31 vectors. * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] *result output result returned here * @return none. */ void arm_dot_prod_q31( q31_t * pSrcA, q31_t * pSrcB, uint32_t blockSize, q63_t * result); /** * @brief Shifts the elements of a Q7 vector a specified number of bits. * @param[in] *pSrc points to the input vector * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_shift_q7( q7_t * pSrc, int8_t shiftBits, q7_t * pDst, uint32_t blockSize); /** * @brief Shifts the elements of a Q15 vector a specified number of bits. * @param[in] *pSrc points to the input vector * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_shift_q15( q15_t * pSrc, int8_t shiftBits, q15_t * pDst, uint32_t blockSize); /** * @brief Shifts the elements of a Q31 vector a specified number of bits. * @param[in] *pSrc points to the input vector * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_shift_q31( q31_t * pSrc, int8_t shiftBits, q31_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a floating-point vector. * @param[in] *pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_offset_f32( float32_t * pSrc, float32_t offset, float32_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a Q7 vector. * @param[in] *pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_offset_q7( q7_t * pSrc, q7_t offset, q7_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a Q15 vector. * @param[in] *pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_offset_q15( q15_t * pSrc, q15_t offset, q15_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a Q31 vector. * @param[in] *pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_offset_q31( q31_t * pSrc, q31_t offset, q31_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a floating-point vector. * @param[in] *pSrc points to the input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_negate_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a Q7 vector. * @param[in] *pSrc points to the input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_negate_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a Q15 vector. * @param[in] *pSrc points to the input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_negate_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a Q31 vector. * @param[in] *pSrc points to the input vector * @param[out] *pDst points to the output vector * @param[in] blockSize number of samples in the vector * @return none. */ void arm_negate_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a floating-point vector. * @param[in] *pSrc input pointer * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_copy_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a Q7 vector. * @param[in] *pSrc input pointer * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_copy_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a Q15 vector. * @param[in] *pSrc input pointer * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_copy_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a Q31 vector. * @param[in] *pSrc input pointer * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_copy_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a floating-point vector. * @param[in] value input value to be filled * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_fill_f32( float32_t value, float32_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a Q7 vector. * @param[in] value input value to be filled * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_fill_q7( q7_t value, q7_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a Q15 vector. * @param[in] value input value to be filled * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_fill_q15( q15_t value, q15_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a Q31 vector. * @param[in] value input value to be filled * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_fill_q31( q31_t value, q31_t * pDst, uint32_t blockSize); /** * @brief Convolution of floating-point sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the location where the output result is written. Length srcALen+srcBLen-1. * @return none. */ void arm_conv_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst); /** * @brief Convolution of Q15 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the location where the output result is written. Length srcALen+srcBLen-1. * @return none. */ void arm_conv_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length srcALen+srcBLen-1. * @return none. */ void arm_conv_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** * @brief Convolution of Q31 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length srcALen+srcBLen-1. * @return none. */ void arm_conv_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** * @brief Convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length srcALen+srcBLen-1. * @return none. */ void arm_conv_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** * @brief Convolution of Q7 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length srcALen+srcBLen-1. * @return none. */ void arm_conv_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst); /** * @brief Partial convolution of floating-point sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q15 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q31 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q7 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Instance structure for the Q15 FIR decimator. */ typedef struct { uint8_t M; /**< decimation factor. */ uint16_t numTaps; /**< number of coefficients in the filter. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ } arm_fir_decimate_instance_q15; /** * @brief Instance structure for the Q31 FIR decimator. */ typedef struct { uint8_t M; /**< decimation factor. */ uint16_t numTaps; /**< number of coefficients in the filter. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ } arm_fir_decimate_instance_q31; /** * @brief Instance structure for the floating-point FIR decimator. */ typedef struct { uint8_t M; /**< decimation factor. */ uint16_t numTaps; /**< number of coefficients in the filter. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ } arm_fir_decimate_instance_f32; /** * @brief Processing function for the floating-point FIR decimator. * @param[in] *S points to an instance of the floating-point FIR decimator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. * @return none */ void arm_fir_decimate_f32( const arm_fir_decimate_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point FIR decimator. * @param[in,out] *S points to an instance of the floating-point FIR decimator structure. * @param[in] numTaps number of coefficients in the filter. * @param[in] M decimation factor. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * <code>blockSize</code> is not a multiple of <code>M</code>. */ arm_status arm_fir_decimate_init_f32( arm_fir_decimate_instance_f32 * S, uint16_t numTaps, uint8_t M, float32_t * pCoeffs, float32_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q15 FIR decimator. * @param[in] *S points to an instance of the Q15 FIR decimator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. * @return none */ void arm_fir_decimate_q15( const arm_fir_decimate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Processing function for the Q15 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4. * @param[in] *S points to an instance of the Q15 FIR decimator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. * @return none */ void arm_fir_decimate_fast_q15( const arm_fir_decimate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 FIR decimator. * @param[in,out] *S points to an instance of the Q15 FIR decimator structure. * @param[in] numTaps number of coefficients in the filter. * @param[in] M decimation factor. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * <code>blockSize</code> is not a multiple of <code>M</code>. */ arm_status arm_fir_decimate_init_q15( arm_fir_decimate_instance_q15 * S, uint16_t numTaps, uint8_t M, q15_t * pCoeffs, q15_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR decimator. * @param[in] *S points to an instance of the Q31 FIR decimator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. * @return none */ void arm_fir_decimate_q31( const arm_fir_decimate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4. * @param[in] *S points to an instance of the Q31 FIR decimator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. * @return none */ void arm_fir_decimate_fast_q31( arm_fir_decimate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR decimator. * @param[in,out] *S points to an instance of the Q31 FIR decimator structure. * @param[in] numTaps number of coefficients in the filter. * @param[in] M decimation factor. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * <code>blockSize</code> is not a multiple of <code>M</code>. */ arm_status arm_fir_decimate_init_q31( arm_fir_decimate_instance_q31 * S, uint16_t numTaps, uint8_t M, q31_t * pCoeffs, q31_t * pState, uint32_t blockSize); /** * @brief Instance structure for the Q15 FIR interpolator. */ typedef struct { uint8_t L; /**< upsample factor. */ uint16_t phaseLength; /**< length of each polyphase filter component. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */ q15_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */ } arm_fir_interpolate_instance_q15; /** * @brief Instance structure for the Q31 FIR interpolator. */ typedef struct { uint8_t L; /**< upsample factor. */ uint16_t phaseLength; /**< length of each polyphase filter component. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */ q31_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */ } arm_fir_interpolate_instance_q31; /** * @brief Instance structure for the floating-point FIR interpolator. */ typedef struct { uint8_t L; /**< upsample factor. */ uint16_t phaseLength; /**< length of each polyphase filter component. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */ float32_t *pState; /**< points to the state variable array. The array is of length phaseLength+numTaps-1. */ } arm_fir_interpolate_instance_f32; /** * @brief Processing function for the Q15 FIR interpolator. * @param[in] *S points to an instance of the Q15 FIR interpolator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of input samples to process per call. * @return none. */ void arm_fir_interpolate_q15( const arm_fir_interpolate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 FIR interpolator. * @param[in,out] *S points to an instance of the Q15 FIR interpolator structure. * @param[in] L upsample factor. * @param[in] numTaps number of filter coefficients in the filter. * @param[in] *pCoeffs points to the filter coefficient buffer. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>. */ arm_status arm_fir_interpolate_init_q15( arm_fir_interpolate_instance_q15 * S, uint8_t L, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR interpolator. * @param[in] *S points to an instance of the Q15 FIR interpolator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of input samples to process per call. * @return none. */ void arm_fir_interpolate_q31( const arm_fir_interpolate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR interpolator. * @param[in,out] *S points to an instance of the Q31 FIR interpolator structure. * @param[in] L upsample factor. * @param[in] numTaps number of filter coefficients in the filter. * @param[in] *pCoeffs points to the filter coefficient buffer. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>. */ arm_status arm_fir_interpolate_init_q31( arm_fir_interpolate_instance_q31 * S, uint8_t L, uint16_t numTaps, q31_t * pCoeffs, q31_t * pState, uint32_t blockSize); /** * @brief Processing function for the floating-point FIR interpolator. * @param[in] *S points to an instance of the floating-point FIR interpolator structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of input samples to process per call. * @return none. */ void arm_fir_interpolate_f32( const arm_fir_interpolate_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point FIR interpolator. * @param[in,out] *S points to an instance of the floating-point FIR interpolator structure. * @param[in] L upsample factor. * @param[in] numTaps number of filter coefficients in the filter. * @param[in] *pCoeffs points to the filter coefficient buffer. * @param[in] *pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>. */ arm_status arm_fir_interpolate_init_f32( arm_fir_interpolate_instance_f32 * S, uint8_t L, uint16_t numTaps, float32_t * pCoeffs, float32_t * pState, uint32_t blockSize); /** * @brief Instance structure for the high precision Q31 Biquad cascade filter. */ typedef struct { uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ q63_t *pState; /**< points to the array of state coefficients. The array is of length 4*numStages. */ q31_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */ uint8_t postShift; /**< additional shift, in bits, applied to each output sample. */ } arm_biquad_cas_df1_32x64_ins_q31; /** * @param[in] *S points to an instance of the high precision Q31 Biquad cascade filter structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of samples to process. * @return none. */ void arm_biquad_cas_df1_32x64_q31( const arm_biquad_cas_df1_32x64_ins_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @param[in,out] *S points to an instance of the high precision Q31 Biquad cascade filter structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] postShift shift to be applied to the output. Varies according to the coefficients format * @return none */ void arm_biquad_cas_df1_32x64_init_q31( arm_biquad_cas_df1_32x64_ins_q31 * S, uint8_t numStages, q31_t * pCoeffs, q63_t * pState, uint8_t postShift); /** * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter. */ typedef struct { uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ float32_t *pState; /**< points to the array of state coefficients. The array is of length 2*numStages. */ float32_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */ } arm_biquad_cascade_df2T_instance_f32; /** * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter. * @param[in] *S points to an instance of the filter data structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of samples to process. * @return none. */ void arm_biquad_cascade_df2T_f32( const arm_biquad_cascade_df2T_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter. * @param[in,out] *S points to an instance of the filter data structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] *pCoeffs points to the filter coefficients. * @param[in] *pState points to the state buffer. * @return none */ void arm_biquad_cascade_df2T_init_f32( arm_biquad_cascade_df2T_instance_f32 * S, uint8_t numStages, float32_t * pCoeffs, float32_t * pState); /** * @brief Instance structure for the Q15 FIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of filter stages. */ q15_t *pState; /**< points to the state variable array. The array is of length numStages. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */ } arm_fir_lattice_instance_q15; /** * @brief Instance structure for the Q31 FIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of filter stages. */ q31_t *pState; /**< points to the state variable array. The array is of length numStages. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */ } arm_fir_lattice_instance_q31; /** * @brief Instance structure for the floating-point FIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of filter stages. */ float32_t *pState; /**< points to the state variable array. The array is of length numStages. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */ } arm_fir_lattice_instance_f32; /** * @brief Initialization function for the Q15 FIR lattice filter. * @param[in] *S points to an instance of the Q15 FIR lattice structure. * @param[in] numStages number of filter stages. * @param[in] *pCoeffs points to the coefficient buffer. The array is of length numStages. * @param[in] *pState points to the state buffer. The array is of length numStages. * @return none. */ void arm_fir_lattice_init_q15( arm_fir_lattice_instance_q15 * S, uint16_t numStages, q15_t * pCoeffs, q15_t * pState); /** * @brief Processing function for the Q15 FIR lattice filter. * @param[in] *S points to an instance of the Q15 FIR lattice structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_lattice_q15( const arm_fir_lattice_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR lattice filter. * @param[in] *S points to an instance of the Q31 FIR lattice structure. * @param[in] numStages number of filter stages. * @param[in] *pCoeffs points to the coefficient buffer. The array is of length numStages. * @param[in] *pState points to the state buffer. The array is of length numStages. * @return none. */ void arm_fir_lattice_init_q31( arm_fir_lattice_instance_q31 * S, uint16_t numStages, q31_t * pCoeffs, q31_t * pState); /** * @brief Processing function for the Q31 FIR lattice filter. * @param[in] *S points to an instance of the Q31 FIR lattice structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_lattice_q31( const arm_fir_lattice_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point FIR lattice filter. * @param[in] *S points to an instance of the floating-point FIR lattice structure. * @param[in] numStages number of filter stages. * @param[in] *pCoeffs points to the coefficient buffer. The array is of length numStages. * @param[in] *pState points to the state buffer. The array is of length numStages. * @return none. */ void arm_fir_lattice_init_f32( arm_fir_lattice_instance_f32 * S, uint16_t numStages, float32_t * pCoeffs, float32_t * pState); /** * @brief Processing function for the floating-point FIR lattice filter. * @param[in] *S points to an instance of the floating-point FIR lattice structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] blockSize number of samples to process. * @return none. */ void arm_fir_lattice_f32( const arm_fir_lattice_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Instance structure for the Q15 IIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of stages in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */ q15_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */ q15_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */ } arm_iir_lattice_instance_q15; /** * @brief Instance structure for the Q31 IIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of stages in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */ q31_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */ q31_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */ } arm_iir_lattice_instance_q31; /** * @brief Instance structure for the floating-point IIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of stages in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */ float32_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */ float32_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */ } arm_iir_lattice_instance_f32; /** * @brief Processing function for the floating-point IIR lattice filter. * @param[in] *S points to an instance of the floating-point IIR lattice structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_iir_lattice_f32( const arm_iir_lattice_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point IIR lattice filter. * @param[in] *S points to an instance of the floating-point IIR lattice structure. * @param[in] numStages number of stages in the filter. * @param[in] *pkCoeffs points to the reflection coefficient buffer. The array is of length numStages. * @param[in] *pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1. * @param[in] *pState points to the state buffer. The array is of length numStages+blockSize-1. * @param[in] blockSize number of samples to process. * @return none. */ void arm_iir_lattice_init_f32( arm_iir_lattice_instance_f32 * S, uint16_t numStages, float32_t *pkCoeffs, float32_t *pvCoeffs, float32_t *pState, uint32_t blockSize); /** * @brief Processing function for the Q31 IIR lattice filter. * @param[in] *S points to an instance of the Q31 IIR lattice structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_iir_lattice_q31( const arm_iir_lattice_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 IIR lattice filter. * @param[in] *S points to an instance of the Q31 IIR lattice structure. * @param[in] numStages number of stages in the filter. * @param[in] *pkCoeffs points to the reflection coefficient buffer. The array is of length numStages. * @param[in] *pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1. * @param[in] *pState points to the state buffer. The array is of length numStages+blockSize. * @param[in] blockSize number of samples to process. * @return none. */ void arm_iir_lattice_init_q31( arm_iir_lattice_instance_q31 * S, uint16_t numStages, q31_t *pkCoeffs, q31_t *pvCoeffs, q31_t *pState, uint32_t blockSize); /** * @brief Processing function for the Q15 IIR lattice filter. * @param[in] *S points to an instance of the Q15 IIR lattice structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_iir_lattice_q15( const arm_iir_lattice_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 IIR lattice filter. * @param[in] *S points to an instance of the fixed-point Q15 IIR lattice structure. * @param[in] numStages number of stages in the filter. * @param[in] *pkCoeffs points to reflection coefficient buffer. The array is of length numStages. * @param[in] *pvCoeffs points to ladder coefficient buffer. The array is of length numStages+1. * @param[in] *pState points to state buffer. The array is of length numStages+blockSize. * @param[in] blockSize number of samples to process per call. * @return none. */ void arm_iir_lattice_init_q15( arm_iir_lattice_instance_q15 * S, uint16_t numStages, q15_t *pkCoeffs, q15_t *pvCoeffs, q15_t *pState, uint32_t blockSize); /** * @brief Instance structure for the floating-point LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ float32_t mu; /**< step size that controls filter coefficient updates. */ } arm_lms_instance_f32; /** * @brief Processing function for floating-point LMS filter. * @param[in] *S points to an instance of the floating-point LMS filter structure. * @param[in] *pSrc points to the block of input data. * @param[in] *pRef points to the block of reference data. * @param[out] *pOut points to the block of output data. * @param[out] *pErr points to the block of error data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_f32( const arm_lms_instance_f32 * S, float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize); /** * @brief Initialization function for floating-point LMS filter. * @param[in] *S points to an instance of the floating-point LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] *pCoeffs points to the coefficient buffer. * @param[in] *pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_init_f32( arm_lms_instance_f32 * S, uint16_t numTaps, float32_t * pCoeffs, float32_t * pState, float32_t mu, uint32_t blockSize); /** * @brief Instance structure for the Q15 LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q15_t mu; /**< step size that controls filter coefficient updates. */ uint32_t postShift; /**< bit shift applied to coefficients. */ } arm_lms_instance_q15; /** * @brief Initialization function for the Q15 LMS filter. * @param[in] *S points to an instance of the Q15 LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] *pCoeffs points to the coefficient buffer. * @param[in] *pState points to the state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. * @return none. */ void arm_lms_init_q15( arm_lms_instance_q15 * S, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, q15_t mu, uint32_t blockSize, uint32_t postShift); /** * @brief Processing function for Q15 LMS filter. * @param[in] *S points to an instance of the Q15 LMS filter structure. * @param[in] *pSrc points to the block of input data. * @param[in] *pRef points to the block of reference data. * @param[out] *pOut points to the block of output data. * @param[out] *pErr points to the block of error data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_q15( const arm_lms_instance_q15 * S, q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize); /** * @brief Instance structure for the Q31 LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q31_t mu; /**< step size that controls filter coefficient updates. */ uint32_t postShift; /**< bit shift applied to coefficients. */ } arm_lms_instance_q31; /** * @brief Processing function for Q31 LMS filter. * @param[in] *S points to an instance of the Q15 LMS filter structure. * @param[in] *pSrc points to the block of input data. * @param[in] *pRef points to the block of reference data. * @param[out] *pOut points to the block of output data. * @param[out] *pErr points to the block of error data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_q31( const arm_lms_instance_q31 * S, q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize); /** * @brief Initialization function for Q31 LMS filter. * @param[in] *S points to an instance of the Q31 LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] *pCoeffs points to coefficient buffer. * @param[in] *pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. * @return none. */ void arm_lms_init_q31( arm_lms_instance_q31 * S, uint16_t numTaps, q31_t *pCoeffs, q31_t *pState, q31_t mu, uint32_t blockSize, uint32_t postShift); /** * @brief Instance structure for the floating-point normalized LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ float32_t mu; /**< step size that control filter coefficient updates. */ float32_t energy; /**< saves previous frame energy. */ float32_t x0; /**< saves previous input sample. */ } arm_lms_norm_instance_f32; /** * @brief Processing function for floating-point normalized LMS filter. * @param[in] *S points to an instance of the floating-point normalized LMS filter structure. * @param[in] *pSrc points to the block of input data. * @param[in] *pRef points to the block of reference data. * @param[out] *pOut points to the block of output data. * @param[out] *pErr points to the block of error data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_norm_f32( arm_lms_norm_instance_f32 * S, float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize); /** * @brief Initialization function for floating-point normalized LMS filter. * @param[in] *S points to an instance of the floating-point LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] *pCoeffs points to coefficient buffer. * @param[in] *pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_norm_init_f32( arm_lms_norm_instance_f32 * S, uint16_t numTaps, float32_t * pCoeffs, float32_t * pState, float32_t mu, uint32_t blockSize); /** * @brief Instance structure for the Q31 normalized LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q31_t mu; /**< step size that controls filter coefficient updates. */ uint8_t postShift; /**< bit shift applied to coefficients. */ q31_t *recipTable; /**< points to the reciprocal initial value table. */ q31_t energy; /**< saves previous frame energy. */ q31_t x0; /**< saves previous input sample. */ } arm_lms_norm_instance_q31; /** * @brief Processing function for Q31 normalized LMS filter. * @param[in] *S points to an instance of the Q31 normalized LMS filter structure. * @param[in] *pSrc points to the block of input data. * @param[in] *pRef points to the block of reference data. * @param[out] *pOut points to the block of output data. * @param[out] *pErr points to the block of error data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_norm_q31( arm_lms_norm_instance_q31 * S, q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize); /** * @brief Initialization function for Q31 normalized LMS filter. * @param[in] *S points to an instance of the Q31 normalized LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] *pCoeffs points to coefficient buffer. * @param[in] *pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. * @return none. */ void arm_lms_norm_init_q31( arm_lms_norm_instance_q31 * S, uint16_t numTaps, q31_t * pCoeffs, q31_t * pState, q31_t mu, uint32_t blockSize, uint8_t postShift); /** * @brief Instance structure for the Q15 normalized LMS filter. */ typedef struct { uint16_t numTaps; /**< Number of coefficients in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q15_t mu; /**< step size that controls filter coefficient updates. */ uint8_t postShift; /**< bit shift applied to coefficients. */ q15_t *recipTable; /**< Points to the reciprocal initial value table. */ q15_t energy; /**< saves previous frame energy. */ q15_t x0; /**< saves previous input sample. */ } arm_lms_norm_instance_q15; /** * @brief Processing function for Q15 normalized LMS filter. * @param[in] *S points to an instance of the Q15 normalized LMS filter structure. * @param[in] *pSrc points to the block of input data. * @param[in] *pRef points to the block of reference data. * @param[out] *pOut points to the block of output data. * @param[out] *pErr points to the block of error data. * @param[in] blockSize number of samples to process. * @return none. */ void arm_lms_norm_q15( arm_lms_norm_instance_q15 * S, q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize); /** * @brief Initialization function for Q15 normalized LMS filter. * @param[in] *S points to an instance of the Q15 normalized LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] *pCoeffs points to coefficient buffer. * @param[in] *pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. * @return none. */ void arm_lms_norm_init_q15( arm_lms_norm_instance_q15 * S, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, q15_t mu, uint32_t blockSize, uint8_t postShift); /** * @brief Correlation of floating-point sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. * @return none. */ void arm_correlate_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst); /** * @brief Correlation of Q15 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. * @return none. */ void arm_correlate_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** * @brief Correlation of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. * @return none. */ void arm_correlate_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** * @brief Correlation of Q31 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. * @return none. */ void arm_correlate_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** * @brief Correlation of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. * @return none. */ void arm_correlate_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** * @brief Correlation of Q7 sequences. * @param[in] *pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] *pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] *pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. * @return none. */ void arm_correlate_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst); /** * @brief Instance structure for the floating-point sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ float32_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_f32; /** * @brief Instance structure for the Q31 sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ q31_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_q31; /** * @brief Instance structure for the Q15 sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ q15_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_q15; /** * @brief Instance structure for the Q7 sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ q7_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_q7; /** * @brief Processing function for the floating-point sparse FIR filter. * @param[in] *S points to an instance of the floating-point sparse FIR structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] *pScratchIn points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. * @return none. */ void arm_fir_sparse_f32( arm_fir_sparse_instance_f32 * S, float32_t * pSrc, float32_t * pDst, float32_t * pScratchIn, uint32_t blockSize); /** * @brief Initialization function for the floating-point sparse FIR filter. * @param[in,out] *S points to an instance of the floating-point sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] *pCoeffs points to the array of filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] *pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. * @return none */ void arm_fir_sparse_init_f32( arm_fir_sparse_instance_f32 * S, uint16_t numTaps, float32_t * pCoeffs, float32_t * pState, int32_t * pTapDelay, uint16_t maxDelay, uint32_t blockSize); /** * @brief Processing function for the Q31 sparse FIR filter. * @param[in] *S points to an instance of the Q31 sparse FIR structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] *pScratchIn points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. * @return none. */ void arm_fir_sparse_q31( arm_fir_sparse_instance_q31 * S, q31_t * pSrc, q31_t * pDst, q31_t * pScratchIn, uint32_t blockSize); /** * @brief Initialization function for the Q31 sparse FIR filter. * @param[in,out] *S points to an instance of the Q31 sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] *pCoeffs points to the array of filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] *pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. * @return none */ void arm_fir_sparse_init_q31( arm_fir_sparse_instance_q31 * S, uint16_t numTaps, q31_t * pCoeffs, q31_t * pState, int32_t * pTapDelay, uint16_t maxDelay, uint32_t blockSize); /** * @brief Processing function for the Q15 sparse FIR filter. * @param[in] *S points to an instance of the Q15 sparse FIR structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] *pScratchIn points to a temporary buffer of size blockSize. * @param[in] *pScratchOut points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. * @return none. */ void arm_fir_sparse_q15( arm_fir_sparse_instance_q15 * S, q15_t * pSrc, q15_t * pDst, q15_t * pScratchIn, q31_t * pScratchOut, uint32_t blockSize); /** * @brief Initialization function for the Q15 sparse FIR filter. * @param[in,out] *S points to an instance of the Q15 sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] *pCoeffs points to the array of filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] *pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. * @return none */ void arm_fir_sparse_init_q15( arm_fir_sparse_instance_q15 * S, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, int32_t * pTapDelay, uint16_t maxDelay, uint32_t blockSize); /** * @brief Processing function for the Q7 sparse FIR filter. * @param[in] *S points to an instance of the Q7 sparse FIR structure. * @param[in] *pSrc points to the block of input data. * @param[out] *pDst points to the block of output data * @param[in] *pScratchIn points to a temporary buffer of size blockSize. * @param[in] *pScratchOut points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. * @return none. */ void arm_fir_sparse_q7( arm_fir_sparse_instance_q7 * S, q7_t * pSrc, q7_t * pDst, q7_t * pScratchIn, q31_t * pScratchOut, uint32_t blockSize); /** * @brief Initialization function for the Q7 sparse FIR filter. * @param[in,out] *S points to an instance of the Q7 sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] *pCoeffs points to the array of filter coefficients. * @param[in] *pState points to the state buffer. * @param[in] *pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. * @return none */ void arm_fir_sparse_init_q7( arm_fir_sparse_instance_q7 * S, uint16_t numTaps, q7_t * pCoeffs, q7_t * pState, int32_t *pTapDelay, uint16_t maxDelay, uint32_t blockSize); /* * @brief Floating-point sin_cos function. * @param[in] theta input value in degrees * @param[out] *pSinVal points to the processed sine output. * @param[out] *pCosVal points to the processed cos output. * @return none. */ void arm_sin_cos_f32( float32_t theta, float32_t *pSinVal, float32_t *pCcosVal); /* * @brief Q31 sin_cos function. * @param[in] theta scaled input value in degrees * @param[out] *pSinVal points to the processed sine output. * @param[out] *pCosVal points to the processed cosine output. * @return none. */ void arm_sin_cos_q31( q31_t theta, q31_t *pSinVal, q31_t *pCosVal); /** * @brief Floating-point complex conjugate. * @param[in] *pSrc points to the input vector * @param[out] *pDst points to the output vector * @param[in] numSamples number of complex samples in each vector * @return none. */ void arm_cmplx_conj_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples); /** * @brief Q31 complex conjugate. * @param[in] *pSrc points to the input vector * @param[out] *pDst points to the output vector * @param[in] numSamples number of complex samples in each vector * @return none. */ void arm_cmplx_conj_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples); /** * @brief Q15 complex conjugate. * @param[in] *pSrc points to the input vector * @param[out] *pDst points to the output vector * @param[in] numSamples number of complex samples in each vector * @return none. */ void arm_cmplx_conj_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples); /** * @brief Floating-point complex magnitude squared * @param[in] *pSrc points to the complex input vector * @param[out] *pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector * @return none. */ void arm_cmplx_mag_squared_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples); /** * @brief Q31 complex magnitude squared * @param[in] *pSrc points to the complex input vector * @param[out] *pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector * @return none. */ void arm_cmplx_mag_squared_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples); /** * @brief Q15 complex magnitude squared * @param[in] *pSrc points to the complex input vector * @param[out] *pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector * @return none. */ void arm_cmplx_mag_squared_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples); /** * @ingroup groupController */ /** * @defgroup PID PID Motor Control * * A Proportional Integral Derivative (PID) controller is a generic feedback control * loop mechanism widely used in industrial control systems. * A PID controller is the most commonly used type of feedback controller. * * This set of functions implements (PID) controllers * for Q15, Q31, and floating-point data types. The functions operate on a single sample * of data and each call to the function returns a single processed value. * <code>S</code> points to an instance of the PID control data structure. <code>in</code> * is the input sample value. The functions return the output value. * * \par Algorithm: * <pre> * y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2] * A0 = Kp + Ki + Kd * A1 = (-Kp ) - (2 * Kd ) * A2 = Kd </pre> * * \par * where \c Kp is proportional constant, \c Ki is Integral constant and \c Kd is Derivative constant * * \par * \image html PID.gif "Proportional Integral Derivative Controller" * * \par * The PID controller calculates an "error" value as the difference between * the measured output and the reference input. * The controller attempts to minimize the error by adjusting the process control inputs. * The proportional value determines the reaction to the current error, * the integral value determines the reaction based on the sum of recent errors, * and the derivative value determines the reaction based on the rate at which the error has been changing. * * \par Instance Structure * The Gains A0, A1, A2 and state variables for a PID controller are stored together in an instance data structure. * A separate instance structure must be defined for each PID Controller. * There are separate instance structure declarations for each of the 3 supported data types. * * \par Reset Functions * There is also an associated reset function for each data type which clears the state array. * * \par Initialization Functions * There is also an associated initialization function for each data type. * The initialization function performs the following operations: * - Initializes the Gains A0, A1, A2 from Kp,Ki, Kd gains. * - Zeros out the values in the state buffer. * * \par * Instance structure cannot be placed into a const data section and it is recommended to use the initialization function. * * \par Fixed-Point Behavior * Care must be taken when using the fixed-point versions of the PID Controller functions. * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup PID * @{ */ /** * @brief Process function for the floating-point PID Control. * @param[in,out] *S is an instance of the floating-point PID Control structure * @param[in] in input sample to process * @return out processed output sample. */ static __INLINE float32_t arm_pid_f32( arm_pid_instance_f32 * S, float32_t in) { float32_t out; /* y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2] */ out = (S->A0 * in) + (S->A1 * S->state[0]) + (S->A2 * S->state[1]) + (S->state[2]); /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } /** * @brief Process function for the Q31 PID Control. * @param[in,out] *S points to an instance of the Q31 PID Control structure * @param[in] in input sample to process * @return out processed output sample. * * <b>Scaling and Overflow Behavior:</b> * \par * The function is implemented using an internal 64-bit accumulator. * The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. * Thus, if the accumulator result overflows it wraps around rather than clip. * In order to avoid overflows completely the input signal must be scaled down by 2 bits as there are four additions. * After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format. */ static __INLINE q31_t arm_pid_q31( arm_pid_instance_q31 * S, q31_t in) { q63_t acc; q31_t out; /* acc = A0 * x[n] */ acc = (q63_t) S->A0 * in; /* acc += A1 * x[n-1] */ acc += (q63_t) S->A1 * S->state[0]; /* acc += A2 * x[n-2] */ acc += (q63_t) S->A2 * S->state[1]; /* convert output to 1.31 format to add y[n-1] */ out = (q31_t) (acc >> 31u); /* out += y[n-1] */ out += S->state[2]; /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } /** * @brief Process function for the Q15 PID Control. * @param[in,out] *S points to an instance of the Q15 PID Control structure * @param[in] in input sample to process * @return out processed output sample. * * <b>Scaling and Overflow Behavior:</b> * \par * The function is implemented using a 64-bit internal accumulator. * Both Gains and state variables are represented in 1.15 format and multiplications yield a 2.30 result. * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. * After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. * Lastly, the accumulator is saturated to yield a result in 1.15 format. */ static __INLINE q15_t arm_pid_q15( arm_pid_instance_q15 * S, q15_t in) { q63_t acc; q15_t out; /* Implementation of PID controller */ #ifdef ARM_MATH_CM0 /* acc = A0 * x[n] */ acc = ((q31_t) S->A0 )* in ; #else /* acc = A0 * x[n] */ acc = (q31_t) __SMUAD(S->A0, in); #endif #ifdef ARM_MATH_CM0 /* acc += A1 * x[n-1] + A2 * x[n-2] */ acc += (q31_t) S->A1 * S->state[0] ; acc += (q31_t) S->A2 * S->state[1] ; #else /* acc += A1 * x[n-1] + A2 * x[n-2] */ acc = __SMLALD(S->A1, (q31_t)__SIMD32(S->state), acc); #endif /* acc += y[n-1] */ acc += (q31_t) S->state[2] << 15; /* saturate the output */ out = (q15_t) (__SSAT((acc >> 15), 16)); /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } /** * @} end of PID group */ /** * @brief Floating-point matrix inverse. * @param[in] *src points to the instance of the input floating-point matrix structure. * @param[out] *dst points to the instance of the output floating-point matrix structure. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR. */ arm_status arm_mat_inverse_f32( const arm_matrix_instance_f32 * src, arm_matrix_instance_f32 * dst); /** * @ingroup groupController */ /** * @defgroup clarke Vector Clarke Transform * Forward Clarke transform converts the instantaneous stator phases into a two-coordinate time invariant vector. * Generally the Clarke transform uses three-phase currents <code>Ia, Ib and Ic</code> to calculate currents * in the two-phase orthogonal stator axis <code>Ialpha</code> and <code>Ibeta</code>. * When <code>Ialpha</code> is superposed with <code>Ia</code> as shown in the figure below * \image html clarke.gif Stator current space vector and its components in (a,b). * and <code>Ia + Ib + Ic = 0</code>, in this condition <code>Ialpha</code> and <code>Ibeta</code> * can be calculated using only <code>Ia</code> and <code>Ib</code>. * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html clarkeFormula.gif * where <code>Ia</code> and <code>Ib</code> are the instantaneous stator phases and * <code>pIalpha</code> and <code>pIbeta</code> are the two coordinates of time invariant vector. * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Clarke transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup clarke * @{ */ /** * * @brief Floating-point Clarke transform * @param[in] Ia input three-phase coordinate <code>a</code> * @param[in] Ib input three-phase coordinate <code>b</code> * @param[out] *pIalpha points to output two-phase orthogonal vector axis alpha * @param[out] *pIbeta points to output two-phase orthogonal vector axis beta * @return none. */ static __INLINE void arm_clarke_f32( float32_t Ia, float32_t Ib, float32_t * pIalpha, float32_t * pIbeta) { /* Calculate pIalpha using the equation, pIalpha = Ia */ *pIalpha = Ia; /* Calculate pIbeta using the equation, pIbeta = (1/sqrt(3)) * Ia + (2/sqrt(3)) * Ib */ *pIbeta = ((float32_t) 0.57735026919 * Ia + (float32_t) 1.15470053838 * Ib); } /** * @brief Clarke transform for Q31 version * @param[in] Ia input three-phase coordinate <code>a</code> * @param[in] Ib input three-phase coordinate <code>b</code> * @param[out] *pIalpha points to output two-phase orthogonal vector axis alpha * @param[out] *pIbeta points to output two-phase orthogonal vector axis beta * @return none. * * <b>Scaling and Overflow Behavior:</b> * \par * The function is implemented using an internal 32-bit accumulator. * The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. * There is saturation on the addition, hence there is no risk of overflow. */ static __INLINE void arm_clarke_q31( q31_t Ia, q31_t Ib, q31_t * pIalpha, q31_t * pIbeta) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ /* Calculating pIalpha from Ia by equation pIalpha = Ia */ *pIalpha = Ia; /* Intermediate product is calculated by (1/(sqrt(3)) * Ia) */ product1 = (q31_t) (((q63_t) Ia * 0x24F34E8B) >> 30); /* Intermediate product is calculated by (2/sqrt(3) * Ib) */ product2 = (q31_t) (((q63_t) Ib * 0x49E69D16) >> 30); /* pIbeta is calculated by adding the intermediate products */ *pIbeta = __QADD(product1, product2); } /** * @} end of clarke group */ /** * @brief Converts the elements of the Q7 vector to Q31 vector. * @param[in] *pSrc input pointer * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_q7_to_q31( q7_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @ingroup groupController */ /** * @defgroup inv_clarke Vector Inverse Clarke Transform * Inverse Clarke transform converts the two-coordinate time invariant vector into instantaneous stator phases. * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html clarkeInvFormula.gif * where <code>pIa</code> and <code>pIb</code> are the instantaneous stator phases and * <code>Ialpha</code> and <code>Ibeta</code> are the two coordinates of time invariant vector. * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Clarke transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup inv_clarke * @{ */ /** * @brief Floating-point Inverse Clarke transform * @param[in] Ialpha input two-phase orthogonal vector axis alpha * @param[in] Ibeta input two-phase orthogonal vector axis beta * @param[out] *pIa points to output three-phase coordinate <code>a</code> * @param[out] *pIb points to output three-phase coordinate <code>b</code> * @return none. */ static __INLINE void arm_inv_clarke_f32( float32_t Ialpha, float32_t Ibeta, float32_t * pIa, float32_t * pIb) { /* Calculating pIa from Ialpha by equation pIa = Ialpha */ *pIa = Ialpha; /* Calculating pIb from Ialpha and Ibeta by equation pIb = -(1/2) * Ialpha + (sqrt(3)/2) * Ibeta */ *pIb = -0.5 * Ialpha + (float32_t) 0.8660254039 *Ibeta; } /** * @brief Inverse Clarke transform for Q31 version * @param[in] Ialpha input two-phase orthogonal vector axis alpha * @param[in] Ibeta input two-phase orthogonal vector axis beta * @param[out] *pIa points to output three-phase coordinate <code>a</code> * @param[out] *pIb points to output three-phase coordinate <code>b</code> * @return none. * * <b>Scaling and Overflow Behavior:</b> * \par * The function is implemented using an internal 32-bit accumulator. * The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. * There is saturation on the subtraction, hence there is no risk of overflow. */ static __INLINE void arm_inv_clarke_q31( q31_t Ialpha, q31_t Ibeta, q31_t * pIa, q31_t * pIb) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ /* Calculating pIa from Ialpha by equation pIa = Ialpha */ *pIa = Ialpha; /* Intermediate product is calculated by (1/(2*sqrt(3)) * Ia) */ product1 = (q31_t) (((q63_t) (Ialpha) * (0x40000000)) >> 31); /* Intermediate product is calculated by (1/sqrt(3) * pIb) */ product2 = (q31_t) (((q63_t) (Ibeta) * (0x6ED9EBA1)) >> 31); /* pIb is calculated by subtracting the products */ *pIb = __QSUB(product2, product1); } /** * @} end of inv_clarke group */ /** * @brief Converts the elements of the Q7 vector to Q15 vector. * @param[in] *pSrc input pointer * @param[out] *pDst output pointer * @param[in] blockSize number of samples to process * @return none. */ void arm_q7_to_q15( q7_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @ingroup groupController */ /** * @defgroup park Vector Park Transform * * Forward Park transform converts the input two-coordinate vector to flux and torque components. * The Park transform can be used to realize the transformation of the <code>Ialpha</code> and the <code>Ibeta</code> currents * from the stationary to the moving reference frame and control the spatial relationship between * the stator vector current and rotor flux vector. * If we consider the d axis aligned with the rotor flux, the diagram below shows the * current vector and the relationship from the two reference frames: * \image html park.gif "Stator current space vector and its component in (a,b) and in the d,q rotating reference frame" * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html parkFormula.gif * where <code>Ialpha</code> and <code>Ibeta</code> are the stator vector components, * <code>pId</code> and <code>pIq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the * cosine and sine values of theta (rotor flux position). * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Park transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup park * @{ */ /** * @brief Floating-point Park transform * @param[in] Ialpha input two-phase vector coordinate alpha * @param[in] Ibeta input two-phase vector coordinate beta * @param[out] *pId points to output rotor reference frame d * @param[out] *pIq points to output rotor reference frame q * @param[in] sinVal sine value of rotation angle theta * @param[in] cosVal cosine value of rotation angle theta * @return none. * * The function implements the forward Park transform. * */ static __INLINE void arm_park_f32( float32_t Ialpha, float32_t Ibeta, float32_t * pId, float32_t * pIq, float32_t sinVal, float32_t cosVal) { /* Calculate pId using the equation, pId = Ialpha * cosVal + Ibeta * sinVal */ *pId = Ialpha * cosVal + Ibeta * sinVal; /* Calculate pIq using the equation, pIq = - Ialpha * sinVal + Ibeta * cosVal */ *pIq = -Ialpha * sinVal + Ibeta * cosVal; } /** * @brief Park transform for Q31 version * @param[in] Ialpha input two-phase vector coordinate alpha * @param[in] Ibeta input two-phase vector coordinate beta * @param[out] *pId points to output rotor reference frame d * @param[out] *pIq points to output rotor reference frame q * @param[in] sinVal sine value of rotation angle theta * @param[in] cosVal cosine value of rotation angle theta * @return none. * * <b>Scaling and Overflow Behavior:</b> * \par * The function is implemented using an internal 32-bit accumulator. * The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. * There is saturation on the addition and subtraction, hence there is no risk of overflow. */ static __INLINE void arm_park_q31( q31_t Ialpha, q31_t Ibeta, q31_t * pId, q31_t * pIq, q31_t sinVal, q31_t cosVal) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ q31_t product3, product4; /* Temporary variables used to store intermediate results */ /* Intermediate product is calculated by (Ialpha * cosVal) */ product1 = (q31_t) (((q63_t) (Ialpha) * (cosVal)) >> 31); /* Intermediate product is calculated by (Ibeta * sinVal) */ product2 = (q31_t) (((q63_t) (Ibeta) * (sinVal)) >> 31); /* Intermediate product is calculated by (Ialpha * sinVal) */ product3 = (q31_t) (((q63_t) (Ialpha) * (sinVal)) >> 31); /* Intermediate product is calculated by (Ibeta * cosVal) */ product4 = (q31_t) (((q63_t) (Ibeta) * (cosVal)) >> 31); /* Calculate pId by adding the two intermediate products 1 and 2 */ *pId = __QADD(product1, product2); /* Calculate pIq by subtracting the two intermediate products 3 from 4 */ *pIq = __QSUB(product4, product3); } /** * @} end of park group */ /** * @brief Converts the elements of the Q7 vector to floating-point vector. * @param[in] *pSrc is input pointer * @param[out] *pDst is output pointer * @param[in] blockSize is the number of samples to process * @return none. */ void arm_q7_to_float( q7_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @ingroup groupController */ /** * @defgroup inv_park Vector Inverse Park transform * Inverse Park transform converts the input flux and torque components to two-coordinate vector. * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html parkInvFormula.gif * where <code>pIalpha</code> and <code>pIbeta</code> are the stator vector components, * <code>Id</code> and <code>Iq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the * cosine and sine values of theta (rotor flux position). * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Park transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup inv_park * @{ */ /** * @brief Floating-point Inverse Park transform * @param[in] Id input coordinate of rotor reference frame d * @param[in] Iq input coordinate of rotor reference frame q * @param[out] *pIalpha points to output two-phase orthogonal vector axis alpha * @param[out] *pIbeta points to output two-phase orthogonal vector axis beta * @param[in] sinVal sine value of rotation angle theta * @param[in] cosVal cosine value of rotation angle theta * @return none. */ static __INLINE void arm_inv_park_f32( float32_t Id, float32_t Iq, float32_t * pIalpha, float32_t * pIbeta, float32_t sinVal, float32_t cosVal) { /* Calculate pIalpha using the equation, pIalpha = Id * cosVal - Iq * sinVal */ *pIalpha = Id * cosVal - Iq * sinVal; /* Calculate pIbeta using the equation, pIbeta = Id * sinVal + Iq * cosVal */ *pIbeta = Id * sinVal + Iq * cosVal; } /** * @brief Inverse Park transform for Q31 version * @param[in] Id input coordinate of rotor reference frame d * @param[in] Iq input coordinate of rotor reference frame q * @param[out] *pIalpha points to output two-phase orthogonal vector axis alpha * @param[out] *pIbeta points to output two-phase orthogonal vector axis beta * @param[in] sinVal sine value of rotation angle theta * @param[in] cosVal cosine value of rotation angle theta * @return none. * * <b>Scaling and Overflow Behavior:</b> * \par * The function is implemented using an internal 32-bit accumulator. * The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. * There is saturation on the addition, hence there is no risk of overflow. */ static __INLINE void arm_inv_park_q31( q31_t Id, q31_t Iq, q31_t * pIalpha, q31_t * pIbeta, q31_t sinVal, q31_t cosVal) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ q31_t product3, product4; /* Temporary variables used to store intermediate results */ /* Intermediate product is calculated by (Id * cosVal) */ product1 = (q31_t) (((q63_t) (Id) * (cosVal)) >> 31); /* Intermediate product is calculated by (Iq * sinVal) */ product2 = (q31_t) (((q63_t) (Iq) * (sinVal)) >> 31); /* Intermediate product is calculated by (Id * sinVal) */ product3 = (q31_t) (((q63_t) (Id) * (sinVal)) >> 31); /* Intermediate product is calculated by (Iq * cosVal) */ product4 = (q31_t) (((q63_t) (Iq) * (cosVal)) >> 31); /* Calculate pIalpha by using the two intermediate products 1 and 2 */ *pIalpha = __QSUB(product1, product2); /* Calculate pIbeta by using the two intermediate products 3 and 4 */ *pIbeta = __QADD(product4, product3); } /** * @} end of Inverse park group */ /** * @brief Converts the elements of the Q31 vector to floating-point vector. * @param[in] *pSrc is input pointer * @param[out] *pDst is output pointer * @param[in] blockSize is the number of samples to process * @return none. */ void arm_q31_to_float( q31_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @ingroup groupInterpolation */ /** * @defgroup LinearInterpolate Linear Interpolation * * Linear interpolation is a method of curve fitting using linear polynomials. * Linear interpolation works by effectively drawing a straight line between two neighboring samples and returning the appropriate point along that line * * \par * \image html LinearInterp.gif "Linear interpolation" * * \par * A Linear Interpolate function calculates an output value(y), for the input(x) * using linear interpolation of the input values x0, x1( nearest input values) and the output values y0 and y1(nearest output values) * * \par Algorithm: * <pre> * y = y0 + (x - x0) * ((y1 - y0)/(x1-x0)) * where x0, x1 are nearest values of input x * y0, y1 are nearest values to output y * </pre> * * \par * This set of functions implements Linear interpolation process * for Q7, Q15, Q31, and floating-point data types. The functions operate on a single * sample of data and each call to the function returns a single processed value. * <code>S</code> points to an instance of the Linear Interpolate function data structure. * <code>x</code> is the input sample value. The functions returns the output value. * * \par * if x is outside of the table boundary, Linear interpolation returns first value of the table * if x is below input range and returns last value of table if x is above range. */ /** * @addtogroup LinearInterpolate * @{ */ /** * @brief Process function for the floating-point Linear Interpolation Function. * @param[in,out] *S is an instance of the floating-point Linear Interpolation structure * @param[in] x input sample to process * @return y processed output sample. * */ static __INLINE float32_t arm_linear_interp_f32( arm_linear_interp_instance_f32 * S, float32_t x) { float32_t y; float32_t x0, x1; /* Nearest input values */ float32_t y0, y1; /* Nearest output values */ float32_t xSpacing = S->xSpacing; /* spacing between input values */ int32_t i; /* Index variable */ float32_t *pYData = S->pYData; /* pointer to output table */ /* Calculation of index */ i = (x - S->x1) / xSpacing; if(i < 0) { /* Iniatilize output for below specified range as least output value of table */ y = pYData[0]; } else if(i >= S->nValues) { /* Iniatilize output for above specified range as last output value of table */ y = pYData[S->nValues-1]; } else { /* Calculation of nearest input values */ x0 = S->x1 + i * xSpacing; x1 = S->x1 + (i +1) * xSpacing; /* Read of nearest output values */ y0 = pYData[i]; y1 = pYData[i + 1]; /* Calculation of output */ y = y0 + (x - x0) * ((y1 - y0)/(x1-x0)); } /* returns output value */ return (y); } /** * * @brief Process function for the Q31 Linear Interpolation Function. * @param[in] *pYData pointer to Q31 Linear Interpolation table * @param[in] x input sample to process * @param[in] nValues number of table values * @return y processed output sample. * * \par * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part. * This function can support maximum of table size 2^12. * */ static __INLINE q31_t arm_linear_interp_q31(q31_t *pYData, q31_t x, uint32_t nValues) { q31_t y; /* output */ q31_t y0, y1; /* Nearest output values */ q31_t fract; /* fractional part */ int32_t index; /* Index to read nearest output values */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ index = ((x & 0xFFF00000) >> 20); if(index >= (nValues - 1)) { return(pYData[nValues - 1]); } else if(index < 0) { return(pYData[0]); } else { /* 20 bits for the fractional part */ /* shift left by 11 to keep fract in 1.31 format */ fract = (x & 0x000FFFFF) << 11; /* Read two nearest output values from the index in 1.31(q31) format */ y0 = pYData[index]; y1 = pYData[index + 1u]; /* Calculation of y0 * (1-fract) and y is in 2.30 format */ y = ((q31_t) ((q63_t) y0 * (0x7FFFFFFF - fract) >> 32)); /* Calculation of y0 * (1-fract) + y1 *fract and y is in 2.30 format */ y += ((q31_t) (((q63_t) y1 * fract) >> 32)); /* Convert y to 1.31 format */ return (y << 1u); } } /** * * @brief Process function for the Q15 Linear Interpolation Function. * @param[in] *pYData pointer to Q15 Linear Interpolation table * @param[in] x input sample to process * @param[in] nValues number of table values * @return y processed output sample. * * \par * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part. * This function can support maximum of table size 2^12. * */ static __INLINE q15_t arm_linear_interp_q15(q15_t *pYData, q31_t x, uint32_t nValues) { q63_t y; /* output */ q15_t y0, y1; /* Nearest output values */ q31_t fract; /* fractional part */ int32_t index; /* Index to read nearest output values */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ index = ((x & 0xFFF00000) >> 20u); if(index >= (nValues - 1)) { return(pYData[nValues - 1]); } else if(index < 0) { return(pYData[0]); } else { /* 20 bits for the fractional part */ /* fract is in 12.20 format */ fract = (x & 0x000FFFFF); /* Read two nearest output values from the index */ y0 = pYData[index]; y1 = pYData[index + 1u]; /* Calculation of y0 * (1-fract) and y is in 13.35 format */ y = ((q63_t) y0 * (0xFFFFF - fract)); /* Calculation of (y0 * (1-fract) + y1 * fract) and y is in 13.35 format */ y += ((q63_t) y1 * (fract)); /* convert y to 1.15 format */ return (y >> 20); } } /** * * @brief Process function for the Q7 Linear Interpolation Function. * @param[in] *pYData pointer to Q7 Linear Interpolation table * @param[in] x input sample to process * @param[in] nValues number of table values * @return y processed output sample. * * \par * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part. * This function can support maximum of table size 2^12. */ static __INLINE q7_t arm_linear_interp_q7(q7_t *pYData, q31_t x, uint32_t nValues) { q31_t y; /* output */ q7_t y0, y1; /* Nearest output values */ q31_t fract; /* fractional part */ int32_t index; /* Index to read nearest output values */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ index = ((x & 0xFFF00000) >> 20u); if(index >= (nValues - 1)) { return(pYData[nValues - 1]); } else if(index < 0) { return(pYData[0]); } else { /* 20 bits for the fractional part */ /* fract is in 12.20 format */ fract = (x & 0x000FFFFF); /* Read two nearest output values from the index and are in 1.7(q7) format */ y0 = pYData[index]; y1 = pYData[index + 1u]; /* Calculation of y0 * (1-fract ) and y is in 13.27(q27) format */ y = ((y0 * (0xFFFFF - fract))); /* Calculation of y1 * fract + y0 * (1-fract) and y is in 13.27(q27) format */ y += (y1 * fract); /* convert y to 1.7(q7) format */ return (y >> 20u); } } /** * @} end of LinearInterpolate group */ /** * @brief Fast approximation to the trigonometric sine function for floating-point data. * @param[in] x input value in radians. * @return sin(x). */ float32_t arm_sin_f32( float32_t x); /** * @brief Fast approximation to the trigonometric sine function for Q31 data. * @param[in] x Scaled input value in radians. * @return sin(x). */ q31_t arm_sin_q31( q31_t x); /** * @brief Fast approximation to the trigonometric sine function for Q15 data. * @param[in] x Scaled input value in radians. * @return sin(x). */ q15_t arm_sin_q15( q15_t x); /** * @brief Fast approximation to the trigonometric cosine function for floating-point data. * @param[in] x input value in radians. * @return cos(x). */ float32_t arm_cos_f32( float32_t x); /** * @brief Fast approximation to the trigonometric cosine function for Q31 data. * @param[in] x Scaled input value in radians. * @return cos(x). */ q31_t arm_cos_q31( q31_t x); /** * @brief Fast approximation to the trigonometric cosine function for Q15 data. * @param[in] x Scaled input value in radians. * @return cos(x). */ q15_t arm_cos_q15( q15_t x); /** * @ingroup groupFastMath */ /** * @defgroup SQRT Square Root * * Computes the square root of a number. * There are separate functions for Q15, Q31, and floating-point data types. * The square root function is computed using the Newton-Raphson algorithm. * This is an iterative algorithm of the form: * <pre> * x1 = x0 - f(x0)/f'(x0) * </pre> * where <code>x1</code> is the current estimate, * <code>x0</code> is the previous estimate and * <code>f'(x0)</code> is the derivative of <code>f()</code> evaluated at <code>x0</code>. * For the square root function, the algorithm reduces to: * <pre> * x0 = in/2 [initial guess] * x1 = 1/2 * ( x0 + in / x0) [each iteration] * </pre> */ /** * @addtogroup SQRT * @{ */ /** * @brief Floating-point square root function. * @param[in] in input value. * @param[out] *pOut square root of input value. * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if * <code>in</code> is negative value and returns zero output for negative values. */ static __INLINE arm_status arm_sqrt_f32( float32_t in, float32_t *pOut) { if(in > 0) { // #if __FPU_USED #if (__FPU_USED == 1) && defined ( __CC_ARM ) *pOut = __sqrtf(in); #else *pOut = sqrtf(in); #endif return (ARM_MATH_SUCCESS); } else { *pOut = 0.0f; return (ARM_MATH_ARGUMENT_ERROR); } } /** * @brief Q31 square root function. * @param[in] in input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF. * @param[out] *pOut square root of input value. * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if * <code>in</code> is negative value and returns zero output for negative values. */ arm_status arm_sqrt_q31( q31_t in, q31_t *pOut); /** * @brief Q15 square root function. * @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF. * @param[out] *pOut square root of input value. * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if * <code>in</code> is negative value and returns zero output for negative values. */ arm_status arm_sqrt_q15( q15_t in, q15_t *pOut); /** * @} end of SQRT group */ /** * @brief floating-point Circular write function. */ static __INLINE void arm_circularWrite_f32( int32_t * circBuffer, int32_t L, uint16_t * writeOffset, int32_t bufferInc, const int32_t * src, int32_t srcInc, uint32_t blockSize) { uint32_t i = 0u; int32_t wOffset; /* Copy the value of Index pointer that points * to the current location where the input samples to be copied */ wOffset = *writeOffset; /* Loop over the blockSize */ i = blockSize; while(i > 0u) { /* copy the input sample to the circular buffer */ circBuffer[wOffset] = *src; /* Update the input pointer */ src += srcInc; /* Circularly update wOffset. Watch out for positive and negative value */ wOffset += bufferInc; if(wOffset >= L) wOffset -= L; /* Decrement the loop counter */ i--; } /* Update the index pointer */ *writeOffset = wOffset; } /** * @brief floating-point Circular Read function. */ static __INLINE void arm_circularRead_f32( int32_t * circBuffer, int32_t L, int32_t * readOffset, int32_t bufferInc, int32_t * dst, int32_t * dst_base, int32_t dst_length, int32_t dstInc, uint32_t blockSize) { uint32_t i = 0u; int32_t rOffset, dst_end; /* Copy the value of Index pointer that points * to the current location from where the input samples to be read */ rOffset = *readOffset; dst_end = (int32_t) (dst_base + dst_length); /* Loop over the blockSize */ i = blockSize; while(i > 0u) { /* copy the sample from the circular buffer to the destination buffer */ *dst = circBuffer[rOffset]; /* Update the input pointer */ dst += dstInc; if(dst == (int32_t *) dst_end) { dst = dst_base; } /* Circularly update rOffset. Watch out for positive and negative value */ rOffset += bufferInc; if(rOffset >= L) { rOffset -= L; } /* Decrement the loop counter */ i--; } /* Update the index pointer */ *readOffset = rOffset; } /** * @brief Q15 Circular write function. */ static __INLINE void arm_circularWrite_q15( q15_t * circBuffer, int32_t L, uint16_t * writeOffset, int32_t bufferInc, const q15_t * src, int32_t srcInc, uint32_t blockSize) { uint32_t i = 0u; int32_t wOffset; /* Copy the value of Index pointer that points * to the current location where the input samples to be copied */ wOffset = *writeOffset; /* Loop over the blockSize */ i = blockSize; while(i > 0u) { /* copy the input sample to the circular buffer */ circBuffer[wOffset] = *src; /* Update the input pointer */ src += srcInc; /* Circularly update wOffset. Watch out for positive and negative value */ wOffset += bufferInc; if(wOffset >= L) wOffset -= L; /* Decrement the loop counter */ i--; } /* Update the index pointer */ *writeOffset = wOffset; } /** * @brief Q15 Circular Read function. */ static __INLINE void arm_circularRead_q15( q15_t * circBuffer, int32_t L, int32_t * readOffset, int32_t bufferInc, q15_t * dst, q15_t * dst_base, int32_t dst_length, int32_t dstInc, uint32_t blockSize) { uint32_t i = 0; int32_t rOffset, dst_end; /* Copy the value of Index pointer that points * to the current location from where the input samples to be read */ rOffset = *readOffset; dst_end = (int32_t) (dst_base + dst_length); /* Loop over the blockSize */ i = blockSize; while(i > 0u) { /* copy the sample from the circular buffer to the destination buffer */ *dst = circBuffer[rOffset]; /* Update the input pointer */ dst += dstInc; if(dst == (q15_t *) dst_end) { dst = dst_base; } /* Circularly update wOffset. Watch out for positive and negative value */ rOffset += bufferInc; if(rOffset >= L) { rOffset -= L; } /* Decrement the loop counter */ i--; } /* Update the index pointer */ *readOffset = rOffset; } /** * @brief Q7 Circular write function. */ static __INLINE void arm_circularWrite_q7( q7_t * circBuffer, int32_t L, uint16_t * writeOffset, int32_t bufferInc, const q7_t * src, int32_t srcInc, uint32_t blockSize) { uint32_t i = 0u; int32_t wOffset; /* Copy the value of Index pointer that points * to the current location where the input samples to be copied */ wOffset = *writeOffset; /* Loop over the blockSize */ i = blockSize; while(i > 0u) { /* copy the input sample to the circular buffer */ circBuffer[wOffset] = *src; /* Update the input pointer */ src += srcInc; /* Circularly update wOffset. Watch out for positive and negative value */ wOffset += bufferInc; if(wOffset >= L) wOffset -= L; /* Decrement the loop counter */ i--; } /* Update the index pointer */ *writeOffset = wOffset; } /** * @brief Q7 Circular Read function. */ static __INLINE void arm_circularRead_q7( q7_t * circBuffer, int32_t L, int32_t * readOffset, int32_t bufferInc, q7_t * dst, q7_t * dst_base, int32_t dst_length, int32_t dstInc, uint32_t blockSize) { uint32_t i = 0; int32_t rOffset, dst_end; /* Copy the value of Index pointer that points * to the current location from where the input samples to be read */ rOffset = *readOffset; dst_end = (int32_t) (dst_base + dst_length); /* Loop over the blockSize */ i = blockSize; while(i > 0u) { /* copy the sample from the circular buffer to the destination buffer */ *dst = circBuffer[rOffset]; /* Update the input pointer */ dst += dstInc; if(dst == (q7_t *) dst_end) { dst = dst_base; } /* Circularly update rOffset. Watch out for positive and negative value */ rOffset += bufferInc; if(rOffset >= L) { rOffset -= L; } /* Decrement the loop counter */ i--; } /* Update the index pointer */ *readOffset = rOffset; } /** * @brief Sum of the squares of the elements of a Q31 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_power_q31( q31_t * pSrc, uint32_t blockSize, q63_t * pResult); /** * @brief Sum of the squares of the elements of a floating-point vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_power_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Sum of the squares of the elements of a Q15 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_power_q15( q15_t * pSrc, uint32_t blockSize, q63_t * pResult); /** * @brief Sum of the squares of the elements of a Q7 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_power_q7( q7_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Mean value of a Q7 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_mean_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult); /** * @brief Mean value of a Q15 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_mean_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /** * @brief Mean value of a Q31 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_mean_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Mean value of a floating-point vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_mean_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Variance of the elements of a floating-point vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_var_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Variance of the elements of a Q31 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_var_q31( q31_t * pSrc, uint32_t blockSize, q63_t * pResult); /** * @brief Variance of the elements of a Q15 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_var_q15( q15_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Root Mean Square of the elements of a floating-point vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_rms_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Root Mean Square of the elements of a Q31 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_rms_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Root Mean Square of the elements of a Q15 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_rms_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /** * @brief Standard deviation of the elements of a floating-point vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_std_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Standard deviation of the elements of a Q31 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_std_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Standard deviation of the elements of a Q15 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output value. * @return none. */ void arm_std_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /** * @brief Floating-point complex magnitude * @param[in] *pSrc points to the complex input vector * @param[out] *pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector * @return none. */ void arm_cmplx_mag_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples); /** * @brief Q31 complex magnitude * @param[in] *pSrc points to the complex input vector * @param[out] *pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector * @return none. */ void arm_cmplx_mag_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples); /** * @brief Q15 complex magnitude * @param[in] *pSrc points to the complex input vector * @param[out] *pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector * @return none. */ void arm_cmplx_mag_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples); /** * @brief Q15 complex dot product * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[in] numSamples number of complex samples in each vector * @param[out] *realResult real part of the result returned here * @param[out] *imagResult imaginary part of the result returned here * @return none. */ void arm_cmplx_dot_prod_q15( q15_t * pSrcA, q15_t * pSrcB, uint32_t numSamples, q31_t * realResult, q31_t * imagResult); /** * @brief Q31 complex dot product * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[in] numSamples number of complex samples in each vector * @param[out] *realResult real part of the result returned here * @param[out] *imagResult imaginary part of the result returned here * @return none. */ void arm_cmplx_dot_prod_q31( q31_t * pSrcA, q31_t * pSrcB, uint32_t numSamples, q63_t * realResult, q63_t * imagResult); /** * @brief Floating-point complex dot product * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[in] numSamples number of complex samples in each vector * @param[out] *realResult real part of the result returned here * @param[out] *imagResult imaginary part of the result returned here * @return none. */ void arm_cmplx_dot_prod_f32( float32_t * pSrcA, float32_t * pSrcB, uint32_t numSamples, float32_t * realResult, float32_t * imagResult); /** * @brief Q15 complex-by-real multiplication * @param[in] *pSrcCmplx points to the complex input vector * @param[in] *pSrcReal points to the real input vector * @param[out] *pCmplxDst points to the complex output vector * @param[in] numSamples number of samples in each vector * @return none. */ void arm_cmplx_mult_real_q15( q15_t * pSrcCmplx, q15_t * pSrcReal, q15_t * pCmplxDst, uint32_t numSamples); /** * @brief Q31 complex-by-real multiplication * @param[in] *pSrcCmplx points to the complex input vector * @param[in] *pSrcReal points to the real input vector * @param[out] *pCmplxDst points to the complex output vector * @param[in] numSamples number of samples in each vector * @return none. */ void arm_cmplx_mult_real_q31( q31_t * pSrcCmplx, q31_t * pSrcReal, q31_t * pCmplxDst, uint32_t numSamples); /** * @brief Floating-point complex-by-real multiplication * @param[in] *pSrcCmplx points to the complex input vector * @param[in] *pSrcReal points to the real input vector * @param[out] *pCmplxDst points to the complex output vector * @param[in] numSamples number of samples in each vector * @return none. */ void arm_cmplx_mult_real_f32( float32_t * pSrcCmplx, float32_t * pSrcReal, float32_t * pCmplxDst, uint32_t numSamples); /** * @brief Minimum value of a Q7 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *result is output pointer * @param[in] index is the array index of the minimum value in the input buffer. * @return none. */ void arm_min_q7( q7_t * pSrc, uint32_t blockSize, q7_t * result, uint32_t * index); /** * @brief Minimum value of a Q15 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output pointer * @param[in] *pIndex is the array index of the minimum value in the input buffer. * @return none. */ void arm_min_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex); /** * @brief Minimum value of a Q31 vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output pointer * @param[out] *pIndex is the array index of the minimum value in the input buffer. * @return none. */ void arm_min_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex); /** * @brief Minimum value of a floating-point vector. * @param[in] *pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] *pResult is output pointer * @param[out] *pIndex is the array index of the minimum value in the input buffer. * @return none. */ void arm_min_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a Q7 vector. * @param[in] *pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] *pResult maximum value returned here * @param[out] *pIndex index of maximum value returned here * @return none. */ void arm_max_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a Q15 vector. * @param[in] *pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] *pResult maximum value returned here * @param[out] *pIndex index of maximum value returned here * @return none. */ void arm_max_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a Q31 vector. * @param[in] *pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] *pResult maximum value returned here * @param[out] *pIndex index of maximum value returned here * @return none. */ void arm_max_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a floating-point vector. * @param[in] *pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] *pResult maximum value returned here * @param[out] *pIndex index of maximum value returned here * @return none. */ void arm_max_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex); /** * @brief Q15 complex-by-complex multiplication * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] numSamples number of complex samples in each vector * @return none. */ void arm_cmplx_mult_cmplx_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t numSamples); /** * @brief Q31 complex-by-complex multiplication * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] numSamples number of complex samples in each vector * @return none. */ void arm_cmplx_mult_cmplx_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t numSamples); /** * @brief Floating-point complex-by-complex multiplication * @param[in] *pSrcA points to the first input vector * @param[in] *pSrcB points to the second input vector * @param[out] *pDst points to the output vector * @param[in] numSamples number of complex samples in each vector * @return none. */ void arm_cmplx_mult_cmplx_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t numSamples); /** * @brief Converts the elements of the floating-point vector to Q31 vector. * @param[in] *pSrc points to the floating-point input vector * @param[out] *pDst points to the Q31 output vector * @param[in] blockSize length of the input vector * @return none. */ void arm_float_to_q31( float32_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the floating-point vector to Q15 vector. * @param[in] *pSrc points to the floating-point input vector * @param[out] *pDst points to the Q15 output vector * @param[in] blockSize length of the input vector * @return none */ void arm_float_to_q15( float32_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the floating-point vector to Q7 vector. * @param[in] *pSrc points to the floating-point input vector * @param[out] *pDst points to the Q7 output vector * @param[in] blockSize length of the input vector * @return none */ void arm_float_to_q7( float32_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q31 vector to Q15 vector. * @param[in] *pSrc is input pointer * @param[out] *pDst is output pointer * @param[in] blockSize is the number of samples to process * @return none. */ void arm_q31_to_q15( q31_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q31 vector to Q7 vector. * @param[in] *pSrc is input pointer * @param[out] *pDst is output pointer * @param[in] blockSize is the number of samples to process * @return none. */ void arm_q31_to_q7( q31_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q15 vector to floating-point vector. * @param[in] *pSrc is input pointer * @param[out] *pDst is output pointer * @param[in] blockSize is the number of samples to process * @return none. */ void arm_q15_to_float( q15_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q15 vector to Q31 vector. * @param[in] *pSrc is input pointer * @param[out] *pDst is output pointer * @param[in] blockSize is the number of samples to process * @return none. */ void arm_q15_to_q31( q15_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q15 vector to Q7 vector. * @param[in] *pSrc is input pointer * @param[out] *pDst is output pointer * @param[in] blockSize is the number of samples to process * @return none. */ void arm_q15_to_q7( q15_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @ingroup groupInterpolation */ /** * @defgroup BilinearInterpolate Bilinear Interpolation * * Bilinear interpolation is an extension of linear interpolation applied to a two dimensional grid. * The underlying function <code>f(x, y)</code> is sampled on a regular grid and the interpolation process * determines values between the grid points. * Bilinear interpolation is equivalent to two step linear interpolation, first in the x-dimension and then in the y-dimension. * Bilinear interpolation is often used in image processing to rescale images. * The CMSIS DSP library provides bilinear interpolation functions for Q7, Q15, Q31, and floating-point data types. * * <b>Algorithm</b> * \par * The instance structure used by the bilinear interpolation functions describes a two dimensional data table. * For floating-point, the instance structure is defined as: * <pre> * typedef struct * { * uint16_t numRows; * uint16_t numCols; * float32_t *pData; * } arm_bilinear_interp_instance_f32; * </pre> * * \par * where <code>numRows</code> specifies the number of rows in the table; * <code>numCols</code> specifies the number of columns in the table; * and <code>pData</code> points to an array of size <code>numRows*numCols</code> values. * The data table <code>pTable</code> is organized in row order and the supplied data values fall on integer indexes. * That is, table element (x,y) is located at <code>pTable[x + y*numCols]</code> where x and y are integers. * * \par * Let <code>(x, y)</code> specify the desired interpolation point. Then define: * <pre> * XF = floor(x) * YF = floor(y) * </pre> * \par * The interpolated output point is computed as: * <pre> * f(x, y) = f(XF, YF) * (1-(x-XF)) * (1-(y-YF)) * + f(XF+1, YF) * (x-XF)*(1-(y-YF)) * + f(XF, YF+1) * (1-(x-XF))*(y-YF) * + f(XF+1, YF+1) * (x-XF)*(y-YF) * </pre> * Note that the coordinates (x, y) contain integer and fractional components. * The integer components specify which portion of the table to use while the * fractional components control the interpolation processor. * * \par * if (x,y) are outside of the table boundary, Bilinear interpolation returns zero output. */ /** * @addtogroup BilinearInterpolate * @{ */ /** * * @brief Floating-point bilinear interpolation. * @param[in,out] *S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate. * @param[in] Y interpolation coordinate. * @return out interpolated value. */ static __INLINE float32_t arm_bilinear_interp_f32( const arm_bilinear_interp_instance_f32 * S, float32_t X, float32_t Y) { float32_t out; float32_t f00, f01, f10, f11; float32_t *pData = S->pData; int32_t xIndex, yIndex, index; float32_t xdiff, ydiff; float32_t b1, b2, b3, b4; xIndex = (int32_t) X; yIndex = (int32_t) Y; /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if(xIndex < 0 || xIndex > (S->numRows-1) || yIndex < 0 || yIndex > ( S->numCols-1)) { return(0); } /* Calculation of index for two nearest points in X-direction */ index = (xIndex - 1) + (yIndex-1) * S->numCols ; /* Read two nearest points in X-direction */ f00 = pData[index]; f01 = pData[index + 1]; /* Calculation of index for two nearest points in Y-direction */ index = (xIndex-1) + (yIndex) * S->numCols; /* Read two nearest points in Y-direction */ f10 = pData[index]; f11 = pData[index + 1]; /* Calculation of intermediate values */ b1 = f00; b2 = f01 - f00; b3 = f10 - f00; b4 = f00 - f01 - f10 + f11; /* Calculation of fractional part in X */ xdiff = X - xIndex; /* Calculation of fractional part in Y */ ydiff = Y - yIndex; /* Calculation of bi-linear interpolated output */ out = b1 + b2 * xdiff + b3 * ydiff + b4 * xdiff * ydiff; /* return to application */ return (out); } /** * * @brief Q31 bilinear interpolation. * @param[in,out] *S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate in 12.20 format. * @param[in] Y interpolation coordinate in 12.20 format. * @return out interpolated value. */ static __INLINE q31_t arm_bilinear_interp_q31( arm_bilinear_interp_instance_q31 * S, q31_t X, q31_t Y) { q31_t out; /* Temporary output */ q31_t acc = 0; /* output */ q31_t xfract, yfract; /* X, Y fractional parts */ q31_t x1, x2, y1, y2; /* Nearest output values */ int32_t rI, cI; /* Row and column indices */ q31_t *pYData = S->pData; /* pointer to output table values */ uint32_t nCols = S->numCols; /* num of rows */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ rI = ((X & 0xFFF00000) >> 20u); /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ cI = ((Y & 0xFFF00000) >> 20u); /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if(rI < 0 || rI > (S->numRows-1) || cI < 0 || cI > ( S->numCols-1)) { return(0); } /* 20 bits for the fractional part */ /* shift left xfract by 11 to keep 1.31 format */ xfract = (X & 0x000FFFFF) << 11u; /* Read two nearest output values from the index */ x1 = pYData[(rI) + nCols * (cI)]; x2 = pYData[(rI) + nCols * (cI) + 1u]; /* 20 bits for the fractional part */ /* shift left yfract by 11 to keep 1.31 format */ yfract = (Y & 0x000FFFFF) << 11u; /* Read two nearest output values from the index */ y1 = pYData[(rI) + nCols * (cI + 1)]; y2 = pYData[(rI) + nCols * (cI + 1) + 1u]; /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 3.29(q29) format */ out = ((q31_t) (((q63_t) x1 * (0x7FFFFFFF - xfract)) >> 32)); acc = ((q31_t) (((q63_t) out * (0x7FFFFFFF - yfract)) >> 32)); /* x2 * (xfract) * (1-yfract) in 3.29(q29) and adding to acc */ out = ((q31_t) ((q63_t) x2 * (0x7FFFFFFF - yfract) >> 32)); acc += ((q31_t) ((q63_t) out * (xfract) >> 32)); /* y1 * (1 - xfract) * (yfract) in 3.29(q29) and adding to acc */ out = ((q31_t) ((q63_t) y1 * (0x7FFFFFFF - xfract) >> 32)); acc += ((q31_t) ((q63_t) out * (yfract) >> 32)); /* y2 * (xfract) * (yfract) in 3.29(q29) and adding to acc */ out = ((q31_t) ((q63_t) y2 * (xfract) >> 32)); acc += ((q31_t) ((q63_t) out * (yfract) >> 32)); /* Convert acc to 1.31(q31) format */ return (acc << 2u); } /** * @brief Q15 bilinear interpolation. * @param[in,out] *S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate in 12.20 format. * @param[in] Y interpolation coordinate in 12.20 format. * @return out interpolated value. */ static __INLINE q15_t arm_bilinear_interp_q15( arm_bilinear_interp_instance_q15 * S, q31_t X, q31_t Y) { q63_t acc = 0; /* output */ q31_t out; /* Temporary output */ q15_t x1, x2, y1, y2; /* Nearest output values */ q31_t xfract, yfract; /* X, Y fractional parts */ int32_t rI, cI; /* Row and column indices */ q15_t *pYData = S->pData; /* pointer to output table values */ uint32_t nCols = S->numCols; /* num of rows */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ rI = ((X & 0xFFF00000) >> 20); /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ cI = ((Y & 0xFFF00000) >> 20); /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if(rI < 0 || rI > (S->numRows-1) || cI < 0 || cI > ( S->numCols-1)) { return(0); } /* 20 bits for the fractional part */ /* xfract should be in 12.20 format */ xfract = (X & 0x000FFFFF); /* Read two nearest output values from the index */ x1 = pYData[(rI) + nCols * (cI)]; x2 = pYData[(rI) + nCols * (cI) + 1u]; /* 20 bits for the fractional part */ /* yfract should be in 12.20 format */ yfract = (Y & 0x000FFFFF); /* Read two nearest output values from the index */ y1 = pYData[(rI) + nCols * (cI + 1)]; y2 = pYData[(rI) + nCols * (cI + 1) + 1u]; /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 13.51 format */ /* x1 is in 1.15(q15), xfract in 12.20 format and out is in 13.35 format */ /* convert 13.35 to 13.31 by right shifting and out is in 1.31 */ out = (q31_t) (((q63_t) x1 * (0xFFFFF - xfract)) >> 4u); acc = ((q63_t) out * (0xFFFFF - yfract)); /* x2 * (xfract) * (1-yfract) in 1.51 and adding to acc */ out = (q31_t) (((q63_t) x2 * (0xFFFFF - yfract)) >> 4u); acc += ((q63_t) out * (xfract)); /* y1 * (1 - xfract) * (yfract) in 1.51 and adding to acc */ out = (q31_t) (((q63_t) y1 * (0xFFFFF - xfract)) >> 4u); acc += ((q63_t) out * (yfract)); /* y2 * (xfract) * (yfract) in 1.51 and adding to acc */ out = (q31_t) (((q63_t) y2 * (xfract)) >> 4u); acc += ((q63_t) out * (yfract)); /* acc is in 13.51 format and down shift acc by 36 times */ /* Convert out to 1.15 format */ return (acc >> 36); } /** * @brief Q7 bilinear interpolation. * @param[in,out] *S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate in 12.20 format. * @param[in] Y interpolation coordinate in 12.20 format. * @return out interpolated value. */ static __INLINE q7_t arm_bilinear_interp_q7( arm_bilinear_interp_instance_q7 * S, q31_t X, q31_t Y) { q63_t acc = 0; /* output */ q31_t out; /* Temporary output */ q31_t xfract, yfract; /* X, Y fractional parts */ q7_t x1, x2, y1, y2; /* Nearest output values */ int32_t rI, cI; /* Row and column indices */ q7_t *pYData = S->pData; /* pointer to output table values */ uint32_t nCols = S->numCols; /* num of rows */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ rI = ((X & 0xFFF00000) >> 20); /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ cI = ((Y & 0xFFF00000) >> 20); /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if(rI < 0 || rI > (S->numRows-1) || cI < 0 || cI > ( S->numCols-1)) { return(0); } /* 20 bits for the fractional part */ /* xfract should be in 12.20 format */ xfract = (X & 0x000FFFFF); /* Read two nearest output values from the index */ x1 = pYData[(rI) + nCols * (cI)]; x2 = pYData[(rI) + nCols * (cI) + 1u]; /* 20 bits for the fractional part */ /* yfract should be in 12.20 format */ yfract = (Y & 0x000FFFFF); /* Read two nearest output values from the index */ y1 = pYData[(rI) + nCols * (cI + 1)]; y2 = pYData[(rI) + nCols * (cI + 1) + 1u]; /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 16.47 format */ out = ((x1 * (0xFFFFF - xfract))); acc = (((q63_t) out * (0xFFFFF - yfract))); /* x2 * (xfract) * (1-yfract) in 2.22 and adding to acc */ out = ((x2 * (0xFFFFF - yfract))); acc += (((q63_t) out * (xfract))); /* y1 * (1 - xfract) * (yfract) in 2.22 and adding to acc */ out = ((y1 * (0xFFFFF - xfract))); acc += (((q63_t) out * (yfract))); /* y2 * (xfract) * (yfract) in 2.22 and adding to acc */ out = ((y2 * (yfract))); acc += (((q63_t) out * (xfract))); /* acc in 16.47 format and down shift by 40 to convert to 1.7 format */ return (acc >> 40); } /** * @} end of BilinearInterpolate group */ #ifdef __cplusplus } #endif #endif /* _ARM_MATH_H */ /** * * End of file. */
1137519-player
lib/CMSIS/Include/arm_math.h
C
lgpl
240,326
/**************************************************************************//** * @file core_cm4.h * @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File * @version V2.10 * @date 19. July 2011 * * @note * Copyright (C) 2009-2011 ARM Limited. All rights reserved. * * @par * ARM Limited (ARM) is supplying this software for use with Cortex-M * processor based microcontrollers. This file can be freely distributed * within development tools that are supporting such ARM based processors. * * @par * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * ******************************************************************************/ #if defined ( __ICCARM__ ) #pragma system_include /* treat file as system include file for MISRA check */ #endif #ifdef __cplusplus extern "C" { #endif #ifndef __CORE_CM4_H_GENERIC #define __CORE_CM4_H_GENERIC /** \mainpage CMSIS Cortex-M4 This documentation describes the CMSIS Cortex-M Core Peripheral Access Layer. It consists of: - Cortex-M Core Register Definitions - Cortex-M functions - Cortex-M instructions - Cortex-M SIMD instructions The CMSIS Cortex-M4 Core Peripheral Access Layer contains C and assembly functions that ease access to the Cortex-M Core */ /** \defgroup CMSIS_MISRA_Exceptions CMSIS MISRA-C:2004 Compliance Exceptions CMSIS violates following MISRA-C2004 Rules: - Violates MISRA 2004 Required Rule 8.5, object/function definition in header file.<br> Function definitions in header files are used to allow 'inlining'. - Violates MISRA 2004 Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br> Unions are used for effective representation of core registers. - Violates MISRA 2004 Advisory Rule 19.7, Function-like macro defined.<br> Function-like macros are used to allow more efficient code. */ /******************************************************************************* * CMSIS definitions ******************************************************************************/ /** \defgroup CMSIS_core_definitions CMSIS Core Definitions This file defines all structures and symbols for CMSIS core: - CMSIS version number - Cortex-M core - Cortex-M core Revision Number @{ */ /* CMSIS CM4 definitions */ #define __CM4_CMSIS_VERSION_MAIN (0x02) /*!< [31:16] CMSIS HAL main version */ #define __CM4_CMSIS_VERSION_SUB (0x10) /*!< [15:0] CMSIS HAL sub version */ #define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16) | __CM4_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */ #define __CORTEX_M (0x04) /*!< Cortex core */ #if defined ( __CC_ARM ) #define __ASM __asm /*!< asm keyword for ARM Compiler */ #define __INLINE __inline /*!< inline keyword for ARM Compiler */ #elif defined ( __ICCARM__ ) #define __ASM __asm /*!< asm keyword for IAR Compiler */ #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ #elif defined ( __GNUC__ ) #define __ASM __asm /*!< asm keyword for GNU Compiler */ #define __INLINE inline /*!< inline keyword for GNU Compiler */ #elif defined ( __TASKING__ ) #define __ASM __asm /*!< asm keyword for TASKING Compiler */ #define __INLINE inline /*!< inline keyword for TASKING Compiler */ #endif /*!< __FPU_USED to be checked prior to making use of FPU specific registers and functions */ #if defined ( __CC_ARM ) #if defined __TARGET_FPU_VFP #if (__FPU_PRESENT == 1) #define __FPU_USED 1 #else #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #define __FPU_USED 0 #endif #else #define __FPU_USED 0 #endif #elif defined ( __ICCARM__ ) #if defined __ARMVFP__ #if (__FPU_PRESENT == 1) #define __FPU_USED 1 #else #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #define __FPU_USED 0 #endif #else #define __FPU_USED 0 #endif #elif defined ( __GNUC__ ) #if defined (__VFP_FP__) && !defined(__SOFTFP__) #if (__FPU_PRESENT == 1) #define __FPU_USED 1 #else #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #define __FPU_USED 0 #endif #else #define __FPU_USED 0 #endif #elif defined ( __TASKING__ ) /* add preprocessor checks to define __FPU_USED */ #define __FPU_USED 0 #endif #include <stdint.h> /*!< standard types definitions */ #include <core_cmInstr.h> /*!< Core Instruction Access */ #include <core_cmFunc.h> /*!< Core Function Access */ #include <core_cm4_simd.h> /*!< Compiler specific SIMD Intrinsics */ #endif /* __CORE_CM4_H_GENERIC */ #ifndef __CMSIS_GENERIC #ifndef __CORE_CM4_H_DEPENDANT #define __CORE_CM4_H_DEPENDANT /* check device defines and use defaults */ #if defined __CHECK_DEVICE_DEFINES #ifndef __CM4_REV #define __CM4_REV 0x0000 #warning "__CM4_REV not defined in device header file; using default!" #endif #ifndef __FPU_PRESENT #define __FPU_PRESENT 0 #warning "__FPU_PRESENT not defined in device header file; using default!" #endif #ifndef __MPU_PRESENT #define __MPU_PRESENT 0 #warning "__MPU_PRESENT not defined in device header file; using default!" #endif #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 4 #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" #endif #ifndef __Vendor_SysTickConfig #define __Vendor_SysTickConfig 0 #warning "__Vendor_SysTickConfig not defined in device header file; using default!" #endif #endif /* IO definitions (access restrictions to peripheral registers) */ #ifdef __cplusplus #define __I volatile /*!< defines 'read only' permissions */ #else #define __I volatile const /*!< defines 'read only' permissions */ #endif #define __O volatile /*!< defines 'write only' permissions */ #define __IO volatile /*!< defines 'read / write' permissions */ /*@} end of group CMSIS_core_definitions */ /******************************************************************************* * Register Abstraction ******************************************************************************/ /** \defgroup CMSIS_core_register CMSIS Core Register Core Register contain: - Core Register - Core NVIC Register - Core SCB Register - Core SysTick Register - Core Debug Register - Core MPU Register - Core FPU Register */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CORE CMSIS Core Type definitions for the Cortex-M Core Registers @{ */ /** \brief Union type to access the Application Program Status Register (APSR). */ typedef union { struct { #if (__CORTEX_M != 0x04) uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */ #else uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ #endif uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ uint32_t N:1; /*!< bit: 31 Negative condition code flag */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } APSR_Type; /** \brief Union type to access the Interrupt Program Status Register (IPSR). */ typedef union { struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } IPSR_Type; /** \brief Union type to access the Special-Purpose Program Status Registers (xPSR). */ typedef union { struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ #if (__CORTEX_M != 0x04) uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ #else uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ #endif uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ uint32_t N:1; /*!< bit: 31 Negative condition code flag */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } xPSR_Type; /** \brief Union type to access the Control Registers (CONTROL). */ typedef union { struct { uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } CONTROL_Type; /*@} end of group CMSIS_CORE */ /** \ingroup CMSIS_core_register \defgroup CMSIS_NVIC CMSIS NVIC Type definitions for the Cortex-M NVIC Registers @{ */ /** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). */ typedef struct { __IO uint32_t ISER[8]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ uint32_t RESERVED0[24]; __IO uint32_t ICER[8]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ uint32_t RSERVED1[24]; __IO uint32_t ISPR[8]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ uint32_t RESERVED2[24]; __IO uint32_t ICPR[8]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ uint32_t RESERVED3[24]; __IO uint32_t IABR[8]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ uint32_t RESERVED4[56]; __IO uint8_t IP[240]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ uint32_t RESERVED5[644]; __O uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ } NVIC_Type; /* Software Triggered Interrupt Register Definitions */ #define NVIC_STIR_INTID_Pos 0 /*!< STIR: INTLINESNUM Position */ #define NVIC_STIR_INTID_Msk (0x1FFUL << NVIC_STIR_INTID_Pos) /*!< STIR: INTLINESNUM Mask */ /*@} end of group CMSIS_NVIC */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SCB CMSIS SCB Type definitions for the Cortex-M System Control Block Registers @{ */ /** \brief Structure type to access the System Control Block (SCB). */ typedef struct { __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ __IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ __IO uint8_t SHP[12]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ __IO uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ __IO uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ __IO uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ __IO uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ __IO uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ __IO uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ __I uint32_t PFR[2]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ __I uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ __I uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ __I uint32_t MMFR[4]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ __I uint32_t ISAR[5]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ uint32_t RESERVED0[5]; __IO uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ } SCB_Type; /* SCB CPUID Register Definitions */ #define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */ #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ #define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */ #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ #define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */ #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ #define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */ #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ #define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */ #define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */ /* SCB Interrupt Control State Register Definitions */ #define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */ #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ #define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */ #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ #define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */ #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ #define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */ #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ #define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */ #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ #define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */ #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ #define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */ #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ #define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */ #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ #define SCB_ICSR_RETTOBASE_Pos 11 /*!< SCB ICSR: RETTOBASE Position */ #define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */ #define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */ #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */ /* SCB Vector Table Offset Register Definitions */ #define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */ #define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ /* SCB Application Interrupt and Reset Control Register Definitions */ #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */ #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ #define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */ #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ #define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */ #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ #define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */ #define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */ #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ #define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */ #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ #define SCB_AIRCR_VECTRESET_Pos 0 /*!< SCB AIRCR: VECTRESET Position */ #define SCB_AIRCR_VECTRESET_Msk (1UL << SCB_AIRCR_VECTRESET_Pos) /*!< SCB AIRCR: VECTRESET Mask */ /* SCB System Control Register Definitions */ #define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */ #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ #define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */ #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ #define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */ #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ /* SCB Configuration Control Register Definitions */ #define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */ #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ #define SCB_CCR_BFHFNMIGN_Pos 8 /*!< SCB CCR: BFHFNMIGN Position */ #define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ #define SCB_CCR_DIV_0_TRP_Pos 4 /*!< SCB CCR: DIV_0_TRP Position */ #define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */ #define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */ #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ #define SCB_CCR_USERSETMPEND_Pos 1 /*!< SCB CCR: USERSETMPEND Position */ #define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ #define SCB_CCR_NONBASETHRDENA_Pos 0 /*!< SCB CCR: NONBASETHRDENA Position */ #define SCB_CCR_NONBASETHRDENA_Msk (1UL << SCB_CCR_NONBASETHRDENA_Pos) /*!< SCB CCR: NONBASETHRDENA Mask */ /* SCB System Handler Control and State Register Definitions */ #define SCB_SHCSR_USGFAULTENA_Pos 18 /*!< SCB SHCSR: USGFAULTENA Position */ #define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ #define SCB_SHCSR_BUSFAULTENA_Pos 17 /*!< SCB SHCSR: BUSFAULTENA Position */ #define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ #define SCB_SHCSR_MEMFAULTENA_Pos 16 /*!< SCB SHCSR: MEMFAULTENA Position */ #define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ #define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */ #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ #define SCB_SHCSR_BUSFAULTPENDED_Pos 14 /*!< SCB SHCSR: BUSFAULTPENDED Position */ #define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ #define SCB_SHCSR_MEMFAULTPENDED_Pos 13 /*!< SCB SHCSR: MEMFAULTPENDED Position */ #define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ #define SCB_SHCSR_USGFAULTPENDED_Pos 12 /*!< SCB SHCSR: USGFAULTPENDED Position */ #define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ #define SCB_SHCSR_SYSTICKACT_Pos 11 /*!< SCB SHCSR: SYSTICKACT Position */ #define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ #define SCB_SHCSR_PENDSVACT_Pos 10 /*!< SCB SHCSR: PENDSVACT Position */ #define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ #define SCB_SHCSR_MONITORACT_Pos 8 /*!< SCB SHCSR: MONITORACT Position */ #define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ #define SCB_SHCSR_SVCALLACT_Pos 7 /*!< SCB SHCSR: SVCALLACT Position */ #define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ #define SCB_SHCSR_USGFAULTACT_Pos 3 /*!< SCB SHCSR: USGFAULTACT Position */ #define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ #define SCB_SHCSR_BUSFAULTACT_Pos 1 /*!< SCB SHCSR: BUSFAULTACT Position */ #define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ #define SCB_SHCSR_MEMFAULTACT_Pos 0 /*!< SCB SHCSR: MEMFAULTACT Position */ #define SCB_SHCSR_MEMFAULTACT_Msk (1UL << SCB_SHCSR_MEMFAULTACT_Pos) /*!< SCB SHCSR: MEMFAULTACT Mask */ /* SCB Configurable Fault Status Registers Definitions */ #define SCB_CFSR_USGFAULTSR_Pos 16 /*!< SCB CFSR: Usage Fault Status Register Position */ #define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ #define SCB_CFSR_BUSFAULTSR_Pos 8 /*!< SCB CFSR: Bus Fault Status Register Position */ #define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ #define SCB_CFSR_MEMFAULTSR_Pos 0 /*!< SCB CFSR: Memory Manage Fault Status Register Position */ #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL << SCB_CFSR_MEMFAULTSR_Pos) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* SCB Hard Fault Status Registers Definitions */ #define SCB_HFSR_DEBUGEVT_Pos 31 /*!< SCB HFSR: DEBUGEVT Position */ #define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ #define SCB_HFSR_FORCED_Pos 30 /*!< SCB HFSR: FORCED Position */ #define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ #define SCB_HFSR_VECTTBL_Pos 1 /*!< SCB HFSR: VECTTBL Position */ #define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ /* SCB Debug Fault Status Register Definitions */ #define SCB_DFSR_EXTERNAL_Pos 4 /*!< SCB DFSR: EXTERNAL Position */ #define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ #define SCB_DFSR_VCATCH_Pos 3 /*!< SCB DFSR: VCATCH Position */ #define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ #define SCB_DFSR_DWTTRAP_Pos 2 /*!< SCB DFSR: DWTTRAP Position */ #define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ #define SCB_DFSR_BKPT_Pos 1 /*!< SCB DFSR: BKPT Position */ #define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ #define SCB_DFSR_HALTED_Pos 0 /*!< SCB DFSR: HALTED Position */ #define SCB_DFSR_HALTED_Msk (1UL << SCB_DFSR_HALTED_Pos) /*!< SCB DFSR: HALTED Mask */ /*@} end of group CMSIS_SCB */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SCnSCB CMSIS System Control and ID Register not in the SCB Type definitions for the Cortex-M System Control and ID Register not in the SCB @{ */ /** \brief Structure type to access the System Control and ID Register not in the SCB. */ typedef struct { uint32_t RESERVED0[1]; __I uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ __IO uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ } SCnSCB_Type; /* Interrupt Controller Type Register Definitions */ #define SCnSCB_ICTR_INTLINESNUM_Pos 0 /*!< ICTR: INTLINESNUM Position */ #define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL << SCnSCB_ICTR_INTLINESNUM_Pos) /*!< ICTR: INTLINESNUM Mask */ /* Auxiliary Control Register Definitions */ #define SCnSCB_ACTLR_DISOOFP_Pos 9 /*!< ACTLR: DISOOFP Position */ #define SCnSCB_ACTLR_DISOOFP_Msk (1UL << SCnSCB_ACTLR_DISOOFP_Pos) /*!< ACTLR: DISOOFP Mask */ #define SCnSCB_ACTLR_DISFPCA_Pos 8 /*!< ACTLR: DISFPCA Position */ #define SCnSCB_ACTLR_DISFPCA_Msk (1UL << SCnSCB_ACTLR_DISFPCA_Pos) /*!< ACTLR: DISFPCA Mask */ #define SCnSCB_ACTLR_DISFOLD_Pos 2 /*!< ACTLR: DISFOLD Position */ #define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ #define SCnSCB_ACTLR_DISDEFWBUF_Pos 1 /*!< ACTLR: DISDEFWBUF Position */ #define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */ #define SCnSCB_ACTLR_DISMCYCINT_Pos 0 /*!< ACTLR: DISMCYCINT Position */ #define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL << SCnSCB_ACTLR_DISMCYCINT_Pos) /*!< ACTLR: DISMCYCINT Mask */ /*@} end of group CMSIS_SCnotSCB */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SysTick CMSIS SysTick Type definitions for the Cortex-M System Timer Registers @{ */ /** \brief Structure type to access the System Timer (SysTick). */ typedef struct { __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ } SysTick_Type; /* SysTick Control / Status Register Definitions */ #define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */ #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ #define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */ #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ #define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */ #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ #define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */ #define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */ /* SysTick Reload Register Definitions */ #define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */ #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */ /* SysTick Current Register Definitions */ #define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */ #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */ /* SysTick Calibration Register Definitions */ #define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */ #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ #define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */ #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ #define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */ #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */ /*@} end of group CMSIS_SysTick */ /** \ingroup CMSIS_core_register \defgroup CMSIS_ITM CMSIS ITM Type definitions for the Cortex-M Instrumentation Trace Macrocell (ITM) @{ */ /** \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). */ typedef struct { __O union { __O uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ __O uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ __O uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ } PORT [32]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ uint32_t RESERVED0[864]; __IO uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ uint32_t RESERVED1[15]; __IO uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ uint32_t RESERVED2[15]; __IO uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ } ITM_Type; /* ITM Trace Privilege Register Definitions */ #define ITM_TPR_PRIVMASK_Pos 0 /*!< ITM TPR: PRIVMASK Position */ #define ITM_TPR_PRIVMASK_Msk (0xFUL << ITM_TPR_PRIVMASK_Pos) /*!< ITM TPR: PRIVMASK Mask */ /* ITM Trace Control Register Definitions */ #define ITM_TCR_BUSY_Pos 23 /*!< ITM TCR: BUSY Position */ #define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ #define ITM_TCR_TraceBusID_Pos 16 /*!< ITM TCR: ATBID Position */ #define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */ #define ITM_TCR_GTSFREQ_Pos 10 /*!< ITM TCR: Global timestamp frequency Position */ #define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ #define ITM_TCR_TSPrescale_Pos 8 /*!< ITM TCR: TSPrescale Position */ #define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */ #define ITM_TCR_SWOENA_Pos 4 /*!< ITM TCR: SWOENA Position */ #define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ #define ITM_TCR_TXENA_Pos 3 /*!< ITM TCR: TXENA Position */ #define ITM_TCR_TXENA_Msk (1UL << ITM_TCR_TXENA_Pos) /*!< ITM TCR: TXENA Mask */ #define ITM_TCR_SYNCENA_Pos 2 /*!< ITM TCR: SYNCENA Position */ #define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ #define ITM_TCR_TSENA_Pos 1 /*!< ITM TCR: TSENA Position */ #define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ #define ITM_TCR_ITMENA_Pos 0 /*!< ITM TCR: ITM Enable bit Position */ #define ITM_TCR_ITMENA_Msk (1UL << ITM_TCR_ITMENA_Pos) /*!< ITM TCR: ITM Enable bit Mask */ /*@}*/ /* end of group CMSIS_ITM */ #if (__MPU_PRESENT == 1) /** \ingroup CMSIS_core_register \defgroup CMSIS_MPU CMSIS MPU Type definitions for the Cortex-M Memory Protection Unit (MPU) @{ */ /** \brief Structure type to access the Memory Protection Unit (MPU). */ typedef struct { __I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ __IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ __IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ __IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ __IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ __IO uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ __IO uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ __IO uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ __IO uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ __IO uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ __IO uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ } MPU_Type; /* MPU Type Register */ #define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */ #define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ #define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */ #define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ #define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */ #define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */ /* MPU Control Register */ #define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */ #define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ #define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */ #define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ #define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */ #define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */ /* MPU Region Number Register */ #define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */ #define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */ /* MPU Region Base Address Register */ #define MPU_RBAR_ADDR_Pos 5 /*!< MPU RBAR: ADDR Position */ #define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ #define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */ #define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ #define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */ #define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */ /* MPU Region Attribute and Size Register */ #define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */ #define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ #define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */ #define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ #define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */ #define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ #define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */ #define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos) /*!< MPU RASR: Region enable bit Disable Mask */ /*@} end of group CMSIS_MPU */ #endif #if (__FPU_PRESENT == 1) /** \ingroup CMSIS_core_register \defgroup CMSIS_FPU CMSIS FPU Type definitions for the Cortex-M Floating Point Unit (FPU) @{ */ /** \brief Structure type to access the Floating Point Unit (FPU). */ typedef struct { uint32_t RESERVED0[1]; __IO uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ __IO uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ __IO uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ __I uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ __I uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ } FPU_Type; /* Floating-Point Context Control Register */ #define FPU_FPCCR_ASPEN_Pos 31 /*!< FPCCR: ASPEN bit Position */ #define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */ #define FPU_FPCCR_LSPEN_Pos 30 /*!< FPCCR: LSPEN Position */ #define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */ #define FPU_FPCCR_MONRDY_Pos 8 /*!< FPCCR: MONRDY Position */ #define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */ #define FPU_FPCCR_BFRDY_Pos 6 /*!< FPCCR: BFRDY Position */ #define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */ #define FPU_FPCCR_MMRDY_Pos 5 /*!< FPCCR: MMRDY Position */ #define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */ #define FPU_FPCCR_HFRDY_Pos 4 /*!< FPCCR: HFRDY Position */ #define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */ #define FPU_FPCCR_THREAD_Pos 3 /*!< FPCCR: processor mode bit Position */ #define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */ #define FPU_FPCCR_USER_Pos 1 /*!< FPCCR: privilege level bit Position */ #define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */ #define FPU_FPCCR_LSPACT_Pos 0 /*!< FPCCR: Lazy state preservation active bit Position */ #define FPU_FPCCR_LSPACT_Msk (1UL << FPU_FPCCR_LSPACT_Pos) /*!< FPCCR: Lazy state preservation active bit Mask */ /* Floating-Point Context Address Register */ #define FPU_FPCAR_ADDRESS_Pos 3 /*!< FPCAR: ADDRESS bit Position */ #define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */ /* Floating-Point Default Status Control Register */ #define FPU_FPDSCR_AHP_Pos 26 /*!< FPDSCR: AHP bit Position */ #define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */ #define FPU_FPDSCR_DN_Pos 25 /*!< FPDSCR: DN bit Position */ #define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */ #define FPU_FPDSCR_FZ_Pos 24 /*!< FPDSCR: FZ bit Position */ #define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */ #define FPU_FPDSCR_RMode_Pos 22 /*!< FPDSCR: RMode bit Position */ #define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ /* Media and FP Feature Register 0 */ #define FPU_MVFR0_FP_rounding_modes_Pos 28 /*!< MVFR0: FP rounding modes bits Position */ #define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ #define FPU_MVFR0_Short_vectors_Pos 24 /*!< MVFR0: Short vectors bits Position */ #define FPU_MVFR0_Short_vectors_Msk (0xFUL << FPU_MVFR0_Short_vectors_Pos) /*!< MVFR0: Short vectors bits Mask */ #define FPU_MVFR0_Square_root_Pos 20 /*!< MVFR0: Square root bits Position */ #define FPU_MVFR0_Square_root_Msk (0xFUL << FPU_MVFR0_Square_root_Pos) /*!< MVFR0: Square root bits Mask */ #define FPU_MVFR0_Divide_Pos 16 /*!< MVFR0: Divide bits Position */ #define FPU_MVFR0_Divide_Msk (0xFUL << FPU_MVFR0_Divide_Pos) /*!< MVFR0: Divide bits Mask */ #define FPU_MVFR0_FP_excep_trapping_Pos 12 /*!< MVFR0: FP exception trapping bits Position */ #define FPU_MVFR0_FP_excep_trapping_Msk (0xFUL << FPU_MVFR0_FP_excep_trapping_Pos) /*!< MVFR0: FP exception trapping bits Mask */ #define FPU_MVFR0_Double_precision_Pos 8 /*!< MVFR0: Double-precision bits Position */ #define FPU_MVFR0_Double_precision_Msk (0xFUL << FPU_MVFR0_Double_precision_Pos) /*!< MVFR0: Double-precision bits Mask */ #define FPU_MVFR0_Single_precision_Pos 4 /*!< MVFR0: Single-precision bits Position */ #define FPU_MVFR0_Single_precision_Msk (0xFUL << FPU_MVFR0_Single_precision_Pos) /*!< MVFR0: Single-precision bits Mask */ #define FPU_MVFR0_A_SIMD_registers_Pos 0 /*!< MVFR0: A_SIMD registers bits Position */ #define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL << FPU_MVFR0_A_SIMD_registers_Pos) /*!< MVFR0: A_SIMD registers bits Mask */ /* Media and FP Feature Register 1 */ #define FPU_MVFR1_FP_fused_MAC_Pos 28 /*!< MVFR1: FP fused MAC bits Position */ #define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ #define FPU_MVFR1_FP_HPFP_Pos 24 /*!< MVFR1: FP HPFP bits Position */ #define FPU_MVFR1_FP_HPFP_Msk (0xFUL << FPU_MVFR1_FP_HPFP_Pos) /*!< MVFR1: FP HPFP bits Mask */ #define FPU_MVFR1_D_NaN_mode_Pos 4 /*!< MVFR1: D_NaN mode bits Position */ #define FPU_MVFR1_D_NaN_mode_Msk (0xFUL << FPU_MVFR1_D_NaN_mode_Pos) /*!< MVFR1: D_NaN mode bits Mask */ #define FPU_MVFR1_FtZ_mode_Pos 0 /*!< MVFR1: FtZ mode bits Position */ #define FPU_MVFR1_FtZ_mode_Msk (0xFUL << FPU_MVFR1_FtZ_mode_Pos) /*!< MVFR1: FtZ mode bits Mask */ /*@} end of group CMSIS_FPU */ #endif /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug CMSIS Core Debug Type definitions for the Cortex-M Core Debug Registers @{ */ /** \brief Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { __IO uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ __O uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IO uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IO uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register */ #define CoreDebug_DHCSR_DBGKEY_Pos 16 /*!< CoreDebug DHCSR: DBGKEY Position */ #define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ #define CoreDebug_DHCSR_S_RESET_ST_Pos 25 /*!< CoreDebug DHCSR: S_RESET_ST Position */ #define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ #define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24 /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ #define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ #define CoreDebug_DHCSR_S_LOCKUP_Pos 19 /*!< CoreDebug DHCSR: S_LOCKUP Position */ #define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ #define CoreDebug_DHCSR_S_SLEEP_Pos 18 /*!< CoreDebug DHCSR: S_SLEEP Position */ #define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ #define CoreDebug_DHCSR_S_HALT_Pos 17 /*!< CoreDebug DHCSR: S_HALT Position */ #define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ #define CoreDebug_DHCSR_S_REGRDY_Pos 16 /*!< CoreDebug DHCSR: S_REGRDY Position */ #define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ #define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5 /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ #define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ #define CoreDebug_DHCSR_C_MASKINTS_Pos 3 /*!< CoreDebug DHCSR: C_MASKINTS Position */ #define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ #define CoreDebug_DHCSR_C_STEP_Pos 2 /*!< CoreDebug DHCSR: C_STEP Position */ #define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ #define CoreDebug_DHCSR_C_HALT_Pos 1 /*!< CoreDebug DHCSR: C_HALT Position */ #define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ #define CoreDebug_DHCSR_C_DEBUGEN_Pos 0 /*!< CoreDebug DHCSR: C_DEBUGEN Position */ #define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL << CoreDebug_DHCSR_C_DEBUGEN_Pos) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register */ #define CoreDebug_DCRSR_REGWnR_Pos 16 /*!< CoreDebug DCRSR: REGWnR Position */ #define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ #define CoreDebug_DCRSR_REGSEL_Pos 0 /*!< CoreDebug DCRSR: REGSEL Position */ #define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL << CoreDebug_DCRSR_REGSEL_Pos) /*!< CoreDebug DCRSR: REGSEL Mask */ /* Debug Exception and Monitor Control Register */ #define CoreDebug_DEMCR_TRCENA_Pos 24 /*!< CoreDebug DEMCR: TRCENA Position */ #define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ #define CoreDebug_DEMCR_MON_REQ_Pos 19 /*!< CoreDebug DEMCR: MON_REQ Position */ #define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ #define CoreDebug_DEMCR_MON_STEP_Pos 18 /*!< CoreDebug DEMCR: MON_STEP Position */ #define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ #define CoreDebug_DEMCR_MON_PEND_Pos 17 /*!< CoreDebug DEMCR: MON_PEND Position */ #define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ #define CoreDebug_DEMCR_MON_EN_Pos 16 /*!< CoreDebug DEMCR: MON_EN Position */ #define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ #define CoreDebug_DEMCR_VC_HARDERR_Pos 10 /*!< CoreDebug DEMCR: VC_HARDERR Position */ #define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ #define CoreDebug_DEMCR_VC_INTERR_Pos 9 /*!< CoreDebug DEMCR: VC_INTERR Position */ #define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ #define CoreDebug_DEMCR_VC_BUSERR_Pos 8 /*!< CoreDebug DEMCR: VC_BUSERR Position */ #define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ #define CoreDebug_DEMCR_VC_STATERR_Pos 7 /*!< CoreDebug DEMCR: VC_STATERR Position */ #define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ #define CoreDebug_DEMCR_VC_CHKERR_Pos 6 /*!< CoreDebug DEMCR: VC_CHKERR Position */ #define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ #define CoreDebug_DEMCR_VC_NOCPERR_Pos 5 /*!< CoreDebug DEMCR: VC_NOCPERR Position */ #define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ #define CoreDebug_DEMCR_VC_MMERR_Pos 4 /*!< CoreDebug DEMCR: VC_MMERR Position */ #define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ #define CoreDebug_DEMCR_VC_CORERESET_Pos 0 /*!< CoreDebug DEMCR: VC_CORERESET Position */ #define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL << CoreDebug_DEMCR_VC_CORERESET_Pos) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ /*@} end of group CMSIS_CoreDebug */ /** \ingroup CMSIS_core_register @{ */ /* Memory mapping of Cortex-M4 Hardware */ #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ #define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */ #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ #if (__MPU_PRESENT == 1) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ #endif #if (__FPU_PRESENT == 1) #define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ #define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */ #endif /*@} */ /******************************************************************************* * Hardware Abstraction Layer ******************************************************************************/ /** \defgroup CMSIS_Core_FunctionInterface CMSIS Core Function Interface Core Function Interface contains: - Core NVIC Functions - Core SysTick Functions - Core Debug Functions - Core Register Access Functions */ /* ########################## NVIC functions #################################### */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_NVICFunctions CMSIS Core NVIC Functions @{ */ /** \brief Set Priority Grouping This function sets the priority grouping field using the required unlock sequence. The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. Only values from 0..7 are used. In case of a conflict between priority grouping and available priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. \param [in] PriorityGroup Priority grouping field */ static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) { uint32_t reg_value; uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */ reg_value = SCB->AIRCR; /* read old register configuration */ reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) | (PriorityGroupTmp << 8)); /* Insert write key and priorty group */ SCB->AIRCR = reg_value; } /** \brief Get Priority Grouping This function gets the priority grouping from NVIC Interrupt Controller. Priority grouping is SCB->AIRCR [10:8] PRIGROUP field. \return Priority grouping field */ static __INLINE uint32_t NVIC_GetPriorityGrouping(void) { return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */ } /** \brief Enable External Interrupt This function enables a device specific interrupt in the NVIC interrupt controller. The interrupt number cannot be a negative value. \param [in] IRQn Number of the external interrupt to enable */ static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) { /* NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); enable interrupt */ NVIC->ISER[(uint32_t)((int32_t)IRQn) >> 5] = (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F)); /* enable interrupt */ } /** \brief Disable External Interrupt This function disables a device specific interrupt in the NVIC interrupt controller. The interrupt number cannot be a negative value. \param [in] IRQn Number of the external interrupt to disable */ static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) { NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */ } /** \brief Get Pending Interrupt This function reads the pending register in the NVIC and returns the pending bit for the specified interrupt. \param [in] IRQn Number of the interrupt for get pending \return 0 Interrupt status is not pending \return 1 Interrupt status is pending */ static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) { return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */ } /** \brief Set Pending Interrupt This function sets the pending bit for the specified interrupt. The interrupt number cannot be a negative value. \param [in] IRQn Number of the interrupt for set pending */ static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) { NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */ } /** \brief Clear Pending Interrupt This function clears the pending bit for the specified interrupt. The interrupt number cannot be a negative value. \param [in] IRQn Number of the interrupt for clear pending */ static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) { NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */ } /** \brief Get Active Interrupt This function reads the active register in NVIC and returns the active bit. \param [in] IRQn Number of the interrupt for get active \return 0 Interrupt status is not active \return 1 Interrupt status is active */ static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) { return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */ } /** \brief Set Interrupt Priority This function sets the priority for the specified interrupt. The interrupt number can be positive to specify an external (device specific) interrupt, or negative to specify an internal (core) interrupt. Note: The priority cannot be set for every core interrupt. \param [in] IRQn Number of the interrupt for set priority \param [in] priority Priority to set */ static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) { if(IRQn < 0) { SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M System Interrupts */ else { NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */ } /** \brief Get Interrupt Priority This function reads the priority for the specified interrupt. The interrupt number can be positive to specify an external (device specific) interrupt, or negative to specify an internal (core) interrupt. The returned priority value is automatically aligned to the implemented priority bits of the microcontroller. \param [in] IRQn Number of the interrupt for get priority \return Interrupt Priority */ static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) { if(IRQn < 0) { return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M system interrupts */ else { return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */ } /** \brief Encode Priority This function encodes the priority for an interrupt with the given priority group, preemptive priority value and sub priority value. In case of a conflict between priority grouping and available priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set. The returned priority value can be used for NVIC_SetPriority(...) function \param [in] PriorityGroup Used priority group \param [in] PreemptPriority Preemptive priority value (starting from 0) \param [in] SubPriority Sub priority value (starting from 0) \return Encoded priority for the interrupt */ static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) { uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */ uint32_t PreemptPriorityBits; uint32_t SubPriorityBits; PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp; SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS; return ( ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) | ((SubPriority & ((1 << (SubPriorityBits )) - 1))) ); } /** \brief Decode Priority This function decodes an interrupt priority value with the given priority group to preemptive priority value and sub priority value. In case of a conflict between priority grouping and available priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set. The priority value can be retrieved with NVIC_GetPriority(...) function \param [in] Priority Priority value \param [in] PriorityGroup Used priority group \param [out] pPreemptPriority Preemptive priority value (starting from 0) \param [out] pSubPriority Sub priority value (starting from 0) */ static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority) { uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */ uint32_t PreemptPriorityBits; uint32_t SubPriorityBits; PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp; SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS; *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1); *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1); } /** \brief System Reset This function initiate a system reset request to reset the MCU. */ static __INLINE void NVIC_SystemReset(void) { __DSB(); /* Ensure all outstanding memory accesses included buffered write are completed before reset */ SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */ __DSB(); /* Ensure completion of memory access */ while(1); /* wait until reset */ } /*@} end of CMSIS_Core_NVICFunctions */ /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_SysTickFunctions CMSIS Core SysTick Functions @{ */ #if (__Vendor_SysTickConfig == 0) /** \brief System Tick Configuration This function initialises the system tick timer and its interrupt and start the system tick timer. Counter is in free running mode to generate periodical interrupts. \param [in] ticks Number of ticks between two interrupts \return 0 Function succeeded \return 1 Function failed */ static __INLINE uint32_t SysTick_Config(uint32_t ticks) { if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */ NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */ SysTick->VAL = 0; /* Load the SysTick Counter Value */ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ return (0); /* Function successful */ } #endif /*@} end of CMSIS_Core_SysTickFunctions */ /* ##################################### Debug In/Output function ########################################### */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_core_DebugFunctions CMSIS Core Debug Functions @{ */ extern volatile int32_t ITM_RxBuffer; /*!< external variable to receive characters */ #define ITM_RXBUFFER_EMPTY 0x5AA55AA5 /*!< value identifying ITM_RxBuffer is ready for next character */ /** \brief ITM Send Character This function transmits a character via the ITM channel 0. It just returns when no debugger is connected that has booked the output. It is blocking when a debugger is connected, but the previous character send is not transmitted. \param [in] ch Character to transmit \return Character to transmit */ static __INLINE uint32_t ITM_SendChar (uint32_t ch) { if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && /* Trace enabled */ (ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */ (ITM->TER & (1UL << 0) ) ) /* ITM Port #0 enabled */ { while (ITM->PORT[0].u32 == 0); ITM->PORT[0].u8 = (uint8_t) ch; } return (ch); } /** \brief ITM Receive Character This function inputs a character via external variable ITM_RxBuffer. It just returns when no debugger is connected that has booked the output. It is blocking when a debugger is connected, but the previous character send is not transmitted. \return Received character \return -1 No character received */ static __INLINE int32_t ITM_ReceiveChar (void) { int32_t ch = -1; /* no character available */ if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) { ch = ITM_RxBuffer; ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ } return (ch); } /** \brief ITM Check Character This function checks external variable ITM_RxBuffer whether a character is available or not. It returns '1' if a character is available and '0' if no character is available. \return 0 No character available \return 1 Character available */ static __INLINE int32_t ITM_CheckChar (void) { if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) { return (0); /* no character available */ } else { return (1); /* character available */ } } /*@} end of CMSIS_core_DebugFunctions */ #endif /* __CORE_CM4_H_DEPENDANT */ #endif /* __CMSIS_GENERIC */ #ifdef __cplusplus } #endif
1137519-player
lib/CMSIS/Include/core_cm4.h
C
lgpl
79,283
/**************************************************************************//** * @file core_cm0.h * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File * @version V2.10 * @date 19. July 2011 * * @note * Copyright (C) 2009-2011 ARM Limited. All rights reserved. * * @par * ARM Limited (ARM) is supplying this software for use with Cortex-M * processor based microcontrollers. This file can be freely distributed * within development tools that are supporting such ARM based processors. * * @par * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * ******************************************************************************/ #if defined ( __ICCARM__ ) #pragma system_include /* treat file as system include file for MISRA check */ #endif #ifdef __cplusplus extern "C" { #endif #ifndef __CORE_CM0_H_GENERIC #define __CORE_CM0_H_GENERIC /** \mainpage CMSIS Cortex-M0 This documentation describes the CMSIS Cortex-M Core Peripheral Access Layer. It consists of: - Cortex-M Core Register Definitions - Cortex-M functions - Cortex-M instructions The CMSIS Cortex-M0 Core Peripheral Access Layer contains C and assembly functions that ease access to the Cortex-M Core */ /** \defgroup CMSIS_MISRA_Exceptions CMSIS MISRA-C:2004 Compliance Exceptions CMSIS violates following MISRA-C2004 Rules: - Violates MISRA 2004 Required Rule 8.5, object/function definition in header file.<br> Function definitions in header files are used to allow 'inlining'. - Violates MISRA 2004 Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br> Unions are used for effective representation of core registers. - Violates MISRA 2004 Advisory Rule 19.7, Function-like macro defined.<br> Function-like macros are used to allow more efficient code. */ /******************************************************************************* * CMSIS definitions ******************************************************************************/ /** \defgroup CMSIS_core_definitions CMSIS Core Definitions This file defines all structures and symbols for CMSIS core: - CMSIS version number - Cortex-M core - Cortex-M core Revision Number @{ */ /* CMSIS CM0 definitions */ #define __CM0_CMSIS_VERSION_MAIN (0x02) /*!< [31:16] CMSIS HAL main version */ #define __CM0_CMSIS_VERSION_SUB (0x10) /*!< [15:0] CMSIS HAL sub version */ #define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | __CM0_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */ #define __CORTEX_M (0x00) /*!< Cortex core */ #if defined ( __CC_ARM ) #define __ASM __asm /*!< asm keyword for ARM Compiler */ #define __INLINE __inline /*!< inline keyword for ARM Compiler */ #elif defined ( __ICCARM__ ) #define __ASM __asm /*!< asm keyword for IAR Compiler */ #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ #elif defined ( __GNUC__ ) #define __ASM __asm /*!< asm keyword for GNU Compiler */ #define __INLINE inline /*!< inline keyword for GNU Compiler */ #elif defined ( __TASKING__ ) #define __ASM __asm /*!< asm keyword for TASKING Compiler */ #define __INLINE inline /*!< inline keyword for TASKING Compiler */ #endif /*!< __FPU_USED to be checked prior to making use of FPU specific registers and functions */ #define __FPU_USED 0 #if defined ( __CC_ARM ) #if defined __TARGET_FPU_VFP #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif #elif defined ( __ICCARM__ ) #if defined __ARMVFP__ #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif #elif defined ( __GNUC__ ) #if defined (__VFP_FP__) && !defined(__SOFTFP__) #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif #elif defined ( __TASKING__ ) /* add preprocessor checks */ #endif #include <stdint.h> /*!< standard types definitions */ #include "core_cmInstr.h" /*!< Core Instruction Access */ #include "core_cmFunc.h" /*!< Core Function Access */ #endif /* __CORE_CM0_H_GENERIC */ #ifndef __CMSIS_GENERIC #ifndef __CORE_CM0_H_DEPENDANT #define __CORE_CM0_H_DEPENDANT /* check device defines and use defaults */ #if defined __CHECK_DEVICE_DEFINES #ifndef __CM0_REV #define __CM0_REV 0x0000 #warning "__CM0_REV not defined in device header file; using default!" #endif #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 2 #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" #endif #ifndef __Vendor_SysTickConfig #define __Vendor_SysTickConfig 0 #warning "__Vendor_SysTickConfig not defined in device header file; using default!" #endif #endif /* IO definitions (access restrictions to peripheral registers) */ #ifdef __cplusplus #define __I volatile /*!< defines 'read only' permissions */ #else #define __I volatile const /*!< defines 'read only' permissions */ #endif #define __O volatile /*!< defines 'write only' permissions */ #define __IO volatile /*!< defines 'read / write' permissions */ /*@} end of group CMSIS_core_definitions */ /******************************************************************************* * Register Abstraction ******************************************************************************/ /** \defgroup CMSIS_core_register CMSIS Core Register Core Register contain: - Core Register - Core NVIC Register - Core SCB Register - Core SysTick Register */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CORE CMSIS Core Type definitions for the Cortex-M Core Registers @{ */ /** \brief Union type to access the Application Program Status Register (APSR). */ typedef union { struct { #if (__CORTEX_M != 0x04) uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */ #else uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ #endif uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ uint32_t N:1; /*!< bit: 31 Negative condition code flag */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } APSR_Type; /** \brief Union type to access the Interrupt Program Status Register (IPSR). */ typedef union { struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } IPSR_Type; /** \brief Union type to access the Special-Purpose Program Status Registers (xPSR). */ typedef union { struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ #if (__CORTEX_M != 0x04) uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ #else uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ #endif uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ uint32_t N:1; /*!< bit: 31 Negative condition code flag */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } xPSR_Type; /** \brief Union type to access the Control Registers (CONTROL). */ typedef union { struct { uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ } b; /*!< Structure used for bit access */ uint32_t w; /*!< Type used for word access */ } CONTROL_Type; /*@} end of group CMSIS_CORE */ /** \ingroup CMSIS_core_register \defgroup CMSIS_NVIC CMSIS NVIC Type definitions for the Cortex-M NVIC Registers @{ */ /** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). */ typedef struct { __IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ uint32_t RESERVED0[31]; __IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ uint32_t RSERVED1[31]; __IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ uint32_t RESERVED2[31]; __IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ uint32_t RESERVED3[31]; uint32_t RESERVED4[64]; __IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ } NVIC_Type; /*@} end of group CMSIS_NVIC */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SCB CMSIS SCB Type definitions for the Cortex-M System Control Block Registers @{ */ /** \brief Structure type to access the System Control Block (SCB). */ typedef struct { __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ uint32_t RESERVED0; __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ uint32_t RESERVED1; __IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ } SCB_Type; /* SCB CPUID Register Definitions */ #define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */ #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ #define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */ #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ #define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */ #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ #define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */ #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ #define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */ #define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */ /* SCB Interrupt Control State Register Definitions */ #define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */ #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ #define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */ #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ #define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */ #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ #define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */ #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ #define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */ #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ #define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */ #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ #define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */ #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ #define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */ #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ #define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */ #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */ /* SCB Application Interrupt and Reset Control Register Definitions */ #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */ #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ #define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */ #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ #define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */ #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */ #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ #define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */ #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ /* SCB System Control Register Definitions */ #define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */ #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ #define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */ #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ #define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */ #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ /* SCB Configuration Control Register Definitions */ #define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */ #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ #define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */ #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ /* SCB System Handler Control and State Register Definitions */ #define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */ #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ /*@} end of group CMSIS_SCB */ /** \ingroup CMSIS_core_register \defgroup CMSIS_SysTick CMSIS SysTick Type definitions for the Cortex-M System Timer Registers @{ */ /** \brief Structure type to access the System Timer (SysTick). */ typedef struct { __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ } SysTick_Type; /* SysTick Control / Status Register Definitions */ #define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */ #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ #define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */ #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ #define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */ #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ #define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */ #define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */ /* SysTick Reload Register Definitions */ #define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */ #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */ /* SysTick Current Register Definitions */ #define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */ #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */ /* SysTick Calibration Register Definitions */ #define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */ #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ #define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */ #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ #define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */ #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */ /*@} end of group CMSIS_SysTick */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug CMSIS Core Debug Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor. Therefore they are not covered by the Cortex-M0 header file. @{ */ /*@} end of group CMSIS_CoreDebug */ /** \ingroup CMSIS_core_register @{ */ /* Memory mapping of Cortex-M0 Hardware */ #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ /*@} */ /******************************************************************************* * Hardware Abstraction Layer ******************************************************************************/ /** \defgroup CMSIS_Core_FunctionInterface CMSIS Core Function Interface Core Function Interface contains: - Core NVIC Functions - Core SysTick Functions - Core Register Access Functions */ /* ########################## NVIC functions #################################### */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_NVICFunctions CMSIS Core NVIC Functions @{ */ /* Interrupt Priorities are WORD accessible only under ARMv6M */ /* The following MACROS handle generation of the register offset and byte masks */ #define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 ) #define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) ) #define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) ) /** \brief Enable External Interrupt This function enables a device specific interrupt in the NVIC interrupt controller. The interrupt number cannot be a negative value. \param [in] IRQn Number of the external interrupt to enable */ static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) { NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); } /** \brief Disable External Interrupt This function disables a device specific interrupt in the NVIC interrupt controller. The interrupt number cannot be a negative value. \param [in] IRQn Number of the external interrupt to disable */ static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) { NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); } /** \brief Get Pending Interrupt This function reads the pending register in the NVIC and returns the pending bit for the specified interrupt. \param [in] IRQn Number of the interrupt for get pending \return 0 Interrupt status is not pending \return 1 Interrupt status is pending */ static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) { return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); } /** \brief Set Pending Interrupt This function sets the pending bit for the specified interrupt. The interrupt number cannot be a negative value. \param [in] IRQn Number of the interrupt for set pending */ static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) { NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); } /** \brief Clear Pending Interrupt This function clears the pending bit for the specified interrupt. The interrupt number cannot be a negative value. \param [in] IRQn Number of the interrupt for clear pending */ static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) { NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */ } /** \brief Set Interrupt Priority This function sets the priority for the specified interrupt. The interrupt number can be positive to specify an external (device specific) interrupt, or negative to specify an internal (core) interrupt. Note: The priority cannot be set for every core interrupt. \param [in] IRQn Number of the interrupt for set priority \param [in] priority Priority to set */ static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) { if(IRQn < 0) { SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } else { NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } } /** \brief Get Interrupt Priority This function reads the priority for the specified interrupt. The interrupt number can be positive to specify an external (device specific) interrupt, or negative to specify an internal (core) interrupt. The returned priority value is automatically aligned to the implemented priority bits of the microcontroller. \param [in] IRQn Number of the interrupt for get priority \return Interrupt Priority */ static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) { if(IRQn < 0) { return((uint32_t)((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */ else { return((uint32_t)((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */ } /** \brief System Reset This function initiate a system reset request to reset the MCU. */ static __INLINE void NVIC_SystemReset(void) { __DSB(); /* Ensure all outstanding memory accesses included buffered write are completed before reset */ SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk); __DSB(); /* Ensure completion of memory access */ while(1); /* wait until reset */ } /*@} end of CMSIS_Core_NVICFunctions */ /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_SysTickFunctions CMSIS Core SysTick Functions @{ */ #if (__Vendor_SysTickConfig == 0) /** \brief System Tick Configuration This function initialises the system tick timer and its interrupt and start the system tick timer. Counter is in free running mode to generate periodical interrupts. \param [in] ticks Number of ticks between two interrupts \return 0 Function succeeded \return 1 Function failed */ static __INLINE uint32_t SysTick_Config(uint32_t ticks) { if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */ NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */ SysTick->VAL = 0; /* Load the SysTick Counter Value */ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ return (0); /* Function successful */ } #endif /*@} end of CMSIS_Core_SysTickFunctions */ #endif /* __CORE_CM0_H_DEPENDANT */ #endif /* __CMSIS_GENERIC */ #ifdef __cplusplus } #endif
1137519-player
lib/CMSIS/Include/core_cm0.h
C
lgpl
31,948
/* ---------------------------------------------------------------------- * Copyright (C) 2010 ARM Limited. All rights reserved. * * $Date: 11. November 2010 * $Revision: V1.0.2 * * Project: CMSIS DSP Library * Title: arm_common_tables.h * * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions * * Target Processor: Cortex-M4/Cortex-M3 * * Version 1.0.2 2010/11/11 * Documentation updated. * * Version 1.0.1 2010/10/05 * Production release and review comments incorporated. * * Version 1.0.0 2010/09/20 * Production release and review comments incorporated. * -------------------------------------------------------------------- */ #ifndef _ARM_COMMON_TABLES_H #define _ARM_COMMON_TABLES_H #include "arm_math.h" extern uint16_t armBitRevTable[256]; extern q15_t armRecipTableQ15[64]; extern q31_t armRecipTableQ31[64]; extern const q31_t realCoefAQ31[1024]; extern const q31_t realCoefBQ31[1024]; #endif /* ARM_COMMON_TABLES_H */
1137519-player
lib/CMSIS/Include/arm_common_tables.h
C
lgpl
1,120
/**************************************************************************//** * @file core_cm4_simd.h * @brief CMSIS Cortex-M4 SIMD Header File * @version V2.10 * @date 19. July 2011 * * @note * Copyright (C) 2010-2011 ARM Limited. All rights reserved. * * @par * ARM Limited (ARM) is supplying this software for use with Cortex-M * processor based microcontrollers. This file can be freely distributed * within development tools that are supporting such ARM based processors. * * @par * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * ******************************************************************************/ #ifdef __cplusplus extern "C" { #endif #ifndef __CORE_CM4_SIMD_H #define __CORE_CM4_SIMD_H /******************************************************************************* * Hardware Abstraction Layer ******************************************************************************/ /* ################### Compiler specific Intrinsics ########################### */ /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics Access to dedicated SIMD instructions @{ */ #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ /* ARM armcc specific functions */ /*------ CM4 SOMD Intrinsics -----------------------------------------------------*/ #define __SADD8 __sadd8 #define __QADD8 __qadd8 #define __SHADD8 __shadd8 #define __UADD8 __uadd8 #define __UQADD8 __uqadd8 #define __UHADD8 __uhadd8 #define __SSUB8 __ssub8 #define __QSUB8 __qsub8 #define __SHSUB8 __shsub8 #define __USUB8 __usub8 #define __UQSUB8 __uqsub8 #define __UHSUB8 __uhsub8 #define __SADD16 __sadd16 #define __QADD16 __qadd16 #define __SHADD16 __shadd16 #define __UADD16 __uadd16 #define __UQADD16 __uqadd16 #define __UHADD16 __uhadd16 #define __SSUB16 __ssub16 #define __QSUB16 __qsub16 #define __SHSUB16 __shsub16 #define __USUB16 __usub16 #define __UQSUB16 __uqsub16 #define __UHSUB16 __uhsub16 #define __SASX __sasx #define __QASX __qasx #define __SHASX __shasx #define __UASX __uasx #define __UQASX __uqasx #define __UHASX __uhasx #define __SSAX __ssax #define __QSAX __qsax #define __SHSAX __shsax #define __USAX __usax #define __UQSAX __uqsax #define __UHSAX __uhsax #define __USAD8 __usad8 #define __USADA8 __usada8 #define __SSAT16 __ssat16 #define __USAT16 __usat16 #define __UXTB16 __uxtb16 #define __UXTAB16 __uxtab16 #define __SXTB16 __sxtb16 #define __SXTAB16 __sxtab16 #define __SMUAD __smuad #define __SMUADX __smuadx #define __SMLAD __smlad #define __SMLADX __smladx #define __SMLALD __smlald #define __SMLALDX __smlaldx #define __SMUSD __smusd #define __SMUSDX __smusdx #define __SMLSD __smlsd #define __SMLSDX __smlsdx #define __SMLSLD __smlsld #define __SMLSLDX __smlsldx #define __SEL __sel #define __QADD __qadd #define __QSUB __qsub #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) /*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/ #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ /* IAR iccarm specific functions */ #include <cmsis_iar.h> /*------ CM4 SIMDDSP Intrinsics -----------------------------------------------------*/ /* intrinsic __SADD8 see intrinsics.h */ /* intrinsic __QADD8 see intrinsics.h */ /* intrinsic __SHADD8 see intrinsics.h */ /* intrinsic __UADD8 see intrinsics.h */ /* intrinsic __UQADD8 see intrinsics.h */ /* intrinsic __UHADD8 see intrinsics.h */ /* intrinsic __SSUB8 see intrinsics.h */ /* intrinsic __QSUB8 see intrinsics.h */ /* intrinsic __SHSUB8 see intrinsics.h */ /* intrinsic __USUB8 see intrinsics.h */ /* intrinsic __UQSUB8 see intrinsics.h */ /* intrinsic __UHSUB8 see intrinsics.h */ /* intrinsic __SADD16 see intrinsics.h */ /* intrinsic __QADD16 see intrinsics.h */ /* intrinsic __SHADD16 see intrinsics.h */ /* intrinsic __UADD16 see intrinsics.h */ /* intrinsic __UQADD16 see intrinsics.h */ /* intrinsic __UHADD16 see intrinsics.h */ /* intrinsic __SSUB16 see intrinsics.h */ /* intrinsic __QSUB16 see intrinsics.h */ /* intrinsic __SHSUB16 see intrinsics.h */ /* intrinsic __USUB16 see intrinsics.h */ /* intrinsic __UQSUB16 see intrinsics.h */ /* intrinsic __UHSUB16 see intrinsics.h */ /* intrinsic __SASX see intrinsics.h */ /* intrinsic __QASX see intrinsics.h */ /* intrinsic __SHASX see intrinsics.h */ /* intrinsic __UASX see intrinsics.h */ /* intrinsic __UQASX see intrinsics.h */ /* intrinsic __UHASX see intrinsics.h */ /* intrinsic __SSAX see intrinsics.h */ /* intrinsic __QSAX see intrinsics.h */ /* intrinsic __SHSAX see intrinsics.h */ /* intrinsic __USAX see intrinsics.h */ /* intrinsic __UQSAX see intrinsics.h */ /* intrinsic __UHSAX see intrinsics.h */ /* intrinsic __USAD8 see intrinsics.h */ /* intrinsic __USADA8 see intrinsics.h */ /* intrinsic __SSAT16 see intrinsics.h */ /* intrinsic __USAT16 see intrinsics.h */ /* intrinsic __UXTB16 see intrinsics.h */ /* intrinsic __SXTB16 see intrinsics.h */ /* intrinsic __UXTAB16 see intrinsics.h */ /* intrinsic __SXTAB16 see intrinsics.h */ /* intrinsic __SMUAD see intrinsics.h */ /* intrinsic __SMUADX see intrinsics.h */ /* intrinsic __SMLAD see intrinsics.h */ /* intrinsic __SMLADX see intrinsics.h */ /* intrinsic __SMLALD see intrinsics.h */ /* intrinsic __SMLALDX see intrinsics.h */ /* intrinsic __SMUSD see intrinsics.h */ /* intrinsic __SMUSDX see intrinsics.h */ /* intrinsic __SMLSD see intrinsics.h */ /* intrinsic __SMLSDX see intrinsics.h */ /* intrinsic __SMLSLD see intrinsics.h */ /* intrinsic __SMLSLDX see intrinsics.h */ /* intrinsic __SEL see intrinsics.h */ /* intrinsic __QADD see intrinsics.h */ /* intrinsic __QSUB see intrinsics.h */ /* intrinsic __PKHBT see intrinsics.h */ /* intrinsic __PKHTB see intrinsics.h */ /*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/ #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ /* GNU gcc specific functions */ /*------ CM4 SIMD Intrinsics -----------------------------------------------------*/ __attribute__( ( always_inline ) ) static __INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SASX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QASX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UASX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __USAX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); return(result); } #define __SSAT16(ARG1,ARG2) \ ({ \ uint32_t __RES, __ARG1 = (ARG1); \ __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ __RES; \ }) #define __USAT16(ARG1,ARG2) \ ({ \ uint32_t __RES, __ARG1 = (ARG1); \ __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ __RES; \ }) __attribute__( ( always_inline ) ) static __INLINE uint32_t __UXTB16(uint32_t op1) { uint32_t result; __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SXTB16(uint32_t op1) { uint32_t result; __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); return(result); } #define __SMLALD(ARG1,ARG2,ARG3) \ ({ \ uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((uint64_t)(ARG3) >> 32), __ARG3_L = (uint32_t)((uint64_t)(ARG3) & 0xFFFFFFFFUL); \ __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \ (uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \ }) #define __SMLALDX(ARG1,ARG2,ARG3) \ ({ \ uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((uint64_t)(ARG3) >> 32), __ARG3_L = (uint32_t)((uint64_t)(ARG3) & 0xFFFFFFFFUL); \ __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \ (uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \ }) __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); return(result); } #define __SMLSLD(ARG1,ARG2,ARG3) \ ({ \ uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((ARG3) >> 32), __ARG3_L = (uint32_t)((ARG3) & 0xFFFFFFFFUL); \ __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \ (uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \ }) #define __SMLSLDX(ARG1,ARG2,ARG3) \ ({ \ uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((ARG3) >> 32), __ARG3_L = (uint32_t)((ARG3) & 0xFFFFFFFFUL); \ __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \ (uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \ }) __attribute__( ( always_inline ) ) static __INLINE uint32_t __SEL (uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QADD(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } __attribute__( ( always_inline ) ) static __INLINE uint32_t __QSUB(uint32_t op1, uint32_t op2) { uint32_t result; __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } #define __PKHBT(ARG1,ARG2,ARG3) \ ({ \ uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ __RES; \ }) #define __PKHTB(ARG1,ARG2,ARG3) \ ({ \ uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ if (ARG3 == 0) \ __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \ else \ __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ __RES; \ }) /*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/ #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ /* TASKING carm specific functions */ /*------ CM4 SIMD Intrinsics -----------------------------------------------------*/ /* not yet supported */ /*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/ #endif /*@} end of group CMSIS_SIMD_intrinsics */ #endif /* __CORE_CM4_SIMD_H */ #ifdef __cplusplus } #endif
1137519-player
lib/CMSIS/Include/core_cm4_simd.h
C
lgpl
23,979
/**************************************************************************//** * @file core_cmFunc.h * @brief CMSIS Cortex-M Core Function Access Header File * @version V2.10 * @date 26. July 2011 * * @note * Copyright (C) 2009-2011 ARM Limited. All rights reserved. * * @par * ARM Limited (ARM) is supplying this software for use with Cortex-M * processor based microcontrollers. This file can be freely distributed * within development tools that are supporting such ARM based processors. * * @par * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * ******************************************************************************/ #ifndef __CORE_CMFUNC_H #define __CORE_CMFUNC_H /* ########################### Core Function Access ########################### */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions @{ */ #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ /* ARM armcc specific functions */ #if (__ARMCC_VERSION < 400677) #error "Please use ARM Compiler Toolchain V4.0.677 or later!" #endif /* intrinsic void __enable_irq(); */ /* intrinsic void __disable_irq(); */ /** \brief Get Control Register This function returns the content of the Control Register. \return Control Register value */ static __INLINE uint32_t __get_CONTROL(void) { register uint32_t __regControl __ASM("control"); return(__regControl); } /** \brief Set Control Register This function writes the given value to the Control Register. \param [in] control Control Register value to set */ static __INLINE void __set_CONTROL(uint32_t control) { register uint32_t __regControl __ASM("control"); __regControl = control; } /** \brief Get ISPR Register This function returns the content of the ISPR Register. \return ISPR Register value */ static __INLINE uint32_t __get_IPSR(void) { register uint32_t __regIPSR __ASM("ipsr"); return(__regIPSR); } /** \brief Get APSR Register This function returns the content of the APSR Register. \return APSR Register value */ static __INLINE uint32_t __get_APSR(void) { register uint32_t __regAPSR __ASM("apsr"); return(__regAPSR); } /** \brief Get xPSR Register This function returns the content of the xPSR Register. \return xPSR Register value */ static __INLINE uint32_t __get_xPSR(void) { register uint32_t __regXPSR __ASM("xpsr"); return(__regXPSR); } /** \brief Get Process Stack Pointer This function returns the current value of the Process Stack Pointer (PSP). \return PSP Register value */ static __INLINE uint32_t __get_PSP(void) { register uint32_t __regProcessStackPointer __ASM("psp"); return(__regProcessStackPointer); } /** \brief Set Process Stack Pointer This function assigns the given value to the Process Stack Pointer (PSP). \param [in] topOfProcStack Process Stack Pointer value to set */ static __INLINE void __set_PSP(uint32_t topOfProcStack) { register uint32_t __regProcessStackPointer __ASM("psp"); __regProcessStackPointer = topOfProcStack; } /** \brief Get Main Stack Pointer This function returns the current value of the Main Stack Pointer (MSP). \return MSP Register value */ static __INLINE uint32_t __get_MSP(void) { register uint32_t __regMainStackPointer __ASM("msp"); return(__regMainStackPointer); } /** \brief Set Main Stack Pointer This function assigns the given value to the Main Stack Pointer (MSP). \param [in] topOfMainStack Main Stack Pointer value to set */ static __INLINE void __set_MSP(uint32_t topOfMainStack) { register uint32_t __regMainStackPointer __ASM("msp"); __regMainStackPointer = topOfMainStack; } /** \brief Get Priority Mask This function returns the current state of the priority mask bit from the Priority Mask Register. \return Priority Mask value */ static __INLINE uint32_t __get_PRIMASK(void) { register uint32_t __regPriMask __ASM("primask"); return(__regPriMask); } /** \brief Set Priority Mask This function assigns the given value to the Priority Mask Register. \param [in] priMask Priority Mask */ static __INLINE void __set_PRIMASK(uint32_t priMask) { register uint32_t __regPriMask __ASM("primask"); __regPriMask = (priMask); } #if (__CORTEX_M >= 0x03) /** \brief Enable FIQ This function enables FIQ interrupts by clearing the F-bit in the CPSR. Can only be executed in Privileged modes. */ #define __enable_fault_irq __enable_fiq /** \brief Disable FIQ This function disables FIQ interrupts by setting the F-bit in the CPSR. Can only be executed in Privileged modes. */ #define __disable_fault_irq __disable_fiq /** \brief Get Base Priority This function returns the current value of the Base Priority register. \return Base Priority register value */ static __INLINE uint32_t __get_BASEPRI(void) { register uint32_t __regBasePri __ASM("basepri"); return(__regBasePri); } /** \brief Set Base Priority This function assigns the given value to the Base Priority register. \param [in] basePri Base Priority value to set */ static __INLINE void __set_BASEPRI(uint32_t basePri) { register uint32_t __regBasePri __ASM("basepri"); __regBasePri = (basePri & 0xff); } /** \brief Get Fault Mask This function returns the current value of the Fault Mask register. \return Fault Mask register value */ static __INLINE uint32_t __get_FAULTMASK(void) { register uint32_t __regFaultMask __ASM("faultmask"); return(__regFaultMask); } /** \brief Set Fault Mask This function assigns the given value to the Fault Mask register. \param [in] faultMask Fault Mask value to set */ static __INLINE void __set_FAULTMASK(uint32_t faultMask) { register uint32_t __regFaultMask __ASM("faultmask"); __regFaultMask = (faultMask & (uint32_t)1); } #endif /* (__CORTEX_M >= 0x03) */ #if (__CORTEX_M == 0x04) /** \brief Get FPSCR This function returns the current value of the Floating Point Status/Control register. \return Floating Point Status/Control register value */ static __INLINE uint32_t __get_FPSCR(void) { #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) register uint32_t __regfpscr __ASM("fpscr"); return(__regfpscr); #else return(0); #endif } /** \brief Set FPSCR This function assigns the given value to the Floating Point Status/Control register. \param [in] fpscr Floating Point Status/Control value to set */ static __INLINE void __set_FPSCR(uint32_t fpscr) { #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) register uint32_t __regfpscr __ASM("fpscr"); __regfpscr = (fpscr); #endif } #endif /* (__CORTEX_M == 0x04) */ #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ /* IAR iccarm specific functions */ #include <cmsis_iar.h> #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ /* GNU gcc specific functions */ /** \brief Enable IRQ Interrupts This function enables IRQ interrupts by clearing the I-bit in the CPSR. Can only be executed in Privileged modes. */ __attribute__( ( always_inline ) ) static __INLINE void __enable_irq(void) { __ASM volatile ("cpsie i"); } /** \brief Disable IRQ Interrupts This function disables IRQ interrupts by setting the I-bit in the CPSR. Can only be executed in Privileged modes. */ __attribute__( ( always_inline ) ) static __INLINE void __disable_irq(void) { __ASM volatile ("cpsid i"); } /** \brief Get Control Register This function returns the content of the Control Register. \return Control Register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_CONTROL(void) { uint32_t result; __ASM volatile ("MRS %0, control" : "=r" (result) ); return(result); } /** \brief Set Control Register This function writes the given value to the Control Register. \param [in] control Control Register value to set */ __attribute__( ( always_inline ) ) static __INLINE void __set_CONTROL(uint32_t control) { __ASM volatile ("MSR control, %0" : : "r" (control) ); } /** \brief Get ISPR Register This function returns the content of the ISPR Register. \return ISPR Register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_IPSR(void) { uint32_t result; __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); return(result); } /** \brief Get APSR Register This function returns the content of the APSR Register. \return APSR Register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_APSR(void) { uint32_t result; __ASM volatile ("MRS %0, apsr" : "=r" (result) ); return(result); } /** \brief Get xPSR Register This function returns the content of the xPSR Register. \return xPSR Register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_xPSR(void) { uint32_t result; __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); return(result); } /** \brief Get Process Stack Pointer This function returns the current value of the Process Stack Pointer (PSP). \return PSP Register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_PSP(void) { register uint32_t result; __ASM volatile ("MRS %0, psp\n" : "=r" (result) ); return(result); } /** \brief Set Process Stack Pointer This function assigns the given value to the Process Stack Pointer (PSP). \param [in] topOfProcStack Process Stack Pointer value to set */ __attribute__( ( always_inline ) ) static __INLINE void __set_PSP(uint32_t topOfProcStack) { __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) ); } /** \brief Get Main Stack Pointer This function returns the current value of the Main Stack Pointer (MSP). \return MSP Register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_MSP(void) { register uint32_t result; __ASM volatile ("MRS %0, msp\n" : "=r" (result) ); return(result); } /** \brief Set Main Stack Pointer This function assigns the given value to the Main Stack Pointer (MSP). \param [in] topOfMainStack Main Stack Pointer value to set */ __attribute__( ( always_inline ) ) static __INLINE void __set_MSP(uint32_t topOfMainStack) { __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) ); } /** \brief Get Priority Mask This function returns the current state of the priority mask bit from the Priority Mask Register. \return Priority Mask value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_PRIMASK(void) { uint32_t result; __ASM volatile ("MRS %0, primask" : "=r" (result) ); return(result); } /** \brief Set Priority Mask This function assigns the given value to the Priority Mask Register. \param [in] priMask Priority Mask */ __attribute__( ( always_inline ) ) static __INLINE void __set_PRIMASK(uint32_t priMask) { __ASM volatile ("MSR primask, %0" : : "r" (priMask) ); } #if (__CORTEX_M >= 0x03) /** \brief Enable FIQ This function enables FIQ interrupts by clearing the F-bit in the CPSR. Can only be executed in Privileged modes. */ __attribute__( ( always_inline ) ) static __INLINE void __enable_fault_irq(void) { __ASM volatile ("cpsie f"); } /** \brief Disable FIQ This function disables FIQ interrupts by setting the F-bit in the CPSR. Can only be executed in Privileged modes. */ __attribute__( ( always_inline ) ) static __INLINE void __disable_fault_irq(void) { __ASM volatile ("cpsid f"); } /** \brief Get Base Priority This function returns the current value of the Base Priority register. \return Base Priority register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_BASEPRI(void) { uint32_t result; __ASM volatile ("MRS %0, basepri_max" : "=r" (result) ); return(result); } /** \brief Set Base Priority This function assigns the given value to the Base Priority register. \param [in] basePri Base Priority value to set */ __attribute__( ( always_inline ) ) static __INLINE void __set_BASEPRI(uint32_t value) { __ASM volatile ("MSR basepri, %0" : : "r" (value) ); } /** \brief Get Fault Mask This function returns the current value of the Fault Mask register. \return Fault Mask register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_FAULTMASK(void) { uint32_t result; __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); return(result); } /** \brief Set Fault Mask This function assigns the given value to the Fault Mask register. \param [in] faultMask Fault Mask value to set */ __attribute__( ( always_inline ) ) static __INLINE void __set_FAULTMASK(uint32_t faultMask) { __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) ); } #endif /* (__CORTEX_M >= 0x03) */ #if (__CORTEX_M == 0x04) /** \brief Get FPSCR This function returns the current value of the Floating Point Status/Control register. \return Floating Point Status/Control register value */ __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_FPSCR(void) { #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) uint32_t result; __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); return(result); #else return(0); #endif } /** \brief Set FPSCR This function assigns the given value to the Floating Point Status/Control register. \param [in] fpscr Floating Point Status/Control value to set */ __attribute__( ( always_inline ) ) static __INLINE void __set_FPSCR(uint32_t fpscr) { #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) ); #endif } #endif /* (__CORTEX_M == 0x04) */ #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ /* TASKING carm specific functions */ /* * The CMSIS functions have been implemented as intrinsics in the compiler. * Please use "carm -?i" to get an up to date list of all instrinsics, * Including the CMSIS ones. */ #endif /*@} end of CMSIS_Core_RegAccFunctions */ #endif /* __CORE_CMFUNC_H */
1137519-player
lib/CMSIS/Include/core_cmFunc.h
C
lgpl
15,691
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <link rel="File-List" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/filelist.xml"> <link rel="Edit-Time-Data" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/editdata.mso"><!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--> <title>Release Notes for STM32F105/7xx and STM32F2xx USB Device Library</title><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>STMicroelectronics</o:Author> <o:LastAuthor>Raouf Hosni</o:LastAuthor> <o:Revision>39</o:Revision> <o:TotalTime>137</o:TotalTime> <o:Created>2009-02-27T19:26:00Z</o:Created> <o:LastSaved>2010-10-15T11:07:00Z</o:LastSaved> <o:Pages>3</o:Pages> <o:Words>973</o:Words> <o:Characters>5548</o:Characters> <o:Company>STMicroelectronics</o:Company> <o:Lines>46</o:Lines> <o:Paragraphs>13</o:Paragraphs> <o:CharactersWithSpaces>6508</o:CharactersWithSpaces> <o:Version>12.00</o:Version> </o:DocumentProperties> </xml><![endif]--><link rel="themeData" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/themedata.thmx"> <link rel="colorSchemeMapping" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/colorschememapping.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>110</w:Zoom> <w:TrackMoves>false</w:TrackMoves> <w:TrackFormatting/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="&#45;-"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" LatentStyleCount="267"> <w:LsdException Locked="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="99" Name="No List"/> <w:LsdException Locked="false" Priority="99" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" Priority="99" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--> <style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:1627400839 -2147483648 8 0 66047 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";} h1 {mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"Heading 1 Char"; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; mso-outline-level:1; font-size:24.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; font-weight:bold;} h2 {mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"Heading 2 Char"; mso-style-next:Normal; margin-top:12.0pt; margin-right:0in; margin-bottom:3.0pt; margin-left:0in; mso-pagination:widow-orphan; page-break-after:avoid; mso-outline-level:2; font-size:14.0pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; font-weight:bold; font-style:italic;} h3 {mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"Heading 3 Char"; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; mso-outline-level:3; font-size:13.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; font-weight:bold;} a:link, span.MsoHyperlink {mso-style-unhide:no; color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-unhide:no; color:blue; text-decoration:underline; text-underline:single;} p {mso-style-unhide:no; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";} p.MsoAcetate, li.MsoAcetate, div.MsoAcetate {mso-style-unhide:no; mso-style-link:"Balloon Text Char"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:8.0pt; font-family:"Tahoma","sans-serif"; mso-fareast-font-family:"Times New Roman";} span.Heading1Char {mso-style-name:"Heading 1 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 1"; mso-ansi-font-size:14.0pt; mso-bidi-font-size:14.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#365F91; mso-themecolor:accent1; mso-themeshade:191; font-weight:bold;} span.Heading2Char {mso-style-name:"Heading 2 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 2"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:13.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#4F81BD; mso-themecolor:accent1; font-weight:bold;} span.Heading3Char {mso-style-name:"Heading 3 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 3"; mso-ansi-font-size:12.0pt; mso-bidi-font-size:12.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#4F81BD; mso-themecolor:accent1; font-weight:bold;} span.BalloonTextChar {mso-style-name:"Balloon Text Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Balloon Text"; mso-ansi-font-size:8.0pt; mso-bidi-font-size:8.0pt; font-family:"Tahoma","sans-serif"; mso-ascii-font-family:Tahoma; mso-hansi-font-family:Tahoma; mso-bidi-font-family:Tahoma;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} /* List Definitions */ @list l0 {mso-list-id:62067358; mso-list-template-ids:-174943062;} @list l0:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l0:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1 {mso-list-id:128015942; mso-list-template-ids:-90681214;} @list l1:level1 {mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2 {mso-list-id:216556000; mso-list-template-ids:925924412;} @list l2:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l2:level2 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l2:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3 {mso-list-id:562446694; mso-list-template-ids:913898366;} @list l3:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l3:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4 {mso-list-id:797802132; mso-list-template-ids:-1971191336;} @list l4:level1 {mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5 {mso-list-id:907304066; mso-list-template-ids:1969781532;} @list l5:level1 {mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6 {mso-list-id:1050613616; mso-list-template-ids:-1009886748;} @list l6:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l6:level2 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l6:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7 {mso-list-id:1234970193; mso-list-template-ids:2055904002;} @list l7:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l7:level2 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l7:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8 {mso-list-id:1846092290; mso-list-template-ids:-768590846;} @list l8:level1 {mso-level-start-at:2; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9 {mso-list-id:1894656566; mso-list-template-ids:1199983812;} @list l9:level1 {mso-level-start-at:2; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} ol {margin-bottom:0in;} ul {margin-bottom:0in;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="7170"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--></head> <body style="" lang="EN-US" link="blue" vlink="blue"> <div class="WordSection1"> <p class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;;"><o:p>&nbsp;</o:p></span></p> <div align="center"> <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900"> <tbody><tr style=""> <td style="padding: 0in;" valign="top"> <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900"> <tbody><tr style=""> <td style="padding: 0in 5.4pt;" valign="top"> <p class="MsoNormal"><span style="font-size: 8pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: blue;"><a href="../../Release_Notes.html">Back to Release page</a></span><span style="font-size: 10pt;"><o:p></o:p></span></p> </td> </tr> <tr style=""> <td style="padding: 1.5pt;"> <h1 style="margin-bottom: 0.25in; text-align: center;" align="center"><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: rgb(51, 102, 255);">Release Notes for STM32F105/7xx and STM32F2xx USB Device Library</span><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><o:p></o:p></span></h1> <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;">Copyright 2011 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p> <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;"><img id="_x0000_i1026" src="../../_htmresc/logo.bmp" border="0" height="65" width="86"></span><span style="font-size: 10pt;"><o:p></o:p></span></p> </td> </tr> </tbody></table> <p class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; display: none;"><o:p>&nbsp;</o:p></span></p> <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900"> <tbody><tr style=""> <td style="padding: 0in;" valign="top"> <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><span style="font-size: 12pt; color: white;">Contents<o:p></o:p></span></h2> <ol style="margin-top: 0in;" start="1" type="1"> <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><a href="#History">STM32F105/7xx and STM32F2xx USB Device Library&nbsp;update History</a><o:p></o:p></span></li> <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><a href="#License">License</a><o:p></o:p></span></li> </ol> <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">STM32F105/7xx and STM32F2xx USB Device Library&nbsp; update History</span></h2><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 171px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0 / 22-July-2011<o:p></o:p></span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main Changes<o:p></o:p></span></u></b></p> <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">First official version for <span style="font-weight: bold; font-style: italic;">STM32F105/7xx</span> and <span style="font-weight: bold; font-style: italic;">STM32F2xx</span> devices</span></li></ul><span style="font-size: 10pt; font-family: Verdana;"></span><br><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span> <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2> <p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: black;">The use of this STM32 software is governed by the terms and conditions of the License Agreement </span><span style="font-size: 10pt; font-family: Verdana; color: black;"><span style="font-weight: bold; font-style: italic;">"MCD-ST Liberty SW License Agreement 20Jul2011 v0.1.pdf"</span> </span><span style="font-size: 10pt; font-family: Verdana; color: black;">available in the root of this package.</span><span style="color: black;"><o:p>&nbsp;</o:p></span></p> <div class="MsoNormal" style="text-align: center;" align="center"><span style="color: black;"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNormal" style="margin: 4.5pt 0in 4.5pt 0.25in; text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">For complete documentation on </span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">STM32(<span style="color: black;">CORTEX M3) 32-Bit Microcontrollers visit </span><u><span style="color: blue;"><a href="http://www.st.com/stm32" target="_blank">www.st.com/STM32</a></span></u></span><span style="color: black;"><o:p></o:p></span></p> </td> </tr> </tbody></table> <p class="MsoNormal"><span style="font-size: 10pt;"><o:p></o:p></span></p> </td> </tr> </tbody></table> </div> <p class="MsoNormal"><o:p>&nbsp;</o:p></p> </div> </body></html>
1137519-player
lib/STM32_USB_Device_Library/Release_Notes.html
HTML
lgpl
37,299
/** ****************************************************************************** * @file usbd_cdc_core.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides the high layer firmware functions to manage the * following functionalities of the USB CDC Class: * - Initialization and Configuration of high and low layer * - Enumeration as CDC Device (and enumeration for each implemented memory interface) * - OUT/IN data transfer * - Command IN transfer (class requests management) * - Error management * * @verbatim * * =================================================================== * CDC Class Driver Description * =================================================================== * This driver manages the "Universal Serial Bus Class Definitions for Communications Devices * Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus * Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007" * This driver implements the following aspects of the specification: * - Device descriptor management * - Configuration descriptor management * - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN) * - Requests management (as described in section 6.2 in specification) * - Abstract Control Model compliant * - Union Functional collection (using 1 IN endpoint for control) * - Data interface class * @note * For the Abstract Control Model, this core allows only transmitting the requests to * lower layer dispatcher (ie. usbd_cdc_vcp.c/.h) which should manage each request and * perform relative actions. * * These aspects may be enriched or modified for a specific user application. * * This driver doesn't implement the following aspects of the specification * (but it is possible to manage these features with some modifications on this driver): * - Any class-specific aspect relative to communication classes should be managed by user application. * - All communication classes other than PSTN are not managed * * @endverbatim * ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_cdc_core.h" #include "usbd_desc.h" #include "usbd_req.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_cdc * @brief usbd core module * @{ */ /** @defgroup usbd_cdc_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup usbd_cdc_Private_Defines * @{ */ /** * @} */ /** @defgroup usbd_cdc_Private_Macros * @{ */ /** * @} */ /** @defgroup usbd_cdc_Private_FunctionPrototypes * @{ */ /********************************************* CDC Device library callbacks *********************************************/ static uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx); static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx); static uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req); static uint8_t usbd_cdc_EP0_RxReady (void *pdev); static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum); static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum); static uint8_t usbd_cdc_SOF (void *pdev); /********************************************* CDC specific management functions *********************************************/ static void Handle_USBAsynchXfer (void *pdev); static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length); #ifdef USE_USB_OTG_HS static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length); #endif /** * @} */ /** @defgroup usbd_cdc_Private_Variables * @{ */ extern CDC_IF_Prop_TypeDef APP_FOPS; extern uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC]; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static __IO uint32_t usbd_cdc_AltSet __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t USB_Rx_Buffer [CDC_DATA_MAX_PACKET_SIZE] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t APP_Rx_Buffer [APP_RX_DATA_SIZE] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t CmdBuff[CDC_CMD_PACKET_SZE] __ALIGN_END ; uint32_t APP_Rx_ptr_in = 0; uint32_t APP_Rx_ptr_out = 0; uint32_t APP_Rx_length = 0; uint8_t USB_Tx_State = 0; static uint32_t cdcCmd = 0xFF; static uint32_t cdcLen = 0; /* CDC interface class callbacks structure */ USBD_Class_cb_TypeDef USBD_CDC_cb = { usbd_cdc_Init, usbd_cdc_DeInit, usbd_cdc_Setup, NULL, /* EP0_TxSent, */ usbd_cdc_EP0_RxReady, usbd_cdc_DataIn, usbd_cdc_DataOut, usbd_cdc_SOF, NULL, NULL, USBD_cdc_GetCfgDesc, #ifdef USE_USB_OTG_HS USBD_cdc_GetOtherCfgDesc, /* use same cobfig as per FS */ #endif /* USE_USB_OTG_HS */ }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB CDC device Configuration Descriptor */ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { /*Configuration Descriptor*/ 0x09, /* bLength: Configuration Descriptor size */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */ 0x00, 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 0xC0, /* bmAttributes: self powered */ 0x32, /* MaxPower 0 mA */ /*---------------------------------------------------------------------------*/ /*Interface Descriptor */ 0x09, /* bLength: Interface Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ /* Interface descriptor type */ 0x00, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x01, /* bNumEndpoints: One endpoints used */ 0x02, /* bInterfaceClass: Communication Interface Class */ 0x02, /* bInterfaceSubClass: Abstract Control Model */ 0x01, /* bInterfaceProtocol: Common AT commands */ 0x00, /* iInterface: */ /*Header Functional Descriptor*/ 0x05, /* bLength: Endpoint Descriptor size */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x00, /* bDescriptorSubtype: Header Func Desc */ 0x10, /* bcdCDC: spec release number */ 0x01, /*Call Management Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 0x00, /* bmCapabilities: D0+D1 */ 0x01, /* bDataInterface: 1 */ /*ACM Functional Descriptor*/ 0x04, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ 0x02, /* bmCapabilities */ /*Union Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x06, /* bDescriptorSubtype: Union func desc */ 0x00, /* bMasterInterface: Communication class interface */ 0x01, /* bSlaveInterface0: Data Class Interface */ /*Endpoint 2 Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ CDC_CMD_EP, /* bEndpointAddress */ 0x03, /* bmAttributes: Interrupt */ LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */ HIBYTE(CDC_CMD_PACKET_SZE), #ifdef USE_USB_OTG_HS 0x10, /* bInterval: */ #else 0xFF, /* bInterval: */ #endif /* USE_USB_OTG_HS */ /*---------------------------------------------------------------------------*/ /*Data class interface descriptor*/ 0x09, /* bLength: Endpoint Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */ 0x01, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x02, /* bNumEndpoints: Two endpoints used */ 0x0A, /* bInterfaceClass: CDC */ 0x00, /* bInterfaceSubClass: */ 0x00, /* bInterfaceProtocol: */ 0x00, /* iInterface: */ /*Endpoint OUT Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ CDC_OUT_EP, /* bEndpointAddress */ 0x02, /* bmAttributes: Bulk */ LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */ HIBYTE(CDC_DATA_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ /*Endpoint IN Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ CDC_IN_EP, /* bEndpointAddress */ 0x02, /* bmAttributes: Bulk */ LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */ HIBYTE(CDC_DATA_MAX_PACKET_SIZE), 0x00 /* bInterval: ignore for Bulk transfer */ } ; #ifdef USE_USB_OTG_HS #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_CDC_CONFIG_DESC_SIZ, 0x00, 0x02, /* bNumInterfaces: 2 interfaces */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ 0xC0, /* bmAttributes: */ 0x32, /* MaxPower 100 mA */ /*Interface Descriptor */ 0x09, /* bLength: Interface Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ /* Interface descriptor type */ 0x00, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x01, /* bNumEndpoints: One endpoints used */ 0x02, /* bInterfaceClass: Communication Interface Class */ 0x02, /* bInterfaceSubClass: Abstract Control Model */ 0x01, /* bInterfaceProtocol: Common AT commands */ 0x00, /* iInterface: */ /*Header Functional Descriptor*/ 0x05, /* bLength: Endpoint Descriptor size */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x00, /* bDescriptorSubtype: Header Func Desc */ 0x10, /* bcdCDC: spec release number */ 0x01, /*Call Management Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 0x00, /* bmCapabilities: D0+D1 */ 0x01, /* bDataInterface: 1 */ /*ACM Functional Descriptor*/ 0x04, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ 0x02, /* bmCapabilities */ /*Union Functional Descriptor*/ 0x05, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x06, /* bDescriptorSubtype: Union func desc */ 0x00, /* bMasterInterface: Communication class interface */ 0x01, /* bSlaveInterface0: Data Class Interface */ /*Endpoint 2 Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ CDC_CMD_EP, /* bEndpointAddress */ 0x03, /* bmAttributes: Interrupt */ LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */ HIBYTE(CDC_CMD_PACKET_SZE), 0xFF, /* bInterval: */ /*---------------------------------------------------------------------------*/ /*Data class interface descriptor*/ 0x09, /* bLength: Endpoint Descriptor size */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */ 0x01, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x02, /* bNumEndpoints: Two endpoints used */ 0x0A, /* bInterfaceClass: CDC */ 0x00, /* bInterfaceSubClass: */ 0x00, /* bInterfaceProtocol: */ 0x00, /* iInterface: */ /*Endpoint OUT Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ CDC_OUT_EP, /* bEndpointAddress */ 0x02, /* bmAttributes: Bulk */ 0x40, /* wMaxPacketSize: */ 0x00, 0x00, /* bInterval: ignore for Bulk transfer */ /*Endpoint IN Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ CDC_IN_EP, /* bEndpointAddress */ 0x02, /* bmAttributes: Bulk */ 0x40, /* wMaxPacketSize: */ 0x00, 0x00 /* bInterval */ }; #endif /* USE_USB_OTG_HS */ /** * @} */ /** @defgroup usbd_cdc_Private_Functions * @{ */ /** * @brief usbd_cdc_Init * Initilaize the CDC interface * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx) { uint8_t *pbuf; /* Open EP IN */ DCD_EP_Open(pdev, CDC_IN_EP, CDC_DATA_IN_PACKET_SIZE, USB_OTG_EP_BULK); /* Open EP OUT */ DCD_EP_Open(pdev, CDC_OUT_EP, CDC_DATA_OUT_PACKET_SIZE, USB_OTG_EP_BULK); /* Open Command IN EP */ DCD_EP_Open(pdev, CDC_CMD_EP, CDC_CMD_PACKET_SZE, USB_OTG_EP_INT); pbuf = (uint8_t *)USBD_DeviceDesc; pbuf[4] = DEVICE_CLASS_CDC; pbuf[5] = DEVICE_SUBCLASS_CDC; /* Initialize the Interface physical components */ APP_FOPS.pIf_Init(); /* Prepare Out endpoint to receive next packet */ DCD_EP_PrepareRx(pdev, CDC_OUT_EP, (uint8_t*)(USB_Rx_Buffer), CDC_DATA_OUT_PACKET_SIZE); return USBD_OK; } /** * @brief usbd_cdc_Init * DeInitialize the CDC layer * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx) { /* Open EP IN */ DCD_EP_Close(pdev, CDC_IN_EP); /* Open EP OUT */ DCD_EP_Close(pdev, CDC_OUT_EP); /* Open Command IN EP */ DCD_EP_Close(pdev, CDC_CMD_EP); /* Restore default state of the Interface physical components */ APP_FOPS.pIf_DeInit(); return USBD_OK; } /** * @brief usbd_cdc_Setup * Handle the CDC specific requests * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req) { uint16_t len; uint8_t *pbuf; switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* CDC Class Requests -------------------------------*/ case USB_REQ_TYPE_CLASS : /* Check if the request is a data setup packet */ if (req->wLength) { /* Check if the request is Device-to-Host */ if (req->bmRequest & 0x80) { /* Get the data to be sent to Host from interface layer */ APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength); /* Send the data to the host */ USBD_CtlSendData (pdev, CmdBuff, req->wLength); } else /* Host-to-Device requeset */ { /* Set the value of the current command to be processed */ cdcCmd = req->bRequest; cdcLen = req->wLength; /* Prepare the reception of the buffer over EP0 Next step: the received data will be managed in usbd_cdc_EP0_TxSent() function. */ USBD_CtlPrepareRx (pdev, CmdBuff, req->wLength); } } else /* No Data request */ { /* Transfer the command to the interface layer */ APP_FOPS.pIf_Ctrl(req->bRequest, NULL, 0); } return USBD_OK; default: USBD_CtlError (pdev, req); return USBD_FAIL; /* Standard Requests -------------------------------*/ case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_DESCRIPTOR: if( (req->wValue >> 8) == CDC_DESCRIPTOR_TYPE) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED pbuf = usbd_cdc_Desc; #else pbuf = usbd_cdc_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM); #endif len = MIN(USB_CDC_DESC_SIZ , req->wLength); } USBD_CtlSendData (pdev, pbuf, len); break; case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, (uint8_t *)&usbd_cdc_AltSet, 1); break; case USB_REQ_SET_INTERFACE : if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM) { usbd_cdc_AltSet = (uint8_t)(req->wValue); } else { /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } break; } } return USBD_OK; } /** * @brief usbd_cdc_EP0_RxReady * Data received on control endpoint * @param pdev: device device instance * @retval status */ static uint8_t usbd_cdc_EP0_RxReady (void *pdev) { if (cdcCmd != NO_CMD) { /* Process the data */ APP_FOPS.pIf_Ctrl(cdcCmd, CmdBuff, cdcLen); /* Reset the command variable to default value */ cdcCmd = NO_CMD; } return USBD_OK; } /** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if (USB_Tx_State == 1) { if (APP_Rx_length == 0) { USB_Tx_State = 0; } else { if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE){ USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } } return USBD_OK; } /** * @brief usbd_audio_DataOut * Data received on non-control Out endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum) { uint16_t USB_Rx_Cnt; /* Get the received data buffer and update the counter */ USB_Rx_Cnt = ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count; /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the application Xfer */ APP_FOPS.pIf_DataRx(USB_Rx_Buffer, USB_Rx_Cnt); /* Prepare Out endpoint to receive next packet */ DCD_EP_PrepareRx(pdev, CDC_OUT_EP, (uint8_t*)(USB_Rx_Buffer), CDC_DATA_OUT_PACKET_SIZE); return USBD_OK; } /** * @brief usbd_audio_SOF * Start Of Frame event management * @param pdev: instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_SOF (void *pdev) { static uint32_t FrameCount = 0; if (FrameCount++ == CDC_IN_FRAME_INTERVAL) { /* Reset the frame counter */ FrameCount = 0; /* Check the data to be sent through IN pipe */ Handle_USBAsynchXfer(pdev); } return USBD_OK; } /** * @brief Handle_USBAsynchXfer * Send data to USB * @param pdev: instance * @retval None */ static void Handle_USBAsynchXfer (void *pdev) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if(USB_Tx_State != 1) { if (APP_Rx_ptr_out == APP_RX_DATA_SIZE) { APP_Rx_ptr_out = 0; } if(APP_Rx_ptr_out == APP_Rx_ptr_in) { USB_Tx_State = 0; return; } if(APP_Rx_ptr_out > APP_Rx_ptr_in) /* rollback */ { APP_Rx_length = APP_RX_DATA_SIZE - APP_Rx_ptr_out; } else { APP_Rx_length = APP_Rx_ptr_in - APP_Rx_ptr_out; } #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED APP_Rx_length &= ~0x03; #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE) { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; } USB_Tx_State = 1; DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } } /** * @brief USBD_cdc_GetCfgDesc * Return configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (usbd_cdc_CfgDesc); return usbd_cdc_CfgDesc; } /** * @brief USBD_cdc_GetCfgDesc * Return configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ #ifdef USE_USB_OTG_HS static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (usbd_cdc_OtherCfgDesc); return usbd_cdc_OtherCfgDesc; } #endif /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
C
lgpl
25,820
/** ****************************************************************************** * @file usbd_cdc_if_template.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Generic media access Layer. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #pragma data_alignment = 4 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* Includes ------------------------------------------------------------------*/ #include "usbd_cdc_if_template.h" #include "stm32_eval.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* These are external variables imported from CDC core to be used for IN transfer management. */ extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer. These data will be sent over USB IN endpoint in the CDC core functions. */ extern uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to start address when writing received data in the buffer APP_Rx_Buffer. */ /* Private function prototypes -----------------------------------------------*/ static uint16_t TEMPLATE_Init (void); static uint16_t TEMPLATE_DeInit (void); static uint16_t TEMPLATE_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len); static uint16_t TEMPLATE_DataTx (uint8_t* Buf, uint32_t Len); static uint16_t TEMPLATE_DataRx (uint8_t* Buf, uint32_t Len); CDC_IF_Prop_TypeDef TEMPLATE_fops = { TEMPLATE_Init, TEMPLATE_DeInit, TEMPLATE_Ctrl, TEMPLATE_DataTx, TEMPLATE_DataRx }; /* Private functions ---------------------------------------------------------*/ /** * @brief TEMPLATE_Init * Initializes the CDC media low layer * @param None * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ static uint16_t TEMPLATE_Init(void) { /* Add your initialization code here */ return USBD_OK; } /** * @brief TEMPLATE_DeInit * DeInitializes the CDC media low layer * @param None * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ static uint16_t TEMPLATE_DeInit(void) { /* Add your deinitialization code here */ return USBD_OK; } /** * @brief TEMPLATE_Ctrl * Manage the CDC class requests * @param Cmd: Command code * @param Buf: Buffer containing command data (request parameters) * @param Len: Number of data to be sent (in bytes) * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ static uint16_t TEMPLATE_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len) { switch (Cmd) { case SEND_ENCAPSULATED_COMMAND: /* Add your code here */ break; case GET_ENCAPSULATED_RESPONSE: /* Add your code here */ break; case SET_COMM_FEATURE: /* Add your code here */ break; case GET_COMM_FEATURE: /* Add your code here */ break; case CLEAR_COMM_FEATURE: /* Add your code here */ break; case SET_LINE_CODING: /* Add your code here */ break; case GET_LINE_CODING: /* Add your code here */ break; case SET_CONTROL_LINE_STATE: /* Add your code here */ break; case SEND_BREAK: /* Add your code here */ break; default: break; } return USBD_OK; } /** * @brief TEMPLATE_DataTx * CDC received data to be send over USB IN endpoint are managed in * this function. * @param Buf: Buffer of data to be sent * @param Len: Number of data to be sent (in bytes) * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ static uint16_t TEMPLATE_DataTx (uint8_t* Buf, uint32_t Len) { /* Get the data to be sent */ for (i = 0; i < Len; i++) { /* APP_Rx_Buffer[APP_Rx_ptr_in] = XXX_ReceiveData(XXX); */ } /* Increment the in pointer */ APP_Rx_ptr_in++; /* To avoid buffer overflow */ if(APP_Rx_ptr_in == APP_RX_DATA_SIZE) { APP_Rx_ptr_in = 0; } return USBD_OK; } /** * @brief TEMPLATE_DataRx * Data received over USB OUT endpoint are sent over CDC interface * through this function. * * @note * This function will block any OUT packet reception on USB endpoint * untill exiting this function. If you exit this function before transfer * is complete on CDC interface (ie. using DMA controller) it will result * in receiving more data while previous ones are still not sent. * * @param Buf: Buffer of data to be received * @param Len: Number of data received (in bytes) * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ static uint16_t TEMPLATE_DataRx (uint8_t* Buf, uint32_t Len) { uint32_t i; /* Send the received buffer */ for (i = 0; i < Len; i++) { /* XXXX_SendData(XXXX, *(Buf + i) ); */ } return USBD_OK; } /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_if_template.c
C
lgpl
6,301
/** ****************************************************************************** * @file usbd_cdc_core.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header file for the usbd_cdc_core.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #ifndef __USB_CDC_CORE_H_ #define __USB_CDC_CORE_H_ #include "usbd_ioreq.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_cdc * @brief This file is the Header file for USBD_cdc.c * @{ */ /** @defgroup usbd_cdc_Exported_Defines * @{ */ #define USB_CDC_CONFIG_DESC_SIZ (67) #define USB_CDC_DESC_SIZ (67-9) #define CDC_DESCRIPTOR_TYPE 0x21 #define DEVICE_CLASS_CDC 0x02 #define DEVICE_SUBCLASS_CDC 0x00 #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 #define USB_STRING_DESCRIPTOR_TYPE 0x03 #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 #define STANDARD_ENDPOINT_DESC_SIZE 0x09 #define CDC_DATA_IN_PACKET_SIZE *(uint16_t *)(((USB_OTG_CORE_HANDLE *)pdev)->dev.pConfig_descriptor + 57) #define CDC_DATA_OUT_PACKET_SIZE *(uint16_t *)(((USB_OTG_CORE_HANDLE *)pdev)->dev.pConfig_descriptor + 64) /*---------------------------------------------------------------------*/ /* CDC definitions */ /*---------------------------------------------------------------------*/ /**************************************************/ /* CDC Requests */ /**************************************************/ #define SEND_ENCAPSULATED_COMMAND 0x00 #define GET_ENCAPSULATED_RESPONSE 0x01 #define SET_COMM_FEATURE 0x02 #define GET_COMM_FEATURE 0x03 #define CLEAR_COMM_FEATURE 0x04 #define SET_LINE_CODING 0x20 #define GET_LINE_CODING 0x21 #define SET_CONTROL_LINE_STATE 0x22 #define SEND_BREAK 0x23 #define NO_CMD 0xFF /** * @} */ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ typedef struct _CDC_IF_PROP { uint16_t (*pIf_Init) (void); uint16_t (*pIf_DeInit) (void); uint16_t (*pIf_Ctrl) (uint32_t Cmd, uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataTx) (uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataRx) (uint8_t* Buf, uint32_t Len); } CDC_IF_Prop_TypeDef; /** * @} */ /** @defgroup USBD_CORE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_Variables * @{ */ extern USBD_Class_cb_TypeDef USBD_CDC_cb; /** * @} */ /** @defgroup USB_CORE_Exported_Functions * @{ */ /** * @} */ #endif // __USB_CDC_CORE_H_ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h
C
lgpl
4,067
/** ****************************************************************************** * @file usbd_cdc_if_template.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Header for dfu_mal.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_CDC_IF_TEMPLATE_H #define __USBD_CDC_IF_TEMPLATE_H /* Includes ------------------------------------------------------------------*/ #ifdef STM32F2XX #include "stm32f2xx.h" #elif defined(STM32F10X_CL) #include "stm32f10x.h" #endif /* STM32F2XX */ #include "usbd_conf.h" #include "usbd_cdc_core.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ extern CDC_IF_Prop_TypeDef TEMPLATE_fops; /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ #endif /* __USBD_CDC_IF_TEMPLATE_H */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_if_template.h
C
lgpl
1,902
/** ****************************************************************************** * @file usbd_hid_core.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides the HID core functions. * * @verbatim * * =================================================================== * HID Class Description * =================================================================== * This module manages the HID class V1.11 following the "Device Class Definition * for Human Interface Devices (HID) Version 1.11 Jun 27, 2001". * This driver implements the following aspects of the specification: * - The Boot Interface Subclass * - The Mouse protocol * - Usage Page : Generic Desktop * - Usage : Joystick) * - Collection : Application * * @note In HS mode and when the DMA is used, all variables and data structures * dealing with the DMA during the transaction process should be 32-bit aligned. * * * @endverbatim * ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_hid_core.h" #include "usbd_desc.h" #include "usbd_req.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_HID * @brief usbd core module * @{ */ /** @defgroup USBD_HID_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_HID_Private_Defines * @{ */ /** * @} */ /** @defgroup USBD_HID_Private_Macros * @{ */ /** * @} */ /** @defgroup USBD_HID_Private_FunctionPrototypes * @{ */ static uint8_t USBD_HID_Init (void *pdev, uint8_t cfgidx); static uint8_t USBD_HID_DeInit (void *pdev, uint8_t cfgidx); static uint8_t USBD_HID_Setup (void *pdev, USB_SETUP_REQ *req); static uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length); static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum); /** * @} */ /** @defgroup USBD_HID_Private_Variables * @{ */ USBD_Class_cb_TypeDef USBD_HID_cb = { USBD_HID_Init, USBD_HID_DeInit, USBD_HID_Setup, NULL, /*EP0_TxSent*/ NULL, /*EP0_RxReady*/ USBD_HID_DataIn, /*DataIn*/ NULL, /*DataOut*/ NULL, /*SOF */ NULL, NULL, USBD_HID_GetCfgDesc, #ifdef USB_OTG_HS_CORE USBD_HID_GetCfgDesc, /* use same config as per FS */ #endif }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static uint32_t USBD_HID_AltSet __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static uint32_t USBD_HID_Protocol __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static uint32_t USBD_HID_IdleState __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB HID device Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /*bNumInterfaces: 1 interface*/ 0x01, /*bConfigurationValue: Configuration value*/ 0x00, /*iConfiguration: Index of string descriptor describing the configuration*/ 0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */ 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/ /************** Descriptor of Joystick Mouse interface ****************/ /* 09 */ 0x09, /*bLength: Interface Descriptor size*/ USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/ 0x00, /*bInterfaceNumber: Number of Interface*/ 0x00, /*bAlternateSetting: Alternate setting*/ 0x01, /*bNumEndpoints*/ 0x03, /*bInterfaceClass: HID*/ 0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ 0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/ 0, /*iInterface: Index of string descriptor*/ /******************** Descriptor of Joystick Mouse HID ********************/ /* 18 */ 0x09, /*bLength: HID Descriptor size*/ HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/ 0x11, /*bcdHID: HID Class Spec release number*/ 0x01, 0x00, /*bCountryCode: Hardware target country*/ 0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/ 0x22, /*bDescriptorType*/ HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/ 0x00, /******************** Descriptor of Mouse endpoint ********************/ /* 27 */ 0x07, /*bLength: Endpoint Descriptor size*/ USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/ HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/ 0x03, /*bmAttributes: Interrupt endpoint*/ HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */ 0x00, 0x0A, /*bInterval: Polling Interval (10 ms)*/ /* 34 */ } ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END = { 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x03, 0x81, 0x06, 0xC0, 0x09, 0x3c, 0x05, 0xff, 0x09, 0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0xb1, 0x22, 0x75, 0x06, 0x95, 0x01, 0xb1, 0x01, 0xc0 }; /** * @} */ /** @defgroup USBD_HID_Private_Functions * @{ */ /** * @brief USBD_HID_Init * Initialize the HID interface * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t USBD_HID_Init (void *pdev, uint8_t cfgidx) { /* Open EP IN */ DCD_EP_Open(pdev, HID_IN_EP, HID_IN_PACKET, USB_OTG_EP_INT); /* Open EP OUT */ DCD_EP_Open(pdev, HID_OUT_EP, HID_OUT_PACKET, USB_OTG_EP_INT); return USBD_OK; } /** * @brief USBD_HID_Init * DeInitialize the HID layer * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t USBD_HID_DeInit (void *pdev, uint8_t cfgidx) { /* Close HID EPs */ DCD_EP_Close (pdev , HID_IN_EP); DCD_EP_Close (pdev , HID_OUT_EP); return USBD_OK; } /** * @brief USBD_HID_Setup * Handle the HID specific requests * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t USBD_HID_Setup (void *pdev, USB_SETUP_REQ *req) { uint16_t len = 0; uint8_t *pbuf = NULL; switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_CLASS : switch (req->bRequest) { case HID_REQ_SET_PROTOCOL: USBD_HID_Protocol = (uint8_t)(req->wValue); break; case HID_REQ_GET_PROTOCOL: USBD_CtlSendData (pdev, (uint8_t *)&USBD_HID_Protocol, 1); break; case HID_REQ_SET_IDLE: USBD_HID_IdleState = (uint8_t)(req->wValue >> 8); break; case HID_REQ_GET_IDLE: USBD_CtlSendData (pdev, (uint8_t *)&USBD_HID_IdleState, 1); break; default: USBD_CtlError (pdev, req); return USBD_FAIL; } break; case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_DESCRIPTOR: if( req->wValue >> 8 == HID_REPORT_DESC) { len = MIN(HID_MOUSE_REPORT_DESC_SIZE , req->wLength); pbuf = HID_MOUSE_ReportDesc; } else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE) { //#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED // pbuf = USBD_HID_Desc; //#else pbuf = USBD_HID_CfgDesc + 0x12; //#endif len = MIN(USB_HID_DESC_SIZ , req->wLength); } USBD_CtlSendData (pdev, pbuf, len); break; case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, (uint8_t *)&USBD_HID_AltSet, 1); break; case USB_REQ_SET_INTERFACE : USBD_HID_AltSet = (uint8_t)(req->wValue); break; } } return USBD_OK; } /** * @brief USBD_HID_SendReport * Send HID Report * @param pdev: device instance * @param buff: pointer to report * @retval status */ uint8_t USBD_HID_SendReport (USB_OTG_CORE_HANDLE *pdev, uint8_t *report, uint16_t len) { if (pdev->dev.device_status == USB_OTG_CONFIGURED ) { DCD_EP_Tx (pdev, HID_IN_EP, report, len); } return USBD_OK; } /** * @brief USBD_HID_GetCfgDesc * return configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ static uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (USBD_HID_CfgDesc); return USBD_HID_CfgDesc; } /** * @brief USBD_HID_DataIn * handle data IN Stage * @param pdev: device instance * @param epnum: endpoint index * @retval status */ static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum) { /* Ensure that the FIFO is empty before a new transfer, this condition could be caused by a new transfer before the end of the previous transfer */ DCD_EP_Flush(pdev, HID_IN_EP); return USBD_OK; } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/hid/src/usbd_hid_core.c
C
lgpl
12,276
/** ****************************************************************************** * @file usbd_hid_core.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header file for the usbd_hid_core.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #ifndef __USB_HID_CORE_H_ #define __USB_HID_CORE_H_ #include "usbd_ioreq.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_HID * @brief This file is the Header file for USBD_msc.c * @{ */ /** @defgroup USBD_HID_Exported_Defines * @{ */ #define USB_HID_CONFIG_DESC_SIZ 34 #define USB_HID_DESC_SIZ 9 #define HID_MOUSE_REPORT_DESC_SIZE 74 #define HID_DESCRIPTOR_TYPE 0x21 #define HID_REPORT_DESC 0x22 #define HID_REQ_SET_PROTOCOL 0x0B #define HID_REQ_GET_PROTOCOL 0x03 #define HID_REQ_SET_IDLE 0x0A #define HID_REQ_GET_IDLE 0x02 #define HID_REQ_SET_REPORT 0x09 #define HID_REQ_GET_REPORT 0x01 /** * @} */ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_Variables * @{ */ extern USBD_Class_cb_TypeDef USBD_HID_cb; /** * @} */ /** @defgroup USB_CORE_Exported_Functions * @{ */ uint8_t USBD_HID_SendReport (USB_OTG_CORE_HANDLE *pdev, uint8_t *report, uint16_t len); /** * @} */ #endif // __USB_HID_CORE_H_ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/hid/inc/usbd_hid_core.h
C
lgpl
2,598
/** ****************************************************************************** * @file usbd_msc_scsi.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides all the USBD SCSI layer functions. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_bot.h" #include "usbd_msc_scsi.h" #include "usbd_msc_mem.h" #include "usbd_msc_data.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup MSC_SCSI * @brief Mass storage SCSI layer module * @{ */ /** @defgroup MSC_SCSI_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup MSC_SCSI_Private_Defines * @{ */ /** * @} */ /** @defgroup MSC_SCSI_Private_Macros * @{ */ /** * @} */ /** @defgroup MSC_SCSI_Private_Variables * @{ */ #include "usart.h" static int8_t mediumRemoved = 0; //#define DEBUG SCSI_Sense_TypeDef SCSI_Sense [SENSE_LIST_DEEPTH]; uint8_t SCSI_Sense_Head; uint8_t SCSI_Sense_Tail; uint16_t SCSI_blk_size; uint32_t SCSI_blk_nbr; uint64_t SCSI_blk_addr; uint32_t SCSI_blk_len; USB_OTG_CORE_HANDLE *cdev; /** * @} */ /** @defgroup MSC_SCSI_Private_FunctionPrototypes * @{ */ static int8_t SCSI_TestUnitReady(uint8_t lun, uint8_t *params); static int8_t SCSI_Inquiry(uint8_t lun, uint8_t *params); static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params); static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params); static int8_t SCSI_RequestSense (uint8_t lun, uint8_t *params); static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params); static int8_t SCSI_ModeSense6 (uint8_t lun, uint8_t *params); static int8_t SCSI_ModeSense10 (uint8_t lun, uint8_t *params); static int8_t SCSI_Write10(uint8_t lun , uint8_t *params); static int8_t SCSI_Read10(uint8_t lun , uint8_t *params); static int8_t SCSI_Verify10(uint8_t lun, uint8_t *params); static int8_t SCSI_CheckAddressRange (uint8_t lun , uint32_t blk_offset , uint16_t blk_nbr); static int8_t SCSI_ProcessRead (uint8_t lun); static int8_t SCSI_ProcessWrite (uint8_t lun); /** * @} */ /** @defgroup MSC_SCSI_Private_Functions * @{ */ /** * @brief SCSI_ProcessCmd * Process SCSI commands * @param pdev: device instance * @param lun: Logical unit number * @param params: Command parameters * @retval status */ int8_t SCSI_ProcessCmd(USB_OTG_CORE_HANDLE *pdev, uint8_t lun, uint8_t *params) { cdev = pdev; switch (params[0]) { case SCSI_TEST_UNIT_READY: return SCSI_TestUnitReady(lun, params); case SCSI_REQUEST_SENSE: return SCSI_RequestSense (lun, params); case SCSI_INQUIRY: return SCSI_Inquiry(lun, params); case SCSI_START_STOP_UNIT: return SCSI_StartStopUnit(lun, params); case SCSI_ALLOW_MEDIUM_REMOVAL: return SCSI_StartStopUnit(lun, params); case SCSI_MODE_SENSE6: return SCSI_ModeSense6 (lun, params); case SCSI_MODE_SENSE10: return SCSI_ModeSense10 (lun, params); case SCSI_READ_FORMAT_CAPACITIES: return SCSI_ReadFormatCapacity(lun, params); case SCSI_READ_CAPACITY10: return SCSI_ReadCapacity10(lun, params); case SCSI_READ10: return SCSI_Read10(lun, params); case SCSI_WRITE10: return SCSI_Write10(lun, params); case SCSI_VERIFY10: return SCSI_Verify10(lun, params); default: SCSI_SenseCode(lun, ILLEGAL_REQUEST, INVALID_CDB); return -1; } } /** * @brief SCSI_TestUnitReady * Process SCSI Test Unit Ready Command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_TestUnitReady(uint8_t lun, uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_TestUnitReady"); #endif /* case 9 : Hi > D0 */ if (MSC_BOT_cbw.dDataLength != 0) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } if(mediumRemoved){ SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } if(USBD_STORAGE_fops->IsReady(lun) !=0 ) { SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } MSC_BOT_DataLen = 0; return 0; } /** * @brief SCSI_Inquiry * Process Inquiry command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_Inquiry(uint8_t lun, uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_Inquiry"); #endif uint8_t* pPage; uint16_t len; if (params[1] & 0x01)/*Evpd is set*/ { pPage = (uint8_t *)MSC_Page00_Inquiry_Data; len = LENGTH_INQUIRY_PAGE00; } else { pPage = (uint8_t *)&USBD_STORAGE_fops->pInquiry[lun * USBD_STD_INQUIRY_LENGTH]; len = pPage[4] + 5; if (params[4] <= len) { len = params[4]; } } MSC_BOT_DataLen = len; while (len) { len--; MSC_BOT_Data[len] = pPage[len]; } return 0; } /** * @brief SCSI_ReadCapacity10 * Process Read Capacity 10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_ReadCapacity10"); #endif if(USBD_STORAGE_fops->GetCapacity(lun, &SCSI_blk_nbr, &SCSI_blk_size) != 0) { SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } else { MSC_BOT_Data[0] = (uint8_t)((SCSI_blk_nbr - 1) >> 24); MSC_BOT_Data[1] = (uint8_t)((SCSI_blk_nbr - 1) >> 16); MSC_BOT_Data[2] = (uint8_t)((SCSI_blk_nbr - 1) >> 8); MSC_BOT_Data[3] = (uint8_t)(SCSI_blk_nbr - 1); MSC_BOT_Data[4] = (uint8_t)(SCSI_blk_size >> 24); MSC_BOT_Data[5] = (uint8_t)(SCSI_blk_size >> 16); MSC_BOT_Data[6] = (uint8_t)(SCSI_blk_size >> 8); MSC_BOT_Data[7] = (uint8_t)(SCSI_blk_size); MSC_BOT_DataLen = 8; return 0; } } /** * @brief SCSI_ReadFormatCapacity * Process Read Format Capacity command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_ReadFormatCapacity"); #endif uint16_t blk_size; uint32_t blk_nbr; uint16_t i; for(i=0 ; i < 12 ; i++) { MSC_BOT_Data[i] = 0; } if(USBD_STORAGE_fops->GetCapacity(lun, &blk_nbr, &blk_size) != 0) { SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } else { MSC_BOT_Data[3] = 0x08; MSC_BOT_Data[4] = (uint8_t)((blk_nbr - 1) >> 24); MSC_BOT_Data[5] = (uint8_t)((blk_nbr - 1) >> 16); MSC_BOT_Data[6] = (uint8_t)((blk_nbr - 1) >> 8); MSC_BOT_Data[7] = (uint8_t)(blk_nbr - 1); MSC_BOT_Data[8] = 0x02; MSC_BOT_Data[9] = (uint8_t)(blk_size >> 16); MSC_BOT_Data[10] = (uint8_t)(blk_size >> 8); MSC_BOT_Data[11] = (uint8_t)(blk_size); MSC_BOT_DataLen = 12; return 0; } } /** * @brief SCSI_ModeSense6 * Process Mode Sense6 command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_ModeSense6 (uint8_t lun, uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_ModeSense6"); #endif uint16_t len = 8 ; MSC_BOT_DataLen = len; while (len) { len--; MSC_BOT_Data[len] = MSC_Mode_Sense6_data[len]; } return 0; } /** * @brief SCSI_ModeSense10 * Process Mode Sense10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_ModeSense10 (uint8_t lun, uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_ModeSense10"); #endif uint16_t len = 8; MSC_BOT_DataLen = len; while (len) { len--; MSC_BOT_Data[len] = MSC_Mode_Sense10_data[len]; } return 0; } /** * @brief SCSI_RequestSense * Process Request Sense command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_RequestSense (uint8_t lun, uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_RequestSense"); #endif uint8_t i; for(i=0 ; i < REQUEST_SENSE_DATA_LEN ; i++) { MSC_BOT_Data[i] = 0; } MSC_BOT_Data[0] = 0x70; MSC_BOT_Data[7] = REQUEST_SENSE_DATA_LEN - 6; if((SCSI_Sense_Head != SCSI_Sense_Tail)) { MSC_BOT_Data[2] = SCSI_Sense[SCSI_Sense_Head].Skey; MSC_BOT_Data[12] = SCSI_Sense[SCSI_Sense_Head].w.b.ASCQ; MSC_BOT_Data[13] = SCSI_Sense[SCSI_Sense_Head].w.b.ASC; SCSI_Sense_Head++; if (SCSI_Sense_Head == SENSE_LIST_DEEPTH) { SCSI_Sense_Head = 0; } } MSC_BOT_DataLen = REQUEST_SENSE_DATA_LEN; if (params[4] <= REQUEST_SENSE_DATA_LEN) { MSC_BOT_DataLen = params[4]; } return 0; } /** * @brief SCSI_SenseCode * Load the last error code in the error list * @param lun: Logical unit number * @param sKey: Sense Key * @param ASC: Additional Sense Key * @retval none */ void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC) { SCSI_Sense[SCSI_Sense_Tail].Skey = sKey; SCSI_Sense[SCSI_Sense_Tail].w.ASC = ASC << 8; SCSI_Sense_Tail++; if (SCSI_Sense_Tail == SENSE_LIST_DEEPTH) { SCSI_Sense_Tail = 0; } } /** * @brief SCSI_StartStopUnit * Process Start Stop Unit command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params) { if(params[0] == 0x1b){ #ifdef DEBUG debug.printf("\r\nSCSI_StartStopUnit"); #endif switch(params[4] & 0x3){ case 0: #ifdef DEBUG debug.printf("::STOP"); #endif break; case 1: #ifdef DEBUG debug.printf("::START"); #endif break; case 2: #ifdef DEBUG debug.printf("::EJECT"); #endif mediumRemoved = 1; IWDG_Enable(); // software reset break; case 3: #ifdef DEBUG debug.printf("::INSERT"); #endif break; default: break; } } else if(params[0] == 0x1e){ #ifdef DEBUG debug.printf("\r\nSCSI_AllowMediumRemoval"); #endif } MSC_BOT_DataLen = 0; return 0; } /** * @brief SCSI_Read10 * Process Read10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_Read10(uint8_t lun , uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_Read10"); #endif if(MSC_BOT_State == BOT_IDLE) /* Idle */ { /* case 10 : Ho <> Di */ if ((MSC_BOT_cbw.bmFlags & 0x80) != 0x80) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } if(USBD_STORAGE_fops->IsReady(lun) !=0 ) { SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } SCSI_blk_addr = (uint32_t)(params[2] << 24) | \ (uint32_t)(params[3] << 16) | \ (uint32_t)(params[4] << 8) | \ (uint32_t)(params[5]); SCSI_blk_len = (uint32_t)(params[7] << 8) | \ (uint32_t)(params[8]); if( SCSI_CheckAddressRange(lun, SCSI_blk_addr, SCSI_blk_len) < 0) { return -1; /* error */ } MSC_BOT_State = BOT_DATA_IN; SCSI_blk_addr <<= 9; SCSI_blk_len <<= 9; /* cases 4,5 : Hi <> Dn */ if (MSC_BOT_cbw.dDataLength != SCSI_blk_len) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } } MSC_BOT_DataLen = MSC_MEDIA_PACKET; return SCSI_ProcessRead(lun); } /** * @brief SCSI_Write10 * Process Write10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_Write10 (uint8_t lun , uint8_t *params) { #ifdef DEBUG debug.printf("\r\nSCSI_Write10"); #endif if (MSC_BOT_State == BOT_IDLE) /* Idle */ { /* case 8 : Hi <> Do */ if ((MSC_BOT_cbw.bmFlags & 0x80) == 0x80) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } /* Check whether Media is ready */ if(USBD_STORAGE_fops->IsReady(lun) !=0 ) { SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } /* Check If media is write-protected */ if(USBD_STORAGE_fops->IsWriteProtected(lun) !=0 ) { SCSI_SenseCode(lun, NOT_READY, WRITE_PROTECTED); return -1; } SCSI_blk_addr = (uint32_t)(params[2] << 24) | \ (uint32_t)(params[3] << 16) | \ (uint32_t)(params[4] << 8) | \ (uint32_t)(params[5]); SCSI_blk_len = (uint32_t)(params[7] << 8) | \ (uint32_t)(params[8]); /* check if LBA address is in the right range */ if(SCSI_CheckAddressRange(lun, SCSI_blk_addr, SCSI_blk_len) < 0) { return -1; /* error */ } SCSI_blk_addr <<= 9; SCSI_blk_len <<= 9; /* cases 3,11,13 : Hn,Ho <> D0 */ if (MSC_BOT_cbw.dDataLength != SCSI_blk_len) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } /* Prepare EP to receive first data packet */ MSC_BOT_State = BOT_DATA_OUT; DCD_EP_PrepareRx (cdev, MSC_OUT_EP, MSC_BOT_Data, MIN (SCSI_blk_len, MSC_MEDIA_PACKET)); } else /* Write Process ongoing */ { return SCSI_ProcessWrite(lun); } return 0; } /** * @brief SCSI_Verify10 * Process Verify10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status */ static int8_t SCSI_Verify10(uint8_t lun , uint8_t *params){ #ifdef DEBUG debug.printf("\r\nSCSI_Verify10"); #endif if ((params[1]& 0x02) == 0x02) { SCSI_SenseCode (lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND); return -1; /* Error, Verify Mode Not supported*/ } if(SCSI_CheckAddressRange(lun, SCSI_blk_addr, SCSI_blk_len) < 0) { return -1; /* error */ } MSC_BOT_DataLen = 0; return 0; } /** * @brief SCSI_CheckAddressRange * Check address range * @param lun: Logical unit number * @param blk_offset: first block address * @param blk_nbr: number of block to be processed * @retval status */ static int8_t SCSI_CheckAddressRange (uint8_t lun , uint32_t blk_offset , uint16_t blk_nbr) { #ifdef DEBUG debug.printf("\r\nSCSI_CheckAddressRange"); #endif if ((blk_offset + blk_nbr) > SCSI_blk_nbr ) { SCSI_SenseCode(lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE); return -1; } return 0; } /** * @brief SCSI_ProcessRead * Handle Read Process * @param lun: Logical unit number * @retval status */ static int8_t SCSI_ProcessRead (uint8_t lun) { #ifdef DEBUG debug.printf("\r\nSCSI_ProcessRead"); #endif uint32_t len; len = MIN(SCSI_blk_len , MSC_MEDIA_PACKET); if( USBD_STORAGE_fops->Read(lun , MSC_BOT_Data, SCSI_blk_addr >> 9, len >> 9) < 0) { SCSI_SenseCode(lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR); return -1; } DCD_EP_Tx (cdev, MSC_IN_EP, MSC_BOT_Data, len); SCSI_blk_addr += len; SCSI_blk_len -= len; /* case 6 : Hi = Di */ MSC_BOT_csw.dDataResidue -= len; if (SCSI_blk_len == 0) { MSC_BOT_State = BOT_LAST_DATA_IN; } return 0; } /** * @brief SCSI_ProcessWrite * Handle Write Process * @param lun: Logical unit number * @retval status */ static int8_t SCSI_ProcessWrite (uint8_t lun) { #ifdef DEBUG debug.printf("\r\nSCSI_ProcessWrite"); #endif uint32_t len; len = MIN(SCSI_blk_len , MSC_MEDIA_PACKET); if(USBD_STORAGE_fops->Write(lun , MSC_BOT_Data, SCSI_blk_addr >> 9, len >> 9) < 0) { SCSI_SenseCode(lun, HARDWARE_ERROR, WRITE_FAULT); return -1; } SCSI_blk_addr += len; SCSI_blk_len -= len; /* case 12 : Ho = Do */ MSC_BOT_csw.dDataResidue -= len; if (SCSI_blk_len == 0) { MSC_BOT_SendCSW (cdev, CSW_CMD_PASSED); } else { /* Prapare EP to Receive next packet */ DCD_EP_PrepareRx (cdev, MSC_OUT_EP, MSC_BOT_Data, MIN (SCSI_blk_len, MSC_MEDIA_PACKET)); } return 0; } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
C
lgpl
18,703
/** ****************************************************************************** * @file usbd_msc_data.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides all the vital inquiry pages and sense data. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_data.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup MSC_DATA * @brief Mass storage info/data module * @{ */ /** @defgroup MSC_DATA_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup MSC_DATA_Private_Defines * @{ */ /** * @} */ /** @defgroup MSC_DATA_Private_Macros * @{ */ /** * @} */ /** @defgroup MSC_DATA_Private_Variables * @{ */ /* USB Mass storage Page 0 Inquiry Data */ const uint8_t MSC_Page00_Inquiry_Data[] = {//7 0x00, 0x00, 0x00, (LENGTH_INQUIRY_PAGE00 - 4), 0x00, 0x80, 0x83 }; /* USB Mass storage sense 6 Data */ const uint8_t MSC_Mode_Sense6_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* USB Mass storage sense 10 Data */ const uint8_t MSC_Mode_Sense10_data[] = { 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /** * @} */ /** @defgroup MSC_DATA_Private_FunctionPrototypes * @{ */ /** * @} */ /** @defgroup MSC_DATA_Private_Functions * @{ */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
C
lgpl
2,411
/** ****************************************************************************** * @file usbd_msc_bot.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides all the BOT protocol core functions. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_bot.h" #include "usbd_msc_scsi.h" #include "usbd_ioreq.h" #include "usbd_msc_mem.h" #include "mpool.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup MSC_BOT * @brief BOT protocol module * @{ */ /** @defgroup MSC_BOT_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup MSC_BOT_Private_Defines * @{ */ /** * @} */ /** @defgroup MSC_BOT_Private_Macros * @{ */ /** * @} */ /** @defgroup MSC_BOT_Private_Variables * @{ */ uint16_t MSC_BOT_DataLen; uint8_t MSC_BOT_State; uint8_t MSC_BOT_Status; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ //__ALIGN_BEGIN uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET] __ALIGN_END ; __ALIGN_BEGIN uint8_t *MSC_BOT_Data = (uint8_t*)mempool __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN MSC_BOT_CBW_TypeDef MSC_BOT_cbw __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN MSC_BOT_CSW_TypeDef MSC_BOT_csw __ALIGN_END ; /** * @} */ /** @defgroup MSC_BOT_Private_FunctionPrototypes * @{ */ static void MSC_BOT_CBW_Decode (USB_OTG_CORE_HANDLE *pdev); static void MSC_BOT_SendData (USB_OTG_CORE_HANDLE *pdev, uint8_t* pbuf, uint16_t len); static void MSC_BOT_Abort(USB_OTG_CORE_HANDLE *pdev); /** * @} */ /** @defgroup MSC_BOT_Private_Functions * @{ */ /** * @brief MSC_BOT_Init * Initialize the BOT Process * @param pdev: device instance * @retval None */ void MSC_BOT_Init (USB_OTG_CORE_HANDLE *pdev) { MSC_BOT_State = BOT_IDLE; MSC_BOT_Status = BOT_STATE_NORMAL; USBD_STORAGE_fops->Init(0); DCD_EP_Flush(pdev, MSC_OUT_EP); DCD_EP_Flush(pdev, MSC_IN_EP); /* Prapare EP to Receive First BOT Cmd */ DCD_EP_PrepareRx (pdev, MSC_OUT_EP, (uint8_t *)&MSC_BOT_cbw, BOT_CBW_LENGTH); } /** * @brief MSC_BOT_Reset * Reset the BOT Machine * @param pdev: device instance * @retval None */ void MSC_BOT_Reset (USB_OTG_CORE_HANDLE *pdev) { MSC_BOT_State = BOT_IDLE; MSC_BOT_Status = BOT_STATE_RECOVERY; /* Prapare EP to Receive First BOT Cmd */ DCD_EP_PrepareRx (pdev, MSC_OUT_EP, (uint8_t *)&MSC_BOT_cbw, BOT_CBW_LENGTH); } /** * @brief MSC_BOT_DeInit * Uninitialize the BOT Machine * @param pdev: device instance * @retval None */ void MSC_BOT_DeInit (USB_OTG_CORE_HANDLE *pdev) { MSC_BOT_State = BOT_IDLE; } /** * @brief MSC_BOT_DataIn * Handle BOT IN data stage * @param pdev: device instance * @param epnum: endpoint index * @retval None */ void MSC_BOT_DataIn (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum) { switch (MSC_BOT_State) { case BOT_DATA_IN: if(SCSI_ProcessCmd(pdev, MSC_BOT_cbw.bLUN, &MSC_BOT_cbw.CB[0]) < 0) { MSC_BOT_SendCSW (pdev, CSW_CMD_FAILED); } break; case BOT_SEND_DATA: case BOT_LAST_DATA_IN: MSC_BOT_SendCSW (pdev, CSW_CMD_PASSED); break; default: break; } } /** * @brief MSC_BOT_DataOut * Proccess MSC OUT data * @param pdev: device instance * @param epnum: endpoint index * @retval None */ void MSC_BOT_DataOut (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum) { switch (MSC_BOT_State) { case BOT_IDLE: MSC_BOT_CBW_Decode(pdev); break; case BOT_DATA_OUT: if(SCSI_ProcessCmd(pdev, MSC_BOT_cbw.bLUN, &MSC_BOT_cbw.CB[0]) < 0) { MSC_BOT_SendCSW (pdev, CSW_CMD_FAILED); } break; default: break; } } /** * @brief MSC_BOT_CBW_Decode * Decode the CBW command and set the BOT state machine accordingtly * @param pdev: device instance * @retval None */ static void MSC_BOT_CBW_Decode (USB_OTG_CORE_HANDLE *pdev) { MSC_BOT_csw.dTag = MSC_BOT_cbw.dTag; MSC_BOT_csw.dDataResidue = MSC_BOT_cbw.dDataLength; if ((USBD_GetRxCount (pdev ,MSC_OUT_EP) != BOT_CBW_LENGTH) || (MSC_BOT_cbw.dSignature != BOT_CBW_SIGNATURE)|| (MSC_BOT_cbw.bLUN > 1) || (MSC_BOT_cbw.bCBLength < 1) || (MSC_BOT_cbw.bCBLength > 16)) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); MSC_BOT_Status = BOT_STATE_ERROR; MSC_BOT_Abort(pdev); } else { if(SCSI_ProcessCmd(pdev, MSC_BOT_cbw.bLUN, &MSC_BOT_cbw.CB[0]) < 0) { MSC_BOT_Abort(pdev); } /*Burst xfer handled internally*/ else if ((MSC_BOT_State != BOT_DATA_IN) && (MSC_BOT_State != BOT_DATA_OUT) && (MSC_BOT_State != BOT_LAST_DATA_IN)) { if (MSC_BOT_DataLen > 0) { MSC_BOT_SendData(pdev, MSC_BOT_Data, MSC_BOT_DataLen); } else if (MSC_BOT_DataLen == 0) { MSC_BOT_SendCSW (pdev, CSW_CMD_PASSED); } } } } /** * @brief MSC_BOT_SendData * Send the requested data * @param pdev: device instance * @param buf: pointer to data buffer * @param len: Data Length * @retval None */ static void MSC_BOT_SendData(USB_OTG_CORE_HANDLE *pdev, uint8_t* buf, uint16_t len) { len = MIN (MSC_BOT_cbw.dDataLength, len); MSC_BOT_csw.dDataResidue -= len; MSC_BOT_csw.bStatus = CSW_CMD_PASSED; MSC_BOT_State = BOT_SEND_DATA; DCD_EP_Tx (pdev, MSC_IN_EP, buf, len); } /** * @brief MSC_BOT_SendCSW * Send the Command Status Wrapper * @param pdev: device instance * @param status : CSW status * @retval None */ void MSC_BOT_SendCSW (USB_OTG_CORE_HANDLE *pdev, uint8_t CSW_Status) { MSC_BOT_csw.dSignature = BOT_CSW_SIGNATURE; MSC_BOT_csw.bStatus = CSW_Status; MSC_BOT_State = BOT_IDLE; DCD_EP_Tx (pdev, MSC_IN_EP, (uint8_t *)&MSC_BOT_csw, BOT_CSW_LENGTH); /* Prapare EP to Receive next Cmd */ DCD_EP_PrepareRx (pdev, MSC_OUT_EP, (uint8_t *)&MSC_BOT_cbw, BOT_CBW_LENGTH); } /** * @brief MSC_BOT_Abort * Abort the current transfer * @param pdev: device instance * @retval status */ static void MSC_BOT_Abort (USB_OTG_CORE_HANDLE *pdev) { if ((MSC_BOT_cbw.bmFlags == 0) && (MSC_BOT_cbw.dDataLength != 0) && (MSC_BOT_Status == BOT_STATE_NORMAL) ) { DCD_EP_Stall(pdev, MSC_OUT_EP ); } DCD_EP_Stall(pdev, MSC_IN_EP); if(MSC_BOT_Status == BOT_STATE_ERROR) { DCD_EP_PrepareRx (pdev, MSC_OUT_EP, (uint8_t *)&MSC_BOT_cbw, BOT_CBW_LENGTH); } } /** * @brief MSC_BOT_CplClrFeature * Complete the clear feature request * @param pdev: device instance * @param epnum: endpoint index * @retval None */ void MSC_BOT_CplClrFeature (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum) { if(MSC_BOT_Status == BOT_STATE_ERROR )/* Bad CBW Signature */ { DCD_EP_Stall(pdev, MSC_IN_EP); MSC_BOT_Status = BOT_STATE_NORMAL; } else if(((epnum & 0x80) == 0x80) && ( MSC_BOT_Status != BOT_STATE_RECOVERY)) { MSC_BOT_SendCSW (pdev, CSW_CMD_FAILED); } } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
C
lgpl
9,552
/** ****************************************************************************** * @file usbd_storage_template.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Memory management layer ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_mem.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Extern function prototypes ------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ #define STORAGE_LUN_NBR 1 int8_t STORAGE_Init (uint8_t lun); int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_size); int8_t STORAGE_IsReady (uint8_t lun); int8_t STORAGE_IsWriteProtected (uint8_t lun); int8_t STORAGE_Read (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); int8_t STORAGE_Write (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); int8_t STORAGE_GetMaxLun (void); /* USB Mass storage Standard Inquiry Data */ const int8_t STORAGE_Inquirydata[] = {//36 /* LUN 0 */ 0x00, 0x80, 0x02, 0x02, (USBD_STD_INQUIRY_LENGTH - 5), 0x00, 0x00, 0x00, 'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */ 'P', 'r', 'o', 'd', 'u', 't', ' ', ' ', /* Product : 16 Bytes */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '0', '.', '0' ,'1', /* Version : 4 Bytes */ }; USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops = { STORAGE_Init, STORAGE_GetCapacity, STORAGE_IsReady, STORAGE_IsWriteProtected, STORAGE_Read, STORAGE_Write, STORAGE_GetMaxLun, STORAGE_Inquirydata, }; USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops = &USBD_MICRO_SDIO_fops; /******************************************************************************* * Function Name : Read_Memory * Description : Handle the Read operation from the microSD card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int8_t STORAGE_Init (uint8_t lun) { return (0); } /******************************************************************************* * Function Name : Read_Memory * Description : Handle the Read operation from the STORAGE card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_size) { return (0); } /******************************************************************************* * Function Name : Read_Memory * Description : Handle the Read operation from the STORAGE card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int8_t STORAGE_IsReady (uint8_t lun) { return (0); } /******************************************************************************* * Function Name : Read_Memory * Description : Handle the Read operation from the STORAGE card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int8_t STORAGE_IsWriteProtected (uint8_t lun) { return 0; } /******************************************************************************* * Function Name : Read_Memory * Description : Handle the Read operation from the STORAGE card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int8_t STORAGE_Read (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { return 0; } /******************************************************************************* * Function Name : Write_Memory * Description : Handle the Write operation to the STORAGE card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int8_t STORAGE_Write (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { return (0); } /******************************************************************************* * Function Name : Write_Memory * Description : Handle the Write operation to the STORAGE card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int8_t STORAGE_GetMaxLun (void) { return (STORAGE_LUN_NBR - 1); } /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/src/usbd_storage_template.c
C
lgpl
6,383
/** ****************************************************************************** * @file usbd_msc_core.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides all the MSC core functions. * * @verbatim * * =================================================================== * MSC Class Description * =================================================================== * This module manages the MSC class V1.0 following the "Universal * Serial Bus Mass Storage Class (MSC) Bulk-Only Transport (BOT) Version 1.0 * Sep. 31, 1999". * This driver implements the following aspects of the specification: * - Bulk-Only Transport protocol * - Subclass : SCSI transparent command set (ref. SCSI Primary Commands - 3 (SPC-3)) * * @endverbatim * ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_mem.h" #include "usbd_msc_core.h" #include "usbd_msc_bot.h" #include "usbd_req.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup MSC_CORE * @brief Mass storage core module * @{ */ /** @defgroup MSC_CORE_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup MSC_CORE_Private_Defines * @{ */ /** * @} */ /** @defgroup MSC_CORE_Private_Macros * @{ */ /** * @} */ /** @defgroup MSC_CORE_Private_FunctionPrototypes * @{ */ uint8_t USBD_MSC_Init (void *pdev, uint8_t cfgidx); uint8_t USBD_MSC_DeInit (void *pdev, uint8_t cfgidx); uint8_t USBD_MSC_Setup (void *pdev, USB_SETUP_REQ *req); uint8_t USBD_MSC_DataIn (void *pdev, uint8_t epnum); uint8_t USBD_MSC_DataOut (void *pdev, uint8_t epnum); uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed, uint16_t *length); #ifdef USB_OTG_HS_CORE uint8_t *USBD_MSC_GetOtherCfgDesc (uint8_t speed, uint16_t *length); #endif uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ]; /** * @} */ /** @defgroup MSC_CORE_Private_Variables * @{ */ USBD_Class_cb_TypeDef USBD_MSC_cb = { USBD_MSC_Init, USBD_MSC_DeInit, USBD_MSC_Setup, NULL, /*EP0_TxSent*/ NULL, /*EP0_RxReady*/ USBD_MSC_DataIn, USBD_MSC_DataOut, NULL, /*SOF */ NULL, NULL, USBD_MSC_GetCfgDesc, #ifdef USB_OTG_HS_CORE USBD_MSC_GetOtherCfgDesc, #endif }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB Mass storage device Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ __ALIGN_BEGIN uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_MSC_CONFIG_DESC_SIZ, 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ 0xC0, /* bmAttributes: */ 0x32, /* MaxPower 100 mA */ /******************** Mass Storage interface ********************/ 0x09, /* bLength: Interface Descriptor size */ 0x04, /* bDescriptorType: */ 0x00, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x02, /* bNumEndpoints*/ 0x08, /* bInterfaceClass: MSC Class */ 0x06, /* bInterfaceSubClass : SCSI transparent*/ 0x50, /* nInterfaceProtocol */ 0x05, /* iInterface: */ /******************** Mass Storage Endpoints ********************/ 0x07, /*Endpoint descriptor length = 7*/ 0x05, /*Endpoint descriptor type */ MSC_IN_EP, /*Endpoint address (IN, address 1) */ 0x02, /*Bulk endpoint type */ LOBYTE(MSC_MAX_PACKET), HIBYTE(MSC_MAX_PACKET), 0x00, /*Polling interval in milliseconds */ 0x07, /*Endpoint descriptor length = 7 */ 0x05, /*Endpoint descriptor type */ MSC_OUT_EP, /*Endpoint address (OUT, address 1) */ 0x02, /*Bulk endpoint type */ LOBYTE(MSC_MAX_PACKET), HIBYTE(MSC_MAX_PACKET), 0x00 /*Polling interval in milliseconds*/ }; #ifdef USB_OTG_HS_CORE #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t USBD_MSC_OtherCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_MSC_CONFIG_DESC_SIZ, 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ 0xC0, /* bmAttributes: */ 0x32, /* MaxPower 100 mA */ /******************** Mass Storage interface ********************/ 0x09, /* bLength: Interface Descriptor size */ 0x04, /* bDescriptorType: */ 0x00, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x02, /* bNumEndpoints*/ 0x08, /* bInterfaceClass: MSC Class */ 0x06, /* bInterfaceSubClass : SCSI transparent command set*/ 0x50, /* nInterfaceProtocol */ 0x05, /* iInterface: */ /******************** Mass Storage Endpoints ********************/ 0x07, /*Endpoint descriptor length = 7*/ 0x05, /*Endpoint descriptor type */ MSC_IN_EP, /*Endpoint address (IN, address 1) */ 0x02, /*Bulk endpoint type */ 0x40, 0x00, 0x00, /*Polling interval in milliseconds */ 0x07, /*Endpoint descriptor length = 7 */ 0x05, /*Endpoint descriptor type */ MSC_OUT_EP, /*Endpoint address (OUT, address 1) */ 0x02, /*Bulk endpoint type */ 0x40, 0x00, 0x00 /*Polling interval in milliseconds*/ }; #endif #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static uint8_t USBD_MSC_MaxLun __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN static uint8_t USBD_MSC_AltSet __ALIGN_END = 0; /** * @} */ /** @defgroup MSC_CORE_Private_Functions * @{ */ /** * @brief USBD_MSC_Init * Initialize the mass storage configuration * @param pdev: device instance * @param cfgidx: configuration index * @retval status */ uint8_t USBD_MSC_Init (void *pdev, uint8_t cfgidx) { USBD_MSC_DeInit(pdev , cfgidx ); /* Open EP IN */ DCD_EP_Open(pdev, MSC_IN_EP, MSC_EPIN_SIZE, USB_OTG_EP_BULK); /* Open EP OUT */ DCD_EP_Open(pdev, MSC_OUT_EP, MSC_EPOUT_SIZE, USB_OTG_EP_BULK); /* Init the BOT layer */ MSC_BOT_Init(pdev); return USBD_OK; } /** * @brief USBD_MSC_DeInit * DeInitilaize the mass storage configuration * @param pdev: device instance * @param cfgidx: configuration index * @retval status */ uint8_t USBD_MSC_DeInit (void *pdev, uint8_t cfgidx) { /* Close MSC EPs */ DCD_EP_Close (pdev , MSC_IN_EP); DCD_EP_Close (pdev , MSC_OUT_EP); /* Un Init the BOT layer */ MSC_BOT_DeInit(pdev); return USBD_OK; } /** * @brief USBD_MSC_Setup * Handle the MSC specific requests * @param pdev: device instance * @param req: USB request * @retval status */ uint8_t USBD_MSC_Setup (void *pdev, USB_SETUP_REQ *req) { switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* Class request */ case USB_REQ_TYPE_CLASS : switch (req->bRequest) { case BOT_GET_MAX_LUN : if((req->wValue == 0) && (req->wLength == 1) && ((req->bmRequest & 0x80) == 0x80)) { USBD_MSC_MaxLun = USBD_STORAGE_fops->GetMaxLun(); if(USBD_MSC_MaxLun > 0) { USBD_CtlSendData (pdev, &USBD_MSC_MaxLun, 1); } else { USBD_CtlError(pdev , req); return USBD_FAIL; } } else { USBD_CtlError(pdev , req); return USBD_FAIL; } break; case BOT_RESET : if((req->wValue == 0) && (req->wLength == 0) && ((req->bmRequest & 0x80) != 0x80)) { MSC_BOT_Reset(pdev); } else { USBD_CtlError(pdev , req); return USBD_FAIL; } break; default: USBD_CtlError(pdev , req); return USBD_FAIL; } break; /* Interface & Endpoint request */ case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, &USBD_MSC_AltSet, 1); break; case USB_REQ_SET_INTERFACE : USBD_MSC_AltSet = (uint8_t)(req->wValue); break; case USB_REQ_CLEAR_FEATURE: /* Flush the FIFO and Clear the stall status */ DCD_EP_Flush(pdev, (uint8_t)req->wIndex); /* Re-activate the EP */ DCD_EP_Close (pdev , (uint8_t)req->wIndex); if((((uint8_t)req->wIndex) & 0x80) == 0x80) { DCD_EP_Open(pdev, ((uint8_t)req->wIndex), MSC_EPIN_SIZE, USB_OTG_EP_BULK); } else { DCD_EP_Open(pdev, ((uint8_t)req->wIndex), MSC_EPOUT_SIZE, USB_OTG_EP_BULK); } /* Handle BOT error */ MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex); break; } break; default: break; } return USBD_OK; } /** * @brief USBD_MSC_DataIn * handle data IN Stage * @param pdev: device instance * @param epnum: endpoint index * @retval status */ uint8_t USBD_MSC_DataIn (void *pdev, uint8_t epnum) { MSC_BOT_DataIn(pdev , epnum); return USBD_OK; } /** * @brief USBD_MSC_DataOut * handle data OUT Stage * @param pdev: device instance * @param epnum: endpoint index * @retval status */ uint8_t USBD_MSC_DataOut (void *pdev, uint8_t epnum) { MSC_BOT_DataOut(pdev , epnum); return USBD_OK; } /** * @brief USBD_MSC_GetCfgDesc * return configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (USBD_MSC_CfgDesc); return USBD_MSC_CfgDesc; } /** * @brief USBD_MSC_GetOtherCfgDesc * return other speed configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ #ifdef USB_OTG_HS_CORE uint8_t *USBD_MSC_GetOtherCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (USBD_MSC_OtherCfgDesc); return USBD_MSC_OtherCfgDesc; } #endif /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
C
lgpl
12,932
/** ****************************************************************************** * @file usbd_msc_core.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header for the usbd_msc_core.c file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef _USB_MSC_CORE_H_ #define _USB_MSC_CORE_H_ #include "usbd_ioreq.h" /** @addtogroup USBD_MSC_BOT * @{ */ /** @defgroup USBD_MSC * @brief This file is the Header file for USBD_msc.c * @{ */ /** @defgroup USBD_BOT_Exported_Defines * @{ */ #define BOT_GET_MAX_LUN 0xFE #define BOT_RESET 0xFF #define USB_MSC_CONFIG_DESC_SIZ 32 #define MSC_EPIN_SIZE *(uint16_t *)(((USB_OTG_CORE_HANDLE *)pdev)->dev.pConfig_descriptor + 22) #define MSC_EPOUT_SIZE *(uint16_t *)(((USB_OTG_CORE_HANDLE *)pdev)->dev.pConfig_descriptor + 29) /** * @} */ /** @defgroup USB_CORE_Exported_Types * @{ */ extern USBD_Class_cb_TypeDef USBD_MSC_cb; /** * @} */ /** * @} */ #endif // _USB_MSC_CORE_H_ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h
C
lgpl
2,002
/** ****************************************************************************** * @file usbd_msc_scsi.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header for the usbd_msc_scsi.c file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_MSC_SCSI_H #define __USBD_MSC_SCSI_H /* Includes ------------------------------------------------------------------*/ #include "usbd_def.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_SCSI * @brief header file for the storage disk file * @{ */ /** @defgroup USBD_SCSI_Exported_Defines * @{ */ #define SENSE_LIST_DEEPTH 4 /* SCSI Commands */ #define SCSI_FORMAT_UNIT 0x04 #define SCSI_INQUIRY 0x12 #define SCSI_MODE_SELECT6 0x15 #define SCSI_MODE_SELECT10 0x55 #define SCSI_MODE_SENSE6 0x1A #define SCSI_MODE_SENSE10 0x5A #define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E #define SCSI_READ6 0x08 #define SCSI_READ10 0x28 #define SCSI_READ12 0xA8 #define SCSI_READ16 0x88 #define SCSI_READ_CAPACITY10 0x25 #define SCSI_READ_CAPACITY16 0x9E #define SCSI_REQUEST_SENSE 0x03 #define SCSI_START_STOP_UNIT 0x1B #define SCSI_TEST_UNIT_READY 0x00 #define SCSI_WRITE6 0x0A #define SCSI_WRITE10 0x2A #define SCSI_WRITE12 0xAA #define SCSI_WRITE16 0x8A #define SCSI_VERIFY10 0x2F #define SCSI_VERIFY12 0xAF #define SCSI_VERIFY16 0x8F #define SCSI_SEND_DIAGNOSTIC 0x1D #define SCSI_READ_FORMAT_CAPACITIES 0x23 #define NO_SENSE 0 #define RECOVERED_ERROR 1 #define NOT_READY 2 #define MEDIUM_ERROR 3 #define HARDWARE_ERROR 4 #define ILLEGAL_REQUEST 5 #define UNIT_ATTENTION 6 #define DATA_PROTECT 7 #define BLANK_CHECK 8 #define VENDOR_SPECIFIC 9 #define COPY_ABORTED 10 #define ABORTED_COMMAND 11 #define VOLUME_OVERFLOW 13 #define MISCOMPARE 14 #define INVALID_CDB 0x20 #define INVALID_FIELED_IN_COMMAND 0x24 #define PARAMETER_LIST_LENGTH_ERROR 0x1A #define INVALID_FIELD_IN_PARAMETER_LIST 0x26 #define ADDRESS_OUT_OF_RANGE 0x21 #define MEDIUM_NOT_PRESENT 0x3A #define MEDIUM_HAVE_CHANGED 0x28 #define WRITE_PROTECTED 0x27 #define UNRECOVERED_READ_ERROR 0x11 #define WRITE_FAULT 0x03 #define READ_FORMAT_CAPACITY_DATA_LEN 0x0C #define READ_CAPACITY10_DATA_LEN 0x08 #define MODE_SENSE10_DATA_LEN 0x08 #define MODE_SENSE6_DATA_LEN 0x04 #define REQUEST_SENSE_DATA_LEN 0x12 #define STANDARD_INQUIRY_DATA_LEN 0x24 #define BLKVFY 0x04 extern uint8_t Page00_Inquiry_Data[]; extern uint8_t Standard_Inquiry_Data[]; extern uint8_t Standard_Inquiry_Data2[]; extern uint8_t Mode_Sense6_data[]; extern uint8_t Mode_Sense10_data[]; extern uint8_t Scsi_Sense_Data[]; extern uint8_t ReadCapacity10_Data[]; extern uint8_t ReadFormatCapacity_Data []; /** * @} */ /** @defgroup USBD_SCSI_Exported_TypesDefinitions * @{ */ typedef struct _SENSE_ITEM { char Skey; union { struct _ASCs { char ASC; char ASCQ; }b; unsigned int ASC; char *pData; } w; } SCSI_Sense_TypeDef; /** * @} */ /** @defgroup USBD_SCSI_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_SCSI_Exported_Variables * @{ */ extern SCSI_Sense_TypeDef SCSI_Sense [SENSE_LIST_DEEPTH]; extern uint8_t SCSI_Sense_Head; extern uint8_t SCSI_Sense_Tail; /** * @} */ /** @defgroup USBD_SCSI_Exported_FunctionsPrototype * @{ */ int8_t SCSI_ProcessCmd(USB_OTG_CORE_HANDLE *pdev, uint8_t lun, uint8_t *cmd); void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC); /** * @} */ #endif /* __USBD_MSC_SCSI_H */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_scsi.h
C
lgpl
6,172
/** ****************************************************************************** * @file usbd_msc_mem.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header for the STORAGE DISK file file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_MEM_H #define __USBD_MEM_H /* Includes ------------------------------------------------------------------*/ #include "usbd_def.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_MEM * @brief header file for the storage disk file * @{ */ /** @defgroup USBD_MEM_Exported_Defines * @{ */ #define USBD_STD_INQUIRY_LENGTH 36 /** * @} */ /** @defgroup USBD_MEM_Exported_TypesDefinitions * @{ */ typedef struct _USBD_STORAGE { int8_t (* Init) (uint8_t lun); int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size); int8_t (* IsReady) (uint8_t lun); int8_t (* IsWriteProtected) (uint8_t lun); int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); int8_t (* GetMaxLun)(void); const int8_t *pInquiry; }USBD_STORAGE_cb_TypeDef; /** * @} */ /** @defgroup USBD_MEM_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_MEM_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBD_MEM_Exported_FunctionsPrototype * @{ */ extern USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops; /** * @} */ #endif /* __USBD_MEM_H */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_mem.h
C
lgpl
2,561
/** ****************************************************************************** * @file usbd_msc_data.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header for the usbd_msc_data.c file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef _USBD_MSC_DATA_H_ #define _USBD_MSC_DATA_H_ /* Includes ------------------------------------------------------------------*/ #include "usbd_conf.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USB_INFO * @brief general defines for the usb device library file * @{ */ /** @defgroup USB_INFO_Exported_Defines * @{ */ #define MODE_SENSE6_LEN 8 #define MODE_SENSE10_LEN 8 #define LENGTH_INQUIRY_PAGE00 7 #define LENGTH_FORMAT_CAPACITIES 20 /** * @} */ /** @defgroup USBD_INFO_Exported_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_INFO_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_INFO_Exported_Variables * @{ */ extern const uint8_t MSC_Page00_Inquiry_Data[]; extern const uint8_t MSC_Mode_Sense6_data[]; extern const uint8_t MSC_Mode_Sense10_data[] ; /** * @} */ /** @defgroup USBD_INFO_Exported_FunctionsPrototype * @{ */ /** * @} */ #endif /* _USBD_MSC_DATA_H_ */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_data.h
C
lgpl
2,273
/** ****************************************************************************** * @file usbd_msc_bot.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header for the usbd_msc_bot.c file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #include "usbd_core.h" /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_MSC_BOT_H #define __USBD_MSC_BOT_H /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup MSC_BOT * @brief This file is the Header file for usbd_bot.c * @{ */ /** @defgroup USBD_CORE_Exported_Defines * @{ */ #define BOT_IDLE 0 /* Idle state */ #define BOT_DATA_OUT 1 /* Data Out state */ #define BOT_DATA_IN 2 /* Data In state */ #define BOT_LAST_DATA_IN 3 /* Last Data In Last */ #define BOT_SEND_DATA 4 /* Send Immediate data */ #define BOT_CBW_SIGNATURE 0x43425355 #define BOT_CSW_SIGNATURE 0x53425355 #define BOT_CBW_LENGTH 31 #define BOT_CSW_LENGTH 13 /* CSW Status Definitions */ #define CSW_CMD_PASSED 0x00 #define CSW_CMD_FAILED 0x01 #define CSW_PHASE_ERROR 0x02 /* BOT Status */ #define BOT_STATE_NORMAL 0 #define BOT_STATE_RECOVERY 1 #define BOT_STATE_ERROR 2 #define DIR_IN 0 #define DIR_OUT 1 #define BOTH_DIR 2 /** * @} */ /** @defgroup MSC_CORE_Private_TypesDefinitions * @{ */ typedef struct _MSC_BOT_CBW { uint32_t dSignature; uint32_t dTag; uint32_t dDataLength; uint8_t bmFlags; uint8_t bLUN; uint8_t bCBLength; uint8_t CB[16]; } MSC_BOT_CBW_TypeDef; typedef struct _MSC_BOT_CSW { uint32_t dSignature; uint32_t dTag; uint32_t dDataResidue; uint8_t bStatus; } MSC_BOT_CSW_TypeDef; /** * @} */ /** @defgroup USBD_CORE_Exported_Types * @{ */ extern uint8_t *MSC_BOT_Data; extern uint16_t MSC_BOT_DataLen; extern uint8_t MSC_BOT_State; extern uint8_t MSC_BOT_BurstMode; extern MSC_BOT_CBW_TypeDef MSC_BOT_cbw; extern MSC_BOT_CSW_TypeDef MSC_BOT_csw; /** * @} */ /** @defgroup USBD_CORE_Exported_FunctionsPrototypes * @{ */ void MSC_BOT_Init (USB_OTG_CORE_HANDLE *pdev); void MSC_BOT_Reset (USB_OTG_CORE_HANDLE *pdev); void MSC_BOT_DeInit (USB_OTG_CORE_HANDLE *pdev); void MSC_BOT_DataIn (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum); void MSC_BOT_DataOut (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum); void MSC_BOT_SendCSW (USB_OTG_CORE_HANDLE *pdev, uint8_t CSW_Status); void MSC_BOT_CplClrFeature (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum); /** * @} */ #endif /* __USBD_MSC_BOT_H */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_bot.h
C
lgpl
4,021
/** ****************************************************************************** * @file usbd_dfu_mal.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Generic media access Layer. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_dfu_mal.h" #include "usbd_flash_if.h" #ifdef DFU_MAL_SUPPORT_OTP #include "usbd_otp_if.h" #endif #ifdef DFU_MAL_SUPPORT_MEM #include "usbd_mem_if_template.h" #endif /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Global Memories callback and string descriptors reference tables. To add a new memory, modify the value of MAX_USED_MEDIA in usbd_dfu_mal.h and add the pointer to the callback structure in this table. Then add the pointer to the memory string descriptor in usbd_dfu_StringDesc table. No other operation is required. */ DFU_MAL_Prop_TypeDef* tMALTab[MAX_USED_MEDIA] = { &DFU_Flash_cb #ifdef DFU_MAL_SUPPORT_OTP , &DFU_Otp_cb #endif #ifdef DFU_MAL_SUPPORT_MEM , &DFU_Mem_cb #endif }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN const uint8_t* usbd_dfu_StringDesc[MAX_USED_MEDIA] __ALIGN_END = { FLASH_IF_STRING #ifdef DFU_MAL_SUPPORT_OTP , OTP_IF_STRING #endif #ifdef DFU_MAL_SUPPORT_MEM , MEM_IF_STRING #endif }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* RAM Buffer for Downloaded Data */ __ALIGN_BEGIN uint8_t MAL_Buffer[XFERSIZE] __ALIGN_END ; /* Private function prototypes -----------------------------------------------*/ static uint8_t MAL_CheckAdd (uint32_t Add); /* Private functions ---------------------------------------------------------*/ /** * @brief MAL_Init * Initializes the Media on the STM32 * @param None * @retval Result of the opeartion (MAL_OK in all cases) */ uint16_t MAL_Init(void) { uint32_t memIdx = 0; /* Init all supported memories */ for(memIdx = 0; memIdx < MAX_USED_MEDIA; memIdx++) { /* If the check addres is positive, exit with the memory index */ if (tMALTab[memIdx]->pMAL_Init != NULL) { tMALTab[memIdx]->pMAL_Init(); } } return MAL_OK; } /** * @brief MAL_DeInit * DeInitializes the Media on the STM32 * @param None * @retval Result of the opeartion (MAL_OK in all cases) */ uint16_t MAL_DeInit(void) { uint32_t memIdx = 0; /* Init all supported memories */ for(memIdx = 0; memIdx < MAX_USED_MEDIA; memIdx++) { /* Check if the command is supported */ if (tMALTab[memIdx]->pMAL_DeInit != NULL) { tMALTab[memIdx]->pMAL_DeInit(); } } return MAL_OK; } /** * @brief MAL_Erase * Erase a sector of memory. * @param Add: Sector address/code * @retval Result of the opeartion: MAL_OK if all operations are OK else MAL_FAIL */ uint16_t MAL_Erase(uint32_t Add) { uint32_t memIdx = MAL_CheckAdd(Add); /* Check if the area is protected */ if (DFU_MAL_IS_PROTECTED_AREA(Add)) { return MAL_FAIL; } if (memIdx < MAX_USED_MEDIA) { /* Check if the command is supported */ if (tMALTab[memIdx]->pMAL_Erase != NULL) { return tMALTab[memIdx]->pMAL_Erase(Add); } else { return MAL_FAIL; } } else { return MAL_FAIL; } } /** * @brief MAL_Write * Write sectors of memory. * @param Add: Sector address/code * @param Len: Number of data to be written (in bytes) * @retval Result of the opeartion: MAL_OK if all operations are OK else MAL_FAIL */ uint16_t MAL_Write (uint32_t Add, uint32_t Len) { uint32_t memIdx = MAL_CheckAdd(Add); /* Check if the area is protected */ if (DFU_MAL_IS_PROTECTED_AREA(Add)) { return MAL_FAIL; } if (memIdx < MAX_USED_MEDIA) { /* Check if the command is supported */ if (tMALTab[memIdx]->pMAL_Write != NULL) { return tMALTab[memIdx]->pMAL_Write(Add, Len); } else { return MAL_FAIL; } } else { return MAL_FAIL; } } /** * @brief MAL_Read * Read sectors of memory. * @param Add: Sector address/code * @param Len: Number of data to be written (in bytes) * @retval Buffer pointer */ uint8_t *MAL_Read (uint32_t Add, uint32_t Len) { uint32_t memIdx = MAL_CheckAdd(Add); if (memIdx < MAX_USED_MEDIA) { /* Check if the command is supported */ if (tMALTab[memIdx]->pMAL_Read != NULL) { return tMALTab[memIdx]->pMAL_Read(Add, Len); } else { return MAL_Buffer; } } else { return MAL_Buffer; } } /** * @brief MAL_GetStatus * Get the status of a given memory. * @param Add: Sector address/code (allow to determine which memory will be addressed) * @param Cmd: 0 for erase and 1 for write * @param buffer: pointer to the buffer where the status data will be stored. * @retval Buffer pointer */ uint16_t MAL_GetStatus(uint32_t Add , uint8_t Cmd, uint8_t *buffer) { uint32_t memIdx = MAL_CheckAdd(Add); if (memIdx < MAX_USED_MEDIA) { if (Cmd & 0x01) { SET_POLLING_TIMING(tMALTab[memIdx]->EraseTiming); } else { SET_POLLING_TIMING(tMALTab[memIdx]->WriteTiming); } return MAL_OK; } else { return MAL_FAIL; } } /** * @brief MAL_CheckAdd * Determine which memory should be managed. * @param Add: Sector address/code (allow to determine which memory will be addressed) * @retval Index of the addressed memory. */ static uint8_t MAL_CheckAdd(uint32_t Add) { uint32_t memIdx = 0; /* Check with all supported memories */ for(memIdx = 0; memIdx < MAX_USED_MEDIA; memIdx++) { /* If the check addres is positive, exit with the memory index */ if (tMALTab[memIdx]->pMAL_CheckAdd(Add) == MAL_OK) { return memIdx; } } /* If no memory found, return MAX_USED_MEDIA */ return (MAX_USED_MEDIA); } /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/src/usbd_dfu_mal.c
C
lgpl
7,512
/** ****************************************************************************** * @file usbd_dfu_core.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides the high layer firmware functions to manage the * following functionalities of the USB DFU Class: * - Initialization and Configuration of high and low layer * - Enumeration as DFU Device (and enumeration for each implemented memory interface) * - Transfers to/from memory interfaces * - Easy-to-customize "plug-in-like" modules for adding/removing memory interfaces. * - Error management * * @verbatim * * =================================================================== * DFU Class Driver Description * =================================================================== * This driver manages the DFU class V1.1 following the "Device Class Specification for * Device Firmware Upgrade Version 1.1 Aug 5, 2004". * This driver implements the following aspects of the specification: * - Device descriptor management * - Configuration descriptor management * - Enumeration as DFU device (in DFU mode only) * - Requests management (supporting ST DFU sub-protocol) * - Memory operations management (Download/Upload/Erase/Detach/GetState/GetStatus) * - DFU state machine implementation. * * @note * ST DFU sub-protocol is compliant with DFU protocol and use sub-requests to manage * memory addressing, commands processing, specific memories operations (ie. Erase) ... * As required by the DFU specification, only endpoint 0 is used in this application. * Other endpoints and functions may be added to the application (ie. DFU ...) * * These aspects may be enriched or modified for a specific user application. * * This driver doesn't implement the following aspects of the specification * (but it is possible to manage these features with some modifications on this driver): * - Manifestation Tolerant mode * * @endverbatim * ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_dfu_core.h" #include "usbd_desc.h" #include "usbd_req.h" #include "usb_bsp.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_dfu * @brief usbd core module * @{ */ /** @defgroup usbd_dfu_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup usbd_dfu_Private_Defines * @{ */ /** * @} */ /** @defgroup usbd_dfu_Private_Macros * @{ */ /** * @} */ /** @defgroup usbd_dfu_Private_FunctionPrototypes * @{ */ /********************************************* DFU Device library callbacks *********************************************/ static uint8_t usbd_dfu_Init (void *pdev, uint8_t cfgidx); static uint8_t usbd_dfu_DeInit (void *pdev, uint8_t cfgidx); static uint8_t usbd_dfu_Setup (void *pdev, USB_SETUP_REQ *req); static uint8_t EP0_TxSent (void *pdev); static uint8_t EP0_RxReady (void *pdev); static uint8_t *USBD_DFU_GetCfgDesc (uint8_t speed, uint16_t *length); #ifdef USB_OTG_HS_CORE static uint8_t *USBD_DFU_GetOtherCfgDesc (uint8_t speed, uint16_t *length); #endif static uint8_t* USBD_DFU_GetUsrStringDesc (uint8_t speed, uint8_t index , uint16_t *length); /********************************************* DFU Requests management functions *********************************************/ static void DFU_Req_DETACH (void *pdev, USB_SETUP_REQ *req); static void DFU_Req_DNLOAD (void *pdev, USB_SETUP_REQ *req); static void DFU_Req_UPLOAD (void *pdev, USB_SETUP_REQ *req); static void DFU_Req_GETSTATUS (void *pdev); static void DFU_Req_CLRSTATUS (void *pdev); static void DFU_Req_GETSTATE (void *pdev); static void DFU_Req_ABORT (void *pdev); static void DFU_LeaveDFUMode (void *pdev); /** * @} */ /** @defgroup usbd_dfu_Private_Variables * @{ */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_dfu_OtherCfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END ; /* The list of Interface String descriptor pointers is defined in usbd_dfu_mal.c file. This list can be updated whenever a memory has to be added or removed */ extern const uint8_t* usbd_dfu_StringDesc[]; /* State Machine variables */ uint8_t DeviceState; uint8_t DeviceStatus[6]; uint32_t Manifest_State = Manifest_complete; /* Data Management variables */ static uint32_t wBlockNum = 0, wlength = 0; static uint32_t Pointer = APP_DEFAULT_ADD; /* Base Address to Erase, Program or Read */ static __IO uint32_t usbd_dfu_AltSet = 0; extern uint8_t MAL_Buffer[]; /* DFU interface class callbacks structure */ USBD_Class_cb_TypeDef DFU_cb = { usbd_dfu_Init, usbd_dfu_DeInit, usbd_dfu_Setup, EP0_TxSent, EP0_RxReady, NULL, /* DataIn, */ NULL, /* DataOut, */ NULL, /*SOF */ NULL, NULL, USBD_DFU_GetCfgDesc, #ifdef USB_OTG_HS_CORE USBD_DFU_GetOtherCfgDesc, /* use same cobfig as per FS */ #endif USBD_DFU_GetUsrStringDesc, }; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB DFU device Configuration Descriptor */ __ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ USB_DFU_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /*bNumInterfaces: 1 interface*/ 0x01, /*bConfigurationValue: Configuration value*/ 0x02, /*iConfiguration: Index of string descriptor describing the configuration*/ 0xC0, /*bmAttributes: bus powered and Supprts Remote Wakeup */ 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/ /* 09 */ /********** Descriptor of DFU interface 0 Alternate setting 0 **************/ USBD_DFU_IF_DESC(0), /* This interface is mandatory for all devices */ #if (USBD_ITF_MAX_NUM > 1) /********** Descriptor of DFU interface 0 Alternate setting 1 **************/ USBD_DFU_IF_DESC(1), #endif /* (USBD_ITF_MAX_NUM > 1) */ #if (USBD_ITF_MAX_NUM > 2) /********** Descriptor of DFU interface 0 Alternate setting 2 **************/ USBD_DFU_IF_DESC(2), #endif /* (USBD_ITF_MAX_NUM > 2) */ #if (USBD_ITF_MAX_NUM > 3) /********** Descriptor of DFU interface 0 Alternate setting 3 **************/ USBD_DFU_IF_DESC(3), #endif /* (USBD_ITF_MAX_NUM > 3) */ #if (USBD_ITF_MAX_NUM > 4) /********** Descriptor of DFU interface 0 Alternate setting 4 **************/ USBD_DFU_IF_DESC(4), #endif /* (USBD_ITF_MAX_NUM > 4) */ #if (USBD_ITF_MAX_NUM > 5) /********** Descriptor of DFU interface 0 Alternate setting 5 **************/ USBD_DFU_IF_DESC(5), #endif /* (USBD_ITF_MAX_NUM > 5) */ #if (USBD_ITF_MAX_NUM > 6) #error "ERROR: usbd_dfu_core.c: Modify the file to support more descriptors!" #endif /* (USBD_ITF_MAX_NUM > 6) */ /******************** DFU Functional Descriptor********************/ 0x09, /*blength = 9 Bytes*/ DFU_DESCRIPTOR_TYPE, /* DFU Functional Descriptor*/ 0x0B, /*bmAttribute bitCanDnload = 1 (bit 0) bitCanUpload = 1 (bit 1) bitManifestationTolerant = 0 (bit 2) bitWillDetach = 1 (bit 3) Reserved (bit4-6) bitAcceleratedST = 0 (bit 7)*/ 0xFF, /*DetachTimeOut= 255 ms*/ 0x00, /*WARNING: In DMA mode the multiple MPS packets feature is still not supported ==> In this case, when using DMA XFERSIZE should be set to 64 in usbd_conf.h */ TRANSFER_SIZE_BYTES(XFERSIZE), /* TransferSize = 1024 Byte*/ 0x1A, /* bcdDFUVersion*/ 0x01 /***********************************************************/ /* 9*/ } ; #ifdef USE_USB_OTG_HS #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t usbd_dfu_OtherCfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */ USB_DFU_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /*bNumInterfaces: 1 interface*/ 0x01, /*bConfigurationValue: Configuration value*/ 0x02, /*iConfiguration: Index of string descriptor describing the configuration*/ 0xC0, /*bmAttributes: bus powered and Supprts Remote Wakeup */ 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/ /* 09 */ /********** Descriptor of DFU interface 0 Alternate setting 0 **************/ USBD_DFU_IF_DESC(0), /* This interface is mandatory for all devices */ #if (USBD_ITF_MAX_NUM > 1) /********** Descriptor of DFU interface 0 Alternate setting 1 **************/ USBD_DFU_IF_DESC(1), #endif /* (USBD_ITF_MAX_NUM > 1) */ #if (USBD_ITF_MAX_NUM > 2) /********** Descriptor of DFU interface 0 Alternate setting 2 **************/ USBD_DFU_IF_DESC(2), #endif /* (USBD_ITF_MAX_NUM > 2) */ #if (USBD_ITF_MAX_NUM > 3) /********** Descriptor of DFU interface 0 Alternate setting 3 **************/ USBD_DFU_IF_DESC(3), #endif /* (USBD_ITF_MAX_NUM > 3) */ #if (USBD_ITF_MAX_NUM > 4) /********** Descriptor of DFU interface 0 Alternate setting 4 **************/ USBD_DFU_IF_DESC(4), #endif /* (USBD_ITF_MAX_NUM > 4) */ #if (USBD_ITF_MAX_NUM > 5) /********** Descriptor of DFU interface 0 Alternate setting 5 **************/ USBD_DFU_IF_DESC(5), #endif /* (USBD_ITF_MAX_NUM > 5) */ #if (USBD_ITF_MAX_NUM > 6) #error "ERROR: usbd_dfu_core.c: Modify the file to support more descriptors!" #endif /* (USBD_ITF_MAX_NUM > 6) */ /******************** DFU Functional Descriptor********************/ 0x09, /*blength = 9 Bytes*/ DFU_DESCRIPTOR_TYPE, /* DFU Functional Descriptor*/ 0x0B, /*bmAttribute bitCanDnload = 1 (bit 0) bitCanUpload = 1 (bit 1) bitManifestationTolerant = 0 (bit 2) bitWillDetach = 1 (bit 3) Reserved (bit4-6) bitAcceleratedST = 0 (bit 7)*/ 0xFF, /*DetachTimeOut= 255 ms*/ 0x00, /*WARNING: In DMA mode the multiple MPS packets feature is still not supported ==> In this case, when using DMA XFERSIZE should be set to 64 in usbd_conf.h */ TRANSFER_SIZE_BYTES(XFERSIZE), /* TransferSize = 1024 Byte*/ 0x1A, /* bcdDFUVersion*/ 0x01 /***********************************************************/ /* 9*/ }; #endif /* USE_USB_OTG_HS */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif __ALIGN_BEGIN static uint8_t usbd_dfu_Desc[USB_DFU_DESC_SIZ] __ALIGN_END = { 0x09, /*blength = 9 Bytes*/ DFU_DESCRIPTOR_TYPE, /* DFU Functional Descriptor*/ 0x0B, /*bmAttribute bitCanDnload = 1 (bit 0) bitCanUpload = 1 (bit 1) bitManifestationTolerant = 0 (bit 2) bitWillDetach = 1 (bit 3) Reserved (bit4-6) bitAcceleratedST = 0 (bit 7)*/ 0xFF, /*DetachTimeOut= 255 ms*/ 0x00, /*WARNING: In DMA mode the multiple MPS packets feature is still not supported ==> In this case, when using DMA XFERSIZE should be set to 64 in usbd_conf.h */ TRANSFER_SIZE_BYTES(XFERSIZE), /* TransferSize = 1024 Byte*/ 0x1A, /* bcdDFUVersion*/ 0x01 }; #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /** * @} */ /** @defgroup usbd_dfu_Private_Functions * @{ */ /** * @brief usbd_dfu_Init * Initializes the DFU interface. * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t usbd_dfu_Init (void *pdev, uint8_t cfgidx) { /* Initilialize the MAL(Media Access Layer) */ MAL_Init(); /* Initialize the state of the DFU interface */ DeviceState = STATE_dfuIDLE; DeviceStatus[0] = STATUS_OK; DeviceStatus[4] = DeviceState; return USBD_OK; } /** * @brief usbd_dfu_Init * De-initializes the DFU layer. * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t usbd_dfu_DeInit (void *pdev, uint8_t cfgidx) { /* Restore default state */ DeviceState = STATE_dfuIDLE; DeviceStatus[0] = STATUS_OK; DeviceStatus[4] = DeviceState; wBlockNum = 0; wlength = 0; /* DeInitilialize the MAL(Media Access Layer) */ MAL_DeInit(); return USBD_OK; } /** * @brief usbd_dfu_Setup * Handles the DFU request parsing. * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t usbd_dfu_Setup (void *pdev, USB_SETUP_REQ *req) { uint16_t len = 0; uint8_t *pbuf = NULL; switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* DFU Class Requests -------------------------------*/ case USB_REQ_TYPE_CLASS : switch (req->bRequest) { case DFU_DNLOAD: DFU_Req_DNLOAD(pdev, req); break; case DFU_UPLOAD: DFU_Req_UPLOAD(pdev, req); break; case DFU_GETSTATUS: DFU_Req_GETSTATUS(pdev); break; case DFU_CLRSTATUS: DFU_Req_CLRSTATUS(pdev); break; case DFU_GETSTATE: DFU_Req_GETSTATE(pdev); break; case DFU_ABORT: DFU_Req_ABORT(pdev); break; case DFU_DETACH: DFU_Req_DETACH(pdev, req); break; default: USBD_CtlError (pdev, req); return USBD_FAIL; } break; /* Standard Requests -------------------------------*/ case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_DESCRIPTOR: if( (req->wValue >> 8) == DFU_DESCRIPTOR_TYPE) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED pbuf = usbd_dfu_Desc; #else pbuf = usbd_dfu_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM); #endif len = MIN(USB_DFU_DESC_SIZ , req->wLength); } USBD_CtlSendData (pdev, pbuf, len); break; case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, (uint8_t *)&usbd_dfu_AltSet, 1); break; case USB_REQ_SET_INTERFACE : if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM) { usbd_dfu_AltSet = (uint8_t)(req->wValue); } else { /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } break; } } return USBD_OK; } /** * @brief EP0_TxSent * Handles the DFU control endpoint data IN stage. * @param pdev: device instance * @retval status */ static uint8_t EP0_TxSent (void *pdev) { uint32_t Addr; USB_SETUP_REQ req; if (DeviceState == STATE_dfuDNBUSY) { /* Decode the Special Command*/ if (wBlockNum == 0) { if ((MAL_Buffer[0] == CMD_GETCOMMANDS) && (wlength == 1)) {} else if (( MAL_Buffer[0] == CMD_SETADDRESSPOINTER ) && (wlength == 5)) { Pointer = MAL_Buffer[1]; Pointer += MAL_Buffer[2] << 8; Pointer += MAL_Buffer[3] << 16; Pointer += MAL_Buffer[4] << 24; } else if (( MAL_Buffer[0] == CMD_ERASE ) && (wlength == 5)) { Pointer = MAL_Buffer[1]; Pointer += MAL_Buffer[2] << 8; Pointer += MAL_Buffer[3] << 16; Pointer += MAL_Buffer[4] << 24; MAL_Erase(Pointer); } else { /* Reset the global length and block number */ wlength = 0; wBlockNum = 0; /* Call the error management function (command will be nacked) */ req.bmRequest = 0; req.wLength = 1; USBD_CtlError (pdev, &req); } } /* Regular Download Command */ else if (wBlockNum > 1) { /* Decode the required address */ Addr = ((wBlockNum - 2) * XFERSIZE) + Pointer; /* Preform the write operation */ MAL_Write(Addr, wlength); } /* Reset the global lenght and block number */ wlength = 0; wBlockNum = 0; /* Update the state machine */ DeviceState = STATE_dfuDNLOAD_SYNC; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; return USBD_OK; } else if (DeviceState == STATE_dfuMANIFEST)/* Manifestation in progress*/ { /* Start leaving DFU mode */ DFU_LeaveDFUMode(pdev); } return USBD_OK; } /** * @brief EP0_RxReady * Handles the DFU control endpoint data OUT stage. * @param pdev: device instance * @retval status */ static uint8_t EP0_RxReady (void *pdev) { return USBD_OK; } /****************************************************************************** DFU Class requests management ******************************************************************************/ /** * @brief DFU_Req_DETACH * Handles the DFU DETACH request. * @param pdev: device instance * @param req: pointer to the request structure. * @retval None. */ static void DFU_Req_DETACH(void *pdev, USB_SETUP_REQ *req) { if (DeviceState == STATE_dfuIDLE || DeviceState == STATE_dfuDNLOAD_SYNC || DeviceState == STATE_dfuDNLOAD_IDLE || DeviceState == STATE_dfuMANIFEST_SYNC || DeviceState == STATE_dfuUPLOAD_IDLE ) { /* Update the state machine */ DeviceState = STATE_dfuIDLE; DeviceStatus[0] = STATUS_OK; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/ DeviceStatus[4] = DeviceState; DeviceStatus[5] = 0; /*iString*/ wBlockNum = 0; wlength = 0; } /* Check the detach capability in the DFU functional descriptor */ if ((usbd_dfu_CfgDesc[12 + (9 * USBD_ITF_MAX_NUM)]) & DFU_DETACH_MASK) { /* Perform an Attach-Detach operation on USB bus */ DCD_DevDisconnect (pdev); DCD_DevConnect (pdev); } else { /* Wait for the period of time specified in Detach request */ USB_OTG_BSP_mDelay (req->wValue); } } /** * @brief DFU_Req_DNLOAD * Handles the DFU DNLOAD request. * @param pdev: device instance * @param req: pointer to the request structure * @retval None */ static void DFU_Req_DNLOAD(void *pdev, USB_SETUP_REQ *req) { /* Data setup request */ if (req->wLength > 0) { if ((DeviceState == STATE_dfuIDLE) || (DeviceState == STATE_dfuDNLOAD_IDLE)) { /* Update the global length and block number */ wBlockNum = req->wValue; wlength = req->wLength; /* Update the state machine */ DeviceState = STATE_dfuDNLOAD_SYNC; DeviceStatus[4] = DeviceState; /* Prepare the reception of the buffer over EP0 */ USBD_CtlPrepareRx (pdev, (uint8_t*)MAL_Buffer, wlength); } /* Unsupported state */ else { /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } } /* 0 Data DNLOAD request */ else { /* End of DNLOAD operation*/ if (DeviceState == STATE_dfuDNLOAD_IDLE || DeviceState == STATE_dfuIDLE ) { Manifest_State = Manifest_In_Progress; DeviceState = STATE_dfuMANIFEST_SYNC; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; DeviceStatus[4] = DeviceState; } else { /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } } } /** * @brief DFU_Req_UPLOAD * Handles the DFU UPLOAD request. * @param pdev: instance * @param req: pointer to the request structure * @retval status */ static void DFU_Req_UPLOAD(void *pdev, USB_SETUP_REQ *req) { uint8_t *Phy_Addr = NULL; uint32_t Addr = 0; /* Data setup request */ if (req->wLength > 0) { if ((DeviceState == STATE_dfuIDLE) || (DeviceState == STATE_dfuUPLOAD_IDLE)) { /* Update the global langth and block number */ wBlockNum = req->wValue; wlength = req->wLength; /* DFU Get Command */ if (wBlockNum == 0) { /* Update the state machine */ DeviceState = (wlength > 3)? STATE_dfuIDLE:STATE_dfuUPLOAD_IDLE; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /* Store the values of all supported commands */ MAL_Buffer[0] = CMD_GETCOMMANDS; MAL_Buffer[1] = CMD_SETADDRESSPOINTER; MAL_Buffer[2] = CMD_ERASE; /* Send the status data over EP0 */ USBD_CtlSendData (pdev, (uint8_t *)(&(MAL_Buffer[0])), 3); } else if (wBlockNum > 1) { DeviceState = STATE_dfuUPLOAD_IDLE ; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; Addr = ((wBlockNum - 2) * XFERSIZE) + Pointer; /* Change is Accelerated*/ /* Return the physical address where data are stored */ Phy_Addr = MAL_Read(Addr, wlength); /* Send the status data over EP0 */ USBD_CtlSendData (pdev, Phy_Addr, wlength); } else /* unsupported wBlockNum */ { DeviceState = STATUS_ERRSTALLEDPKT; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } } /* Unsupported state */ else { wlength = 0; wBlockNum = 0; /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } } /* No Data setup request */ else { DeviceState = STATE_dfuIDLE; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; DeviceStatus[4] = DeviceState; } } /** * @brief DFU_Req_GETSTATUS * Handles the DFU GETSTATUS request. * @param pdev: instance * @retval status */ static void DFU_Req_GETSTATUS(void *pdev) { switch (DeviceState) { case STATE_dfuDNLOAD_SYNC: if (wlength != 0) { DeviceState = STATE_dfuDNBUSY; DeviceStatus[4] = DeviceState; if ((wBlockNum == 0) && (MAL_Buffer[0] == CMD_ERASE)) { MAL_GetStatus(Pointer, 0, DeviceStatus); } else { MAL_GetStatus(Pointer, 1, DeviceStatus); } } else /* (wlength==0)*/ { DeviceState = STATE_dfuDNLOAD_IDLE; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; } break; case STATE_dfuMANIFEST_SYNC : if (Manifest_State == Manifest_In_Progress) { DeviceState = STATE_dfuMANIFEST; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 1; /*bwPollTimeout = 1ms*/ DeviceStatus[2] = 0; DeviceStatus[3] = 0; //break; } else if ((Manifest_State == Manifest_complete) && \ ((usbd_dfu_CfgDesc[(11 + (9 * USBD_ITF_MAX_NUM))]) & 0x04)) { DeviceState = STATE_dfuIDLE; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; //break; } break; default : break; } /* Send the status data over EP0 */ USBD_CtlSendData (pdev, (uint8_t *)(&(DeviceStatus[0])), 6); } /** * @brief DFU_Req_CLRSTATUS * Handles the DFU CLRSTATUS request. * @param pdev: device instance * @retval status */ static void DFU_Req_CLRSTATUS(void *pdev) { if (DeviceState == STATE_dfuERROR) { DeviceState = STATE_dfuIDLE; DeviceStatus[0] = STATUS_OK;/*bStatus*/ DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/ DeviceStatus[4] = DeviceState;/*bState*/ DeviceStatus[5] = 0;/*iString*/ } else { /*State Error*/ DeviceState = STATE_dfuERROR; DeviceStatus[0] = STATUS_ERRUNKNOWN;/*bStatus*/ DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/ DeviceStatus[4] = DeviceState;/*bState*/ DeviceStatus[5] = 0;/*iString*/ } } /** * @brief DFU_Req_GETSTATE * Handles the DFU GETSTATE request. * @param pdev: device instance * @retval None */ static void DFU_Req_GETSTATE(void *pdev) { /* Return the current state of the DFU interface */ USBD_CtlSendData (pdev, &DeviceState, 1); } /** * @brief DFU_Req_ABORT * Handles the DFU ABORT request. * @param pdev: device instance * @retval None */ static void DFU_Req_ABORT(void *pdev) { if (DeviceState == STATE_dfuIDLE || DeviceState == STATE_dfuDNLOAD_SYNC || DeviceState == STATE_dfuDNLOAD_IDLE || DeviceState == STATE_dfuMANIFEST_SYNC || DeviceState == STATE_dfuUPLOAD_IDLE ) { DeviceState = STATE_dfuIDLE; DeviceStatus[0] = STATUS_OK; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/ DeviceStatus[4] = DeviceState; DeviceStatus[5] = 0; /*iString*/ wBlockNum = 0; wlength = 0; } } /** * @brief DFU_LeaveDFUMode * Handles the sub-protocol DFU leave DFU mode request (leaves DFU mode * and resets device to jump to user loaded code). * @param pdev: device instance * @retval None */ void DFU_LeaveDFUMode(void *pdev) { Manifest_State = Manifest_complete; if ((usbd_dfu_CfgDesc[(11 + (9 * USBD_ITF_MAX_NUM))]) & 0x04) { DeviceState = STATE_dfuMANIFEST_SYNC; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; return; } else { DeviceState = STATE_dfuMANIFEST_WAIT_RESET; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /* Disconnect the USB device */ DCD_DevDisconnect (pdev); /* DeInitilialize the MAL(Media Access Layer) */ MAL_DeInit(); /* Generate system reset to allow jumping to the user code */ NVIC_SystemReset(); /* This instruction will not be reached (system reset) */ return; } } /** * @brief USBD_DFU_GetCfgDesc * Returns configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ static uint8_t *USBD_DFU_GetCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (usbd_dfu_CfgDesc); return usbd_dfu_CfgDesc; } #ifdef USB_OTG_HS_CORE /** * @brief USBD_DFU_GetOtherCfgDesc * Returns other speed configuration descriptor. * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ static uint8_t *USBD_DFU_GetOtherCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (usbd_dfu_OtherCfgDesc); return usbd_dfu_OtherCfgDesc; } #endif /** * @brief USBD_DFU_GetUsrStringDesc * Manages the transfer of memory interfaces string descriptors. * @param speed : current device speed * @param index: desciptor index * @param length : pointer data length * @retval pointer to the descriptor table or NULL if the descriptor is not supported. */ static uint8_t* USBD_DFU_GetUsrStringDesc (uint8_t speed, uint8_t index , uint16_t *length) { /* Check if the requested string interface is supported */ if (index <= (USBD_IDX_INTERFACE_STR + USBD_ITF_MAX_NUM)) { USBD_GetString ((uint8_t *)usbd_dfu_StringDesc[index - USBD_IDX_INTERFACE_STR - 1], USBD_StrDesc, length); return USBD_StrDesc; } /* Not supported Interface Descriptor index */ else { return NULL; } } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/src/usbd_dfu_core.c
C
lgpl
31,767
/** ****************************************************************************** * @file usbd_otp_if.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Specific media access Layer for OTP (One Time Programming) memory. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_otp_if.h" #include "usbd_dfu_mal.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ uint16_t OTP_If_Write (uint32_t Add, uint32_t Len); uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len); uint16_t OTP_If_DeInit(void); uint16_t OTP_If_CheckAdd(uint32_t Add); /* Private variables ---------------------------------------------------------*/ DFU_MAL_Prop_TypeDef DFU_Otp_cb = { OTP_IF_STRING, NULL, /* Init not supported*/ NULL, /* DeInit not supported */ NULL, /* Erase not supported */ OTP_If_Write, OTP_If_Read, OTP_If_CheckAdd, 1, /* Erase Time in ms */ 10 /* Programming Time in ms */ }; /* Private functions ---------------------------------------------------------*/ /** * @brief OTP_If_Write * Memory write routine. * @param Add: Address to be written to. * @param Len: Number of data to be written (in bytes). * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t OTP_If_Write(uint32_t Add, uint32_t Len) { uint32_t idx = 0; if (Len & 0x3) /* Not an aligned data */ { for (idx = Len; idx < ((Len & 0xFFFC) + 4); idx++) { MAL_Buffer[idx] = 0xFF; } } /* Data received are Word multiple */ for (idx = 0; idx < Len; idx = idx + 4) { FLASH_ProgramWord(Add, *(uint32_t *)(MAL_Buffer + idx)); Add += 4; } return MAL_OK; } /** * @brief OTP_If_Read * Memory read routine. * @param Add: Address to be read from. * @param Len: Number of data to be read (in bytes). * @retval Pointer to the phyisical address where data should be read. */ uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED uint32_t idx = 0; for (idx = 0; idx < Len; idx += 4) { *(uint32_t*)(MAL_Buffer + idx) = *(uint32_t *)(Add + idx); } return (uint8_t*)(MAL_Buffer); #else return (uint8_t*)(Add); #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ } /** * @brief OTP_If_CheckAdd * Check if the address is an allowed address for this memory. * @param Add: Address to be checked. * @param Len: Number of data to be read (in bytes). * @retval MAL_OK if the address is allowed, MAL_FAIL else. */ uint16_t OTP_If_CheckAdd(uint32_t Add) { if ((Add >= OTP_START_ADD) && (Add < OTP_END_ADD)) { return MAL_OK; } else { return MAL_FAIL; } } /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/src/usbd_otp_if.c
C
lgpl
3,934
/** ****************************************************************************** * @file usbd_mem_if_template.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Specific media access Layer for a template memory. This file is provided as template example showing how to implement a new memory interface based on pre-defined API. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_mem_if_template.h" #include "usbd_dfu_mal.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ uint16_t MEM_If_Init(void); uint16_t MEM_If_Erase (uint32_t Add); uint16_t MEM_If_Write (uint32_t Add, uint32_t Len); uint8_t *MEM_If_Read (uint32_t Add, uint32_t Len); uint16_t MEM_If_DeInit(void); uint16_t MEM_If_CheckAdd(uint32_t Add); /* Private variables ---------------------------------------------------------*/ DFU_MAL_Prop_TypeDef DFU_Mem_cb = { MEM_IF_STRING, MEM_If_Init, MEM_If_DeInit, MEM_If_Erase, MEM_If_Write, MEM_If_Read, MEM_If_CheckAdd, 10, /* Erase Time in ms */ 10 /* Programming Time in ms */ }; /* Private functions ---------------------------------------------------------*/ /** * @brief MEM_If_Init * Memory initialization routine. * @param None * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t MEM_If_Init(void) { return MAL_OK; } /** * @brief MEM_If_DeInit * Memory deinitialization routine. * @param None * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t MEM_If_DeInit(void) { return MAL_OK; } /** * @brief MEM_If_Erase * Erase sector. * @param Add: Address of sector to be erased. * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t MEM_If_Erase(uint32_t Add) { return MAL_OK; } /** * @brief MEM_If_Write * Memory write routine. * @param Add: Address to be written to. * @param Len: Number of data to be written (in bytes). * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t MEM_If_Write(uint32_t Add, uint32_t Len) { return MAL_OK; } /** * @brief MEM_If_Read * Memory read routine. * @param Add: Address to be read from. * @param Len: Number of data to be read (in bytes). * @retval Pointer to the phyisical address where data should be read. */ uint8_t *MEM_If_Read (uint32_t Add, uint32_t Len) { /* Return a valid address to avoid HardFault */ return (uint8_t*)(MAL_Buffer); } /** * @brief MEM_If_CheckAdd * Check if the address is an allowed address for this memory. * @param Add: Address to be checked. * @param Len: Number of data to be read (in bytes). * @retval MAL_OK if the address is allowed, MAL_FAIL else. */ uint16_t MEM_If_CheckAdd(uint32_t Add) { if ((Add >= MEM_START_ADD) && (Add < MEM_END_ADD)) { return MAL_OK; } else { return MAL_FAIL; } } /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/src/usbd_mem_if_template.c
C
lgpl
4,219
/** ****************************************************************************** * @file usbd_flash_if.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Specific media access Layer for internal flash. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_flash_if.h" #include "usbd_dfu_mal.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ uint16_t FLASH_If_Init(void); uint16_t FLASH_If_Erase (uint32_t Add); uint16_t FLASH_If_Write (uint32_t Add, uint32_t Len); uint8_t *FLASH_If_Read (uint32_t Add, uint32_t Len); uint16_t FLASH_If_DeInit(void); uint16_t FLASH_If_CheckAdd(uint32_t Add); /* Private variables ---------------------------------------------------------*/ DFU_MAL_Prop_TypeDef DFU_Flash_cb = { FLASH_IF_STRING, FLASH_If_Init, FLASH_If_DeInit, FLASH_If_Erase, FLASH_If_Write, FLASH_If_Read, FLASH_If_CheckAdd, 50, /* Erase Time in ms */ 50 /* Programming Time in ms */ }; /* Private functions ---------------------------------------------------------*/ /** * @brief FLASH_If_Init * Memory initialization routine. * @param None * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t FLASH_If_Init(void) { /* Unlock the internal flash */ FLASH_Unlock(); return MAL_OK; } /** * @brief FLASH_If_DeInit * Memory deinitialization routine. * @param None * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t FLASH_If_DeInit(void) { /* Lock the internal flash */ FLASH_Lock(); return MAL_OK; } /******************************************************************************* * Function Name : FLASH_If_Erase * Description : Erase sector * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t FLASH_If_Erase(uint32_t Add) { #ifdef STM32F2XX /* Check which sector has to be erased */ if (Add < 0x08004000) { FLASH_EraseSector(FLASH_Sector_0, VoltageRange_3); } else if (Add < 0x08008000) { FLASH_EraseSector(FLASH_Sector_1, VoltageRange_3); } else if (Add < 0x0800C000) { FLASH_EraseSector(FLASH_Sector_2, VoltageRange_3); } else if (Add < 0x08010000) { FLASH_EraseSector(FLASH_Sector_3, VoltageRange_3); } else if (Add < 0x08020000) { FLASH_EraseSector(FLASH_Sector_4, VoltageRange_3); } else if (Add < 0x08040000) { FLASH_EraseSector(FLASH_Sector_5, VoltageRange_3); } else if (Add < 0x08060000) { FLASH_EraseSector(FLASH_Sector_6, VoltageRange_3); } else if (Add < 0x08080000) { FLASH_EraseSector(FLASH_Sector_7, VoltageRange_3); } else if (Add < 0x080A0000) { FLASH_EraseSector(FLASH_Sector_8, VoltageRange_3); } else if (Add < 0x080C0000) { FLASH_EraseSector(FLASH_Sector_9, VoltageRange_3); } else if (Add < 0x080E0000) { FLASH_EraseSector(FLASH_Sector_10, VoltageRange_3); } else if (Add < 0x08100000) { FLASH_EraseSector(FLASH_Sector_11, VoltageRange_3); } else { return MAL_FAIL; } #elif defined(STM32F10X_CL) /* Call the standard Flash erase function */ FLASH_ErasePage(Add); #endif /* STM32F2XX */ return MAL_OK; } /** * @brief FLASH_If_Write * Memory write routine. * @param Add: Address to be written to. * @param Len: Number of data to be written (in bytes). * @retval MAL_OK if operation is successeful, MAL_FAIL else. */ uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len) { uint32_t idx = 0; if (Len & 0x3) /* Not an aligned data */ { for (idx = Len; idx < ((Len & 0xFFFC) + 4); idx++) { MAL_Buffer[idx] = 0xFF; } } /* Data received are Word multiple */ for (idx = 0; idx < Len; idx = idx + 4) { FLASH_ProgramWord(Add, *(uint32_t *)(MAL_Buffer + idx)); Add += 4; } return MAL_OK; } /** * @brief FLASH_If_Read * Memory read routine. * @param Add: Address to be read from. * @param Len: Number of data to be read (in bytes). * @retval Pointer to the phyisical address where data should be read. */ uint8_t *FLASH_If_Read (uint32_t Add, uint32_t Len) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED uint32_t idx = 0; for (idx = 0; idx < Len; idx += 4) { *(uint32_t*)(MAL_Buffer + idx) = *(uint32_t *)(Add + idx); } return (uint8_t*)(MAL_Buffer); #else return (uint8_t *)(Add); #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ } /** * @brief FLASH_If_CheckAdd * Check if the address is an allowed address for this memory. * @param Add: Address to be checked. * @param Len: Number of data to be read (in bytes). * @retval MAL_OK if the address is allowed, MAL_FAIL else. */ uint16_t FLASH_If_CheckAdd(uint32_t Add) { if ((Add >= FLASH_START_ADD) && (Add < FLASH_END_ADD)) { return MAL_OK; } else { return MAL_FAIL; } } /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/src/usbd_flash_if.c
C
lgpl
6,297
/** ****************************************************************************** * @file usbd_dfu_mal.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Header for usbd_dfu_mal.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __DFU_MAL_H #define __DFU_MAL_H /* Includes ------------------------------------------------------------------*/ #ifdef STM32F2XX #include "stm32f2xx.h" #elif defined(STM32F10X_CL) #include "stm32f10x.h" #endif /* STM32F2XX */ #include "usbd_conf.h" #include "usbd_dfu_core.h" /* Exported types ------------------------------------------------------------*/ typedef struct _DFU_MAL_PROP { const uint8_t* pStrDesc; uint16_t (*pMAL_Init) (void); uint16_t (*pMAL_DeInit) (void); uint16_t (*pMAL_Erase) (uint32_t Add); uint16_t (*pMAL_Write) (uint32_t Add, uint32_t Len); uint8_t *(*pMAL_Read) (uint32_t Add, uint32_t Len); uint16_t (*pMAL_CheckAdd) (uint32_t Add); const uint32_t EraseTiming; const uint32_t WriteTiming; } DFU_MAL_Prop_TypeDef; /* Exported constants --------------------------------------------------------*/ #define MAL_OK 0 #define MAL_FAIL 1 /* utils macro ---------------------------------------------------------------*/ #define _1st_BYTE(x) (uint8_t)((x)&0xFF) /* 1st addressing cycle */ #define _2nd_BYTE(x) (uint8_t)(((x)&0xFF00)>>8) /* 2nd addressing cycle */ #define _3rd_BYTE(x) (uint8_t)(((x)&0xFF0000)>>16) /* 3rd addressing cycle */ #define _4th_BYTE(x) (uint8_t)(((x)&0xFF000000)>>24) /* 4th addressing cycle */ /* Exported macro ------------------------------------------------------------*/ #define SET_POLLING_TIMING(x) buffer[1] = _1st_BYTE(x);\ buffer[2] = _2nd_BYTE(x);\ buffer[3] = _3rd_BYTE(x); /* Exported functions ------------------------------------------------------- */ uint16_t MAL_Init (void); uint16_t MAL_DeInit (void); uint16_t MAL_Erase (uint32_t SectorAddress); uint16_t MAL_Write (uint32_t SectorAddress, uint32_t DataLength); uint8_t *MAL_Read (uint32_t SectorAddress, uint32_t DataLength); uint16_t MAL_GetStatus(uint32_t SectorAddress ,uint8_t Cmd, uint8_t *buffer); extern uint8_t MAL_Buffer[XFERSIZE]; /* RAM Buffer for Downloaded Data */ #endif /* __DFU_MAL_H */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/inc/usbd_dfu_mal.h
C
lgpl
3,331
/** ****************************************************************************** * @file usbd_dfu_core.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header file for the usbd_dfu_core.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #ifndef __USB_DFU_CORE_H_ #define __USB_DFU_CORE_H_ #include "usbd_ioreq.h" #include "usbd_dfu_mal.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_dfu * @brief This file is the Header file for USBD_dfu.c * @{ */ /** @defgroup usbd_dfu_Exported_Defines * @{ */ #define USB_DFU_CONFIG_DESC_SIZ (18 + (9 * USBD_ITF_MAX_NUM)) #define USB_DFU_DESC_SIZ 9 #define DFU_DESCRIPTOR_TYPE 0x21 /*---------------------------------------------------------------------*/ /* DFU definitions */ /*---------------------------------------------------------------------*/ /**************************************************/ /* DFU Requests DFU states */ /**************************************************/ #define STATE_appIDLE 0 #define STATE_appDETACH 1 #define STATE_dfuIDLE 2 #define STATE_dfuDNLOAD_SYNC 3 #define STATE_dfuDNBUSY 4 #define STATE_dfuDNLOAD_IDLE 5 #define STATE_dfuMANIFEST_SYNC 6 #define STATE_dfuMANIFEST 7 #define STATE_dfuMANIFEST_WAIT_RESET 8 #define STATE_dfuUPLOAD_IDLE 9 #define STATE_dfuERROR 10 /**************************************************/ /* DFU Requests DFU status */ /**************************************************/ #define STATUS_OK 0x00 #define STATUS_ERRTARGET 0x01 #define STATUS_ERRFILE 0x02 #define STATUS_ERRWRITE 0x03 #define STATUS_ERRERASE 0x04 #define STATUS_ERRCHECK_ERASED 0x05 #define STATUS_ERRPROG 0x06 #define STATUS_ERRVERIFY 0x07 #define STATUS_ERRADDRESS 0x08 #define STATUS_ERRNOTDONE 0x09 #define STATUS_ERRFIRMWARE 0x0A #define STATUS_ERRVENDOR 0x0B #define STATUS_ERRUSBR 0x0C #define STATUS_ERRPOR 0x0D #define STATUS_ERRUNKNOWN 0x0E #define STATUS_ERRSTALLEDPKT 0x0F /**************************************************/ /* DFU Requests DFU states Manifestation State */ /**************************************************/ #define Manifest_complete 0x00 #define Manifest_In_Progress 0x01 /**************************************************/ /* Special Commands with Download Request */ /**************************************************/ #define CMD_GETCOMMANDS 0x00 #define CMD_SETADDRESSPOINTER 0x21 #define CMD_ERASE 0x41 /**************************************************/ /* Other defines */ /**************************************************/ /* Bit Detach capable = bit 3 in bmAttributes field */ #define DFU_DETACH_MASK (uint8_t)(1 << 4) /** * @} */ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ /**************************************************/ /* DFU Requests */ /**************************************************/ typedef enum _DFU_REQUESTS { DFU_DETACH = 0, DFU_DNLOAD = 1, DFU_UPLOAD, DFU_GETSTATUS, DFU_CLRSTATUS, DFU_GETSTATE, DFU_ABORT } DFU_REQUESTS; typedef void (*pFunction)(void); /** * @} */ /** @defgroup USBD_CORE_Exported_Macros * @{ */ /********** Descriptor of DFU interface 0 Alternate setting n ****************/ #define USBD_DFU_IF_DESC(n) 0x09, /* bLength: Interface Descriptor size */ \ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \ 0x00, /* bInterfaceNumber: Number of Interface */ \ (n), /* bAlternateSetting: Alternate setting */ \ 0x00, /* bNumEndpoints*/ \ 0xFE, /* bInterfaceClass: Application Specific Class Code */ \ 0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \ 0x02, /* nInterfaceProtocol: DFU mode protocol */ \ USBD_IDX_INTERFACE_STR + (n) + 1 /* iInterface: Index of string descriptor */ \ /* 18 */ /** * @} */ /** @defgroup USBD_CORE_Exported_Variables * @{ */ extern USBD_Class_cb_TypeDef DFU_cb; /** * @} */ /** @defgroup USB_CORE_Exported_Functions * @{ */ /** * @} */ #endif // __USB_DFU_CORE_H_ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/inc/usbd_dfu_core.h
C
lgpl
5,924
/** ****************************************************************************** * @file usbd_mem_if_template.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Header for usbd_mem_if_template.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MEM_IF_MAL_H #define __MEM_IF_MAL_H /* Includes ------------------------------------------------------------------*/ #ifdef STM32F2XX #include "stm32f2xx.h" #endif /* STM32F2XX */ #include "usbd_dfu_mal.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ #define MEM_START_ADD 0x00000000 /* Dummy start address */ #define MEM_END_ADD (uint32_t)(MEM_START_ADD + (5 * 1024)) /* Dummy Size = 5KB */ #define MEM_IF_STRING "@Dummy Memory /0x00000000/01*002Kg,03*001Kg" extern DFU_MAL_Prop_TypeDef DFU_Mem_cb; /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ #endif /* __MEM_IF_MAL_H */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/inc/usbd_mem_if_template.h
C
lgpl
2,070
/** ****************************************************************************** * @file usbd_otp_if.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Header for usbd_otp_if.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __OTP_IF_MAL_H #define __OTP_IF_MAL_H /* Includes ------------------------------------------------------------------*/ #include "usbd_dfu_mal.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ #define OTP_START_ADD 0x1FFF7800 #define OTP_END_ADD (uint32_t)(OTP_START_ADD + 528) #define OTP_IF_STRING "@OTP Area /0x1FFF7800/01*512 g,01*016 g" extern DFU_MAL_Prop_TypeDef DFU_Otp_cb; /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ #endif /* __OTP_IF_MAL_H */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/inc/usbd_otp_if.h
C
lgpl
1,941
/** ****************************************************************************** * @file usbd_flash_if.h * @author MCD Application Team * @version V1.0.0RC1 * @date 18-March-2011 * @brief Header for usbd_flash_if.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __FLASH_IF_MAL_H #define __FLASH_IF_MAL_H /* Includes ------------------------------------------------------------------*/ #include "usbd_dfu_mal.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ #define FLASH_START_ADD 0x08000000 #ifdef STM32F2XX #define FLASH_END_ADD 0x08100000 #define FLASH_IF_STRING "@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg" #elif defined(STM32F10X_CL) #define FLASH_END_ADD 0x08040000 #define FLASH_IF_STRING "@Internal Flash /0x08000000/06*002Ka,122*002Kg" #endif /* STM32F2XX */ extern DFU_MAL_Prop_TypeDef DFU_Flash_cb; /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ #endif /* __FLASH_IF_MAL_H */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/dfu/inc/usbd_flash_if.h
C
lgpl
2,173
/** ****************************************************************************** * @file usbd_audio_core.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides the high layer firmware functions to manage the * following functionalities of the USB Audio Class: * - Initialization and Configuration of high and low layer * - Enumeration as Audio Streaming Device * - Audio Streaming data transfer * - AudioControl requests management * - Error management * * @verbatim * * =================================================================== * Audio Class Driver Description * =================================================================== * This driver manages the Audio Class 1.0 following the "USB Device Class Definition for * Audio Devices V1.0 Mar 18, 98". * This driver implements the following aspects of the specification: * - Device descriptor management * - Configuration descriptor management * - Standard AC Interface Descriptor management * - 1 Audio Streaming Interface (with single channel, PCM, Stereo mode) * - 1 Audio Streaming Endpoint * - 1 Audio Terminal Input (1 channel) * - Audio Class-Specific AC Interfaces * - Audio Class-Specific AS Interfaces * - AudioControl Requests: only SET_CUR and GET_CUR requests are supported (for Mute) * - Audio Feature Unit (limited to Mute control) * - Audio Synchronization type: Asynchronous * - Single fixed audio sampling rate (configurable in usbd_conf.h file) * * @note * The Audio Class 1.0 is based on USB Specification 1.0 and thus supports only * Low and Full speed modes and does not allow High Speed transfers. * Please refer to "USB Device Class Definition for Audio Devices V1.0 Mar 18, 98" * for more details. * * These aspects may be enriched or modified for a specific user application. * * This driver doesn't implement the following aspects of the specification * (but it is possible to manage these features with some modifications on this driver): * - AudioControl Endpoint management * - AudioControl requsests other than SET_CUR and GET_CUR * - Abstraction layer for AudioControl requests (only Mute functionality is managed) * - Audio Synchronization type: Adaptive * - Audio Compression modules and interfaces * - MIDI interfaces and modules * - Mixer/Selector/Processing/Extension Units (Feature unit is limited to Mute control) * - Any other application-specific modules * - Multiple and Variable audio sampling rates * - Out Streaming Endpoint/Interface (microphone) * * @endverbatim * ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_audio_core.h" #include "usbd_audio_out_if.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_audio * @brief usbd core module * @{ */ /** @defgroup usbd_audio_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup usbd_audio_Private_Defines * @{ */ /** * @} */ /** @defgroup usbd_audio_Private_Macros * @{ */ /** * @} */ /** @defgroup usbd_audio_Private_FunctionPrototypes * @{ */ /********************************************* AUDIO Device library callbacks *********************************************/ static uint8_t usbd_audio_Init (void *pdev, uint8_t cfgidx); static uint8_t usbd_audio_DeInit (void *pdev, uint8_t cfgidx); static uint8_t usbd_audio_Setup (void *pdev, USB_SETUP_REQ *req); static uint8_t usbd_audio_EP0_RxReady(void *pdev); static uint8_t usbd_audio_DataIn (void *pdev, uint8_t epnum); static uint8_t usbd_audio_DataOut (void *pdev, uint8_t epnum); static uint8_t usbd_audio_SOF (void *pdev); static uint8_t usbd_audio_OUT_Incplt (void *pdev); /********************************************* AUDIO Requests management functions *********************************************/ static void AUDIO_Req_GetCurrent(void *pdev, USB_SETUP_REQ *req); static void AUDIO_Req_SetCurrent(void *pdev, USB_SETUP_REQ *req); static uint8_t *USBD_audio_GetCfgDesc (uint8_t speed, uint16_t *length); /** * @} */ /** @defgroup usbd_audio_Private_Variables * @{ */ /* Main Buffer for Audio Data Out transfers and its relative pointers */ uint8_t IsocOutBuff [TOTAL_OUT_BUF_SIZE * 2]; uint8_t* IsocOutWrPtr = IsocOutBuff; uint8_t* IsocOutRdPtr = IsocOutBuff; /* Main Buffer for Audio Control Rrequests transfers and its relative variables */ uint8_t AudioCtl[64]; uint8_t AudioCtlCmd = 0; uint32_t AudioCtlLen = 0; uint8_t AudioCtlUnit = 0; static uint32_t PlayFlag = 0; static __IO uint32_t usbd_audio_AltSet = 0; static uint8_t usbd_audio_CfgDesc[AUDIO_CONFIG_DESC_SIZE]; /* AUDIO interface class callbacks structure */ USBD_Class_cb_TypeDef AUDIO_cb = { usbd_audio_Init, usbd_audio_DeInit, usbd_audio_Setup, NULL, /* EP0_TxSent */ usbd_audio_EP0_RxReady, usbd_audio_DataIn, usbd_audio_DataOut, usbd_audio_SOF, NULL, usbd_audio_OUT_Incplt, USBD_audio_GetCfgDesc, #ifdef USB_OTG_HS_CORE USBD_audio_GetCfgDesc, /* use same config as per FS */ #endif }; /* USB AUDIO device Configuration Descriptor */ static uint8_t usbd_audio_CfgDesc[AUDIO_CONFIG_DESC_SIZE] = { /* Configuration 1 */ 0x09, /* bLength */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */ LOBYTE(AUDIO_CONFIG_DESC_SIZE), /* wTotalLength 109 bytes*/ HIBYTE(AUDIO_CONFIG_DESC_SIZE), 0x02, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ 0xC0, /* bmAttributes BUS Powred*/ 0x32, /* bMaxPower = 100 mA*/ /* 09 byte*/ /* USB Speaker Standard interface descriptor */ AUDIO_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x00, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x00, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* 09 byte*/ /* USB Speaker Class-specific AC Interface Descriptor */ AUDIO_INTERFACE_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_HEADER, /* bDescriptorSubtype */ 0x00, /* 1.00 */ /* bcdADC */ 0x01, 0x27, /* wTotalLength = 39*/ 0x00, 0x01, /* bInCollection */ 0x01, /* baInterfaceNr */ /* 09 byte*/ /* USB Speaker Input Terminal Descriptor */ AUDIO_INPUT_TERMINAL_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_INPUT_TERMINAL, /* bDescriptorSubtype */ 0x01, /* bTerminalID */ 0x01, /* wTerminalType AUDIO_TERMINAL_USB_STREAMING 0x0101 */ 0x01, 0x00, /* bAssocTerminal */ 0x01, /* bNrChannels */ 0x00, /* wChannelConfig 0x0000 Mono */ 0x00, 0x00, /* iChannelNames */ 0x00, /* iTerminal */ /* 12 byte*/ /* USB Speaker Audio Feature Unit Descriptor */ 0x09, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_FEATURE_UNIT, /* bDescriptorSubtype */ AUDIO_OUT_STREAMING_CTRL, /* bUnitID */ 0x01, /* bSourceID */ 0x01, /* bControlSize */ AUDIO_CONTROL_MUTE, /* bmaControls(0) */ 0x00, /* bmaControls(1) */ 0x00, /* iTerminal */ /* 09 byte*/ /*USB Speaker Output Terminal Descriptor */ 0x09, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_CONTROL_OUTPUT_TERMINAL, /* bDescriptorSubtype */ 0x03, /* bTerminalID */ 0x01, /* wTerminalType 0x0301*/ 0x03, 0x00, /* bAssocTerminal */ 0x02, /* bSourceID */ 0x00, /* iTerminal */ /* 09 byte*/ /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */ /* Interface 1, Alternate Setting 0 */ AUDIO_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x01, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x00, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* 09 byte*/ /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Operational */ /* Interface 1, Alternate Setting 1 */ AUDIO_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x01, /* bInterfaceNumber */ 0x01, /* bAlternateSetting */ 0x01, /* bNumEndpoints */ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* 09 byte*/ /* USB Speaker Audio Streaming Interface Descriptor */ AUDIO_STREAMING_INTERFACE_DESC_SIZE, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */ 0x01, /* bTerminalLink */ 0x01, /* bDelay */ 0x01, /* wFormatTag AUDIO_FORMAT_PCM 0x0001*/ 0x00, /* 07 byte*/ /* USB Speaker Audio Type III Format Interface Descriptor */ 0x0B, /* bLength */ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */ AUDIO_FORMAT_TYPE_III, /* bFormatType */ 0x02, /* bNrChannels */ 0x02, /* bSubFrameSize : 2 Bytes per frame (16bits) */ 16, /* bBitResolution (16-bits per sample) */ 0x01, /* bSamFreqType only one frequency supported */ SAMPLE_FREQ(USBD_AUDIO_FREQ), /* Audio sampling frequency coded on 3 bytes */ /* 11 byte*/ /* Endpoint 1 - Standard Descriptor */ AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_OUT_EP, /* bEndpointAddress 1 out endpoint*/ USB_ENDPOINT_TYPE_ISOCHRONOUS, /* bmAttributes */ AUDIO_PACKET_SZE(USBD_AUDIO_FREQ), /* wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */ 0x01, /* bInterval */ 0x00, /* bRefresh */ 0x00, /* bSynchAddress */ /* 09 byte*/ /* Endpoint - Audio Streaming Descriptor*/ AUDIO_STREAMING_ENDPOINT_DESC_SIZE, /* bLength */ AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ AUDIO_ENDPOINT_GENERAL, /* bDescriptor */ 0x00, /* bmAttributes */ 0x00, /* bLockDelayUnits */ 0x00, /* wLockDelay */ 0x00, /* 07 byte*/ } ; /** * @} */ /** @defgroup usbd_audio_Private_Functions * @{ */ /** * @brief usbd_audio_Init * Initilaizes the AUDIO interface. * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t usbd_audio_Init (void *pdev, uint8_t cfgidx) { /* Open EP OUT */ DCD_EP_Open(pdev, AUDIO_OUT_EP, AUDIO_OUT_PACKET, USB_OTG_EP_ISOC); /* Initialize the Audio output Hardware layer */ if (AUDIO_OUT_fops.Init(USBD_AUDIO_FREQ, DEFAULT_VOLUME, 0) != USBD_OK) { return USBD_FAIL; } /* Prepare Out endpoint to receive audio data */ DCD_EP_PrepareRx(pdev, AUDIO_OUT_EP, (uint8_t*)IsocOutBuff, AUDIO_OUT_PACKET); return USBD_OK; } /** * @brief usbd_audio_Init * DeInitializes the AUDIO layer. * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t usbd_audio_DeInit (void *pdev, uint8_t cfgidx) { DCD_EP_Close (pdev , AUDIO_OUT_EP); /* DeInitialize the Audio output Hardware layer */ if (AUDIO_OUT_fops.DeInit(0) != USBD_OK) { return USBD_FAIL; } return USBD_OK; } /** * @brief usbd_audio_Setup * Handles the Audio control request parsing. * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t usbd_audio_Setup (void *pdev, USB_SETUP_REQ *req) { uint16_t len; uint8_t *pbuf; switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* AUDIO Class Requests -------------------------------*/ case USB_REQ_TYPE_CLASS : switch (req->bRequest) { case AUDIO_REQ_GET_CUR: AUDIO_Req_GetCurrent(pdev, req); break; case AUDIO_REQ_SET_CUR: AUDIO_Req_SetCurrent(pdev, req); break; default: USBD_CtlError (pdev, req); return USBD_FAIL; } break; /* Standard Requests -------------------------------*/ case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_DESCRIPTOR: if( (req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED pbuf = usbd_audio_Desc; #else pbuf = usbd_audio_CfgDesc + 18; #endif len = MIN(USB_AUDIO_DESC_SIZ , req->wLength); } USBD_CtlSendData (pdev, pbuf, len); break; case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, (uint8_t *)&usbd_audio_AltSet, 1); break; case USB_REQ_SET_INTERFACE : if ((uint8_t)(req->wValue) < AUDIO_TOTAL_IF_NUM) { usbd_audio_AltSet = (uint8_t)(req->wValue); } else { /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } break; } } return USBD_OK; } /** * @brief usbd_audio_EP0_RxReady * Handles audio control requests data. * @param pdev: device device instance * @retval status */ static uint8_t usbd_audio_EP0_RxReady (void *pdev) { /* Check if an AudioControl request has been issued */ if (AudioCtlCmd == AUDIO_REQ_SET_CUR) {/* In this driver, to simplify code, only SET_CUR request is managed */ /* Check for which addressed unit the AudioControl request has been issued */ if (AudioCtlUnit == AUDIO_OUT_STREAMING_CTRL) {/* In this driver, to simplify code, only one unit is manage */ /* Call the audio interface mute function */ AUDIO_OUT_fops.MuteCtl(AudioCtl[0]); /* Reset the AudioCtlCmd variable to prevent re-entering this function */ AudioCtlCmd = 0; AudioCtlLen = 0; } } return USBD_OK; } /** * @brief usbd_audio_DataIn * Handles the audio IN data stage. * @param pdev: instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_audio_DataIn (void *pdev, uint8_t epnum) { return USBD_OK; } /** * @brief usbd_audio_DataOut * Handles the Audio Out data stage. * @param pdev: instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_audio_DataOut (void *pdev, uint8_t epnum) { if (epnum == AUDIO_OUT_EP) { /* Increment the Buffer pointer or roll it back when all buffers are full */ if (IsocOutWrPtr >= (IsocOutBuff + (AUDIO_OUT_PACKET * OUT_PACKET_NUM))) {/* All buffers are full: roll back */ IsocOutWrPtr = IsocOutBuff; } else {/* Increment the buffer pointer */ IsocOutWrPtr += AUDIO_OUT_PACKET; } /* Toggle the frame index */ ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].even_odd_frame = (((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].even_odd_frame)? 0:1; /* Prepare Out endpoint to receive next audio packet */ DCD_EP_PrepareRx(pdev, AUDIO_OUT_EP, (uint8_t*)(IsocOutWrPtr), AUDIO_OUT_PACKET); /* Trigger the start of streaming only when half buffer is full */ if ((PlayFlag == 0) && (IsocOutWrPtr >= (IsocOutBuff + ((AUDIO_OUT_PACKET * OUT_PACKET_NUM) / 2)))) { /* Enable start of Streaming */ PlayFlag = 1; } } return USBD_OK; } /** * @brief usbd_audio_SOF * Handles the SOF event (data buffer update and synchronization). * @param pdev: instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_audio_SOF (void *pdev) { /* Check if there are available data in stream buffer. In this function, a single variable (PlayFlag) is used to avoid software delays. The play operation must be executed as soon as possible after the SOF detection. */ if (PlayFlag) { /* Start playing received packet */ AUDIO_OUT_fops.AudioCmd((uint8_t*)(IsocOutRdPtr), /* Samples buffer pointer */ AUDIO_OUT_PACKET, /* Number of samples in Bytes */ AUDIO_CMD_PLAY); /* Command to be processed */ /* Increment the Buffer pointer or roll it back when all buffers all full */ if (IsocOutRdPtr >= (IsocOutBuff + (AUDIO_OUT_PACKET * OUT_PACKET_NUM))) {/* Roll back to the start of buffer */ IsocOutRdPtr = IsocOutBuff; } else {/* Increment to the next sub-buffer */ IsocOutRdPtr += AUDIO_OUT_PACKET; } /* If all available buffers have been consumed, stop playing */ if (IsocOutRdPtr == IsocOutWrPtr) { /* Pause the audio stream */ AUDIO_OUT_fops.AudioCmd((uint8_t*)(IsocOutBuff), /* Samples buffer pointer */ AUDIO_OUT_PACKET, /* Number of samples in Bytes */ AUDIO_CMD_PAUSE); /* Command to be processed */ /* Stop entering play loop */ PlayFlag = 0; /* Reset buffer pointers */ IsocOutRdPtr = IsocOutBuff; IsocOutWrPtr = IsocOutBuff; } } return USBD_OK; } /** * @brief usbd_audio_OUT_Incplt * Handles the iso out incomplete event. * @param pdev: instance * @retval status */ static uint8_t usbd_audio_OUT_Incplt (void *pdev) { return USBD_OK; } /****************************************************************************** AUDIO Class requests management ******************************************************************************/ /** * @brief AUDIO_Req_GetCurrent * Handles the GET_CUR Audio control request. * @param pdev: instance * @param req: setup class request * @retval status */ static void AUDIO_Req_GetCurrent(void *pdev, USB_SETUP_REQ *req) { /* Send the current mute state */ USBD_CtlSendData (pdev, AudioCtl, req->wLength); } /** * @brief AUDIO_Req_SetCurrent * Handles the SET_CUR Audio control request. * @param pdev: instance * @param req: setup class request * @retval status */ static void AUDIO_Req_SetCurrent(void *pdev, USB_SETUP_REQ *req) { if (req->wLength) { /* Prepare the reception of the buffer over EP0 */ USBD_CtlPrepareRx (pdev, AudioCtl, req->wLength); /* Set the global variables indicating current request and its length to the function usbd_audio_EP0_RxReady() which will process the request */ AudioCtlCmd = AUDIO_REQ_SET_CUR; /* Set the request value */ AudioCtlLen = req->wLength; /* Set the request data length */ AudioCtlUnit = HIBYTE(req->wIndex); /* Set the request target unit */ } } /** * @brief USBD_audio_GetCfgDesc * Returns configuration descriptor. * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ static uint8_t *USBD_audio_GetCfgDesc (uint8_t speed, uint16_t *length) { *length = sizeof (usbd_audio_CfgDesc); return usbd_audio_CfgDesc; } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/audio/src/usbd_audio_core.c
C
lgpl
23,865
/** ****************************************************************************** * @file usbd_audio_out_if.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides the Audio Out (palyback) interface API. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_audio_core.h" #include "usbd_audio_out_if.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_audio_out_if * @brief usbd out interface module * @{ */ /** @defgroup usbd_audio_out_if_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup usbd_audio_out_if_Private_Defines * @{ */ /** * @} */ /** @defgroup usbd_audio_out_if_Private_Macros * @{ */ /** * @} */ /** @defgroup usbd_audio_out_if_Private_FunctionPrototypes * @{ */ static uint8_t Init (uint32_t AudioFreq, uint32_t Volume, uint32_t options); static uint8_t DeInit (uint32_t options); static uint8_t AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd); static uint8_t VolumeCtl (uint8_t vol); static uint8_t MuteCtl (uint8_t cmd); static uint8_t PeriodicTC (uint8_t cmd); static uint8_t GetState (void); /** * @} */ /** @defgroup usbd_audio_out_if_Private_Variables * @{ */ AUDIO_FOPS_TypeDef AUDIO_OUT_fops = { Init, DeInit, AudioCmd, VolumeCtl, MuteCtl, PeriodicTC, GetState }; static uint8_t AudioState = AUDIO_STATE_INACTIVE; /** * @} */ /** @defgroup usbd_audio_out_if_Private_Functions * @{ */ /** * @brief Init * Initialize and configures all required resources for audio play function. * @param AudioFreq: Statrtup audio frequency. * @param Volume: Startup volume to be set. * @param options: specific options passed to low layer function. * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else. */ static uint8_t Init (uint32_t AudioFreq, uint32_t Volume, uint32_t options) { static uint32_t Initialized = 0; /* Check if the low layer has already been initialized */ if (Initialized == 0) { /* Call low layer function */ if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, Volume, AudioFreq) != 0) { AudioState = AUDIO_STATE_ERROR; return AUDIO_FAIL; } /* Set the Initialization flag to prevent reinitializing the interface again */ Initialized = 1; } /* Update the Audio state machine */ AudioState = AUDIO_STATE_ACTIVE; return AUDIO_OK; } /** * @brief DeInit * Free all resources used by low layer and stops audio-play function. * @param options: options passed to low layer function. * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else. */ static uint8_t DeInit (uint32_t options) { /* Update the Audio state machine */ AudioState = AUDIO_STATE_INACTIVE; return AUDIO_OK; } /** * @brief AudioCmd * Play, Stop, Pause or Resume current file. * @param pbuf: address from which file shoud be played. * @param size: size of the current buffer/file. * @param cmd: command to be executed, can be AUDIO_CMD_PLAY , AUDIO_CMD_PAUSE, * AUDIO_CMD_RESUME or AUDIO_CMD_STOP. * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else. */ static uint8_t AudioCmd(uint8_t* pbuf, uint32_t size, uint8_t cmd) { /* Check the current state */ if ((AudioState == AUDIO_STATE_INACTIVE) || (AudioState == AUDIO_STATE_ERROR)) { AudioState = AUDIO_STATE_ERROR; return AUDIO_FAIL; } switch (cmd) { /* Process the PLAY command ----------------------------*/ case AUDIO_CMD_PLAY: /* If current state is Active or Stopped */ if ((AudioState == AUDIO_STATE_ACTIVE) || \ (AudioState == AUDIO_STATE_STOPPED) || \ (AudioState == AUDIO_STATE_PLAYING)) { Audio_MAL_Play((uint32_t)pbuf, (size/2)); AudioState = AUDIO_STATE_PLAYING; return AUDIO_OK; } /* If current state is Paused */ else if (AudioState == AUDIO_STATE_PAUSED) { if (EVAL_AUDIO_PauseResume(AUDIO_RESUME, (uint32_t)pbuf, (size/2)) != 0) { AudioState = AUDIO_STATE_ERROR; return AUDIO_FAIL; } else { AudioState = AUDIO_STATE_PLAYING; return AUDIO_OK; } } else /* Not allowed command */ { return AUDIO_FAIL; } /* Process the STOP command ----------------------------*/ case AUDIO_CMD_STOP: if (AudioState != AUDIO_STATE_PLAYING) { /* Unsupported command */ return AUDIO_FAIL; } else if (EVAL_AUDIO_Stop(CODEC_PDWN_SW) != 0) { AudioState = AUDIO_STATE_ERROR; return AUDIO_FAIL; } else { AudioState = AUDIO_STATE_STOPPED; return AUDIO_OK; } /* Process the PAUSE command ---------------------------*/ case AUDIO_CMD_PAUSE: if (AudioState != AUDIO_STATE_PLAYING) { /* Unsupported command */ return AUDIO_FAIL; } else if (EVAL_AUDIO_PauseResume(AUDIO_PAUSE, (uint32_t)pbuf, (size/2)) != 0) { AudioState = AUDIO_STATE_ERROR; return AUDIO_FAIL; } else { AudioState = AUDIO_STATE_PAUSED; return AUDIO_OK; } /* Unsupported command ---------------------------------*/ default: return AUDIO_FAIL; } } /** * @brief VolumeCtl * Set the volume level in % * @param vol: volume level to be set in % (from 0% to 100%) * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else. */ static uint8_t VolumeCtl (uint8_t vol) { /* Call low layer volume setting function */ if (EVAL_AUDIO_VolumeCtl(vol) != 0) { AudioState = AUDIO_STATE_ERROR; return AUDIO_FAIL; } return AUDIO_OK; } /** * @brief MuteCtl * Mute or Unmute the audio current output * @param cmd: can be 0 to unmute, or 1 to mute. * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else. */ static uint8_t MuteCtl (uint8_t cmd) { /* Call low layer mute setting function */ if (EVAL_AUDIO_Mute(cmd) != 0) { AudioState = AUDIO_STATE_ERROR; return AUDIO_FAIL; } return AUDIO_OK; } /** * @brief * * @param * @param * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else. */ static uint8_t PeriodicTC (uint8_t cmd) { return AUDIO_OK; } /** * @brief GetState * Return the current state of the audio machine * @param None * @retval Current State. */ static uint8_t GetState (void) { return AudioState; } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/audio/src/usbd_audio_out_if.c
C
lgpl
7,905
/** ****************************************************************************** * @file usbd_audio_out_if.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header file for the usbd_audio_out_if.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #ifndef __USB_AUDIO_OUT_IF_H_ #define __USB_AUDIO_OUT_IF_H_ #ifdef STM32F2XX #include "stm322xg_usb_audio_codec.h" #elif defined(STM32F10X_CL) #include "stm3210c_usb_audio_codec.h" #endif /* STM32F2XX */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_audio * @brief This file is the Header file for USBD_audio.c * @{ */ /** @defgroup usbd_audio_Exported_Defines * @{ */ /* Audio Commands enmueration */ typedef enum { AUDIO_CMD_PLAY = 1, AUDIO_CMD_PAUSE, AUDIO_CMD_STOP, }AUDIO_CMD_TypeDef; /* Mute commands */ #define AUDIO_MUTE 0x01 #define AUDIO_UNMUTE 0x00 /* Functions return value */ #define AUDIO_OK 0x00 #define AUDIO_FAIL 0xFF /* Audio Machine States */ #define AUDIO_STATE_INACTIVE 0x00 #define AUDIO_STATE_ACTIVE 0x01 #define AUDIO_STATE_PLAYING 0x02 #define AUDIO_STATE_PAUSED 0x03 #define AUDIO_STATE_STOPPED 0x04 #define AUDIO_STATE_ERROR 0x05 /** * @} */ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_Variables * @{ */ extern AUDIO_FOPS_TypeDef AUDIO_OUT_fops; /** * @} */ /** @defgroup USB_CORE_Exported_Functions * @{ */ /** * @} */ #endif /* __USB_AUDIO_OUT_IF_H_ */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/audio/inc/usbd_audio_out_if.h
C
lgpl
2,782
/** ****************************************************************************** * @file usbd_audio_core.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header file for the usbd_audio_core.c file. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #ifndef __USB_AUDIO_CORE_H_ #define __USB_AUDIO_CORE_H_ #include "usbd_ioreq.h" #include "usbd_req.h" #include "usbd_desc.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup usbd_audio * @brief This file is the Header file for USBD_audio.c * @{ */ /** @defgroup usbd_audio_Exported_Defines * @{ */ /* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */ #define AUDIO_OUT_PACKET (uint32_t)(((USBD_AUDIO_FREQ * 2 * 2) /1000)) /* Number of sub-packets in the audio transfer buffer. You can modify this value but always make sure that it is an even number and higher than 3 */ #define OUT_PACKET_NUM 4 /* Total size of the audio transfer buffer */ #define TOTAL_OUT_BUF_SIZE ((uint32_t)(AUDIO_OUT_PACKET * OUT_PACKET_NUM)) #define AUDIO_CONFIG_DESC_SIZE 109 #define AUDIO_INTERFACE_DESC_SIZE 9 #define USB_AUDIO_DESC_SIZ 0x09 #define AUDIO_STANDARD_ENDPOINT_DESC_SIZE 0x09 #define AUDIO_STREAMING_ENDPOINT_DESC_SIZE 0x07 #define AUDIO_DESCRIPTOR_TYPE 0x21 #define USB_DEVICE_CLASS_AUDIO 0x01 #define AUDIO_SUBCLASS_AUDIOCONTROL 0x01 #define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02 #define AUDIO_PROTOCOL_UNDEFINED 0x00 #define AUDIO_STREAMING_GENERAL 0x01 #define AUDIO_STREAMING_FORMAT_TYPE 0x02 /* Audio Descriptor Types */ #define AUDIO_INTERFACE_DESCRIPTOR_TYPE 0x24 #define AUDIO_ENDPOINT_DESCRIPTOR_TYPE 0x25 /* Audio Control Interface Descriptor Subtypes */ #define AUDIO_CONTROL_HEADER 0x01 #define AUDIO_CONTROL_INPUT_TERMINAL 0x02 #define AUDIO_CONTROL_OUTPUT_TERMINAL 0x03 #define AUDIO_CONTROL_FEATURE_UNIT 0x06 #define AUDIO_INPUT_TERMINAL_DESC_SIZE 0x0C #define AUDIO_OUTPUT_TERMINAL_DESC_SIZE 0x09 #define AUDIO_STREAMING_INTERFACE_DESC_SIZE 0x07 #define AUDIO_CONTROL_MUTE 0x0001 #define AUDIO_FORMAT_TYPE_I 0x01 #define AUDIO_FORMAT_TYPE_III 0x03 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 #define AUDIO_ENDPOINT_GENERAL 0x01 #define AUDIO_REQ_GET_CUR 0x81 #define AUDIO_REQ_SET_CUR 0x01 #define AUDIO_OUT_STREAMING_CTRL 0x02 /** * @} */ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ typedef struct _Audio_Fops { uint8_t (*Init) (uint32_t AudioFreq, uint32_t Volume, uint32_t options); uint8_t (*DeInit) (uint32_t options); uint8_t (*AudioCmd) (uint8_t* pbuf, uint32_t size, uint8_t cmd); uint8_t (*VolumeCtl) (uint8_t vol); uint8_t (*MuteCtl) (uint8_t cmd); uint8_t (*PeriodicTC) (uint8_t cmd); uint8_t (*GetState) (void); }AUDIO_FOPS_TypeDef; /** * @} */ /** @defgroup USBD_CORE_Exported_Macros * @{ */ #define AUDIO_PACKET_SZE(frq) (uint8_t)(((frq * 2 * 2)/1000) & 0xFF), \ (uint8_t)((((frq * 2 * 2)/1000) >> 8) & 0xFF) #define SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16)) /** * @} */ /** @defgroup USBD_CORE_Exported_Variables * @{ */ extern USBD_Class_cb_TypeDef AUDIO_cb; /** * @} */ /** @defgroup USB_CORE_Exported_Functions * @{ */ /** * @} */ #endif // __USB_AUDIO_CORE_H_ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Class/audio/inc/usbd_audio_core.h
C
lgpl
5,094
/** ****************************************************************************** * @file usbd_req.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides the standard USB requests following chapter 9. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_req.h" #include "usbd_ioreq.h" #include "usbd_desc.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_REQ * @brief USB standard requests module * @{ */ /** @defgroup USBD_REQ_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_REQ_Private_Defines * @{ */ /** * @} */ /** @defgroup USBD_REQ_Private_Macros * @{ */ /** * @} */ /** @defgroup USBD_REQ_Private_Variables * @{ */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint32_t USBD_ep_status __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint32_t USBD_default_cfg __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint32_t USBD_cfg_status __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ; /** * @} */ /** @defgroup USBD_REQ_Private_FunctionPrototypes * @{ */ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static void USBD_SetAddress(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static void USBD_ClrFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); static uint8_t USBD_GetLen(uint8_t *buf); /** * @} */ /** @defgroup USBD_REQ_Private_Functions * @{ */ /** * @brief USBD_StdDevReq * Handle standard usb device requests * @param pdev: device instance * @param req: usb request * @retval status */ USBD_Status USBD_StdDevReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { USBD_Status ret = USBD_OK; switch (req->bRequest) { case USB_REQ_GET_DESCRIPTOR: USBD_GetDescriptor (pdev, req) ; break; case USB_REQ_SET_ADDRESS: USBD_SetAddress(pdev, req); break; case USB_REQ_SET_CONFIGURATION: USBD_SetConfig (pdev , req); break; case USB_REQ_GET_CONFIGURATION: USBD_GetConfig (pdev , req); break; case USB_REQ_GET_STATUS: USBD_GetStatus (pdev , req); break; case USB_REQ_SET_FEATURE: USBD_SetFeature (pdev , req); break; case USB_REQ_CLEAR_FEATURE: USBD_ClrFeature (pdev , req); break; default: USBD_CtlError(pdev , req); break; } return ret; } /** * @brief USBD_StdItfReq * Handle standard usb interface requests * @param pdev: USB OTG device instance * @param req: usb request * @retval status */ USBD_Status USBD_StdItfReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { USBD_Status ret = USBD_OK; switch (pdev->dev.device_status) { case USB_OTG_CONFIGURED: if (LOBYTE(req->wIndex) <= USBD_ITF_MAX_NUM) { pdev->dev.class_cb->Setup (pdev, req); if((req->wLength == 0)&& (ret == USBD_OK)) { USBD_CtlSendStatus(pdev); } } else { USBD_CtlError(pdev , req); } break; default: USBD_CtlError(pdev , req); break; } return ret; } /** * @brief USBD_StdEPReq * Handle standard usb endpoint requests * @param pdev: USB OTG device instance * @param req: usb request * @retval status */ USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint8_t ep_addr; USBD_Status ret = USBD_OK; ep_addr = LOBYTE(req->wIndex); switch (req->bRequest) { case USB_REQ_SET_FEATURE : switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } break; case USB_OTG_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) { if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } } pdev->dev.class_cb->Setup (pdev, req); USBD_CtlSendStatus(pdev); break; default: USBD_CtlError(pdev , req); break; } break; case USB_REQ_CLEAR_FEATURE : switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } break; case USB_OTG_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) { if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_ClrStall(pdev , ep_addr); pdev->dev.class_cb->Setup (pdev, req); } USBD_CtlSendStatus(pdev); } break; default: USBD_CtlError(pdev , req); break; } break; case USB_REQ_GET_STATUS: switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } break; case USB_OTG_CONFIGURED: if ((ep_addr & 0x80)== 0x80) { if(pdev->dev.in_ep[ep_addr & 0x7F].is_stall) { USBD_ep_status = 0x0001; } else { USBD_ep_status = 0x0000; } } else if ((ep_addr & 0x80)== 0x00) { if(pdev->dev.out_ep[ep_addr].is_stall) { USBD_ep_status = 0x0001; } else { USBD_ep_status = 0x0000; } } USBD_CtlSendData (pdev, (uint8_t *)&USBD_ep_status, 2); break; default: USBD_CtlError(pdev , req); break; } break; default: break; } return ret; } /** * @brief USBD_GetDescriptor * Handle Get Descriptor requests * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint16_t len; uint8_t *pbuf; switch (req->wValue >> 8) { case USB_DESC_TYPE_DEVICE: pbuf = pdev->dev.usr_device->GetDeviceDescriptor(pdev->cfg.speed, &len); if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT)) { len = 8; } break; case USB_DESC_TYPE_CONFIGURATION: pbuf = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len); #ifdef USB_OTG_HS_CORE if((pdev->cfg.speed == USB_OTG_SPEED_FULL )&& (pdev->cfg.phy_itface == USB_OTG_ULPI_PHY)) { pbuf = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len); } #endif pbuf[1] = USB_DESC_TYPE_CONFIGURATION; pdev->dev.pConfig_descriptor = pbuf; break; case USB_DESC_TYPE_STRING: switch ((uint8_t)(req->wValue)) { case USBD_IDX_LANGID_STR: pbuf = pdev->dev.usr_device->GetLangIDStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_MFC_STR: pbuf = pdev->dev.usr_device->GetManufacturerStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_PRODUCT_STR: pbuf = pdev->dev.usr_device->GetProductStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_SERIAL_STR: pbuf = pdev->dev.usr_device->GetSerialStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_CONFIG_STR: pbuf = pdev->dev.usr_device->GetConfigurationStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_INTERFACE_STR: pbuf = pdev->dev.usr_device->GetInterfaceStrDescriptor(pdev->cfg.speed, &len); break; default: #ifdef USB_SUPPORT_USER_STRING_DESC pbuf = pdev->dev.class_cb->GetUsrStrDescriptor(pdev->cfg.speed, (req->wValue) , &len); break; #else USBD_CtlError(pdev , req); return; #endif /* USBD_CtlError(pdev , req); */ } break; case USB_DESC_TYPE_DEVICE_QUALIFIER: #ifdef USB_OTG_HS_CORE if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) { pbuf = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len); USBD_DeviceQualifierDesc[4]= pbuf[14]; USBD_DeviceQualifierDesc[5]= pbuf[15]; USBD_DeviceQualifierDesc[6]= pbuf[16]; pbuf = USBD_DeviceQualifierDesc; len = USB_LEN_DEV_QUALIFIER_DESC; break; } else { USBD_CtlError(pdev , req); return; } #else USBD_CtlError(pdev , req); return; #endif case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: #ifdef USB_OTG_HS_CORE if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) { pbuf = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len); pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; break; } else { USBD_CtlError(pdev , req); return; } #else USBD_CtlError(pdev , req); return; #endif default: USBD_CtlError(pdev , req); return; } if((len != 0)&& (req->wLength != 0)) { len = MIN(len , req->wLength); USBD_CtlSendData (pdev, pbuf, len); } } /** * @brief USBD_SetAddress * Set device address * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_SetAddress(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint8_t dev_addr; if ((req->wIndex == 0) && (req->wLength == 0)) { dev_addr = (uint8_t)(req->wValue) & 0x7F; if (pdev->dev.device_status == USB_OTG_CONFIGURED) { USBD_CtlError(pdev , req); } else { pdev->dev.device_address = dev_addr; DCD_EP_SetAddress(pdev, dev_addr); USBD_CtlSendStatus(pdev); if (dev_addr != 0) { pdev->dev.device_status = USB_OTG_ADDRESSED; } else { pdev->dev.device_status = USB_OTG_DEFAULT; } } } else { USBD_CtlError(pdev , req); } } /** * @brief USBD_SetConfig * Handle Set device configuration request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_SetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { static uint8_t cfgidx; cfgidx = (uint8_t)(req->wValue); if (cfgidx > USBD_CFG_MAX_NUM ) { USBD_CtlError(pdev , req); } else { switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: if (cfgidx) { pdev->dev.device_config = cfgidx; pdev->dev.device_status = USB_OTG_CONFIGURED; USBD_SetCfg(pdev , cfgidx); USBD_CtlSendStatus(pdev); } else { USBD_CtlSendStatus(pdev); } break; case USB_OTG_CONFIGURED: if (cfgidx == 0) { pdev->dev.device_status = USB_OTG_ADDRESSED; pdev->dev.device_config = cfgidx; USBD_ClrCfg(pdev , cfgidx); USBD_CtlSendStatus(pdev); } else if (cfgidx != pdev->dev.device_config) { /* Clear old configuration */ USBD_ClrCfg(pdev , pdev->dev.device_config); /* set new configuration */ pdev->dev.device_config = cfgidx; USBD_SetCfg(pdev , cfgidx); USBD_CtlSendStatus(pdev); } else { USBD_CtlSendStatus(pdev); } break; default: USBD_CtlError(pdev , req); break; } } } /** * @brief USBD_GetConfig * Handle Get device configuration request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { if (req->wLength != 1) { USBD_CtlError(pdev , req); } else { switch (pdev->dev.device_status ) { case USB_OTG_ADDRESSED: USBD_CtlSendData (pdev, (uint8_t *)&USBD_default_cfg, 1); break; case USB_OTG_CONFIGURED: USBD_CtlSendData (pdev, &pdev->dev.device_config, 1); break; default: USBD_CtlError(pdev , req); break; } } } /** * @brief USBD_GetStatus * Handle Get Status request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: case USB_OTG_CONFIGURED: if (pdev->dev.DevRemoteWakeup) { USBD_cfg_status = USB_CONFIG_SELF_POWERED | USB_CONFIG_REMOTE_WAKEUP; } else { USBD_cfg_status = USB_CONFIG_SELF_POWERED; } USBD_CtlSendData (pdev, (uint8_t *)&USBD_cfg_status, 1); break; default : USBD_CtlError(pdev , req); break; } } /** * @brief USBD_SetFeature * Handle Set device feature request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { USB_OTG_DCTL_TypeDef dctl; uint8_t test_mode = 0; if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { pdev->dev.DevRemoteWakeup = 1; pdev->dev.class_cb->Setup (pdev, req); USBD_CtlSendStatus(pdev); } else if ((req->wValue == USB_FEATURE_TEST_MODE) && ((req->wIndex & 0xFF) == 0)) { dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL); test_mode = req->wIndex >> 8; switch (test_mode) { case 1: // TEST_J dctl.b.tstctl = 1; break; case 2: // TEST_K dctl.b.tstctl = 2; break; case 3: // TEST_SE0_NAK dctl.b.tstctl = 3; break; case 4: // TEST_PACKET dctl.b.tstctl = 4; break; case 5: // TEST_FORCE_ENABLE dctl.b.tstctl = 5; break; } USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DCTL, dctl.d32); USBD_CtlSendStatus(pdev); } } /** * @brief USBD_ClrFeature * Handle clear device feature request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_ClrFeature(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: case USB_OTG_CONFIGURED: if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { pdev->dev.DevRemoteWakeup = 0; pdev->dev.class_cb->Setup (pdev, req); USBD_CtlSendStatus(pdev); } break; default : USBD_CtlError(pdev , req); break; } } /** * @brief USBD_ParseSetupRequest * Copy buffer into setup structure * @param pdev: device instance * @param req: usb request * @retval None */ void USBD_ParseSetupRequest( USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { req->bmRequest = *(uint8_t *) (pdev->dev.setup_packet); req->bRequest = *(uint8_t *) (pdev->dev.setup_packet + 1); req->wValue = SWAPBYTE (pdev->dev.setup_packet + 2); req->wIndex = SWAPBYTE (pdev->dev.setup_packet + 4); req->wLength = SWAPBYTE (pdev->dev.setup_packet + 6); pdev->dev.in_ep[0].ctl_data_len = req->wLength ; pdev->dev.device_state = USB_OTG_EP0_SETUP; } /** * @brief USBD_CtlError * Handle USB low level Error * @param pdev: device instance * @param req: usb request * @retval None */ void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { if((req->bmRequest & 0x80) == 0x80) { DCD_EP_Stall(pdev , 0x80); } else { if(req->wLength == 0) { DCD_EP_Stall(pdev , 0x80); } else { DCD_EP_Stall(pdev , 0); } } USB_OTG_EP0_OutStart(pdev); } /** * @brief USBD_GetString * Convert Ascii string into unicode one * @param desc : descriptor buffer * @param unicode : Formatted string buffer (unicode) * @param len : descriptor length * @retval None */ void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len) { uint8_t idx = 0; if (desc != NULL) { *len = USBD_GetLen(desc) * 2 + 2; unicode[idx++] = *len; unicode[idx++] = USB_DESC_TYPE_STRING; while (*desc != NULL) { unicode[idx++] = *desc++; unicode[idx++] = 0x00; } } } /** * @brief USBD_GetLen * return the string length * @param buf : pointer to the ascii string buffer * @retval string length */ static uint8_t USBD_GetLen(uint8_t *buf) { uint8_t len = 0; while (*buf != NULL) { len++; buf++; } return len; } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/src/usbd_req.c
C
lgpl
20,755
/** ****************************************************************************** * @file usbd_ioreq.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides the IO requests APIs for control endpoints. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_ioreq.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_IOREQ * @brief control I/O requests module * @{ */ /** @defgroup USBD_IOREQ_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Private_Defines * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Private_Macros * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Private_Variables * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Private_FunctionPrototypes * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Private_Functions * @{ */ /** * @brief USBD_CtlSendData * send data on the ctl pipe * @param pdev: device instance * @param buff: pointer to data buffer * @param len: length of data to be sent * @retval status */ USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; pdev->dev.in_ep[0].total_data_len = len; pdev->dev.in_ep[0].rem_data_len = len; pdev->dev.device_state = USB_OTG_EP0_DATA_IN; DCD_EP_Tx (pdev, 0, pbuf, len); return ret; } /** * @brief USBD_CtlContinueSendData * continue sending data on the ctl pipe * @param pdev: device instance * @param buff: pointer to data buffer * @param len: length of data to be sent * @retval status */ USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; DCD_EP_Tx (pdev, 0, pbuf, len); return ret; } /** * @brief USBD_CtlPrepareRx * receive data on the ctl pipe * @param pdev: USB OTG device instance * @param buff: pointer to data buffer * @param len: length of data to be received * @retval status */ USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; pdev->dev.out_ep[0].total_data_len = len; pdev->dev.out_ep[0].rem_data_len = len; pdev->dev.device_state = USB_OTG_EP0_DATA_OUT; DCD_EP_PrepareRx (pdev, 0, pbuf, len); return ret; } /** * @brief USBD_CtlContinueRx * continue receive data on the ctl pipe * @param pdev: USB OTG device instance * @param buff: pointer to data buffer * @param len: length of data to be received * @retval status */ USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len) { USBD_Status ret = USBD_OK; DCD_EP_PrepareRx (pdev, 0, pbuf, len); return ret; } /** * @brief USBD_CtlSendStatus * send zero lzngth packet on the ctl pipe * @param pdev: USB OTG device instance * @retval status */ USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev) { USBD_Status ret = USBD_OK; pdev->dev.device_state = USB_OTG_EP0_STATUS_IN; DCD_EP_Tx (pdev, 0, NULL, 0); USB_OTG_EP0_OutStart(pdev); return ret; } /** * @brief USBD_CtlReceiveStatus * receive zero lzngth packet on the ctl pipe * @param pdev: USB OTG device instance * @retval status */ USBD_Status USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE *pdev) { USBD_Status ret = USBD_OK; pdev->dev.device_state = USB_OTG_EP0_STATUS_OUT; DCD_EP_PrepareRx ( pdev, 0, NULL, 0); USB_OTG_EP0_OutStart(pdev); return ret; } /** * @brief USBD_GetRxCount * returns the received data length * @param pdev: USB OTG device instance * epnum: endpoint index * @retval Rx Data blength */ uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) { return pdev->dev.out_ep[epnum].xfer_count; } /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/src/usbd_ioreq.c
C
lgpl
5,617
/** ****************************************************************************** * @file usbd_core.c * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief This file provides all the USBD core functions. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbd_core.h" #include "usbd_req.h" #include "usbd_ioreq.h" #include "usb_dcd_int.h" #include "usb_bsp.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_CORE * @brief usbd core module * @{ */ /** @defgroup USBD_CORE_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_CORE_Private_Defines * @{ */ /** * @} */ /** @defgroup USBD_CORE_Private_Macros * @{ */ /** * @} */ /** @defgroup USBD_CORE_Private_FunctionPrototypes * @{ */ static uint8_t USBD_SetupStage(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); static uint8_t USBD_SOF(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_Reset(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_Suspend(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_Resume(USB_OTG_CORE_HANDLE *pdev); #ifdef VBUS_SENSING_ENABLED static uint8_t USBD_DevConnected(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_DevDisconnected(USB_OTG_CORE_HANDLE *pdev); #endif static uint8_t USBD_IsoINIncomplete(USB_OTG_CORE_HANDLE *pdev); static uint8_t USBD_IsoOUTIncomplete(USB_OTG_CORE_HANDLE *pdev); /** * @} */ /** @defgroup USBD_CORE_Private_Variables * @{ */ USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb = { USBD_DataOutStage, USBD_DataInStage, USBD_SetupStage, USBD_SOF, USBD_Reset, USBD_Suspend, USBD_Resume, USBD_IsoINIncomplete, USBD_IsoOUTIncomplete, #ifdef VBUS_SENSING_ENABLED USBD_DevConnected, USBD_DevDisconnected, #endif }; USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops = &USBD_DCD_INT_cb; /** * @} */ /** @defgroup USBD_CORE_Private_Functions * @{ */ /** * @brief USBD_Init * Initailizes the device stack and load the class driver * @param pdev: device instance * @param core_address: USB OTG core ID * @param class_cb: Class callback structure address * @param usr_cb: User callback structure address * @retval None */ void USBD_Init(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID, USBD_DEVICE *pDevice, USBD_Class_cb_TypeDef *class_cb, USBD_Usr_cb_TypeDef *usr_cb) { /* Hardware Init */ USB_OTG_BSP_Init(pdev); USBD_DeInit(pdev); /*Register class and user callbacks */ pdev->dev.class_cb = class_cb; pdev->dev.usr_cb = usr_cb; pdev->dev.usr_device = pDevice; /* set USB OTG core params */ DCD_Init(pdev , coreID); /* Upon Init call usr callback */ pdev->dev.usr_cb->Init(); /* Enable Interrupts */ USB_OTG_BSP_EnableInterrupt(pdev); } /** * @brief USBD_DeInit * Re-Initialize th deviuce library * @param pdev: device instance * @retval status: status */ USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev) { /* Software Init */ return USBD_OK; } /** * @brief USBD_SetupStage * Handle the setup stage * @param pdev: device instance * @retval status */ static uint8_t USBD_SetupStage(USB_OTG_CORE_HANDLE *pdev) { USB_SETUP_REQ req; USBD_ParseSetupRequest(pdev , &req); switch (req.bmRequest & 0x1F) { case USB_REQ_RECIPIENT_DEVICE: USBD_StdDevReq (pdev, &req); break; case USB_REQ_RECIPIENT_INTERFACE: USBD_StdItfReq(pdev, &req); break; case USB_REQ_RECIPIENT_ENDPOINT: USBD_StdEPReq(pdev, &req); break; default: DCD_EP_Stall(pdev , req.bmRequest & 0x80); break; } return USBD_OK; } /** * @brief USBD_DataOutStage * Handle data out stage * @param pdev: device instance * @param epnum: endpoint index * @retval status */ static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) { USB_OTG_EP *ep; if(epnum == 0) { ep = &pdev->dev.out_ep[0]; if ( pdev->dev.device_state == USB_OTG_EP0_DATA_OUT) { if(ep->rem_data_len > ep->maxpacket) { ep->rem_data_len -= ep->maxpacket; if(pdev->cfg.dma_enable == 1) { /* in slave mode this, is handled by the RxSTSQLvl ISR */ ep->xfer_buff += ep->maxpacket; } USBD_CtlContinueRx (pdev, ep->xfer_buff, MIN(ep->rem_data_len ,ep->maxpacket)); } else { if((pdev->dev.class_cb->EP0_RxReady != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { pdev->dev.class_cb->EP0_RxReady(pdev); } USBD_CtlSendStatus(pdev); } } } else if((pdev->dev.class_cb->DataOut != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { pdev->dev.class_cb->DataOut(pdev, epnum); } return USBD_OK; } /** * @brief USBD_DataInStage * Handle data in stage * @param pdev: device instance * @param epnum: endpoint index * @retval status */ static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) { USB_OTG_EP *ep; if(epnum == 0) { ep = &pdev->dev.in_ep[0]; if ( pdev->dev.device_state == USB_OTG_EP0_DATA_IN) { if(ep->rem_data_len > ep->maxpacket) { ep->rem_data_len -= ep->maxpacket; if(pdev->cfg.dma_enable == 1) { /* in slave mode this, is handled by the TxFifoEmpty ISR */ ep->xfer_buff += ep->maxpacket; } USBD_CtlContinueSendData (pdev, ep->xfer_buff, ep->rem_data_len); } else { /* last packet is MPS multiple, so send ZLP packet */ if((ep->total_data_len % ep->maxpacket == 0) && (ep->total_data_len >= ep->maxpacket) && (ep->total_data_len < ep->ctl_data_len )) { USBD_CtlContinueSendData(pdev , NULL, 0); ep->ctl_data_len = 0; } else { if((pdev->dev.class_cb->EP0_TxSent != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { pdev->dev.class_cb->EP0_TxSent(pdev); } USBD_CtlReceiveStatus(pdev); } } } } else if((pdev->dev.class_cb->DataIn != NULL)&& (pdev->dev.device_status == USB_OTG_CONFIGURED)) { pdev->dev.class_cb->DataIn(pdev, epnum); } return USBD_OK; } /** * @brief USBD_Reset * Handle Reset event * @param pdev: device instance * @retval status */ static uint8_t USBD_Reset(USB_OTG_CORE_HANDLE *pdev) { /* Open EP0 OUT */ DCD_EP_Open(pdev, 0x00, USB_OTG_MAX_EP0_SIZE, EP_TYPE_CTRL); /* Open EP0 IN */ DCD_EP_Open(pdev, 0x80, USB_OTG_MAX_EP0_SIZE, EP_TYPE_CTRL); /* Upon Reset call usr call back */ pdev->dev.device_status = USB_OTG_DEFAULT; pdev->dev.usr_cb->DeviceReset(pdev->cfg.speed); return USBD_OK; } /** * @brief USBD_Resume * Handle Resume event * @param pdev: device instance * @retval status */ static uint8_t USBD_Resume(USB_OTG_CORE_HANDLE *pdev) { /* Upon Resume call usr call back */ pdev->dev.usr_cb->DeviceResumed(); pdev->dev.device_status = USB_OTG_CONFIGURED; return USBD_OK; } /** * @brief USBD_Suspend * Handle Suspend event * @param pdev: device instance * @retval status */ static uint8_t USBD_Suspend(USB_OTG_CORE_HANDLE *pdev) { pdev->dev.device_status = USB_OTG_SUSPENDED; /* Upon Resume call usr call back */ pdev->dev.usr_cb->DeviceSuspended(); return USBD_OK; } /** * @brief USBD_SOF * Handle SOF event * @param pdev: device instance * @retval status */ static uint8_t USBD_SOF(USB_OTG_CORE_HANDLE *pdev) { if(pdev->dev.class_cb->SOF) { pdev->dev.class_cb->SOF(pdev); } return USBD_OK; } /** * @brief USBD_SetCfg * Configure device and start the interface * @param pdev: device instance * @param cfgidx: configuration index * @retval status */ USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx) { pdev->dev.class_cb->Init(pdev, cfgidx); /* Upon set config call usr call back */ pdev->dev.usr_cb->DeviceConfigured(); return USBD_OK; } /** * @brief USBD_ClrCfg * Clear current configuration * @param pdev: device instance * @param cfgidx: configuration index * @retval status: USBD_Status */ USBD_Status USBD_ClrCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx) { pdev->dev.class_cb->DeInit(pdev, cfgidx); return USBD_OK; } /** * @brief USBD_IsoINIncomplete * Handle iso in incomplete event * @param pdev: device instance * @retval status */ static uint8_t USBD_IsoINIncomplete(USB_OTG_CORE_HANDLE *pdev) { pdev->dev.class_cb->IsoINIncomplete(pdev); return USBD_OK; } /** * @brief USBD_IsoOUTIncomplete * Handle iso out incomplete event * @param pdev: device instance * @retval status */ static uint8_t USBD_IsoOUTIncomplete(USB_OTG_CORE_HANDLE *pdev) { pdev->dev.class_cb->IsoOUTIncomplete(pdev); return USBD_OK; } #ifdef VBUS_SENSING_ENABLED /** * @brief USBD_DevConnected * Handle device connection event * @param pdev: device instance * @retval status */ static uint8_t USBD_DevConnected(USB_OTG_CORE_HANDLE *pdev) { pdev->dev.usr_cb->DeviceConnected(); return USBD_OK; } /** * @brief USBD_DevDisconnected * Handle device disconnection event * @param pdev: device instance * @retval status */ static uint8_t USBD_DevDisconnected(USB_OTG_CORE_HANDLE *pdev) { pdev->dev.usr_cb->DeviceDisconnected(); pdev->dev.class_cb->DeInit(pdev, 0); return USBD_OK; } #endif /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/src/usbd_core.c
C
lgpl
11,329
/** ****************************************************************************** * @file usbd_conf_template.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief usb device configuration template file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_CONF__H__ #define __USBD_CONF__H__ /* Includes ------------------------------------------------------------------*/ #include "stm32f2xx.h" /** @defgroup USB_CONF_Exported_Defines * @{ */ #define USE_USB_OTG_HS #define USBD_CFG_MAX_NUM 1 #define USB_MAX_STR_DESC_SIZ 64 #define USBD_EP0_MAX_PACKET_SIZE 64 /** * @} */ /** @defgroup USB_CONF_Exported_Types * @{ */ /** * @} */ /** @defgroup USB_CONF_Exported_Macros * @{ */ /** * @} */ /** @defgroup USB_CONF_Exported_Variables * @{ */ /** * @} */ /** @defgroup USB_CONF_Exported_FunctionsPrototype * @{ */ /** * @} */ #endif //__USBD_CONF__H__ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/inc/usbd_conf_template.h
C
lgpl
1,916
/** ****************************************************************************** * @file usbd_usr.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Header file for usbd_usr.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_USR_H__ #define __USBD_USR_H__ /* Includes ------------------------------------------------------------------*/ #include "usbd_core.h" /** @addtogroup USBD_USER * @{ */ /** @addtogroup USBD_MSC_DEMO_USER_CALLBACKS * @{ */ /** @defgroup USBD_USR * @brief This file is the Header file for usbd_usr.c * @{ */ /** @defgroup USBD_USR_Exported_Types * @{ */ extern USBD_Usr_cb_TypeDef USR_cb; extern USBD_Usr_cb_TypeDef USR_FS_cb; extern USBD_Usr_cb_TypeDef USR_HS_cb; /** * @} */ /** @defgroup USBD_USR_Exported_Defines * @{ */ /** * @} */ /** @defgroup USBD_USR_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_USR_Exported_Variables * @{ */ void USBD_USR_Init(void); void USBD_USR_DeviceReset (uint8_t speed); void USBD_USR_DeviceConfigured (void); void USBD_USR_DeviceSuspended(void); void USBD_USR_DeviceResumed(void); void USBD_USR_DeviceConnected(void); void USBD_USR_DeviceDisconnected(void); void USBD_USR_FS_Init(void); void USBD_USR_FS_DeviceReset (uint8_t speed); void USBD_USR_FS_DeviceConfigured (void); void USBD_USR_FS_DeviceSuspended(void); void USBD_USR_FS_DeviceResumed(void); void USBD_USR_FS_DeviceConnected(void); void USBD_USR_FS_DeviceDisconnected(void); void USBD_USR_HS_Init(void); void USBD_USR_HS_DeviceReset (uint8_t speed); void USBD_USR_HS_DeviceConfigured (void); void USBD_USR_HS_DeviceSuspended(void); void USBD_USR_HS_DeviceResumed(void); void USBD_USR_HS_DeviceConnected(void); void USBD_USR_HS_DeviceDisconnected(void); /** * @} */ /** @defgroup USBD_USR_Exported_FunctionsPrototype * @{ */ /** * @} */ #endif /*__USBD_USR_H__*/ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/inc/usbd_usr.h
C
lgpl
3,080
/** ****************************************************************************** * @file usbd_core.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief Header file for usbd_core.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_CORE_H #define __USBD_CORE_H /* Includes ------------------------------------------------------------------*/ #include "usb_dcd.h" #include "usbd_def.h" #include "usbd_conf.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_CORE * @brief This file is the Header file for usbd_core.c file * @{ */ /** @defgroup USBD_CORE_Exported_Defines * @{ */ typedef enum { USBD_OK = 0, USBD_BUSY, USBD_FAIL, }USBD_Status; /** * @} */ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBD_CORE_Exported_FunctionsPrototype * @{ */ void USBD_Init(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID, USBD_DEVICE *pDevice, USBD_Class_cb_TypeDef *class_cb, USBD_Usr_cb_TypeDef *usr_cb); USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev); USBD_Status USBD_ClrCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx); USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx); /** * @} */ #endif /* __USBD_CORE_H */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/inc/usbd_core.h
C
lgpl
2,550
/** ****************************************************************************** * @file usbd_ioreq.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header file for the usbd_ioreq.c file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_IOREQ_H_ #define __USBD_IOREQ_H_ /* Includes ------------------------------------------------------------------*/ #include "usbd_def.h" #include "usbd_core.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_IOREQ * @brief header file for the usbd_ioreq.c file * @{ */ /** @defgroup USBD_IOREQ_Exported_Defines * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Exported_Types * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype * @{ */ USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *buf, uint16_t len); USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len); USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len); USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len); USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev); USBD_Status USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE *pdev); uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); /** * @} */ #endif /* __USBD_IOREQ_H_ */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/inc/usbd_ioreq.h
C
lgpl
2,944
/** ****************************************************************************** * @file usbd_req.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief header file for the usbd_req.c file ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USB_REQUEST_H_ #define __USB_REQUEST_H_ /* Includes ------------------------------------------------------------------*/ #include "usbd_def.h" #include "usbd_core.h" #include "usbd_conf.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_REQ * @brief header file for the usbd_ioreq.c file * @{ */ /** @defgroup USBD_REQ_Exported_Defines * @{ */ /** * @} */ /** @defgroup USBD_REQ_Exported_Types * @{ */ /** * @} */ /** @defgroup USBD_REQ_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_REQ_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBD_REQ_Exported_FunctionsPrototype * @{ */ USBD_Status USBD_StdDevReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); USBD_Status USBD_StdItfReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); void USBD_ParseSetupRequest( USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); /** * @} */ #endif /* __USB_REQUEST_H_ */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/inc/usbd_req.h
C
lgpl
2,536
/** ****************************************************************************** * @file usbd_def.h * @author MCD Application Team * @version V1.0.0 * @date 22-July-2011 * @brief general defines for the usb device library ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_DEF_H #define __USBD_DEF_H /* Includes ------------------------------------------------------------------*/ #include "usbd_conf.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USB_DEF * @brief general defines for the usb device library file * @{ */ /** @defgroup USB_DEF_Exported_Defines * @{ */ #ifndef NULL #define NULL 0 #endif #define USB_LEN_DEV_QUALIFIER_DESC 0x0A #define USB_LEN_DEV_DESC 0x12 #define USB_LEN_CFG_DESC 0x09 #define USB_LEN_IF_DESC 0x09 #define USB_LEN_EP_DESC 0x07 #define USB_LEN_OTG_DESC 0x03 #define USBD_IDX_LANGID_STR 0x00 #define USBD_IDX_MFC_STR 0x01 #define USBD_IDX_PRODUCT_STR 0x02 #define USBD_IDX_SERIAL_STR 0x03 #define USBD_IDX_CONFIG_STR 0x04 #define USBD_IDX_INTERFACE_STR 0x05 #define USB_REQ_TYPE_STANDARD 0x00 #define USB_REQ_TYPE_CLASS 0x20 #define USB_REQ_TYPE_VENDOR 0x40 #define USB_REQ_TYPE_MASK 0x60 #define USB_REQ_RECIPIENT_DEVICE 0x00 #define USB_REQ_RECIPIENT_INTERFACE 0x01 #define USB_REQ_RECIPIENT_ENDPOINT 0x02 #define USB_REQ_RECIPIENT_MASK 0x03 #define USB_REQ_GET_STATUS 0x00 #define USB_REQ_CLEAR_FEATURE 0x01 #define USB_REQ_SET_FEATURE 0x03 #define USB_REQ_SET_ADDRESS 0x05 #define USB_REQ_GET_DESCRIPTOR 0x06 #define USB_REQ_SET_DESCRIPTOR 0x07 #define USB_REQ_GET_CONFIGURATION 0x08 #define USB_REQ_SET_CONFIGURATION 0x09 #define USB_REQ_GET_INTERFACE 0x0A #define USB_REQ_SET_INTERFACE 0x0B #define USB_REQ_SYNCH_FRAME 0x0C #define USB_DESC_TYPE_DEVICE 1 #define USB_DESC_TYPE_CONFIGURATION 2 #define USB_DESC_TYPE_STRING 3 #define USB_DESC_TYPE_INTERFACE 4 #define USB_DESC_TYPE_ENDPOINT 5 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 #define USB_CONFIG_REMOTE_WAKEUP 2 #define USB_CONFIG_SELF_POWERED 1 #define USB_FEATURE_EP_HALT 0 #define USB_FEATURE_REMOTE_WAKEUP 1 #define USB_FEATURE_TEST_MODE 2 /** * @} */ /** @defgroup USBD_DEF_Exported_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_DEF_Exported_Macros * @{ */ #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) #define LOBYTE(x) ((uint8_t)(x & 0x00FF)) #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) /** * @} */ /** @defgroup USBD_DEF_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBD_DEF_Exported_FunctionsPrototype * @{ */ /** * @} */ #endif /* __USBD_DEF_H */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_Device_Library/Core/inc/usbd_def.h
C
lgpl
4,951
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <link rel="File-List" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/filelist.xml"> <link rel="Edit-Time-Data" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/editdata.mso"><!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--> <title>Release Notes for STM32F105/7xx and STM32F2xx USB Host Library</title><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>STMicroelectronics</o:Author> <o:LastAuthor>Raouf Hosni</o:LastAuthor> <o:Revision>39</o:Revision> <o:TotalTime>137</o:TotalTime> <o:Created>2009-02-27T19:26:00Z</o:Created> <o:LastSaved>2010-10-15T11:07:00Z</o:LastSaved> <o:Pages>3</o:Pages> <o:Words>973</o:Words> <o:Characters>5548</o:Characters> <o:Company>STMicroelectronics</o:Company> <o:Lines>46</o:Lines> <o:Paragraphs>13</o:Paragraphs> <o:CharactersWithSpaces>6508</o:CharactersWithSpaces> <o:Version>12.00</o:Version> </o:DocumentProperties> </xml><![endif]--><link rel="themeData" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/themedata.thmx"> <link rel="colorSchemeMapping" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/colorschememapping.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>110</w:Zoom> <w:TrackMoves>false</w:TrackMoves> <w:TrackFormatting/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="&#45;-"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" LatentStyleCount="267"> <w:LsdException Locked="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="99" Name="No List"/> <w:LsdException Locked="false" Priority="99" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" Priority="99" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--> <style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:1627400839 -2147483648 8 0 66047 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";} h1 {mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"Heading 1 Char"; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; mso-outline-level:1; font-size:24.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; font-weight:bold;} h2 {mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"Heading 2 Char"; mso-style-next:Normal; margin-top:12.0pt; margin-right:0in; margin-bottom:3.0pt; margin-left:0in; mso-pagination:widow-orphan; page-break-after:avoid; mso-outline-level:2; font-size:14.0pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; font-weight:bold; font-style:italic;} h3 {mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"Heading 3 Char"; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; mso-outline-level:3; font-size:13.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; font-weight:bold;} a:link, span.MsoHyperlink {mso-style-unhide:no; color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-unhide:no; color:blue; text-decoration:underline; text-underline:single;} p {mso-style-unhide:no; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";} p.MsoAcetate, li.MsoAcetate, div.MsoAcetate {mso-style-unhide:no; mso-style-link:"Balloon Text Char"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:8.0pt; font-family:"Tahoma","sans-serif"; mso-fareast-font-family:"Times New Roman";} span.Heading1Char {mso-style-name:"Heading 1 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 1"; mso-ansi-font-size:14.0pt; mso-bidi-font-size:14.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#365F91; mso-themecolor:accent1; mso-themeshade:191; font-weight:bold;} span.Heading2Char {mso-style-name:"Heading 2 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 2"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:13.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#4F81BD; mso-themecolor:accent1; font-weight:bold;} span.Heading3Char {mso-style-name:"Heading 3 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 3"; mso-ansi-font-size:12.0pt; mso-bidi-font-size:12.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#4F81BD; mso-themecolor:accent1; font-weight:bold;} span.BalloonTextChar {mso-style-name:"Balloon Text Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Balloon Text"; mso-ansi-font-size:8.0pt; mso-bidi-font-size:8.0pt; font-family:"Tahoma","sans-serif"; mso-ascii-font-family:Tahoma; mso-hansi-font-family:Tahoma; mso-bidi-font-family:Tahoma;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} /* List Definitions */ @list l0 {mso-list-id:62067358; mso-list-template-ids:-174943062;} @list l0:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l0:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l0:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1 {mso-list-id:128015942; mso-list-template-ids:-90681214;} @list l1:level1 {mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l1:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2 {mso-list-id:216556000; mso-list-template-ids:925924412;} @list l2:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l2:level2 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l2:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l2:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3 {mso-list-id:562446694; mso-list-template-ids:913898366;} @list l3:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l3:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l3:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4 {mso-list-id:797802132; mso-list-template-ids:-1971191336;} @list l4:level1 {mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l4:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5 {mso-list-id:907304066; mso-list-template-ids:1969781532;} @list l5:level1 {mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l5:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6 {mso-list-id:1050613616; mso-list-template-ids:-1009886748;} @list l6:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l6:level2 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l6:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l6:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7 {mso-list-id:1234970193; mso-list-template-ids:2055904002;} @list l7:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l7:level2 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l7:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l7:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8 {mso-list-id:1846092290; mso-list-template-ids:-768590846;} @list l8:level1 {mso-level-start-at:2; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l8:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9 {mso-list-id:1894656566; mso-list-template-ids:1199983812;} @list l9:level1 {mso-level-start-at:2; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level2 {mso-level-tab-stop:1.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level3 {mso-level-tab-stop:1.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level4 {mso-level-tab-stop:2.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level5 {mso-level-tab-stop:2.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level6 {mso-level-tab-stop:3.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level7 {mso-level-tab-stop:3.5in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level8 {mso-level-tab-stop:4.0in; mso-level-number-position:left; text-indent:-.25in;} @list l9:level9 {mso-level-tab-stop:4.5in; mso-level-number-position:left; text-indent:-.25in;} ol {margin-bottom:0in;} ul {margin-bottom:0in;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="7170"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--></head> <body style="" lang="EN-US" link="blue" vlink="blue"> <div class="WordSection1"> <p class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;;"><o:p>&nbsp;</o:p></span></p> <div align="center"> <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900"> <tbody><tr style=""> <td style="padding: 0in;" valign="top"> <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900"> <tbody><tr style=""> <td style="padding: 0in 5.4pt;" valign="top"> <p class="MsoNormal"><span style="font-size: 8pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: blue;"><a href="../../Release_Notes.html">Back to Release page</a></span><span style="font-size: 10pt;"><o:p></o:p></span></p> </td> </tr> <tr style=""> <td style="padding: 1.5pt;"> <h1 style="margin-bottom: 0.25in; text-align: center;" align="center"><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: rgb(51, 102, 255);">Release Notes for STM32F105/7xx and STM32F2xx USB Host Library</span><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><o:p></o:p></span></h1> <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;">Copyright 2011 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p> <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;"><img id="_x0000_i1026" src="../../_htmresc/logo.bmp" border="0" height="65" width="86"></span><span style="font-size: 10pt;"><o:p></o:p></span></p> </td> </tr> </tbody></table> <p class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; display: none;"><o:p>&nbsp;</o:p></span></p> <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900"> <tbody><tr style=""> <td style="padding: 0in;" valign="top"> <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><span style="font-size: 12pt; color: white;">Contents<o:p></o:p></span></h2> <ol style="margin-top: 0in;" start="1" type="1"> <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><a href="#History">STM32F105/7xx and STM32F2xx USB Host Library&nbsp;update History</a><o:p></o:p></span></li> <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><a href="#License">License</a><o:p></o:p></span></li> </ol> <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">STM32F105/7xx and STM32F2xx USB Host Library&nbsp; update History</span></h2><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 171px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.0.0 / 22-July-2011 <o:p></o:p></span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main Changes<o:p></o:p></span></u></b></p> <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Second official version supporting STM32F105/7 and STM32F2xx devices</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Add support for <span style="font-weight: bold; font-style: italic;">STM32F2xx</span> devices</span><span style="font-size: 10pt; font-family: Verdana;"></span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Add multi interface feature</span><span style="font-size: 10pt; font-family: Verdana;"></span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Add dynamic configuration parsing</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Add USBH_DeAllocate_AllChannel function in the Host channel management layer to clean up channels allocation table when de-initializing the library</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Change the core layer to stop correctly the host core and free all allocated channels</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Add usbh_conf.h file in the application layer to customize some user parameters</span></li></ul><span style="font-size: 10pt; font-family: Verdana;"><br></span><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 171px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0&nbsp;- 11/29/2010<o:p></o:p></span></h3> <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Created&nbsp;</span></li></ul><h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2> <p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: black;">The use of this STM32 software is governed by the terms and conditions of the License Agreement </span><span style="font-size: 10pt; font-family: Verdana; color: black;"><span style="font-weight: bold; font-style: italic;">"MCD-ST Liberty SW License Agreement 20Jul2011 v0.1.pdf"</span> </span><span style="font-size: 10pt; font-family: Verdana; color: black;">available in the root of this package.</span><span style="color: black;"><o:p>&nbsp;</o:p></span></p> <div class="MsoNormal" style="text-align: center;" align="center"><span style="color: black;"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNormal" style="margin: 4.5pt 0in 4.5pt 0.25in; text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">For complete documentation on </span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">STM32(<span style="color: black;">CORTEX M3) 32-Bit Microcontrollers visit </span><u><span style="color: blue;"><a href="http://www.st.com/stm32" target="_blank">www.st.com/STM32</a></span></u></span><span style="color: black;"><o:p></o:p></span></p> </td> </tr> </tbody></table> <p class="MsoNormal"><span style="font-size: 10pt;"><o:p></o:p></span></p> </td> </tr> </tbody></table> </div> <p class="MsoNormal"><o:p>&nbsp;</o:p></p> </div> </body></html>
1137519-player
lib/STM32_USB_HOST_Library/Release_Notes.html
HTML
lgpl
39,097
/** ****************************************************************************** * @file usbh_msc_core.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file implements the MSC class driver functions * =================================================================== * MSC Class Description * =================================================================== * This module manages the MSC class V1.0 following the "Universal * Serial Bus Mass Storage Class (MSC) Bulk-Only Transport (BOT) Version 1.0 * Sep. 31, 1999". * This driver implements the following aspects of the specification: * - Bulk-Only Transport protocol * - Subclass : SCSI transparent command set (ref. SCSI Primary Commands - 3 (SPC-3)) * * @endverbatim * ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> */ /* Includes ------------------------------------------------------------------*/ #include "usbh_msc_core.h" #include "usbh_msc_scsi.h" #include "usbh_msc_bot.h" #include "usbh_core.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_MSC_CLASS * @{ */ /** @defgroup USBH_MSC_CORE * @brief This file includes the mass storage related functions * @{ */ /** @defgroup USBH_MSC_CORE_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_MSC_CORE_Private_Defines * @{ */ #define USBH_MSC_ERROR_RETRY_LIMIT 10 /** * @} */ /** @defgroup USBH_MSC_CORE_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_MSC_CORE_Private_Variables * @{ */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN MSC_Machine_TypeDef MSC_Machine __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN USB_Setup_TypeDef MSC_Setup __ALIGN_END ; uint8_t MSCErrorCount = 0; /** * @} */ /** @defgroup USBH_MSC_CORE_Private_FunctionPrototypes * @{ */ static USBH_Status USBH_MSC_InterfaceInit (USB_OTG_CORE_HANDLE *pdev , void *phost); static void USBH_MSC_InterfaceDeInit (USB_OTG_CORE_HANDLE *pdev , void *phost); static USBH_Status USBH_MSC_Handle(USB_OTG_CORE_HANDLE *pdev , void *phost); static USBH_Status USBH_MSC_ClassRequest(USB_OTG_CORE_HANDLE *pdev , void *phost); static USBH_Status USBH_MSC_BOTReset(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost); static USBH_Status USBH_MSC_GETMaxLUN(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost); USBH_Class_cb_TypeDef USBH_MSC_cb = { USBH_MSC_InterfaceInit, USBH_MSC_InterfaceDeInit, USBH_MSC_ClassRequest, USBH_MSC_Handle, }; void USBH_MSC_ErrorHandle(uint8_t status); /** * @} */ /** @defgroup USBH_MSC_CORE_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBH_MSC_CORE_Private_Functions * @{ */ /** * @brief USBH_MSC_InterfaceInit * Interface initialization for MSC class. * @param pdev: Selected device * @param hdev: Selected device property * @retval USBH_Status : Status of class request handled. */ static USBH_Status USBH_MSC_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev, void *phost) { USBH_HOST *pphost = phost; if((pphost->device_prop.Itf_Desc[0].bInterfaceClass == MSC_CLASS) && \ (pphost->device_prop.Itf_Desc[0].bInterfaceProtocol == MSC_PROTOCOL)) { if(pphost->device_prop.Ep_Desc[0][0].bEndpointAddress & 0x80) { MSC_Machine.MSBulkInEp = (pphost->device_prop.Ep_Desc[0][0].bEndpointAddress); MSC_Machine.MSBulkInEpSize = pphost->device_prop.Ep_Desc[0][0].wMaxPacketSize; } else { MSC_Machine.MSBulkOutEp = (pphost->device_prop.Ep_Desc[0][0].bEndpointAddress); MSC_Machine.MSBulkOutEpSize = pphost->device_prop.Ep_Desc[0] [0].wMaxPacketSize; } if(pphost->device_prop.Ep_Desc[0][1].bEndpointAddress & 0x80) { MSC_Machine.MSBulkInEp = (pphost->device_prop.Ep_Desc[0][1].bEndpointAddress); MSC_Machine.MSBulkInEpSize = pphost->device_prop.Ep_Desc[0][1].wMaxPacketSize; } else { MSC_Machine.MSBulkOutEp = (pphost->device_prop.Ep_Desc[0][1].bEndpointAddress); MSC_Machine.MSBulkOutEpSize = pphost->device_prop.Ep_Desc[0][1].wMaxPacketSize; } MSC_Machine.hc_num_out = USBH_Alloc_Channel(pdev, MSC_Machine.MSBulkOutEp); MSC_Machine.hc_num_in = USBH_Alloc_Channel(pdev, MSC_Machine.MSBulkInEp); /* Open the new channels */ USBH_Open_Channel (pdev, MSC_Machine.hc_num_out, pphost->device_prop.address, pphost->device_prop.speed, EP_TYPE_BULK, MSC_Machine.MSBulkOutEpSize); USBH_Open_Channel (pdev, MSC_Machine.hc_num_in, pphost->device_prop.address, pphost->device_prop.speed, EP_TYPE_BULK, MSC_Machine.MSBulkInEpSize); } else { pphost->usr_cb->USBH_USR_DeviceNotSupported(); } return USBH_OK ; } /** * @brief USBH_MSC_InterfaceDeInit * De-Initialize interface by freeing host channels allocated to interface * @param pdev: Selected device * @param hdev: Selected device property * @retval None */ void USBH_MSC_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev, void *phost) { if ( MSC_Machine.hc_num_out) { USB_OTG_HC_Halt(pdev, MSC_Machine.hc_num_out); USBH_Free_Channel (pdev, MSC_Machine.hc_num_out); MSC_Machine.hc_num_out = 0; /* Reset the Channel as Free */ } if ( MSC_Machine.hc_num_in) { USB_OTG_HC_Halt(pdev, MSC_Machine.hc_num_in); USBH_Free_Channel (pdev, MSC_Machine.hc_num_in); MSC_Machine.hc_num_in = 0; /* Reset the Channel as Free */ } } /** * @brief USBH_MSC_ClassRequest * This function will only initialize the MSC state machine * @param pdev: Selected device * @param hdev: Selected device property * @retval USBH_Status : Status of class request handled. */ static USBH_Status USBH_MSC_ClassRequest(USB_OTG_CORE_HANDLE *pdev , void *phost) { USBH_Status status = USBH_OK ; USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_INIT_STATE; return status; } /** * @brief USBH_MSC_Handle * MSC state machine handler * @param pdev: Selected device * @param hdev: Selected device property * @retval USBH_Status */ static USBH_Status USBH_MSC_Handle(USB_OTG_CORE_HANDLE *pdev , void *phost) { USBH_HOST *pphost = phost; USBH_Status status = USBH_BUSY; uint8_t mscStatus = USBH_MSC_BUSY; uint8_t appliStatus = 0; static uint8_t maxLunExceed = FALSE; if(HCD_IsDeviceConnected(pdev)) { switch(USBH_MSC_BOTXferParam.MSCState) { case USBH_MSC_BOT_INIT_STATE: USBH_MSC_Init(pdev); USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_RESET; break; case USBH_MSC_BOT_RESET: /* Issue BOT RESET request */ status = USBH_MSC_BOTReset(pdev, phost); if(status == USBH_OK ) { USBH_MSC_BOTXferParam.MSCState = USBH_MSC_GET_MAX_LUN; } if(status == USBH_NOT_SUPPORTED ) { /* If the Command has failed, then we need to move to Next State, after STALL condition is cleared by Control-Transfer */ USBH_MSC_BOTXferParam.MSCStateBkp = USBH_MSC_GET_MAX_LUN; /* a Clear Feature should be issued here */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_CTRL_ERROR_STATE; } break; case USBH_MSC_GET_MAX_LUN: /* Issue GetMaxLUN request */ status = USBH_MSC_GETMaxLUN(pdev, phost); if(status == USBH_OK ) { MSC_Machine.maxLun = *(MSC_Machine.buff) ; /* If device has more that one logical unit then it is not supported */ if((MSC_Machine.maxLun > 0) && (maxLunExceed == FALSE)) { maxLunExceed = TRUE; pphost->usr_cb->USBH_USR_DeviceNotSupported(); break; } USBH_MSC_BOTXferParam.MSCState = USBH_MSC_TEST_UNIT_READY; } if(status == USBH_NOT_SUPPORTED ) { /* If the Command has failed, then we need to move to Next State, after STALL condition is cleared by Control-Transfer */ USBH_MSC_BOTXferParam.MSCStateBkp = USBH_MSC_TEST_UNIT_READY; /* a Clear Feature should be issued here */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_CTRL_ERROR_STATE; } break; case USBH_MSC_CTRL_ERROR_STATE: /* Issue Clearfeature request */ status = USBH_ClrFeature(pdev, phost, 0x00, pphost->Control.hc_num_out); if(status == USBH_OK ) { /* If GetMaxLun Request not support, assume Single LUN configuration */ MSC_Machine.maxLun = 0; USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOTXferParam.MSCStateBkp; } break; case USBH_MSC_TEST_UNIT_READY: /* Issue SCSI command TestUnitReady */ mscStatus = USBH_MSC_TestUnitReady(pdev); if(mscStatus == USBH_MSC_OK ) { USBH_MSC_BOTXferParam.MSCState = USBH_MSC_READ_CAPACITY10; MSCErrorCount = 0; status = USBH_OK; } else { USBH_MSC_ErrorHandle(mscStatus); } break; case USBH_MSC_READ_CAPACITY10: /* Issue READ_CAPACITY10 SCSI command */ mscStatus = USBH_MSC_ReadCapacity10(pdev); if(mscStatus == USBH_MSC_OK ) { USBH_MSC_BOTXferParam.MSCState = USBH_MSC_MODE_SENSE6; MSCErrorCount = 0; status = USBH_OK; } else { USBH_MSC_ErrorHandle(mscStatus); } break; case USBH_MSC_MODE_SENSE6: /* Issue ModeSense6 SCSI command for detecting if device is write-protected */ mscStatus = USBH_MSC_ModeSense6(pdev); if(mscStatus == USBH_MSC_OK ) { USBH_MSC_BOTXferParam.MSCState = USBH_MSC_DEFAULT_APPLI_STATE; MSCErrorCount = 0; status = USBH_OK; } else { USBH_MSC_ErrorHandle(mscStatus); } break; case USBH_MSC_REQUEST_SENSE: /* Issue RequestSense SCSI command for retreiving error code */ mscStatus = USBH_MSC_RequestSense(pdev); if(mscStatus == USBH_MSC_OK ) { USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOTXferParam.MSCStateBkp; status = USBH_OK; } else { USBH_MSC_ErrorHandle(mscStatus); } break; case USBH_MSC_BOT_USB_TRANSFERS: /* Process the BOT state machine */ USBH_MSC_HandleBOTXfer(pdev , phost); break; case USBH_MSC_DEFAULT_APPLI_STATE: /* Process Application callback for MSC */ appliStatus = pphost->usr_cb->USBH_USR_MSC_Application(); if(appliStatus == 0) { USBH_MSC_BOTXferParam.MSCState = USBH_MSC_DEFAULT_APPLI_STATE; } else if (appliStatus == 1) { /* De-init requested from application layer */ status = USBH_APPLY_DEINIT; } break; case USBH_MSC_UNRECOVERED_STATE: status = USBH_UNRECOVERED_ERROR; break; default: break; } } return status; } /** * @brief USBH_MSC_BOTReset * This request is used to reset the mass storage device and its * associated interface. This class-specific request shall ready the * device for the next CBW from the host. * @param pdev: Selected device * @retval USBH_Status : Status of class request handled. */ static USBH_Status USBH_MSC_BOTReset(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS | \ USB_REQ_RECIPIENT_INTERFACE; phost->Control.setup.b.bRequest = USB_REQ_BOT_RESET; phost->Control.setup.b.wValue.w = 0; phost->Control.setup.b.wIndex.w = 0; phost->Control.setup.b.wLength.w = 0; return USBH_CtlReq(pdev, phost, 0 , 0 ); } /** * @brief USBH_MSC_GETMaxLUN * This request is used to reset the mass storage device and its * associated interface. This class-specific request shall ready the * device for the next CBW from the host. * @param pdev: Selected device * @retval USBH_Status : USB ctl xfer status */ static USBH_Status USBH_MSC_GETMaxLUN(USB_OTG_CORE_HANDLE *pdev , USBH_HOST *phost) { phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \ USB_REQ_RECIPIENT_INTERFACE; phost->Control.setup.b.bRequest = USB_REQ_GET_MAX_LUN; phost->Control.setup.b.wValue.w = 0; phost->Control.setup.b.wIndex.w = 0; phost->Control.setup.b.wLength.w = 1; return USBH_CtlReq(pdev, phost, MSC_Machine.buff , 1 ); } /** * @brief USBH_MSC_ErrorHandle * The function is for handling errors occuring during the MSC * state machine * @param status * @retval None */ void USBH_MSC_ErrorHandle(uint8_t status) { if(status == USBH_MSC_FAIL) { MSCErrorCount++; if(MSCErrorCount < USBH_MSC_ERROR_RETRY_LIMIT) { /* Try MSC level error recovery, Issue the request Sense to get Drive error reason */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_REQUEST_SENSE; USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; } else { /* Error trials exceeded the limit, go to unrecovered state */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_UNRECOVERED_STATE; } } else if(status == USBH_MSC_PHASE_ERROR) { /* Phase error, Go to Unrecoovered state */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_UNRECOVERED_STATE; } else if(status == USBH_MSC_BUSY) { /*No change in state*/ } } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/MSC/src/usbh_msc_core.c
C
lgpl
16,260
/** ****************************************************************************** * @file usbh_msc_scsi.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file implements the SCSI commands ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_msc_core.h" #include "usbh_msc_scsi.h" #include "usbh_msc_bot.h" #include "usbh_ioreq.h" #include "usbh_def.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_MSC_CLASS * @{ */ /** @defgroup USBH_MSC_SCSI * @brief This file includes the mass storage related functions * @{ */ /** @defgroup USBH_MSC_SCSI_Private_TypesDefinitions * @{ */ MassStorageParameter_TypeDef USBH_MSC_Param; /** * @} */ /** @defgroup USBH_MSC_SCSI_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_MSC_SCSI_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_MSC_SCSI_Private_Variables * @{ */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t USBH_DataInBuffer[512] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN uint8_t USBH_DataOutBuffer[512] __ALIGN_END ; /** * @} */ /** @defgroup USBH_MSC_SCSI_Private_FunctionPrototypes * @{ */ /** * @} */ /** @defgroup USBH_MSC_SCSI_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBH_MSC_SCSI_Private_Functions * @{ */ /** * @brief USBH_MSC_TestUnitReady * Issues 'Test unit ready' command to the device. Once the response * received, it updates the status to upper layer. * @param None * @retval Status */ uint8_t USBH_MSC_TestUnitReady (USB_OTG_CORE_HANDLE *pdev) { uint8_t index; USBH_MSC_Status_TypeDef status = USBH_MSC_BUSY; if(HCD_IsDeviceConnected(pdev)) { switch(USBH_MSC_BOTXferParam.CmdStateMachine) { case CMD_SEND_STATE: /*Prepare the CBW and relevent field*/ USBH_MSC_CBWData.field.CBWTransferLength = 0; /* No Data Transfer */ USBH_MSC_CBWData.field.CBWFlags = USB_EP_DIR_OUT; USBH_MSC_CBWData.field.CBWLength = CBW_LENGTH_TEST_UNIT_READY; USBH_MSC_BOTXferParam.pRxTxBuff = USBH_MSC_CSWData.CSWArray; USBH_MSC_BOTXferParam.DataLength = USBH_MSC_CSW_MAX_LENGTH; USBH_MSC_BOTXferParam.MSCStateCurrent = USBH_MSC_TEST_UNIT_READY; for(index = CBW_CB_LENGTH; index != 0; index--) { USBH_MSC_CBWData.field.CBWCB[index] = 0x00; } USBH_MSC_CBWData.field.CBWCB[0] = OPCODE_TEST_UNIT_READY; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_SEND_CBW; /* Start the transfer, then let the state machine magage the other transactions */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_USB_TRANSFERS; USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_BUSY; USBH_MSC_BOTXferParam.CmdStateMachine = CMD_WAIT_STATUS; status = USBH_MSC_BUSY; break; case CMD_WAIT_STATUS: if(USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_OK) { /* Commands successfully sent and Response Received */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_OK; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_FAIL ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_FAIL; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_PHASE_ERROR ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_PHASE_ERROR; } break; default: break; } } return status; } /** * @brief USBH_MSC_ReadCapacity10 * Issue the read capacity command to the device. Once the response * received, it updates the status to upper layer * @param None * @retval Status */ uint8_t USBH_MSC_ReadCapacity10(USB_OTG_CORE_HANDLE *pdev) { uint8_t index; USBH_MSC_Status_TypeDef status = USBH_MSC_BUSY; if(HCD_IsDeviceConnected(pdev)) { switch(USBH_MSC_BOTXferParam.CmdStateMachine) { case CMD_SEND_STATE: /*Prepare the CBW and relevent field*/ USBH_MSC_CBWData.field.CBWTransferLength = XFER_LEN_READ_CAPACITY10; USBH_MSC_CBWData.field.CBWFlags = USB_EP_DIR_IN; USBH_MSC_CBWData.field.CBWLength = CBW_LENGTH; USBH_MSC_BOTXferParam.pRxTxBuff = USBH_DataInBuffer; USBH_MSC_BOTXferParam.MSCStateCurrent = USBH_MSC_READ_CAPACITY10; for(index = CBW_CB_LENGTH; index != 0; index--) { USBH_MSC_CBWData.field.CBWCB[index] = 0x00; } USBH_MSC_CBWData.field.CBWCB[0] = OPCODE_READ_CAPACITY10; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_SEND_CBW; /* Start the transfer, then let the state machine manage the other transactions */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_USB_TRANSFERS; USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_BUSY; USBH_MSC_BOTXferParam.CmdStateMachine = CMD_WAIT_STATUS; status = USBH_MSC_BUSY; break; case CMD_WAIT_STATUS: if(USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_OK) { /*assign the capacity*/ (((uint8_t*)&USBH_MSC_Param.MSCapacity )[3]) = USBH_DataInBuffer[0]; (((uint8_t*)&USBH_MSC_Param.MSCapacity )[2]) = USBH_DataInBuffer[1]; (((uint8_t*)&USBH_MSC_Param.MSCapacity )[1]) = USBH_DataInBuffer[2]; (((uint8_t*)&USBH_MSC_Param.MSCapacity )[0]) = USBH_DataInBuffer[3]; /*assign the page length*/ (((uint8_t*)&USBH_MSC_Param.MSPageLength )[1]) = USBH_DataInBuffer[6]; (((uint8_t*)&USBH_MSC_Param.MSPageLength )[0]) = USBH_DataInBuffer[7]; /* Commands successfully sent and Response Received */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_OK; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_FAIL ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_FAIL; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_PHASE_ERROR ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_PHASE_ERROR; } else { /* Wait for the Commands to get Completed */ /* NO Change in state Machine */ } break; default: break; } } return status; } /** * @brief USBH_MSC_ModeSense6 * Issue the Mode Sense6 Command to the device. This function is used * for reading the WriteProtect Status of the Mass-Storage device. * @param None * @retval Status */ uint8_t USBH_MSC_ModeSense6(USB_OTG_CORE_HANDLE *pdev) { uint8_t index; USBH_MSC_Status_TypeDef status = USBH_MSC_BUSY; if(HCD_IsDeviceConnected(pdev)) { switch(USBH_MSC_BOTXferParam.CmdStateMachine) { case CMD_SEND_STATE: /*Prepare the CBW and relevent field*/ USBH_MSC_CBWData.field.CBWTransferLength = XFER_LEN_MODE_SENSE6; USBH_MSC_CBWData.field.CBWFlags = USB_EP_DIR_IN; USBH_MSC_CBWData.field.CBWLength = CBW_LENGTH; USBH_MSC_BOTXferParam.pRxTxBuff = USBH_DataInBuffer; USBH_MSC_BOTXferParam.MSCStateCurrent = USBH_MSC_MODE_SENSE6; for(index = CBW_CB_LENGTH; index != 0; index--) { USBH_MSC_CBWData.field.CBWCB[index] = 0x00; } USBH_MSC_CBWData.field.CBWCB[0] = OPCODE_MODE_SENSE6; USBH_MSC_CBWData.field.CBWCB[2] = MODE_SENSE_PAGE_CONTROL_FIELD | \ MODE_SENSE_PAGE_CODE; USBH_MSC_CBWData.field.CBWCB[4] = XFER_LEN_MODE_SENSE6; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_SEND_CBW; /* Start the transfer, then let the state machine manage the other transactions */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_USB_TRANSFERS; USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_BUSY; USBH_MSC_BOTXferParam.CmdStateMachine = CMD_WAIT_STATUS; status = USBH_MSC_BUSY; break; case CMD_WAIT_STATUS: if(USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_OK) { /* Assign the Write Protect status */ /* If WriteProtect = 0, Writing is allowed If WriteProtect != 0, Disk is Write Protected */ if ( USBH_DataInBuffer[2] & MASK_MODE_SENSE_WRITE_PROTECT) { USBH_MSC_Param.MSWriteProtect = DISK_WRITE_PROTECTED; } else { USBH_MSC_Param.MSWriteProtect = 0; } /* Commands successfully sent and Response Received */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_OK; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_FAIL ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_FAIL; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_PHASE_ERROR ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_PHASE_ERROR; } else { /* Wait for the Commands to get Completed */ /* NO Change in state Machine */ } break; default: break; } } return status; } /** * @brief USBH_MSC_RequestSense * Issues the Request Sense command to the device. Once the response * received, it updates the status to upper layer * @param None * @retval Status */ uint8_t USBH_MSC_RequestSense(USB_OTG_CORE_HANDLE *pdev) { USBH_MSC_Status_TypeDef status = USBH_MSC_BUSY; uint8_t index; if(HCD_IsDeviceConnected(pdev)) { switch(USBH_MSC_BOTXferParam.CmdStateMachine) { case CMD_SEND_STATE: /*Prepare the CBW and relevent field*/ USBH_MSC_CBWData.field.CBWTransferLength = \ ALLOCATION_LENGTH_REQUEST_SENSE; USBH_MSC_CBWData.field.CBWFlags = USB_EP_DIR_IN; USBH_MSC_CBWData.field.CBWLength = CBW_LENGTH; USBH_MSC_BOTXferParam.pRxTxBuff = USBH_DataInBuffer; USBH_MSC_BOTXferParam.MSCStateBkp = USBH_MSC_BOTXferParam.MSCStateCurrent; USBH_MSC_BOTXferParam.MSCStateCurrent = USBH_MSC_REQUEST_SENSE; for(index = CBW_CB_LENGTH; index != 0; index--) { USBH_MSC_CBWData.field.CBWCB[index] = 0x00; } USBH_MSC_CBWData.field.CBWCB[0] = OPCODE_REQUEST_SENSE; USBH_MSC_CBWData.field.CBWCB[1] = DESC_REQUEST_SENSE; USBH_MSC_CBWData.field.CBWCB[4] = ALLOCATION_LENGTH_REQUEST_SENSE; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_SEND_CBW; /* Start the transfer, then let the state machine magage the other transactions */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_USB_TRANSFERS; USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_BUSY; USBH_MSC_BOTXferParam.CmdStateMachine = CMD_WAIT_STATUS; status = USBH_MSC_BUSY; break; case CMD_WAIT_STATUS: if(USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_OK) { /* Get Sense data*/ (((uint8_t*)&USBH_MSC_Param.MSSenseKey )[3]) = USBH_DataInBuffer[0]; (((uint8_t*)&USBH_MSC_Param.MSSenseKey )[2]) = USBH_DataInBuffer[1]; (((uint8_t*)&USBH_MSC_Param.MSSenseKey )[1]) = USBH_DataInBuffer[2]; (((uint8_t*)&USBH_MSC_Param.MSSenseKey )[0]) = USBH_DataInBuffer[3]; /* Commands successfully sent and Response Received */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_OK; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_FAIL ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_FAIL; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_PHASE_ERROR ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_PHASE_ERROR; } else { /* Wait for the Commands to get Completed */ /* NO Change in state Machine */ } break; default: break; } } return status; } /** * @brief USBH_MSC_Write10 * Issue the write command to the device. Once the response received, * it updates the status to upper layer * @param dataBuffer : DataBuffer contains the data to write * @param address : Address to which the data will be written * @param nbOfbytes : NbOfbytes to be written * @retval Status */ uint8_t USBH_MSC_Write10(USB_OTG_CORE_HANDLE *pdev, uint8_t *dataBuffer, uint32_t address, uint32_t nbOfbytes) { uint8_t index; USBH_MSC_Status_TypeDef status = USBH_MSC_BUSY; uint16_t nbOfPages; if(HCD_IsDeviceConnected(pdev)) { switch(USBH_MSC_BOTXferParam.CmdStateMachine) { case CMD_SEND_STATE: USBH_MSC_CBWData.field.CBWTransferLength = nbOfbytes; USBH_MSC_CBWData.field.CBWFlags = USB_EP_DIR_OUT; USBH_MSC_CBWData.field.CBWLength = CBW_LENGTH; USBH_MSC_BOTXferParam.pRxTxBuff = dataBuffer; for(index = CBW_CB_LENGTH; index != 0; index--) { USBH_MSC_CBWData.field.CBWCB[index] = 0x00; } USBH_MSC_CBWData.field.CBWCB[0] = OPCODE_WRITE10; /*logical block address*/ USBH_MSC_CBWData.field.CBWCB[2] = (((uint8_t*)&address)[3]) ; USBH_MSC_CBWData.field.CBWCB[3] = (((uint8_t*)&address)[2]); USBH_MSC_CBWData.field.CBWCB[4] = (((uint8_t*)&address)[1]); USBH_MSC_CBWData.field.CBWCB[5] = (((uint8_t*)&address)[0]); /*USBH_MSC_PAGE_LENGTH = 512*/ nbOfPages = nbOfbytes/ USBH_MSC_PAGE_LENGTH; /*Tranfer length */ USBH_MSC_CBWData.field.CBWCB[7] = (((uint8_t *)&nbOfPages)[1]) ; USBH_MSC_CBWData.field.CBWCB[8] = (((uint8_t *)&nbOfPages)[0]) ; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_SEND_CBW; /* Start the transfer, then let the state machine magage the other transactions */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_USB_TRANSFERS; USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_BUSY; USBH_MSC_BOTXferParam.CmdStateMachine = CMD_WAIT_STATUS; status = USBH_MSC_BUSY; break; case CMD_WAIT_STATUS: if(USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_OK) { /* Commands successfully sent and Response Received */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_OK; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_FAIL ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_PHASE_ERROR ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_PHASE_ERROR; } break; default: break; } } return status; } /** * @brief USBH_MSC_Read10 * Issue the read command to the device. Once the response received, * it updates the status to upper layer * @param dataBuffer : DataBuffer will contain the data to be read * @param address : Address from which the data will be read * @param nbOfbytes : NbOfbytes to be read * @retval Status */ uint8_t USBH_MSC_Read10(USB_OTG_CORE_HANDLE *pdev, uint8_t *dataBuffer, uint32_t address, uint32_t nbOfbytes) { uint8_t index; static USBH_MSC_Status_TypeDef status = USBH_MSC_BUSY; uint16_t nbOfPages; status = USBH_MSC_BUSY; if(HCD_IsDeviceConnected(pdev)) { switch(USBH_MSC_BOTXferParam.CmdStateMachine) { case CMD_SEND_STATE: /*Prepare the CBW and relevent field*/ USBH_MSC_CBWData.field.CBWTransferLength = nbOfbytes; USBH_MSC_CBWData.field.CBWFlags = USB_EP_DIR_IN; USBH_MSC_CBWData.field.CBWLength = CBW_LENGTH; USBH_MSC_BOTXferParam.pRxTxBuff = dataBuffer; for(index = CBW_CB_LENGTH; index != 0; index--) { USBH_MSC_CBWData.field.CBWCB[index] = 0x00; } USBH_MSC_CBWData.field.CBWCB[0] = OPCODE_READ10; /*logical block address*/ USBH_MSC_CBWData.field.CBWCB[2] = (((uint8_t*)&address)[3]); USBH_MSC_CBWData.field.CBWCB[3] = (((uint8_t*)&address)[2]); USBH_MSC_CBWData.field.CBWCB[4] = (((uint8_t*)&address)[1]); USBH_MSC_CBWData.field.CBWCB[5] = (((uint8_t*)&address)[0]); /*USBH_MSC_PAGE_LENGTH = 512*/ nbOfPages = nbOfbytes/ USBH_MSC_PAGE_LENGTH; /*Tranfer length */ USBH_MSC_CBWData.field.CBWCB[7] = (((uint8_t *)&nbOfPages)[1]) ; USBH_MSC_CBWData.field.CBWCB[8] = (((uint8_t *)&nbOfPages)[0]) ; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_SEND_CBW; /* Start the transfer, then let the state machine magage the other transactions */ USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_USB_TRANSFERS; USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_BUSY; USBH_MSC_BOTXferParam.CmdStateMachine = CMD_WAIT_STATUS; status = USBH_MSC_BUSY; break; case CMD_WAIT_STATUS: if((USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_OK) && \ (HCD_IsDeviceConnected(pdev))) { /* Commands successfully sent and Response Received */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_OK; } else if (( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_FAIL ) && \ (HCD_IsDeviceConnected(pdev))) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; } else if ( USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_PHASE_ERROR ) { /* Failure Mode */ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; status = USBH_MSC_PHASE_ERROR; } else { /* Wait for the Commands to get Completed */ /* NO Change in state Machine */ } break; default: break; } } return status; } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/MSC/src/usbh_msc_scsi.c
C
lgpl
21,020
#include "usb_conf.h" #include "diskio.h" #include "usbh_msc_core.h" /*-------------------------------------------------------------------------- Module Private Functions and Variables ---------------------------------------------------------------------------*/ static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */ extern USB_OTG_CORE_HANDLE USB_OTG_Core; extern USBH_HOST USB_Host; /*-----------------------------------------------------------------------*/ /* Initialize Disk Drive */ /*-----------------------------------------------------------------------*/ DSTATUS disk_initialize ( BYTE drv /* Physical drive number (0) */ ) { if(HCD_IsDeviceConnected(&USB_OTG_Core)) { Stat &= ~STA_NOINIT; } return Stat; } /*-----------------------------------------------------------------------*/ /* Get Disk Status */ /*-----------------------------------------------------------------------*/ DSTATUS disk_status ( BYTE drv /* Physical drive number (0) */ ) { if (drv) return STA_NOINIT; /* Supports only single drive */ return Stat; } /*-----------------------------------------------------------------------*/ /* Read Sector(s) */ /*-----------------------------------------------------------------------*/ DRESULT disk_read ( BYTE drv, /* Physical drive number (0) */ BYTE *buff, /* Pointer to the data buffer to store read data */ DWORD sector, /* Start sector number (LBA) */ BYTE count /* Sector count (1..255) */ ) { BYTE status = USBH_MSC_OK; if (drv || !count) return RES_PARERR; if (Stat & STA_NOINIT) return RES_NOTRDY; if(HCD_IsDeviceConnected(&USB_OTG_Core)) { do { status = USBH_MSC_Read10(&USB_OTG_Core, buff,sector,512); USBH_MSC_HandleBOTXfer(&USB_OTG_Core ,&USB_Host); if(!HCD_IsDeviceConnected(&USB_OTG_Core)) { return RES_ERROR; } } while(status == USBH_MSC_BUSY ); } if(status == USBH_MSC_OK) return RES_OK; return RES_ERROR; } /*-----------------------------------------------------------------------*/ /* Write Sector(s) */ /*-----------------------------------------------------------------------*/ #if _READONLY == 0 DRESULT disk_write ( BYTE drv, /* Physical drive number (0) */ const BYTE *buff, /* Pointer to the data to be written */ DWORD sector, /* Start sector number (LBA) */ BYTE count /* Sector count (1..255) */ ) { BYTE status = USBH_MSC_OK; if (drv || !count) return RES_PARERR; if (Stat & STA_NOINIT) return RES_NOTRDY; if (Stat & STA_PROTECT) return RES_WRPRT; if(HCD_IsDeviceConnected(&USB_OTG_Core)) { do { status = USBH_MSC_Write10(&USB_OTG_Core,(BYTE*)buff,sector,512); USBH_MSC_HandleBOTXfer(&USB_OTG_Core, &USB_Host); if(!HCD_IsDeviceConnected(&USB_OTG_Core)) { return RES_ERROR; } } while(status == USBH_MSC_BUSY ); } if(status == USBH_MSC_OK) return RES_OK; return RES_ERROR; } #endif /* _READONLY == 0 */ /*-----------------------------------------------------------------------*/ /* Miscellaneous Functions */ /*-----------------------------------------------------------------------*/ #if _USE_IOCTL != 0 DRESULT disk_ioctl ( BYTE drv, /* Physical drive number (0) */ BYTE ctrl, /* Control code */ void *buff /* Buffer to send/receive control data */ ) { DRESULT res = RES_OK; if (drv) return RES_PARERR; res = RES_ERROR; if (Stat & STA_NOINIT) return RES_NOTRDY; switch (ctrl) { case CTRL_SYNC : /* Make sure that no pending write process */ res = RES_OK; break; case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */ *(DWORD*)buff = (DWORD) USBH_MSC_Param.MSCapacity; res = RES_OK; break; case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */ *(WORD*)buff = 512; res = RES_OK; break; case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */ *(DWORD*)buff = 512; break; default: res = RES_PARERR; } return res; } #endif /* _USE_IOCTL != 0 */
1137519-player
lib/STM32_USB_HOST_Library/Class/MSC/src/usbh_msc_fatfs.c
C
lgpl
5,006
/** ****************************************************************************** * @file usbh_msc_bot.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file includes the mass storage related functions ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_msc_core.h" #include "usbh_msc_scsi.h" #include "usbh_msc_bot.h" #include "usbh_ioreq.h" #include "usbh_def.h" #include "usb_hcd_int.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_MSC_CLASS * @{ */ /** @defgroup USBH_MSC_BOT * @brief This file includes the mass storage related functions * @{ */ /** @defgroup USBH_MSC_BOT_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_MSC_BOT_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_MSC_BOT_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_MSC_BOT_Private_Variables * @{ */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN HostCBWPkt_TypeDef USBH_MSC_CBWData __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN HostCSWPkt_TypeDef USBH_MSC_CSWData __ALIGN_END ; static uint32_t BOTStallErrorCount; /* Keeps count of STALL Error Cases*/ /** * @} */ /** @defgroup USBH_MSC_BOT_Private_FunctionPrototypes * @{ */ /** * @} */ /** @defgroup USBH_MSC_BOT_Exported_Variables * @{ */ USBH_BOTXfer_TypeDef USBH_MSC_BOTXferParam; /** * @} */ /** @defgroup USBH_MSC_BOT_Private_Functions * @{ */ /** * @brief USBH_MSC_Init * Initializes the mass storage parameters * @param None * @retval None */ void USBH_MSC_Init(USB_OTG_CORE_HANDLE *pdev ) { if(HCD_IsDeviceConnected(pdev)) { USBH_MSC_CBWData.field.CBWSignature = USBH_MSC_BOT_CBW_SIGNATURE; USBH_MSC_CBWData.field.CBWTag = USBH_MSC_BOT_CBW_TAG; USBH_MSC_CBWData.field.CBWLUN = 0; /*Only one LUN is supported*/ USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE; } BOTStallErrorCount = 0; MSCErrorCount = 0; } /** * @brief USBH_MSC_HandleBOTXfer * This function manages the different states of BOT transfer and * updates the status to upper layer. * @param None * @retval None * */ void USBH_MSC_HandleBOTXfer (USB_OTG_CORE_HANDLE *pdev ,USBH_HOST *phost) { uint8_t xferDirection, index; static uint32_t remainingDataLength; static uint8_t *datapointer; static uint8_t error_direction; USBH_Status status; URB_STATE URB_Status = URB_IDLE; if(HCD_IsDeviceConnected(pdev)) { switch (USBH_MSC_BOTXferParam.BOTState) { case USBH_MSC_SEND_CBW: /* send CBW */ USBH_BulkSendData (pdev, &USBH_MSC_CBWData.CBWArray[0], USBH_MSC_BOT_CBW_PACKET_LENGTH , MSC_Machine.hc_num_out); USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_SEND_CBW; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_SENT_CBW; break; case USBH_MSC_SENT_CBW: URB_Status = HCD_GetURB_State(pdev , MSC_Machine.hc_num_out); if(URB_Status == URB_DONE) { BOTStallErrorCount = 0; USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_SENT_CBW; /* If the CBW Pkt is sent successful, then change the state */ xferDirection = (USBH_MSC_CBWData.field.CBWFlags & USB_REQ_DIR_MASK); if ( USBH_MSC_CBWData.field.CBWTransferLength != 0 ) { remainingDataLength = USBH_MSC_CBWData.field.CBWTransferLength ; datapointer = USBH_MSC_BOTXferParam.pRxTxBuff; /* If there is Data Transfer Stage */ if (xferDirection == USB_D2H) { /* Data Direction is IN */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_DATAIN_STATE; } else { /* Data Direction is OUT */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_DATAOUT_STATE; } } else {/* If there is NO Data Transfer Stage */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_RECEIVE_CSW_STATE; } } else if(URB_Status == URB_NOTREADY) { USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOTXferParam.BOTStateBkp; } else if(URB_Status == URB_STALL) { error_direction = USBH_MSC_DIR_OUT; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_ERROR_OUT; } break; case USBH_MSC_BOT_DATAIN_STATE: URB_Status = HCD_GetURB_State(pdev , MSC_Machine.hc_num_in); /* BOT DATA IN stage */ if((URB_Status == URB_DONE) ||(USBH_MSC_BOTXferParam.BOTStateBkp != USBH_MSC_BOT_DATAIN_STATE)) { BOTStallErrorCount = 0; USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_BOT_DATAIN_STATE; if(remainingDataLength > USBH_MSC_MPS_SIZE) { USBH_BulkReceiveData (pdev, datapointer, USBH_MSC_MPS_SIZE , MSC_Machine.hc_num_in); remainingDataLength -= USBH_MSC_MPS_SIZE; datapointer = datapointer + USBH_MSC_MPS_SIZE; } else if ( remainingDataLength == 0) { /* If value was 0, and successful transfer, then change the state */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_RECEIVE_CSW_STATE; } else { USBH_BulkReceiveData (pdev, datapointer, remainingDataLength , MSC_Machine.hc_num_in); remainingDataLength = 0; /* Reset this value and keep in same state */ } } else if(URB_Status == URB_STALL) { /* This is Data Stage STALL Condition */ error_direction = USBH_MSC_DIR_IN; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_ERROR_IN; /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 6.7.2 Host expects to receive data from the device 3. On a STALL condition receiving data, then: The host shall accept the data received. The host shall clear the Bulk-In pipe. 4. The host shall attempt to receive a CSW. USBH_MSC_BOTXferParam.BOTStateBkp is used to switch to the Original state after the ClearFeature Command is issued. */ USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_RECEIVE_CSW_STATE; } break; case USBH_MSC_BOT_DATAOUT_STATE: /* BOT DATA OUT stage */ URB_Status = HCD_GetURB_State(pdev , MSC_Machine.hc_num_out); if(URB_Status == URB_DONE) { BOTStallErrorCount = 0; USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_BOT_DATAOUT_STATE; if(remainingDataLength > USBH_MSC_MPS_SIZE) { USBH_BulkSendData (pdev, datapointer, USBH_MSC_MPS_SIZE , MSC_Machine.hc_num_out); datapointer = datapointer + USBH_MSC_MPS_SIZE; remainingDataLength = remainingDataLength - USBH_MSC_MPS_SIZE; } else if ( remainingDataLength == 0) { /* If value was 0, and successful transfer, then change the state */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_RECEIVE_CSW_STATE; } else { USBH_BulkSendData (pdev, datapointer, remainingDataLength , MSC_Machine.hc_num_out); remainingDataLength = 0; /* Reset this value and keep in same state */ } } else if(URB_Status == URB_NOTREADY) { USBH_BulkSendData (pdev, (datapointer - USBH_MSC_MPS_SIZE), USBH_MSC_MPS_SIZE , MSC_Machine.hc_num_out); } else if(URB_Status == URB_STALL) { error_direction = USBH_MSC_DIR_OUT; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_ERROR_OUT; /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 6.7.3 Ho - Host expects to send data to the device 3. On a STALL condition sending data, then: " The host shall clear the Bulk-Out pipe. 4. The host shall attempt to receive a CSW. The Above statement will do the clear the Bulk-Out pipe. The Below statement will help in Getting the CSW. USBH_MSC_BOTXferParam.BOTStateBkp is used to switch to the Original state after the ClearFeature Command is issued. */ USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_RECEIVE_CSW_STATE; } break; case USBH_MSC_RECEIVE_CSW_STATE: /* BOT CSW stage */ /* NOTE: We cannot reset the BOTStallErrorCount here as it may come from the clearFeature from previous command */ USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_RECEIVE_CSW_STATE; USBH_MSC_BOTXferParam.pRxTxBuff = USBH_MSC_CSWData.CSWArray; USBH_MSC_BOTXferParam.DataLength = USBH_MSC_CSW_MAX_LENGTH; for(index = USBH_MSC_CSW_LENGTH; index != 0; index--) { USBH_MSC_CSWData.CSWArray[index] = 0; } USBH_MSC_CSWData.CSWArray[0] = 0; USBH_BulkReceiveData (pdev, USBH_MSC_BOTXferParam.pRxTxBuff, USBH_MSC_CSW_MAX_LENGTH , MSC_Machine.hc_num_in); USBH_MSC_BOTXferParam.BOTState = USBH_MSC_DECODE_CSW; break; case USBH_MSC_DECODE_CSW: URB_Status = HCD_GetURB_State(pdev , MSC_Machine.hc_num_in); /* Decode CSW */ if(URB_Status == URB_DONE) { BOTStallErrorCount = 0; USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_RECEIVE_CSW_STATE; USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOTXferParam.MSCStateCurrent ; USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_DecodeCSW(pdev , phost); } else if(URB_Status == URB_STALL) { error_direction = USBH_MSC_DIR_IN; USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_ERROR_IN; } break; case USBH_MSC_BOT_ERROR_IN: status = USBH_MSC_BOT_Abort(pdev, phost, USBH_MSC_DIR_IN); if (status == USBH_OK) { /* Check if the error was due in Both the directions */ if (error_direction == USBH_MSC_BOTH_DIR) {/* If Both directions are Needed, Switch to OUT Direction */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_ERROR_OUT; } else { /* Switch Back to the Original State, In many cases this will be USBH_MSC_RECEIVE_CSW_STATE state */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOTXferParam.BOTStateBkp; } } else if (status == USBH_UNRECOVERED_ERROR) { /* This means that there is a STALL Error limit, Do Reset Recovery */ USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_PHASE_ERROR; } break; case USBH_MSC_BOT_ERROR_OUT: status = USBH_MSC_BOT_Abort(pdev, phost, USBH_MSC_DIR_OUT); if ( status == USBH_OK) { /* Switch Back to the Original State */ USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOTXferParam.BOTStateBkp; } else if (status == USBH_UNRECOVERED_ERROR) { /* This means that there is a STALL Error limit, Do Reset Recovery */ USBH_MSC_BOTXferParam.BOTXferStatus = USBH_MSC_PHASE_ERROR; } break; default: break; } } } /** * @brief USBH_MSC_BOT_Abort * This function manages the different Error handling for STALL * @param direction : IN / OUT * @retval None */ USBH_Status USBH_MSC_BOT_Abort(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t direction) { USBH_Status status; status = USBH_BUSY; switch (direction) { case USBH_MSC_DIR_IN : /* send ClrFeture on Bulk IN endpoint */ status = USBH_ClrFeature(pdev, phost, MSC_Machine.MSBulkInEp, MSC_Machine.hc_num_in); break; case USBH_MSC_DIR_OUT : /*send ClrFeature on Bulk OUT endpoint */ status = USBH_ClrFeature(pdev, phost, MSC_Machine.MSBulkOutEp, MSC_Machine.hc_num_out); break; default: break; } BOTStallErrorCount++; /* Check Continous Number of times, STALL has Occured */ if (BOTStallErrorCount > MAX_BULK_STALL_COUNT_LIMIT ) { status = USBH_UNRECOVERED_ERROR; } return status; } /** * @brief USBH_MSC_DecodeCSW * This function decodes the CSW received by the device and updates the * same to upper layer. * @param None * @retval On success USBH_MSC_OK, on failure USBH_MSC_FAIL * @notes * Refer to USB Mass-Storage Class : BOT (www.usb.org) * 6.3.1 Valid CSW Conditions : * The host shall consider the CSW valid when: * 1. dCSWSignature is equal to 53425355h * 2. the CSW is 13 (Dh) bytes in length, * 3. dCSWTag matches the dCBWTag from the corresponding CBW. */ uint8_t USBH_MSC_DecodeCSW(USB_OTG_CORE_HANDLE *pdev , USBH_HOST *phost) { uint8_t status; uint32_t dataXferCount = 0; status = USBH_MSC_FAIL; if(HCD_IsDeviceConnected(pdev)) { /*Checking if the transfer length is diffrent than 13*/ dataXferCount = HCD_GetXferCnt(pdev, MSC_Machine.hc_num_in); if(dataXferCount != USBH_MSC_CSW_LENGTH) { /*(4) Hi > Dn (Host expects to receive data from the device, Device intends to transfer no data) (5) Hi > Di (Host expects to receive data from the device, Device intends to send data to the host) (9) Ho > Dn (Host expects to send data to the device, Device intends to transfer no data) (11) Ho > Do (Host expects to send data to the device, Device intends to receive data from the host)*/ status = USBH_MSC_PHASE_ERROR; } else { /* CSW length is Correct */ /* Check validity of the CSW Signature and CSWStatus */ if(USBH_MSC_CSWData.field.CSWSignature == USBH_MSC_BOT_CSW_SIGNATURE) {/* Check Condition 1. dCSWSignature is equal to 53425355h */ if(USBH_MSC_CSWData.field.CSWTag == USBH_MSC_CBWData.field.CBWTag) { /* Check Condition 3. dCSWTag matches the dCBWTag from the corresponding CBW */ if(USBH_MSC_CSWData.field.CSWStatus == USBH_MSC_OK) { /* Refer to USB Mass-Storage Class : BOT (www.usb.org) Hn Host expects no data transfers Hi Host expects to receive data from the device Ho Host expects to send data to the device Dn Device intends to transfer no data Di Device intends to send data to the host Do Device intends to receive data from the host Section 6.7 (1) Hn = Dn (Host expects no data transfers, Device intends to transfer no data) (6) Hi = Di (Host expects to receive data from the device, Device intends to send data to the host) (12) Ho = Do (Host expects to send data to the device, Device intends to receive data from the host) */ status = USBH_MSC_OK; } else if(USBH_MSC_CSWData.field.CSWStatus == USBH_MSC_FAIL) { status = USBH_MSC_FAIL; } else if(USBH_MSC_CSWData.field.CSWStatus == USBH_MSC_PHASE_ERROR) { /* Refer to USB Mass-Storage Class : BOT (www.usb.org) Section 6.7 (2) Hn < Di ( Host expects no data transfers, Device intends to send data to the host) (3) Hn < Do ( Host expects no data transfers, Device intends to receive data from the host) (7) Hi < Di ( Host expects to receive data from the device, Device intends to send data to the host) (8) Hi <> Do ( Host expects to receive data from the device, Device intends to receive data from the host) (10) Ho <> Di (Host expects to send data to the device, Di Device intends to send data to the host) (13) Ho < Do (Host expects to send data to the device, Device intends to receive data from the host) */ status = USBH_MSC_PHASE_ERROR; } } /* CSW Tag Matching is Checked */ } /* CSW Signature Correct Checking */ else { /* If the CSW Signature is not valid, We sall return the Phase Error to Upper Layers for Reset Recovery */ status = USBH_MSC_PHASE_ERROR; } } /* CSW Length Check*/ } USBH_MSC_BOTXferParam.BOTXferStatus = status; return status; } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/MSC/src/usbh_msc_bot.c
C
lgpl
19,057
/** ****************************************************************************** * @file usbh_msc_scsi.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief Header file for usbh_msc_scsi.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_MSC_SCSI_H__ #define __USBH_MSC_SCSI_H__ /* Includes ------------------------------------------------------------------*/ #include "usbh_stdreq.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_MSC_CLASS * @{ */ /** @defgroup USBH_MSC_SCSI * @brief This file is the Header file for usbh_msc_scsi.c * @{ */ /** @defgroup USBH_MSC_SCSI_Exported_Types * @{ */ typedef enum { USBH_MSC_OK = 0, USBH_MSC_FAIL = 1, USBH_MSC_PHASE_ERROR = 2, USBH_MSC_BUSY = 3 }USBH_MSC_Status_TypeDef; typedef enum { CMD_UNINITIALIZED_STATE =0, CMD_SEND_STATE, CMD_WAIT_STATUS } CMD_STATES_TypeDef; typedef struct __MassStorageParameter { uint32_t MSCapacity; uint32_t MSSenseKey; uint16_t MSPageLength; uint8_t MSBulkOutEp; uint8_t MSBulkInEp; uint8_t MSWriteProtect; } MassStorageParameter_TypeDef; /** * @} */ /** @defgroup USBH_MSC_SCSI_Exported_Defines * @{ */ #define OPCODE_TEST_UNIT_READY 0X00 #define OPCODE_READ_CAPACITY10 0x25 #define OPCODE_MODE_SENSE6 0x1A #define OPCODE_READ10 0x28 #define OPCODE_WRITE10 0x2A #define OPCODE_REQUEST_SENSE 0x03 #define DESC_REQUEST_SENSE 0X00 #define ALLOCATION_LENGTH_REQUEST_SENSE 63 #define XFER_LEN_READ_CAPACITY10 8 #define XFER_LEN_MODE_SENSE6 63 #define MASK_MODE_SENSE_WRITE_PROTECT 0x80 #define MODE_SENSE_PAGE_CONTROL_FIELD 0x00 #define MODE_SENSE_PAGE_CODE 0x3F #define DISK_WRITE_PROTECTED 0x01 /** * @} */ /** @defgroup USBH_MSC_SCSI_Exported_Macros * @{ */ /** * @} */ /** @defgroup _Exported_Variables * @{ */ extern MassStorageParameter_TypeDef USBH_MSC_Param; /** * @} */ /** @defgroup USBH_MSC_SCSI_Exported_FunctionsPrototype * @{ */ uint8_t USBH_MSC_TestUnitReady(USB_OTG_CORE_HANDLE *pdev); uint8_t USBH_MSC_ReadCapacity10(USB_OTG_CORE_HANDLE *pdev); uint8_t USBH_MSC_ModeSense6(USB_OTG_CORE_HANDLE *pdev); uint8_t USBH_MSC_RequestSense(USB_OTG_CORE_HANDLE *pdev); uint8_t USBH_MSC_Write10(USB_OTG_CORE_HANDLE *pdev, uint8_t *, uint32_t , uint32_t ); uint8_t USBH_MSC_Read10(USB_OTG_CORE_HANDLE *pdev, uint8_t *, uint32_t , uint32_t ); void USBH_MSC_StateMachine(USB_OTG_CORE_HANDLE *pdev); /** * @} */ #endif //__USBH_MSC_SCSI_H__ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/MSC/inc/usbh_msc_scsi.h
C
lgpl
3,940
/** ****************************************************************************** * @file usbh_msc_bot.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief Header file for usbh_msc_bot.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_MSC_BOT_H__ #define __USBH_MSC_BOT_H__ /* Includes ------------------------------------------------------------------*/ #include "usbh_stdreq.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_MSC_CLASS * @{ */ /** @defgroup USBH_MSC_BOT * @brief This file is the Header file for usbh_msc_core.c * @{ */ /** @defgroup USBH_MSC_BOT_Exported_Types * @{ */ typedef union _USBH_CBW_Block { struct __CBW { uint32_t CBWSignature; uint32_t CBWTag; uint32_t CBWTransferLength; uint8_t CBWFlags; uint8_t CBWLUN; uint8_t CBWLength; uint8_t CBWCB[16]; }field; uint8_t CBWArray[31]; }HostCBWPkt_TypeDef; typedef enum { USBH_MSC_BOT_INIT_STATE = 0, USBH_MSC_BOT_RESET, USBH_MSC_GET_MAX_LUN, USBH_MSC_TEST_UNIT_READY, USBH_MSC_READ_CAPACITY10, USBH_MSC_MODE_SENSE6, USBH_MSC_REQUEST_SENSE, USBH_MSC_BOT_USB_TRANSFERS, USBH_MSC_DEFAULT_APPLI_STATE, USBH_MSC_CTRL_ERROR_STATE, USBH_MSC_UNRECOVERED_STATE } MSCState; typedef struct _BOTXfer { uint8_t MSCState; uint8_t MSCStateBkp; uint8_t MSCStateCurrent; uint8_t CmdStateMachine; uint8_t BOTState; uint8_t BOTStateBkp; uint8_t* pRxTxBuff; uint16_t DataLength; uint8_t BOTXferErrorCount; uint8_t BOTXferStatus; } USBH_BOTXfer_TypeDef; typedef union _USBH_CSW_Block { struct __CSW { uint32_t CSWSignature; uint32_t CSWTag; uint32_t CSWDataResidue; uint8_t CSWStatus; }field; uint8_t CSWArray[13]; }HostCSWPkt_TypeDef; /** * @} */ /** @defgroup USBH_MSC_BOT_Exported_Defines * @{ */ #define USBH_MSC_SEND_CBW 1 #define USBH_MSC_SENT_CBW 2 #define USBH_MSC_BOT_DATAIN_STATE 3 #define USBH_MSC_BOT_DATAOUT_STATE 4 #define USBH_MSC_RECEIVE_CSW_STATE 5 #define USBH_MSC_DECODE_CSW 6 #define USBH_MSC_BOT_ERROR_IN 7 #define USBH_MSC_BOT_ERROR_OUT 8 #define USBH_MSC_BOT_CBW_SIGNATURE 0x43425355 #define USBH_MSC_BOT_CBW_TAG 0x20304050 #define USBH_MSC_BOT_CSW_SIGNATURE 0x53425355 #define USBH_MSC_CSW_DATA_LENGTH 0x000D #define USBH_MSC_BOT_CBW_PACKET_LENGTH 31 #define USBH_MSC_CSW_LENGTH 13 #define USBH_MSC_CSW_MAX_LENGTH 63 /* CSW Status Definitions */ #define USBH_MSC_CSW_CMD_PASSED 0x00 #define USBH_MSC_CSW_CMD_FAILED 0x01 #define USBH_MSC_CSW_PHASE_ERROR 0x02 #define USBH_MSC_SEND_CSW_DISABLE 0 #define USBH_MSC_SEND_CSW_ENABLE 1 #define USBH_MSC_DIR_IN 0 #define USBH_MSC_DIR_OUT 1 #define USBH_MSC_BOTH_DIR 2 //#define USBH_MSC_PAGE_LENGTH 0x40 #define USBH_MSC_PAGE_LENGTH 512 #define CBW_CB_LENGTH 16 #define CBW_LENGTH 10 #define CBW_LENGTH_TEST_UNIT_READY 6 #define USB_REQ_BOT_RESET 0xFF #define USB_REQ_GET_MAX_LUN 0xFE #define MAX_BULK_STALL_COUNT_LIMIT 0x04 /* If STALL is seen on Bulk Endpoint continously, this means that device and Host has phase error Hence a Reset is needed */ /** * @} */ /** @defgroup USBH_MSC_BOT_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_MSC_BOT_Exported_Variables * @{ */ extern USBH_BOTXfer_TypeDef USBH_MSC_BOTXferParam; extern HostCBWPkt_TypeDef USBH_MSC_CBWData; extern HostCSWPkt_TypeDef USBH_MSC_CSWData; /** * @} */ /** @defgroup USBH_MSC_BOT_Exported_FunctionsPrototype * @{ */ void USBH_MSC_HandleBOTXfer(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost); uint8_t USBH_MSC_DecodeCSW(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost); void USBH_MSC_Init(USB_OTG_CORE_HANDLE *pdev); USBH_Status USBH_MSC_BOT_Abort(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t direction); /** * @} */ #endif //__USBH_MSC_BOT_H__ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/MSC/inc/usbh_msc_bot.h
C
lgpl
5,689
/** ****************************************************************************** * @file usbh_msc_core.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file contains all the prototypes for the usbh_msc_core.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_MSC_CORE_H #define __USBH_MSC_CORE_H /* Includes ------------------------------------------------------------------*/ #include "usbh_core.h" #include "usbh_stdreq.h" #include "usb_bsp.h" #include "usbh_ioreq.h" #include "usbh_hcs.h" #include "usbh_msc_core.h" #include "usbh_msc_scsi.h" #include "usbh_msc_bot.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_MSC_CLASS * @{ */ /** @defgroup USBH_MSC_CORE * @brief This file is the Header file for usbh_msc_core.c * @{ */ /** @defgroup USBH_MSC_CORE_Exported_Types * @{ */ /* Structure for MSC process */ typedef struct _MSC_Process { uint8_t hc_num_in; uint8_t hc_num_out; uint8_t MSBulkOutEp; uint8_t MSBulkInEp; uint16_t MSBulkInEpSize; uint16_t MSBulkOutEpSize; uint8_t buff[USBH_MSC_MPS_SIZE]; uint8_t maxLun; } MSC_Machine_TypeDef; /** * @} */ /** @defgroup USBH_MSC_CORE_Exported_Defines * @{ */ #define USB_REQ_BOT_RESET 0xFF #define USB_REQ_GET_MAX_LUN 0xFE /** * @} */ /** @defgroup USBH_MSC_CORE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_MSC_CORE_Exported_Variables * @{ */ extern USBH_Class_cb_TypeDef USBH_MSC_cb; extern MSC_Machine_TypeDef MSC_Machine; extern uint8_t MSCErrorCount; /** * @} */ /** @defgroup USBH_MSC_CORE_Exported_FunctionsPrototype * @{ */ /** * @} */ #endif /* __USBH_MSC_CORE_H */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/MSC/inc/usbh_msc_core.h
C
lgpl
2,966
/** ****************************************************************************** * @file usbh_hid_mouse.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file is the application layer for USB Host HID Mouse Handling. ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_mouse.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_HID_CLASS * @{ */ /** @defgroup USBH_HID_MOUSE * @brief This file includes HID Layer Handlers for USB Host HID class. * @{ */ /** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_HID_MOUSE_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_HID_MOUSE_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes * @{ */ static void MOUSE_Init (void); static void MOUSE_Decode(uint8_t *data); /** * @} */ /** @defgroup USBH_HID_MOUSE_Private_Variables * @{ */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined (__CC_ARM) /*!< ARM Compiler */ __align(4) #elif defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #elif defined (__GNUC__) /*!< GNU Compiler */ #pragma pack(4) #elif defined (__TASKING__) /*!< TASKING Compiler */ __align(4) #endif /* __CC_ARM */ #endif HID_MOUSE_Data_TypeDef HID_MOUSE_Data; HID_cb_TypeDef HID_MOUSE_cb = { MOUSE_Init, MOUSE_Decode, }; /** * @} */ /** @defgroup USBH_HID_MOUSE_Private_Functions * @{ */ /** * @brief MOUSE_Init * Init Mouse State. * @param None * @retval None */ static void MOUSE_Init ( void) { /* Call User Init*/ USR_MOUSE_Init(); } /** * @brief MOUSE_Decode * Decode Mouse data * @param data : Pointer to Mouse HID data buffer * @retval None */ static void MOUSE_Decode(uint8_t *data) { HID_MOUSE_Data.button = data[0]; HID_MOUSE_Data.x = data[1]; HID_MOUSE_Data.y = data[2]; USR_MOUSE_ProcessData(&HID_MOUSE_Data); } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/HID/src/usbh_hid_mouse.c
C
lgpl
3,216
/** ****************************************************************************** * @file usbh_hid_core.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file is the HID Layer Handlers for USB Host HID class. * * @verbatim * * =================================================================== * HID Class Description * =================================================================== * This module manages the MSC class V1.11 following the "Device Class Definition * for Human Interface Devices (HID) Version 1.11 Jun 27, 2001". * This driver implements the following aspects of the specification: * - The Boot Interface Subclass * - The Mouse and Keyboard protocols * * @endverbatim * ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_core.h" #include "usbh_hid_mouse.h" #include "usbh_hid_keybd.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_HID_CLASS * @{ */ /** @defgroup USBH_HID_CORE * @brief This file includes HID Layer Handlers for USB Host HID class. * @{ */ /** @defgroup USBH_HID_CORE_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_HID_CORE_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_HID_CORE_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_HID_CORE_Private_Variables * @{ */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN HID_Machine_TypeDef HID_Machine __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN HID_Report_TypeDef HID_Report __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN USB_Setup_TypeDef HID_Setup __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN USBH_HIDDesc_TypeDef HID_Desc __ALIGN_END ; __IO uint8_t flag = 0; /** * @} */ /** @defgroup USBH_HID_CORE_Private_FunctionPrototypes * @{ */ static USBH_Status USBH_HID_InterfaceInit (USB_OTG_CORE_HANDLE *pdev , void *phost); static void USBH_ParseHIDDesc (USBH_HIDDesc_TypeDef *desc, uint8_t *buf); static void USBH_HID_InterfaceDeInit (USB_OTG_CORE_HANDLE *pdev , void *phost); static USBH_Status USBH_HID_Handle(USB_OTG_CORE_HANDLE *pdev , void *phost); static USBH_Status USBH_HID_ClassRequest(USB_OTG_CORE_HANDLE *pdev , void *phost); static USBH_Status USBH_Get_HID_ReportDescriptor (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint16_t length); static USBH_Status USBH_Get_HID_Descriptor (USB_OTG_CORE_HANDLE *pdev,\ USBH_HOST *phost, uint16_t length); static USBH_Status USBH_Set_Idle (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t duration, uint8_t reportId); static USBH_Status USBH_Set_Protocol (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t protocol); USBH_Class_cb_TypeDef HID_cb = { USBH_HID_InterfaceInit, USBH_HID_InterfaceDeInit, USBH_HID_ClassRequest, USBH_HID_Handle }; /** * @} */ /** @defgroup USBH_HID_CORE_Private_Functions * @{ */ /** * @brief USBH_HID_InterfaceInit * The function init the HID class. * @param pdev: Selected device * @param hdev: Selected device property * @retval USBH_Status :Response for USB HID driver intialization */ static USBH_Status USBH_HID_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev, void *phost) { uint8_t maxEP; USBH_HOST *pphost = phost; uint8_t num =0; USBH_Status status = USBH_BUSY ; HID_Machine.state = HID_ERROR; if(pphost->device_prop.Itf_Desc[0].bInterfaceSubClass == HID_BOOT_CODE) { /*Decode Bootclass Protocl: Mouse or Keyboard*/ if(pphost->device_prop.Itf_Desc[0].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE) { HID_Machine.cb = &HID_KEYBRD_cb; } else if(pphost->device_prop.Itf_Desc[0].bInterfaceProtocol == HID_MOUSE_BOOT_CODE) { HID_Machine.cb = &HID_MOUSE_cb; } HID_Machine.state = HID_IDLE; HID_Machine.ctl_state = HID_REQ_IDLE; HID_Machine.ep_addr = pphost->device_prop.Ep_Desc[0][0].bEndpointAddress; HID_Machine.length = pphost->device_prop.Ep_Desc[0][0].wMaxPacketSize; HID_Machine.poll = pphost->device_prop.Ep_Desc[0][0].bInterval ; /* Check fo available number of endpoints */ /* Find the number of EPs in the Interface Descriptor */ /* Choose the lower number in order not to overrun the buffer allocated */ maxEP = ( (pphost->device_prop.Itf_Desc[0].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ? pphost->device_prop.Itf_Desc[0].bNumEndpoints : USBH_MAX_NUM_ENDPOINTS); /* Decode endpoint IN and OUT address from interface descriptor */ for (num=0; num < maxEP; num++) { if(pphost->device_prop.Ep_Desc[0][num].bEndpointAddress & 0x80) { HID_Machine.HIDIntInEp = (pphost->device_prop.Ep_Desc[0][num].bEndpointAddress); HID_Machine.hc_num_in =\ USBH_Alloc_Channel(pdev, pphost->device_prop.Ep_Desc[0][num].bEndpointAddress); /* Open channel for IN endpoint */ USBH_Open_Channel (pdev, HID_Machine.hc_num_in, pphost->device_prop.address, pphost->device_prop.speed, EP_TYPE_INTR, HID_Machine.length); } else { HID_Machine.HIDIntOutEp = (pphost->device_prop.Ep_Desc[0][num].bEndpointAddress); HID_Machine.hc_num_out =\ USBH_Alloc_Channel(pdev, pphost->device_prop.Ep_Desc[0][num].bEndpointAddress); /* Open channel for OUT endpoint */ USBH_Open_Channel (pdev, HID_Machine.hc_num_out, pphost->device_prop.address, pphost->device_prop.speed, EP_TYPE_INTR, HID_Machine.length); } } flag =0; status = USBH_OK; } else { pphost->usr_cb->USBH_USR_DeviceNotSupported(); } return status; } /** * @brief USBH_HID_InterfaceDeInit * The function DeInit the Host Channels used for the HID class. * @param pdev: Selected device * @param hdev: Selected device property * @retval None */ void USBH_HID_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev, void *phost) { //USBH_HOST *pphost = phost; if(HID_Machine.hc_num_in != 0x00) { USB_OTG_HC_Halt(pdev, HID_Machine.hc_num_in); USBH_Free_Channel (pdev, HID_Machine.hc_num_in); HID_Machine.hc_num_in = 0; /* Reset the Channel as Free */ } if(HID_Machine.hc_num_out != 0x00) { USB_OTG_HC_Halt(pdev, HID_Machine.hc_num_out); USBH_Free_Channel (pdev, HID_Machine.hc_num_out); HID_Machine.hc_num_out = 0; /* Reset the Channel as Free */ } flag = 0; } /** * @brief USBH_HID_ClassRequest * The function is responsible for handling HID Class requests * for HID class. * @param pdev: Selected device * @param hdev: Selected device property * @retval USBH_Status :Response for USB Set Protocol request */ static USBH_Status USBH_HID_ClassRequest(USB_OTG_CORE_HANDLE *pdev , void *phost) { USBH_HOST *pphost = phost; USBH_Status status = USBH_BUSY; USBH_Status classReqStatus = USBH_BUSY; /* Switch HID state machine */ switch (HID_Machine.ctl_state) { case HID_IDLE: case HID_REQ_GET_HID_DESC: /* Get HID Desc */ if (USBH_Get_HID_Descriptor (pdev, pphost, USB_HID_DESC_SIZE)== USBH_OK) { USBH_ParseHIDDesc(&HID_Desc, pdev->host.Rx_Buffer); HID_Machine.ctl_state = HID_REQ_GET_REPORT_DESC; } break; case HID_REQ_GET_REPORT_DESC: /* Get Report Desc */ if (USBH_Get_HID_ReportDescriptor(pdev , pphost, HID_Desc.wItemLength) == USBH_OK) { HID_Machine.ctl_state = HID_REQ_SET_IDLE; } break; case HID_REQ_SET_IDLE: classReqStatus = USBH_Set_Idle (pdev, pphost, 0, 0); /* set Idle */ if (classReqStatus == USBH_OK) { HID_Machine.ctl_state = HID_REQ_SET_PROTOCOL; } else if(classReqStatus == USBH_NOT_SUPPORTED) { HID_Machine.ctl_state = HID_REQ_SET_PROTOCOL; } break; case HID_REQ_SET_PROTOCOL: /* set protocol */ if (USBH_Set_Protocol (pdev ,pphost, 0) == USBH_OK) { HID_Machine.ctl_state = HID_REQ_IDLE; /* all requests performed*/ status = USBH_OK; } break; default: break; } return status; } /** * @brief USBH_HID_Handle * The function is for managing state machine for HID data transfers * @param pdev: Selected device * @param hdev: Selected device property * @retval USBH_Status */ static USBH_Status USBH_HID_Handle(USB_OTG_CORE_HANDLE *pdev , void *phost) { USBH_HOST *pphost = phost; USBH_Status status = USBH_OK; switch (HID_Machine.state) { case HID_IDLE: HID_Machine.cb->Init(); HID_Machine.state = HID_GET_DATA; break; case HID_GET_DATA: /* Sync with start of Even Frame */ while(USB_OTG_IsEvenFrame(pdev) == FALSE); USBH_InterruptReceiveData(pdev, HID_Machine.buff, HID_Machine.length, HID_Machine.hc_num_in); flag = 1; HID_Machine.state = HID_POLL; HID_Machine.timer = HCD_GetCurrentFrame(pdev); break; case HID_POLL: if(( HCD_GetCurrentFrame(pdev) - HID_Machine.timer) >= HID_Machine.poll) { HID_Machine.state = HID_GET_DATA; } else if(HCD_GetURB_State(pdev , HID_Machine.hc_num_in) == URB_DONE) { if(flag == 1) /* handle data once */ { flag = 0; HID_Machine.cb->Decode(HID_Machine.buff); } } else if(HCD_GetURB_State(pdev, HID_Machine.hc_num_in) == URB_STALL) /* IN Endpoint Stalled */ { /* Issue Clear Feature on interrupt IN endpoint */ if( (USBH_ClrFeature(pdev, pphost, HID_Machine.ep_addr, HID_Machine.hc_num_in)) == USBH_OK) { /* Change state to issue next IN token */ HID_Machine.state = HID_GET_DATA; } } break; default: break; } return status; } /** * @brief USBH_Get_HID_ReportDescriptor * Issue report Descriptor command to the device. Once the response * received, parse the report descriptor and update the status. * @param pdev : Selected device * @param Length : HID Report Descriptor Length * @retval USBH_Status : Response for USB HID Get Report Descriptor Request */ static USBH_Status USBH_Get_HID_ReportDescriptor (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint16_t length) { USBH_Status status; status = USBH_GetDescriptor(pdev, phost, USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD, USB_DESC_HID_REPORT, pdev->host.Rx_Buffer, length); /* HID report descriptor is available in pdev->host.Rx_Buffer. In case of USB Boot Mode devices for In report handling , HID report descriptor parsing is not required. In case, for supporting Non-Boot Protocol devices and output reports, user may parse the report descriptor*/ return status; } /** * @brief USBH_Get_HID_Descriptor * Issue HID Descriptor command to the device. Once the response * received, parse the report descriptor and update the status. * @param pdev : Selected device * @param Length : HID Descriptor Length * @retval USBH_Status : Response for USB HID Get Report Descriptor Request */ static USBH_Status USBH_Get_HID_Descriptor (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint16_t length) { USBH_Status status; status = USBH_GetDescriptor(pdev, phost, USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD, USB_DESC_HID, pdev->host.Rx_Buffer, length); return status; } /** * @brief USBH_Set_Idle * Set Idle State. * @param pdev: Selected device * @param duration: Duration for HID Idle request * @param reportID : Targetted report ID for Set Idle request * @retval USBH_Status : Response for USB Set Idle request */ static USBH_Status USBH_Set_Idle (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t duration, uint8_t reportId) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\ USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = USB_HID_SET_IDLE; phost->Control.setup.b.wValue.w = (duration << 8 ) | reportId; phost->Control.setup.b.wIndex.w = 0; phost->Control.setup.b.wLength.w = 0; return USBH_CtlReq(pdev, phost, 0 , 0 ); } /** * @brief USBH_Set_Report * Issues Set Report * @param pdev: Selected device * @param reportType : Report type to be sent * @param reportID : Targetted report ID for Set Report request * @param reportLen : Length of data report to be send * @param reportBuff : Report Buffer * @retval USBH_Status : Response for USB Set Idle request */ USBH_Status USBH_Set_Report (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t reportType, uint8_t reportId, uint8_t reportLen, uint8_t* reportBuff) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\ USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = USB_HID_SET_REPORT; phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId; phost->Control.setup.b.wIndex.w = 0; phost->Control.setup.b.wLength.w = reportLen; return USBH_CtlReq(pdev, phost, reportBuff , reportLen ); } /** * @brief USBH_Set_Protocol * Set protocol State. * @param pdev: Selected device * @param protocol : Set Protocol for HID : boot/report protocol * @retval USBH_Status : Response for USB Set Protocol request */ static USBH_Status USBH_Set_Protocol(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t protocol) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\ USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = USB_HID_SET_PROTOCOL; if(protocol != 0) { /* Boot Protocol */ phost->Control.setup.b.wValue.w = 0; } else { /*Report Protocol*/ phost->Control.setup.b.wValue.w = 1; } phost->Control.setup.b.wIndex.w = 0; phost->Control.setup.b.wLength.w = 0; return USBH_CtlReq(pdev, phost, 0 , 0 ); } /** * @brief USBH_ParseHIDDesc * This function Parse the HID descriptor * @param buf: Buffer where the source descriptor is available * @retval None */ static void USBH_ParseHIDDesc (USBH_HIDDesc_TypeDef *desc, uint8_t *buf) { desc->bLength = *(uint8_t *) (buf + 0); desc->bDescriptorType = *(uint8_t *) (buf + 1); desc->bcdHID = LE16 (buf + 2); desc->bCountryCode = *(uint8_t *) (buf + 4); desc->bNumDescriptors = *(uint8_t *) (buf + 5); desc->bReportDescriptorType = *(uint8_t *) (buf + 6); desc->wItemLength = LE16 (buf + 7); } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/HID/src/usbh_hid_core.c
C
lgpl
19,103
/** ****************************************************************************** * @file usbh_hid_keybd.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file is the application layer for USB Host HID Keyboard handling * QWERTY and AZERTY Keyboard are supported as per the selection in * usbh_hid_keybd.h ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_keybd.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_HID_CLASS * @{ */ /** @defgroup USBH_HID_KEYBD * @brief This file includes HID Layer Handlers for USB Host HID class. * @{ */ /** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_HID_KEYBD_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_HID_KEYBD_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes * @{ */ static void KEYBRD_Init (void); static void KEYBRD_Decode(uint8_t *data); /** * @} */ #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined (__CC_ARM) /*!< ARM Compiler */ __align(4) #elif defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #elif defined (__GNUC__) /*!< GNU Compiler */ #pragma pack(4) #elif defined (__TASKING__) /*!< TASKING Compiler */ __align(4) #endif /* __CC_ARM */ #endif /** @defgroup USBH_HID_KEYBD_Private_Variables * @{ */ HID_cb_TypeDef HID_KEYBRD_cb= { KEYBRD_Init, KEYBRD_Decode }; /* ******************************************************************************* * LOCAL CONSTANTS ******************************************************************************* */ static const uint8_t HID_KEYBRD_Codes[] = { 0, 0, 0, 0, 31, 50, 48, 33, 19, 34, 35, 36, 24, 37, 38, 39, /* 0x00 - 0x0F */ 52, 51, 25, 26, 17, 20, 32, 21, 23, 49, 18, 47, 22, 46, 2, 3, /* 0x10 - 0x1F */ 4, 5, 6, 7, 8, 9, 10, 11, 43, 110, 15, 16, 61, 12, 13, 27, /* 0x20 - 0x2F */ 28, 29, 42, 40, 41, 1, 53, 54, 55, 30, 112, 113, 114, 115, 116, 117, /* 0x30 - 0x3F */ 118, 119, 120, 121, 122, 123, 124, 125, 126, 75, 80, 85, 76, 81, 86, 89, /* 0x40 - 0x4F */ 79, 84, 83, 90, 95, 100, 105, 106, 108, 93, 98, 103, 92, 97, 102, 91, /* 0x50 - 0x5F */ 96, 101, 99, 104, 45, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7F */ 0, 0, 0, 0, 0, 107, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xA0 - 0xAF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xB0 - 0xBF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xC0 - 0xCF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xD0 - 0xDF */ 58, 44, 60, 127, 64, 57, 62, 128 /* 0xE0 - 0xE7 */ }; #ifdef QWERTY_KEYBOARD static const int8_t HID_KEYBRD_Key[] = { '\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\0', '\r', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\', '\0', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '\0', '\n', '\0', '\0', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '\0', '\0', '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1', '\0', '/', '8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; static const int8_t HID_KEYBRD_ShiftKey[] = { '\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\0', '\0', '\0', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '|', '\0', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '\0', '\n', '\0', '\0', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; #else static const int8_t HID_KEYBRD_Key[] = { '\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\0', '\r', '\t', 'a', 'z', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\', '\0', 'q', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', '\0', '\0', '\n', '\0', '\0', 'w', 'x', 'c', 'v', 'b', 'n', ',', ';', ':', '!', '\0', '\0', '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1','\0', '/', '8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; static const int8_t HID_KEYBRD_ShiftKey[] = { '\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\0', '\0', '\0', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '*', '\0', 'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', '%', '\0', '\n', '\0', '\0', 'W', 'X', 'C', 'V', 'B', 'N', '?', '.', '/', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; #endif /** * @} */ /** @defgroup USBH_HID_KEYBD_Private_Functions * @{ */ /** * @brief KEYBRD_Init. * Initialize the keyboard function. * @param None * @retval None */ static void KEYBRD_Init (void) { /* Call User Init*/ USR_KEYBRD_Init(); } /** * @brief KEYBRD_ProcessData. * The function is to decode the pressed keys. * @param pbuf : Pointer to the HID IN report data buffer * @retval None */ static void KEYBRD_Decode(uint8_t *pbuf) { static uint8_t shift; static uint8_t keys[KBR_MAX_NBR_PRESSED]; static uint8_t keys_new[KBR_MAX_NBR_PRESSED]; static uint8_t keys_last[KBR_MAX_NBR_PRESSED]; static uint8_t key_newest; static uint8_t nbr_keys; static uint8_t nbr_keys_new; static uint8_t nbr_keys_last; uint8_t ix; uint8_t jx; uint8_t error; uint8_t output; nbr_keys = 0; nbr_keys_new = 0; nbr_keys_last = 0; key_newest = 0x00; /* Check if Shift key is pressed */ if ((pbuf[0] == KBD_LEFT_SHIFT) || (pbuf[0] == KBD_RIGHT_SHIFT)) { shift = TRUE; } else { shift = FALSE; } error = FALSE; /* Check for the value of pressed key */ for (ix = 2; ix < 2 + KBR_MAX_NBR_PRESSED; ix++) { if ((pbuf[ix] == 0x01) || (pbuf[ix] == 0x02) || (pbuf[ix] == 0x03)) { error = TRUE; } } if (error == TRUE) { return; } nbr_keys = 0; nbr_keys_new = 0; for (ix = 2; ix < 2 + KBR_MAX_NBR_PRESSED; ix++) { if (pbuf[ix] != 0) { keys[nbr_keys] = pbuf[ix]; nbr_keys++; for (jx = 0; jx < nbr_keys_last; jx++) { if (pbuf[ix] == keys_last[jx]) { break; } } if (jx == nbr_keys_last) { keys_new[nbr_keys_new] = pbuf[ix]; nbr_keys_new++; } } } if (nbr_keys_new == 1) { key_newest = keys_new[0]; if (shift == TRUE) { output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[key_newest]]; } else { output = HID_KEYBRD_Key[HID_KEYBRD_Codes[key_newest]]; } /* call user process handle */ USR_KEYBRD_ProcessData(output); } else { key_newest = 0x00; } nbr_keys_last = nbr_keys; for (ix = 0; ix < KBR_MAX_NBR_PRESSED; ix++) { keys_last[ix] = keys[ix]; } } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/HID/src/usbh_hid_keybd.c
C
lgpl
10,787
/** ****************************************************************************** * @file usbh_hid_mouse.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file contains all the prototypes for the usbh_hid_mouse.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_HID_MOUSE_H #define __USBH_HID_MOUSE_H /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_core.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_HID_CLASS * @{ */ /** @defgroup USBH_HID_MOUSE * @brief This file is the Header file for USBH_HID_MOUSE.c * @{ */ /** @defgroup USBH_HID_MOUSE_Exported_Types * @{ */ typedef struct _HID_MOUSE_Data { uint8_t x; uint8_t y; uint8_t z; /* Not Supported */ uint8_t button; } HID_MOUSE_Data_TypeDef; /** * @} */ /** @defgroup USBH_HID_MOUSE_Exported_Defines * @{ */ /** * @} */ /** @defgroup USBH_HID_MOUSE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_HID_MOUSE_Exported_Variables * @{ */ extern HID_cb_TypeDef HID_MOUSE_cb; extern HID_MOUSE_Data_TypeDef HID_MOUSE_Data; /** * @} */ /** @defgroup USBH_HID_MOUSE_Exported_FunctionsPrototype * @{ */ void USR_MOUSE_Init (void); void USR_MOUSE_ProcessData (HID_MOUSE_Data_TypeDef *data); /** * @} */ #endif /* __USBH_HID_MOUSE_H */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/HID/inc/usbh_hid_mouse.h
C
lgpl
2,549
/** ****************************************************************************** * @file usbh_hid_keybd.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file contains all the prototypes for the usbh_hid_keybd.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive -----------------------------------------------*/ #ifndef __USBH_HID_KEYBD_H #define __USBH_HID_KEYBD_H /* Includes ------------------------------------------------------------------*/ #include "usb_conf.h" #include "usbh_hid_core.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_HID_CLASS * @{ */ /** @defgroup USBH_HID_KEYBD * @brief This file is the Header file for USBH_HID_KEYBD.c * @{ */ /** @defgroup USBH_HID_KEYBD_Exported_Types * @{ */ /** * @} */ /** @defgroup USBH_HID_KEYBD_Exported_Defines * @{ */ //#define QWERTY_KEYBOARD #define AZERTY_KEYBOARD #define KBD_LEFT_CTRL 0x01 #define KBD_LEFT_SHIFT 0x02 #define KBD_LEFT_ALT 0x04 #define KBD_LEFT_GUI 0x08 #define KBD_RIGHT_CTRL 0x10 #define KBD_RIGHT_SHIFT 0x20 #define KBD_RIGHT_ALT 0x40 #define KBD_RIGHT_GUI 0x80 #define KBR_MAX_NBR_PRESSED 6 /** * @} */ /** @defgroup USBH_HID_KEYBD_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_HID_KEYBD_Exported_Variables * @{ */ extern HID_cb_TypeDef HID_KEYBRD_cb; /** * @} */ /** @defgroup USBH_HID_KEYBD_Exported_FunctionsPrototype * @{ */ void USR_KEYBRD_Init (void); void USR_KEYBRD_ProcessData (uint8_t pbuf); /** * @} */ #endif /* __USBH_HID_KEYBD_H */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/HID/inc/usbh_hid_keybd.h
C
lgpl
2,915
/** ****************************************************************************** * @file usbh_hid_core.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file contains all the prototypes for the usbh_hid_core.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_HID_CORE_H #define __USBH_HID_CORE_H /* Includes ------------------------------------------------------------------*/ #include "usbh_core.h" #include "usbh_stdreq.h" #include "usb_bsp.h" #include "usbh_ioreq.h" #include "usbh_hcs.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_CLASS * @{ */ /** @addtogroup USBH_HID_CLASS * @{ */ /** @defgroup USBH_HID_CORE * @brief This file is the Header file for USBH_HID_CORE.c * @{ */ /** @defgroup USBH_HID_CORE_Exported_Types * @{ */ /* States for HID State Machine */ typedef enum { HID_IDLE= 0, HID_SEND_DATA, HID_BUSY, HID_GET_DATA, HID_POLL, HID_ERROR, } HID_State; typedef enum { HID_REQ_IDLE = 0, HID_REQ_GET_REPORT_DESC, HID_REQ_GET_HID_DESC, HID_REQ_SET_IDLE, HID_REQ_SET_PROTOCOL, HID_REQ_SET_REPORT, } HID_CtlState; typedef struct HID_cb { void (*Init) (void); void (*Decode) (uint8_t *data); } HID_cb_TypeDef; typedef struct _HID_Report { uint8_t ReportID; uint8_t ReportType; uint16_t UsagePage; uint32_t Usage[2]; uint32_t NbrUsage; uint32_t UsageMin; uint32_t UsageMax; int32_t LogMin; int32_t LogMax; int32_t PhyMin; int32_t PhyMax; int32_t UnitExp; uint32_t Unit; uint32_t ReportSize; uint32_t ReportCnt; uint32_t Flag; uint32_t PhyUsage; uint32_t AppUsage; uint32_t LogUsage; } HID_Report_TypeDef; /* Structure for HID process */ typedef struct _HID_Process { uint8_t buff[64]; uint8_t hc_num_in; uint8_t hc_num_out; HID_State state; uint8_t HIDIntOutEp; uint8_t HIDIntInEp; HID_CtlState ctl_state; uint16_t length; uint8_t ep_addr; uint16_t poll; __IO uint16_t timer; HID_cb_TypeDef *cb; } HID_Machine_TypeDef; /** * @} */ /** @defgroup USBH_HID_CORE_Exported_Defines * @{ */ #define USB_HID_REQ_GET_REPORT 0x01 #define USB_HID_GET_IDLE 0x02 #define USB_HID_GET_PROTOCOL 0x03 #define USB_HID_SET_REPORT 0x09 #define USB_HID_SET_IDLE 0x0A #define USB_HID_SET_PROTOCOL 0x0B /** * @} */ /** @defgroup USBH_HID_CORE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_HID_CORE_Exported_Variables * @{ */ extern USBH_Class_cb_TypeDef HID_cb; /** * @} */ /** @defgroup USBH_HID_CORE_Exported_FunctionsPrototype * @{ */ USBH_Status USBH_Set_Report (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t reportType, uint8_t reportId, uint8_t reportLen, uint8_t* reportBuff); /** * @} */ #endif /* __USBH_HID_CORE_H */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Class/HID/inc/usbh_hid_core.h
C
lgpl
4,715
/** ****************************************************************************** * @file usbh_core.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file implements the functions for the core state machine process * the enumeration and the control transfer process ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_ioreq.h" #include "usb_bsp.h" #include "usbh_hcs.h" #include "usbh_stdreq.h" #include "usbh_core.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_CORE * @brief TThis file handles the basic enumaration when a device is connected * to the host. * @{ */ /** @defgroup USBH_CORE_Private_TypesDefinitions * @{ */ void USBH_Disconnect (void *pdev); void USBH_Connect (void *pdev); USB_OTG_hPort_TypeDef USBH_DeviceConnStatus_cb = { USBH_Disconnect, USBH_Connect, 0, 0, 0, 0 }; /** * @} */ /** @defgroup USBH_CORE_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_CORE_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_CORE_Private_Variables * @{ */ /** * @} */ /** @defgroup USBH_CORE_Private_FunctionPrototypes * @{ */ static USBH_Status USBH_HandleEnum(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost); USBH_Status USBH_HandleControl (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost); /** * @} */ /** @defgroup USBH_CORE_Private_Functions * @{ */ /** * @brief USBH_Connect * USB Connect callback function from the Interrupt. * @param selected device * @retval none */ void USBH_Connect (void *pdev) { USB_OTG_CORE_HANDLE *ppdev = pdev; ppdev->host.port_cb->ConnStatus = 1; ppdev->host.port_cb->ConnHandled = 0; } /** * @brief USBH_Disconnect * USB Disconnect callback function from the Interrupt. * @param selected device * @retval none */ void USBH_Disconnect (void *pdev) { USB_OTG_CORE_HANDLE *ppdev = pdev; /* Make device Not connected flag true */ ppdev->host.port_cb->DisconnStatus = 1; ppdev->host.port_cb->DisconnHandled = 0; } /** * @brief USBH_Init * Host hardware and stack initializations * @param class_cb: Class callback structure address * @param usr_cb: User callback structure address * @retval None */ void USBH_Init(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID, USBH_HOST *phost, USBH_Class_cb_TypeDef *class_cb, USBH_Usr_cb_TypeDef *usr_cb) { /* Hardware Init */ USB_OTG_BSP_Init(pdev); /* configure GPIO pin used for switching VBUS power */ USB_OTG_BSP_ConfigVBUS(0); /* Host de-initializations */ USBH_DeInit(pdev, phost); /*Register class and user callbacks */ phost->class_cb = class_cb; phost->usr_cb = usr_cb; pdev->host.port_cb = &USBH_DeviceConnStatus_cb; pdev->host.port_cb->ConnStatus = 0; pdev->host.port_cb->DisconnStatus = 0; /* Start the USB OTG core */ HCD_Init(pdev , coreID); /* Upon Init call usr call back */ phost->usr_cb->Init(); /* Enable Interrupts */ USB_OTG_BSP_EnableInterrupt(pdev); } /** * @brief USBH_DeInit * Re-Initialize Host * @param None * @retval status: USBH_Status */ USBH_Status USBH_DeInit(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost) { /* Software Init */ phost->gState = HOST_IDLE; phost->gStateBkp = HOST_IDLE; phost->EnumState = ENUM_IDLE; phost->RequestState = CMD_SEND; phost->Control.state = CTRL_SETUP; phost->Control.ep0size = USB_OTG_MAX_EP0_SIZE; phost->device_prop.address = USBH_DEVICE_ADDRESS_DEFAULT; phost->device_prop.speed = HPRT0_PRTSPD_FULL_SPEED; USBH_Free_Channel (pdev, phost->Control.hc_num_in); USBH_Free_Channel (pdev, phost->Control.hc_num_out); return USBH_OK; } /** * @brief USBH_Process * USB Host core main state machine process * @param None * @retval None */ void USBH_Process(USB_OTG_CORE_HANDLE *pdev , USBH_HOST *phost) { volatile USBH_Status status = USBH_FAIL; switch (phost->gState) { case HOST_ISSUE_CORE_RESET : if ( HCD_ResetPort(pdev) == 0) { phost->gState = HOST_IDLE; } break; case HOST_IDLE : if (HCD_IsDeviceConnected(pdev)) { /* Wait for USB Connect Interrupt void USBH_ISR_Connected(void) */ USBH_DeAllocate_AllChannel(pdev); phost->gState = HOST_DEV_ATTACHED; } break; case HOST_DEV_ATTACHED : phost->usr_cb->DeviceAttached(); pdev->host.port_cb->DisconnStatus = 0; pdev->host.port_cb->ConnHandled = 1; phost->Control.hc_num_out = USBH_Alloc_Channel(pdev, 0x00); phost->Control.hc_num_in = USBH_Alloc_Channel(pdev, 0x80); /* Reset USB Device */ if ( HCD_ResetPort(pdev) == 0) { phost->usr_cb->ResetDevice(); /* Wait for USB USBH_ISR_PrtEnDisableChange() Host is Now ready to start the Enumeration */ phost->device_prop.speed = HCD_GetCurrentSpeed(pdev); phost->gState = HOST_ENUMERATION; phost->usr_cb->DeviceSpeedDetected(phost->device_prop.speed); /* Open Control pipes */ USBH_Open_Channel (pdev, phost->Control.hc_num_in, phost->device_prop.address, phost->device_prop.speed, EP_TYPE_CTRL, phost->Control.ep0size); /* Open Control pipes */ USBH_Open_Channel (pdev, phost->Control.hc_num_out, phost->device_prop.address, phost->device_prop.speed, EP_TYPE_CTRL, phost->Control.ep0size); } break; case HOST_ENUMERATION: /* Check for enumeration status */ if ( USBH_HandleEnum(pdev , phost) == USBH_OK) { /* The function shall return USBH_OK when full enumeration is complete */ /* user callback for end of device basic enumeration */ phost->usr_cb->EnumerationDone(); phost->gState = HOST_USR_INPUT; } break; case HOST_USR_INPUT: /*The function should return user response true to move to class state */ if ( phost->usr_cb->UserInput() == USBH_USR_RESP_OK) { if((phost->class_cb->Init(pdev, phost))\ == USBH_OK) { phost->gState = HOST_CLASS_REQUEST; } } break; case HOST_CLASS_REQUEST: /* process class standard contol requests state machine */ status = phost->class_cb->Requests(pdev, phost); if(status == USBH_OK) { phost->gState = HOST_CLASS; } else { USBH_ErrorHandle(phost, status); } break; case HOST_CLASS: /* process class state machine */ status = phost->class_cb->Machine(pdev, phost); USBH_ErrorHandle(phost, status); break; case HOST_CTRL_XFER: /* process control transfer state machine */ USBH_HandleControl(pdev, phost); break; case HOST_SUSPENDED: break; case HOST_ERROR_STATE: /* Re-Initilaize Host for new Enumeration */ USBH_DeInit(pdev, phost); phost->usr_cb->DeInit(); phost->class_cb->DeInit(pdev, &phost->device_prop); break; default : break; } /* check device disconnection event */ if (!(HCD_IsDeviceConnected(pdev)) && (pdev->host.port_cb->DisconnHandled == 0)) { /* Manage User disconnect operations*/ phost->usr_cb->DeviceDisconnected(); pdev->host.port_cb->DisconnHandled = 1; /* Handle to avoid the Re-entry*/ /* Re-Initilaize Host for new Enumeration */ USBH_DeInit(pdev, phost); phost->usr_cb->DeInit(); phost->class_cb->DeInit(pdev, &phost->device_prop); } } /** * @brief USBH_ErrorHandle * This function handles the Error on Host side. * @param errType : Type of Error or Busy/OK state * @retval None */ void USBH_ErrorHandle(USBH_HOST *phost, USBH_Status errType) { /* Error unrecovered or not supported device speed */ if ( (errType == USBH_ERROR_SPEED_UNKNOWN) || (errType == USBH_UNRECOVERED_ERROR) ) { phost->usr_cb->UnrecoveredError(); phost->gState = HOST_ERROR_STATE; } /* USB host restart requested from application layer */ else if(errType == USBH_APPLY_DEINIT) { phost->gState = HOST_ERROR_STATE; /* user callback for initalization */ phost->usr_cb->Init(); } } /** * @brief USBH_HandleEnum * This function includes the complete enumeration process * @param pdev: Selected device * @retval USBH_Status */ static USBH_Status USBH_HandleEnum(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost) { USBH_Status Status = USBH_BUSY; uint8_t Local_Buffer[64]; switch (phost->EnumState) { case ENUM_IDLE: /* Get Device Desc for only 1st 8 bytes : To get EP0 MaxPacketSize */ if ( USBH_Get_DevDesc(pdev , phost, 8) == USBH_OK) { phost->Control.ep0size = phost->device_prop.Dev_Desc.bMaxPacketSize; /* Issue Reset */ HCD_ResetPort(pdev); phost->EnumState = ENUM_GET_FULL_DEV_DESC; /* modify control channels configuration for MaxPacket size */ USBH_Modify_Channel (pdev, phost->Control.hc_num_out, 0, 0, 0, phost->Control.ep0size); USBH_Modify_Channel (pdev, phost->Control.hc_num_in, 0, 0, 0, phost->Control.ep0size); } break; case ENUM_GET_FULL_DEV_DESC: /* Get FULL Device Desc */ if ( USBH_Get_DevDesc(pdev, phost, USB_DEVICE_DESC_SIZE)\ == USBH_OK) { /* user callback for device descriptor available */ phost->usr_cb->DeviceDescAvailable(&phost->device_prop.Dev_Desc); phost->EnumState = ENUM_SET_ADDR; } break; case ENUM_SET_ADDR: /* set address */ if ( USBH_SetAddress(pdev, phost, USBH_DEVICE_ADDRESS) == USBH_OK) { phost->device_prop.address = USBH_DEVICE_ADDRESS; /* user callback for device address assigned */ phost->usr_cb->DeviceAddressAssigned(); phost->EnumState = ENUM_GET_CFG_DESC; /* modify control channels to update device address */ USBH_Modify_Channel (pdev, phost->Control.hc_num_in, phost->device_prop.address, 0, 0, 0); USBH_Modify_Channel (pdev, phost->Control.hc_num_out, phost->device_prop.address, 0, 0, 0); } break; case ENUM_GET_CFG_DESC: /* get standard configuration descriptor */ if ( USBH_Get_CfgDesc(pdev, phost, USB_CONFIGURATION_DESC_SIZE) == USBH_OK) { phost->EnumState = ENUM_GET_FULL_CFG_DESC; } break; case ENUM_GET_FULL_CFG_DESC: /* get FULL config descriptor (config, interface, endpoints) */ if (USBH_Get_CfgDesc(pdev, phost, phost->device_prop.Cfg_Desc.wTotalLength) == USBH_OK) { /* User callback for configuration descriptors available */ phost->usr_cb->ConfigurationDescAvailable(&phost->device_prop.Cfg_Desc, phost->device_prop.Itf_Desc, phost->device_prop.Ep_Desc[0]); phost->EnumState = ENUM_GET_MFC_STRING_DESC; } break; case ENUM_GET_MFC_STRING_DESC: if (phost->device_prop.Dev_Desc.iManufacturer != 0) { /* Check that Manufacturer String is available */ if ( USBH_Get_StringDesc(pdev, phost, phost->device_prop.Dev_Desc.iManufacturer, Local_Buffer , 0xff) == USBH_OK) { /* User callback for Manufacturing string */ phost->usr_cb->ManufacturerString(Local_Buffer); phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; } } else { phost->usr_cb->ManufacturerString("N/A"); phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; } break; case ENUM_GET_PRODUCT_STRING_DESC: if (phost->device_prop.Dev_Desc.iProduct != 0) { /* Check that Product string is available */ if ( USBH_Get_StringDesc(pdev, phost, phost->device_prop.Dev_Desc.iProduct, Local_Buffer, 0xff) == USBH_OK) { /* User callback for Product string */ phost->usr_cb->ProductString(Local_Buffer); phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; } } else { phost->usr_cb->ProductString("N/A"); phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; } break; case ENUM_GET_SERIALNUM_STRING_DESC: if (phost->device_prop.Dev_Desc.iSerialNumber != 0) { /* Check that Serial number string is available */ if ( USBH_Get_StringDesc(pdev, phost, phost->device_prop.Dev_Desc.iSerialNumber, Local_Buffer, 0xff) == USBH_OK) { /* User callback for Serial number string */ phost->usr_cb->SerialNumString(Local_Buffer); phost->EnumState = ENUM_SET_CONFIGURATION; } } else { phost->usr_cb->SerialNumString("N/A"); phost->EnumState = ENUM_SET_CONFIGURATION; } break; case ENUM_SET_CONFIGURATION: /* set configuration (default config) */ if (USBH_SetCfg(pdev, phost, phost->device_prop.Cfg_Desc.bConfigurationValue) == USBH_OK) { phost->EnumState = ENUM_DEV_CONFIGURED; } break; case ENUM_DEV_CONFIGURED: /* user callback for enumeration done */ Status = USBH_OK; break; default: break; } return Status; } /** * @brief USBH_HandleControl * Handles the USB control transfer state machine * @param pdev: Selected device * @retval Status */ USBH_Status USBH_HandleControl (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost) { uint8_t direction; static uint16_t timeout = 0; USBH_Status status = USBH_OK; URB_STATE URB_Status = URB_IDLE; phost->Control.status = CTRL_START; switch (phost->Control.state) { case CTRL_SETUP: /* send a SETUP packet */ USBH_CtlSendSetup (pdev, phost->Control.setup.d8 , phost->Control.hc_num_out); phost->Control.state = CTRL_SETUP_WAIT; break; case CTRL_SETUP_WAIT: URB_Status = HCD_GetURB_State(pdev , phost->Control.hc_num_out); /* case SETUP packet sent successfully */ if(URB_Status == URB_DONE) { direction = (phost->Control.setup.b.bmRequestType & USB_REQ_DIR_MASK); /* check if there is a data stage */ if (phost->Control.setup.b.wLength.w != 0 ) { timeout = DATA_STAGE_TIMEOUT; if (direction == USB_D2H) { /* Data Direction is IN */ phost->Control.state = CTRL_DATA_IN; } else { /* Data Direction is OUT */ phost->Control.state = CTRL_DATA_OUT; } } /* No DATA stage */ else { timeout = NODATA_STAGE_TIMEOUT; /* If there is No Data Transfer Stage */ if (direction == USB_D2H) { /* Data Direction is IN */ phost->Control.state = CTRL_STATUS_OUT; } else { /* Data Direction is OUT */ phost->Control.state = CTRL_STATUS_IN; } } /* Set the delay timer to enable timeout for data stage completion */ phost->Control.timer = HCD_GetCurrentFrame(pdev); } else if(URB_Status == URB_ERROR) { phost->Control.state = CTRL_ERROR; phost->Control.status = CTRL_XACTERR; } break; case CTRL_DATA_IN: /* Issue an IN token */ USBH_CtlReceiveData(pdev, phost->Control.buff, phost->Control.length, phost->Control.hc_num_in); phost->Control.state = CTRL_DATA_IN_WAIT; break; case CTRL_DATA_IN_WAIT: URB_Status = HCD_GetURB_State(pdev , phost->Control.hc_num_in); /* check is DATA packet transfered successfully */ if (URB_Status == URB_DONE) { phost->Control.state = CTRL_STATUS_OUT; } /* manage error cases*/ if (URB_Status == URB_STALL) { /* In stall case, return to previous machine state*/ phost->gState = phost->gStateBkp; } else if (URB_Status == URB_ERROR) { /* Device error */ phost->Control.state = CTRL_ERROR; } else if ((HCD_GetCurrentFrame(pdev)- phost->Control.timer) > timeout) { /* timeout for IN transfer */ phost->Control.state = CTRL_ERROR; } break; case CTRL_DATA_OUT: /* Start DATA out transfer (only one DATA packet)*/ pdev->host.hc[phost->Control.hc_num_out].toggle_out ^= 1; USBH_CtlSendData (pdev, phost->Control.buff, phost->Control.length , phost->Control.hc_num_out); phost->Control.state = CTRL_DATA_OUT_WAIT; break; case CTRL_DATA_OUT_WAIT: URB_Status = HCD_GetURB_State(pdev , phost->Control.hc_num_out); if (URB_Status == URB_DONE) { /* If the Setup Pkt is sent successful, then change the state */ phost->Control.state = CTRL_STATUS_IN; } /* handle error cases */ else if (URB_Status == URB_STALL) { /* In stall case, return to previous machine state*/ phost->gState = phost->gStateBkp; } else if (URB_Status == URB_NOTREADY) { /* Nack received from device */ phost->Control.state = CTRL_DATA_OUT; } else if (URB_Status == URB_ERROR) { /* device error */ phost->Control.state = CTRL_ERROR; } break; case CTRL_STATUS_IN: /* Send 0 bytes out packet */ USBH_CtlReceiveData (pdev, 0, 0, phost->Control.hc_num_in); phost->Control.state = CTRL_STATUS_IN_WAIT; break; case CTRL_STATUS_IN_WAIT: URB_Status = HCD_GetURB_State(pdev , phost->Control.hc_num_in); if ( URB_Status == URB_DONE) { /* Control transfers completed, Exit the State Machine */ phost->gState = phost->gStateBkp; } else if (URB_Status == URB_ERROR) { phost->Control.state = CTRL_ERROR; } else if((HCD_GetCurrentFrame(pdev)\ - phost->Control.timer) > timeout) { phost->Control.state = CTRL_ERROR; } else if(URB_Status == URB_STALL) { /* Control transfers completed, Exit the State Machine */ phost->gState = phost->gStateBkp; phost->Control.status = CTRL_STALL; status = USBH_NOT_SUPPORTED; } break; case CTRL_STATUS_OUT: pdev->host.hc[phost->Control.hc_num_out].toggle_out ^= 1; USBH_CtlSendData (pdev, 0, 0, phost->Control.hc_num_out); phost->Control.state = CTRL_STATUS_OUT_WAIT; break; case CTRL_STATUS_OUT_WAIT: URB_Status = HCD_GetURB_State(pdev , phost->Control.hc_num_out); if (URB_Status == URB_DONE) { phost->gState = phost->gStateBkp; } else if (URB_Status == URB_NOTREADY) { phost->Control.state = CTRL_STATUS_OUT; } else if (URB_Status == URB_ERROR) { phost->Control.state = CTRL_ERROR; } break; case CTRL_ERROR: /* After a halt condition is encountered or an error is detected by the host, a control endpoint is allowed to recover by accepting the next Setup PID; i.e., recovery actions via some other pipe are not required for control endpoints. For the Default Control Pipe, a device reset will ultimately be required to clear the halt or error condition if the next Setup PID is not accepted. */ if (++ phost->Control.errorcount <= USBH_MAX_ERROR_COUNT) { /* Do the transmission again, starting from SETUP Packet */ phost->Control.state = CTRL_SETUP; } else { phost->Control.status = CTRL_FAIL; phost->gState = phost->gStateBkp; status = USBH_FAIL; } break; default: break; } return status; } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/src/usbh_core.c
C
lgpl
23,292
/** ****************************************************************************** * @file usbh_ioreq.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file handles the issuing of the USB transactions ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_ioreq.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_IOREQ * @brief This file handles the standard protocol processing (USB v2.0) * @{ */ /** @defgroup USBH_IOREQ_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_IOREQ_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_IOREQ_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_IOREQ_Private_Variables * @{ */ /** * @} */ /** @defgroup USBH_IOREQ_Private_FunctionPrototypes * @{ */ static USBH_Status USBH_SubmitSetupRequest(USBH_HOST *phost, uint8_t* buff, uint16_t length); /** * @} */ /** @defgroup USBH_IOREQ_Private_Functions * @{ */ /** * @brief USBH_CtlReq * USBH_CtlReq sends a control request and provide the status after * completion of the request * @param pdev: Selected device * @param req: Setup Request Structure * @param buff: data buffer address to store the response * @param length: length of the response * @retval Status */ USBH_Status USBH_CtlReq (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t *buff, uint16_t length) { USBH_Status status; URB_STATE URB_Status = URB_IDLE; URB_Status = HCD_GetURB_State(pdev, phost->Control.hc_num_out); status = USBH_BUSY; switch (phost->RequestState) { case CMD_SEND: /* Start a SETUP transfer */ USBH_SubmitSetupRequest(phost, buff, length); phost->RequestState = CMD_WAIT; status = USBH_BUSY; break; case CMD_WAIT: if (URB_Status == URB_DONE) { /* Commands successfully sent and Response Received */ phost->RequestState = CMD_SEND; status = USBH_OK; } else if (URB_Status == URB_ERROR) { /* Failure Mode */ phost->RequestState = CMD_SEND; status = USBH_FAIL; } else if (URB_Status == URB_STALL) { /* Commands successfully sent and Response Received */ phost->RequestState = CMD_SEND; status = USBH_NOT_SUPPORTED; } break; default: break; } return status; } /** * @brief USBH_CtlSendSetup * Sends the Setup Packet to the Device * @param pdev: Selected device * @param buff: Buffer pointer from which the Data will be send to Device * @param hc_num: Host channel Number * @retval Status */ USBH_Status USBH_CtlSendSetup ( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t hc_num){ pdev->host.hc[hc_num].ep_is_in = 0; pdev->host.hc[hc_num].data_pid = HC_PID_SETUP; pdev->host.hc[hc_num].xfer_buff = buff; pdev->host.hc[hc_num].xfer_len = USBH_SETUP_PKT_SIZE; return (USBH_Status)HCD_SubmitRequest (pdev , hc_num); } /** * @brief USBH_CtlSendData * Sends a data Packet to the Device * @param pdev: Selected device * @param buff: Buffer pointer from which the Data will be sent to Device * @param length: Length of the data to be sent * @param hc_num: Host channel Number * @retval Status */ USBH_Status USBH_CtlSendData ( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t length, uint8_t hc_num) { pdev->host.hc[hc_num].ep_is_in = 0; pdev->host.hc[hc_num].xfer_buff = buff; pdev->host.hc[hc_num].xfer_len = length; if ( length == 0 ) { /* For Status OUT stage, Length==0, Status Out PID = 1 */ pdev->host.hc[hc_num].toggle_out = 1; } /* Set the Data Toggle bit as per the Flag */ if ( pdev->host.hc[hc_num].toggle_out == 0) { /* Put the PID 0 */ pdev->host.hc[hc_num].data_pid = HC_PID_DATA0; } else { /* Put the PID 1 */ pdev->host.hc[hc_num].data_pid = HC_PID_DATA1 ; } HCD_SubmitRequest (pdev , hc_num); return USBH_OK; } /** * @brief USBH_CtlReceiveData * Receives the Device Response to the Setup Packet * @param pdev: Selected device * @param buff: Buffer pointer in which the response needs to be copied * @param length: Length of the data to be received * @param hc_num: Host channel Number * @retval Status. */ USBH_Status USBH_CtlReceiveData(USB_OTG_CORE_HANDLE *pdev, uint8_t* buff, uint8_t length, uint8_t hc_num) { pdev->host.hc[hc_num].ep_is_in = 1; pdev->host.hc[hc_num].data_pid = HC_PID_DATA1; pdev->host.hc[hc_num].xfer_buff = buff; pdev->host.hc[hc_num].xfer_len = length; HCD_SubmitRequest (pdev , hc_num); return USBH_OK; } /** * @brief USBH_BulkSendData * Sends the Bulk Packet to the device * @param pdev: Selected device * @param buff: Buffer pointer from which the Data will be sent to Device * @param length: Length of the data to be sent * @param hc_num: Host channel Number * @retval Status */ USBH_Status USBH_BulkSendData ( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint16_t length, uint8_t hc_num) { pdev->host.hc[hc_num].ep_is_in = 0; pdev->host.hc[hc_num].xfer_buff = buff; pdev->host.hc[hc_num].xfer_len = length; /* Set the Data Toggle bit as per the Flag */ if ( pdev->host.hc[hc_num].toggle_out == 0) { /* Put the PID 0 */ pdev->host.hc[hc_num].data_pid = HC_PID_DATA0; } else { /* Put the PID 1 */ pdev->host.hc[hc_num].data_pid = HC_PID_DATA1 ; } HCD_SubmitRequest (pdev , hc_num); return USBH_OK; } /** * @brief USBH_BulkReceiveData * Receives IN bulk packet from device * @param pdev: Selected device * @param buff: Buffer pointer in which the received data packet to be copied * @param length: Length of the data to be received * @param hc_num: Host channel Number * @retval Status. */ USBH_Status USBH_BulkReceiveData( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint16_t length, uint8_t hc_num) { pdev->host.hc[hc_num].ep_is_in = 1; pdev->host.hc[hc_num].xfer_buff = buff; pdev->host.hc[hc_num].xfer_len = length; if( pdev->host.hc[hc_num].toggle_in == 0) { pdev->host.hc[hc_num].data_pid = HC_PID_DATA0; } else { pdev->host.hc[hc_num].data_pid = HC_PID_DATA1; } HCD_SubmitRequest (pdev , hc_num); return USBH_OK; } /** * @brief USBH_InterruptReceiveData * Receives the Device Response to the Interrupt IN token * @param pdev: Selected device * @param buff: Buffer pointer in which the response needs to be copied * @param length: Length of the data to be received * @param hc_num: Host channel Number * @retval Status. */ USBH_Status USBH_InterruptReceiveData( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t length, uint8_t hc_num) { pdev->host.hc[hc_num].ep_is_in = 1; pdev->host.hc[hc_num].xfer_buff = buff; pdev->host.hc[hc_num].xfer_len = length; if(pdev->host.hc[hc_num].toggle_in == 0) { pdev->host.hc[hc_num].data_pid = HC_PID_DATA0; } else { pdev->host.hc[hc_num].data_pid = HC_PID_DATA1; } /* toggle DATA PID */ pdev->host.hc[hc_num].toggle_in ^= 1; HCD_SubmitRequest (pdev , hc_num); return USBH_OK; } /** * @brief USBH_InterruptSendData * Sends the data on Interrupt OUT Endpoint * @param pdev: Selected device * @param buff: Buffer pointer from where the data needs to be copied * @param length: Length of the data to be sent * @param hc_num: Host channel Number * @retval Status. */ USBH_Status USBH_InterruptSendData( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t length, uint8_t hc_num) { pdev->host.hc[hc_num].ep_is_in = 0; pdev->host.hc[hc_num].xfer_buff = buff; pdev->host.hc[hc_num].xfer_len = length; if(pdev->host.hc[hc_num].toggle_in == 0) { pdev->host.hc[hc_num].data_pid = HC_PID_DATA0; } else { pdev->host.hc[hc_num].data_pid = HC_PID_DATA1; } pdev->host.hc[hc_num].toggle_in ^= 1; HCD_SubmitRequest (pdev , hc_num); return USBH_OK; } /** * @brief USBH_SubmitSetupRequest * Start a setup transfer by changing the state-machine and * initializing the required variables needed for the Control Transfer * @param pdev: Selected device * @param setup: Setup Request Structure * @param buff: Buffer used for setup request * @param length: Length of the data * @retval Status. */ static USBH_Status USBH_SubmitSetupRequest(USBH_HOST *phost, uint8_t* buff, uint16_t length) { /* Save Global State */ phost->gStateBkp = phost->gState; /* Prepare the Transactions */ phost->gState = HOST_CTRL_XFER; phost->Control.buff = buff; phost->Control.length = length; phost->Control.state = CTRL_SETUP; return USBH_OK; } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/src/usbh_ioreq.c
C
lgpl
11,154
/** ****************************************************************************** * @file usbh_hcs.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file implements functions for opening and closing host channels ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hcs.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_HCS * @brief This file includes opening and closing host channels * @{ */ /** @defgroup USBH_HCS_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_HCS_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_HCS_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_HCS_Private_Variables * @{ */ /** * @} */ /** @defgroup USBH_HCS_Private_FunctionPrototypes * @{ */ static uint16_t USBH_GetFreeChannel (USB_OTG_CORE_HANDLE *pdev); /** * @} */ /** @defgroup USBH_HCS_Private_Functions * @{ */ /** * @brief USBH_Open_Channel * Open a pipe * @param pdev : Selected device * @param hc_num: Host channel Number * @param dev_address: USB Device address allocated to attached device * @param speed : USB device speed (Full/Low) * @param ep_type: end point type (Bulk/int/ctl) * @param mps: max pkt size * @retval Status */ uint8_t USBH_Open_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps) { pdev->host.hc[hc_num].ep_num = pdev->host.channel[hc_num]& 0x7F; pdev->host.hc[hc_num].ep_is_in = (pdev->host.channel[hc_num] & 0x80 ) == 0x80; pdev->host.hc[hc_num].dev_addr = dev_address; pdev->host.hc[hc_num].ep_type = ep_type; pdev->host.hc[hc_num].max_packet = mps; pdev->host.hc[hc_num].speed = speed; pdev->host.hc[hc_num].toggle_in = 0; pdev->host.hc[hc_num].toggle_out = 0; if(speed == HPRT0_PRTSPD_HIGH_SPEED) { pdev->host.hc[hc_num].do_ping = 1; } USB_OTG_HC_Init(pdev, hc_num) ; return HC_OK; } /** * @brief USBH_Modify_Channel * Modify a pipe * @param pdev : Selected device * @param hc_num: Host channel Number * @param dev_address: USB Device address allocated to attached device * @param speed : USB device speed (Full/Low) * @param ep_type: end point type (Bulk/int/ctl) * @param mps: max pkt size * @retval Status */ uint8_t USBH_Modify_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps) { if(dev_address != 0) { pdev->host.hc[hc_num].dev_addr = dev_address; } if((pdev->host.hc[hc_num].max_packet != mps) && (mps != 0)) { pdev->host.hc[hc_num].max_packet = mps; } if((pdev->host.hc[hc_num].speed != speed ) && (speed != 0 )) { pdev->host.hc[hc_num].speed = speed; } USB_OTG_HC_Init(pdev, hc_num); return HC_OK; } /** * @brief USBH_Alloc_Channel * Allocate a new channel for the pipe * @param ep_addr: End point for which the channel to be allocated * @retval hc_num: Host channel number */ uint8_t USBH_Alloc_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr) { uint16_t hc_num; hc_num = USBH_GetFreeChannel(pdev); if (hc_num != HC_ERROR) { pdev->host.channel[hc_num] = HC_USED | ep_addr; } return hc_num; } /** * @brief USBH_Free_Pipe * Free the USB host channel * @param idx: Channel number to be freed * @retval Status */ uint8_t USBH_Free_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t idx) { if(idx < HC_MAX) { pdev->host.channel[idx] &= HC_USED_MASK; } return USBH_OK; } /** * @brief USBH_DeAllocate_AllChannel * Free all USB host channel * @param pdev : core instance * @retval Status */ uint8_t USBH_DeAllocate_AllChannel (USB_OTG_CORE_HANDLE *pdev) { uint8_t idx; for (idx = 2; idx < HC_MAX ; idx ++) { pdev->host.channel[idx] = 0; } return USBH_OK; } /** * @brief USBH_GetFreeChannel * Get a free channel number for allocation to a device endpoint * @param None * @retval idx: Free Channel number */ static uint16_t USBH_GetFreeChannel (USB_OTG_CORE_HANDLE *pdev) { uint8_t idx = 0; for (idx = 0 ; idx < HC_MAX ; idx++) { if ((pdev->host.channel[idx] & HC_USED) == 0) { return idx; } } return HC_ERROR; } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/src/usbh_hcs.c
C
lgpl
5,860
/** ****************************************************************************** * @file usbh_stdreq.c * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief This file implements the standard requests for device enumeration ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "usbh_ioreq.h" #include "usbh_stdreq.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_STDREQ * @brief This file implements the standard requests for device enumeration * @{ */ /** @defgroup USBH_STDREQ_Private_Defines * @{ */ /** * @} */ /** @defgroup USBH_STDREQ_Private_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBH_STDREQ_Private_Macros * @{ */ /** * @} */ /** @defgroup USBH_STDREQ_Private_Variables * @{ */ /** * @} */ /** @defgroup USBH_STDREQ_Private_FunctionPrototypes * @{ */ static void USBH_ParseDevDesc (USBH_DevDesc_TypeDef* , uint8_t *buf, uint16_t length); static void USBH_ParseCfgDesc (USBH_CfgDesc_TypeDef* cfg_desc, USBH_InterfaceDesc_TypeDef* itf_desc, USBH_EpDesc_TypeDef* ep_desc, uint8_t *buf, uint16_t length); static USBH_DescHeader_t *USBH_GetNextDesc (uint8_t *pbuf, uint16_t *ptr); static void USBH_ParseInterfaceDesc (USBH_InterfaceDesc_TypeDef *if_descriptor, uint8_t *buf); static void USBH_ParseEPDesc (USBH_EpDesc_TypeDef *ep_descriptor, uint8_t *buf); static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length); /** * @} */ /** @defgroup USBH_STDREQ_Private_Functions * @{ */ /** * @brief USBH_Get_DevDesc * Issue Get Device Descriptor command to the device. Once the response * received, it parses the device descriptor and updates the status. * @param pdev: Selected device * @param dev_desc: Device Descriptor buffer address * @param pdev->host.Rx_Buffer: Receive Buffer address * @param length: Length of the descriptor * @retval Status */ USBH_Status USBH_Get_DevDesc(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t length) { USBH_Status status; if((status = USBH_GetDescriptor(pdev, phost, USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, USB_DESC_DEVICE, pdev->host.Rx_Buffer, length)) == USBH_OK) { /* Commands successfully sent and Response Received */ USBH_ParseDevDesc(&phost->device_prop.Dev_Desc, pdev->host.Rx_Buffer, length); } return status; } /** * @brief USBH_Get_CfgDesc * Issues Configuration Descriptor to the device. Once the response * received, it parses the configuartion descriptor and updates the * status. * @param pdev: Selected device * @param cfg_desc: Configuration Descriptor address * @param itf_desc: Interface Descriptor address * @param ep_desc: Endpoint Descriptor address * @param length: Length of the descriptor * @retval Status */ USBH_Status USBH_Get_CfgDesc(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint16_t length) { USBH_Status status; if((status = USBH_GetDescriptor(pdev, phost, USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, USB_DESC_CONFIGURATION, pdev->host.Rx_Buffer, length)) == USBH_OK) { /* Commands successfully sent and Response Received */ USBH_ParseCfgDesc (&phost->device_prop.Cfg_Desc, phost->device_prop.Itf_Desc, phost->device_prop.Ep_Desc[0], pdev->host.Rx_Buffer, length); } return status; } /** * @brief USBH_Get_StringDesc * Issues string Descriptor command to the device. Once the response * received, it parses the string descriptor and updates the status. * @param pdev: Selected device * @param string_index: String index for the descriptor * @param buff: Buffer address for the descriptor * @param length: Length of the descriptor * @retval Status */ USBH_Status USBH_Get_StringDesc(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t string_index, uint8_t *buff, uint16_t length) { USBH_Status status; if((status = USBH_GetDescriptor(pdev, phost, USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, USB_DESC_STRING | string_index, pdev->host.Rx_Buffer, length)) == USBH_OK) { /* Commands successfully sent and Response Received */ USBH_ParseStringDesc(pdev->host.Rx_Buffer,buff, length); } return status; } /** * @brief USBH_GetDescriptor * Issues Descriptor command to the device. Once the response received, * it parses the descriptor and updates the status. * @param pdev: Selected device * @param req_type: Descriptor type * @param value_idx: wValue for the GetDescriptr request * @param buff: Buffer to store the descriptor * @param length: Length of the descriptor * @retval Status */ USBH_Status USBH_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t req_type, uint16_t value_idx, uint8_t* buff, uint16_t length ) { phost->Control.setup.b.bmRequestType = USB_D2H | req_type; phost->Control.setup.b.bRequest = USB_REQ_GET_DESCRIPTOR; phost->Control.setup.b.wValue.w = value_idx; if ((value_idx & 0xff00) == USB_DESC_STRING) { phost->Control.setup.b.wIndex.w = 0x0409; } else { phost->Control.setup.b.wIndex.w = 0; } phost->Control.setup.b.wLength.w = length; return USBH_CtlReq(pdev, phost, buff , length ); } /** * @brief USBH_SetAddress * This command sets the address to the connected device * @param pdev: Selected device * @param DeviceAddress: Device address to assign * @retval Status */ USBH_Status USBH_SetAddress(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t DeviceAddress) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE | \ USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_SET_ADDRESS; phost->Control.setup.b.wValue.w = (uint16_t)DeviceAddress; phost->Control.setup.b.wIndex.w = 0; phost->Control.setup.b.wLength.w = 0; return USBH_CtlReq(pdev, phost, 0 , 0 ); } /** * @brief USBH_SetCfg * The command sets the configuration value to the connected device * @param pdev: Selected device * @param cfg_idx: Configuration value * @retval Status */ USBH_Status USBH_SetCfg(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint16_t cfg_idx) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE |\ USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_SET_CONFIGURATION; phost->Control.setup.b.wValue.w = cfg_idx; phost->Control.setup.b.wIndex.w = 0; phost->Control.setup.b.wLength.w = 0; return USBH_CtlReq(pdev, phost, 0 , 0 ); } /** * @brief USBH_ClrFeature * This request is used to clear or disable a specific feature. * @param pdev: Selected device * @param ep_num: endpoint number * @param hc_num: Host channel number * @retval Status */ USBH_Status USBH_ClrFeature(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t ep_num, uint8_t hc_num) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_ENDPOINT | USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_CLEAR_FEATURE; phost->Control.setup.b.wValue.w = FEATURE_SELECTOR_ENDPOINT; phost->Control.setup.b.wIndex.w = ep_num; phost->Control.setup.b.wLength.w = 0; if ((ep_num & USB_REQ_DIR_MASK ) == USB_D2H) { /* EP Type is IN */ pdev->host.hc[hc_num].toggle_in = 0; } else {/* EP Type is OUT */ pdev->host.hc[hc_num].toggle_out = 0; } return USBH_CtlReq(pdev, phost, 0 , 0 ); } /** * @brief USBH_ParseDevDesc * This function Parses the device descriptor * @param dev_desc: device_descriptor destinaton address * @param buf: Buffer where the source descriptor is available * @param length: Length of the descriptor * @retval None */ static void USBH_ParseDevDesc (USBH_DevDesc_TypeDef* dev_desc, uint8_t *buf, uint16_t length) { dev_desc->bLength = *(uint8_t *) (buf + 0); dev_desc->bDescriptorType = *(uint8_t *) (buf + 1); dev_desc->bcdUSB = LE16 (buf + 2); dev_desc->bDeviceClass = *(uint8_t *) (buf + 4); dev_desc->bDeviceSubClass = *(uint8_t *) (buf + 5); dev_desc->bDeviceProtocol = *(uint8_t *) (buf + 6); dev_desc->bMaxPacketSize = *(uint8_t *) (buf + 7); if (length > 8) { /* For 1st time after device connection, Host may issue only 8 bytes for Device Descriptor Length */ dev_desc->idVendor = LE16 (buf + 8); dev_desc->idProduct = LE16 (buf + 10); dev_desc->bcdDevice = LE16 (buf + 12); dev_desc->iManufacturer = *(uint8_t *) (buf + 14); dev_desc->iProduct = *(uint8_t *) (buf + 15); dev_desc->iSerialNumber = *(uint8_t *) (buf + 16); dev_desc->bNumConfigurations = *(uint8_t *) (buf + 17); } } /** * @brief USBH_ParseCfgDesc * This function Parses the configuration descriptor * @param cfg_desc: Configuration Descriptor address * @param itf_desc: Interface Descriptor address * @param ep_desc: Endpoint Descriptor address * @param buf: Buffer where the source descriptor is available * @param length: Length of the descriptor * @retval None */ static void USBH_ParseCfgDesc (USBH_CfgDesc_TypeDef* cfg_desc, USBH_InterfaceDesc_TypeDef* itf_desc, USBH_EpDesc_TypeDef* ep_desc, uint8_t *buf, uint16_t length) { USBH_InterfaceDesc_TypeDef *pif ; USBH_EpDesc_TypeDef *pep; USBH_DescHeader_t *pdesc = (USBH_DescHeader_t *)buf; uint16_t ptr; int8_t if_ix; int8_t ep_ix; pdesc = (USBH_DescHeader_t *)buf; /* Parse configuration descriptor */ cfg_desc->bLength = *(uint8_t *) (buf + 0); cfg_desc->bDescriptorType = *(uint8_t *) (buf + 1); cfg_desc->wTotalLength = LE16 (buf + 2); cfg_desc->bNumInterfaces = *(uint8_t *) (buf + 4); cfg_desc->bConfigurationValue = *(uint8_t *) (buf + 5); cfg_desc->iConfiguration = *(uint8_t *) (buf + 6); cfg_desc->bmAttributes = *(uint8_t *) (buf + 7); cfg_desc->bMaxPower = *(uint8_t *) (buf + 8); if (length > USB_CONFIGURATION_DESC_SIZE) { ptr = USB_LEN_CFG_DESC; if ( cfg_desc->bNumInterfaces <= USBH_MAX_NUM_INTERFACES) { if_ix = 0; pif = (USBH_InterfaceDesc_TypeDef *)0; /* Parse Interface descriptor relative to the current configuration */ if(cfg_desc->bNumInterfaces <= USBH_MAX_NUM_INTERFACES) { while (if_ix < cfg_desc->bNumInterfaces) { pdesc = USBH_GetNextDesc((uint8_t *)pdesc, &ptr); if (pdesc->bDescriptorType == USB_DESC_TYPE_INTERFACE) { pif = &itf_desc[if_ix]; USBH_ParseInterfaceDesc (pif, (uint8_t *)pdesc); ep_ix = 0; /* Parse Ep descriptors relative to the current interface */ if(pif->bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) { while (ep_ix < pif->bNumEndpoints) { pdesc = USBH_GetNextDesc((void* )pdesc, &ptr); if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT) { pep = &ep_desc[ep_ix]; USBH_ParseEPDesc (pep, (uint8_t *)pdesc); ep_ix++; } else { ptr += pdesc->bLength; } } } if_ix++; } else { ptr += pdesc->bLength; } } } } } } /** * @brief USBH_ParseInterfaceDesc * This function Parses the interface descriptor * @param if_descriptor : Interface descriptor destination * @param buf: Buffer where the descriptor data is available * @retval None */ static void USBH_ParseInterfaceDesc (USBH_InterfaceDesc_TypeDef *if_descriptor, uint8_t *buf) { if_descriptor->bLength = *(uint8_t *) (buf + 0); if_descriptor->bDescriptorType = *(uint8_t *) (buf + 1); if_descriptor->bInterfaceNumber = *(uint8_t *) (buf + 2); if_descriptor->bAlternateSetting = *(uint8_t *) (buf + 3); if_descriptor->bNumEndpoints = *(uint8_t *) (buf + 4); if_descriptor->bInterfaceClass = *(uint8_t *) (buf + 5); if_descriptor->bInterfaceSubClass = *(uint8_t *) (buf + 6); if_descriptor->bInterfaceProtocol = *(uint8_t *) (buf + 7); if_descriptor->iInterface = *(uint8_t *) (buf + 8); } /** * @brief USBH_ParseEPDesc * This function Parses the endpoint descriptor * @param ep_descriptor: Endpoint descriptor destination address * @param buf: Buffer where the parsed descriptor stored * @retval None */ static void USBH_ParseEPDesc (USBH_EpDesc_TypeDef *ep_descriptor, uint8_t *buf) { ep_descriptor->bLength = *(uint8_t *) (buf + 0); ep_descriptor->bDescriptorType = *(uint8_t *) (buf + 1); ep_descriptor->bEndpointAddress = *(uint8_t *) (buf + 2); ep_descriptor->bmAttributes = *(uint8_t *) (buf + 3); ep_descriptor->wMaxPacketSize = LE16 (buf + 4); ep_descriptor->bInterval = *(uint8_t *) (buf + 6); } /** * @brief USBH_ParseStringDesc * This function Parses the string descriptor * @param psrc: Source pointer containing the descriptor data * @param pdest: Destination address pointer * @param length: Length of the descriptor * @retval None */ static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length) { uint16_t strlength; uint16_t idx; /* The UNICODE string descriptor is not NULL-terminated. The string length is computed by substracting two from the value of the first byte of the descriptor. */ /* Check which is lower size, the Size of string or the length of bytes read from the device */ if ( psrc[1] == USB_DESC_TYPE_STRING) { /* Make sure the Descriptor is String Type */ /* psrc[0] contains Size of Descriptor, subtract 2 to get the length of string */ strlength = ( ( (psrc[0]-2) <= length) ? (psrc[0]-2) :length); psrc += 2; /* Adjust the offset ignoring the String Len and Descriptor type */ for (idx = 0; idx < strlength; idx+=2 ) {/* Copy Only the string and ignore the UNICODE ID, hence add the src */ *pdest = psrc[idx]; pdest++; } *pdest = 0; /* mark end of string */ } } /** * @brief USBH_GetNextDesc * This function return the next descriptor header * @param buf: Buffer where the cfg descriptor is available * @param ptr: data popinter inside the cfg descriptor * @retval next header */ static USBH_DescHeader_t *USBH_GetNextDesc (uint8_t *pbuf, uint16_t *ptr) { USBH_DescHeader_t *pnext; *ptr += ((USBH_DescHeader_t *)pbuf)->bLength; pnext = (USBH_DescHeader_t *)((uint8_t *)pbuf + \ ((USBH_DescHeader_t *)pbuf)->bLength); return(pnext); } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/src/usbh_stdreq.c
C
lgpl
18,436
/** ****************************************************************************** * @file usbh_conf_template * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief General USB Host library configuration ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBH_CONF__H__ #define __USBH_CONF__H__ /* Includes ------------------------------------------------------------------*/ /** @addtogroup USBH_OTG_DRIVER * @{ */ /** @defgroup USBH_CONF * @brief usb otg low level driver configuration file * @{ */ /** @defgroup USBH_CONF_Exported_Defines * @{ */ #define USBH_MAX_NUM_ENDPOINTS 2 #define USBH_MAX_NUM_INTERFACES 2 #ifdef USE_USB_OTG_FS #define USBH_MSC_MPS_SIZE 0x40 #else #define USBH_MSC_MPS_SIZE 0x200 #endif /** * @} */ /** @defgroup USBH_CONF_Exported_Types * @{ */ /** * @} */ /** @defgroup USBH_CONF_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_CONF_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBH_CONF_Exported_FunctionsPrototype * @{ */ /** * @} */ #endif //__USBH_CONF__H__ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/inc/usbh_conf_template.h
C
lgpl
2,173
/** ****************************************************************************** * @file usbh_stdreq.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief Header file for usbh_stdreq.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_STDREQ_H #define __USBH_STDREQ_H /* Includes ------------------------------------------------------------------*/ #include "usb_conf.h" #include "usb_hcd.h" #include "usbh_core.h" #include "usbh_def.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_STDREQ * @brief This file is the * @{ */ /** @defgroup USBH_STDREQ_Exported_Defines * @{ */ /*Standard Feature Selector for clear feature command*/ #define FEATURE_SELECTOR_ENDPOINT 0X00 #define FEATURE_SELECTOR_DEVICE 0X01 #define INTERFACE_DESC_TYPE 0x04 #define ENDPOINT_DESC_TYPE 0x05 #define INTERFACE_DESC_SIZE 0x09 #define USBH_HID_CLASS 0x03 /** * @} */ /** @defgroup USBH_STDREQ_Exported_Types * @{ */ /** * @} */ /** @defgroup USBH_STDREQ_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_STDREQ_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBH_STDREQ_Exported_FunctionsPrototype * @{ */ USBH_Status USBH_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t req_type, uint16_t value_idx, uint8_t* buff, uint16_t length ); USBH_Status USBH_Get_DevDesc(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t length); USBH_Status USBH_Get_StringDesc(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t string_index, uint8_t *buff, uint16_t length); USBH_Status USBH_SetCfg(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint16_t configuration_value); USBH_Status USBH_Get_CfgDesc(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint16_t length); USBH_Status USBH_SetAddress(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t DeviceAddress); USBH_Status USBH_ClrFeature(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t ep_num, uint8_t hc_num); USBH_Status USBH_Issue_ClrFeature(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t ep_num); /** * @} */ #endif /* __USBH_STDREQ_H */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/inc/usbh_stdreq.h
C
lgpl
4,174
/** ****************************************************************************** * @file usbh_hcs.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief Header file for usbh_hcs.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_HCS_H #define __USBH_HCS_H /* Includes ------------------------------------------------------------------*/ #include "usbh_core.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_HCS * @brief This file is the header file for usbh_hcs.c * @{ */ /** @defgroup USBH_HCS_Exported_Defines * @{ */ #define HC_MAX 8 #define HC_OK 0x0000 #define HC_USED 0x8000 #define HC_ERROR 0xFFFF #define HC_USED_MASK 0x7FFF /** * @} */ /** @defgroup USBH_HCS_Exported_Types * @{ */ /** * @} */ /** @defgroup USBH_HCS_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_HCS_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBH_HCS_Exported_FunctionsPrototype * @{ */ uint8_t USBH_Alloc_Channel(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr); uint8_t USBH_Free_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t idx); uint8_t USBH_DeAllocate_AllChannel (USB_OTG_CORE_HANDLE *pdev); uint8_t USBH_Open_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps); uint8_t USBH_Modify_Channel (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps); /** * @} */ #endif /* __USBH_HCS_H */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/inc/usbh_hcs.h
C
lgpl
2,940
/** ****************************************************************************** * @file usbh_ioreq.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief Header file for usbh_ioreq.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_IOREQ_H #define __USBH_IOREQ_H /* Includes ------------------------------------------------------------------*/ #include "usb_conf.h" #include "usbh_core.h" #include "usbh_def.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_IOREQ * @brief This file is the header file for usbh_ioreq.c * @{ */ /** @defgroup USBH_IOREQ_Exported_Defines * @{ */ #define USBH_SETUP_PKT_SIZE 8 #define USBH_EP0_EP_NUM 0 #define USBH_MAX_PACKET_SIZE 0x40 /** * @} */ /** @defgroup USBH_IOREQ_Exported_Types * @{ */ /** * @} */ /** @defgroup USBH_IOREQ_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_IOREQ_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBH_IOREQ_Exported_FunctionsPrototype * @{ */ USBH_Status USBH_CtlSendSetup ( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t hc_num); USBH_Status USBH_CtlSendData ( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t length, uint8_t hc_num); USBH_Status USBH_CtlReceiveData( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t length, uint8_t hc_num); USBH_Status USBH_BulkReceiveData( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint16_t length, uint8_t hc_num); USBH_Status USBH_BulkSendData ( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint16_t length, uint8_t hc_num); USBH_Status USBH_InterruptReceiveData( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t length, uint8_t hc_num); USBH_Status USBH_InterruptSendData( USB_OTG_CORE_HANDLE *pdev, uint8_t *buff, uint8_t length, uint8_t hc_num); USBH_Status USBH_CtlReq (USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost, uint8_t *buff, uint16_t length); /** * @} */ #endif /* __USBH_IOREQ_H */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/inc/usbh_ioreq.h
C
lgpl
3,873
/** ****************************************************************************** * @file usbh_core.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief Header file for usbh_core.c ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Define to prevent recursive ----------------------------------------------*/ #ifndef __USBH_CORE_H #define __USBH_CORE_H /* Includes ------------------------------------------------------------------*/ #include "usb_hcd.h" #include "usbh_def.h" #include "usbh_conf.h" /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_CORE * @brief This file is the Header file for usbh_core.c * @{ */ /** @defgroup USBH_CORE_Exported_Defines * @{ */ #define MSC_CLASS 0x08 #define HID_CLASS 0x03 #define MSC_PROTOCOL 0x50 #define CBI_PROTOCOL 0x01 #define USBH_MAX_ERROR_COUNT 2 #define USBH_DEVICE_ADDRESS_DEFAULT 0 #define USBH_DEVICE_ADDRESS 1 /** * @} */ /** @defgroup USBH_CORE_Exported_Types * @{ */ typedef enum { USBH_OK = 0, USBH_BUSY, USBH_FAIL, USBH_NOT_SUPPORTED, USBH_UNRECOVERED_ERROR, USBH_ERROR_SPEED_UNKNOWN, USBH_APPLY_DEINIT }USBH_Status; /* Following states are used for gState */ typedef enum { HOST_IDLE =0, HOST_ISSUE_CORE_RESET, HOST_DEV_ATTACHED, HOST_DEV_DISCONNECTED, HOST_ISSUE_RESET, HOST_DETECT_DEVICE_SPEED, HOST_ENUMERATION, HOST_CLASS_REQUEST, HOST_CLASS, HOST_CTRL_XFER, HOST_USR_INPUT, HOST_SUSPENDED, HOST_ERROR_STATE }HOST_State; /* Following states are used for EnumerationState */ typedef enum { ENUM_IDLE = 0, ENUM_GET_FULL_DEV_DESC, ENUM_SET_ADDR, ENUM_GET_CFG_DESC, ENUM_GET_FULL_CFG_DESC, ENUM_GET_MFC_STRING_DESC, ENUM_GET_PRODUCT_STRING_DESC, ENUM_GET_SERIALNUM_STRING_DESC, ENUM_SET_CONFIGURATION, ENUM_DEV_CONFIGURED } ENUM_State; /* Following states are used for CtrlXferStateMachine */ typedef enum { CTRL_IDLE =0, CTRL_SETUP, CTRL_SETUP_WAIT, CTRL_DATA_IN, CTRL_DATA_IN_WAIT, CTRL_DATA_OUT, CTRL_DATA_OUT_WAIT, CTRL_STATUS_IN, CTRL_STATUS_IN_WAIT, CTRL_STATUS_OUT, CTRL_STATUS_OUT_WAIT, CTRL_ERROR } CTRL_State; typedef enum { USBH_USR_NO_RESP = 0, USBH_USR_RESP_OK = 1, } USBH_USR_Status; /* Following states are used for RequestState */ typedef enum { CMD_IDLE =0, CMD_SEND, CMD_WAIT } CMD_State; typedef struct _Ctrl { uint8_t hc_num_in; uint8_t hc_num_out; uint8_t ep0size; uint8_t *buff; uint16_t length; uint8_t errorcount; uint16_t timer; CTRL_STATUS status; USB_Setup_TypeDef setup; CTRL_State state; } USBH_Ctrl_TypeDef; typedef struct _DeviceProp { uint8_t address; uint8_t speed; USBH_DevDesc_TypeDef Dev_Desc; USBH_CfgDesc_TypeDef Cfg_Desc; USBH_InterfaceDesc_TypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES]; USBH_EpDesc_TypeDef Ep_Desc[USBH_MAX_NUM_INTERFACES][USBH_MAX_NUM_ENDPOINTS]; USBH_HIDDesc_TypeDef HID_Desc; }USBH_Device_TypeDef; typedef struct _USBH_Class_cb { USBH_Status (*Init)\ (USB_OTG_CORE_HANDLE *pdev , void *phost); void (*DeInit)\ (USB_OTG_CORE_HANDLE *pdev , void *phost); USBH_Status (*Requests)\ (USB_OTG_CORE_HANDLE *pdev , void *phost); USBH_Status (*Machine)\ (USB_OTG_CORE_HANDLE *pdev , void *phost); } USBH_Class_cb_TypeDef; typedef struct _USBH_USR_PROP { void (*Init)(void); /* HostLibInitialized */ void (*DeInit)(void); /* HostLibInitialized */ void (*DeviceAttached)(void); /* DeviceAttached */ void (*ResetDevice)(void); void (*DeviceDisconnected)(void); void (*OverCurrentDetected)(void); void (*DeviceSpeedDetected)(uint8_t DeviceSpeed); /* DeviceSpeed */ void (*DeviceDescAvailable)(void *); /* DeviceDescriptor is available */ void (*DeviceAddressAssigned)(void); /* Address is assigned to USB Device */ void (*ConfigurationDescAvailable)(USBH_CfgDesc_TypeDef *, USBH_InterfaceDesc_TypeDef *, USBH_EpDesc_TypeDef *); /* Configuration Descriptor available */ void (*ManufacturerString)(void *); /* ManufacturerString*/ void (*ProductString)(void *); /* ProductString*/ void (*SerialNumString)(void *); /* SerialNubString*/ void (*EnumerationDone)(void); /* Enumeration finished */ USBH_USR_Status (*UserInput)(void); int (*USBH_USR_MSC_Application) (void); void (*USBH_USR_DeviceNotSupported)(void); /* Device is not supported*/ void (*UnrecoveredError)(void); } USBH_Usr_cb_TypeDef; typedef struct _Host_TypeDef { HOST_State gState; /* Host State Machine Value */ HOST_State gStateBkp; /* backup of previous State machine value */ ENUM_State EnumState; /* Enumeration state Machine */ CMD_State RequestState; USBH_Ctrl_TypeDef Control; USBH_Device_TypeDef device_prop; USBH_Class_cb_TypeDef *class_cb; USBH_Usr_cb_TypeDef *usr_cb; } USBH_HOST, *pUSBH_HOST; /** * @} */ /** @defgroup USBH_CORE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBH_CORE_Exported_Variables * @{ */ /** * @} */ /** @defgroup USBH_CORE_Exported_FunctionsPrototype * @{ */ void USBH_Init(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID, USBH_HOST *phost, USBH_Class_cb_TypeDef *class_cb, USBH_Usr_cb_TypeDef *usr_cb); USBH_Status USBH_DeInit(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost); void USBH_Process(USB_OTG_CORE_HANDLE *pdev , USBH_HOST *phost); void USBH_ErrorHandle(USBH_HOST *phost, USBH_Status errType); /** * @} */ #endif /* __USBH_CORE_H */ /** * @} */ /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/inc/usbh_core.h
C
lgpl
7,440
/** ****************************************************************************** * @file usbh_def.h * @author MCD Application Team * @version V2.0.0 * @date 22-July-2011 * @brief Definitions used in the USB host library ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /** @addtogroup USBH_LIB * @{ */ /** @addtogroup USBH_LIB_CORE * @{ */ /** @defgroup USBH_DEF * @brief This file is includes USB descriptors * @{ */ #ifndef USBH_DEF_H #define USBH_DEF_H #ifndef USBH_NULL #define USBH_NULL ((void *)0) #endif #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif #define ValBit(VAR,POS) (VAR & (1 << POS)) #define SetBit(VAR,POS) (VAR |= (1 << POS)) #define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255)) #define LE16(addr) (((u16)(*((u8 *)(addr))))\ + (((u16)(*(((u8 *)(addr)) + 1))) << 8)) #define USB_LEN_DESC_HDR 0x02 #define USB_LEN_DEV_DESC 0x12 #define USB_LEN_CFG_DESC 0x09 #define USB_LEN_IF_DESC 0x09 #define USB_LEN_EP_DESC 0x07 #define USB_LEN_OTG_DESC 0x03 #define USB_LEN_SETUP_PKT 0x08 /* bmRequestType :D7 Data Phase Transfer Direction */ #define USB_REQ_DIR_MASK 0x80 #define USB_H2D 0x00 #define USB_D2H 0x80 /* bmRequestType D6..5 Type */ #define USB_REQ_TYPE_STANDARD 0x00 #define USB_REQ_TYPE_CLASS 0x20 #define USB_REQ_TYPE_VENDOR 0x40 #define USB_REQ_TYPE_RESERVED 0x60 /* bmRequestType D4..0 Recipient */ #define USB_REQ_RECIPIENT_DEVICE 0x00 #define USB_REQ_RECIPIENT_INTERFACE 0x01 #define USB_REQ_RECIPIENT_ENDPOINT 0x02 #define USB_REQ_RECIPIENT_OTHER 0x03 /* Table 9-4. Standard Request Codes */ /* bRequest , Value */ #define USB_REQ_GET_STATUS 0x00 #define USB_REQ_CLEAR_FEATURE 0x01 #define USB_REQ_SET_FEATURE 0x03 #define USB_REQ_SET_ADDRESS 0x05 #define USB_REQ_GET_DESCRIPTOR 0x06 #define USB_REQ_SET_DESCRIPTOR 0x07 #define USB_REQ_GET_CONFIGURATION 0x08 #define USB_REQ_SET_CONFIGURATION 0x09 #define USB_REQ_GET_INTERFACE 0x0A #define USB_REQ_SET_INTERFACE 0x0B #define USB_REQ_SYNCH_FRAME 0x0C /* Table 9-5. Descriptor Types of USB Specifications */ #define USB_DESC_TYPE_DEVICE 1 #define USB_DESC_TYPE_CONFIGURATION 2 #define USB_DESC_TYPE_STRING 3 #define USB_DESC_TYPE_INTERFACE 4 #define USB_DESC_TYPE_ENDPOINT 5 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 #define USB_DESC_TYPE_INTERFACE_POWER 8 #define USB_DESC_TYPE_HID 0x21 #define USB_DESC_TYPE_HID_REPORT 0x22 #define USB_DEVICE_DESC_SIZE 18 #define USB_CONFIGURATION_DESC_SIZE 9 #define USB_HID_DESC_SIZE 9 #define USB_INTERFACE_DESC_SIZE 9 #define USB_ENDPOINT_DESC_SIZE 7 /* Descriptor Type and Descriptor Index */ /* Use the following values when calling the function USBH_GetDescriptor */ #define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00) #define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00) #define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00) #define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00) #define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00) #define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00) #define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00) #define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00) #define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00) #define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00) #define USB_EP_TYPE_CTRL 0x00 #define USB_EP_TYPE_ISOC 0x01 #define USB_EP_TYPE_BULK 0x02 #define USB_EP_TYPE_INTR 0x03 #define USB_EP_DIR_OUT 0x00 #define USB_EP_DIR_IN 0x80 #define USB_EP_DIR_MSK 0x80 /* supported classes */ #define USB_MSC_CLASS 0x08 #define USB_HID_CLASS 0x03 /* Interface Descriptor field values for HID Boot Protocol */ #define HID_BOOT_CODE 0x01 #define HID_KEYBRD_BOOT_CODE 0x01 #define HID_MOUSE_BOOT_CODE 0x02 /* As per USB specs 9.2.6.4 :Standard request with data request timeout: 5sec Standard request with no data stage timeout : 50ms */ #define DATA_STAGE_TIMEOUT 5000 #define NODATA_STAGE_TIMEOUT 50 /** * @} */ #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \ + USB_INTERFACE_DESC_SIZE\ + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE)) #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\ ConfigurationDescriptor.wTotalLength) /* This Union is copied from usb_core.h */ typedef union { uint16_t w; struct BW { uint8_t msb; uint8_t lsb; } bw; } uint16_t_uint8_t; typedef union _USB_Setup { uint8_t d8[8]; struct _SetupPkt_Struc { uint8_t bmRequestType; uint8_t bRequest; uint16_t_uint8_t wValue; uint16_t_uint8_t wIndex; uint16_t_uint8_t wLength; } b; } USB_Setup_TypeDef; typedef struct _DescHeader { uint8_t bLength; uint8_t bDescriptorType; } USBH_DescHeader_t; typedef struct _DeviceDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t bcdUSB; /* USB Specification Number which device complies too */ uint8_t bDeviceClass; uint8_t bDeviceSubClass; uint8_t bDeviceProtocol; /* If equal to Zero, each interface specifies its own class code if equal to 0xFF, the class code is vendor specified. Otherwise field is valid Class Code.*/ uint8_t bMaxPacketSize; uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */ uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */ uint16_t bcdDevice; /* Device Release Number */ uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */ uint8_t iProduct; /* Index of Product String Descriptor */ uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */ uint8_t bNumConfigurations; /* Number of Possible Configurations */ } USBH_DevDesc_TypeDef; typedef struct _ConfigurationDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t wTotalLength; /* Total Length of Data Returned */ uint8_t bNumInterfaces; /* Number of Interfaces */ uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/ uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */ uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/ uint8_t bMaxPower; /*Maximum Power Consumption */ } USBH_CfgDesc_TypeDef; typedef struct _HIDDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */ uint8_t bCountryCode; /* specifies the transfer type. */ uint8_t bNumDescriptors; /* specifies the transfer type. */ uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */ uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */ } USBH_HIDDesc_TypeDef; typedef struct _InterfaceDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bInterfaceNumber; uint8_t bAlternateSetting; /* Value used to select alternative setting */ uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */ uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */ uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */ uint8_t bInterfaceProtocol; /* Protocol Code */ uint8_t iInterface; /* Index of String Descriptor Describing this interface */ } USBH_InterfaceDesc_TypeDef; typedef struct _EndpointDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */ uint8_t bmAttributes; /* specifies the transfer type. */ uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */ uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */ } USBH_EpDesc_TypeDef; #endif /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1137519-player
lib/STM32_USB_HOST_Library/Core/inc/usbh_def.h
C
lgpl
11,228
/* * sd.c * * Created on: 2011/02/22 * Author: masayuki */ #include "sd.h" //#include "lcd.h" #include "usart.h" #include "fat.h" #include "delay.h" #include <stdio.h> #include <string.h> #include "settings.h" //#define SD_DEBUG //#define SDIO_DMA_ENABLE 1 volatile card_info_typedef cardInfo; void EXTI9_5_IRQHandler(void) // assigned for SD card detection (push/pull). { if(EXTI_GetFlagStatus(EXTI_Line8)){ Delayms(50); if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8)){ debug.printf("\r\nSD card pulled."); } else { debug.printf("\r\nSD card inserted."); } IWDG_Enable(); // software reset EXTI_ClearFlag(EXTI_Line8); while(1); } } /* inline void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST) { DMA_InitTypeDef DMA_InitStructure; DMA_ClearFlag(DMA2_Stream3, DMA_FLAG_FEIF3 | DMA_FLAG_DMEIF3 | DMA_FLAG_TEIF3 | DMA_FLAG_HTIF3 | DMA_FLAG_TCIF3); // !< DMA2 Channel4 disable DMA_Cmd(DMA2_Stream3, DISABLE); DMA_DeInit(DMA2_Stream3); // !< DMA2 Channel4 Config DMA_InitStructure.DMA_Channel = DMA_Channel_4; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SDIO->FIFO; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BufferDST; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = 0; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC4; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_INC4; DMA_Init(DMA2_Stream3, &DMA_InitStructure); DMA_FlowControllerConfig(DMA2_Stream3, DMA_FlowCtrl_Peripheral); // !< DMA2 Channel4 enable DMA_Cmd(DMA2_Stream3, ENABLE); } */ uint32_t SDSetDPSM(uint32_t dLen, uint32_t dBlkSize, uint32_t trDir, uint32_t trMode, uint32_t timeout, void *buf) { uint32_t ret, sta, *pbuf = (uint32_t*)buf; SDIO_DataInitTypeDef SDIO_DataInitStructure; // DPSM DPSM WAIT_R SDIO_DataInitStructure.SDIO_DataTimeOut = timeout; SDIO_DataInitStructure.SDIO_DataLength = dLen; SDIO_DataInitStructure.SDIO_DataBlockSize = dBlkSize; SDIO_DataInitStructure.SDIO_TransferDir = trDir; SDIO_DataInitStructure.SDIO_TransferMode = trMode; SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable; SDIO_DataConfig(&SDIO_DataInitStructure); do{ if(STA_RXDAVL_BB_FLAG){ *pbuf++ = SDIO->FIFO; } }while(!((sta = SDIO->STA) & SDIO_BLOCK_READ_STATUS_MASK)); #ifdef SD_DEBUG if(!(sta & SDIO_FLAG_DATAEND)){ if(sta & SDIO_FLAG_RXOVERR){ USARTPutString("\r\n*RXOVERR"); ret = SDIO_FLAG_RXOVERR; } if(sta & SDIO_FLAG_STBITERR){ USARTPutString("\r\n*STBITERR"); ret = SDIO_FLAG_STBITERR; } if(sta & SDIO_FLAG_DATAEND){ USARTPutString("\r\n*DATAEND"); ret = SDIO_FLAG_DATAEND; } if(sta & SDIO_FLAG_DTIMEOUT){ USARTPutString("\r\n*DTIMEOUT"); ret = SDIO_FLAG_DTIMEOUT; } if(sta & SDIO_FLAG_DCRCFAIL){ USARTPutString("\r\n*DCRCFAIL"); ret = SDIO_FLAG_DCRCFAIL; } } #endif SDIO_ClearFlag(SDIO_FLAG_STBITERR | SDIO_FLAG_DBCKEND | SDIO_FLAG_DATAEND | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DCRCFAIL); return ret; } uint32_t SDSendCMD(int cmdIdx, uint32_t arg, uint32_t resType, uint32_t *resbuf) { uint32_t sta; uint32_t ret = resType ? SDIO_FLAG_CMDREND : SDIO_FLAG_CMDSENT; SDIO_CmdInitTypeDef SDIO_CmdInitStructure; SDIO_CmdInitStructure.SDIO_Argument = arg; SDIO_CmdInitStructure.SDIO_CmdIndex = cmdIdx; SDIO_CmdInitStructure.SDIO_Response = resType; SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No; SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable; SDIO_SendCommand(&SDIO_CmdInitStructure); do{ sta = SDIO->STA; if(sta & SDIO_FLAG_CTIMEOUT){ ret = SDIO_FLAG_CTIMEOUT; USARTPutString("\r\n*TIMEOUT"); break; } if(sta & SDIO_FLAG_CCRCFAIL){ ret = SDIO_FLAG_CCRCFAIL; USARTPutString("\r\n*CRCFAIL"); break; } }while(!(sta & ret)); if(resType != SDIO_Response_No){ *(resbuf + 0) = SDIO_GetResponse(SDIO_RESP1); *(resbuf + 1) = SDIO_GetResponse(SDIO_RESP2); *(resbuf + 2) = SDIO_GetResponse(SDIO_RESP3); *(resbuf + 3) = SDIO_GetResponse(SDIO_RESP4); } SDIO_ClearFlag(SDIO_FLAG_CMDSENT | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT | SDIO_FLAG_CCRCFAIL); return ret; } /* void DMA2_Stream6_IRQHandler(void){ USARTPutString("\r\nDMA2_Stream6_IRQ"); } */ /* void SDIO_IRQHandler(void){ USARTPutString("\r\nSDIO_IRQ"); } */ inline uint32_t SDBlockRead(void *buf, uint32_t blockAddress) { __disable_irq(); uint32_t sta, timeout = 500000, *pbuf = (uint32_t*)buf; // CMD17 Single Block Read SDIO->ICR = 0xffffffff; SDIO->ARG = cardInfo.csdVer ? blockAddress : (blockAddress << 9); SDIO->CMD = SDIO_CPSM_Enable | SDIO_Wait_No | \ SDIO_Response_Short | 17; while(!((sta = SDIO->STA) & SDIO_CMD_STATUS_MASK)); #ifdef SD_DEBUG if(!(sta & SDIO_FLAG_CMDREND)){ USARTPutString("\r\nCMD17:"); if(sta & SDIO_FLAG_CTIMEOUT){ USARTPutString("\r\nCTIMEOUT"); } if(sta & SDIO_FLAG_CCRCFAIL){ USARTPutString("\r\nCCRCFAIL"); } if(sta & SDIO_FLAG_STBITERR){ USARTPutString("\r\nSTBITERR"); } } #endif #ifdef SDIO_DMA_ENABLE SD_LowLevel_DMA_RxConfig((uint32_t *)buf); SDIO->ICR = 0xffffffff; SDIO->DTIMER = 1000000; SDIO->DLEN = 512; SDIO->DCTRL = SDIO_DataBlockSize_512b | SDIO_TransferDir_ToSDIO | \ SDIO_TransferMode_Block | SDIO_DCTRL_DTEN | SDIO_DCTRL_DMAEN; while(!(DMA2->LISR & 0x08000000) && timeout--); sta = SDIO->STA; #else SDIO->ICR = 0xffffffff; SDIO->DTIMER = 0xffffffff; SDIO->DLEN = 512; SDIO->DCTRL = SDIO_DataBlockSize_512b | SDIO_TransferDir_ToSDIO | \ SDIO_TransferMode_Block | SDIO_DCTRL_DTEN; do{ while(STA_RXFIFOHF_BB_FLAG){ pbuf[0] = SDIO->FIFO; pbuf[1] = SDIO->FIFO; pbuf[2] = SDIO->FIFO; pbuf[3] = SDIO->FIFO; pbuf[4] = SDIO->FIFO; pbuf[5] = SDIO->FIFO; pbuf[6] = SDIO->FIFO; pbuf[7] = SDIO->FIFO; pbuf += 8; } }while(!((sta = SDIO->STA) & SDIO_BLOCK_READ_STATUS_MASK) && timeout--); #endif if(!(sta & (SDIO_FLAG_DATAEND | SDIO_FLAG_DBCKEND))){ #ifdef SD_DEBUG USARTPutString("\r\nBLOCK*"); if(sta & SDIO_FLAG_DCRCFAIL){ USARTPutString("DCRCFAIL"); } if(sta & SDIO_FLAG_DTIMEOUT){ USARTPutString("DTIMEOUT"); } if(timeout <= 0){ USARTPutString("STIMEOUT"); } if(sta & SDIO_FLAG_RXOVERR){ USARTPutString("RXOVERR"); } if(sta & SDIO_FLAG_STBITERR){ USARTPutString("STBITERR"); } #endif // CMD12 Stop Multi Block Read SDIO->ICR = 0xffffffff; SDIO->ARG = 0; SDIO->CMD = SDIO_CPSM_Enable | SDIO_Wait_No | \ SDIO_Response_Short | 12; while(!((sta = SDIO->STA) & SDIO_CMD_STATUS_MASK)); #ifdef SD_DEBUG if(!(sta & SDIO_FLAG_CMDREND)){ USARTPutString("\r\nCMD12:"); if(sta & SDIO_FLAG_CTIMEOUT){ USARTPutString("CTIMEOUT"); } if(sta & SDIO_FLAG_CCRCFAIL){ USARTPutString("CCRCFAIL"); } } #endif } __enable_irq(); return 0; } inline uint32_t SDMultiBlockRead(void *buf, uint32_t blockAddress, uint32_t count) { __disable_irq(); uint32_t sta, timeout = 100000, *pbuf = (uint32_t*)buf; // CMD18 Multi Block Read SDIO->ICR = 0xffffffff; SDIO->ARG = cardInfo.csdVer ? blockAddress : (blockAddress << 9); SDIO->CMD = SDIO_CPSM_Enable | SDIO_Wait_No | \ SDIO_Response_Short | 18; while(!((sta = SDIO->STA) & SDIO_CMD_STATUS_MASK)); #ifdef SD_DEBUG if(!(sta & SDIO_FLAG_CMDREND)){ USARTPutString("\r\nCMD18:"); if(sta & SDIO_FLAG_CTIMEOUT){ USARTPutString("CTIMEOUT"); } if(sta & SDIO_FLAG_CCRCFAIL){ USARTPutString("CCRCFAIL"); } } #endif #ifdef SDIO_DMA_ENABLE SD_LowLevel_DMA_RxConfig((uint32_t *)buf); SDIO->ICR = 0xffffffff; SDIO->DTIMER = 1000000; SDIO->DLEN = count << 9; SDIO->DCTRL = SDIO_DataBlockSize_512b | SDIO_TransferDir_ToSDIO | \ SDIO_TransferMode_Block | SDIO_DCTRL_DTEN | SDIO_DCTRL_DMAEN; while(!(DMA2->LISR & 0x08000000) && timeout--); sta = SDIO->STA; #else SDIO->DTIMER = 1000000; SDIO->DLEN = count << 9; SDIO->ICR = 0xffffffff; SDIO->DCTRL = SDIO_DataBlockSize_512b | SDIO_TransferDir_ToSDIO | \ SDIO_TransferMode_Block | SDIO_DCTRL_DTEN; do{ while(STA_RXFIFOHF_BB_FLAG){ pbuf[0] = SDIO->FIFO; pbuf[1] = SDIO->FIFO; pbuf[2] = SDIO->FIFO; pbuf[3] = SDIO->FIFO; pbuf[4] = SDIO->FIFO; pbuf[5] = SDIO->FIFO; pbuf[6] = SDIO->FIFO; pbuf[7] = SDIO->FIFO; pbuf += 8; } }while(!((sta = SDIO->STA) & SDIO_BLOCK_READ_STATUS_MASK) && timeout--); #endif #ifdef SD_DEBUG if(!(sta & SDIO_FLAG_DATAEND)){ USARTPutString("\r\nMULTI*"); if(sta & SDIO_FLAG_DCRCFAIL){ USARTPutString("DCRCFAIL"); } if(sta & SDIO_FLAG_DTIMEOUT){ USARTPutString("DTIMEOUT"); } if(timeout <= 0){ USARTPutString("STIMEOUT"); } if(sta & SDIO_FLAG_RXOVERR){ USARTPutString("RXOVERR"); } if(sta & SDIO_FLAG_STBITERR){ USARTPutString("STBITERR"); } } #endif // CMD12 Stop Multi Block Read SDIO->ICR = 0xffffffff; SDIO->ARG = 0; SDIO->CMD = SDIO_CPSM_Enable | SDIO_Wait_No | \ SDIO_Response_Short | 12; while(!((sta = SDIO->STA) & SDIO_CMD_STATUS_MASK)); #ifdef SD_DEBUG if(!(sta & SDIO_FLAG_CMDREND)){ USARTPutString("\r\nCMD12:"); if(sta & SDIO_FLAG_CTIMEOUT){ USARTPutString("CTIMEOUT"); } if(sta & SDIO_FLAG_CCRCFAIL){ USARTPutString("CCRCFAIL"); } } #endif __enable_irq(); return 0; } inline uint32_t SDMultiBlockWrite(void *buf, uint32_t blockAddress, uint32_t count) { __disable_irq(); uint32_t *pbuf = (uint32_t*)buf, ret = count * 512; uint32_t resbuf[4], res, sta; volatile int delay; res = SDSendCMD(55, cardInfo.rca, SDIO_Response_Short, resbuf); res = SDSendCMD(23, count, SDIO_Response_Short, resbuf); res = SDSendCMD(25, cardInfo.csdVer ? blockAddress : (blockAddress << 9), SDIO_Response_Short, resbuf); delay = 2000; while(delay--){}; // int fifo_cnt = 0; SDIO->DLEN = count * 512; SDIO->DTIMER = 0x0fffffff; SDIO->ICR = 0xffffffff; SDIO->DCTRL = SDIO_DataBlockSize_512b | SDIO_TransferDir_ToCard | \ SDIO_TransferMode_Block | SDIO_DCTRL_DTEN; do{ while((SDIO->STA & SDIO_FLAG_TXFIFOHE)){ // if(++fifo_cnt <= (count * 16)){ SDIO->FIFO = pbuf[0]; SDIO->FIFO = pbuf[1]; SDIO->FIFO = pbuf[2]; SDIO->FIFO = pbuf[3]; SDIO->FIFO = pbuf[4]; SDIO->FIFO = pbuf[5]; SDIO->FIFO = pbuf[6]; SDIO->FIFO = pbuf[7]; pbuf += 8; // } else { // SDIO->FIFO = 0; // SDIO->FIFO = 0; // SDIO->FIFO = 0; // SDIO->FIFO = 0; // SDIO->FIFO = 0; // SDIO->FIFO = 0; // SDIO->FIFO = 0; // SDIO->FIFO = 0; // } } }while(!((sta = SDIO->STA) & (SDIO_FLAG_TXUNDERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DATAEND | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_STBITERR))); if(!(sta & SDIO_FLAG_DATAEND)){ if(sta & SDIO_FLAG_TXUNDERR){ USARTPutString("\r\nSDIO_FLAG_TXUNDERR"); } if(sta & SDIO_FLAG_DCRCFAIL){ USARTPutString("\r\nSDIO_FLAG_DCRCFAIL"); debug.printf(" SDIO->DCOUNT:%d", SDIO->DCOUNT); } if(sta & SDIO_FLAG_DTIMEOUT){ USARTPutString("\r\nSDIO_FLAG_DTIMEOUT"); } if(sta & SDIO_FLAG_STBITERR){ USARTPutString("\r\nSDIO_FLAG_STBITERR"); } } while(SDIO->STA & SDIO_FLAG_TXACT){}; STOP: res = SDSendCMD(12, 0, SDIO_Response_Short, resbuf); resbuf[0] = 0; do{ res = SDSendCMD(13, cardInfo.rca, SDIO_Response_Short, resbuf); }while(!(resbuf[0] & 0x00000100)); __enable_irq(); return 0; } int SD_Switch_BusWidth(int width) { uint32_t res, resbuf[4]; SDIO_InitTypeDef SDIO_InitStructure; if(width != 1 && width != 4){ width = 1; } if(width == 4 && cardInfo.busWidth != 0x5){ width = 1; } // CMD55 USARTPutString("\r\n\nCMD55"); res = SDSendCMD(55, 0x00000000 | cardInfo.rca, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // ACMD6 USARTPutString("\r\n\nACMD6"); res = SDSendCMD(6, width == 1 ? 0x000000000 : 0x000000002, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); SDIO_InitStructure.SDIO_ClockDiv = 0; // SDIO_CK frequency = SDIOCLK / [CLKDIV + 2] = 48MHz / (0 + 2) = 24MHz SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising; SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable; SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Enable; SDIO_InitStructure.SDIO_BusWide = width == 1 ? SDIO_BusWide_1b : SDIO_BusWide_4b; SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable; SDIO_Init(&SDIO_InitStructure); return res; } int SDInit(void){ uint8_t tbuf[512]; uint16_t ccc; int i, hcsTry = 0, retry = 0; uint32_t res, resbuf[4]; SDIO_InitTypeDef SDIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); */ /* NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE); #ifdef SDIO_DMA_ENABLE RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); #endif GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_SDIO); // SDIO_D0 GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SDIO); // SDIO_D1 GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SDIO); // SDIO_D2 GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SDIO); // SDIO_D3 /* GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_SDIO); // SDIO_D4 GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_SDIO); // SDIO_D5 GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_SDIO); // SDIO_D6 GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SDIO); // SDIO_D7 */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SDIO); // SDIO_CK GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_SDIO); // SDIO_CMD // PORTC SDIO_D[3:0] SDIO_CK push-pull AFに設定 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* // PORTB GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); */ // PORTD SDIO_CMD push-pull AFに設定 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOD, &GPIO_InitStructure); // PORTA 8pin Card Detect GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); // PORTA 8pin as external interrupt EXTI_InitStructure.EXTI_Line = EXTI_Line8; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* 外部割込み設定 */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // SDIO初期設定 USARTPutString("\r\n***SD Card Debug***"); SDIO_DeInit(); SDIO_InitStructure.SDIO_ClockDiv = 255; SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising; SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable; SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Enable; SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b; SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable; SDIO_Init(&SDIO_InitStructure); SDIO_SetPowerState(SDIO_PowerState_ON); SDIO_ClockCmd(ENABLE); Delayms(10); // CMD0 USARTPutString("\r\n\nCMD0"); res = SDSendCMD(0, 0x00000000, SDIO_Response_No, resbuf); debug.printf("\r\nsta:0x%08x", res); Delayms(10); // CMD8 USARTPutString("\r\n\nCMD8"); res = SDSendCMD(8, 0x000001AA, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); if(res == SDIO_FLAG_CTIMEOUT){ USARTPutString("\r\nnot SD card"); do{ // CMD1 USARTPutString("\r\n\nCMD1"); res = SDSendCMD(1, 0x40FF8000, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); if(res == SDIO_FLAG_CTIMEOUT) goto SD_INIT; }while(!(resbuf[0] & _BV(31))); // CMD2 USARTPutString("\r\n\nCMD2"); res = SDSendCMD(2, 0x00000000, SDIO_Response_Long, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); debug.printf("\r\nres:0x%08x", resbuf[1]); debug.printf("\r\nres:0x%08x", resbuf[2]); debug.printf("\r\nres:0x%08x", resbuf[3]); cardInfo.rca = 0x00010000; // CMD3 USARTPutString("\r\n\nCMD3"); res = SDSendCMD(3, 0x00000000 | cardInfo.rca, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // CMD9 SEND_CSD USARTPutString("\r\n\nCMD9"); res = SDSendCMD(9, 0x00000000 | cardInfo.rca, SDIO_Response_Long, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); debug.printf("\r\nres:0x%08x", resbuf[1]); debug.printf("\r\nres:0x%08x", resbuf[2]); debug.printf("\r\nres:0x%08x", resbuf[3]); // CMD7 USARTPutString("\r\n\nCMD7"); res = SDSendCMD(7, 0x00000000 | cardInfo.rca, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // CMD6 powerclass USARTPutString("\r\n\nCMD6"); res = SDSendCMD(6, 0x03bb0a00, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); Delayms(10); SDIO_InitStructure.SDIO_ClockDiv = 0; // SDIO_CK frequency = SDIOCLK / [CLKDIV + 2] = 48MHz / (0 + 2) = 24MHz SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising; SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable; SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Enable; SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b; SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable; SDIO_Init(&SDIO_InitStructure); // CMD8 USARTPutString("\r\n\nCMD8"); res = SDSendCMD(8, 0x00000000, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); // DPSM DPSM WAIT_R for ACMD13 SDSetDPSM(512, SDIO_DataBlockSize_512b, SDIO_TransferDir_ToSDIO, SDIO_TransferMode_Block, 1000000, tbuf); for(i = 0;i < 512;i++){ if((i % 16) == 0) USARTPutString("\r\n"); debug.printf("%02x ", tbuf[i]); } // CMD16 USARTPutString("\r\n\nCMD16"); res = SDSendCMD(16, 0x00000200, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); cardInfo.csdVer = CSD_VER_1XX; /* int n; for(n = 0;n < 1000;n++){ SDBlockRead(tbuf, 0); for(i = 0;i < 512;i++){ if((i % 16) == 0) USARTPutString("\r\n"); debug.printf("%02x ", tbuf[i]); } } while(1); */ return 0; } SD_INIT: do{ // CMD55 USARTPutString("\r\n\nCMD55"); res = SDSendCMD(55, 0x00000000, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // ACMD41 if(!hcsTry){ USARTPutString("\r\n\nACMD41"); res = SDSendCMD(41, 0x00ff8000 | _BV(30), SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); if(res == SDIO_FLAG_CTIMEOUT) hcsTry = 1; }else{ USARTPutString("\r\n\nACMD41"); res = SDSendCMD(41, 0x00ff8000, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); } if(retry++ > 500){ USARTPutString("\r\n\nCard initialization failed!!"); return 1; } }while(!(resbuf[0] & _BV(31))); if(resbuf[0] & _BV(30)){ cardInfo.csdVer = CSD_VER_2XX; }else{ cardInfo.csdVer = CSD_VER_1XX; } // CMD2 USARTPutString("\r\n\nCMD2"); res = SDSendCMD(2, 0x00000000, SDIO_Response_Long, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); debug.printf("\r\nres:0x%08x", resbuf[1]); debug.printf("\r\nres:0x%08x", resbuf[2]); debug.printf("\r\nres:0x%08x", resbuf[3]); // CMD3 USARTPutString("\r\n\nCMD3"); res = SDSendCMD(3, 0x00000000, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); cardInfo.rca = resbuf[0] & 0xffff0000; // CMD9 SEND_CSD USARTPutString("\r\n\nCMD9"); res = SDSendCMD(9, 0x00000000 | cardInfo.rca, SDIO_Response_Long, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); debug.printf("\r\nres:0x%08x", resbuf[1]); debug.printf("\r\nres:0x%08x", resbuf[2]); debug.printf("\r\nres:0x%08x", resbuf[3]); // TRAN_SPEED cardInfo.tranSpeed = tranUnit[resbuf[0] & 0x00000007]; cardInfo.tranSpeed *= timeVal[(resbuf[0] & 0x00000078) >> 3]; // MAX_CLOCK_FREQUENCY ccc = (resbuf[1] >> 20) & 0x0fff; cardInfo.maxClkFreq = (ccc & _BV(10)) ? 50:20; if(cardInfo.csdVer == CSD_VER_1XX){ cardInfo.c_size = (resbuf[1] & 0x000003ff) << 2; cardInfo.c_size |= (resbuf[2] >> 30) & 0x3; // cardInfo.c_size_mult = (resbuf[2] & 0x00070000) >> 16; cardInfo.c_size_mult = (resbuf[2] & 0x00038000) >> 15; cardInfo.read_bl_len = (resbuf[1] & 0x000f0000) >> 16; cardInfo.totalBlocks = ((cardInfo.c_size + 1) << (cardInfo.c_size_mult + cardInfo.read_bl_len - 7)); } else if(cardInfo.csdVer == CSD_VER_2XX){ cardInfo.c_size = (resbuf[1] & 0x0000003f) << 16; cardInfo.c_size |= (resbuf[2] & 0xffff0000) >> 16; cardInfo.totalBlocks = (cardInfo.c_size + 1) << 10; } // CMD7 USARTPutString("\r\n\nCMD7"); res = SDSendCMD(7, 0x00000000 | cardInfo.rca, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); SDIO_InitStructure.SDIO_ClockDiv = 5; // SDIO_CK frequency = SDIOCLK / [CLKDIV + 2] = 48MHz / (0 + 2) = 24MHz SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising; SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable; SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Enable; SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b; SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable; SDIO_Init(&SDIO_InitStructure); // CMD16 USARTPutString("\r\n\nCMD16"); res = SDSendCMD(16, 0x00000200, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // CMD55 USARTPutString("\r\n\nCMD55"); res = SDSendCMD(55, 0x00000000 | cardInfo.rca, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // ACMD13 SD_STATUS USARTPutString("\r\n\nACMD13"); res = SDSendCMD(13, 0x00000000, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // DPSM DPSM WAIT_R for ACMD13 SDSetDPSM(64, SDIO_DataBlockSize_64b, SDIO_TransferDir_ToSDIO, SDIO_TransferMode_Block, 1000000, tbuf); // Speed Class Rating cardInfo.speedClass = tbuf[8] * 2; cardInfo.speedClass = cardInfo.speedClass < 8 ? cardInfo.speedClass : 10; // ACMD51 // CMD55 USARTPutString("\r\n\nCMD55"); res = SDSendCMD(55, 0x00000000 | cardInfo.rca, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // ACMD51 SEND_SCR USARTPutString("\r\n\nACMD51"); res = SDSendCMD(51, 0x00000000, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // DPSM DPSM WAIT_R for ACMD51 SDSetDPSM(8, SDIO_DataBlockSize_8b, SDIO_TransferDir_ToSDIO, SDIO_TransferMode_Block, 1000000, tbuf); cardInfo.specVer = tbuf[0] & 0x0f; cardInfo.busWidth = tbuf[1] & 0x0f; SD_Switch_BusWidth(settings_group.card_conf.busWidth); /* // CMD6 USARTPutString("\r\n\nCMD6"); res = SDSendCMD(6, 0x00FFFFFF, SDIO_Response_Short, resbuf); // res = SDSendCMD(6, 0x00000001, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // DPSM DPSM WAIT_R for CMD6 SDSetDPSM(64, SDIO_DataBlockSize_64b, SDIO_TransferDir_ToSDIO, SDIO_TransferMode_Block, 1000000, tbuf); debug.printf("\r\nHS support:%02x", tbuf[63-50]); debug.printf("\r\nswitch status:%02x", tbuf[63-47]); debug.printf("\r\nbusy check:%02x", tbuf[63-34]); debug.printf("\r\ninfo:%02x", tbuf[63-50]); for(i = 0;i < 64;i++){ if((i % 16) == 0) USARTPutString("\r\n"); debug.printf("%02x", tbuf[i]); } // CMD6 USARTPutString("\r\n\nCMD6"); // res = SDSendCMD(6, 0x80FFFFF1, SDIO_Response_Short, resbuf); res = SDSendCMD(6, 0x80000001, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // DPSM DPSM WAIT_R for CMD6 SDSetDPSM(64, SDIO_DataBlockSize_64b, SDIO_TransferDir_ToSDIO, SDIO_TransferMode_Block, 100000, tbuf); Delayms(100); SDIO_InitStructure.SDIO_ClockDiv = 0; // SDIO_CK frequency = SDIOCLK / [CLKDIV + 2] = 48MHz / (0 + 2) = 24MHz SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising; SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Enable; SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Enable; SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_4b; SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable; SDIO_Init(&SDIO_InitStructure); debug.printf("\r\nswitch status:%02x", tbuf[63-47]); debug.printf("\r\nbusy check:%02x", tbuf[63-34]); debug.printf("\r\ninfo:%02x", tbuf[63-50]); for(i = 0;i < 64;i++){ if((i % 16) == 0) USARTPutString("\r\n"); debug.printf("%02x", tbuf[i]); } // CMD6 USARTPutString("\r\n\nCMD6"); res = SDSendCMD(6, 0x00FFFFFF, SDIO_Response_Short, resbuf); // res = SDSendCMD(6, 0x80000001, SDIO_Response_Short, resbuf); debug.printf("\r\nsta:0x%08x", res); debug.printf("\r\nres:0x%08x", resbuf[0]); // DPSM DPSM WAIT_R for CMD6 SDSetDPSM(64, SDIO_DataBlockSize_64b, SDIO_TransferDir_ToSDIO, SDIO_TransferMode_Block, 100000, tbuf); debug.printf("\r\nswitch status:%02x", tbuf[63-47]); debug.printf("\r\nbusy check:%02x", tbuf[63-34]); debug.printf("\r\ninfo:%02x", tbuf[63-50]); for(i = 0;i < 64;i++){ if((i % 16) == 0) USARTPutString("\r\n"); debug.printf("%02x", tbuf[i]); } */ /* memset(tbuf, '\0', sizeof(tbuf)); SDMultiBlockRead(tbuf, 0, 1); USARTPutString("\r\nMBR"); for(i = 0;i < 512;i++){ if((i % 16) == 0) USARTPutString("\r\n"); debug.printf("%02x ", tbuf[i]); } */ debug.printf("\r\n\nSpec Version:%s", &specVer[cardInfo.specVer][0]); debug.printf("\r\nHigh Capacity:%s", cardInfo.csdVer ? "Yes" : "No"); char s[10]; if(cardInfo.speedClass){ SPRINTF(s, "CLASS%d", cardInfo.speedClass); } else { strcpy(s, "N/A"); } debug.printf("\r\nSpeed Class:%s", s); debug.printf("\r\nSupported Bus Widths:%s", &busWidth[cardInfo.busWidth][0]); debug.printf("\r\nMax Transfer Speed Per Bus:%dMbit/s", cardInfo.tranSpeed / 1000); debug.printf("\r\nMax Clock Frequency:%dMHz", cardInfo.maxClkFreq); debug.printf("\r\nTotal Blocks:%d", cardInfo.totalBlocks); debug.printf("\r\nccc:%04x", ccc); debug.printf("\r\nCard Capacity:%0.2fGB", (float)cardInfo.totalBlocks / 1000000000.0f * 512.0f); return 0; }
1137519-player
sd.c
C
lgpl
28,656
/* * aac.h * * Created on: 2012/03/27 * Author: Tonsuke */ #ifndef AAC_H_ #define AAC_H_ #include "stm32f4xx_conf.h" #include "mjpeg.h" typedef struct media_info_typedef { media_sound sound; sound_format format; esds_format bitrate; } media_info_typedef; extern int PlayAAC(int id); #endif /* AAC_H_ */
1137519-player
aac.h
C
lgpl
322
/* * mpool.h * * Created on: 2011/05/14 * Author: Tonsuke */ #ifndef MPOOL_H_ #define MPOOL_H_ #include "stm32f4xx_conf.h" #include "fat.h" #define CCM_BASE ((uint32_t)(0x10000000)) /* Core Coupled Memory Base Address 64KB */ volatile struct { uint32_t mem_seek; }mpool_struct; uint8_t mempool[38000]; extern void create_mpool(); extern void* mpool_alloc(uint32_t sizeofmemory); extern void mpool_destroy(); extern void* jmemread(MY_FILE *fp, size_t *nbytes, int32_t n); #endif /* MPOOL_H_ */
1137519-player
mpool.h
C
lgpl
515
/* * board_config.h * * Created on: 2013/02/07 * Author: Tonsuke */ #ifndef BOARD_CONFIG_H_ #define BOARD_CONFIG_H_ #include "stm32f4xx_conf.h" #define FLASH_SECTOR_1_OFFSET (0x4000) #define FLASH_SECOTR_1_ADDR (FLASH_BASE + FLASH_SECTOR_1_OFFSET) #define FLASH_SECTOR_1_SIZE (16384) #define FLASH_SETTING_OFFSET (0x3000) #define FLASH_SETTING_BASE (FLASH_BASE + FLASH_SECTOR_1_OFFSET + FLASH_SETTING_OFFSET) #define FLASH_SETTING_SIZE (4096) #define TP_CAL_OFFSET 0 #define GET_VAL_FLASH_SETTING(type, offset) (*(type*)(FLASH_SETTING_BASE + offset)) /* XPT2046_CS_BB */ /* --- GPIOA ODR Register ---*/ /* Alias word address of GPIOA ODR 15 bit */ #define GPIOA_ODR_OFFSET (GPIOA_BASE + 0x14) #define GPIOA_ODR_15_BitNumber 0x0F #define GPIOA_ODR_15_BB (*(__IO uint32_t *)(PERIPH_BB_BASE + (GPIOA_ODR_OFFSET * 32) + (GPIOA_ODR_15_BitNumber * 4))) #define XPT2046_CS_BB GPIOA_ODR_15_BB #define XPT2046_CS_DEASSERT (XPT2046_CS_BB = 1) #define XPT2046_CS_ASSERT (XPT2046_CS_BB = 0) /* TP_PEN_INPUT_BB */ /* --- GPIOC IDR Register ---*/ /* Alias word address of GPIOC IDR 4 bit */ #define GPIOC_IDR_OFFSET (GPIOC_BASE + 0x10) #define GPIOC_IDR_4_BitNumber 0x04 #define GPIOC_IDR_4_BB (*(__IO uint32_t *)(PERIPH_BB_BASE + (GPIOC_IDR_OFFSET * 32) + (GPIOC_IDR_4_BitNumber * 4))) #define TP_PEN_INPUT_BB GPIOC_IDR_4_BB /* AUDIO_OUT_BB */ /* --- GPIOC ODR Register ---*/ /* Alias word address of GPIOC ODR 5 bit */ #define GPIOC_ODR_OFFSET (GPIOC_BASE + 0x14) #define GPIOC_ODR_5_BitNumber 0x05 #define GPIOC_ODR_5_BB (*(__IO uint32_t *)(PERIPH_BB_BASE + (GPIOC_ODR_OFFSET * 32) + (GPIOC_ODR_5_BitNumber * 4))) #define AUDIO_OUT_BB GPIOC_ODR_5_BB #define AUDIO_OUT_SHUTDOWN (AUDIO_OUT_BB = 0) #define AUDIO_OUT_ENABLE (AUDIO_OUT_BB = 1) /* SOUND_DMA_HALF_TRANS_BB */ /* --- DMA1 LISR Register ---*/ /* Alias word address of DMA1 LISR DMA_LISR_HTIF1 bit */ #define DMA1_LISR_OFFSET (DMA1_BASE + 0x0) #define DMA1_LISR_DMA_LISR_HTIF1_BitNumber 10 #define DMA1_LISR_DMA_LISR_HTIF1_BB (*(__IO uint32_t *)(PERIPH_BB_BASE + (DMA1_LISR_OFFSET * 32) + (DMA1_LISR_DMA_LISR_HTIF1_BitNumber * 4))) #define SOUND_DMA_HALF_TRANS_BB DMA1_LISR_DMA_LISR_HTIF1_BB /* SOUND_DMA_CLEAR_HALF_TRANS_BB */ /* --- DMA1 LIFCR Register ---*/ /* Alias word address of DMA1 LIFCR DMA_LIFCR_CHTIF1 bit */ #define DMA1_LIFCR_OFFSET (DMA1_BASE + 0x8) #define DMA1_LIFCR_DMA_LIFCR_CHTIF1_BitNumber 10 #define DMA1_LIFCR_DMA_LIFCR_CHTIF1_BB (*(__IO uint32_t *)(PERIPH_BB_BASE + (DMA1_LIFCR_OFFSET * 32) + (DMA1_LIFCR_DMA_LIFCR_CHTIF1_BitNumber * 4))) #define SOUND_DMA_CLEAR_HALF_TRANS_BB DMA1_LIFCR_DMA_LIFCR_CHTIF1_BB /* SOUND_DMA_FULL_TRANS_BB */ /* --- DMA1 LISR Register ---*/ /* Alias word address of DMA1 LISR DMA_LISR_TCIF1 bit */ #define DMA1_LISR_OFFSET (DMA1_BASE + 0x0) #define DMA1_LISR_DMA_LISR_TCIF1_BitNumber 11 #define DMA1_LISR_DMA_LISR_TCIF1_BB (*(__IO uint32_t *)(PERIPH_BB_BASE + (DMA1_LISR_OFFSET * 32) + (DMA1_LISR_DMA_LISR_TCIF1_BitNumber * 4))) #define SOUND_DMA_FULL_TRANS_BB DMA1_LISR_DMA_LISR_TCIF1_BB /* SOUND_DMA_CLEAR_FULL_TRANS_BB */ /* --- DMA1 LIFCR Register ---*/ /* Alias word address of DMA1 LIFCR DMA_LIFCR_CTCIF1 bit */ #define DMA1_LIFCR_OFFSET (DMA1_BASE + 0x8) #define DMA1_LIFCR_DMA_LIFCR_CTCIF1_BitNumber 11 #define DMA1_LIFCR_DMA_LIFCR_CTCIF1_BB (*(__IO uint32_t *)(PERIPH_BB_BASE + (DMA1_LIFCR_OFFSET * 32) + (DMA1_LIFCR_DMA_LIFCR_CTCIF1_BitNumber * 4))) #define SOUND_DMA_CLEAR_FULL_TRANS_BB DMA1_LIFCR_DMA_LIFCR_CTCIF1_BB #define TRANSFER_IT_ENABLE_MASK (uint32_t)(DMA_SxCR_TCIE | DMA_SxCR_HTIE | \ DMA_SxCR_TEIE | DMA_SxCR_DMEIE) #define DMA_SOUND_IT_ENABLE (DMA1_Stream1->CR |= (uint32_t)((DMA_IT_TC | DMA_IT_HT) & TRANSFER_IT_ENABLE_MASK)) #define DMA_SOUND_IT_DISABLE (DMA1_Stream1->CR &= ~(uint32_t)((DMA_IT_TC | DMA_IT_HT) & TRANSFER_IT_ENABLE_MASK)) #endif /* BOARD_CONFIG_H_ */
1137519-player
board_config.h
C
lgpl
3,980
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.tech; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import android.nfc.tech.NfcF; import com.sinpo.xnfc.nfc.Util; public class FeliCa { public static final byte[] EMPTY = {}; protected byte[] data; protected FeliCa() { } protected FeliCa(byte[] bytes) { data = (bytes == null) ? FeliCa.EMPTY : bytes; } public int size() { return data.length; } public byte[] getBytes() { return data; } @Override public String toString() { return Util.toHexString(data, 0, data.length); } public final static class IDm extends FeliCa { public static final byte[] EMPTY = { 0, 0, 0, 0, 0, 0, 0, 0, }; public IDm(byte[] bytes) { super((bytes == null || bytes.length < 8) ? IDm.EMPTY : bytes); } public final String getManufactureCode() { return Util.toHexString(data, 0, 2); } public final String getCardIdentification() { return Util.toHexString(data, 2, 6); } public boolean isEmpty() { final byte[] d = data; for (final byte v : d) { if (v != 0) return false; } return true; } } public final static class PMm extends FeliCa { public static final byte[] EMPTY = { 0, 0, 0, 0, 0, 0, 0, 0, }; public PMm(byte[] bytes) { super((bytes == null || bytes.length < 8) ? PMm.EMPTY : bytes); } public final String getIcCode() { return Util.toHexString(data, 0, 2); } public final String getMaximumResponseTime() { return Util.toHexString(data, 2, 6); } } public final static class SystemCode extends FeliCa { public static final byte[] EMPTY = { 0, 0, }; public SystemCode(byte[] sc) { super((sc == null || sc.length < 2) ? SystemCode.EMPTY : sc); } public int toInt() { return toInt(data); } public static int toInt(byte[] data) { return 0x0000FFFF & ((data[0] << 8) | (0x000000FF & data[1])); } } public final static class ServiceCode extends FeliCa { public static final byte[] EMPTY = { 0, 0, }; public static final int T_UNKNOWN = 0; public static final int T_RANDOM = 1; public static final int T_CYCLIC = 2; public static final int T_PURSE = 3; public ServiceCode(byte[] sc) { super((sc == null || sc.length < 2) ? ServiceCode.EMPTY : sc); } public ServiceCode(int code) { this(new byte[] { (byte) (code & 0xFF), (byte) (code >> 8) }); } public int toInt() { return 0x0000FFFF & ((data[1] << 8) | (0x000000FF & data[0])); } public boolean isEncrypt() { return (data[0] & 0x1) == 0; } public boolean isWritable() { final int f = data[0] & 0x3F; return (f & 0x2) == 0 || f == 0x13 || f == 0x12; } public int getAccessAttr() { return data[0] & 0x3F; } public int getDataType() { final int f = data[0] & 0x3F; if ((f & 0x10) == 0) return T_PURSE; return ((f & 0x04) == 0) ? T_RANDOM : T_CYCLIC; } } public final static class Block extends FeliCa { public Block() { data = new byte[16]; } public Block(byte[] bytes) { super((bytes == null || bytes.length < 16) ? new byte[16] : bytes); } } public final static class BlockListElement extends FeliCa { private static final byte LENGTH_2_BYTE = (byte) 0x80; private static final byte LENGTH_3_BYTE = (byte) 0x00; // private static final byte ACCESSMODE_DECREMENT = (byte) 0x00; // private static final byte ACCESSMODE_CACHEBACK = (byte) 0x01; private final byte lengthAndaccessMode; private final byte serviceCodeListOrder; public BlockListElement(byte mode, byte order, byte... blockNumber) { if (blockNumber.length > 1) { lengthAndaccessMode = (byte) (mode | LENGTH_2_BYTE & 0xFF); } else { lengthAndaccessMode = (byte) (mode | LENGTH_3_BYTE & 0xFF); } serviceCodeListOrder = (byte) (order & 0x0F); data = (blockNumber == null) ? FeliCa.EMPTY : blockNumber; } @Override public byte[] getBytes() { if ((this.lengthAndaccessMode & LENGTH_2_BYTE) == 1) { ByteBuffer buff = ByteBuffer.allocate(2); buff.put( (byte) ((this.lengthAndaccessMode | this.serviceCodeListOrder) & 0xFF)) .put(data[0]); return buff.array(); } else { ByteBuffer buff = ByteBuffer.allocate(3); buff.put( (byte) ((this.lengthAndaccessMode | this.serviceCodeListOrder) & 0xFF)) .put(data[1]).put(data[0]); return buff.array(); } } } public final static class MemoryConfigurationBlock extends FeliCa { public MemoryConfigurationBlock(byte[] bytes) { super((bytes == null || bytes.length < 4) ? new byte[4] : bytes); } public boolean isNdefSupport() { return (data == null) ? false : (data[3] & (byte) 0xff) == 1; } public void setNdefSupport(boolean ndefSupport) { data[3] = (byte) (ndefSupport ? 1 : 0); } public boolean isWritable(int... addrs) { if (data == null) return false; boolean result = true; for (int a : addrs) { byte b = (byte) ((a & 0xff) + 1); if (a < 8) { result &= (data[0] & b) == b; continue; } else if (a < 16) { result &= (data[1] & b) == b; continue; } else result &= (data[2] & b) == b; } return result; } } public final static class Service extends FeliCa { private final ServiceCode[] serviceCodes; private final BlockListElement[] blockListElements; public Service(ServiceCode[] codes, BlockListElement... blocks) { serviceCodes = (codes == null) ? new ServiceCode[0] : codes; blockListElements = (blocks == null) ? new BlockListElement[0] : blocks; } @Override public byte[] getBytes() { int length = 0; for (ServiceCode s : this.serviceCodes) { length += s.getBytes().length; } for (BlockListElement b : blockListElements) { length += b.getBytes().length; } ByteBuffer buff = ByteBuffer.allocate(length); for (ServiceCode s : this.serviceCodes) { buff.put(s.getBytes()); } for (BlockListElement b : blockListElements) { buff.put(b.getBytes()); } return buff.array(); } @Override public String toString() { StringBuilder sb = new StringBuilder(); for (ServiceCode s : serviceCodes) { sb.append(s.toString()); } for (BlockListElement b : blockListElements) { sb.append(b.toString()); } return sb.toString(); } } public final static class Command extends FeliCa { private final int length; private final byte code; private final IDm idm; public Command(final byte[] bytes) { this(bytes[0], Arrays.copyOfRange(bytes, 1, bytes.length)); } public Command(byte code, final byte... bytes) { this.code = code; if (bytes.length >= 8) { idm = new IDm(Arrays.copyOfRange(bytes, 0, 8)); data = Arrays.copyOfRange(bytes, 8, bytes.length); } else { idm = null; data = bytes; } length = bytes.length + 2; } public Command(byte code, IDm idm, final byte... bytes) { this.code = code; this.idm = idm; this.data = bytes; this.length = idm.getBytes().length + data.length + 2; } public Command(byte code, byte[] idm, final byte... bytes) { this.code = code; this.idm = new IDm(idm); this.data = bytes; this.length = idm.length + data.length + 2; } @Override public byte[] getBytes() { ByteBuffer buff = ByteBuffer.allocate(length); byte length = (byte) this.length; if (idm != null) { buff.put(length).put(code).put(idm.getBytes()).put(data); } else { buff.put(length).put(code).put(data); } return buff.array(); } } public static class Response extends FeliCa { protected final int length; protected final byte code; protected final IDm idm; public Response(byte[] bytes) { if (bytes != null && bytes.length >= 10) { length = bytes[0] & 0xff; code = bytes[1]; idm = new IDm(Arrays.copyOfRange(bytes, 2, 10)); data = bytes; } else { length = 0; code = 0; idm = new IDm(null); data = FeliCa.EMPTY; } } public IDm getIDm() { return idm; } } public final static class PollingResponse extends Response { private final PMm pmm; public PollingResponse(byte[] bytes) { super(bytes); if (size() >= 18) { pmm = new PMm(Arrays.copyOfRange(data, 10, 18)); } else { pmm = new PMm(null); } } public PMm getPMm() { return pmm; } } public final static class ReadResponse extends Response { public static final byte[] EMPTY = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xFF, (byte) 0xFF }; private final byte[] blockData; public ReadResponse(byte[] rsp) { super((rsp == null || rsp.length < 12) ? ReadResponse.EMPTY : rsp); if (getStatusFlag1() == STA1_NORMAL && getBlockCount() > 0) { blockData = Arrays.copyOfRange(data, 13, data.length); } else { blockData = FeliCa.EMPTY; } } public int getStatusFlag1() { return data[10] & 0x000000FF; } public int getStatusFlag2() { return data[11] & 0x000000FF; } public int getStatusFlag12() { return (getStatusFlag1() << 8) | getStatusFlag2(); } public int getBlockCount() { return (data.length > 12) ? (0xFF & data[12]) : 0; } public byte[] getBlockData() { return blockData; } public boolean isOkey() { return getStatusFlag1() == STA1_NORMAL; } } public final static class WriteResponse extends Response { public WriteResponse(byte[] rsp) { super((rsp == null || rsp.length < 12) ? ReadResponse.EMPTY : rsp); } public int getStatusFlag1() { return data[0] & 0x000000FF; } public int getStatusFlag2() { return data[1] & 0x000000FF; } public int getStatusFlag12() { return (getStatusFlag1() << 8) | getStatusFlag2(); } public boolean isOkey() { return getStatusFlag1() == STA1_NORMAL; } } public final static class Tag { private final NfcF nfcTag; private boolean isFeliCaLite; private byte[] sys; private IDm idm; private PMm pmm; public Tag(NfcF tag) { nfcTag = tag; sys = tag.getSystemCode(); idm = new IDm(tag.getTag().getId()); pmm = new PMm(tag.getManufacturer()); } public int getSystemCode() { return SystemCode.toInt(sys); } public byte[] getSystemCodeByte() { return sys; } public IDm getIDm() { return idm; } public PMm getPMm() { return pmm; } public boolean checkFeliCaLite() throws IOException { isFeliCaLite = !polling(SYS_FELICA_LITE).getIDm().isEmpty(); return isFeliCaLite; } public boolean isFeliCaLite() { return isFeliCaLite; } public PollingResponse polling(int systemCode) throws IOException { Command cmd = new Command(CMD_POLLING, new byte[] { (byte) (systemCode >> 8), (byte) (systemCode & 0xff), (byte) 0x01, (byte) 0x00 }); final byte s[] = cmd.getBytes(); final byte r[] = transceive(s); final PollingResponse rsp = new PollingResponse(r); idm = rsp.getIDm(); pmm = rsp.getPMm(); return rsp; } public PollingResponse polling() throws IOException { return polling(SYS_FELICA_LITE); } public final SystemCode[] getSystemCodeList() throws IOException { final Command cmd = new Command(CMD_REQUEST_SYSTEMCODE, idm); final byte s[] = cmd.getBytes(); final byte r[] = transceive(s); final int num; if (r == null || r.length < 12 || r[1] != (byte) 0x0d) { num = 0; } else { num = r[10] & 0x000000FF; } final SystemCode ret[] = new SystemCode[num]; for (int i = 0; i < num; ++i) { ret[i] = new SystemCode(Arrays.copyOfRange(r, 11 + i * 2, 13 + i * 2)); } return ret; } public ServiceCode[] getServiceCodeList() throws IOException { ArrayList<ServiceCode> ret = new ArrayList<ServiceCode>(); int index = 1; while (true) { byte[] bytes = searchServiceCode(index); if (bytes.length != 2 && bytes.length != 4) break; if (bytes.length == 2) { if (bytes[0] == (byte) 0xff && bytes[1] == (byte) 0xff) break; ret.add(new ServiceCode(bytes)); } ++index; } return ret.toArray(new ServiceCode[ret.size()]); } public byte[] searchServiceCode(int index) throws IOException { Command cmd = new Command(CMD_SEARCH_SERVICECODE, idm, new byte[] { (byte) (index & 0xff), (byte) (index >> 8) }); final byte s[] = cmd.getBytes(); final byte r[] = transceive(s); final byte ret[]; if (r == null || r.length < 12 || r[1] != (byte) 0x0b) ret = FeliCa.EMPTY; else ret = Arrays.copyOfRange(r, 10, r.length); return ret; } public ReadResponse readWithoutEncryption(byte addr, byte... service) throws IOException { Command cmd = new Command(CMD_READ_WO_ENCRYPTION, idm, new byte[] { (byte) 0x01, (byte) service[0], (byte) service[1], (byte) 0x01, (byte) 0x80, addr }); final byte s[] = cmd.getBytes(); final byte r[] = transceive(s); final ReadResponse ret = new ReadResponse(r); return ret; } public ReadResponse readWithoutEncryption(ServiceCode code, byte addr) throws IOException { return readWithoutEncryption(addr, code.getBytes()); } public ReadResponse readWithoutEncryption(byte addr) throws IOException { final byte code0 = (byte) (SRV_FELICA_LITE_READWRITE >> 8); final byte code1 = (byte) (SRV_FELICA_LITE_READWRITE & 0xff); return readWithoutEncryption(addr, code0, code1); } public WriteResponse writeWithoutEncryption(ServiceCode code, byte addr, byte[] buff) throws IOException { byte[] bytes = code.getBytes(); ByteBuffer b = ByteBuffer.allocate(22); b.put(new byte[] { (byte) 0x01, (byte) bytes[0], (byte) bytes[1], (byte) 0x01, (byte) 0x80, (byte) addr }); b.put(buff, 0, buff.length > 16 ? 16 : buff.length); Command cmd = new Command(CMD_WRITE_WO_ENCRYPTION, idm, b.array()); return new WriteResponse(transceive(cmd)); } public WriteResponse writeWithoutEncryption(byte addr, byte[] buff) throws IOException { ByteBuffer b = ByteBuffer.allocate(22); b.put(new byte[] { (byte) 0x01, (byte) (SRV_FELICA_LITE_READWRITE >> 8), (byte) (SRV_FELICA_LITE_READWRITE & 0xff), (byte) 0x01, (byte) 0x80, addr }); b.put(buff, 0, buff.length > 16 ? 16 : buff.length); Command cmd = new Command(CMD_WRITE_WO_ENCRYPTION, idm, b.array()); return new WriteResponse(transceive(cmd)); } public MemoryConfigurationBlock getMemoryConfigBlock() throws IOException { ReadResponse r = readWithoutEncryption((byte) 0x88); return new MemoryConfigurationBlock(r.getBlockData()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); if (idm != null) { sb.append(idm.toString()); if (pmm != null) sb.append(pmm.toString()); } return sb.toString(); } public void connect() throws IOException { nfcTag.connect(); } public void close() throws IOException { nfcTag.close(); } public byte[] transceive(Command cmd) throws IOException { return transceive(cmd.getBytes()); } public byte[] transceive(byte... cmd) throws IOException { return nfcTag.transceive(cmd); } } // polling public static final byte CMD_POLLING = 0x00; public static final byte RSP_POLLING = 0x01; // request service public static final byte CMD_REQUEST_SERVICE = 0x02; public static final byte RSP_REQUEST_SERVICE = 0x03; // request RESPONSE public static final byte CMD_REQUEST_RESPONSE = 0x04; public static final byte RSP_REQUEST_RESPONSE = 0x05; // read without encryption public static final byte CMD_READ_WO_ENCRYPTION = 0x06; public static final byte RSP_READ_WO_ENCRYPTION = 0x07; // write without encryption public static final byte CMD_WRITE_WO_ENCRYPTION = 0x08; public static final byte RSP_WRITE_WO_ENCRYPTION = 0x09; // search service code public static final byte CMD_SEARCH_SERVICECODE = 0x0a; public static final byte RSP_SEARCH_SERVICECODE = 0x0b; // request system code public static final byte CMD_REQUEST_SYSTEMCODE = 0x0c; public static final byte RSP_REQUEST_SYSTEMCODE = 0x0d; // authentication 1 public static final byte CMD_AUTHENTICATION1 = 0x10; public static final byte RSP_AUTHENTICATION1 = 0x11; // authentication 2 public static final byte CMD_AUTHENTICATION2 = 0x12; public static final byte RSP_AUTHENTICATION2 = 0x13; // read public static final byte CMD_READ = 0x14; public static final byte RSP_READ = 0x15; // write public static final byte CMD_WRITE = 0x16; public static final byte RSP_WRITE = 0x17; public static final int SYS_ANY = 0xffff; public static final int SYS_FELICA_LITE = 0x88b4; public static final int SYS_COMMON = 0xfe00; public static final int SRV_FELICA_LITE_READONLY = 0x0b00; public static final int SRV_FELICA_LITE_READWRITE = 0x0900; public static final int STA1_NORMAL = 0x00; public static final int STA1_ERROR = 0xff; public static final int STA2_NORMAL = 0x00; public static final int STA2_ERROR_LENGTH = 0x01; public static final int STA2_ERROR_FLOWN = 0x02; public static final int STA2_ERROR_MEMORY = 0x70; public static final int STA2_ERROR_WRITELIMIT = 0x71; }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/tech/FeliCa.java
Java
gpl3
17,665
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.tech; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import com.sinpo.xnfc.nfc.Util; import android.nfc.tech.IsoDep; public class Iso7816 { public static final byte[] EMPTY = { 0 }; protected byte[] data; protected Iso7816() { data = Iso7816.EMPTY; } protected Iso7816(byte[] bytes) { data = (bytes == null) ? Iso7816.EMPTY : bytes; } public boolean match(byte[] bytes) { return match(bytes, 0); } public boolean match(byte[] bytes, int start) { final byte[] data = this.data; if (data.length <= bytes.length - start) { for (final byte v : data) { if (v != bytes[start++]) return false; } } else { return false; } return true; } public boolean match(byte tag) { return (data.length == 1 && data[0] == tag); } public boolean match(short tag) { final byte[] data = this.data; if (data.length == 2) { final byte d0 = (byte) (0x000000FF & (tag >> 8)); final byte d1 = (byte) (0x000000FF & tag); return (data[0] == d0 && data[1] == d1); } return (tag >= 0 && tag <= 255) ? match((byte) tag) : false; } public int size() { return data.length; } public byte[] getBytes() { return data; } public byte[] getBytes(int start, int count) { return Arrays.copyOfRange(data, start, start + count); } public int toInt() { return Util.toInt(getBytes()); } public int toIntR() { return Util.toIntR(getBytes()); } @Override public String toString() { return Util.toHexString(data, 0, data.length); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || !(obj instanceof Iso7816)) return false; return match(((Iso7816) obj).getBytes(), 0); } public final static class ID extends Iso7816 { public ID(byte... bytes) { super(bytes); } } public static class Response extends Iso7816 { public static final byte[] EMPTY = {}; public static final byte[] ERROR = { 0x6F, 0x00 }; // SW_UNKNOWN public Response(byte[] bytes) { super((bytes == null || bytes.length < 2) ? Response.ERROR : bytes); } public byte getSw1() { return data[data.length - 2]; } public byte getSw2() { return data[data.length - 1]; } public String getSw12String() { int sw1 = getSw1() & 0x000000FF; int sw2 = getSw2() & 0x000000FF; return String.format("0x%02X%02X", sw1, sw2); } public short getSw12() { final byte[] d = this.data; int n = d.length; return (short) ((d[n - 2] << 8) | (0xFF & d[n - 1])); } public boolean isOkey() { return equalsSw12(SW_NO_ERROR); } public boolean equalsSw12(short val) { return getSw12() == val; } public int size() { return data.length - 2; } public byte[] getBytes() { return isOkey() ? Arrays.copyOfRange(data, 0, size()) : Response.EMPTY; } } public final static class MifareDResponse extends Response { public MifareDResponse(byte[] bytes) { super(bytes); } } public final static class BerT extends Iso7816 { // tag template public static final byte TMPL_FCP = 0x62; // File Control Parameters public static final byte TMPL_FMD = 0x64; // File Management Data public static final byte TMPL_FCI = 0x6F; // FCP and FMD // proprietary information public final static BerT CLASS_PRI = new BerT((byte) 0xA5); // short EF identifier public final static BerT CLASS_SFI = new BerT((byte) 0x88); // dedicated file name public final static BerT CLASS_DFN = new BerT((byte) 0x84); // application data object public final static BerT CLASS_ADO = new BerT((byte) 0x61); // application id public final static BerT CLASS_AID = new BerT((byte) 0x4F); // proprietary information public static int test(byte[] bytes, int start) { int len = 1; if ((bytes[start] & 0x1F) == 0x1F) { while ((bytes[start + len] & 0x80) == 0x80) ++len; ++len; } return len; } public static BerT read(byte[] bytes, int start) { return new BerT(Arrays.copyOfRange(bytes, start, start + test(bytes, start))); } public BerT(byte tag) { this(new byte[] { tag }); } public BerT(short tag) { this(new byte[] { (byte) (0x000000FF & (tag >> 8)), (byte) (0x000000FF & tag) }); } public BerT(byte[] bytes) { super(bytes); } public boolean hasChild() { return ((data[0] & 0x20) == 0x20); } public short toShort() { if (size() <= 2) { return (short) Util.toInt(data); } return 0; } } public final static class BerL extends Iso7816 { private final int val; public static int test(byte[] bytes, int start) { int len = 1; if ((bytes[start] & 0x80) == 0x80) { len += bytes[start] & 0x07; } return len; } public static int calc(byte[] bytes, int start) { if ((bytes[start] & 0x80) == 0x80) { int v = 0; int e = start + bytes[start] & 0x07; while (++start <= e) { v <<= 8; v |= bytes[start] & 0xFF; } return v; } return bytes[start]; } public static BerL read(byte[] bytes, int start) { return new BerL(Arrays.copyOfRange(bytes, start, start + test(bytes, start))); } public BerL(byte[] bytes) { super(bytes); val = calc(bytes, 0); } public BerL(int len) { super(null); val = len; } public int toInt() { return val; } } public final static class BerV extends Iso7816 { public static BerV read(byte[] bytes, int start, int len) { return new BerV(Arrays.copyOfRange(bytes, start, start + len)); } public BerV(byte[] bytes) { super(bytes); } } public final static class BerTLV extends Iso7816 { public static int test(byte[] bytes, int start) { final int lt = BerT.test(bytes, start); final int ll = BerL.test(bytes, start + lt); final int lv = BerL.calc(bytes, start + lt); return lt + ll + lv; } public static byte[] getValue(BerTLV tlv) { if (tlv == null || tlv.length() == 0) return null; return tlv.v.getBytes(); } public static BerTLV read(Iso7816 obj) { return read(obj.getBytes(), 0); } public static BerTLV read(byte[] bytes, int start) { int s = start; final BerT t = BerT.read(bytes, s); s += t.size(); final BerL l = BerL.read(bytes, s); s += l.size(); final BerV v = BerV.read(bytes, s, l.toInt()); s += v.size(); final BerTLV tlv = new BerTLV(t, l, v); tlv.data = Arrays.copyOfRange(bytes, start, s); return tlv; } public static void extractChildren(ArrayList<BerTLV> out, Iso7816 obj) { extractChildren(out, obj.getBytes()); } public static void extractChildren(ArrayList<BerTLV> out, byte[] data) { int start = 0; int end = data.length - 3; while (start <= end) { final BerTLV tlv = read(data, start); out.add(tlv); start += tlv.size(); } } public static void extractPrimitives(BerHouse out, Iso7816 obj) { extractPrimitives(out.tlvs, obj.getBytes()); } public static void extractPrimitives(ArrayList<BerTLV> out, Iso7816 obj) { extractPrimitives(out, obj.getBytes()); } public static void extractPrimitives(BerHouse out, byte[] data) { extractPrimitives(out.tlvs, data); } public static void extractPrimitives(ArrayList<BerTLV> out, byte[] data) { int start = 0; int end = data.length - 3; while (start <= end) { final BerTLV tlv = read(data, start); if (tlv.t.hasChild()) extractPrimitives(out, tlv.v.getBytes()); else out.add(tlv); start += tlv.size(); } } public static ArrayList<BerTLV> extractOptionList(byte[] data) { final ArrayList<BerTLV> ret = new ArrayList<BerTLV>(); int start = 0; int end = data.length; while (start < end) { final BerT t = BerT.read(data, start); start += t.size(); if (start < end) { BerL l = BerL.read(data, start); start += l.size(); if (start <= end) ret.add(new BerTLV(t, l, null)); } } return ret; } public final BerT t; public final BerL l; public final BerV v; public BerTLV(BerT t, BerL l, BerV v) { this.t = t; this.l = l; this.v = v; } public int length() { return l.toInt(); } } public final static class BerHouse { final ArrayList<BerTLV> tlvs = new ArrayList<BerTLV>(); public int count() { return tlvs.size(); } public void add(short t, Response v) { tlvs.add(new BerTLV(new BerT(t), new BerL(v.size()), new BerV(v .getBytes()))); } public void add(short t, byte[] v) { tlvs.add(new BerTLV(new BerT(t), new BerL(v.length), new BerV(v))); } public void add(BerT t, byte[] v) { tlvs.add(new BerTLV(t, new BerL(v.length), new BerV(v))); } public void add(BerTLV tlv) { tlvs.add(tlv); } public BerTLV get(int index) { return tlvs.get(index); } public BerTLV findFirst(byte tag) { for (BerTLV tlv : tlvs) if (tlv.t.match(tag)) return tlv; return null; } public BerTLV findFirst(byte... tag) { for (BerTLV tlv : tlvs) if (tlv.t.match(tag)) return tlv; return null; } public BerTLV findFirst(short tag) { for (BerTLV tlv : tlvs) if (tlv.t.match(tag)) return tlv; return null; } public BerTLV findFirst(BerT tag) { for (BerTLV tlv : tlvs) if (tlv.t.match(tag.getBytes())) return tlv; return null; } public ArrayList<BerTLV> findAll(byte tag) { final ArrayList<BerTLV> ret = new ArrayList<BerTLV>(); for (BerTLV tlv : tlvs) if (tlv.t.match(tag)) ret.add(tlv); return ret; } public ArrayList<BerTLV> findAll(byte... tag) { final ArrayList<BerTLV> ret = new ArrayList<BerTLV>(); for (BerTLV tlv : tlvs) if (tlv.t.match(tag)) ret.add(tlv); return ret; } public ArrayList<BerTLV> findAll(short tag) { final ArrayList<BerTLV> ret = new ArrayList<BerTLV>(); for (BerTLV tlv : tlvs) if (tlv.t.match(tag)) ret.add(tlv); return ret; } public ArrayList<BerTLV> findAll(BerT tag) { final ArrayList<BerTLV> ret = new ArrayList<BerTLV>(); for (BerTLV tlv : tlvs) if (tlv.t.match(tag.getBytes())) ret.add(tlv); return ret; } public String toString() { final StringBuilder ret = new StringBuilder(); for (BerTLV t : tlvs) { ret.append(t.t.toString()).append(' '); ret.append(t.l.toInt()).append(' '); ret.append(t.v.toString()).append('\n'); } return ret.toString(); } } public final static class StdTag { private final IsoDep nfcTag; private ID id; public StdTag(IsoDep tag) { nfcTag = tag; id = new ID(tag.getTag().getId()); } public ID getID() { return id; } public Response getBalance(boolean isEP) throws IOException { final byte[] cmd = { (byte) 0x80, // CLA Class (byte) 0x5C, // INS Instruction (byte) 0x00, // P1 Parameter 1 (byte) (isEP ? 2 : 1), // P2 Parameter 2 (byte) 0x04, // Le }; return new Response(transceive(cmd)); } public Response readRecord(int sfi, int index) throws IOException { final byte[] cmd = { (byte) 0x00, // CLA Class (byte) 0xB2, // INS Instruction (byte) index, // P1 Parameter 1 (byte) ((sfi << 3) | 0x04), // P2 Parameter 2 (byte) 0x00, // Le }; return new Response(transceive(cmd)); } public Response readRecord(int sfi) throws IOException { final byte[] cmd = { (byte) 0x00, // CLA Class (byte) 0xB2, // INS Instruction (byte) 0x01, // P1 Parameter 1 (byte) ((sfi << 3) | 0x05), // P2 Parameter 2 (byte) 0x00, // Le }; return new Response(transceive(cmd)); } public Response readBinary(int sfi) throws IOException { final byte[] cmd = { (byte) 0x00, // CLA Class (byte) 0xB0, // INS Instruction (byte) (0x00000080 | (sfi & 0x1F)), // P1 Parameter 1 (byte) 0x00, // P2 Parameter 2 (byte) 0x00, // Le }; return new Response(transceive(cmd)); } public Response readData(int sfi) throws IOException { final byte[] cmd = { (byte) 0x80, // CLA Class (byte) 0xCA, // INS Instruction (byte) 0x00, // P1 Parameter 1 (byte) (sfi & 0x1F), // P2 Parameter 2 (byte) 0x00, // Le }; return new Response(transceive(cmd)); } public Response getData(short tag) throws IOException { final byte[] cmd = { (byte) 0x80, // CLA Class (byte) 0xCA, // INS Instruction (byte) ((tag >> 8) & 0xFF), (byte) (tag & 0xFF), (byte) 0x00, // Le }; return new Response(transceive(cmd)); } public Response readData(short tag) throws IOException { final byte[] cmd = { (byte) 0x80, // CLA Class (byte) 0xCA, // INS Instruction (byte) ((tag >> 8) & 0xFF), // P1 Parameter 1 (byte) (tag & 0x1F), // P2 Parameter 2 (byte) 0x00, // Lc (byte) 0x00, // Le }; return new Response(transceive(cmd)); } public Response selectByID(byte... id) throws IOException { ByteBuffer buff = ByteBuffer.allocate(id.length + 6); buff.put((byte) 0x00) // CLA Class .put((byte) 0xA4) // INS Instruction .put((byte) 0x00) // P1 Parameter 1 .put((byte) 0x00) // P2 Parameter 2 .put((byte) id.length) // Lc .put(id).put((byte) 0x00); // Le return new Response(transceive(buff.array())); } public Response selectByName(byte... name) throws IOException { ByteBuffer buff = ByteBuffer.allocate(name.length + 6); buff.put((byte) 0x00) // CLA Class .put((byte) 0xA4) // INS Instruction .put((byte) 0x04) // P1 Parameter 1 .put((byte) 0x00) // P2 Parameter 2 .put((byte) name.length) // Lc .put(name).put((byte) 0x00); // Le return new Response(transceive(buff.array())); } public Response getProcessingOptions(byte... pdol) throws IOException { ByteBuffer buff = ByteBuffer.allocate(pdol.length + 6); buff.put((byte) 0x80) // CLA Class .put((byte) 0xA8) // INS Instruction .put((byte) 0x00) // P1 Parameter 1 .put((byte) 0x00) // P2 Parameter 2 .put((byte) pdol.length) // Lc .put(pdol).put((byte) 0x00); // Le return new Response(transceive(buff.array())); } public void connect() throws IOException { nfcTag.connect(); } public void close() throws IOException { nfcTag.close(); } public byte[] transceive(final byte[] cmd) throws IOException { try { byte[] rsp = null; byte c[] = cmd; do { byte[] r = nfcTag.transceive(c); if (r == null) break; int N = r.length - 2; if (N < 0) { rsp = r; break; } if (r[N] == CH_STA_LE) { c[c.length - 1] = r[N + 1]; continue; } if (rsp == null) { rsp = r; } else { int n = rsp.length; N += n; rsp = Arrays.copyOf(rsp, N); n -= 2; for (byte i : r) rsp[n++] = i; } if (r[N] != CH_STA_MORE) break; byte s = r[N + 1]; if (s != 0) { c = CMD_GETRESPONSE.clone(); } else { rsp[rsp.length - 1] = CH_STA_OK; break; } } while (true); return rsp; } catch (Exception e) { return Response.ERROR; } } private static final byte CH_STA_OK = (byte) 0x90; private static final byte CH_STA_MORE = (byte) 0x61; private static final byte CH_STA_LE = (byte) 0x6C; private static final byte CMD_GETRESPONSE[] = { 0, (byte) 0xC0, 0, 0, 0, }; } public static final short SW_NO_ERROR = (short) 0x9000; public static final short SW_DESFIRE_NO_ERROR = (short) 0x9100; public static final short SW_BYTES_REMAINING_00 = 0x6100; public static final short SW_WRONG_LENGTH = 0x6700; public static final short SW_SECURITY_STATUS_NOT_SATISFIED = 0x6982; public static final short SW_FILE_INVALID = 0x6983; public static final short SW_DATA_INVALID = 0x6984; public static final short SW_CONDITIONS_NOT_SATISFIED = 0x6985; public static final short SW_COMMAND_NOT_ALLOWED = 0x6986; public static final short SW_APPLET_SELECT_FAILED = 0x6999; public static final short SW_WRONG_DATA = 0x6A80; public static final short SW_FUNC_NOT_SUPPORTED = 0x6A81; public static final short SW_FILE_NOT_FOUND = 0x6A82; public static final short SW_RECORD_NOT_FOUND = 0x6A83; public static final short SW_INCORRECT_P1P2 = 0x6A86; public static final short SW_WRONG_P1P2 = 0x6B00; public static final short SW_CORRECT_LENGTH_00 = 0x6C00; public static final short SW_INS_NOT_SUPPORTED = 0x6D00; public static final short SW_CLA_NOT_SUPPORTED = 0x6E00; public static final short SW_UNKNOWN = 0x6F00; public static final short SW_FILE_FULL = 0x6A84; }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/tech/Iso7816.java
Java
gpl3
17,186
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc; import static android.nfc.NfcAdapter.EXTRA_TAG; import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1; import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH; import android.annotation.SuppressLint; import android.app.Activity; import android.app.PendingIntent; import android.content.Intent; import android.content.IntentFilter; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.tech.IsoDep; import android.nfc.tech.NfcF; import com.sinpo.xnfc.nfc.reader.ReaderListener; import com.sinpo.xnfc.nfc.reader.ReaderManager; public final class NfcManager { private final Activity activity; private NfcAdapter nfcAdapter; private PendingIntent pendingIntent; private static String[][] TECHLISTS; private static IntentFilter[] TAGFILTERS; private int status; static { try { TECHLISTS = new String[][] { { IsoDep.class.getName() }, { NfcF.class.getName() }, }; TAGFILTERS = new IntentFilter[] { new IntentFilter( NfcAdapter.ACTION_TECH_DISCOVERED, "*/*") }; } catch (Exception e) { } } public NfcManager(Activity activity) { this.activity = activity; nfcAdapter = NfcAdapter.getDefaultAdapter(activity); pendingIntent = PendingIntent.getActivity(activity, 0, new Intent( activity, activity.getClass()) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); setupBeam(true); status = getStatus(); } public void onPause() { setupOldFashionBeam(false); if (nfcAdapter != null) nfcAdapter.disableForegroundDispatch(activity); } public void onResume() { setupOldFashionBeam(true); if (nfcAdapter != null) nfcAdapter.enableForegroundDispatch(activity, pendingIntent, TAGFILTERS, TECHLISTS); } public boolean updateStatus() { int sta = getStatus(); if (sta != status) { status = sta; return true; } return false; } public boolean readCard(Intent intent, ReaderListener listener) { final Tag tag = (Tag) intent.getParcelableExtra(EXTRA_TAG); if (tag != null) { ReaderManager.readCard(tag, listener); return true; } return false; } private int getStatus() { return (nfcAdapter == null) ? -1 : nfcAdapter.isEnabled() ? 1 : 0; } @SuppressLint("NewApi") private void setupBeam(boolean enable) { final int api = android.os.Build.VERSION.SDK_INT; if (nfcAdapter != null && api >= ICE_CREAM_SANDWICH) { if (enable) nfcAdapter.setNdefPushMessage(createNdefMessage(), activity); } } @SuppressWarnings("deprecation") private void setupOldFashionBeam(boolean enable) { final int api = android.os.Build.VERSION.SDK_INT; if (nfcAdapter != null && api >= GINGERBREAD_MR1 && api < ICE_CREAM_SANDWICH) { if (enable) nfcAdapter.enableForegroundNdefPush(activity, createNdefMessage()); else nfcAdapter.disableForegroundNdefPush(activity); } } NdefMessage createNdefMessage() { String uri = "3play.google.com/store/apps/details?id=com.sinpo.xnfc"; byte[] data = uri.getBytes(); // about this '3'.. see NdefRecord.createUri which need api level 14 data[0] = 3; NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, null, data); return new NdefMessage(new NdefRecord[] { record }); } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/NfcManager.java
Java
gpl3
3,962
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc; public final class Util { private final static char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; private Util() { } public static byte[] toBytes(int a) { return new byte[] { (byte) (0x000000ff & (a >>> 24)), (byte) (0x000000ff & (a >>> 16)), (byte) (0x000000ff & (a >>> 8)), (byte) (0x000000ff & (a)) }; } public static boolean testBit(byte data, int bit) { final byte mask = (byte) ((1 << bit) & 0x000000FF); return (data & mask) == mask; } public static int toInt(byte[] b, int s, int n) { int ret = 0; final int e = s + n; for (int i = s; i < e; ++i) { ret <<= 8; ret |= b[i] & 0xFF; } return ret; } public static int toIntR(byte[] b, int s, int n) { int ret = 0; for (int i = s; (i >= 0 && n > 0); --i, --n) { ret <<= 8; ret |= b[i] & 0xFF; } return ret; } public static int toInt(byte... b) { int ret = 0; for (final byte a : b) { ret <<= 8; ret |= a & 0xFF; } return ret; } public static int toIntR(byte... b) { return toIntR(b, b.length - 1, b.length); } public static String toHexString(byte... d) { return (d == null || d.length == 0) ? "" : toHexString(d, 0, d.length); } public static String toHexString(byte[] d, int s, int n) { final char[] ret = new char[n * 2]; final int e = s + n; int x = 0; for (int i = s; i < e; ++i) { final byte v = d[i]; ret[x++] = HEX[0x0F & (v >> 4)]; ret[x++] = HEX[0x0F & v]; } return new String(ret); } public static String toHexStringR(byte[] d, int s, int n) { final char[] ret = new char[n * 2]; int x = 0; for (int i = s + n - 1; i >= s; --i) { final byte v = d[i]; ret[x++] = HEX[0x0F & (v >> 4)]; ret[x++] = HEX[0x0F & v]; } return new String(ret); } public static String ensureString(String str) { return str == null ? "" : str; } public static String toStringR(int n) { final StringBuilder ret = new StringBuilder(16).append('0'); long N = 0xFFFFFFFFL & n; while (N != 0) { ret.append((int) (N % 100)); N /= 100; } return ret.toString(); } public static int parseInt(String txt, int radix, int def) { int ret; try { ret = Integer.valueOf(txt, radix); } catch (Exception e) { ret = def; } return ret; } public static int BCDtoInt(byte[] b, int s, int n) { int ret = 0; final int e = s + n; for (int i = s; i < e; ++i) { int h = (b[i] >> 4) & 0x0F; int l = b[i] & 0x0F; if (h > 9 || l > 9) return -1; ret = ret * 100 + h * 10 + l; } return ret; } public static int BCDtoInt(byte... b) { return BCDtoInt(b, 0, b.length); } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/Util.java
Java
gpl3
3,331
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.bean; import java.util.ArrayList; import com.sinpo.xnfc.SPEC; public class Card extends Application { public static final Card EMPTY = new Card(); private final ArrayList<Application> applications; public Card() { applications = new ArrayList<Application>(2); } public Exception getReadingException() { return (Exception) getProperty(SPEC.PROP.EXCEPTION); } public boolean hasReadingException() { return hasProperty(SPEC.PROP.EXCEPTION); } public final boolean isUnknownCard() { return applicationCount() == 0; } public final int applicationCount() { return applications.size(); } public final Application getApplication(int index) { return applications.get(index); } public final void addApplication(Application app) { if (app != null) applications.add(app); } public String toHtml() { return HtmlFormatter.formatCardInfo(this); } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/bean/Card.java
Java
gpl3
1,566
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.bean; import com.sinpo.xnfc.SPEC; import android.util.SparseArray; public class Application { private final SparseArray<Object> properties = new SparseArray<Object>(); public final void setProperty(SPEC.PROP prop, Object value) { properties.put(prop.ordinal(), value); } public final Object getProperty(SPEC.PROP prop) { return properties.get(prop.ordinal()); } public final boolean hasProperty(SPEC.PROP prop) { return getProperty(prop) != null; } public final String getStringProperty(SPEC.PROP prop) { final Object v = getProperty(prop); return (v != null) ? v.toString() : ""; } public final float getFloatProperty(SPEC.PROP prop) { final Object v = getProperty(prop); if (v == null) return Float.NaN; if (v instanceof Float) return ((Float) v).floatValue(); return Float.parseFloat(v.toString()); } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/bean/Application.java
Java
gpl3
1,535
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.bean; import com.sinpo.xnfc.SPEC; public final class HtmlFormatter { static String formatCardInfo(Card card) { final StringBuilder ret = new StringBuilder(); startTag(ret, SPEC.TAG_BLK); final int N = card.applicationCount(); for (int i = 0; i < N; ++i) { if (i > 0) { newline(ret); newline(ret); } formatApplicationInfo(ret, card.getApplication(i)); } endTag(ret, SPEC.TAG_BLK); return ret.toString(); } private static void startTag(StringBuilder out, String tag) { out.append('<').append(tag).append('>'); } private static void endTag(StringBuilder out, String tag) { out.append('<').append('/').append(tag).append('>'); } private static void newline(StringBuilder out) { out.append("<br />"); } private static void spliter(StringBuilder out) { out.append("\n<").append(SPEC.TAG_SP).append(" />\n"); } private static boolean formatProperty(StringBuilder out, String tag, Object value) { if (value == null) return false; startTag(out, tag); out.append(value.toString()); endTag(out, tag); return true; } private static boolean formatProperty(StringBuilder out, String tag, Object prop, String value) { if (value == null || value.isEmpty()) return false; startTag(out, tag); out.append(prop.toString()); endTag(out, tag); startTag(out, SPEC.TAG_TEXT); out.append(value); endTag(out, SPEC.TAG_TEXT); return true; } private static boolean formatApplicationInfo(StringBuilder out, Application app) { if (!formatProperty(out, SPEC.TAG_H1, app.getProperty(SPEC.PROP.ID))) return false; newline(out); spliter(out); newline(out); { SPEC.PROP prop = SPEC.PROP.SERIAL; if (formatProperty(out, SPEC.TAG_LAB, prop, app.getStringProperty(prop))) newline(out); } { SPEC.PROP prop = SPEC.PROP.PARAM; if (formatProperty(out, SPEC.TAG_LAB, prop, app.getStringProperty(prop))) newline(out); } { SPEC.PROP prop = SPEC.PROP.VERSION; if (formatProperty(out, SPEC.TAG_LAB, prop, app.getStringProperty(prop))) newline(out); } { SPEC.PROP prop = SPEC.PROP.DATE; if (formatProperty(out, SPEC.TAG_LAB, prop, app.getStringProperty(prop))) newline(out); } { SPEC.PROP prop = SPEC.PROP.COUNT; if (formatProperty(out, SPEC.TAG_LAB, prop, app.getStringProperty(prop))) newline(out); } { SPEC.PROP prop = SPEC.PROP.TLIMIT; Float balance = (Float) app.getProperty(prop); if (balance != null && !balance.isNaN()) { String cur = app.getProperty(SPEC.PROP.CURRENCY).toString(); String val = String.format("%.2f %s", balance, cur); if (formatProperty(out, SPEC.TAG_LAB, prop, val)) newline(out); } } { SPEC.PROP prop = SPEC.PROP.DLIMIT; Float balance = (Float) app.getProperty(prop); if (balance != null && !balance.isNaN()) { String cur = app.getProperty(SPEC.PROP.CURRENCY).toString(); String val = String.format("%.2f %s", balance, cur); if (formatProperty(out, SPEC.TAG_LAB, prop, val)) newline(out); } } { SPEC.PROP prop = SPEC.PROP.ECASH; Float balance = (Float) app.getProperty(prop); if (balance != null) { formatProperty(out, SPEC.TAG_LAB, prop); if (balance.isNaN()) { out.append(SPEC.PROP.ACCESS); } else { formatProperty(out, SPEC.TAG_H2, String.format("%.2f ", balance)); formatProperty(out, SPEC.TAG_LAB, app.getProperty(SPEC.PROP.CURRENCY).toString()); } newline(out); } } { SPEC.PROP prop = SPEC.PROP.BALANCE; Float balance = (Float) app.getProperty(prop); if (balance != null) { formatProperty(out, SPEC.TAG_LAB, prop); if (balance.isNaN()) { out.append(SPEC.PROP.ACCESS); } else { formatProperty(out, SPEC.TAG_H2, String.format("%.2f ", balance)); formatProperty(out, SPEC.TAG_LAB, app.getProperty(SPEC.PROP.CURRENCY).toString()); } newline(out); } } { SPEC.PROP prop = SPEC.PROP.TRANSLOG; String[] logs = (String[]) app.getProperty(prop); if (logs != null && logs.length > 0) { spliter(out); newline(out); startTag(out, SPEC.TAG_PARAG); formatProperty(out, SPEC.TAG_LAB, prop); newline(out); endTag(out, SPEC.TAG_PARAG); for (String log : logs) { formatProperty(out, SPEC.TAG_H3, log); newline(out); } newline(out); } } return true; } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/bean/HtmlFormatter.java
Java
gpl3
5,113
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader; import android.nfc.Tag; import android.nfc.tech.IsoDep; import android.nfc.tech.NfcF; import android.os.AsyncTask; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.nfc.Util; import com.sinpo.xnfc.nfc.bean.Card; import com.sinpo.xnfc.nfc.reader.pboc.StandardPboc; public final class ReaderManager extends AsyncTask<Tag, SPEC.EVENT, Card> { public static void readCard(Tag tag, ReaderListener listener) { new ReaderManager(listener).execute(tag); } private ReaderListener realListener; private ReaderManager(ReaderListener listener) { realListener = listener; } @Override protected Card doInBackground(Tag... detectedTag) { return readCard(detectedTag[0]); } @Override protected void onProgressUpdate(SPEC.EVENT... events) { if (realListener != null) realListener.onReadEvent(events[0]); } @Override protected void onPostExecute(Card card) { if (realListener != null) realListener.onReadEvent(SPEC.EVENT.FINISHED, card); } private Card readCard(Tag tag) { final Card card = new Card(); try { publishProgress(SPEC.EVENT.READING); card.setProperty(SPEC.PROP.ID, Util.toHexString(tag.getId())); final IsoDep isodep = IsoDep.get(tag); if (isodep != null) StandardPboc.readCard(isodep, card); final NfcF nfcf = NfcF.get(tag); if (nfcf != null) FelicaReader.readCard(nfcf, card); publishProgress(SPEC.EVENT.IDLE); } catch (Exception e) { card.setProperty(SPEC.PROP.EXCEPTION, e); publishProgress(SPEC.EVENT.ERROR); } return card; } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/ReaderManager.java
Java
gpl3
2,214
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader; import com.sinpo.xnfc.SPEC; public interface ReaderListener { void onReadEvent(SPEC.EVENT event, Object... obj); }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/ReaderListener.java
Java
gpl3
809
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader.pboc; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.nfc.Util; import com.sinpo.xnfc.nfc.bean.Application; import com.sinpo.xnfc.nfc.bean.Card; import com.sinpo.xnfc.nfc.tech.Iso7816; import android.nfc.tech.IsoDep; @SuppressWarnings("unchecked") public abstract class StandardPboc { private static Class<?>[][] readers = { { BeijingMunicipal.class, WuhanTong.class, ShenzhenTong.class, CityUnion.class, }, { Quickpass.class, } }; public static void readCard(IsoDep tech, Card card) throws InstantiationException, IllegalAccessException, IOException { final Iso7816.StdTag tag = new Iso7816.StdTag(tech); tag.connect(); for (final Class<?> g[] : readers) { HINT hint = HINT.RESETANDGONEXT; for (final Class<?> r : g) { final StandardPboc reader = (StandardPboc) r.newInstance(); switch (hint) { case RESETANDGONEXT: if (!reader.resetTag(tag)) continue; case GONEXT: hint = reader.readCard(tag, card); break; default: break; } if (hint == HINT.STOP) break; } } tag.close(); } protected boolean resetTag(Iso7816.StdTag tag) throws IOException { return tag.selectByID(DFI_MF).isOkey() || tag.selectByName(DFN_PSE).isOkey(); } protected enum HINT { STOP, GONEXT, RESETANDGONEXT, } protected final static byte[] DFI_MF = { (byte) 0x3F, (byte) 0x00 }; protected final static byte[] DFI_EP = { (byte) 0x10, (byte) 0x01 }; protected final static byte[] DFN_PSE = { (byte) '1', (byte) 'P', (byte) 'A', (byte) 'Y', (byte) '.', (byte) 'S', (byte) 'Y', (byte) 'S', (byte) '.', (byte) 'D', (byte) 'D', (byte) 'F', (byte) '0', (byte) '1', }; protected final static byte[] DFN_PXX = { (byte) 'P' }; protected final static int SFI_EXTRA = 21; protected static int MAX_LOG = 10; protected static int SFI_LOG = 24; protected final static byte TRANS_CSU = 6; protected final static byte TRANS_CSU_CPX = 9; protected abstract SPEC.APP getApplicationId(); protected byte[] getMainApplicationId() { return DFI_EP; } protected SPEC.CUR getCurrency() { return SPEC.CUR.CNY; } protected boolean selectMainApplication(Iso7816.StdTag tag) throws IOException { final byte[] aid = getMainApplicationId(); return ((aid.length == 2) ? tag.selectByID(aid) : tag.selectByName(aid)) .isOkey(); } protected HINT readCard(Iso7816.StdTag tag, Card card) throws IOException { /*--------------------------------------------------------------*/ // select Main Application /*--------------------------------------------------------------*/ if (!selectMainApplication(tag)) return HINT.GONEXT; Iso7816.Response INFO, BALANCE; /*--------------------------------------------------------------*/ // read card info file, binary (21) /*--------------------------------------------------------------*/ INFO = tag.readBinary(SFI_EXTRA); /*--------------------------------------------------------------*/ // read balance /*--------------------------------------------------------------*/ BALANCE = tag.getBalance(true); /*--------------------------------------------------------------*/ // read log file, record (24) /*--------------------------------------------------------------*/ ArrayList<byte[]> LOG = readLog24(tag, SFI_LOG); /*--------------------------------------------------------------*/ // build result /*--------------------------------------------------------------*/ final Application app = createApplication(); parseBalance(app, BALANCE); parseInfo21(app, INFO, 4, true); parseLog24(app, LOG); configApplication(app); card.addApplication(app); return HINT.STOP; } protected void parseBalance(Application app, Iso7816.Response... data) { int amount = 0; for (Iso7816.Response rsp : data) { if (rsp.isOkey() && rsp.size() >= 4) { int n = Util.toInt(rsp.getBytes(), 0, 4); if (n > 1000000 || n < -1000000) n -= 0x80000000; amount += n; } } app.setProperty(SPEC.PROP.BALANCE, (amount / 100.0f)); } protected void parseInfo21(Application app, Iso7816.Response data, int dec, boolean bigEndian) { if (!data.isOkey() || data.size() < 30) { return; } final byte[] d = data.getBytes(); if (dec < 1 || dec > 10) { app.setProperty(SPEC.PROP.SERIAL, Util.toHexString(d, 10, 10)); } else { final int sn = bigEndian ? Util.toIntR(d, 19, dec) : Util.toInt(d, 20 - dec, dec); app.setProperty(SPEC.PROP.SERIAL, String.format("%d", 0xFFFFFFFFL & sn)); } if (d[9] != 0) app.setProperty(SPEC.PROP.VERSION, String.valueOf(d[9])); app.setProperty(SPEC.PROP.DATE, String.format( "%02X%02X.%02X.%02X - %02X%02X.%02X.%02X", d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27])); } protected boolean addLog24(final Iso7816.Response r, ArrayList<byte[]> l) { if (!r.isOkey()) return false; final byte[] raw = r.getBytes(); final int N = raw.length - 23; if (N < 0) return false; for (int s = 0, e = 0; s <= N; s = e) { l.add(Arrays.copyOfRange(raw, s, (e = s + 23))); } return true; } protected ArrayList<byte[]> readLog24(Iso7816.StdTag tag, int sfi) throws IOException { final ArrayList<byte[]> ret = new ArrayList<byte[]>(MAX_LOG); final Iso7816.Response rsp = tag.readRecord(sfi); if (rsp.isOkey()) { addLog24(rsp, ret); } else { for (int i = 1; i <= MAX_LOG; ++i) { if (!addLog24(tag.readRecord(sfi, i), ret)) break; } } return ret; } protected void parseLog24(Application app, ArrayList<byte[]>... logs) { final ArrayList<String> ret = new ArrayList<String>(MAX_LOG); for (final ArrayList<byte[]> log : logs) { if (log == null) continue; for (final byte[] v : log) { final int money = Util.toInt(v, 5, 4); if (money > 0) { final char s = (v[9] == TRANS_CSU || v[9] == TRANS_CSU_CPX) ? '-' : '+'; final int over = Util.toInt(v, 2, 3); final String slog; if (over > 0) { slog = String .format("%02X%02X.%02X.%02X %02X:%02X %c%.2f [o:%.2f] [%02X%02X%02X%02X%02X%02X]", v[16], v[17], v[18], v[19], v[20], v[21], s, (money / 100.0f), (over / 100.0f), v[10], v[11], v[12], v[13], v[14], v[15]); } else { slog = String .format("%02X%02X.%02X.%02X %02X:%02X %C%.2f [%02X%02X%02X%02X%02X%02X]", v[16], v[17], v[18], v[19], v[20], v[21], s, (money / 100.0f), v[10], v[11], v[12], v[13], v[14], v[15]); } ret.add(slog); } } } if (!ret.isEmpty()) app.setProperty(SPEC.PROP.TRANSLOG, ret.toArray(new String[ret.size()])); } protected Application createApplication() { return new Application(); } protected void configApplication(Application app) { app.setProperty(SPEC.PROP.ID, getApplicationId()); app.setProperty(SPEC.PROP.CURRENCY, getCurrency()); } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/pboc/StandardPboc.java
Java
gpl3
7,673
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader.pboc; import java.io.IOException; import java.util.ArrayList; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.nfc.Util; import com.sinpo.xnfc.nfc.bean.Application; import com.sinpo.xnfc.nfc.bean.Card; import com.sinpo.xnfc.nfc.tech.Iso7816; final class WuhanTong extends StandardPboc { @Override protected SPEC.APP getApplicationId() { return SPEC.APP.WUHANTONG; } @Override protected byte[] getMainApplicationId() { return new byte[] { (byte) 0x41, (byte) 0x50, (byte) 0x31, (byte) 0x2E, (byte) 0x57, (byte) 0x48, (byte) 0x43, (byte) 0x54, (byte) 0x43, }; } @SuppressWarnings("unchecked") @Override protected HINT readCard(Iso7816.StdTag tag, Card card) throws IOException { Iso7816.Response INFO, SERL, BALANCE; /*--------------------------------------------------------------*/ // read card info file, binary (5, 10) /*--------------------------------------------------------------*/ if (!(SERL = tag.readBinary(SFI_SERL)).isOkey()) return HINT.GONEXT; if (!(INFO = tag.readBinary(SFI_INFO)).isOkey()) return HINT.GONEXT; BALANCE = tag.getBalance(true); /*--------------------------------------------------------------*/ // select Main Application /*--------------------------------------------------------------*/ if (!tag.selectByName(getMainApplicationId()).isOkey()) return HINT.RESETANDGONEXT; /*--------------------------------------------------------------*/ // read balance /*--------------------------------------------------------------*/ if (!BALANCE.isOkey()) BALANCE = tag.getBalance(true); /*--------------------------------------------------------------*/ // read log file, record (24) /*--------------------------------------------------------------*/ ArrayList<byte[]> LOG = readLog24(tag, SFI_LOG); /*--------------------------------------------------------------*/ // build result /*--------------------------------------------------------------*/ final Application app = createApplication(); parseBalance(app, BALANCE); parseInfo5(app, SERL, INFO); parseLog24(app, LOG); configApplication(app); card.addApplication(app); return HINT.STOP; } private final static int SFI_INFO = 5; private final static int SFI_SERL = 10; private void parseInfo5(Application app, Iso7816.Response sn, Iso7816.Response info) { if (sn.size() < 27 || info.size() < 27) { return; } final byte[] d = info.getBytes(); app.setProperty(SPEC.PROP.SERIAL, Util.toHexString(sn.getBytes(), 0, 5)); app.setProperty(SPEC.PROP.VERSION, String.format("%02d", d[24])); app.setProperty(SPEC.PROP.DATE, String.format( "%02X%02X.%02X.%02X - %02X%02X.%02X.%02X", d[20], d[21], d[22], d[23], d[16], d[17], d[18], d[19])); } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/pboc/WuhanTong.java
Java
gpl3
3,445
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader.pboc; import com.sinpo.xnfc.SPEC; final class ShenzhenTong extends StandardPboc { @Override protected SPEC.APP getApplicationId() { return SPEC.APP.SHENZHENTONG; } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/pboc/ShenzhenTong.java
Java
gpl3
864
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader.pboc; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.nfc.Util; import com.sinpo.xnfc.nfc.bean.Application; import com.sinpo.xnfc.nfc.tech.Iso7816; import android.annotation.SuppressLint; final class CityUnion extends StandardPboc { private SPEC.APP applicationId = SPEC.APP.UNKNOWN; @Override protected SPEC.APP getApplicationId() { return applicationId; } @Override protected byte[] getMainApplicationId() { return new byte[] { (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x86, (byte) 0x98, (byte) 0x07, (byte) 0x01, }; } @SuppressLint("DefaultLocale") @Override protected void parseInfo21(Application app, Iso7816.Response data, int dec, boolean bigEndian) { if (!data.isOkey() || data.size() < 30) { return; } final byte[] d = data.getBytes(); if (d[2] == 0x20 && d[3] == 0x00) { applicationId = SPEC.APP.SHANGHAIGJ; bigEndian = true; } else { applicationId = SPEC.APP.CHANGANTONG; bigEndian = false; } if (dec < 1 || dec > 10) { app.setProperty(SPEC.PROP.SERIAL, Util.toHexString(d, 10, 10)); } else { final int sn = Util.toInt(d, 20 - dec, dec); final String ss = bigEndian ? Util.toStringR(sn) : String.format( "%d", 0xFFFFFFFFL & sn); app.setProperty(SPEC.PROP.SERIAL, ss); } if (d[9] != 0) app.setProperty(SPEC.PROP.VERSION, String.valueOf(d[9])); app.setProperty(SPEC.PROP.DATE, String.format( "%02X%02X.%02X.%02X - %02X%02X.%02X.%02X", d[20], d[21], d[22], d[23], d[24], d[25], d[26], d[27])); } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/pboc/CityUnion.java
Java
gpl3
2,232
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader.pboc; import java.io.IOException; import java.util.ArrayList; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.nfc.Util; import com.sinpo.xnfc.nfc.bean.Application; import com.sinpo.xnfc.nfc.bean.Card; import com.sinpo.xnfc.nfc.tech.Iso7816; import com.sinpo.xnfc.nfc.tech.Iso7816.BerHouse; import com.sinpo.xnfc.nfc.tech.Iso7816.BerTLV; public class Quickpass extends StandardPboc { protected final static byte[] DFN_PPSE = { (byte) '2', (byte) 'P', (byte) 'A', (byte) 'Y', (byte) '.', (byte) 'S', (byte) 'Y', (byte) 'S', (byte) '.', (byte) 'D', (byte) 'D', (byte) 'F', (byte) '0', (byte) '1', }; protected final static byte[] AID_DEBIT = { (byte) 0xA0, 0x00, 0x00, 0x03, 0x33, 0x01, 0x01, 0x01 }; protected final static byte[] AID_CREDIT = { (byte) 0xA0, 0x00, 0x00, 0x03, 0x33, 0x01, 0x01, 0x02 }; protected final static byte[] AID_QUASI_CREDIT = { (byte) 0xA0, 0x00, 0x00, 0x03, 0x33, 0x01, 0x01, 0x03 }; public final static short MARK_LOG = (short) 0xDFFF; protected final static short[] TAG_GLOBAL = { (short) 0x9F79 /* 电子现金余额 */, (short) 0x9F78 /* 电子现金单笔上限 */, (short) 0x9F77 /* 电子现金余额上限 */, (short) 0x9F13 /* 联机ATC */, (short) 0x9F36 /* ATC */, (short) 0x9F51 /* 货币代码 */, (short) 0x9F4F /* 日志文件格式 */, (short) 0x9F4D /* 日志文件ID */, (short) 0x5A /* 帐号 */, (short) 0x5F24 /* 失效日期 */, (short) 0x5F25 /* 生效日期 */, }; @Override protected SPEC.APP getApplicationId() { return SPEC.APP.QUICKPASS; } @Override protected boolean resetTag(Iso7816.StdTag tag) throws IOException { Iso7816.Response rsp = tag.selectByName(DFN_PPSE); if (!rsp.isOkey()) return false; BerTLV.extractPrimitives(topTLVs, rsp); return true; } protected HINT readCard(Iso7816.StdTag tag, Card card) throws IOException { final ArrayList<Iso7816.ID> aids = getApplicationIds(tag); for (Iso7816.ID aid : aids) { /*--------------------------------------------------------------*/ // select application /*--------------------------------------------------------------*/ Iso7816.Response rsp = tag.selectByName(aid.getBytes()); if (!rsp.isOkey()) continue; final BerHouse subTLVs = new BerHouse(); /*--------------------------------------------------------------*/ // collect info /*--------------------------------------------------------------*/ BerTLV.extractPrimitives(subTLVs, rsp); collectTLVFromGlobalTags(tag, subTLVs); /*--------------------------------------------------------------*/ // parse PDOL and get processing options // 这是正规途径,但是每次GPO都会使ATC加1,达到65535卡片就锁定了 /*--------------------------------------------------------------*/ // rsp = tag.getProcessingOptions(buildPDOL(subTLVs)); // if (rsp.isOkey()) // BerTLV.extractPrimitives(subTLVs, rsp); /*--------------------------------------------------------------*/ // 遍历目录下31个文件,山寨途径,微暴力,不知会对卡片折寿多少 // 相对于GPO不停的增加ATC,这是一种折中 // (遍历过程一般不会超过15个文件就会结束) /*--------------------------------------------------------------*/ collectTLVFromRecords(tag, subTLVs); // String dump = subTLVs.toString(); /*--------------------------------------------------------------*/ // build result /*--------------------------------------------------------------*/ final Application app = createApplication(); parseInfo(app, subTLVs); parseLogs(app, subTLVs); card.addApplication(app); } return card.isUnknownCard() ? HINT.RESETANDGONEXT : HINT.STOP; } private static void parseInfo(Application app, BerHouse tlvs) { Object prop = parseString(tlvs, (short) 0x5A); if (prop != null) app.setProperty(SPEC.PROP.SERIAL, prop); prop = parseApplicationName(tlvs, (String) prop); if (prop != null) app.setProperty(SPEC.PROP.ID, prop); prop = parseInteger(tlvs, (short) 0x9F08); if (prop != null) app.setProperty(SPEC.PROP.VERSION, prop); prop = parseInteger(tlvs, (short) 0x9F36); if (prop != null) app.setProperty(SPEC.PROP.COUNT, prop); prop = parseValidity(tlvs, (short) 0x5F25, (short) 0x5F24); if (prop != null) app.setProperty(SPEC.PROP.DATE, prop); prop = parseCurrency(tlvs, (short) 0x9F51); if (prop != null) app.setProperty(SPEC.PROP.CURRENCY, prop); prop = parseAmount(tlvs, (short) 0x9F77); if (prop != null) app.setProperty(SPEC.PROP.DLIMIT, prop); prop = parseAmount(tlvs, (short) 0x9F78); if (prop != null) app.setProperty(SPEC.PROP.TLIMIT, prop); prop = parseAmount(tlvs, (short) 0x9F79); if (prop != null) app.setProperty(SPEC.PROP.ECASH, prop); } private ArrayList<Iso7816.ID> getApplicationIds(Iso7816.StdTag tag) throws IOException { final ArrayList<Iso7816.ID> ret = new ArrayList<Iso7816.ID>(); // try to read DDF BerTLV sfi = topTLVs.findFirst(Iso7816.BerT.CLASS_SFI); if (sfi != null && sfi.length() == 1) { final int SFI = sfi.v.toInt(); Iso7816.Response r = tag.readRecord(SFI, 1); for (int p = 2; r.isOkey(); ++p) { BerTLV.extractPrimitives(topTLVs, r); r = tag.readRecord(SFI, p); } } // add extracted ArrayList<BerTLV> aids = topTLVs.findAll(Iso7816.BerT.CLASS_AID); if (aids != null) { for (BerTLV aid : aids) ret.add(new Iso7816.ID(aid.v.getBytes())); } // use default list if (ret.isEmpty()) { ret.add(new Iso7816.ID(AID_DEBIT)); ret.add(new Iso7816.ID(AID_CREDIT)); ret.add(new Iso7816.ID(AID_QUASI_CREDIT)); } return ret; } /** * private static void buildPDO(ByteBuffer out, int len, byte... val) { * final int n = Math.min((val != null) ? val.length : 0, len); * * int i = 0; while (i < n) out.put(val[i++]); * * while (i++ < len) out.put((byte) 0); } * * private static byte[] buildPDOL(Iso7816.BerHouse tlvs) { * * final ByteBuffer buff = ByteBuffer.allocate(64); * * buff.put((byte) 0x83).put((byte) 0x00); * * try { final byte[] pdol = tlvs.findFirst((short) 0x9F38).v.getBytes(); * * ArrayList<BerTLV> list = BerTLV.extractOptionList(pdol); for * (Iso7816.BerTLV tlv : list) { final int tag = tlv.t.toInt(); final int * len = tlv.l.toInt(); * * switch (tag) { case 0x9F66: // 终端交易属性 buildPDO(buff, len, (byte) 0x48); * break; case 0x9F02: // 授权金额 buildPDO(buff, len); break; case 0x9F03: // * 其它金额 buildPDO(buff, len); break; case 0x9F1A: // 终端国家代码 buildPDO(buff, * len, (byte) 0x01, (byte) 0x56); break; case 0x9F37: // 不可预知数 * buildPDO(buff, len); break; case 0x5F2A: // 交易货币代码 buildPDO(buff, len, * (byte) 0x01, (byte) 0x56); break; case 0x95: // 终端验证结果 buildPDO(buff, * len); break; case 0x9A: // 交易日期 buildPDO(buff, len); break; case 0x9C: // * 交易类型 buildPDO(buff, len); break; default: throw null; } } // 更新数据长度 * buff.put(1, (byte) (buff.position() - 2)); } catch (Exception e) { * buff.position(2); } * * return Arrays.copyOfRange(buff.array(), 0, buff.position()); } */ private static void collectTLVFromGlobalTags(Iso7816.StdTag tag, BerHouse tlvs) throws IOException { for (short t : TAG_GLOBAL) { Iso7816.Response r = tag.getData(t); if (r.isOkey()) tlvs.add(BerTLV.read(r)); } } private static void collectTLVFromRecords(Iso7816.StdTag tag, BerHouse tlvs) throws IOException { // info files for (int sfi = 1; sfi <= 10; ++sfi) { Iso7816.Response r = tag.readRecord(sfi, 1); for (int idx = 2; r.isOkey() && idx <= 10; ++idx) { BerTLV.extractPrimitives(tlvs, r); r = tag.readRecord(sfi, idx); } } // check if already get sfi of log file BerTLV logEntry = tlvs.findFirst((short) 0x9F4D); final int S, E; if (logEntry != null && logEntry.length() == 2) { S = E = logEntry.v.getBytes()[0] & 0x000000FF; } else { S = 11; E = 31; } // log files for (int sfi = S; sfi <= E; ++sfi) { Iso7816.Response r = tag.readRecord(sfi, 1); boolean findOne = r.isOkey(); for (int idx = 2; r.isOkey() && idx <= 10; ++idx) { tlvs.add(MARK_LOG, r); r = tag.readRecord(sfi, idx); } if (findOne) break; } } private static SPEC.APP parseApplicationName(BerHouse tlvs, String serial) { String f = parseString(tlvs, (short) 0x84); if (f != null) { if (f.endsWith("010101")) return SPEC.APP.DEBIT; if (f.endsWith("010102")) return SPEC.APP.CREDIT; if (f.endsWith("010103")) return SPEC.APP.QCREDIT; } return SPEC.APP.UNKNOWN; } private static SPEC.CUR parseCurrency(BerHouse tlvs, short tag) { return SPEC.CUR.CNY; } private static String parseValidity(BerHouse tlvs, short from, short to) { final byte[] f = BerTLV.getValue(tlvs.findFirst(from)); final byte[] t = BerTLV.getValue(tlvs.findFirst(to)); if (t == null || t.length != 3 || t[0] == 0 || t[0] == (byte) 0xFF) return null; if (f == null || f.length != 3 || f[0] == 0 || f[0] == (byte) 0xFF) return String.format("? - 20%02x.%02x.%02x", t[0], t[1], t[2]); return String.format("20%02x.%02x.%02x - 20%02x.%02x.%02x", f[0], f[1], f[2], t[0], t[1], t[2]); } private static String parseString(BerHouse tlvs, short tag) { final byte[] v = BerTLV.getValue(tlvs.findFirst(tag)); return (v != null) ? Util.toHexString(v) : null; } private static Float parseAmount(BerHouse tlvs, short tag) { Integer v = parseIntegerBCD(tlvs, tag); return (v != null) ? v / 100.0f : null; } private static Integer parseInteger(BerHouse tlvs, short tag) { final byte[] v = BerTLV.getValue(tlvs.findFirst(tag)); return (v != null) ? Util.toInt(v) : null; } private static Integer parseIntegerBCD(BerHouse tlvs, short tag) { final byte[] v = BerTLV.getValue(tlvs.findFirst(tag)); return (v != null) ? Util.BCDtoInt(v) : null; } private static void parseLogs(Application app, BerHouse tlvs) { final byte[] rawTemp = BerTLV.getValue(tlvs.findFirst((short) 0x9F4F)); if (rawTemp == null) return; final ArrayList<BerTLV> temp = BerTLV.extractOptionList(rawTemp); if (temp == null || temp.isEmpty()) return; final ArrayList<BerTLV> logs = tlvs.findAll(MARK_LOG); final ArrayList<String> ret = new ArrayList<String>(logs.size()); for (BerTLV log : logs) { String l = parseLog(temp, log.v.getBytes()); if (l != null) ret.add(l); } if (!ret.isEmpty()) app.setProperty(SPEC.PROP.TRANSLOG, ret.toArray(new String[ret.size()])); } private static String parseLog(ArrayList<BerTLV> temp, byte[] data) { try { int date = -1, time = -1; int amount = 0, type = -1; int cursor = 0; for (BerTLV f : temp) { final int n = f.length(); switch (f.t.toInt()) { case 0x9A: // 交易日期 date = Util.BCDtoInt(data, cursor, n); break; case 0x9F21: // 交易时间 time = Util.BCDtoInt(data, cursor, n); break; case 0x9F02: // 授权金额 amount = Util.BCDtoInt(data, cursor, n); break; case 0x9C: // 交易类型 type = Util.BCDtoInt(data, cursor, n); break; case 0x9F03: // 其它金额 case 0x9F1A: // 终端国家代码 case 0x5F2A: // 交易货币代码 case 0x9F4E: // 商户名称 case 0x9F36: // 应用交易计数器(ATC) default: break; } cursor += n; } if (amount <= 0) return null; final char sign; switch (type) { case 0: // 刷卡消费 case 1: // 取现 case 8: // 转账 case 9: // 支付 case 20: // 退款 case 40: // 持卡人账户转账 sign = '-'; break; default: sign = '+'; break; } String sd = (date <= 0) ? "****.**.**" : String.format( "20%02d.%02d.%02d", (date / 10000) % 100, (date / 100) % 100, date % 100); String st = (time <= 0) ? "**:**" : String.format("%02d:%02d", (time / 10000) % 100, (time / 100) % 100); final StringBuilder ret = new StringBuilder(); ret.append(String.format("%s %s %c%.2f", sd, st, sign, amount / 100f)); return ret.toString(); } catch (Exception e) { return null; } } private final BerHouse topTLVs = new BerHouse(); }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/pboc/Quickpass.java
Java
gpl3
12,953
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader.pboc; import java.io.IOException; import java.util.ArrayList; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.nfc.Util; import com.sinpo.xnfc.nfc.bean.Application; import com.sinpo.xnfc.nfc.bean.Card; import com.sinpo.xnfc.nfc.tech.Iso7816; final class BeijingMunicipal extends StandardPboc { @Override protected SPEC.APP getApplicationId() { return SPEC.APP.BEIJINGMUNICIPAL; } @SuppressWarnings("unchecked") @Override protected HINT readCard(Iso7816.StdTag tag, Card card) throws IOException { Iso7816.Response INFO, CNT, BALANCE; /*--------------------------------------------------------------*/ // read card info file, binary (4) /*--------------------------------------------------------------*/ INFO = tag.readBinary(SFI_EXTRA_LOG); if (!INFO.isOkey()) return HINT.GONEXT; /*--------------------------------------------------------------*/ // read card operation file, binary (5) /*--------------------------------------------------------------*/ CNT = tag.readBinary(SFI_EXTRA_CNT); /*--------------------------------------------------------------*/ // select Main Application /*--------------------------------------------------------------*/ if (!tag.selectByID(DFI_EP).isOkey()) return HINT.RESETANDGONEXT; BALANCE = tag.getBalance(true); /*--------------------------------------------------------------*/ // read log file, record (24) /*--------------------------------------------------------------*/ ArrayList<byte[]> LOG = readLog24(tag, SFI_LOG); /*--------------------------------------------------------------*/ // build result /*--------------------------------------------------------------*/ final Application app = createApplication(); parseBalance(app, BALANCE); parseInfo4(app, INFO, CNT); parseLog24(app, LOG); configApplication(app); card.addApplication(app); return HINT.STOP; } private final static int SFI_EXTRA_LOG = 4; private final static int SFI_EXTRA_CNT = 5; private void parseInfo4(Application app, Iso7816.Response info, Iso7816.Response cnt) { if (!info.isOkey() || info.size() < 32) { return; } final byte[] d = info.getBytes(); app.setProperty(SPEC.PROP.SERIAL, Util.toHexString(d, 0, 8)); app.setProperty(SPEC.PROP.VERSION, String.format("%02X.%02X%02X", d[8], d[9], d[10])); app.setProperty(SPEC.PROP.DATE, String.format( "%02X%02X.%02X.%02X - %02X%02X.%02X.%02X", d[24], d[25], d[26], d[27], d[28], d[29], d[30], d[31])); if (cnt != null && cnt.isOkey() && cnt.size() > 4) { byte[] e = cnt.getBytes(); final int n = Util.toInt(e, 1, 4); if (e[0] == 0) app.setProperty(SPEC.PROP.COUNT, String.format("%d", n)); else app.setProperty(SPEC.PROP.COUNT, String.format("%d*", n)); } } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/pboc/BeijingMunicipal.java
Java
gpl3
3,469
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.nfc.reader; import java.io.IOException; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.nfc.Util; import com.sinpo.xnfc.nfc.bean.Application; import com.sinpo.xnfc.nfc.bean.Card; import com.sinpo.xnfc.nfc.tech.FeliCa; import android.nfc.tech.NfcF; final class FelicaReader { static void readCard(NfcF tech, Card card) throws IOException { final FeliCa.Tag tag = new FeliCa.Tag(tech); tag.connect(); /* * FeliCa.SystemCode systems[] = tag.getSystemCodeList(); if (systems.length == 0) { systems = new FeliCa.SystemCode[] { new FeliCa.SystemCode( tag.getSystemCodeByte()) }; } for (final FeliCa.SystemCode sys : systems) card.addApplication(readApplication(tag, sys.toInt())); */ // better old card compatibility card.addApplication(readApplication(tag, SYS_OCTOPUS)); try { card.addApplication(readApplication(tag, SYS_SZT)); } catch (IOException e) { // for early version of OCTOPUS which will throw shit } tag.close(); } private static final int SYS_SZT = 0x8005; private static final int SYS_OCTOPUS = 0x8008; private static final int SRV_SZT = 0x0118; private static final int SRV_OCTOPUS = 0x0117; private static Application readApplication(FeliCa.Tag tag, int system) throws IOException { final FeliCa.ServiceCode scode; final Application app; if (system == SYS_OCTOPUS) { app = new Application(); app.setProperty(SPEC.PROP.ID, SPEC.APP.OCTOPUS); app.setProperty(SPEC.PROP.CURRENCY, SPEC.CUR.HKD); scode = new FeliCa.ServiceCode(SRV_OCTOPUS); } else if (system == SYS_SZT) { app = new Application(); app.setProperty(SPEC.PROP.ID, SPEC.APP.SHENZHENTONG); app.setProperty(SPEC.PROP.CURRENCY, SPEC.CUR.CNY); scode = new FeliCa.ServiceCode(SRV_SZT); } else { return null; } app.setProperty(SPEC.PROP.SERIAL, tag.getIDm().toString()); app.setProperty(SPEC.PROP.PARAM, tag.getPMm().toString()); tag.polling(system); final float[] data = new float[] { 0, 0, 0 }; int p = 0; for (byte i = 0; p < data.length; ++i) { final FeliCa.ReadResponse r = tag.readWithoutEncryption(scode, i); if (!r.isOkey()) break; data[p++] = (Util.toInt(r.getBlockData(), 0, 4) - 350) / 10.0f; } if (p != 0) app.setProperty(SPEC.PROP.BALANCE, parseBalance(data)); else app.setProperty(SPEC.PROP.BALANCE, Float.NaN); return app; } private static float parseBalance(float[] value) { float balance = 0f; for (float v : value) balance += v; return balance; } }
0antwei-nfcreader
src/com/sinpo/xnfc/nfc/reader/FelicaReader.java
Java
gpl3
3,192
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc; import java.lang.Thread.UncaughtExceptionHandler; import com.sinpo.xnfc.R; import android.app.Application; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.widget.Toast; public final class ThisApplication extends Application implements UncaughtExceptionHandler { private static ThisApplication instance; @Override public void uncaughtException(Thread thread, Throwable ex) { System.exit(0); } @Override public void onCreate() { super.onCreate(); Thread.setDefaultUncaughtExceptionHandler(this); instance = this; } public static String name() { return getStringResource(R.string.app_name); } public static String version() { try { return instance.getPackageManager().getPackageInfo( instance.getPackageName(), 0).versionName; } catch (Exception e) { return "1.0"; } } public static void showMessage(int fmt, CharSequence... msgs) { String msg = String.format(getStringResource(fmt), msgs); Toast.makeText(instance, msg, Toast.LENGTH_LONG).show(); } public static Typeface getFontResource(int pathId) { String path = getStringResource(pathId); return Typeface.createFromAsset(instance.getAssets(), path); } public static int getDimensionResourcePixelSize(int resId) { return instance.getResources().getDimensionPixelSize(resId); } public static int getColorResource(int resId) { return instance.getResources().getColor(resId); } public static String getStringResource(int resId) { return instance.getString(resId); } public static Drawable getDrawableResource(int resId) { return instance.getResources().getDrawable(resId); } public static DisplayMetrics getDisplayMetrics() { return instance.getResources().getDisplayMetrics(); } }
0antwei-nfcreader
src/com/sinpo/xnfc/ThisApplication.java
Java
gpl3
2,479
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.ui; import android.app.Activity; import android.content.Intent; import com.sinpo.xnfc.R; import com.sinpo.xnfc.ThisApplication; public final class AboutPage { private static final String TAG = "ABOUTPAGE_ACTION"; public static CharSequence getContent(Activity activity) { String tip = ThisApplication .getStringResource(R.string.info_main_about); tip = tip.replace("<app />", ThisApplication.name()); tip = tip.replace("<version />", ThisApplication.version()); return new SpanFormatter(null).toSpanned(tip); } public static boolean isSendByMe(Intent intent) { return intent != null && TAG.equals(intent.getAction()); } static SpanFormatter.ActionHandler getActionHandler(Activity activity) { return new Handler(activity); } private static final class Handler implements SpanFormatter.ActionHandler { private final Activity activity; Handler(Activity activity) { this.activity = activity; } @Override public void handleAction(CharSequence name) { activity.setIntent(new Intent(TAG)); } } private AboutPage() { } }
0antwei-nfcreader
src/com/sinpo/xnfc/ui/AboutPage.java
Java
gpl3
1,750
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.ui; import android.animation.LayoutTransition; import android.annotation.SuppressLint; import android.content.Context; import android.os.Build; import android.text.ClipboardManager; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.sinpo.xnfc.R; import com.sinpo.xnfc.ThisApplication; public final class Toolbar { final ViewGroup toolbar; @SuppressLint("NewApi") public Toolbar(ViewGroup toolbar) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) toolbar.setLayoutTransition(new LayoutTransition()); this.toolbar = toolbar; } public void copyPageContent(TextView textArea) { final CharSequence text = textArea.getText(); if (text != null) { ((ClipboardManager) textArea.getContext().getSystemService( Context.CLIPBOARD_SERVICE)).setText(text); ThisApplication.showMessage(R.string.info_main_copied); } } public void show(int... buttons) { hide(); showDelayed(1000, buttons); } private void hide() { final int n = toolbar.getChildCount(); for (int i = 0; i < n; ++i) toolbar.getChildAt(i).setVisibility(View.GONE); } private void showDelayed(int delay, int... buttons) { toolbar.postDelayed(new Helper(buttons), delay); } private final class Helper implements Runnable { private final int[] buttons; Helper(int... buttons) { this.buttons = buttons; } @Override public void run() { final int n = toolbar.getChildCount(); for (int i = 0; i < n; ++i) { final View view = toolbar.getChildAt(i); int visibility = View.GONE; if (buttons != null) { final int id = view.getId(); for (int btn : buttons) { if (btn == id) { visibility = View.VISIBLE; break; } } } view.setVisibility(visibility); } } } }
0antwei-nfcreader
src/com/sinpo/xnfc/ui/Toolbar.java
Java
gpl3
2,488
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.ui; import java.lang.ref.WeakReference; import org.xml.sax.XMLReader; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.FontMetricsInt; import android.graphics.Typeface; import android.text.Editable; import android.text.Html; import android.text.Spannable; import android.text.Spanned; import android.text.TextPaint; import android.text.style.ClickableSpan; import android.text.style.LineHeightSpan; import android.text.style.MetricAffectingSpan; import android.text.style.ReplacementSpan; import android.util.DisplayMetrics; import android.view.View; import com.sinpo.xnfc.R; import com.sinpo.xnfc.SPEC; import com.sinpo.xnfc.ThisApplication; public final class SpanFormatter implements Html.TagHandler { public interface ActionHandler { void handleAction(CharSequence name); } private final ActionHandler handler; public SpanFormatter(ActionHandler handler) { this.handler = handler; } public CharSequence toSpanned(String html) { return Html.fromHtml(html, null, this); } private static final class ActionSpan extends ClickableSpan { private final String action; private final ActionHandler handler; private final int color; ActionSpan(String action, ActionHandler handler, int color) { this.action = action; this.handler = handler; this.color = color; } @Override public void onClick(View widget) { if (handler != null) handler.handleAction(action); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setColor(color); } } private static final class FontSpan extends MetricAffectingSpan { final int color; final float size; final Typeface face; final boolean bold; FontSpan(int color, float size, Typeface face) { this.color = color; this.size = size; if (face == Typeface.DEFAULT) { this.face = null; this.bold = false; } else if (face == Typeface.DEFAULT_BOLD) { this.face = null; this.bold = true; } else { this.face = face; this.bold = false; } } @Override public void updateDrawState(TextPaint ds) { ds.setTextSize(size); ds.setColor(color); if (face != null) { ds.setTypeface(face); } else if (bold) { Typeface tf = ds.getTypeface(); if (tf != null) { int style = tf.getStyle() | Typeface.BOLD; tf = Typeface.create(tf, style); ds.setTypeface(tf); style &= ~tf.getStyle(); if ((style & Typeface.BOLD) != 0) { ds.setFakeBoldText(true); } } } } @Override public void updateMeasureState(TextPaint p) { updateDrawState(p); } } private static final class ParagSpan implements LineHeightSpan { private final int linespaceDelta; ParagSpan(int linespaceDelta) { this.linespaceDelta = linespaceDelta; } @Override public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, FontMetricsInt fm) { fm.bottom += linespaceDelta; fm.descent += linespaceDelta; } } private static final class SplitterSpan extends ReplacementSpan { private final int color; private final int width; private final int height; SplitterSpan(int color, int width, int height) { this.color = color; this.width = width; this.height = height; } @Override public void updateDrawState(TextPaint ds) { ds.setTextSize(1); } @Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { return 0; } @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { canvas.save(); canvas.translate(x, (bottom + top) / 2 - height); final int c = paint.getColor(); paint.setColor(color); canvas.drawRect(x, 0, x + width, height, paint); paint.setColor(c); canvas.restore(); } } @Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { final int len = output.length(); if (opening) { if (SPEC.TAG_TEXT.equals(tag)) { markFontSpan(output, len, R.color.tag_text, R.dimen.tag_text, Typeface.DEFAULT); } else if (SPEC.TAG_TIP.equals(tag)) { markParagSpan(output, len, R.dimen.tag_parag); markFontSpan(output, len, R.color.tag_tip, R.dimen.tag_tip, getTipFont()); } else if (SPEC.TAG_LAB.equals(tag)) { markFontSpan(output, len, R.color.tag_lab, R.dimen.tag_lab, Typeface.DEFAULT_BOLD); } else if (SPEC.TAG_ITEM.equals(tag)) { markFontSpan(output, len, R.color.tag_item, R.dimen.tag_item, Typeface.DEFAULT); } else if (SPEC.TAG_H1.equals(tag)) { markFontSpan(output, len, R.color.tag_h1, R.dimen.tag_h1, Typeface.DEFAULT_BOLD); } else if (SPEC.TAG_H2.equals(tag)) { markFontSpan(output, len, R.color.tag_h2, R.dimen.tag_h2, Typeface.DEFAULT_BOLD); } else if (SPEC.TAG_H3.equals(tag)) { markFontSpan(output, len, R.color.tag_h3, R.dimen.tag_h3, Typeface.SERIF); } else if (tag.startsWith(SPEC.TAG_ACT)) { markActionSpan(output, len, tag, R.color.tag_action); } else if (SPEC.TAG_PARAG.equals(tag)) { markParagSpan(output, len, R.dimen.tag_parag); } else if (SPEC.TAG_SP.equals(tag)) { markSpliterSpan(output, len, R.color.tag_action, R.dimen.tag_spliter); } } else { if (SPEC.TAG_TEXT.equals(tag)) { setSpan(output, len, FontSpan.class); } else if (SPEC.TAG_TIP.equals(tag)) { setSpan(output, len, FontSpan.class); setSpan(output, len, ParagSpan.class); } else if (SPEC.TAG_LAB.equals(tag)) { setSpan(output, len, FontSpan.class); } else if (SPEC.TAG_ITEM.equals(tag)) { setSpan(output, len, FontSpan.class); } else if (SPEC.TAG_H1.equals(tag)) { setSpan(output, len, FontSpan.class); } else if (SPEC.TAG_H2.equals(tag)) { setSpan(output, len, FontSpan.class); } else if (SPEC.TAG_H3.equals(tag)) { setSpan(output, len, FontSpan.class); } else if (tag.startsWith(SPEC.TAG_ACT)) { setSpan(output, len, ActionSpan.class); } else if (SPEC.TAG_PARAG.equals(tag)) { setSpan(output, len, ParagSpan.class); } } } private static void markSpliterSpan(Editable out, int pos, int colorId, int heightId) { DisplayMetrics dm = ThisApplication.getDisplayMetrics(); int color = ThisApplication.getColorResource(colorId); int height = ThisApplication.getDimensionResourcePixelSize(heightId); out.append("-------------------").setSpan( new SplitterSpan(color, dm.widthPixels, height), pos, out.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } private static void markFontSpan(Editable out, int pos, int colorId, int sizeId, Typeface face) { int color = ThisApplication.getColorResource(colorId); float size = ThisApplication.getDimensionResourcePixelSize(sizeId); FontSpan span = new FontSpan(color, size, face); out.setSpan(span, pos, pos, Spannable.SPAN_MARK_MARK); } private static void markParagSpan(Editable out, int pos, int linespaceId) { int linespace = ThisApplication .getDimensionResourcePixelSize(linespaceId); ParagSpan span = new ParagSpan(linespace); out.setSpan(span, pos, pos, Spannable.SPAN_MARK_MARK); } private void markActionSpan(Editable out, int pos, String tag, int colorId) { int color = ThisApplication.getColorResource(colorId); out.setSpan(new ActionSpan(tag, handler, color), pos, pos, Spannable.SPAN_MARK_MARK); } private static void setSpan(Editable out, int pos, Class<?> kind) { Object span = getLastMarkSpan(out, kind); out.setSpan(span, out.getSpanStart(span), pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } private static Object getLastMarkSpan(Spanned text, Class<?> kind) { Object[] objs = text.getSpans(0, text.length(), kind); if (objs.length == 0) { return null; } else { return objs[objs.length - 1]; } } private static Typeface getTipFont() { Typeface ret = null; WeakReference<Typeface> wr = TIPFONT; if (wr != null) ret = wr.get(); if (ret == null) { ret = ThisApplication.getFontResource(R.string.font_oem3); TIPFONT = new WeakReference<Typeface>(ret); } return ret; } private static WeakReference<Typeface> TIPFONT; }
0antwei-nfcreader
src/com/sinpo/xnfc/ui/SpanFormatter.java
Java
gpl3
8,905
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.ui; import android.app.Activity; import android.app.Dialog; import android.content.Intent; import com.sinpo.xnfc.R; import com.sinpo.xnfc.ThisApplication; import com.sinpo.xnfc.SPEC.EVENT; import com.sinpo.xnfc.nfc.bean.Card; import com.sinpo.xnfc.nfc.reader.ReaderListener; public final class NfcPage implements ReaderListener { private static final String TAG = "READCARD_ACTION"; private static final String RET = "READCARD_RESULT"; private static final String STA = "READCARD_STATUS"; private final Activity activity; public NfcPage(Activity activity) { this.activity = activity; } public static boolean isSendByMe(Intent intent) { return intent != null && TAG.equals(intent.getAction()); } public static boolean isNormalInfo(Intent intent) { return intent != null && intent.hasExtra(STA); } public static CharSequence getContent(Activity activity, Intent intent) { String info = intent.getStringExtra(RET); if (info == null || info.length() == 0) return null; return new SpanFormatter(AboutPage.getActionHandler(activity)) .toSpanned(info); } @Override public void onReadEvent(EVENT event, Object... objs) { if (event == EVENT.IDLE) { showProgressBar(); } else if (event == EVENT.FINISHED) { hideProgressBar(); final Card card; if (objs != null && objs.length > 0) card = (Card) objs[0]; else card = null; activity.setIntent(buildResult(card)); } } private Intent buildResult(Card card) { final Intent ret = new Intent(TAG); if (card != null && !card.hasReadingException()) { if (card.isUnknownCard()) { ret.putExtra(RET, ThisApplication .getStringResource(R.string.info_nfc_unknown)); } else { ret.putExtra(RET, card.toHtml()); ret.putExtra(STA, 1); } } else { ret.putExtra(RET, ThisApplication.getStringResource(R.string.info_nfc_error)); } return ret; } private void showProgressBar() { Dialog d = progressBar; if (d == null) { d = new Dialog(activity, R.style.progressBar); d.setCancelable(false); d.setContentView(R.layout.progress); progressBar = d; } if (!d.isShowing()) d.show(); } private void hideProgressBar() { final Dialog d = progressBar; if (d != null && d.isShowing()) d.cancel(); } private Dialog progressBar; }
0antwei-nfcreader
src/com/sinpo/xnfc/ui/NfcPage.java
Java
gpl3
2,981
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc.ui; import static android.provider.Settings.ACTION_SETTINGS; import android.app.Activity; import android.content.Intent; import android.nfc.NfcAdapter; import com.sinpo.xnfc.R; import com.sinpo.xnfc.ThisApplication; public final class MainPage { public static CharSequence getContent(Activity activity) { final NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity); final int resid; if (nfc == null) resid = R.string.info_nfc_notsupport; else if (!nfc.isEnabled()) resid = R.string.info_nfc_disabled; else resid = R.string.info_nfc_nocard; String tip = ThisApplication.getStringResource(resid); return new SpanFormatter(new Handler(activity)).toSpanned(tip); } private static final class Handler implements SpanFormatter.ActionHandler { private final Activity activity; Handler(Activity activity) { this.activity = activity; } @Override public void handleAction(CharSequence name) { startNfcSettingsActivity(); } private void startNfcSettingsActivity() { activity.startActivityForResult(new Intent(ACTION_SETTINGS), 0); } } private MainPage() { } }
0antwei-nfcreader
src/com/sinpo/xnfc/ui/MainPage.java
Java
gpl3
1,798
/* NFCard is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. NFCard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget. If not, see <http://www.gnu.org/licenses/>. Additional permission under GNU GPL version 3 section 7 */ package com.sinpo.xnfc; import com.sinpo.xnfc.R; public final class SPEC { public enum PAGE { DEFAULT, INFO, ABOUT, } public enum EVENT { IDLE, ERROR, READING, FINISHED, } public enum PROP { ID(R.string.spec_prop_id), SERIAL(R.string.spec_prop_serial), PARAM(R.string.spec_prop_param), VERSION(R.string.spec_prop_version), DATE(R.string.spec_prop_date), COUNT(R.string.spec_prop_count), CURRENCY(R.string.spec_prop_currency), TLIMIT(R.string.spec_prop_tlimit), DLIMIT(R.string.spec_prop_dlimit), ECASH(R.string.spec_prop_ecash), BALANCE(R.string.spec_prop_balance), TRANSLOG(R.string.spec_prop_translog), ACCESS(R.string.spec_prop_access), EXCEPTION(R.string.spec_prop_exception); public String toString() { return ThisApplication.getStringResource(resId); } private final int resId; private PROP(int resId) { this.resId = resId; } } public enum APP { UNKNOWN(R.string.spec_app_unknown), SHENZHENTONG(R.string.spec_app_shenzhentong), QUICKPASS(R.string.spec_app_quickpass), OCTOPUS(R.string.spec_app_octopus_hk), BEIJINGMUNICIPAL(R.string.spec_app_beijing), WUHANTONG(R.string.spec_app_wuhantong), CHANGANTONG(R.string.spec_app_changantong), SHANGHAIGJ(R.string.spec_app_shanghai), DEBIT(R.string.spec_app_debit), CREDIT(R.string.spec_app_credit), QCREDIT(R.string.spec_app_qcredit); public String toString() { return ThisApplication.getStringResource(resId); } private final int resId; private APP(int resId) { this.resId = resId; } } public enum CUR { UNKNOWN(R.string.spec_cur_unknown), USD(R.string.spec_cur_usd), CNY(R.string.spec_cur_cny), HKD(R.string.spec_cur_hkd); public String toString() { return ThisApplication.getStringResource(resId); } private final int resId; private CUR(int resId) { this.resId = resId; } } public static final String TAG_BLK = "div"; public static final String TAG_TIP = "t_tip"; public static final String TAG_ACT = "t_action"; public static final String TAG_EM = "t_em"; public static final String TAG_H1 = "t_head1"; public static final String TAG_H2 = "t_head2"; public static final String TAG_H3 = "t_head3"; public static final String TAG_SP = "t_splitter"; public static final String TAG_TEXT = "t_text"; public static final String TAG_ITEM = "t_item"; public static final String TAG_LAB = "t_label"; public static final String TAG_PARAG = "t_parag"; }
0antwei-nfcreader
src/com/sinpo/xnfc/SPEC.java
Java
gpl3
3,101