forked from microchip-pic-avr-solutions/library-motor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor_control_inline_internal.h
96 lines (81 loc) · 3.74 KB
/
motor_control_inline_internal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
Header file for Motor Control library inline definitions of internal functions
Company:
Microchip Technology Inc.
File Name:
motor_control_inline_internal.h
Summary:
This header file contains implementation details of the Motor Control Library
that are not part of its public interface and are subject to change.
Please use the functions and type definitions contained in other header files
of the Motor Control Library instead.
Description:
This header file is automatically included when the library interfaces header file
is included in the project.
*******************************************************************************/
// DOM-IGNORE-BEGIN
/* *********************************************************************
*
* (c) 2017 Microchip Technology Inc. and its subsidiaries. You may use
* this software and any derivatives exclusively with Microchip products.
*
* This software and any accompanying information is for suggestion only.
* It does not modify Microchip's standard warranty for its products.
* You agree that you are solely responsible for testing the software and
* determining its suitability. Microchip has no obligation to modify,
* test, certify, or support the software.
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH
* MICROCHIP PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY
* APPLICATION.
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL,
* PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF
* ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT
* EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO
* MICROCHIP FOR THIS SOFTWARE.
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF
* THESE TERMS.
*
* *****************************************************************************/
// DOM-IGNORE-END
#ifndef _MOTOR_CONTROL_INLINE_INTERNAL_H_
#define _MOTOR_CONTROL_INLINE_INTERNAL_H_
// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
/* This section lists the other files that are included in this file.
*/
#include <stdint.h>
/**
* Compute limit(x + ofs_out, min, max)
* This optimized code works ONLY if ofs_out >= 0
*/
static inline int16_t MC_adjust_zero_sequence(int16_t x, int16_t ofs_out, int16_t min, int16_t max)
{
int16_t w;
asm volatile (
" add %[ofs_out], %[x], %[w]\n" /* overflow is only positive */
" cpslt %[min], %[w]\n"
" mov %[min], %[w]\n" /* if (w < min) { w = min; } */
" btss SR, #2\n" /* if ofs_out > 0, OV = SR<2> indicates we need positive clipping */
" cpslt %[w], %[max]\n"
" mov %[max], %[w]\n"
: [w]"=&r"(w)
: [x]"r"(x),
[ofs_out]"r"(ofs_out),
[min]"r"(min),
[max]"r"(max)
);
return w;
}
#ifdef __cplusplus // Provide C++ Compatability
extern "C" {
#endif
#endif // _MOTOR_CONTROL_INLINE_INTERNAL_H_