Exemplo n.º 1
0
/* Dcm Example Initialise Routine.
 * 初始化Can、CanIf、PduR和DCM ,
 * 需要使用“dcm_ex1.arxml”生成其相应配置文件。*/
void DcmEx1Init(void)
{
    Can_Init(&Can_ConfigData); 
    CanIf_Init(&CanIf_Config);
    CanTp_Init();
    PduR_Init(&PduR_Config);
    Dcm_Init();
    //启动配置的两个CAN通道 CAN_CTRL_0 和 CAN_CTRL_1
    CanIf_SetControllerMode(vCanIf_Channel_0,CANIF_CS_STARTED);
    CanIf_SetControllerMode(vCanIf_Channel_1,CANIF_CS_STARTED);
}
Exemplo n.º 2
0
/*
 * Controller :: CanIf_Arc_ChannelIdType (CanIf-specific id to abstract from Can driver/controllers)
 * ConfigurationIndex :: CanIf_Arc_ConfigurationIndexType
 */
void CanIf_InitController(uint8 Controller, uint8 ConfigurationIndex)
{
  // We call this a CanIf channel. Hopefully makes it easier to follow.
  CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller;
  CanIf_ControllerModeType mode;

  VALIDATE_NO_RV(CanIf_Global.initRun, CANIF_INIT_CONTROLLER_ID, CANIF_E_UNINIT );
  VALIDATE_NO_RV(channel < CANIF_CHANNEL_CNT, CANIF_INIT_CONTROLLER_ID, CANIF_E_PARAM_CONTROLLER);
  VALIDATE_NO_RV(ConfigurationIndex < CANIF_CHANNEL_CONFIGURATION_CNT, CANIF_INIT_CONTROLLER_ID, CANIF_E_PARAM_POINTER);

  if (CanIf_GetControllerMode(channel, &mode) == E_OK)
  {
    if (mode == CANIF_CS_STARTED)
    {
      CanIf_SetControllerMode(channel, CANIF_CS_STOPPED); // CANIF092
    }
    else if (mode != CANIF_CS_STOPPED)
    {
      VALIDATE_NO_RV(FALSE, CANIF_INIT_CONTROLLER_ID, CANIF_E_PARAM_CONTROLLER_MODE); // CANIF092
    }
  }
  else
  {
    VALIDATE_NO_RV(FALSE, CANIF_INIT_CONTROLLER_ID, CANIF_E_PARAM_CONTROLLER_MODE);
  }

  // CANIF293: ..Subsequently the CAN Interface calls the corresponding
  //             CAN Driver initialization services.

  // CANIF066: The CAN Interface has access to the CAN Driver configuration data. All
  // public CAN Driver configuration data are described in [8] Specification of CAN Driver.

  // Grab the configuration from the Can Controller
  const Can_ControllerConfigType *canConfig;
  const CanControllerIdType canControllerId = ARC_GET_CHANNEL_CONTROLLER(channel);

  // Validate that the configuration at the index match the right channel
  VALIDATE_NO_RV(CanIf_ConfigPtr->ControllerConfig[ConfigurationIndex].CanIfControllerIdRef == channel, CANIF_INIT_CONTROLLER_ID, CANIF_E_PARAM_CONTROLLER);

  canConfig = CanIf_ConfigPtr->ControllerConfig[ConfigurationIndex].CanIfInitControllerRef;

  // Validate that the CanIfControllerConfig points to configuration for the right Can Controller
  VALIDATE_NO_RV(canConfig->CanControllerId == canControllerId, CANIF_INIT_CONTROLLER_ID, CANIF_E_PARAM_CONTROLLER);

  Can_InitController(canControllerId, canConfig);

  // Set mode to stopped
  CanIf_SetControllerMode(channel, CANIF_CS_STOPPED);
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: heathzj/moped
void StartupTask( void ) {
    pi_printf("infor: start up\r\n");

    bcm2835_read_mac_address();

    parse_config();

    printf("ACT LED on GPIO %d\r\n", act_led_gpio);
    printf("CAN bus frequency %d MHz\r\n", MCP2515_FREQUENCY_MHz);

    EcuM_StartupTwo();

	// Startup CanIf due to ComM is missing in this example
	CanIf_SetControllerMode(CANIF_CanIfCtrlCfg, CANIF_CS_STARTED);
	CanIf_SetPduMode(CANIF_CanIfCtrlCfg, CANIF_SET_ONLINE);

	 /** Setup Com stack with necessary parameters**/
	Com_IpduGroupVector groupVector;
	Com_ClearIpduGroupVector(groupVector);
	//Start the IPDU group
	Com_SetIpduGroup(groupVector, COM_PDU_GROUP_ID_TXIPDUGROUP, TRUE);
	Com_SetIpduGroup(groupVector, COM_PDU_GROUP_ID_RXIPDUGROUP, TRUE);
	Com_IpduGroupControl(groupVector, TRUE);

	TerminateTask();

}
Exemplo n.º 4
0
void CanIf_ControllerBusOff(uint8 Controller)
{
  CanIf_Arc_ChannelIdType channel = 0xff;

  VALIDATE_NO_RV( CanIf_Global.initRun, CANIF_CONTROLLER_BUSOFF_ID, CANIF_E_UNINIT );

  for(int i = 0; i < CANIF_CHANNEL_CNT; i++)
  {
	  if(CanIf_ConfigPtr->Arc_ChannelToControllerMap[i] == Controller)
	  {
		  channel = i;
	  }
  }

  VALIDATE_NO_RV( Controller < CANIF_CHANNEL_CNT, CANIF_CONTROLLER_BUSOFF_ID, CANIF_E_PARAM_CONTROLLER );

  // According to figure 35 in canif spec this should be done in
  // Can driver but it is better to do it here
  CanIf_SetControllerMode(channel, CANIF_CS_STOPPED);

  if (CanIf_ConfigPtr->DispatchConfig->CanIfBusOffNotification != NULL)
  {
    CanIf_ConfigPtr->DispatchConfig->CanIfBusOffNotification(channel);
  }
}
Exemplo n.º 5
0
// Tasks
void Task1( void ) {

	EcuM_StartupTwo();

	CanIf_SetControllerMode(CANIF_Controller_A, CANIF_CS_STARTED);
	Com_IpduGroupStart(CanDbImportedPdus, 1);

	TerminateTask();
}
Exemplo n.º 6
0
void StartupHook(void)
{
    /* Add Code Here */
    (void)SetRelAlarm(ID_vAlarmReceiver,50,10);
	(void)SetRelAlarm(ID_vAlarmSender,100,200);
	(void)SetRelAlarm(ID_vAlarmMainFunction,200,1); //so cyclic 1 Ticks = 4ms
	Can_Init(&Can_ConfigData); 
    CanIf_Init(&CanIf_Config);
    CanNm_Init(&CanNm_Config);
    CanSM_Init(&CanSM_Cfg);
    Nm_Init(&Nm_Config);
    ComM_Init(&ComM_Cfg);
    CanIf_SetControllerMode(vCanIf_Channel_0,CANIF_CS_STARTED);
    CanIf_SetControllerMode(vCanIf_Channel_1,CANIF_CS_STARTED);
    Nm_PassiveStartUp(vNm_Channel_0);
    ComM_RequestComMode(vComM_User_0,COMM_FULL_COMMUNICATION);
    CanNm_NetworkRequest(vCanNm_Channel_0);
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: idmond/moped
void StartupTask( void ) {
    pi_printf("infor: start up\r\n");

    EcuM_StartupTwo();

	// Startup CanIf due to ComM is missing in this example
	CanIf_SetControllerMode(CANIF_CanIfCtrlCfg, CANIF_CS_STARTED);
	CanIf_SetPduMode(CANIF_CanIfCtrlCfg, CANIF_SET_ONLINE);

	 /** Setup Com stack with necessary parameters**/
	Com_IpduGroupVector groupVector;
	//Start the IPDU group
	Com_ClearIpduGroupVector(groupVector);
	//Start the IPDU group
	Com_SetIpduGroup(groupVector, COM_PDU_GROUP_ID_TXCOMIPDUGROUP, TRUE);
	Com_SetIpduGroup(groupVector, COM_PDU_GROUP_ID_RXCOMIPDUGROUP, TRUE);
	Com_IpduGroupControl(groupVector, TRUE);

	TerminateTask();

}
Exemplo n.º 8
0
Std_ReturnType CanSM_Internal_SetNetworkControllerMode(NetworkHandleType NetworkHandle, CanIf_ControllerModeType controllerMode)
{
	Std_ReturnType totalStatus = E_OK;
	const CanSM_NetworkType *NetworkCfg = &CanSM_Config->Networks[NetworkHandle];
	for(uint8 ctrl = 0; ctrl < NetworkCfg->ControllerCount; ctrl++) {
		uint8 index;
		if( E_OK != CanSM_Internal_GetCanSMControllerIndex(NetworkCfg->Controllers[ctrl].CanIfControllerId, &index) ) {
			return E_NOT_OK;
		}

		CanSM_Internal.ControllerModeBuf[index].hasPendingCtrlIndication = TRUE;
		CanSM_Internal.ControllerModeBuf[index].pendingCtrlMode = controllerMode;
		if( E_OK != CanIf_SetControllerMode(NetworkCfg->Controllers[ctrl].CanIfControllerId, controllerMode)) {
			/* Not accepted. No mode indication pending */
			CanSM_Internal.ControllerModeBuf[index].hasPendingCtrlIndication = FALSE;
			totalStatus = E_NOT_OK;
		}
	}

	return totalStatus;
}
Exemplo n.º 9
0
void CAN_InterfaceTest(const char* driverName, int sendcountmax, int baud, int config) {
  int cnt;
  sendcount = 0;
  recvcount = 0;
  time_t t_start, t_end;
	Std_ReturnType std_ret;

  /* CanIf_ConfigTypeはAUTOSARの仕様に準拠したため、本バージョンでは未使用。NULLを指定する */
  CanIf_Init(NULL);

  /* AUTOSARの仕様に準拠し、各種設定は静的なデータとしてコンパイル時に確定させる。
    本サンプルプログラムでは、テストのため内部設定を直接書き換える。
     CanIfConfigurationsは、CanIf_Initの実行後に修正する必要がある */

  /* ドライバ名の設定 */
  CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.driverName = driverName;
  CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.driverName = driverName;
  /* ボーレートの設定 */
  CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.baudRate = baud;
  CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.baudRate = baud;
  /* Acceptフィルタの設定 */
  CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.acceptCode = 0x00000000;
  CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.acceptMask = 0xffffffff;
  CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.acceptCode = 0x00000000;
  CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.acceptMask = 0xffffffff;
  /* PDU-IDの登録 */
  CanIfConfigurations.initConfiguration[RECVCFG].CanIfNumberOfCanRxPduIds = 1;
  CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfCanRxPduCanId = RECV_PDUID;
  CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfCanRxPduId = RECV_PDUID;
  CanIfConfigurations.initConfiguration[RECVCFG].CanIfNumberOfCanTxPduIds = 0;
  CanIfConfigurations.initConfiguration[RECVCFG].CanIfNumberOfDynamicCanTxPduIds = 0;

  CanIfConfigurations.initConfiguration[SENDCFG].CanIfNumberOfCanTxPduIds = 1;
  CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfTxPduIdCanId = SEND_PDUID;
  CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfCanTxPduId = SEND_PDUID;
  CanIfConfigurations.initConfiguration[SENDCFG].CanIfNumberOfCanRxPduIds = 0;
  CanIfConfigurations.initConfiguration[SENDCFG].CanIfNumberOfDynamicCanTxPduIds = 0;

  /* 受信コールバックの設定 */
  CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfRxUserType = CANIF_CAN_NM;
	if(config == 0) {
		CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfUserRxIndication = CanRxCallback;
		CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfUserTxConfirmtion = CanTxCallback;
	} else {
		CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfUserRxIndication = NULL;
		CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfUserTxConfirmtion = NULL;
	}

  /* コントローラの初期化 */
  CanIf_InitController(sendController, SENDCFG);
  CanIf_InitController(recvController, RECVCFG);


  if (CanIf_SetControllerMode(sendController, CANIF_CS_STARTED) != E_OK) {
    printf("CanIf_SetControllerMode(0, CANIF_CS_STARTED) failed\n");
    return;
  }
  if (CanIf_SetControllerMode(recvController, CANIF_CS_STARTED) != E_OK) {
    printf("CanIf_SetControllerMode(1, CANIF_CS_STARTED) failed\n");
    return;
  }


  time(&t_start);
  for(cnt = 0; (cnt < (sendcountmax * 5) && recvcount < sendcountmax); ++cnt) {
    Dem_Sleep(1000);

    /* 送信テスト */

    if(sub_loop_trg == 0 && sendcount < sendcountmax) {
		PduInfoType pduInfo;
		uint8 buf[8];
		sprintf((char*)buf, "UU%4.4d*", cnt);
		buf[7] = 0x00;
		pduInfo.SduDataPtr = buf;
		pduInfo.SduLength = 8;

		do{	/* エラーの時はリトライして待つ */
			std_ret = CanIf_Transmit(SEND_PDUID, &pduInfo);
			printf("CanIf_Transmit std_ret = %d, cnt = %d\n",std_ret ,cnt);
		}while(std_ret != E_OK);

		printf("Transmit ch:%d to ch:%d: ID:%x '%8.8s'\n", 
			sendController, recvController, SEND_PDUID, pduInfo.SduDataPtr);
		++sendcount;
	}


	// ヒステリシスを持った、送信の制御
	if(sub_loop_trg == 0) {
		if((sendcount - recvcount) >= sub_loop_limit) sub_loop_trg = 1;
	} else {
	  	if((sendcount - recvcount) < (sub_loop_limit / 4)) sub_loop_trg = 0;
	}


    if (config == 1) {
      /* 受信テスト */
      if (CanIf_ReadRxPduData(RECV_PDUID, &recvData) == E_OK) {
        /* 受信データあり */
        printf("Receive  ch:%d ID:%x '%8.8s'\n", 
	       recvController, RECV_PDUID, recvData.SduDataPtr);
        ++recvcount;
		
      }
    }
  }
  if (recvcount == sendcountmax) {
    printf("All data received. (%d/%d)\n", recvcount, sendcountmax);
  }
  else {
    printf("%d data lost.(%d/%d)\n", sendcountmax - recvcount, recvcount, sendcountmax);
  }
  time(&t_end);
  printf("Total time: %d [Sec]\n", (t_end - t_start));

  /* 終了処理の追加 */
  CanIf_Deinit();
}