#include "device.h"
#include "driverlib.h"
#include <inc/hw_ipc.h>
#include "usblib/usbd.h"
#ifdef _FLASH
#include <stddef.h>
extern uint16_t RamfuncsLoadStart;
extern uint16_t RamfuncsLoadEnd;
extern uint16_t RamfuncsLoadSize;
extern uint16_t RamfuncsRunStart;
extern uint16_t RamfuncsRunEnd;
extern uint16_t RamfuncsRunSize;
#define DEVICE_FLASH_WAITSTATES 3
#endif
namespace Device{
// Function to initialize the device. Primarily initializes system control to a
// known state by disabling the watchdog, setting up the SYSCLKOUT frequency,
// and enabling the clocks to the peripherals.
void init() {
SysCtl_disableWatchdog();
#ifdef _FLASH
// Copy time critical code and flash setup code to RAM. This includes the
// following functions: InitFlash();
// The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart symbols
// are created by the linker. Refer to the device .cmd file.
std::memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
// Call Flash Initialization to setup flash waitstates. This function must
// reside in RAM.
Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, DEVICE_FLASH_WAITSTATES);
#endif
#ifdef CPU1
// Set up PLL control and clock dividers
// Define to pass to SysCtl_setClock(). Will configure the clock as follows:
// PLLSYSCLK = 10MHz (XTAL_OSC) * 40 (IMULT) * 1 (FMULT) / 2 (PLLCLK_BY_2)
const uint32_t DEVICE_SETCLOCK_CFG =
SYSCTL_OSCSRC_XTAL | SYSCTL_IMULT(40) |
SYSCTL_FMULT_NONE | SYSCTL_SYSDIV(2) |
SYSCTL_PLL_ENABLE;
SysCtl_setClock(DEVICE_SETCLOCK_CFG);
// Make sure the LSPCLK divider is set to the default (divide by 4)
SysCtl_setLowSpeedClock(SYSCTL_LSPCLK_PRESCALE_4);
// ASSERT(SysCtl_getClock(DEVICE_OSCSRC_FREQ) == DEVICE_SYSCLK_FREQ);
// ASSERT(SysCtl_getLowSpeedClock(DEVICE_OSCSRC_FREQ) == DEVICE_LSPCLK_FREQ);
#ifndef _FLASH
// Call Device_cal function when run using debugger
// This function is called as part of the Boot code. The function is called
// in the Device_init function since during debug time resets, the boot code
// will not be executed and the gel script will reinitialize all the
// registers and the calibrated values will be lost.
// Sysctl_deviceCal is a wrapper function for Device_Cal
SysCtl_deviceCal();
#endif
#endif
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_DMA);
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_USBA);
}
}
// Error handling function to be called when an ASSERT is violated
// Must have C linkage, called by usb.lib
extern "C" void __error__(const char*filename, uint32_t line, const char*reason) {
// An ASSERT condition was evaluated as false. You can use the filename and
// line parameters to determine what went wrong.
ESTOP0;
}
//! Configure the CPU Timer.
void CPUTimerInit() {
// Initialize timer period to maximum.
CPUTimer_setPeriod(CPUTIMER0_BASE,0xFFFFFFFF);
// Initialize Pre-scale counter to divide by 1.
CPUTimer_setPreScaler(CPUTIMER0_BASE, 0U);
// Make sure timer is stopped.
CPUTimer_stopTimer(CPUTIMER0_BASE);
// Reload all counter register with period value:
CPUTimer_reloadTimerCounter(CPUTIMER0_BASE);
}
namespace usb{
void GPIOEnable() { // Set the USB DM and DP.
GPIO_setMasterCore(42, GPIO_CORE_CPU1);
GPIO_setAnalogMode(42, GPIO_ANALOG_ENABLED);
GPIO_setMasterCore(43, GPIO_CORE_CPU1);
GPIO_setAnalogMode(43, GPIO_ANALOG_ENABLED);
}
//__interrupt void DeviceIntHandler() {
// tDevice::USB0DeviceIntHandler();
// Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
//}
}
Detected encoding: UTF-8 | 0
|