📄 wdogav.c
字号:
/************************************************************************** * * Copyright (c) 2005 Curtiss-Wright Controls, Inc. All rights * reserved. This Source Code is the Property of Curtiss-Wright * Controls, Inc. and can only be used in accordance with Source * Code License Agreement(s) of Curtiss-Wright Controls, Inc. or any * of its subsidiaries. * **************************************************************************//****************************************************************************** Filename : wDogAv.c * Author : Melanie Babin* Created : May 27, 2004** Description: Dy 4 SVME/DMV-182/183/CCA145 Avionics Watchdog driver * for vxWorks.* The target VME card provides programmable 24-bit Watchdog Timers.* The resolution of a timer is 1us. The watchdogs are configured by* jumpers to generate either a hardware reset or an interrupt request* when terminal count is reached.* It is possible to update the watchdog minimum and maximum timeout* values at any time when the watchdog is not locked.** History: ** 01a,27may04,mb created, PT: 1444* 02a,07sep04,mb PT 2154: fixed wDogAvJmprChk logic * 02b,08sep04,mb PT 2156: modified wDogAvShow to display* correct minimum timeout value* Added wDogMinMaxSet boolean variable* 02c,nov04,jb updated for CCA-145* 02d,10jan05,rcd ported to VME-183.* 02e,10apr05,aak get rid of local variables min\maxValue (CR#2673)* 02f,09may05,tis add support for CCA-146* 03a,22sep05,asu removed extra bracket in CCA-146 define, Task#9784* 03b,28sep05 asu -added support for CCA-149.* 03c,18oct05,rsr CR3242, added semaphore to wDogAvInit/MinMaxSet/Get functions* to ensure data does not become corrupted by another task* 03d,08nov05,tis merged v12 with v9.1.3 and removed all refrences to DEVROM_DEBUG**//*DESCRIPTIONThis module contains the avionics watchdog driver routines.FEATURESDRIVER INITIALIZATIONThe following are the steps to be taken in order to use the driver:1) In config.h define INCLUDE_WDOG_AV (MANDATORY)2) Call wDogAvInit (MANDATORY) 3) Call wDogAvMinMaxSet (OPTIONAL - can use defaults instead)4) Call wDogAvStart (MANDATORY)5) Call wDogAvLock (OPTIONAL)6) Call wDogAvKick (MANDATORY - called whenever necessary)7) Call wDogAvShow (OPTIONAL - show routine)8) Call wDogAvMin or wDogAvMaxGet (OPTIONAL)USER CALLABLE ROUTINESThis driver provides the following functions:1) wDogAvInit: Sets the register pointer, initializes all variables performs a jumper check, and installs an interrupt service routine.2) wDogAvStart: Checks the mode and enables interrupts or sets the reset bit in watchdog registers to effectively "start" handling of watchdog events.3) wDogAvLock: Allows the user to lock the watchdog registers. Locking the registers will render them inaccessible until a cold reboot.4) wDogAvKick: Writes to a specific kick location which resets the Watchdog. 5) wDogAvMinMaxSet: Allows the user to set the minimum and maximum timeout values for the watchdog.6) wDogAvMinGet: Retrieves the minimum timeout value.7) wDogAvMaxGet: Retrieves the maximum timeout value. 8) wDogAvShow: - Displays the addresses of the watchdog registers - Displays the contents of the minimum and maximum timeout registers - Shows the status of wDogInitialized, wDogLocked, wDogJmprInstalled, wDogIntEnabled, wDogIntConnected, wDogMode*//* * includes */#include "vxWorks.h"#include "semLib.h" #include "h/drv/timer/wDogAv.h"/* * Defines */#define WDOG_MASK_BITS_7_0 0x000000ff#define WDOG_MASK_BITS_15_8 0x0000ff00#define WDOG_MASK_BITS_23_16 0x00ff0000#if (defined(CCA_145) || defined(CCA_146) || defined(CCA_149)|| defined(VME_183))#define WDOG_INT_CLEAR_VALUE 0x01#define WDOG_INT_MSK_VALUE 0x01#define WDOG_ENBL_VALUE 0x08#define WDOG_RESET_ENBL_VALUE 0x01#endif#define WDOG_KICK_VALUE 0xff#define WDOG_DEFAULT_MIN 0x000000#define WDOG_DEFAULT_MAX 0x001000/* * Local Variables */ LOCAL BOOL wDogInitialized = FALSE;LOCAL BOOL wDogLocked;LOCAL STATUS wDogIntEnabled;LOCAL STATUS wDogIntConnected;LOCAL STATUS wDogMinMaxSet = FALSE;LOCAL SEM_ID wDogSemId;#if (defined(CCA_145)|| defined(CCA_146) || defined(CCA_149) || defined(VME_183))LOCAL BOOL wDogEnabled;LOCAL BOOL wDogCPU0IntMasked;LOCAL BOOL wDogCPU1IntMasked;#endif#if !(defined(CCA_145)|| defined(CCA_146) || defined(CCA_149) || defined(VME_183))LOCAL BOOL wDogJmprInstalled;#endifLOCAL BOOL wDogDebug = FALSE;LOCAL UINT8 *wDogAdrs;LOCAL int wDogInterrupt;LOCAL int wDogMode;/************************************************************ Function Name : wDogAvJmprChk** Description :* Check for jumper * 1 - jumper not installed, watchdog disabled -send error* 0 - jumper installed, watchdog enabled -proceed*** Arguments :* void** Return Value :* BOOL - TRUE if jumper is installed.* - FALSE if jumper is not installed** Comments:* N/A* NOMANUAL*/#if !(defined(CCA_145)|| defined(CCA_146) || defined(CCA_149)|| defined(VME_183))LOCAL BOOL wDogAvJmprChk(void){ UINT8 *pAddress = wDogAdrs; int jmprAdrs = *pAddress & WDOG_JMPR_OFFSET; if( WDOG_JMPR_OFFSET == jmprAdrs ) { if(wDogDebug) { logMsg("Jumper is installed, watchdog is disabled.\n" "Please install the jumper.\n\n",0,0,0,0,0,0); } return TRUE; } else { if(wDogDebug) { logMsg("Jumper is not installed, watchdog is enabled.\n\n" ,0,0,0,0,0,0); } return FALSE; }}#endif/************************************************************ Function Name : wDogAvLock* Description :* Locks the watchdog timer registers* 1 - registers all locked* 0 - registers are all R/W*** Arguments :* void** Return Value :* STATUS - OK if watchdog has been locked.* - ERROR if watchdog has not been initialized** Comments:* Locking the registers will render them inaccessible* until a cold reboot.**/STATUS wDogAvLock(void){ UINT8 *pAddress = wDogAdrs; UINT8 *pCtrlAdrs; if (wDogInitialized) { pCtrlAdrs = pAddress + IOFPGA_WD_CONTROL; *pCtrlAdrs |= WDOG_LOCK_OFFSET; IO_SYNC; wDogLocked = TRUE; if(wDogDebug) { logMsg("Watchdog has been Locked.\n" ,0,0,0,0,0,0); } return OK; } else { if(wDogDebug) { logMsg("Watchdog has not been Locked.\n" ,0,0,0,0,0,0); } return ERROR; }}/************************************************************ Function Name : wDogAvMinMaxSet* Description :* Sets the minimum and maximum timeout registers.*** Arguments :* int minVal* int maxVal** Return Value :* STATUS - OK if the minimum and maximum timeout * values were set.* - ERROR if the watchdog has not been initialized* if the watchdog has been locked* if the minimum and maximum values are* incorrect** Comments:* N/A**/STATUS wDogAvMinMaxSet(int minVal,int maxVal){ UINT8 *pAddress = wDogAdrs; UINT8 *pMaxValAdrs, *pMinValAdrs; int maxTemp, minTemp,maximumValue,minimumValue;#if (defined(CCA_145) || defined(CCA_146) || defined(CCA_149)|| defined(VME_183)) BOOL wasEnabled = wDogEnabled; #endif if(wDogInitialized && !wDogLocked) { if(minVal < WDOG_MIN_BOUNDARY || maxVal > WDOG_MAX_BOUNDARY || minVal > maxVal) { /* minVal == maxVal is valid */ if(wDogDebug) { logMsg("Minimum and Maximum values are incorrect.\n" ,0,0,0,0,0,0); } return ERROR; } else { maximumValue = maxVal;#if !(defined(CCA_145)|| defined(CCA_146) || defined(CCA_149)|| defined(VME_183)) minimumValue = maxVal - minVal; /* for 182 */#else minimumValue = minVal; /* for 145 or 183 */#endif /* Before altering the value in this register the watchdog must be in the disabled state */#if (defined(CCA_145) || defined(CCA_146) || defined(CCA_149)|| defined(VME_183)) if (wDogEnabled) wDogDisable();#endif /* use mutex semaphore to ensure only one taks will access the ports otherwise corruption of data could result because a higher priority task stepped in and wrote its data while the other task was reading or writing its data */ if(NULL != wDogSemId) { if(OK == semTake(wDogSemId, WAIT_FOREVER)) { } else /* error occurred in taking of semaphore */ { return ERROR; } } /* The 24-bit field permits any value between 0 and 16.7 seconds, with a granularity of 1us */ pMaxValAdrs = pAddress + IOFPGA_WD_MAX_TIMEOUT_7_0; maxTemp = (WDOG_MASK_BITS_7_0 & maximumValue); *pMaxValAdrs = (UINT8)maxTemp; pMaxValAdrs = pAddress + IOFPGA_WD_MAX_TIMEOUT_15_8; maxTemp = (WDOG_MASK_BITS_15_8 & maximumValue)>>8; *pMaxValAdrs = (UINT8)maxTemp; pMaxValAdrs = pAddress + IOFPGA_WD_MAX_TIMEOUT_23_16; maxTemp = (WDOG_MASK_BITS_23_16 & maximumValue)>>16; *pMaxValAdrs = (UINT8)maxTemp; pMinValAdrs = pAddress + IOFPGA_WD_MIN_TIMEOUT_7_0; minTemp = (WDOG_MASK_BITS_7_0 & minimumValue); *pMinValAdrs = (UINT8)minTemp; pMinValAdrs = pAddress + IOFPGA_WD_MIN_TIMEOUT_15_8; minTemp = (WDOG_MASK_BITS_15_8 & minimumValue)>>8; *pMinValAdrs = (UINT8)minTemp; pMinValAdrs = pAddress + IOFPGA_WD_MIN_TIMEOUT_23_16; minTemp = (WDOG_MASK_BITS_23_16 & minimumValue)>>16; *pMinValAdrs = (UINT8)minTemp; IO_SYNC; if(NULL != wDogSemId) { semGive(wDogSemId); }#if (defined(CCA_145) || defined(CCA_146) || defined(CCA_149)|| defined(VME_183)) /* Put back watchdog original state */ if (wasEnabled) wDogEnable();#endif if(wDogDebug) { logMsg("Minimum and Maximum values are correct.\n" ,0,0,0,0,0,0); } wDogMinMaxSet = TRUE; return OK; } } else { if(wDogDebug) { logMsg("Watchdog might not be initialized or might be locked.\n" ,0,0,0,0,0,0); } return ERROR; }} /************************************************************ Function Name : wDogAvMinGet* Description :* Retrieves the current minimum timeout value*** Arguments :* void** Return Value :* int - minimum timeout value or ERROR if the watchdog* has not been initialized** Comments:* N/A*/int wDogAvMinGet(void){ UINT32 localMinimumValue = 0; UINT8 *pMinValAdrs; UINT8 *pAddress = wDogAdrs; if(wDogInitialized) { if(NULL != wDogSemId) { if(OK == semTake(wDogSemId, WAIT_FOREVER)) { } else { return ERROR; } } pMinValAdrs = pAddress + IOFPGA_WD_MIN_TIMEOUT_7_0; localMinimumValue = (UINT8)*pMinValAdrs; pMinValAdrs = pAddress + IOFPGA_WD_MIN_TIMEOUT_15_8; localMinimumValue |= (UINT8)(*pMinValAdrs)<<8; pMinValAdrs = pAddress + IOFPGA_WD_MIN_TIMEOUT_23_16; localMinimumValue |= (UINT8)(*pMinValAdrs)<<16; IO_SYNC; if(NULL != wDogSemId) { semGive(wDogSemId); } if(wDogDebug) printf("Minimum Value: 0x%.6x \n",localMinimumValue); return localMinimumValue; } else { if(wDogDebug) { printf("Watchdog has not been initialized.\n"); } return ERROR; }}/************************************************************ Function Name : wDogAvMaxGet* Description :* Retrieves the current maximum timeout value*** Arguments :* void** Return Value :* int - maximum timeout value or ERROR if the watchdog* has not been initialized** Comments:* N/A*/int wDogAvMaxGet(void){ UINT32 localMaximumValue = 0; UINT8 *pMaxValAdrs; UINT8 *pAddress = wDogAdrs; if(wDogInitialized) { if(NULL != wDogSemId) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -