| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

p33c_macros.h
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2 * and any derivatives exclusively with Microchip products.
3 *
4 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9 *
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17 *
18 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19 * TERMS.
20 */
21
22 /*
23 * File: p33c_macros.h
24 * Author: M91406
25 * Comments: Header files providing inline assembly macros for basic CPU instructions
26 * Revision history:
27 * 1.0 Initial release 06/22/20
28 */
29
30 // This is a guard condition so that contents of this file are not included
31 // more than once.
32 #ifndef P33C_CPU_MACROS_H
33 #define P33C_CPU_MACROS_H
34
35 #include <xc.h> // include processor files - each processor file is guarded.
36
37 #define WDT_RESET() asm volatile ("CRLWDT\n")
38 #define PWRSAV_IDLE() asm volatile ("PWRSAV #1\n")
39 #define PWRSAV_SLEEP() asm volatile ("PWRSAV #0\n")
40 #define CPU_RESET() asm volatile ("RESET\n")
41
42 /**********************************************************************************
43 * @def ALTWREG_SWAP
44 * @brief Swaps the current working register set
45 * @param x: Index of new Working Register Set (Target) of type unsigned integer
46 * @return Index of previous Working Register Set (Origin) of type unsigned integer
47 **********************************************************************************/
48 #define ALTWREG_SWAP(x) __extension__ ({ \
49 volatile uint16_t __x = (x), __v; \
50 __asm__ ("ctxtswp %1;\n\t" : "=d" (__v) : "d" (__x)); __v; \
51 })
52
53 /**********************************************************************************
54 * @def SwapWordBytes(x)
55 * @brief: Swaps high and low byte of a 16 bit value
56 * @param x: Value to be swapped
57 * @return 16-bit value of swapped byte order
58 **********************************************************************************/
59 #define SwapWordBytes(x) __extension__ ({ \
60 volatile uint16_t __x = (x), __v; \
61 __asm__ ("swap %0;\n\t" : "=d" (__v) : "d" (__x)); __v; \
62 })
63
64 /**********************************************************************************
65 * @def ReverseBitOrder16b(x)
66 * @brief: Reverses the bit order of a 16 bit value
67 * @param x: Value to be reversed
68 * @return 16-bit value in reverse bit order
69 **********************************************************************************/
70
71 #define ReverseBitOrder16b(x) __extension__ ({ \
72 volatile uint16_t __x = (x), __v; \
73 __asm__ volatile ( \
74 "0: do #15, 1f\n\t" \
75 "sl %1, %1\n\t" \
76 "1: rrc %0, %0\n\t" \
77 : "=d" (__v), \
78 "+d" (__x)); \
79 __v; \
80 })
81
82 #endif /* P33C_CPU_MACROS_H */
83
84 // end of file