Пример #1
0
EXPORT void Can_Hw_DisableControllerInterrupts(uint8 controller)
{
	  imask_t state;
	  Can_UnitType *canUnit;
	  CAN_HW_t *canHw;

	  canUnit = CAN_GET_PRIVATE_DATA(controller);

	  VALIDATE_NO_RV( (canUnit->state!=CANIF_CS_UNINIT), 0x4, CAN_E_UNINIT );

	  Irq_Save(state);
	  if(canUnit->lock_cnt > 0 )
	  {
	    // Interrupts already disabled
	    canUnit->lock_cnt++;
	    Irq_Restore(state);
	    return;
	  }
	  canUnit->lock_cnt++;
	  Irq_Restore(state);

	  /* Don't try to be intelligent, turn everything off */
	  canHw = GetController(controller);

	  /* Turn off the tx interrupt mailboxes */
	   CAN_ITConfig(canHw, CAN_IT_TME, DISABLE);

	   /* Turn off the bus off/tx warning/rx warning and error and rx  */
	   CAN_ITConfig(canHw, CAN_IT_FMP0 | CAN_IT_BOF | CAN_IT_ERR | CAN_IT_WKU, DISABLE);
}
Пример #2
0
//lint -esym(904, Com_RxIndication) //PC-Lint Exception of rule 14.7
void Com_RxIndication(PduIdType ComRxPduId, const PduInfoType* PduInfoPtr) {
	PDU_ID_CHECK_NO_RETURN(ComRxPduId, 0x14);

	const ComIPdu_type *IPdu = GET_IPdu(ComRxPduId);
	Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(ComRxPduId);
	imask_t state;
	Irq_Save(state);

	// If Ipdu is stopped
	if (!Arc_IPdu->Com_Arc_IpduStarted) {
		Irq_Restore(state);
		return;
	}

	// Check callout status
	if (IPdu->ComIPduCallout != NULL) {
		if (!IPdu->ComIPduCallout(ComRxPduId, PduInfoPtr->SduDataPtr)) {
			// TODO Report error to DET.
			// Det_ReportError();
			Irq_Restore(state);
			return;
		}
	}

	// Copy IPDU data
	memcpy(IPdu->ComIPduDataPtr, PduInfoPtr->SduDataPtr, IPdu->ComIPduSize);

	Com_RxProcessSignals(IPdu,Arc_IPdu);

	Irq_Restore(state);

	return;
}
Пример #3
0
void Com_TpRxIndication(PduIdType PduId, NotifResultType Result) {
	PDU_ID_CHECK_NO_RETURN(PduId, 0x14);

	const ComIPdu_type *IPdu = GET_IPdu(PduId);
	Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(PduId);
	imask_t state;

	Irq_Save(state);

	// If Ipdu is stopped
	if (!Arc_IPdu->Com_Arc_IpduStarted) {
		UnlockTpBuffer(getPduId(IPdu));
		Irq_Restore(state);
		return;
	}
	if (Result == NTFRSLT_OK) {
		if (IPdu->ComIPduSignalProcessing == IMMEDIATE) {
			// irqs needs to be disabled until signal notifications have been called
			// Otherwise a new Tp session can start and fill up pdus
			UnlockTpBuffer(getPduId(IPdu));
		}
		// In deferred mode, buffers are unlocked in mainfunction
		Com_RxProcessSignals(IPdu,Arc_IPdu);
	} else {
		UnlockTpBuffer(getPduId(IPdu));
	}
	Irq_Restore(state);

}
Пример #4
0
Std_ReturnType Com_Internal_TriggerIPduSend(PduIdType ComTxPduId) {
	PDU_ID_CHECK(ComTxPduId, 0x17, E_NOT_OK);

#if PDUR_COM_SUPPORT == STD_OFF
	return E_NOT_OK;
#else
	const ComIPdu_type *IPdu = GET_IPdu(ComTxPduId);
	Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(ComTxPduId);
    imask_t state;
    Irq_Save(state);

    if( isPduBufferLocked(ComTxPduId) ) {
    	return E_NOT_OK;
    }

	// Is the IPdu ready for transmission?
	if (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer == 0 && Arc_IPdu->Com_Arc_IpduStarted) {

        //lint --e(725)	Suppress PC-Lint warning "Expected positive indentation...". What means?
		// Check callout status
		if (IPdu->ComIPduCallout != NULL) {
			if (!IPdu->ComIPduCallout(ComTxPduId, IPdu->ComIPduDataPtr)) {
				// TODO Report error to DET.
				// Det_ReportError();
			    Irq_Restore(state);
				return E_NOT_OK;
			}
		}
		PduInfoType PduInfoPackage;
		PduInfoPackage.SduDataPtr = (uint8 *)IPdu->ComIPduDataPtr;
		if (IPdu->ComIPduDynSignalRef != 0) {
			uint8 sizeWithoutDynSignal = IPdu->ComIPduSize - (IPdu->ComIPduDynSignalRef->ComBitSize/8);
			PduInfoPackage.SduLength = sizeWithoutDynSignal + Arc_IPdu->Com_Arc_DynSignalLength;
		} else {
			PduInfoPackage.SduLength = IPdu->ComIPduSize;
		}

		// Send IPdu!
		if (PduR_ComTransmit(IPdu->ArcIPduOutgoingId, &PduInfoPackage) == E_OK) {
			// Clear all update bits for the contained signals
			for (uint8 i = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[i] != NULL); i++) {
				if (IPdu->ComIPduSignalRef[i]->ComSignalArcUseUpdateBit) {
					CLEARBIT(IPdu->ComIPduDataPtr, IPdu->ComIPduSignalRef[i]->ComUpdateBitPosition);
				}
			}
		} else {
			UnlockTpBuffer(getPduId(IPdu));
			return E_NOT_OK;
		}

		// Reset miminum delay timer.
		Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer = IPdu->ComTxIPdu.ComTxIPduMinimumDelayFactor;
	} else {
		return E_NOT_OK;
	}
    Irq_Restore(state);
    return E_OK;
#endif
}
Пример #5
0
StatusType ReleaseResource( ResourceType ResID) {
	StatusType rv = E_OK;
	OsTaskVarType *pcbPtr = Os_SysTaskGetCurr();
	OsResourceType *rPtr;
	uint32_t flags;

	Irq_Save(flags);
	if( ResID == RES_SCHEDULER ) {
		rPtr = &Os_Sys.resScheduler;
	} else {
		/* Check we can access it */
		if( (pcbPtr->constPtr->resourceAccess & (1<< ResID)) == 0 ) {
			rv = E_OS_ID;
			goto err;
		}
		rPtr = Os_ResourceGet(ResID);
	}

	/* Check for invalid configuration */
	if( rPtr->owner == NO_TASK_OWNER)
	{
		rv = E_OS_NOFUNC;
		Irq_Restore(flags);
		goto err;
	}

	if( (pcbPtr->activePriority < rPtr->ceiling_priority))
	{
		rv = E_OS_ACCESS;
		Irq_Restore(flags);
		goto err;
	}

	Os_TaskResourceRemove(rPtr,pcbPtr);

	/* do a rescheduling (in some cases) (see OSEK OS 4.6.1) */
	if ( (pcbPtr->constPtr->scheduling == FULL) &&
		 (Os_Sys.intNestCnt == 0) &&
		 (Os_SchedulerResourceIsFree()) ) {

		OsTaskVarType* top_pcb = Os_TaskGetTop();

		/* only dispatch if some other ready task has higher prio */
		if (top_pcb->activePriority > Os_SysTaskGetCurr()->activePriority) {
			Os_Dispatch(OP_RELEASE_RESOURCE);
		}
	}
	Irq_Restore(flags);

	OS_STD_END_1(OSServiceId_ReleaseResource,ResID);
}
Пример #6
0
void Wdg_SetTriggerCondition (uint16 timeout)
{
    /* This is not SWS_Wdg_00140 but 0 is supported and will not reset the watchdog
	 * meaning that it will take some time until the watchdog expires
     */
    if (timeout == 0) {
        return;
    }

    imask_t state;
    Irq_Save(state);

    /* @req SWS_Wdg_00093 Configured for fixed activation code */

    /*lint -save -e923 Ok, the casting is done in Freesacale header file  */
#if defined(CFG_MPC5567)
	ECSM.SWTSR.R = 0x55;
	ECSM.SWTSR.R = 0xAA;
#elif defined(CFG_MPC560X) || defined(CFG_MPC563XM) || defined(CFG_MPC5668) || defined(CFG_MPC5744P) || defined(CFG_MPC5645S) || defined(CFG_MPC5643L) || defined(CFG_SPC56XL70) || defined(CFG_MPC5644A) || defined(CFG_MPC5777M)
	SWT.SR.R = 0x0000A602;
	SWT.SR.R = 0x0000B480;
#elif defined(CFG_MPC5516)
	MCM.SWTSR.R = 0x55;
	MCM.SWTSR.R = 0xAA;
#else
	MCM.SWTSR.R = 0x55;
	MCM.SWTSR.R = 0xAA;
#endif
	/*lint -restore */

    Irq_Restore(state);
}
Пример #7
0
void OsTick(void)
{
	imask_t imask;
	AlarmType AlarmId;

	Irq_Save(imask);

	knl_os_tick ++;
	// Process Alarm

	for(AlarmId=0; AlarmId<cfgOsMaxAlarmId; AlarmId++)
	{
		if(knl_alarm_cb[AlarmId].Left > 0)
		{
			knl_alarm_cb[AlarmId].Left--;
			if(0u == knl_alarm_cb[AlarmId].Left)
			{
				(void)ActivateTask(AlarmList[AlarmId]);
				knl_alarm_cb[AlarmId].Left = knl_alarm_cb[AlarmId].Cycle;
			}
		}
	}

	Irq_Restore(imask);
}
Пример #8
0
/*
 * Function: CreateUdpSocket
 * Description: Create a socket to an UDP port
 * Return: Handle to the socket
 */
int CreateUdpSocket(uint16_t port, UdpCbkFunc cbkFunc)
{
	int udpSocket;
	struct sockaddr_in sLocalAddr;
	imask_t val;

	  /* Init socket */
	udpSocket = lwip_socket(AF_INET, SOCK_DGRAM, 0);

	Irq_Save(val);
	for(int i=0;i<MAX_NUM_OF_SOCKETS;i++){
		if(sockList[i] == (-1)){
			sockList[i] = udpSocket;
			cbkFuncList[i] = cbkFunc;
			break;
		}
	}
	Irq_Restore(val);

	memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));

	/*Source*/
	sLocalAddr.sin_family = AF_INET;
	sLocalAddr.sin_len = sizeof(sLocalAddr);
	sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	sLocalAddr.sin_port = htons(port);

	if(lwip_bind(udpSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0)
	{
		KillUdpSocket(udpSocket);
	}

	return udpSocket;
}
Пример #9
0
/*
 *	This function preparing transmission of response
 *	pending message to tester.
 */
static void sendResponse(const Dcm_DslProtocolRowType *protocol,
		Dcm_NegativeResponseCodeType responseCode) {
	//Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
	const Dcm_DslProtocolRxType *protocolRx = NULL;
	const Dcm_DslMainConnectionType *mainConnection = NULL;
	const Dcm_DslConnectionType *connection = NULL;
	const Dcm_DslProtocolRowType *protocolRow = NULL;
	Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
	Std_ReturnType transmitResult;
    imask_t state;

    Irq_Save(state);
	/** @req DCM119 */
	if (findRxPduIdParentConfigurationLeafs(protocol->DslRunTimeProtocolParameters->diagReqestRxPduId, &protocolRx,	&mainConnection, &connection, &protocolRow, &runtime)) {
		if (runtime->localTxBuffer.status == NOT_IN_USE) {
			runtime->localTxBuffer.status = PROVIDED_TO_DSD;
			runtime->localTxBuffer.buffer[0] = SID_NEGATIVE_RESPONSE;
			runtime->localTxBuffer.buffer[1] = protocol->DslProtocolRxBufferID->pduInfo.SduDataPtr[0];
			runtime->localTxBuffer.buffer[2] = responseCode;
			runtime->localTxBuffer.PduInfo.SduDataPtr = runtime->localTxBuffer.buffer;
			runtime->localTxBuffer.PduInfo.SduLength = 3;
			runtime->localTxBuffer.status = DCM_TRANSMIT_SIGNALED; // In the DslProvideTxBuffer 'callback' this state signals it is the local buffer we are interested in sending.
			transmitResult = PduR_DcmTransmit(mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, &(runtime->localTxBuffer.PduInfo));/** @req DCM115.Partially */ /* The P2ServerMin has not been implemented. */
			if (transmitResult != E_OK) {
				// TODO: What to do here?
				releaseExternalRxTxBuffers(protocolRow, runtime);
			}
		}
	}
    Irq_Restore(state);
}
Пример #10
0
/*
 *  This function is called from the DSD module to the DSL when
 *  a response to a diagnostic request has been copied into the
 *  given TX-buffer and is ready for transmission.
 */
void DslDsdProcessingDone(PduIdType rxPduIdRef, DsdProcessingDoneResultType responseResult) {
	const Dcm_DslProtocolRxType *protocolRx = NULL;
	const Dcm_DslMainConnectionType *mainConnection = NULL;
	const Dcm_DslConnectionType *connection = NULL;
	const Dcm_DslProtocolRowType *protocolRow = NULL;
	Dcm_DslRunTimeProtocolParametersType *runtime = NULL;

	DEBUG( DEBUG_MEDIUM, "DslDsdProcessingDone rxPduIdRef=%d\n", rxPduIdRef);

	if (findRxPduIdParentConfigurationLeafs(rxPduIdRef, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
	    imask_t state;
	    Irq_Save(state);
		switch (responseResult) {
		case DSD_TX_RESPONSE_READY:
			runtime->externalTxBufferStatus = DSD_PENDING_RESPONSE_SIGNALED; /** @req DCM114 */
			break;
		case DSD_TX_RESPONSE_SUPPRESSED: /** @req DCM238 */
			DEBUG( DEBUG_MEDIUM, "DslDsdProcessingDone called with DSD_TX_RESPONSE_SUPPRESSED.\n");
			releaseExternalRxTxBuffersHelper(rxPduIdRef);
			break;
		default:
			DEBUG( DEBUG_MEDIUM, "Unknown response result from DslDsdProcessingDone!\n");
			break;
		}
	    Irq_Restore(state);
	}
}
Пример #11
0
/* @req 4.0.3/IPDUM169 */
Std_ReturnType IpduM_TriggerTransmit(PduIdType TxPduId, PduInfoType *PduInfoPtr) {
	Std_ReturnType status;
	VALIDATE_INIT(IPDUM_API_TRIGGER_TRANSMIT);
	VALIDATE_PARAM_POINTER(IPDUM_API_TRIGGER_TRANSMIT, PduInfoPtr);
	VALIDATE_TX_PATHWAY_ID(IPDUM_API_TRIGGER_TRANSMIT, TxPduId);
	const IpduM_TxPathway *txPathway = &(IpduM_Config->txPathways[TxPduId]);

	imask_t state;
	Irq_Save(state);

	if ((*(txPathway->activeDynamicPart))->IpduMJitUpdate) {
		status = FetchTxPart(*(txPathway->activeDynamicPart));
		// Need to do something with return value - seems appropiate to set DET error
		VALIDATE_NO_RETURN(status == E_OK, IPDUM_API_TRIGGER_TRANSMIT, IPDUM_E_PARAM);
	}

	if (HAS_STATIC_PART(txPathway) && txPathway->staticPart->IpduMJitUpdate){
		status = FetchTxPart(txPathway->staticPart);
		// Need to do something with return value - seems appropiate to set DET error
		VALIDATE_NO_RETURN(status == E_OK, IPDUM_API_TRIGGER_TRANSMIT, IPDUM_E_PARAM);
	}

	memcpy(PduInfoPtr->SduDataPtr, txPathway->buffer, txPathway->pduSize);
	Irq_Restore(state);
	PduInfoPtr->SduLength = txPathway->pduSize;

	return E_OK;
}
Пример #12
0
uint8 Com_ReceiveDynSignal(Com_SignalIdType SignalId, void* SignalDataPtr, uint16* Length) {
	const ComSignal_type * Signal = GET_Signal(SignalId);
	Com_Arc_IPdu_type    *Arc_IPdu   = GET_ArcIPdu(Signal->ComIPduHandleId);
	const ComIPdu_type   *IPdu       = GET_IPdu(Signal->ComIPduHandleId);
    imask_t state;
   	uint8 startFromPduByte;
	uint8 r = E_OK;
	const void* pduDataPtr;
	Com_SignalType signalType = Signal->ComSignalType;
	if (signalType != UINT8_DYN) {
		return COM_SERVICE_NOT_AVAILABLE;
	}

    Irq_Save(state);

	if (*Length > Arc_IPdu->Com_Arc_DynSignalLength) {
		*Length = Arc_IPdu->Com_Arc_DynSignalLength;
	}
	startFromPduByte = (Signal->ComBitPosition) / 8;
	pduDataPtr = 0;
	if (IPdu->ComIPduSignalProcessing == DEFERRED && IPdu->ComIPduDirection == RECEIVE) {
		pduDataPtr = IPdu->ComIPduDeferredDataPtr;
	} else {
		if (isPduBufferLocked(getPduId(IPdu))) {
			r = COM_BUSY;
		}
		pduDataPtr = IPdu->ComIPduDataPtr;
	}
	memcpy((void*)SignalDataPtr, (void*)((uint8*)pduDataPtr + startFromPduByte), *Length);

    Irq_Restore(state);

	return r;
}
Пример #13
0
Lin_StatusType Lin_GetStatus( uint8 Channel, uint8** Lin_SduPtr )
{
	volatile struct LINFLEX_tag * LINFLEXHw = LINFLEX(Channel);

	VALIDATE_W_RV( (LinDriverStatus != LIN_UNINIT), LIN_GETSTATUS_SERVICE_ID, LIN_E_UNINIT, LIN_NOT_OK);
	VALIDATE_W_RV( (LinChannelStatus[Channel] != LIN_CH_UNINIT), LIN_GETSTATUS_SERVICE_ID, LIN_E_CHANNEL_UNINIT, LIN_NOT_OK);
	VALIDATE_W_RV( (Channel < LIN_CONTROLLER_CNT), LIN_GETSTATUS_SERVICE_ID, LIN_E_INVALID_CHANNEL, LIN_NOT_OK);
	VALIDATE_W_RV( (Lin_SduPtr!=NULL), LIN_GETSTATUS_SERVICE_ID, LIN_E_INVALID_POINTER, LIN_NOT_OK);

	imask_t state;
    Irq_Save(state);
	Lin_StatusType res = LinChannelStatus[Channel];
	/* We can only check for valid sdu ptr when LIN_RX_OK */
	if(LinChannelStatus[Channel] == LIN_RX_OK || LinChannelStatus[Channel] == LIN_RX_ERROR){
		CopyToBuffer(LinBufRx[Channel], LINFLEXHw);
		*Lin_SduPtr = LinBufRx[Channel];
		if(LinChannelStatus[Channel] == LIN_RX_ERROR){
			ResyncDriver(Channel);
		}
		LinChannelStatus[Channel]=LIN_CH_OPERATIONAL;
	} else if(LinChannelStatus[Channel] == LIN_TX_OK || LinChannelStatus[Channel] == LIN_TX_ERROR){
		if(LinChannelStatus[Channel] == LIN_TX_ERROR){
			ResyncDriver(Channel);
		}
		LinChannelStatus[Channel]=LIN_CH_OPERATIONAL;
	}
    Irq_Restore(state);
	return res;
}
Пример #14
0
/* This function services the internal Watchdog timer */
void Wdg_Trigger (void)
{
	imask_t state;

    Irq_Save(state);

	//  According to MPC55xx manual:
	//  To prevent the watchdog timer from interrupting or resetting
	//  the SWTSR must be serviced by performing the following sequence:
	//  1. Write 0x55 to the SWTSR.
	//  2. Write 0xAA to the SWTSR.
#if defined(CFG_MPC5567)
	ECSM.SWTSR.R = 0x55;
	ECSM.SWTSR.R = 0xAA;
#elif defined(CFG_MPC560X) || defined(CFG_MPC563XM) || defined(CFG_MPC5668)
	SWT.SR.R = 0x0000A602;
	SWT.SR.R = 0x0000B480;
#elif defined(CFG_MPC5516)
	MCM.SWTSR.R = 0x55;
	MCM.SWTSR.R = 0xAA;
#else
	MCM.SWTSR.R = 0x55;
	MCM.SWTSR.R = 0xAA;
#endif

    Irq_Restore(state);
}
Пример #15
0
/**
 * Increase the semaphore value by 1. If
 *
 * @param semPtr
 */
void SignalSemaphore( OsSemaphoreType *semPtr ) {
    uint32_t flags;
    OsTaskVarType *taskPtr;

    Irq_Save(flags);

    assert( semPtr != NULL );

    ++semPtr->val;

    /* Remove the first task that waits at the semaphore */
    if( semPtr->val <= 0 ) {

        taskPtr = STAILQ_FIRST(&semPtr->taskHead);
        /* Make the first task ready */
        Os_TaskMakeReady(taskPtr);

        /* Release the first task in queue */
        STAILQ_REMOVE_HEAD(&semPtr->taskHead,semEntry);

        if( taskPtr->activePriority > Os_SysTaskGetCurr()->activePriority ) {
            Os_Dispatch(OP_SIGNAL_SEMAPHORE);
        }
    }

    Irq_Restore(flags);
}
Пример #16
0
BufReq_ReturnType Com_CopyRxData(PduIdType PduId, const PduInfoType* PduInfoPtr, PduLengthType* RxBufferSizePtr) {
	/* !req COM782 */ /* If pdu group stopped -> return BUFREQ_E_NOT_OK */
	imask_t state;
	BufReq_ReturnType r = BUFREQ_OK;
	uint8 remainingBytes;
	boolean sizeOk;
	boolean dirOk;
	boolean lockOk;
	if(COM_INIT != initStatus) {
		DET_REPORTERROR(COM_COPYRXDATA_ID, COM_E_UNINIT);
		return BUFREQ_NOT_OK;
	}
	Irq_Save(state);
	/* @req COM658 */ /* Interrupts disabled */
	remainingBytes = GET_IPdu(PduId)->ComIPduSize - Com_BufferPduState[PduId].currentPosition;
	sizeOk = remainingBytes >= PduInfoPtr->SduLength;
    dirOk = GET_IPdu(PduId)->ComIPduDirection == RECEIVE;
	lockOk = isPduBufferLocked(PduId);
	if (dirOk && lockOk && sizeOk) {
		memcpy((void *)((uint8 *)GET_ArcIPdu(PduId)->ComIPduDataPtr+Com_BufferPduState[PduId].currentPosition), PduInfoPtr->SduDataPtr, PduInfoPtr->SduLength);
		Com_BufferPduState[PduId].currentPosition += PduInfoPtr->SduLength;
		*RxBufferSizePtr = GET_IPdu(PduId)->ComIPduSize - Com_BufferPduState[PduId].currentPosition;
	} else {
		r = BUFREQ_NOT_OK;
	}
	Irq_Restore(state);
	return r;
}
Пример #17
0
BufReq_ReturnType Com_StartOfReception(PduIdType ComRxPduId, PduLengthType TpSduLength, PduLengthType* RxBufferSizePtr) {
	PduLengthType ComIPduSize;
	imask_t state;
	BufReq_ReturnType r = BUFREQ_OK;
	Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(ComRxPduId);

	Irq_Save(state);
	if (Arc_IPdu->Com_Arc_IpduStarted) {
		if (GET_IPdu(ComRxPduId)->ComIPduDirection == RECEIVE) {
			if (!Com_BufferPduState[ComRxPduId].locked) {
				ComIPduSize = GET_IPdu(ComRxPduId)->ComIPduSize;
				if (ComIPduSize >= TpSduLength) {
					Com_BufferPduState[ComRxPduId].locked = TRUE;
					*RxBufferSizePtr = ComIPduSize;
					Com_SetDynSignalLength(ComRxPduId,TpSduLength);
				} else {
					r = BUFREQ_OVFL;
				}
			} else {
				r = BUFREQ_BUSY;
			}
		}
	} else {
		r = BUFREQ_NOT_OK;
	}
	Irq_Restore(state);
	return r;
}
Пример #18
0
/**
 *
 * @param PduId
 * @param PduInfoPtr
 * @param RetryInfoPtr not supported
 * @param TxDataCntPtr
 * @return
 */
BufReq_ReturnType Com_CopyTxData(PduIdType PduId, PduInfoType* PduInfoPtr, RetryInfoType* RetryInfoPtr, PduLengthType* TxDataCntPtr) {
	/* TODO: Validate PduId, etc? */
	/* !req COM663*/
	/* !req COM783*/ /* Do not copy any data and return BUFREQ_E_NOT_OK if pdu group stopped */
	imask_t state;
	BufReq_ReturnType r = BUFREQ_OK;

	if(COM_INIT != initStatus) {
		DET_REPORTERROR(COM_COPYTXDATA_ID, COM_E_UNINIT);
		return BUFREQ_NOT_OK;
	}

	const ComIPdu_type *IPdu = GET_IPdu(PduId);
	boolean dirOk = ComConfig->ComIPdu[PduId].ComIPduDirection == SEND;
	boolean sizeOk;
	(void)RetryInfoPtr; // get rid of compiler warning

	Irq_Save(state);
	sizeOk = IPdu->ComIPduSize >= Com_BufferPduState[PduId].currentPosition + PduInfoPtr->SduLength;
	Com_BufferPduState[PduId].locked = true;
	if (dirOk && sizeOk) {
		void* source = (void *)GET_ArcIPdu(PduId)->ComIPduDataPtr;
		memcpy(PduInfoPtr->SduDataPtr,(uint8 *)source + Com_BufferPduState[PduId].currentPosition, PduInfoPtr->SduLength);
		Com_BufferPduState[PduId].currentPosition += PduInfoPtr->SduLength;
		*TxDataCntPtr = IPdu->ComIPduSize - Com_BufferPduState[PduId].currentPosition;
	} else {
		r = BUFREQ_NOT_OK;
	}
	Irq_Restore(state);
	return r;
}
Пример #19
0
Std_ReturnType Com_SendSignalGroup(Com_SignalGroupIdType SignalGroupId) {
//#warning Com_SendSignalGroup should be performed atomically. Should we disable interrupts here?
	const ComSignal_type * Signal = GET_Signal(SignalGroupId);
	Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(Signal->ComIPduHandleId);
	const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);

	if (isPduBufferLocked(getPduId(IPdu))) {
		return COM_BUSY;
	}

	// Copy shadow buffer to Ipdu data space
	imask_t irq_state;

	Irq_Save(irq_state);

	Com_CopySignalGroupDataFromShadowBufferToPdu(SignalGroupId);

	// If the signal has an update bit. Set it!
	if (Signal->ComSignalArcUseUpdateBit) {
		SETBIT(IPdu->ComIPduDataPtr, Signal->ComUpdateBitPosition);
	}

	// If signal has triggered transmit property, trigger a transmission!
	if (Signal->ComTransferProperty == TRIGGERED) {
		Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft = IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeNumberOfRepetitions + 1;
	}
	Irq_Restore(irq_state);

	return E_OK;
}
Пример #20
0
uint8 Com_SendSignal(Com_SignalIdType SignalId, const void *SignalDataPtr) {
	VALIDATE_SIGNAL(SignalId, 0x0a, E_NOT_OK);
	// Store pointer to signal for easier coding.
	const ComSignal_type * Signal = GET_Signal(SignalId);
	const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
	Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(Signal->ComIPduHandleId);

	if (isPduBufferLocked(getPduId(IPdu))) {
		return COM_BUSY;
	}
	//DEBUG(DEBUG_LOW, "Com_SendSignal: id %d, nBytes %d, BitPosition %d, intVal %d\n", SignalId, nBytes, signal->ComBitPosition, (uint32)*(uint8 *)SignalDataPtr);

	imask_t irq_state;

	Irq_Save(irq_state);
	Com_WriteSignalDataToPdu(Signal->ComHandleId, SignalDataPtr);

	// If the signal has an update bit. Set it!
	if (Signal->ComSignalArcUseUpdateBit) {
		SETBIT(IPdu->ComIPduDataPtr, Signal->ComUpdateBitPosition);
	}

	/*
	 * If signal has triggered transmit property, trigger a transmission!
	 */
	if (Signal->ComTransferProperty == TRIGGERED) {
		Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft = IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeNumberOfRepetitions + 1;
	}
	Irq_Restore(irq_state);

	return E_OK;
}
Пример #21
0
void Com_TpTxConfirmation(PduIdType PduId, NotifResultType Result) {
	imask_t state;
	PDU_ID_CHECK_NO_RV(PduId, 0x15);
	(void)Result; // touch	
	Irq_Save(state);
	UnlockTpBuffer(PduId);
	Irq_Restore(state);
}
Пример #22
0
EXPORT void Can_Hw_EnableControllerInterrupts( uint8 controller )
{
	 imask_t state;
	  Can_UnitType *canUnit;
	  CAN_HW_t *canHw;
	  const Can_ControllerConfigType *canHwConfig;

	  canUnit = CAN_GET_PRIVATE_DATA(controller);

	  VALIDATE_NO_RV( (canUnit->state!=CANIF_CS_UNINIT), 0x5, CAN_E_UNINIT );

	  Irq_Save(state);
	  if( canUnit->lock_cnt > 1 )
	  {
	    // IRQ should still be disabled so just decrement counter
	    canUnit->lock_cnt--;
	    Irq_Restore(state);
	    return;
	  } else if (canUnit->lock_cnt == 1)
	  {
	    canUnit->lock_cnt = 0;
	  }
	  Irq_Restore(state);

	  canHw = GetController(controller);

	  canHwConfig = CAN_GET_CONTROLLER_CONFIG(Can_Global.channelMap[controller]);

	   if( canHwConfig->CanRxProcessing == CAN_PROCESS_TYPE_INTERRUPT ) {
	     /* Turn on the rx interrupt */
	 	CAN_ITConfig(canHw, CAN_IT_FMP0, ENABLE);
	   }
	   if( canHwConfig->CanTxProcessing == CAN_PROCESS_TYPE_INTERRUPT ) {
	 	/* Turn on the tx interrupt mailboxes */
	   	CAN_ITConfig(canHw, CAN_IT_TME, ENABLE);
	   }

	   // BusOff here represents all errors and warnings
	   if( canHwConfig->CanBusOffProcessing == CAN_PROCESS_TYPE_INTERRUPT ) {
	 	/* Turn on the bus off/tx warning/rx warning and error and rx  */
	 	CAN_ITConfig(canHw, CAN_IT_BOF | CAN_IT_ERR | CAN_IT_WKU, ENABLE);
	   }

	   return;
}
Пример #23
0
StatusType 	ActivateTask( TaskType TaskID )
{
	imask_t imask;
	assert(TaskID < cfgOsMaxTaskId);
	Irq_Save(imask);
	knl_bitmap |= (1u<<TaskID); 
	Irq_Restore(imask);
	return E_OK;
}
Пример #24
0
StatusType WaitSemaphore( OsSemaphoreType *semPtr, TickType tmo ) {
    OsTaskVarType *pcbPtr;
    uint32_t flags;
    StatusType rv = E_OK;
    (void)tmo;

    Irq_Save(flags);

    --semPtr->val;

    pcbPtr = Os_SysTaskGetCurr();
    assert(OS_SYS_PTR->intNestCnt == 0 );

    if (pcbPtr->constPtr->proc_type != PROC_EXTENDED) {
        return E_OS_ACCESS;
    }

    if(semPtr->val < 0 ) {
        /* To WAITING state */
        if( tmo == 0 ) {
            /* Failed to acquire the semaphore */
            rv = E_NOT_OK;
        } else {
            /* Add this task to the semaphore */
            STAILQ_INSERT_TAIL(&semPtr->taskHead,pcbPtr,semEntry);

            Os_Dispatch(OP_WAIT_SEMAPHORE);
        }
    } else {
        /* We got the semaphore */
        if( tmo == 0 ) {

            rv = E_NOT_OK;
        } else {
            /*
             * Wait for the semaphore to be signaled or timeout
             */
            if ( Os_SchedulerResourceIsFree() ) {
                /* Set the timeout */
                if( tmo != TICK_MAX ) {
                    TAILQ_INSERT_TAIL(&OS_SYS_PTR->timerHead,pcbPtr,timerEntry);
                    pcbPtr->timerDec = tmo;
                }

                Os_Dispatch(OP_WAIT_SEMAPHORE);
            } else {
                /* We hold RES_SCHEDULER */
                rv = E_NOT_OK;
            }
        }
    }

    Irq_Restore(flags);

    return rv;
}
Пример #25
0
static Std_ReturnType FetchTxPart(const IpduM_TxPart *txPart) {

	Std_ReturnType ret;

	PduInfoType pduInfo = {
		.SduDataPtr = IpduM_Config->txBuffer,
		.SduLength  = txPart->txPathway->pduSize
	};

	imask_t irq_state;
	Irq_Save(irq_state);

	ret = PduR_IpduMTriggerTransmit(txPart->pduId, &pduInfo);

	/*lint -save -e522 */
	CopySegments(txPart->segments, txPart->nSegments, txPart->txPathway->buffer, pduInfo.SduDataPtr);

	/*lint -restore */
	Irq_Restore(irq_state);

	return ret;

}


/* @req 4.0.3/IPDUM033 */
/* @req 4.0.3/IPDUM083 */
/* @req 4.0.3/IPDUM067 */
/* @req 4.0.3/IPDUM068 */
/* @req 4.0.3/IPDUM143 */
void IpduM_Init(const IpduM_ConfigType *config) {
	// Com_Init() and PduR_Init() has to be called before IpduM_Init(), see chapter 7.3 of IpduM SRS.
	Std_ReturnType status;
	VALIDATE_PARAM_POINTER_NO_RV(IPDUM_API_INIT, config);
	IpduM_Config = config;


	for (uint16 i = 0; i < IPDUM_N_TX_PATHWAYS; i++) {
		const IpduM_TxPathway *txPathway = &(IpduM_Config->txPathways[i]);
		memset(txPathway->buffer, txPathway->IpduMIPduUnusedAreasDefault, txPathway->pduSize);

		status = FetchTxPart(*(txPathway->activeDynamicPart));
		// Need to do something with return value - seems appropiate to set DET error
		VALIDATE_NO_RETURN(status == E_OK, IPDUM_API_INIT, IPDUM_E_PARAM);

		if (HAS_STATIC_PART(txPathway)) {
			status = FetchTxPart(txPathway->staticPart);
			// Need to do something with return value - seems appropiate to set DET error
			VALIDATE_NO_RETURN(status == E_OK, IPDUM_API_INIT, IPDUM_E_PARAM);
		}
	}

	ipdum_state = IPDUM_INIT;
}
Пример #26
0
StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle)
{
	imask_t imask;
	assert(AlarmId<cfgOsMaxAlarmId);
	
	Irq_Save(imask);
	knl_alarm_cb[AlarmId].Left = Increment;
	knl_alarm_cb[AlarmId].Cycle = Cycle;
	Irq_Restore(imask);
	return E_OK;
}
Пример #27
0
EXPORT Can_ReturnType Can_Hw_Write( Can_HwHandleType/* Can_HTHType */ hth, const Can_PduType *pduInfo ) {
	  Can_ReturnType rv = CAN_OK;
	  CAN_HW_t *canHw;
	  const Can_HardwareObjectType *hohObj;
	  const Can_ControllerConfigType *canHwConfig;
	  uint32 controller;
	  imask_t state;

	  hohObj = Can_FindHoh(hth, &controller);
	  if (hohObj == NULL)
	    return CAN_NOT_OK;

	  Can_UnitType *canUnit = CAN_GET_PRIVATE_DATA(controller);

	  canHw = GetController(controller);
	  Irq_Save(state);

	  CanTxMsg TxMessage;

	  TxMessage.RTR=CAN_RTR_DATA;
	  TxMessage.DLC=pduInfo->length;

	  memcpy(TxMessage.Data, pduInfo->sdu, pduInfo->length);

	  if (hohObj->CanIdType == CAN_ID_TYPE_EXTENDED) {
		TxMessage.IDE=CAN_ID_EXT;
		TxMessage.ExtId=pduInfo->id;
	  } else {
		TxMessage.IDE=CAN_ID_STD;
		TxMessage.StdId=pduInfo->id;
	  }

	  // check for any free box
	  if(CAN_Transmit(canHw,&TxMessage) != CAN_NO_MB) {
	    canHwConfig = CAN_GET_CONTROLLER_CONFIG(Can_Global.channelMap[controller]);

	    if( canHwConfig->CanTxProcessing == CAN_PROCESS_TYPE_INTERRUPT ) {
	  	  /* Turn on the tx interrupt mailboxes */
	    	CAN_ITConfig(canHw,CAN_IT_TME, ENABLE);
	    }

		// Increment statistics
		canUnit->stats.txSuccessCnt++;

	    // Store pdu handle in unit to be used by TxConfirmation
	    canUnit->swPduHandle = pduInfo->swPduHandle;
	  } else {
	    rv = CAN_BUSY;
	  }
	  Irq_Restore(state);

	  return rv;
}
Пример #28
0
/*
 * Function: KillUdpSocket
 * Description: Kill a socket to an UDP port
 * Param: Handle to the socket
 */
void KillUdpSocket(int socket)
{
	imask_t val;
	Irq_Save(val);
	for(int i=0;i<MAX_NUM_OF_SOCKETS;i++){
		if(sockList[i] == socket){
			sockList[i] = (-1);
		}
	}
	Irq_Restore(val);
	lwip_close(socket);
}
Пример #29
0
StatusType CancelAlarm(AlarmType AlarmId)
{
	imask_t imask;
	assert(AlarmId<cfgOsMaxAlarmId);

	Irq_Save(imask);
	knl_alarm_cb[AlarmId].Left = 0u;
	knl_alarm_cb[AlarmId].Cycle = 0u;
	Irq_Restore(imask);

	return E_OK;
}
Пример #30
0
/** !req SWS_Port_00066 */
void Port_RefreshPortDirection(void) {
    VALIDATE_STATE_INIT(PORT_REFRESH_PORT_DIRECTION_ID);
    uint8 pinNr = 0;
    imask_t state;
    Irq_Save(state);
    for (uint16 i = 0; Port_configPtr->pinConfig[i].PortPinId != PORT_INVALID_REG; i++) {
        pinNr = Port_configPtr->pinConfig[i].PortPinId;
        SET_PORT_REGISTER(pinNr, PM, Port_configPtr->pinConfig[i], PORT_MODULE_ID, PORT_GLOBAL_ID, PORT_E_UNEXPECTED_EXECUTION);
        SET_PORT_REGISTER(pinNr, PIBC, Port_configPtr->pinConfig[i], PORT_MODULE_ID, PORT_GLOBAL_ID, PORT_E_UNEXPECTED_EXECUTION);
    }
    Irq_Restore(state);
}