summaryrefslogtreecommitdiffstats
path: root/hal/hwconfig.cpp
blob: f443f596421b0f24cfded3789f39e4c1537cebac (plain)
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
/* 
 * File:   hwconfig.cpp
 * Author: naopross
 */

#include "hwconfig.hpp"

extern "C" {
#include <xc.h>
}

void hw::reglock()
{
    SYSKEY = 0x00000000; 
}

void hw::regunlock()
{
    SYSKEY = 0x12345678;
    SYSKEY = 0xAA996655;
    SYSKEY = 0x556699AA;
}

void osc::initialize()
{
    hw::regunlock(); 
    // CF no clock failure; COSC FRCDIV; PLLODIV DIV_256; UFRCEN disabled; PBDIVRDY disabled; SLOCK out of lock; FRCDIV FRC/1; SLPEN Idle on WAIT instruction; NOSC FRCDIV; PLLMULT MUL_24; SOSCEN disabled; PBDIV DIV_8; CLKLOCK unlocked; OSWEN Switch is Complete; SOSCRDY disabled; 
    OSCCON = 0x381F7700;
    hw::reglock();
    // TUN Center Frequency; 
    OSCTUN = 0x0;
    // DIVSWEN disabled; RSLP disabled; ACTIVE Active; ROSEL SYSCLK; OE Not Driven out on REFCLKO pin; SIDL disabled; RODIV 0; ON disabled; 
    REFOCON = 0x100;
    // ROTRIM 0; 
    REFOTRIM = 0x0;
}

void interrupts::initialize()
{
    //  Enable the multi vector
    INTCONbits.MVEC = 1;
    //  Enable Global Interrupts 
    __builtin_mtc0(12,0,(__builtin_mfc0(12,0) | 0x0001));
}