scutimer: Modified the source code according to MISRAC 2012.

This patch modifies the code according to MISRAC 2012.

Signed-off-by: P L Sai Krishna <lakshmis@xilinx.com>
This commit is contained in:
P L Sai Krishna 2015-01-06 17:07:37 +05:30 committed by Nava kishore Manne
parent 58b9762523
commit 9c59617e3a
6 changed files with 66 additions and 57 deletions

View file

@ -80,9 +80,10 @@
* @note None. * @note None.
* *
******************************************************************************/ ******************************************************************************/
int XScuTimer_CfgInitialize(XScuTimer *InstancePtr, s32 XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
XScuTimer_Config *ConfigPtr, u32 EffectiveAddress) XScuTimer_Config *ConfigPtr, u32 EffectiveAddress)
{ {
s32 Status;
Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr != NULL);
Xil_AssertNonvoid(ConfigPtr != NULL); Xil_AssertNonvoid(ConfigPtr != NULL);
@ -92,29 +93,31 @@ int XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
* device and reinitialize, but prevents a user from inadvertently * device and reinitialize, but prevents a user from inadvertently
* initializing. * initializing.
*/ */
if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) { if (InstancePtr->IsStarted != XIL_COMPONENT_IS_STARTED) {
return XST_DEVICE_IS_STARTED; /*
* Copy configuration into the instance structure.
*/
InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
/*
* Save the base address pointer such that the registers of the block
* can be accessed and indicate it has not been started yet.
*/
InstancePtr->Config.BaseAddr = EffectiveAddress;
InstancePtr->IsStarted = (u32)0;
/*
* Indicate the instance is ready to use, successfully initialized.
*/
InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
Status =(s32)XST_SUCCESS;
} }
else {
/* Status = (s32)XST_DEVICE_IS_STARTED;
* Copy configuration into the instance structure. }
*/ return Status;
InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
/*
* Save the base address pointer such that the registers of the block
* can be accessed and indicate it has not been started yet.
*/
InstancePtr->Config.BaseAddr = EffectiveAddress;
InstancePtr->IsStarted = 0;
/*
* Indicate the instance is ready to use, successfully initialized.
*/
InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
return XST_SUCCESS;
} }
/****************************************************************************/ /****************************************************************************/
@ -187,7 +190,7 @@ void XScuTimer_Stop(XScuTimer *InstancePtr)
/* /*
* Clear the 'timer enable' bit in the register. * Clear the 'timer enable' bit in the register.
*/ */
Register &= ~XSCUTIMER_CONTROL_ENABLE_MASK; Register &= (u32)(~XSCUTIMER_CONTROL_ENABLE_MASK);
/* /*
* Update the Control register with the new value. * Update the Control register with the new value.
@ -198,7 +201,7 @@ void XScuTimer_Stop(XScuTimer *InstancePtr)
/* /*
* Indicate that the device is stopped. * Indicate that the device is stopped.
*/ */
InstancePtr->IsStarted = 0; InstancePtr->IsStarted = (u32)0;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -232,12 +235,12 @@ void XScuTimer_SetPrescaler(XScuTimer *InstancePtr, u8 PrescalerValue)
/* /*
* Clear all of the prescaler control bits in the register. * Clear all of the prescaler control bits in the register.
*/ */
ControlReg &= ~XSCUTIMER_CONTROL_PRESCALER_MASK; ControlReg &= (u32)(~XSCUTIMER_CONTROL_PRESCALER_MASK);
/* /*
* Set the prescaler value. * Set the prescaler value.
*/ */
ControlReg |= (PrescalerValue << XSCUTIMER_CONTROL_PRESCALER_SHIFT); ControlReg |= (((u32)PrescalerValue) << XSCUTIMER_CONTROL_PRESCALER_SHIFT);
/* /*
* Write the register with the new values. * Write the register with the new values.
@ -275,5 +278,5 @@ u8 XScuTimer_GetPrescaler(XScuTimer *InstancePtr)
XSCUTIMER_CONTROL_OFFSET); XSCUTIMER_CONTROL_OFFSET);
ControlReg &= XSCUTIMER_CONTROL_PRESCALER_MASK; ControlReg &= XSCUTIMER_CONTROL_PRESCALER_MASK;
return (ControlReg >> XSCUTIMER_CONTROL_PRESCALER_SHIFT); return (u8)(ControlReg >> XSCUTIMER_CONTROL_PRESCALER_SHIFT);
} }

View file

@ -176,7 +176,7 @@ typedef struct {
* *
******************************************************************************/ ******************************************************************************/
#define XScuTimer_RestartTimer(InstancePtr) \ #define XScuTimer_RestartTimer(InstancePtr) \
XScuTimer_LoadTimer(InstancePtr, \ XScuTimer_LoadTimer((InstancePtr), \
XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \ XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
XSCUTIMER_LOAD_OFFSET)) XSCUTIMER_LOAD_OFFSET))
@ -198,7 +198,7 @@ typedef struct {
******************************************************************************/ ******************************************************************************/
#define XScuTimer_LoadTimer(InstancePtr, Value) \ #define XScuTimer_LoadTimer(InstancePtr, Value) \
XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \ XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
XSCUTIMER_LOAD_OFFSET, Value) XSCUTIMER_LOAD_OFFSET, (Value))
/****************************************************************************/ /****************************************************************************/
/** /**
@ -342,12 +342,12 @@ XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId);
/* /*
* Selftest function in xscutimer_selftest.c * Selftest function in xscutimer_selftest.c
*/ */
int XScuTimer_SelfTest(XScuTimer *InstancePtr); s32 XScuTimer_SelfTest(XScuTimer *InstancePtr);
/* /*
* Interface functions in xscutimer.c * Interface functions in xscutimer.c
*/ */
int XScuTimer_CfgInitialize(XScuTimer *InstancePtr, s32 XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
XScuTimer_Config *ConfigPtr, u32 EffectiveAddress); XScuTimer_Config *ConfigPtr, u32 EffectiveAddress);
void XScuTimer_Start(XScuTimer *InstancePtr); void XScuTimer_Start(XScuTimer *InstancePtr);
void XScuTimer_Stop(XScuTimer *InstancePtr); void XScuTimer_Stop(XScuTimer *InstancePtr);

View file

@ -68,7 +68,7 @@
*/ */
XScuTimer_Config XScuTimer_ConfigTable[XPAR_XSCUTIMER_NUM_INSTANCES] = { XScuTimer_Config XScuTimer_ConfigTable[XPAR_XSCUTIMER_NUM_INSTANCES] = {
{ {
XPAR_XSCUTIMER_0_DEVICE_ID, (u16)XPAR_XSCUTIMER_0_DEVICE_ID,
XPAR_XSCUTIMER_0_BASEADDR (u32)XPAR_XSCUTIMER_0_BASEADDR
} }
}; };

View file

@ -69,10 +69,10 @@ extern "C" {
* @{ * @{
*/ */
#define XSCUTIMER_LOAD_OFFSET 0x00 /**< Timer Load Register */ #define XSCUTIMER_LOAD_OFFSET 0x00U /**< Timer Load Register */
#define XSCUTIMER_COUNTER_OFFSET 0x04 /**< Timer Counter Register */ #define XSCUTIMER_COUNTER_OFFSET 0x04U /**< Timer Counter Register */
#define XSCUTIMER_CONTROL_OFFSET 0x08 /**< Timer Control Register */ #define XSCUTIMER_CONTROL_OFFSET 0x08U /**< Timer Control Register */
#define XSCUTIMER_ISR_OFFSET 0x0C /**< Timer Interrupt #define XSCUTIMER_ISR_OFFSET 0x0CU /**< Timer Interrupt
Status Register */ Status Register */
/* @} */ /* @} */
@ -82,11 +82,11 @@ extern "C" {
* @{ * @{
*/ */
#define XSCUTIMER_CONTROL_PRESCALER_MASK 0x0000FF00 /**< Prescaler */ #define XSCUTIMER_CONTROL_PRESCALER_MASK 0x0000FF00U /**< Prescaler */
#define XSCUTIMER_CONTROL_PRESCALER_SHIFT 8 #define XSCUTIMER_CONTROL_PRESCALER_SHIFT 8U
#define XSCUTIMER_CONTROL_IRQ_ENABLE_MASK 0x00000004 /**< Intr enable */ #define XSCUTIMER_CONTROL_IRQ_ENABLE_MASK 0x00000004U /**< Intr enable */
#define XSCUTIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002 /**< Auto-reload */ #define XSCUTIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002U /**< Auto-reload */
#define XSCUTIMER_CONTROL_ENABLE_MASK 0x00000001 /**< Timer enable */ #define XSCUTIMER_CONTROL_ENABLE_MASK 0x00000001U /**< Timer enable */
/* @} */ /* @} */
/** @name Interrupt Status register /** @name Interrupt Status register
@ -94,7 +94,7 @@ extern "C" {
* @{ * @{
*/ */
#define XSCUTIMER_ISR_EVENT_FLAG_MASK 0x00000001 /**< Event flag */ #define XSCUTIMER_ISR_EVENT_FLAG_MASK 0x00000001U /**< Event flag */
/*@}*/ /*@}*/
/**************************** Type Definitions *******************************/ /**************************** Type Definitions *******************************/
@ -118,7 +118,7 @@ extern "C" {
* *
******************************************************************************/ ******************************************************************************/
#define XScuTimer_SetLoadReg(BaseAddr, Value) \ #define XScuTimer_SetLoadReg(BaseAddr, Value) \
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_LOAD_OFFSET, Value) XScuTimer_WriteReg(BaseAddr, XSCUTIMER_LOAD_OFFSET, (Value))
/****************************************************************************/ /****************************************************************************/
/** /**
@ -151,7 +151,7 @@ extern "C" {
* *
******************************************************************************/ ******************************************************************************/
#define XScuTimer_SetCounterReg(BaseAddr, Value) \ #define XScuTimer_SetCounterReg(BaseAddr, Value) \
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_COUNTER_OFFSET, Value) XScuTimer_WriteReg(BaseAddr, XSCUTIMER_COUNTER_OFFSET, (Value))
/****************************************************************************/ /****************************************************************************/
/** /**
@ -186,7 +186,7 @@ extern "C" {
* *
******************************************************************************/ ******************************************************************************/
#define XScuTimer_SetControlReg(BaseAddr, Value) \ #define XScuTimer_SetControlReg(BaseAddr, Value) \
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_CONTROL_OFFSET, Value) XScuTimer_WriteReg(BaseAddr, XSCUTIMER_CONTROL_OFFSET, (Value))
/****************************************************************************/ /****************************************************************************/
/** /**
@ -219,7 +219,7 @@ extern "C" {
* *
******************************************************************************/ ******************************************************************************/
#define XScuTimer_SetIntrReg(BaseAddr, Value) \ #define XScuTimer_SetIntrReg(BaseAddr, Value) \
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_ISR_OFFSET, Value) XScuTimer_WriteReg(BaseAddr, XSCUTIMER_ISR_OFFSET, (Value))
/****************************************************************************/ /****************************************************************************/
/** /**

View file

@ -52,7 +52,7 @@
/************************** Constant Definitions *****************************/ /************************** Constant Definitions *****************************/
#define XSCUTIMER_SELFTEST_VALUE 0xA55AF00F #define XSCUTIMER_SELFTEST_VALUE 0xA55AF00FU
/**************************** Type Definitions *******************************/ /**************************** Type Definitions *******************************/
@ -79,11 +79,12 @@
* @note None. * @note None.
* *
******************************************************************************/ ******************************************************************************/
int XScuTimer_SelfTest(XScuTimer *InstancePtr) s32 XScuTimer_SelfTest(XScuTimer *InstancePtr)
{ {
u32 Register; u32 Register;
u32 CtrlOrig; u32 CtrlOrig;
u32 LoadOrig; u32 LoadOrig;
s32 Status;
/* /*
* Assert to ensure the inputs are valid and the instance has been * Assert to ensure the inputs are valid and the instance has been
@ -97,7 +98,7 @@ int XScuTimer_SelfTest(XScuTimer *InstancePtr)
*/ */
CtrlOrig = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr, CtrlOrig = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr,
XSCUTIMER_CONTROL_OFFSET); XSCUTIMER_CONTROL_OFFSET);
Register = CtrlOrig & ~XSCUTIMER_CONTROL_ENABLE_MASK; Register = CtrlOrig & (u32)(~XSCUTIMER_CONTROL_ENABLE_MASK);
XScuTimer_WriteReg(InstancePtr->Config.BaseAddr, XScuTimer_WriteReg(InstancePtr->Config.BaseAddr,
XSCUTIMER_CONTROL_OFFSET, Register); XSCUTIMER_CONTROL_OFFSET, Register);
@ -124,8 +125,11 @@ int XScuTimer_SelfTest(XScuTimer *InstancePtr)
* match with the value written to it. * match with the value written to it.
*/ */
if (Register != XSCUTIMER_SELFTEST_VALUE) { if (Register != XSCUTIMER_SELFTEST_VALUE) {
return XST_FAILURE; Status = (s32)XST_FAILURE;
}
else {
Status = (s32)XST_SUCCESS;
} }
return XST_SUCCESS; return Status;
} }

View file

@ -58,6 +58,9 @@
/***************** Macros (Inline Functions) Definitions *********************/ /***************** Macros (Inline Functions) Definitions *********************/
/************************** Variable Definitions ****************************/
extern XScuTimer_Config XScuTimer_ConfigTable[XPAR_XSCUTIMER_NUM_INSTANCES];
/************************** Function Prototypes ******************************/ /************************** Function Prototypes ******************************/
/*****************************************************************************/ /*****************************************************************************/
@ -75,16 +78,15 @@
******************************************************************************/ ******************************************************************************/
XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId) XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId)
{ {
extern XScuTimer_Config XScuTimer_ConfigTable[];
XScuTimer_Config *CfgPtr = NULL; XScuTimer_Config *CfgPtr = NULL;
int Index; u32 Index;
for (Index = 0; Index < XPAR_XSCUTIMER_NUM_INSTANCES; Index++) { for (Index = 0U; Index < XPAR_XSCUTIMER_NUM_INSTANCES; Index++) {
if (XScuTimer_ConfigTable[Index].DeviceId == DeviceId) { if (XScuTimer_ConfigTable[Index].DeviceId == DeviceId) {
CfgPtr = &XScuTimer_ConfigTable[Index]; CfgPtr = &XScuTimer_ConfigTable[Index];
break; break;
} }
} }
return (CfgPtr); return (XScuTimer_Config *)CfgPtr;
} }