IoT Supervisor 0.0
Loading...
Searching...
No Matches
InitDevice.c
Go to the documentation of this file.
1
12// USER INCLUDES
13#include <SI_EFM8BB1_Register_Enums.h>
14#include "InitDevice.h"
15
16// USER PROTOTYPES
17// USER FUNCTIONS
18
19// $[Library Includes]
20// [Library Includes]$
21
22//==============================================================================
23// enter_DefaultMode_from_RESET
24//==============================================================================
42
44{
45 // $[Watchdog Timer Init Variable Declarations]
46 uint32_t i;
47 bool ea;
48 // [Watchdog Timer Init Variable Declarations]$
49
50 // $[WDTCN - Watchdog Timer Control]
51 // Deprecated
52 // [WDTCN - Watchdog Timer Control]$
53
54 // $[WDTCN_2 - Watchdog Timer Control]
55
56 // Feed WDT timer before disabling (Erratum WDT_E102)
57 WDTCN = 0xA5;
58
59 // Add 2 LFO cycle delay before disabling WDT (Erratum WDT_E102)
60 for (i = 0; i < (2 * 3062500UL) / (10000 * 3); i++)
61 {
62 NOP();
63 }
64
65 // Disable WDT before changing interval
66 ea = IE_EA;
67 IE_EA = 0;
68 WDTCN = 0xDE;
69 WDTCN = 0xAD;
70 IE_EA = ea;
71
72 // Delay 2 LFO cycles to ensure WDT is completely disabled
73 for (i = 0; i < (2 * 3062500UL) / (10000 * 3); i++)
74 {
75 NOP();
76 }
77
78 // Change WDT interval
79 WDTCN = 1;
80
81 // Start WDT
82 WDTCN = 0xA5;
83
84 // [WDTCN_2 - Watchdog Timer Control]$
85
86}
87
89{
90 // $[P0 - Port 0 Pin Latch]
91
101 P0 = P0_B0__LOW | P0_B1__HIGH | P0_B2__HIGH | P0_B3__LOW | P0_B4__HIGH
102 | P0_B5__HIGH | P0_B6__HIGH | P0_B7__LOW;
103 // [P0 - Port 0 Pin Latch]$
104
105 // $[P0MDOUT - Port 0 Output Mode]
106
116 P0MDOUT = P0MDOUT_B0__OPEN_DRAIN | P0MDOUT_B1__OPEN_DRAIN
117 | P0MDOUT_B2__OPEN_DRAIN | P0MDOUT_B3__PUSH_PULL
118 | P0MDOUT_B4__PUSH_PULL | P0MDOUT_B5__OPEN_DRAIN
119 | P0MDOUT_B6__OPEN_DRAIN | P0MDOUT_B7__PUSH_PULL;
120 // [P0MDOUT - Port 0 Output Mode]$
121
122 // $[P0MDIN - Port 0 Input Mode]
123
133 P0MDIN = P0MDIN_B0__DIGITAL | P0MDIN_B1__ANALOG | P0MDIN_B2__DIGITAL
134 | P0MDIN_B3__DIGITAL | P0MDIN_B4__DIGITAL | P0MDIN_B5__DIGITAL
135 | P0MDIN_B6__DIGITAL | P0MDIN_B7__DIGITAL;
136 // [P0MDIN - Port 0 Input Mode]$
137
138 // $[P0SKIP - Port 0 Skip]
139
149 P0SKIP = P0SKIP_B0__SKIPPED | P0SKIP_B1__SKIPPED | P0SKIP_B2__SKIPPED
150 | P0SKIP_B3__SKIPPED | P0SKIP_B4__NOT_SKIPPED
151 | P0SKIP_B5__NOT_SKIPPED | P0SKIP_B6__SKIPPED
152 | P0SKIP_B7__NOT_SKIPPED;
153 // [P0SKIP - Port 0 Skip]$
154
155 // $[P0MASK - Port 0 Mask]
156 // [P0MASK - Port 0 Mask]$
157
158 // $[P0MAT - Port 0 Match]
159 // [P0MAT - Port 0 Match]$
160
161}
162
164{
165 // $[XBR2 - Port I/O Crossbar 2]
166
170 XBR2 = XBR2_WEAKPUD__PULL_UPS_ENABLED | XBR2_XBARE__ENABLED;
171 // [XBR2 - Port I/O Crossbar 2]$
172
173 // $[PRTDRV - Port Drive Strength]
174 // [PRTDRV - Port Drive Strength]$
175
176 // $[XBR0 - Port I/O Crossbar 0]
177
187 XBR0 = XBR0_URT0E__ENABLED | XBR0_SPI0E__DISABLED | XBR0_SMB0E__DISABLED
188 | XBR0_CP0E__DISABLED | XBR0_CP0AE__DISABLED | XBR0_CP1E__DISABLED
189 | XBR0_CP1AE__ENABLED | XBR0_SYSCKE__DISABLED;
190 // [XBR0 - Port I/O Crossbar 0]$
191
192 // $[XBR1 - Port I/O Crossbar 1]
193 // [XBR1 - Port I/O Crossbar 1]$
194
195}
196
198{
199 // $[CLKSEL - Clock Select]
200
204 CLKSEL = CLKSEL_CLKSL__HFOSC | CLKSEL_CLKDIV__SYSCLK_DIV_16;
205 // [CLKSEL - Clock Select]$
206
207}
208
210{
211 // $[CMP0MX - Comparator 0 Multiplexer Selection]
212
216 uint8_t delay;
217
218 CMP0MX = CMP0MX_CMXP__LDO_OUT | CMP0MX_CMXN__CMP0N1;
219 // Delay to allow the comparator inputs to settle
220 for (delay = 0; delay < 0x20; delay++)
221 ;
222 // [CMP0MX - Comparator 0 Multiplexer Selection]$
223
224 // $[CMP0MD - Comparator 0 Mode]
225
228 CMP0MD |= CMP0MD_CPRIE__RISE_INT_ENABLED;
229 // [CMP0MD - Comparator 0 Mode]$
230
231 // $[CMP0CN0 - Comparator 0 Control 0]
232
235 CMP0CN0 |= CMP0CN0_CPEN__ENABLED;
236 // [CMP0CN0 - Comparator 0 Control 0]$
237
238}
239
241{
242 // $[Timer Initialization]
243 //Save Timer Configuration
244 uint8_t TCON_save;
245 TCON_save = TCON;
246 //Stop Timers
247 TCON &= ~TCON_TR0__BMASK & ~TCON_TR1__BMASK;
248
249 // [Timer Initialization]$
250
251 // $[TH0 - Timer 0 High Byte]
252
255 TH0 = (0x80 << TH0_TH0__SHIFT);
256 // [TH0 - Timer 0 High Byte]$
257
258 // $[TL0 - Timer 0 Low Byte]
259
262 TL0 = (0x60 << TL0_TL0__SHIFT);
263 // [TL0 - Timer 0 Low Byte]$
264
265 // $[TH1 - Timer 1 High Byte]
266 // [TH1 - Timer 1 High Byte]$
267
268 // $[TL1 - Timer 1 Low Byte]
269 // [TL1 - Timer 1 Low Byte]$
270
271 // $[Timer Restoration]
272 //Restore Timer Configuration
273 TCON |= (TCON_save & TCON_TR0__BMASK) | (TCON_save & TCON_TR1__BMASK);
274
275 // [Timer Restoration]$
276
277}
278
280{
281 // $[CKCON0 - Clock Control 0]
282 // [CKCON0 - Clock Control 0]$
283
284 // $[TMOD - Timer 0/1 Mode]
285
293 TMOD = TMOD_T0M__MODE3 | TMOD_T1M__MODE3 | TMOD_CT0__TIMER
294 | TMOD_GATE0__DISABLED | TMOD_CT1__TIMER | TMOD_GATE1__DISABLED;
295 // [TMOD - Timer 0/1 Mode]$
296
297 // $[TCON - Timer 0/1 Control]
298
301 TCON |= TCON_TR1__RUN;
302 // [TCON - Timer 0/1 Control]$
303
304}
305
307{
308 // $[EIE1 - Extended Interrupt Enable 1]
309
320 EIE1 = EIE1_EADC0__ENABLED | EIE1_EWADC0__DISABLED | EIE1_ECP0__DISABLED
321 | EIE1_ECP1__ENABLED | EIE1_EMAT__DISABLED | EIE1_EPCA0__DISABLED
322 | EIE1_ESMB0__DISABLED | EIE1_ET3__DISABLED;
323 // [EIE1 - Extended Interrupt Enable 1]$
324
325 // $[EIP1 - Extended Interrupt Priority 1]
326 // [EIP1 - Extended Interrupt Priority 1]$
327
328 // $[IE - Interrupt Enable]
329
339 IE = IE_EA__ENABLED | IE_EX0__DISABLED | IE_EX1__DISABLED
340 | IE_ESPI0__DISABLED | IE_ET0__ENABLED | IE_ET1__ENABLED
341 | IE_ET2__DISABLED | IE_ES0__ENABLED;
342 // [IE - Interrupt Enable]$
343
344 // $[IP - Interrupt Priority]
345 // [IP - Interrupt Priority]$
346
347}
348
350{
351 // $[SCON0 - UART0 Serial Port Control]
352
355 SCON0 |= SCON0_REN__RECEIVE_ENABLED;
356 // [SCON0 - UART0 Serial Port Control]$
357
358}
359
361{
362 // $[ADC0CN1 - ADC0 Control 1]
363
366 ADC0CN1 = ADC0CN1_ADCMBE__CM_BUFFER_ENABLED;
367 // [ADC0CN1 - ADC0 Control 1]$
368
369 // $[ADC0MX - ADC0 Multiplexer Selection]
370
373 ADC0MX = ADC0MX_ADC0MX__ADC0P11;
374 // [ADC0MX - ADC0 Multiplexer Selection]$
375
376 // $[ADC0CF - ADC0 Configuration]
377
383 ADC0CF = (0x06 << ADC0CF_ADSC__SHIFT) | ADC0CF_AD8BE__NORMAL
384 | ADC0CF_ADGN__GAIN_0P5 | ADC0CF_ADTM__TRACK_NORMAL;
385 // [ADC0CF - ADC0 Configuration]$
386
387 // $[ADC0AC - ADC0 Accumulator Configuration]
388
395 ADC0AC = ADC0AC_ADSJST__LEFT_NO_SHIFT | ADC0AC_AD12BE__12_BIT_DISABLED
396 | ADC0AC_ADAE__ACC_DISABLED | ADC0AC_ADRPT__ACC_1;
397 // [ADC0AC - ADC0 Accumulator Configuration]$
398
399 // $[ADC0TK - ADC0 Burst Mode Track Time]
400
405 ADC0TK = ADC0TK_AD12SM__SAMPLE_FOUR | (0x22 << ADC0TK_ADTK__SHIFT);
406 // [ADC0TK - ADC0 Burst Mode Track Time]$
407
408 // $[ADC0PWR - ADC0 Power Control]
409
415 ADC0PWR = (0x04 << ADC0PWR_ADPWR__SHIFT) | ADC0PWR_ADLPM__LP_BUFFER_ENABLED
416 | ADC0PWR_ADMXLP__LP_MUX_VREF_ENABLED | ADC0PWR_ADBIAS__MODE3;
417 // [ADC0PWR - ADC0 Power Control]$
418
419 // $[ADC0GTH - ADC0 Greater-Than High Byte]
420 // [ADC0GTH - ADC0 Greater-Than High Byte]$
421
422 // $[ADC0GTL - ADC0 Greater-Than Low Byte]
423 // [ADC0GTL - ADC0 Greater-Than Low Byte]$
424
425 // $[ADC0LTH - ADC0 Less-Than High Byte]
426 // [ADC0LTH - ADC0 Less-Than High Byte]$
427
428 // $[ADC0LTL - ADC0 Less-Than Low Byte]
429 // [ADC0LTL - ADC0 Less-Than Low Byte]$
430
431 // $[ADC0CN0 - ADC0 Control 0]
432
436 ADC0CN0 &= ~ADC0CN0_ADCM__FMASK;
437 ADC0CN0 |= ADC0CN0_ADBMEN__BURST_ENABLED | ADC0CN0_ADCM__TIMER2;
438 // [ADC0CN0 - ADC0 Control 0]$
439
440}
441
443{
444 // $[Timer Initialization]
445 // Save Timer Configuration
446 uint8_t TMR2CN0_TR2_save;
447 TMR2CN0_TR2_save = TMR2CN0 & TMR2CN0_TR2__BMASK;
448 // Stop Timer
449 TMR2CN0 &= ~(TMR2CN0_TR2__BMASK);
450 // [Timer Initialization]$
451
452 // $[TMR2CN0 - Timer 2 Control]
453 // [TMR2CN0 - Timer 2 Control]$
454
455 // $[TMR2H - Timer 2 High Byte]
456
459 TMR2H = (0xE7 << TMR2H_TMR2H__SHIFT);
460 // [TMR2H - Timer 2 High Byte]$
461
462 // $[TMR2L - Timer 2 Low Byte]
463
466 TMR2L = (0x14 << TMR2L_TMR2L__SHIFT);
467 // [TMR2L - Timer 2 Low Byte]$
468
469 // $[TMR2RLH - Timer 2 Reload High Byte]
470
473 TMR2RLH = (0xE7 << TMR2RLH_TMR2RLH__SHIFT);
474 // [TMR2RLH - Timer 2 Reload High Byte]$
475
476 // $[TMR2RLL - Timer 2 Reload Low Byte]
477
480 TMR2RLL = (0x14 << TMR2RLL_TMR2RLL__SHIFT);
481 // [TMR2RLL - Timer 2 Reload Low Byte]$
482
483 // $[TMR2CN0]
484
487 TMR2CN0 |= TMR2CN0_TR2__RUN;
488 // [TMR2CN0]$
489
490 // $[Timer Restoration]
491 // Restore Timer Configuration
492 TMR2CN0 |= TMR2CN0_TR2_save;
493 // [Timer Restoration]$
494
495}
496
498{
499 // $[P1 - Port 1 Pin Latch]
500 // [P1 - Port 1 Pin Latch]$
501
502 // $[P1MDOUT - Port 1 Output Mode]
503 // [P1MDOUT - Port 1 Output Mode]$
504
505 // $[P1MDIN - Port 1 Input Mode]
506
512 P1MDIN = P1MDIN_B0__DIGITAL | P1MDIN_B1__DIGITAL | P1MDIN_B2__DIGITAL
513 | P1MDIN_B3__ANALOG;
514 // [P1MDIN - Port 1 Input Mode]$
515
516 // $[P1SKIP - Port 1 Skip]
517
523 P1SKIP = P1SKIP_B0__NOT_SKIPPED | P1SKIP_B1__SKIPPED
524 | P1SKIP_B2__NOT_SKIPPED | P1SKIP_B3__SKIPPED;
525 // [P1SKIP - Port 1 Skip]$
526
527 // $[P1MASK - Port 1 Mask]
528 // [P1MASK - Port 1 Mask]$
529
530 // $[P1MAT - Port 1 Match]
531 // [P1MAT - Port 1 Match]$
532
533}
534
536{
537 // $[CMP1MX - Comparator 1 Multiplexer Selection]
538
542 uint8_t delay;
543
544 CMP1MX = CMP1MX_CMXP__LDO_OUT | CMP1MX_CMXN__CMP1N5;
545 // Delay to allow the comparator inputs to settle
546 for (delay = 0; delay < 0x20; delay++)
547 ;
548 // [CMP1MX - Comparator 1 Multiplexer Selection]$
549
550 // $[CMP1MD - Comparator 1 Mode]
551
554 CMP1MD |= CMP1MD_CPRIE__RISE_INT_ENABLED;
555 // [CMP1MD - Comparator 1 Mode]$
556
557 // $[CMP1CN0 - Comparator 1 Control 0]
558
563 CMP1CN0 &= ~CMP1CN0_CPHYP__FMASK;
564 CMP1CN0 |= CMP1CN0_CPEN__ENABLED | CMP1CN0_CPHYP__ENABLED_MODE1
565 | CMP1CN0_CPHYN__ENABLED_MODE3;
566 // [CMP1CN0 - Comparator 1 Control 0]$
567
568}
569
571{
572
573}
574
void enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:25
void PBCFG_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:163
void CLOCK_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:197
void CMP_1_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:535
void VREF_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:570
void PORTS_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:88
void WDT_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:43
void TIMER01_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:240
void TIMER16_2_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:442
void ADC_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:360
void TIMER_SETUP_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:279
void UART_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:349
void PORTS_1_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:497
void INTERRUPT_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:306
void CMP_0_enter_DefaultMode_from_RESET(void)
Definition InitDevice.c:209