Xenomai  3.0.8
tdma.h
1 /***
2  *
3  * include/rtmac/tdma/tdma.h
4  *
5  * RTmac - real-time networking media access control subsystem
6  * Copyright (C) 2002 Marc Kleine-Budde <kleine-budde@gmx.de>,
7  * 2003-2005 Jan Kiszka <Jan.Kiszka@web.de>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  */
24 
25 #ifndef __TDMA_H_
26 #define __TDMA_H_
27 
28 #include <rtdm/driver.h>
29 
30 #include <rtnet_rtpc.h>
31 #include <rtmac/rtmac_disc.h>
32 
33 
34 #define RTMAC_TYPE_TDMA 0x0001
35 
36 #define TDMA_MAGIC 0x3A0D4D0A
37 
38 #define TDMA_FLAG_CALIBRATED 1
39 #define TDMA_FLAG_RECEIVED_SYNC 2
40 #define TDMA_FLAG_MASTER 3 /* also set for backup masters */
41 #define TDMA_FLAG_BACKUP_MASTER 4
42 #define TDMA_FLAG_ATTACHED 5
43 #define TDMA_FLAG_BACKUP_ACTIVE 6
44 
45 #define DEFAULT_SLOT 0
46 #define DEFAULT_NRT_SLOT 1
47 
48 /* job IDs */
49 #define WAIT_ON_SYNC -1
50 #define XMIT_SYNC -2
51 #define BACKUP_SYNC -3
52 #define XMIT_REQ_CAL -4
53 #define XMIT_RPL_CAL -5
54 
55 
56 struct tdma_priv;
57 
58 
59 struct tdma_job {
60  struct list_head entry;
61  int id;
62  unsigned int ref_count;
63 };
64 
65 
66 #define SLOT_JOB(job) ((struct tdma_slot *)(job))
67 
68 struct tdma_slot {
69  struct tdma_job head;
70 
71  u64 offset;
72  unsigned int period;
73  unsigned int phasing;
74  unsigned int mtu;
75  unsigned int size;
76  struct rtskb_prio_queue *queue;
77  struct rtskb_prio_queue local_queue;
78 };
79 
80 
81 #define REQUEST_CAL_JOB(job) ((struct tdma_request_cal *)(job))
82 
83 struct tdma_request_cal {
84  struct tdma_job head;
85 
86  struct tdma_priv *tdma;
87  u64 offset;
88  unsigned int period;
89  unsigned int phasing;
90  unsigned int cal_rounds;
91  u64 *cal_results;
92  u64 *result_buffer;
93 };
94 
95 
96 #define REPLY_CAL_JOB(job) ((struct tdma_reply_cal *)(job))
97 
98 struct tdma_reply_cal {
99  struct tdma_job head;
100 
101  u32 reply_cycle;
102  u64 reply_offset;
103  struct rtskb *reply_rtskb;
104 };
105 
106 struct tdma_priv {
107  unsigned int magic;
108  struct rtnet_device *rtdev;
109  char device_name[32];
110  struct rtdm_driver api_driver;
111  struct rtdm_device api_device;
112 
113 #ifdef ALIGN_RTOS_TASK
114  __u8 __align[(ALIGN_RTOS_TASK -
115  ((sizeof(unsigned int) +
116  sizeof(struct rtnet_device *) +
117  sizeof(struct rtdm_device)
118  ) & (ALIGN_RTOS_TASK-1))
119  ) & (ALIGN_RTOS_TASK-1)];
120 #endif
121  rtdm_task_t worker_task;
122  rtdm_event_t worker_wakeup;
123  rtdm_event_t xmit_event;
124  rtdm_event_t sync_event;
125 
126  unsigned long flags;
127  unsigned int cal_rounds;
128  u32 current_cycle;
129  u64 current_cycle_start;
130  u64 master_packet_delay_ns;
131  nanosecs_rel_t clock_offset;
132 
133  struct tdma_job sync_job;
134  struct tdma_job *first_job;
135  struct tdma_job *current_job;
136  volatile unsigned int job_list_revision;
137 
138  unsigned int max_slot_id;
139  struct tdma_slot **slot_table;
140 
141  struct rt_proc_call *calibration_call;
142  unsigned char master_hw_addr[MAX_ADDR_LEN];
143 
144  rtdm_lock_t lock;
145 
146 #ifdef CONFIG_XENO_DRIVERS_NET_TDMA_MASTER
147  struct rtskb_pool cal_rtskb_pool;
148  u64 cycle_period;
149  u64 backup_sync_inc;
150 #endif
151 
152 #ifdef CONFIG_XENO_OPT_VFILE
153  struct list_head list_entry;
154 #endif
155 };
156 
157 
158 extern struct rtmac_disc tdma_disc;
159 
160 #define print_jobs() do { \
161  struct tdma_job *entry; \
162  rtdm_printk("%s:%d - ", __FUNCTION__, __LINE__); \
163  list_for_each_entry(entry, &tdma->first_job->entry, entry) \
164  rtdm_printk("%d ", entry->id); \
165  rtdm_printk("\n"); \
166 } while (0)
167 
168 #endif /* __TDMA_H_ */
ipipe_spinlock_t rtdm_lock_t
Lock variable.
Definition: driver.h:551
int64_t nanosecs_rel_t
RTDM type for representing relative intervals.
Definition: rtdm.h:49
Real-Time Driver Model for Xenomai, driver API header.
RTDM device.
Definition: driver.h:338
RTDM driver.
Definition: driver.h:249