/*
 * Copyright 2019-2020 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

FUNC void restoreFlexRAM(void)
{
    unsigned int value;

    value = _RDWORD(0x400E4044);
    value &= ~(0xFFFF);
    value |= 0xFFAA;
    _WDWORD(0x400E4044, value);

    value = _RDWORD(0x400E4048);
    value &= ~(0xFFFF);
    value |= 0xFFAA;
    _WDWORD(0x400E4048, value);

    value = _RDWORD(0x400E4040);
    value &= ~(0xFF << 8);
    value |= 0x7 | (0xAA << 8);
    _WDWORD(0x400E4040, value);
}

FUNC void Setup (void) {
  SP = _RDWORD(0x00000000);          // Setup Stack Pointer
  PC = _RDWORD(0x00000004);          // Setup Program Counter
  _WDWORD(0xE000ED08, 0x00000000);   // Setup Vector Table Offset Register
}

FUNC void OnResetExec (void)  {      // executes upon software RESET
  Setup();                           // Setup for Running
}

restoreFlexRAM();

LOAD %L INCREMENTAL                  // Download

Setup();
//g, main
