MotorWare f2806x Driver API Documentation
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 
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 
73  const OSC_Number_e oscNumber,
74  const uint_least8_t trimValue)
75 {
76  OSC_Obj *osc = (OSC_Obj *)clkHandle;
77 
79 
80  if(oscNumber == OSC_Number_1)
81  {
82  // clear the bits
84 
85  // set the bits
86  osc->INTOSC1TRIM |= trimValue;
87  }
88  else
89  {
90  // clear the bits
92 
93  // set the bits
94  osc->INTOSC2TRIM |= trimValue;
95  }
96 
98 
99  return;
100 } // end of OSC_setCoarseTrim() function
101 
102 
104  const OSC_Number_e oscNumber,
105  const uint_least8_t trimValue)
106 {
107  OSC_Obj *osc = (OSC_Obj *)clkHandle;
108 
110 
111  if(oscNumber == OSC_Number_1)
112  {
113  // clear the bits
115 
116  // set the bits
117  osc->INTOSC1TRIM |= trimValue << 9;
118  }
119  else
120  {
121  // clear the bits
123 
124  // set the bits
125  osc->INTOSC2TRIM |= trimValue << 9;
126  }
127 
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 
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 
154 
155  return;
156 } // end of OSC_setTrim() function
157 
158 
159 // end of file
OSC_Handle OSC_init(void *pMemory, const size_t numBytes)
Initializes the oscillator (OSC) handle.
Definition: osc.c:57
#define OSC_INTOSCnTRIM_COARSE_BITS
Defines the location of the COARSETRIM bits in the INTOSCnTRIM register.
Definition: osc.h:75
struct _OSC_Obj_ * OSC_Handle
Defines the oscillator (OSC) handle.
Definition: osc.h:125
#define DISABLE_PROTECTED_REGISTER_WRITE_MODE
Define to disable protected register writes.
Definition: cpu.h:101
volatile uint16_t INTOSC1TRIM
Internal Oscillator 1 Trim Register.
Definition: osc.h:117
Defines the oscillator (OSC) object.
Definition: osc.h:115
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
Denotes oscillator number 1.
Definition: osc.h:108
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
volatile uint16_t INTOSC2TRIM
Internal Oscillator 2 Trim Register.
Definition: osc.h:119
#define ENABLE_PROTECTED_REGISTER_WRITE_MODE
Define to allow protected register writes.
Definition: cpu.h:93
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
#define OSC_INTOSCnTRIM_FINE_BITS
Defines the location of the FINETRIM bits in the INTOSCnTRIM register.
Definition: osc.h:79
Contains public interface to various functions related to the oscillator (OSC) object.
OSC_Number_e
Enumeration to define the oscillator (OSC) number.
Definition: osc.h:106