}
}
}
- }
+
rpp_sci_printf("Messages transmitted: %d/100\r\n", messagesTransmitted);
rpp_sci_printf("Messages received: %d/100\r\n", messagesReceived);
rpp_sci_printf("TX timeouts: %d\r\n", txTimeOutCnt);
return 0;
}
+}
+
+
+static struct rpp_can_ctrl_config ctrl_config[] = {
+ {
+ .baudrate = 500000
+ },
+ {
+ .baudrate = 500000
+ },
+ {
+ .baudrate = 500000
+ }
+};
+
+static struct rpp_can_tx_config tx_config[] = {
+ {
+ .type = RPP_CAN_EXTENDED,
+ .controller = 1,
+ .msg_obj = 2,
+ },
+ {
+ .type = RPP_CAN_EXTENDED,
+ .controller = 2,
+ .msg_obj = 2,
+ },
+ {
+ .type = RPP_CAN_EXTENDED,
+ .controller = 3,
+ .msg_obj = 2,
+ }
+};
+
+static struct rpp_can_rx_config rx_config[] = {
+ {
+ .type = RPP_CAN_MIXED,
+ .controller = 1,
+ .msg_obj = 1,
+ .id = 1,
+ .mask = 0,
+ },
+ {
+ .type = RPP_CAN_EXTENDED,
+ .controller = 2,
+ .msg_obj = 1,
+ .id = 1,
+ .mask = 0,
+ },
+ {
+ .type = RPP_CAN_MIXED,
+ .controller = 3,
+ .msg_obj = 1,
+ .id = 1,
+ .mask = 0,
+ }
+};
+
+static struct rpp_can_config can_config = {
+ .num_tx_obj = 3,
+ .num_rx_obj = 3,
+ .tx_config = tx_config,
+ .rx_config = rx_config,
+ .ctrl = ctrl_config,
+};
+
+
+int cmd_do_can_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ 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
+
+
+
+ return rpp_can_init(&can_config);
+}
+
+
+int cmd_do_can_send(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ uint32_t controller_id;
+ uint32_t i, l = 0;
+ int ret;
+ struct rpp_can_pdu pdu;
+ char *p, *s;
+
+ int ERR = 1;
+
+ p = param[1];
+ ret = sscanf(p, "%i %i%n", &controller_id, &pdu.id, &l);
+ if (ret < 2)
+ {
+ rpp_sci_printf("Cannot parse parameter %d\n", ret+1);
+ return -CMDERR_BADPAR;
+ }
+ p += l;
+
+ i = 0;
+ do {
+ ret = sscanf(p, "%2hhx%n", &pdu.data[i], &l);
+ if (ret < 1) break;
+ i++;
+ p += l;
+ } while (1);
+
+ pdu.dlc = i;
+
+
+ rpp_sci_printf("Testing CAN send, sending message\n");
+ if (rpp_can_write(controller_id-1, &pdu) == SUCCESS)
+{
+ rpp_sci_printf("can%u\t%X\t[%u]\t", controller_id, pdu.id, pdu.dlc);
+ for (i=0; i<pdu.dlc; i++)
+ {
+ rpp_sci_printf("%X ", pdu.data[i]);
+ }
+}
+else
+{
+rpp_sci_printf("Error: rpp_can_write");
+}
+ rpp_sci_printf("\n");
+
+
+ return 0;
+}
+
+
+int cmd_do_can_dump(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ uint32_t controller_id = 0;
+ bool rx_ind;
+ struct rpp_can_pdu pdu;
+
+ uint32_t i;
+
+ if (!(sscanf(*param+8, "%u", &controller_id) == 1))
+ {
+ rpp_sci_printf("Unable to parse controller ID\n");
+ return 1;
+ }
+
+ rpp_can_init(&can_config);
+
+ while(cmd_io->getc(cmd_io) < 0)
+ {
+ rpp_can_check_rx_ind(controller_id-1, &rx_ind);
+ if (rx_ind)
+ {
+ rpp_can_read(controller_id-1, &pdu);
+ rpp_sci_printf("Read something\n");
+ }
+ }
+
+ return 0;
+}
+
+
+
#endif /* DOCGEN */
/** @brief command descriptor for test CAN loopback command */
CMD_HANDLER(cmd_do_test_can_loopback), (void *)&cmd_list_can
};
+
+cmd_des_t const cmd_des_can_init={
+ 0, 0,
+ "caninit", "Initialize CAN controllers",
+ "Will (maybe) implement later :)",
+ CMD_HANDLER(cmd_do_can_init), (void *)&cmd_list_can
+};
+
+cmd_des_t const cmd_des_can_send={
+ 0, 0,
+ "cansend", "Test sending message over CAN",
+ "Will (maybe) implement later :)",
+ CMD_HANDLER(cmd_do_can_send), (void *)&cmd_list_can
+};
+
+
+cmd_des_t const cmd_des_can_dump={
+ 0, 0,
+ "candump", "Dump all messages received over CAN",
+ "Will (maybe) add later :)",
+ CMD_HANDLER(cmd_do_can_dump), (void *)&cmd_list_can
+};
+
+
+
cmd_des_t const *cmd_list_can[]={
&cmd_des_test_can_loopback,
+ &cmd_des_can_init,
+ &cmd_des_can_send,
+ &cmd_des_can_dump,
NULL
};