1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
16 #include "mpc55xx.h"
\r
21 static const Wdg_ConfigType *configWdgPtr;
\r
22 static const Wdg_SettingsType *modeWdgConfig;
\r
26 void StartWatchdog(void)
\r
28 #if defined(CFG_MPC5567)
\r
29 ECSM.SWTCR.R = 0x00D8;;
\r
30 #elif defined(CFG_MPC560X) || defined(CFG_MPC5668)
\r
31 SWT.CR.R = 0x8000011B;
\r
33 MCM.SWTCR.R = 0x00D8;
\r
38 void StopWatchdog(void)
\r
40 #if defined(CFG_MPC5567)
\r
41 ECSM.SWTCR.R = 0x0059;;
\r
42 #elif defined(CFG_MPC560X) || defined(CFG_MPC5668)
\r
43 SWT.SR.R = 0x0000c520; /* Write keys to clear soft lock bit */
\r
44 SWT.SR.R = 0x0000d928;
\r
45 SWT.CR.R = 0x8000010A;
\r
47 MCM.SWTCR.R = 0x0059;
\r
51 void Wdg_Init (const Wdg_ConfigType* ConfigPtr)
\r
53 /* Keep a pointer to the config. */
\r
54 configWdgPtr = ConfigPtr;
\r
56 Wdg_SetMode(ConfigPtr->Wdg_ModeConfig->Wdg_DefaultMode);
\r
59 Std_ReturnType Wdg_SetMode (WdgIf_ModeType Mode)
\r
61 Std_ReturnType res = E_NOT_OK;
\r
64 case WDGIF_OFF_MODE:
\r
65 modeWdgConfig = &configWdgPtr->Wdg_ModeConfig->WdgSettingsOff;
\r
67 case WDGIF_FAST_MODE:
\r
68 modeWdgConfig = &configWdgPtr->Wdg_ModeConfig->WdgSettingsFast;
\r
70 case WDGIF_SLOW_MODE:
\r
71 modeWdgConfig = &(configWdgPtr->Wdg_ModeConfig->WdgSettingsSlow);
\r
77 if (modeWdgConfig != 0)
\r
79 /* Enable watchdog if config tell us to.. */
\r
80 if (modeWdgConfig->ActivationBit)
\r
82 #if defined(CFG_MPC560X)
\r
83 StopWatchdog(); // must be stopped in order to change TO
\r
84 SWT.TO.R = modeWdgConfig->ReloadValue;
\r
99 /* This function services the internal Watchdog timer */
\r
100 void Wdg_Trigger (void)
\r
106 // According to MPC55xx manual:
\r
107 // To prevent the watchdog timer from interrupting or resetting
\r
108 // the SWTSR must be serviced by performing the following sequence:
\r
109 // 1. Write 0x55 to the SWTSR.
\r
110 // 2. Write 0xAA to the SWTSR.
\r
111 #if defined(CFG_MPC5567)
\r
112 ECSM.SWTSR.R = 0x55;
\r
113 ECSM.SWTSR.R = 0xAA;
\r
114 #elif defined(CFG_MPC560X)
\r
115 SWT.SR.R = 0x0000A602;
\r
116 SWT.SR.R = 0x0000B480;
\r
118 MCM.SWTSR.R = 0x55;
\r
119 MCM.SWTSR.R = 0xAA;
\r
122 Irq_Restore(state);
\r