MotorWare f2806x Driver API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

osc.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2015, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
37
38
39 // **************************************************************************
40 // the includes
41
42 #include "sw/drivers/osc/src/32b/f28x/f2806x/osc.h"
43
44
45 // **************************************************************************
46 // the defines
47
48
49 // **************************************************************************
50 // the globals
51
52
53 // **************************************************************************
54 // the functions
55
56
57 OSC_Handle OSC_init(void *pMemory,const size_t numBytes)
58 {
59 OSC_Handle oscHandle;
60
61
62 if(numBytes < sizeof(OSC_Obj))
63 return((OSC_Handle)NULL);
64
65 // assign the handle
66 oscHandle = (OSC_Handle)pMemory;
67
68 return(oscHandle);
69 } // end of OSC_init() function
70
71
72 void OSC_setCoarseTrim(OSC_Handle clkHandle,
73 const OSC_Number_e oscNumber,
74 const uint_least8_t trimValue)
75 {
76 OSC_Obj *osc = (OSC_Obj *)clkHandle;
77
78 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
79
80 if(oscNumber == OSC_Number_1)
81 {
82 // clear the bits
83 osc->INTOSC1TRIM &= (~OSC_INTOSCnTRIM_COARSE_BITS);
84
85 // set the bits
86 osc->INTOSC1TRIM |= trimValue;
87 }
88 else
89 {
90 // clear the bits
91 osc->INTOSC2TRIM &= (~OSC_INTOSCnTRIM_COARSE_BITS);
92
93 // set the bits
94 osc->INTOSC2TRIM |= trimValue;
95 }
96
97 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
98
99 return;
100 } // end of OSC_setCoarseTrim() function
101
102
103 void OSC_setFineTrim(OSC_Handle clkHandle,
104 const OSC_Number_e oscNumber,
105 const uint_least8_t trimValue)
106 {
107 OSC_Obj *osc = (OSC_Obj *)clkHandle;
108
109 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
110
111 if(oscNumber == OSC_Number_1)
112 {
113 // clear the bits
114 osc->INTOSC1TRIM &= (~OSC_INTOSCnTRIM_FINE_BITS);
115
116 // set the bits
117 osc->INTOSC1TRIM |= trimValue << 9;
118 }
119 else
120 {
121 // clear the bits
122 osc->INTOSC2TRIM &= (~OSC_INTOSCnTRIM_FINE_BITS);
123
124 // set the bits
125 osc->INTOSC2TRIM |= trimValue << 9;
126 }
127
128 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
129
130 return;
131 } // end of OSC_setFineTrim() function
132
133
134 void OSC_setTrim(OSC_Handle clkHandle,
135 const OSC_Number_e oscNumber,
136 const uint16_t trimValue)
137 {
138 OSC_Obj *osc = (OSC_Obj *)clkHandle;
139
140 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
141
142 if(oscNumber == OSC_Number_1)
143 {
144 // set the bits
145 osc->INTOSC1TRIM = trimValue;
146 }
147 else
148 {
149 // set the bits
150 osc->INTOSC2TRIM = trimValue;
151 }
152
153 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
154
155 return;
156 } // end of OSC_setTrim() function
157
158
159 // end of file
OSC_init
OSC_Handle OSC_init(void *pMemory, const size_t numBytes)
Initializes the oscillator (OSC) handle.
Definition: osc.c:57
OSC_INTOSCnTRIM_COARSE_BITS
#define OSC_INTOSCnTRIM_COARSE_BITS
Defines the location of the COARSETRIM bits in the INTOSCnTRIM register.
Definition: osc.h:75
OSC_Handle
struct _OSC_Obj_ * OSC_Handle
Defines the oscillator (OSC) handle.
Definition: osc.h:125
DISABLE_PROTECTED_REGISTER_WRITE_MODE
#define DISABLE_PROTECTED_REGISTER_WRITE_MODE
Define to disable protected register writes.
Definition: cpu.h:101
_OSC_Obj_::INTOSC1TRIM
volatile uint16_t INTOSC1TRIM
Internal Oscillator 1 Trim Register.
Definition: osc.h:117
_OSC_Obj_
Defines the oscillator (OSC) object.
Definition: osc.h:115
OSC_setCoarseTrim
void OSC_setCoarseTrim(OSC_Handle clkHandle, const OSC_Number_e oscNumber, const uint_least8_t trimValue)
Sets the coarse trim value for a specified oscillator.
Definition: osc.c:72
OSC_Number_1
Denotes oscillator number 1.
Definition: osc.h:108
OSC_setTrim
void OSC_setTrim(OSC_Handle clkHandle, const OSC_Number_e oscNumber, const uint16_t trimValue)
Sets the trim value for a specified oscillator.
Definition: osc.c:134
_OSC_Obj_::INTOSC2TRIM
volatile uint16_t INTOSC2TRIM
Internal Oscillator 2 Trim Register.
Definition: osc.h:119
ENABLE_PROTECTED_REGISTER_WRITE_MODE
#define ENABLE_PROTECTED_REGISTER_WRITE_MODE
Define to allow protected register writes.
Definition: cpu.h:93
OSC_setFineTrim
void OSC_setFineTrim(OSC_Handle clkHandle, const OSC_Number_e oscNumber, const uint_least8_t trimValue)
Sets the fine trim value for a specified oscillator.
Definition: osc.c:103
OSC_INTOSCnTRIM_FINE_BITS
#define OSC_INTOSCnTRIM_FINE_BITS
Defines the location of the FINETRIM bits in the INTOSCnTRIM register.
Definition: osc.h:79
osc.h
Contains public interface to various functions related to the oscillator (OSC) object.
OSC_Number_e
OSC_Number_e
Enumeration to define the oscillator (OSC) number.
Definition: osc.h:106