};
+/**
+ * @brief Initialize the device as FlexRay node.
+ *
+ * Syntax:
+ * frbtinitA - initializes the device as FlexRay node A
+ * frbtinitB - initializes the device as FlexRay node B
+ *
+ * The command calls a Fr_Init function from theAutosar specification, which
+ * initializes internal data structures of the driver.
+ *
+ * This command should be called before any other commands.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char* p = NULL;
+ const Fr_ConfigType* Fr_ConfigPtr = NULL;
+
+ p = param[1];
+ if (*p == 'A') {
+ Fr_ConfigPtr = &Fr_config_node_A;
+ }
+ else if (*p == 'B') {
+ Fr_ConfigPtr = &Fr_config_node_B;
+ }
+ else {
+ return -CMDERR_BADPAR;
+ }
+
+ Fr_Init(Fr_ConfigPtr);
+ rpp_sci_printf("FlexRay initialized.\n");
+ return 0;
+}
+
+/**
+ * @brief Initialize the device FlexRay controller.
+ *
+ * Syntax:
+ * frbtctrlinit - initializes the device FlexRay controller.
+ *
+ * The command calls a Fr_ControllerInit function from the Autosar specification, which
+ * initializes the FlexRay controller registers with the configuration data retreived by the
+ * frbtinit command.
+ *
+ * This command should be called right after frbtinit and before any other commands.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_ctrlinit(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ retVal = Fr_ControllerInit(0);
+ if (retVal & E_OK) {
+ rpp_sci_printf("FlexRay controller initialized.\n");
+ }
+ else {
+ if (retVal & FR_INIT_ERR_CLUSTER_CONFIG) {
+ rpp_sci_printf("Cluster configuration data error: %x\n", (retVal & 0x3FFFFFE) >> 1 );
+ }
+ else if (retVal & FR_INIT_ERR_NODE_CONFIG) {
+ rpp_sci_printf("Node configuration data error: %x\n", (retVal & 0x3FFFFFE) >> 1 );
+ }
+ else if (retVal & FR_INIT_ERR_MSGRAM_CONFIG) {
+ rpp_sci_printf("Message RAM configuration data error: %x\n", (retVal & 0x3FFFFFE) >> 1 );
+ }
+ else if (retVal & FR_INIT_ERR_BUFFPARAM_CONFIG) {
+ rpp_sci_printf("Buffer configuration data error: %x\n", (retVal & 0x3FFFFFE) >> 1 );
+ }
+ else if (retVal & (uint32_t)FR_INIT_ERR_BUFF_CONFIG) {
+ rpp_sci_printf("Buffer configuration error: %x\n", (retVal & 0x3FFFFFE) >> 1 );
+ }
+ else {
+ rpp_sci_printf("POC state switching error.\n");
+ }
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Starts FlexRay communication
+ *
+ * Syntax:
+ * frbtstart - initializes the device FlexRay controller.
+ *
+ * The command calls a Fr_StartCommunication function from the Autosar specification, which
+ * initiates new FlexRay network if coldstarter or join to the existing network.
+ *
+ * This command should be called right after all buffers are initialized and filled with data.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ retVal = Fr_StartCommunication(0);
+ if (retVal & E_OK) {
+ rpp_sci_printf("FlexRay communication is running.\n");
+ }
+ else {
+ if (retVal & FR_STARTUP_ERR_SW_STUP_FOLLOW) {
+ rpp_sci_printf("Can not switch POC to RUN state.\n");
+ }
+ else if (retVal & FR_STARTUP_ERR_CSINH_DIS) {
+ rpp_sci_printf("Cold start inhibit disabled error.\n");
+ }
+ else if (retVal & FR_STARTUP_ERR_SW_STUP_READY) {
+ rpp_sci_printf("Can not switch back to READY from STARTUP.\n");
+ }
+ else if (retVal & FR_STARTUP_ERR_SW_STUP_AS_NCOLD) {
+ rpp_sci_printf("Can not switch to STARTUP as non-coldstarter.\n");
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ }
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Invokes POC command ALLOW_COLDSTART
+ *
+ * Syntax:
+ * frbtallowcs - Invokes POC command ALLOW_COLDSTART.
+ *
+ * The command calls a Fr_AllowColdstart function from the Autosar specification, which
+ * Invokes POC command ALLOW_COLDSTART.
+ *
+ * This function is called automatically in Fr_StartCommunication, so there is no need
+ * to call it manually. This command is for testing purposes.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_allowcoldstart(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ retVal = Fr_AllowColdstart(0);
+ if (retVal & E_OK) {
+ rpp_sci_printf("FlexRay node is coldstarter.\n");
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Invokes POC command ALL_SLOTS
+ *
+ * Syntax:
+ * frbtallslots - Invokes POC command ALL_SLOTS.
+ *
+ * The command calls a Fr_AllSlots function from the Autosar specification, which
+ * Invokes POC command ALL_SLOTS.
+ * FlexRay node may be configured to communicate only in key slots by default.
+ * This command, when called on running FlexRay node, allows it to communicate
+ * in all configured slots.
+ *
+ * If the pSingleSlotEnabled parameter is set to TRUE, this command should be called
+ * after the frbtstart command.
+ * There is no need to call it if pSingleSlotEnabled parameter is set to FALSE.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_allslots(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ retVal = Fr_AllSlots(0);
+ if (retVal & E_OK) {
+ rpp_sci_printf("FlexRay node is communicating in all slots.\n");
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Halt FlexRay communication
+ *
+ * Syntax:
+ * frbthalt - Halt FlexRay communication after actual communication cycle.
+ *
+ * The command calls a Fr_HaltCommunication function from the Autosar specification, which
+ * Invokes POC command DEFERRED_HALT.
+ * The command stops FlexRay node communication after the end of actual communication cycle.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_halt(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ retVal = Fr_HaltCommunication(0);
+ if (retVal & E_OK) {
+ rpp_sci_printf("FlexRay node communication halted.\n");
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Abort FlexRay communication
+ *
+ * Syntax:
+ * frbtabort - Abort FlexRay communication immediately (before the end of the communication cycle)
+ *
+ * The command calls a Fr_AbortCommunication function from the Autosar specification, which
+ * Invokes POC command FREEZE.
+ * The command stops FlexRay node communication immediately.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_abort(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ retVal = Fr_AbortCommunication(0);
+ if (retVal & E_OK) {
+ rpp_sci_printf("FlexRay node communication aborted.\n");
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Send wake up pattern
+ *
+ * Syntax:
+ * frbtwup - Sends wake up pattern on configured channel
+ *
+ * The command calls a Fr_SendWUP function from the Autosar specification, which
+ * invokes POC command WAKEUP that initiates wake up procedure.
+ *
+ * The command should be called before frbtstart, to wake up all sleeping nodes.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_sendwup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ retVal = Fr_SendWUP(0);
+ if (retVal & E_OK) {
+ rpp_sci_printf("Wake up pattern has been sent.\n");
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Set channel for wake up pattern sending.
+ *
+ * Syntax:
+ * frbtsetwuchX - Set wake up channel to X, where X is a character A or B.
+ *
+ * The command calls a Fr_SetWakeupChannel function from the Autosar specification, which
+ * switches POC to CONFIG state, sets the channel for wake up and then switches the POC
+ * to ready state again.
+ *
+ * The command should be called after frbtctrlinit and before frbtstart.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_setwuchannel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ Fr_ChannelType channel = FR_CHANNEL_A;
+ char* p = NULL;
+
+ p = param[1];
+ if (*p == 'A') {
+ channel = FR_CHANNEL_A;
+ }
+ else if (*p == 'B') {
+ channel = FR_CHANNEL_B;
+ }
+ else {
+ return -CMDERR_BADPAR;
+ }
+ retVal = Fr_SetWakeupChannel(0, channel);
+ if (retVal & E_OK) {
+ rpp_sci_printf("Wake up channel has been set.\n");
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Get and print POC status of the FlexRay controller.
+
+ * Syntax:
+ * frbtgetpocst - Get and print POC status of the FlexRay controller.
+ *
+ * The command calls a Fr_GetPOCStatus function from the Autosar specification, which
+ * returns POC status.
+ *
+ * The command should be called after frbtctrlinit.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_getpocstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ Fr_POCStatusType status;
+ char* ErrorModeStrings[] = {"ACTIVE", "HALT", "PASSIVE"};
+ char* SlotModeStrings[] = {"KEYSLOT", "ALL_PENDING", "ALL"};
+ char* StartupStateStrings[] = {
+ "UNDEFINED", "COLDSTART_LISTEN", "COLDSTART_CHECK", "COLDSTART_JOIN",
+ "COLDSTART_CONSISTENCY_CHECK", "INTEGRATION_LISTEN", "INITIALIZE_SCHEDULE", "INTEGRATION_CONSISTENCY_CHECK",
+ "COLDSTART_GAP", "EXTERNAL_STARTUP", "ABORT", "COLDSTART_COLLISION_RESOLUTION",
+ "PREPARE"
+ };
+ char* StateStrings[] = {
+ "CONFIG", "DEFAULT_CONFIG", "HALT", "NORMAL_ACTIVE",
+ "NORMAL_PASSIVE", "READY", "STARTUP", "LOOPBACK",
+ "MONITOR", "WAKEUP"
+ };
+ char* WakeupStatusStrings[] = {
+ "UNDEFINED", "RECEIVED_HEADER", "RECEIVED_WUP", "COLLISION_HEADER",
+ "COLLISION_WUP", "COLLISION_UNKNOWN", "TRANSMITTED"
+ };
+
+ retVal = Fr_GetPOCStatus(0, &status);
+ if (retVal & E_OK) {
+ rpp_sci_printf("POC status:\n");
+ rpp_sci_printf("CHIHaltRequest: %s\n", (status.CHIHaltRequest == TRUE) ? "TRUE" : "FALSE");
+ rpp_sci_printf("CHIReadyRequest: %s\n", (status.CHIReadyRequest == TRUE) ? "TRUE" : "FALSE");
+ rpp_sci_printf("ColdstartNoise: %s\n", (status.ColdstartNoise == TRUE) ? "TRUE" : "FALSE");
+ rpp_sci_printf("Freeze: %s\n", (status.Freeze == TRUE) ? "TRUE" : "FALSE");
+ rpp_sci_printf("ErrorMode: %s\n", ErrorModeStrings[status.ErrorMode]);
+ rpp_sci_printf("SlotMode: %s\n", SlotModeStrings[status.SlotMode]);
+ rpp_sci_printf("StartupState: %s\n", StartupStateStrings[status.StartupState]);
+ rpp_sci_printf("State: %s\n", StateStrings[status.State]);
+ rpp_sci_printf("WakeupStatus: %s\n", WakeupStatusStrings[status.WakeupStatus]);
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/**
+ * @brief Send given data through the FlexRay in selected slot.
+ *
+ * Syntax:
+ * frbttransmitX DATA - Transmit data DATA in slot X. DATA is a sequence of hexadecimal\n
+ * numbers separated by spaces. Each number represents one 32b word of data to be sent.\n
+ * X is a decimal number of the slot, where data will be sent.
+ *
+ * The command calls a Fr_TransmitTxLPdu function from the Autosar specification, which
+ * copies data from the parameter to the output buffer and into message RAM. TX request\n
+ * is set and data will be transfered in next communication cycle.
+ *
+ * The command can be called before and after frbtstart.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_fr_transmittxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+
+ //retVal = Fr_GetPOCStatus(0, &status);
+ if (retVal & E_OK) {
+
+ }
+ else {
+ rpp_sci_printf("General error.\n");
+ return -CMDERR_BADCFG;
+ }
+ return 0;
+}
+
+/** Command descriptor for FlexRay init command */
+cmd_des_t const cmd_des_fr_init={
+ 0, 0,
+ "frbtinit?","\tfrbtinitX - Initialize FlexRay node X, where X is a character A or B.",
+ cmd_do_fr_init, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller init command */
+cmd_des_t const cmd_des_fr_ctrlinit={
+ 0, 0,
+ "frbtctrlinit","\tfrbtctrlinit - Initialize FlexRay node controller.",
+ cmd_do_fr_ctrlinit, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller init command */
+cmd_des_t const cmd_des_fr_start={
+ 0, 0,
+ "frbtstart","\tfrbtstart - Initiate new FlexRay network or join to the existing one.",
+ cmd_do_fr_start, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller allow coldstart command */
+cmd_des_t const cmd_des_fr_allowcoldstart={
+ 0, 0,
+ "frbtallowcs","\tfrbtallowcs - Invokes POC command ALLOW_COLDSTART - just for testing purposes, there is no need to call this command manualy.",
+ cmd_do_fr_allowcoldstart, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller all slots command */
+cmd_des_t const cmd_des_fr_allslots={
+ 0, 0,
+ "frbtallslots","\tfrbtallslots - Invokes POC command ALL_SLOTS.",
+ cmd_do_fr_allslots, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller halt command */
+cmd_des_t const cmd_des_fr_halt={
+ 0, 0,
+ "frbthalts","\tfrbthalt - Halt FlexRay communication after actual communication cycle.",
+ cmd_do_fr_halt, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller abort command */
+cmd_des_t const cmd_des_fr_abort={
+ 0, 0,
+ "frbtabort","\tfrbtabort - Abort FlexRay communication immediately",
+ cmd_do_fr_abort, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller send wake up pattern command */
+cmd_des_t const cmd_des_fr_sendwup={
+ 0, 0,
+ "frbtwup","\tfrbtwup - Initiates wake up procedure.",
+ cmd_do_fr_sendwup, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller sent wake up pattern channel command */
+cmd_des_t const cmd_des_fr_setwuchannel={
+ 0, 0,
+ "frbtsetwuch?","\tfrbtsetwuchX - Set wake up channel to X, where X is a character A or B.",
+ cmd_do_fr_setwuchannel, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay controller get POC status command */
+cmd_des_t const cmd_des_fr_getpocstatus={
+ 0, 0,
+ "frbtgetpocst","\tfrbtgetpocst - Print FlexRay POC status.",
+ cmd_do_fr_getpocstatus, (void *)&cmd_list_fr_basic_test
+};
+
+/** Command descriptor for FlexRay transmit tx lpdu command */
+cmd_des_t const cmd_des_fr_transmittxlpdu={
+ 0, 0,
+ "frbttransmit*","\tfrbttransmitX DATA - Transmit data DATA in slot X. DATA is a sequence of hexadecimal\n"
+ "numbers separated by spaces. Each number represents one 32b word of data to be sent.\n"
+ "X is a decimal number of the slot, where data will be sent.",
+ cmd_do_fr_transmittxlpdu, (void *)&cmd_list_fr_basic_test
+};
/** List of commands for flexRay, defined as external */
cmd_des_t const *cmd_list_fr_basic_test[]={
+ &cmd_des_fr_init,
+ &cmd_des_fr_ctrlinit,
+ &cmd_des_fr_start,
+ &cmd_des_fr_allowcoldstart,
+ &cmd_des_fr_allslots,
+ &cmd_des_fr_halt,
+ &cmd_des_fr_abort,
+ &cmd_des_fr_sendwup,
+ &cmd_des_fr_setwuchannel,
+ &cmd_des_fr_getpocstatus,
+ &cmd_des_fr_transmittxlpdu,
NULL
};