#ifndef _LIN_CONFIG_H_
#define _LIN_CONFIG_H_
+#define LIN_EXIT_OK 1
+
+/* Flags passed to configuration functions */
#define FLASH_CONF_fl (1 << 0)
#define RESET_DEVICE_fl (1 << 1)
#define SLLIN_ATTACH_fl (1 << 2)
int bus_termination; /* LIN bus termination in device -- Master or Slave */
/* Subscriber/publisher table entries */
- struct linc_frame_entry frame_entry[MAX_LIN_ID];
+ struct linc_frame_entry frame_entry[MAX_LIN_ID + 1];
/* Scheduler table entries */
// FIXME max value
struct linc_scheduler_entry scheduler_entry[100];
int flags; /* Flags passed to configuration function
of particular device */
};
-struct linc_lin_state linc_lin_state;
-
#endif /* _LIN_CONFIG_H_ */
linc_lin_state->scheduler_entry[linc_lin_state->scheduler_entries_cnt].interval_ms = interval;
linc_lin_state->scheduler_entries_cnt++;
- //printf("Time = %d Entry = %d\n", interval, linid);
+ //printf("Time = %d Lin ID = %d Entry no. = %d\n",
+ // interval, linid, linc_lin_state->scheduler_entries_cnt-1);
}
cur = cur->next;
}
tmp_node = tmp_node->next;
}
- if (linid >= 0) {
+ if (linid >= 0 && linid <= MAX_LIN_ID) {
memcpy(&linc_lin_state->frame_entry[linid], &tmp_fr_entry,
sizeof(struct linc_frame_entry));
}
char iface[IFNAMSIZ+1];
};
+void sllin_ms_to_timeval(int ms, struct timeval *tv)
+{
+ tv->tv_sec = (int) ms/1000;
+ tv->tv_usec = (ms % 1000) * 1000;
+}
+
+int sllin_cache_config(struct linc_lin_state *linc_lin_state,
+ struct sllin_connection *sllin_connection)
+{
+
+ return 0;
+}
+
int sllin_bcm_config(struct linc_lin_state *linc_lin_state,
struct sllin_connection *sllin_connection)
{
int ret;
int i;
- //printf("tty %s to netdevice %s\n", linc_lin_state->dev, sllin_connection->iface);
-
s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM);
if (s < 0) {
perror("socket(): bcmsocket");
}
for (i = 0; i < linc_lin_state->scheduler_entries_cnt; i++) {
+ struct timeval time;
memset(&msg, 0, sizeof(msg));
+
msg.msg_head.nframes = 1;
msg.msg_head.opcode = TX_SETUP;
msg.msg_head.flags |= SETTIMER | STARTTIMER;
- //msg.msg_head.ival2.tv_sec = // FIXME
- msg.msg_head.ival2.tv_usec =
- linc_lin_state->scheduler_entry[i].interval_ms * 1000;
- msg.msg_head.can_id =
- linc_lin_state->scheduler_entry[i].lin_id | CAN_RTR_FLAG;
+ sllin_ms_to_timeval(
+ linc_lin_state->scheduler_entry[i].interval_ms, &time);
+ msg.msg_head.ival2.tv_sec = time.tv_sec;
+ msg.msg_head.ival2.tv_usec = time.tv_usec;
+ msg.msg_head.can_id = (
+ linc_lin_state->scheduler_entry[i].lin_id | CAN_RTR_FLAG);
msg.frame.can_dlc = 0;
+ msg.frame.can_id = msg.msg_head.can_id;
+
+ //printf("tv_sec = %i, tv_usec = %i\n", time.tv_sec, time.tv_usec);
sendto(s, &msg, sizeof(msg), 0,
(struct sockaddr*)&caddr, sizeof(caddr));
- printf(".\n");
//read_response(s); // FIXME
}
- close(s);
+ /* Do not close "s" to make BCM configuration running */
printf("Configuration finished\n");
return 0;
return -1;
}
- printf("Attached tty %s to netdevice %s\n", linc_lin_state->dev, sllin_connection.iface);
+ printf("Attached tty %s to netdevice %s\n",
+ linc_lin_state->dev, sllin_connection.iface);
}
if (linc_lin_state->flags & SLLIN_DETACH_fl) {
return -1;
}
- printf("Detached sllin line discipline from %s\n", linc_lin_state->dev);
- return 0;
+ printf("Detached sllin line discipline from %s\n",
+ linc_lin_state->dev);
+
+ close(tty);
+ return LIN_EXIT_OK;
}
ret = sllin_bcm_config(linc_lin_state, &sllin_connection);
+ if (ret < 0)
+ return ret;
+
+ ret = sllin_cache_config(linc_lin_state, &sllin_connection);
+
+ /* !!! Do not close "tty" to enable newly
+ configured tty line discipline */
- printf("Press any key to detach %s ...\n", linc_lin_state->dev);
- getchar();
- close(tty);
return ret;
}