]> rtime.felk.cvut.cz Git - socketcan-simulink.git/blobdiff - blocks/tlc_c/sfunction_cansetup.tlc
The first round of changes to port RPP code to Linux SocketCAN.
[socketcan-simulink.git] / blocks / tlc_c / sfunction_cansetup.tlc
index 481944c0fbc371ae061a222f2cadc7f86739e60a..f2eec3498b0e35c97327e485af301b982452bdff 100644 (file)
@@ -51,7 +51,7 @@
 
     %% Ensure required header files are included
     %<RppCommonBlockTypeSetup(block, system)>
-       %<LibAddToCommonIncludes("<sys/ti_drv_dmm.h>")>
+       %% %<LibAddToCommonIncludes("<sys/ti_drv_dmm.h>")>
 
        %assign ::rpp_can_config_present = 1
 
 %function Start(block, system) Output
  %openfile buffer
 
+       enum ert_can_msg_types {
+               ERT_CAN_STANDARD,
+               ERT_CAN_EXTENDED,
+               ERT_CAN_MIXED,
+       };
+
+       struct ert_can_channel_config {
+               unsigned int baudrate;
+               const char *net_dev_name;
+       };
+
+       struct ert_can_tx_config {
+               int channel;
+               int id_type;
+               canid_t id;
+               int msg_obj;
+       };
+
+       struct ert_can_rx_config {
+               int channel;
+               int id_type;
+               canid_t id;
+               canid_t mask;
+               int msg_obj;
+       };
+
+       struct ert_can_config {
+               int num_tx_obj;
+               int num_rx_obj;
+               struct ert_can_tx_config *tx_config;
+               struct ert_can_rx_config *rx_config;
+               struct ert_can_channel_config *channel_config;
+       };
+
        #define CAN_TX_COUNT %<Rpp.Can.Tx.NumBlocks>
        #define CAN_RX_COUNT %<Rpp.Can.Rx.NumBlocks>
 
-       struct rpp_can_ctrl_config can_ctrl_cfg[3] = {
+       struct ert_can_channel_config can_channel_config[3] = {
                {
                        .baudrate = %<LibBlockParameterValue(baudrate_can1, 0)>
                },
                {
-                   .baudrate = %<LibBlockParameterValue(baudrate_can2, 0)>
+                       .baudrate = %<LibBlockParameterValue(baudrate_can2, 0)>
                },
                {
-                   .baudrate = %<LibBlockParameterValue(baudrate_can3, 0)>
+                       .baudrate = %<LibBlockParameterValue(baudrate_can3, 0)>
                }
        };
 
-       struct rpp_can_tx_config tx_config[CAN_TX_COUNT] = {
+       struct ert_can_tx_config tx_config[CAN_TX_COUNT] = {
          %foreach id = Rpp.Can.Tx.NumBlocks
                %with Rpp.Can.Tx.Block[id]
                // %<Name>
                {
                  %if %<Type> == 1
-                       .type = RPP_CAN_STANDARD,
+                       .id_type = ERT_CAN_STANDARD,
                  %elseif %<Type> == 2
-                       .type = RPP_CAN_EXTENDED,
+                       .id_type = ERT_CAN_EXTENDED,
                  %else
-                       .type = RPP_CAN_MIXED,
+                       .id_type = ERT_CAN_MIXED,
                  %endif
-                 .controller = %<Controller>,
-                 .msg_obj = %<MsgObj>
+                 .id = %<Id>,
+                 .channel = %<Controller>,
+                 .msg_obj = %<MsgObj>,
                },
                %endwith
          %endforeach
        };
 
-       struct rpp_can_rx_config rx_config[CAN_RX_COUNT] = {
+       struct ert_can_rx_config rx_config[CAN_RX_COUNT] = {
          %foreach id = Rpp.Can.Rx.NumBlocks
                %with Rpp.Can.Rx.Block[id]
                // %<Name>
                {
                  %if %<Type>==1
-                       .type = RPP_CAN_STANDARD,
+                       .id_type = ERT_CAN_STANDARD,
                  %elseif %<Type>==2
-                       .type = RPP_CAN_EXTENDED,
+                       .id_type = ERT_CAN_EXTENDED,
                  %else
-                       .type = RPP_CAN_MIXED,
+                       .id_type = ERT_CAN_MIXED,
                  %endif
-                 .controller = %<Controller>,
-                 .msg_obj = %<MsgObj>,
                  .id = %<Id>,
-                 .mask = %<SPRINTF("%#x", Mask)>
+                 .mask = %<SPRINTF("%#x", Mask)>,
+                 .channel = %<Controller>,
+                 .msg_obj = %<MsgObj>,
                },
                %endwith
          %endforeach
        };
 
-       const struct rpp_can_config can_config = {
+       const struct ert_can_config can_config = {
                .num_tx_obj = CAN_TX_COUNT,
                .num_rx_obj = CAN_RX_COUNT,
                .tx_config = tx_config,
                .rx_config = rx_config,
-               .ctrl = can_ctrl_cfg
+               .channel_config = can_channel_config
        };
 
+        int can_rx_handles[CAN_RX_COUNT];
+
+        int can_tx_handles[CAN_RX_COUNT];
+
        %closefile buffer
        %<LibSetSourceFileSection(LibGetModelDotCFile(), "Declarations", buffer)>
        int returnstatus;
 
-       dmmREG->PC4 = 1<<13; // set CAN_NSTB
-    dmmREG->PC5 = 1<<15; // clr CAN_EN
-       dmmREG->PC5 = 1<<13; // clr CAN_NSTB
-       dmmREG->PC4 = 1<<13; // set CAN_NSTB
-       dmmREG->PC4 = 1<<15; // set CAN_EN
-
        returnstatus = rpp_can_init(&can_config);
-       if (returnstatus == FAILURE) {
-           rpp_sci_printf("CAN driver initialization error.\n");
+       if (returnstatus < 0) {
+           printf("CAN driver initialization error.\n");
        }
        %%else {
-       %%      rpp_sci_printf("CAN communication initialized.\n");
+       %%      printf("CAN communication initialized.\n");
        %%}
  %endfunction