Xenomai  3.0-rc7
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_SHUTDOWN 0
39 #define TDMA_FLAG_CALIBRATED 1
40 #define TDMA_FLAG_RECEIVED_SYNC 2
41 #define TDMA_FLAG_MASTER 3 /* also set for backup masters */
42 #define TDMA_FLAG_BACKUP_MASTER 4
43 #define TDMA_FLAG_ATTACHED 5
44 #define TDMA_FLAG_BACKUP_ACTIVE 6
45 
46 #define DEFAULT_SLOT 0
47 #define DEFAULT_NRT_SLOT 1
48 
49 /* job IDs */
50 #define WAIT_ON_SYNC -1
51 #define XMIT_SYNC -2
52 #define BACKUP_SYNC -3
53 #define XMIT_REQ_CAL -4
54 #define XMIT_RPL_CAL -5
55 
56 
57 struct tdma_priv;
58 
59 
60 struct tdma_job {
61  struct list_head entry;
62  int id;
63  unsigned int ref_count;
64 };
65 
66 
67 #define SLOT_JOB(job) ((struct tdma_slot *)(job))
68 
69 struct tdma_slot {
70  struct tdma_job head;
71 
72  u64 offset;
73  unsigned int period;
74  unsigned int phasing;
75  unsigned int mtu;
76  unsigned int size;
77  struct rtskb_prio_queue *queue;
78  struct rtskb_prio_queue local_queue;
79 };
80 
81 
82 #define REQUEST_CAL_JOB(job) ((struct tdma_request_cal *)(job))
83 
84 struct tdma_request_cal {
85  struct tdma_job head;
86 
87  struct tdma_priv *tdma;
88  u64 offset;
89  unsigned int period;
90  unsigned int phasing;
91  unsigned int cal_rounds;
92  u64 *cal_results;
93  u64 *result_buffer;
94 };
95 
96 
97 #define REPLY_CAL_JOB(job) ((struct tdma_reply_cal *)(job))
98 
99 struct tdma_reply_cal {
100  struct tdma_job head;
101 
102  u32 reply_cycle;
103  u64 reply_offset;
104  struct rtskb *reply_rtskb;
105 };
106 
107 struct tdma_priv {
108  unsigned int magic;
109  struct rtnet_device *rtdev;
110  char device_name[32];
111  struct rtdm_driver api_driver;
112  struct rtdm_device api_device;
113 
114 #ifdef ALIGN_RTOS_TASK
115  __u8 __align[(ALIGN_RTOS_TASK -
116  ((sizeof(unsigned int) +
117  sizeof(struct rtnet_device *) +
118  sizeof(struct rtdm_device)
119  ) & (ALIGN_RTOS_TASK-1))
120  ) & (ALIGN_RTOS_TASK-1)];
121 #endif
122  rtdm_task_t worker_task;
123  rtdm_event_t worker_wakeup;
124  rtdm_event_t xmit_event;
125  rtdm_event_t sync_event;
126 
127  unsigned long flags;
128  unsigned int cal_rounds;
129  u32 current_cycle;
130  u64 current_cycle_start;
131  u64 master_packet_delay_ns;
132  nanosecs_rel_t clock_offset;
133 
134  struct tdma_job sync_job;
135  struct tdma_job *first_job;
136  struct tdma_job *current_job;
137  volatile unsigned int job_list_revision;
138 
139  unsigned int max_slot_id;
140  struct tdma_slot **slot_table;
141 
142  struct rt_proc_call *calibration_call;
143  unsigned char master_hw_addr[MAX_ADDR_LEN];
144 
145  rtdm_lock_t lock;
146 
147 #ifdef CONFIG_XENO_DRIVERS_NET_TDMA_MASTER
148  struct rtskb_pool cal_rtskb_pool;
149  u64 cycle_period;
150  u64 backup_sync_inc;
151 #endif
152 
153 #ifdef CONFIG_XENO_OPT_VFILE
154  struct list_head list_entry;
155 #endif
156 };
157 
158 
159 extern struct rtmac_disc tdma_disc;
160 
161 #define print_jobs() do { \
162  struct tdma_job *entry; \
163  rtdm_printk("%s:%d - ", __FUNCTION__, __LINE__); \
164  list_for_each_entry(entry, &tdma->first_job->entry, entry) \
165  rtdm_printk("%d ", entry->id); \
166  rtdm_printk("\n"); \
167 } while (0)
168 
169 #endif /* __TDMA_H_ */
ipipe_spinlock_t rtdm_lock_t
Lock variable.
Definition: driver.h:528
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:321
RTDM driver.
Definition: driver.h:245