tte_api.h

Go to the documentation of this file.
00001 /***********************************************************************
00002  * Copyright (c) 2007, TTTech Computertechnik AG
00003  ***********************************************************************
00004  * File           : tte_api.h
00005  * Author(s)      : Petr Grillinger
00006  * Created        : Mar. 13, 2007
00007  * Compatibility  : ANSI C
00008  * Depends on     : <stdint.h> types
00009  * Description    : TTEthernet application interface
00010  ***********************************************************************
00011  * $Id: tte_api.h 28911 2009-09-17 07:53:25Z grillinger $
00012  ***********************************************************************/
00013 
00022 #ifndef _TTE_API_H_
00023 #define _TTE_API_H_
00024 
00025 /* This is needed when the API is linked with C++ programs. It guarantees
00026  * that the linker always handles the functions with C semantics. */
00027 #ifdef __cplusplus
00028     extern "C" {
00029 #endif /* __cplusplus */
00030 
00031 /*#ifdef __STRICT_ANSI__*/
00032 #   define TTE_INLINE
00033 /*#else
00034 #   define TTE_INLINE inline
00035 #endif*/
00036 
00061 #define TTE_API_HDR_VER ( (int32_t) (0x02<<16 | 0x0000) )
00062 
00063 
00075 typedef uint64_t tte_time_t;
00076 
00077 
00083 typedef enum {
00084     TTE_DIR_INPUT  = 1,   
00085     TTE_DIR_OUTPUT = 2,   
00086     TTE_DIR_INOUT  = 3,   
00087 } tte_direction_t;
00088 
00089 
00094 typedef enum {
00095     TTE_TT_TRAFFIC = 0,   
00096     TTE_BG_TRAFFIC = 2,   
00097     TTE_CT_TRAFFIC = 3    
00098 } tte_traffic_type_t;
00099 
00100 
00102 typedef struct {
00104     uint8_t  dst_mac[6];
00106     uint8_t  src_mac[6];
00108     uint16_t type;
00109 } __attribute__((__packed__)) tte_eth_hdr_t;
00110 
00111 
00118 typedef struct {
00121     uint8_t     empty_data;
00122 
00126     uint8_t     fresh_data;
00127 
00130     uint8_t     locked;
00131 
00134     uint8_t     free_entries;
00135 
00139     uint8_t     dropped_frames;
00140 
00144     tte_time_t  timestamp;
00145 } tte_buf_status_t;
00146 
00147 
00156 typedef struct {
00158     uint8_t ctrl_id;
00159 
00162     uint8_t direction;
00163 
00166     uint8_t traffic_type;
00167 
00170     uint8_t  channel;
00171 
00173     uint16_t ct_id;
00174 
00177     uint8_t shared;
00178 
00180     void *priv;
00181 } tte_buffer_t;
00182 
00183 
00187 typedef struct {
00189     uint16_t      length;
00190 
00192     tte_eth_hdr_t eth_hdr;
00193 
00195     uint8_t      *data;
00196 
00198     uint16_t      ct_id;
00199 
00201     uint8_t       channel;
00202 } tte_frame_t;
00203 
00204 
00214 typedef uint32_t tte_ctrl_status_t;
00215 
00216 
00220 #define TTE_STAT_RUNNING         ((uint32_t)1)
00221 
00226 #define TTE_STAT_CONFIGURED      ((uint32_t)2)
00227 
00231 #define TTE_STAT_BOOTSTRAP       ((uint32_t)4)
00232 
00235 #define TTE_STAT_SYNCHRONIZED    ((uint32_t)8)
00236 
00240 #define TTE_STAT_ERROR           ((uint32_t)16)
00241 
00242 
00252 typedef enum {
00253 
00263     TTE_VAR_LINK_STATUS = 4096,
00264 
00275     TTE_VAR_CTRL_STATUS,
00276 
00282     TTE_VAR_CTRL_COUNT,
00283 
00289     TTE_VAR_CHANNEL_COUNT,
00290 
00298     TTE_VAR_TIME_RESOLUTION,
00299 
00318     TTE_VAR_API_VERSION,
00319 
00327     TTE_VAR_THREAD_SAFE,
00328 
00338     TTE_VAR_MAC_ADDRESS,
00339 } tte_var_id_t;
00340 
00341 
00356 typedef enum {
00357 
00365     TTE_BUFVAR_RECEIVE_CB = 8192,
00366 
00376     TTE_BUFVAR_TRANSMIT_CB,
00377 
00384     TTE_BUFVAR_CB_ARG,
00385 
00399     TTE_BUFVAR_DMA_OUTPUT,
00400 
00416     TTE_BUFVAR_DMA_INPUT,
00417 } tte_buf_var_id_t;
00418 
00419 
00423 typedef struct {
00426     uint32_t *data;
00427 
00429     uint32_t length;
00430 } tte_conf_t;
00431 /* @} basic_api_types ***************************************************/
00432 
00433 
00434 
00445 typedef enum {
00447     ETT_NULLPTR      = -9999,
00449     ETT_NOMEM        = -9998,
00451     ETT_INVCTRL      = -9997,
00453     ETT_IO           = -9996,
00455     ETT_INVCHAN      = -9995,
00457     ETT_INVMSGID     = -9994,
00459     ETT_FAILED       = -9992,
00461     ETT_CONFIG       = -9991,
00463     ETT_INVSIZE      = -9989,
00465     ETT_NOMSG        = -9988,
00467     ETT_LINKLOST     = -9987,
00469     ETT_SYNC         = -9984,
00471     ETT_NOINIT       = -9979,
00473     ETT_NOTSUPPORTED = -9978,
00475     ETT_DEADLINE     = -9977,
00477     ETT_TIMEOUT      = -9976,
00479     ETT_NOSPC        = -9975,
00481     ETT_AGAIN        = -9974,
00483     ETT_INITIALIZED  = -9973,
00485     ETT_DMA_NOT_DONE = -9972,
00487     ETT_NO_DMA_MEM   = -9971,
00489     ETT_DMA_BUF_BUSY = -9970,
00491     ETT_DMA_BUSY     = -9969,
00493     ETT_SUCCESS      = 0
00494 } tte_retval_t;
00495 /* @} return_codes ******************************************************/
00496 
00497 
00498 
00499 
00517 extern int32_t tte_init(void);
00518 
00519 
00531 extern int32_t tte_start(const uint8_t ctrl_id);
00532 
00533 
00542 extern int32_t tte_stop(const uint8_t ctrl_id);
00543 
00544 
00551 extern int32_t tte_exit(void);
00552 
00553 
00565 extern int32_t tte_configure(const uint8_t ctrl_id,
00566                              const tte_conf_t * const conf);
00567 
00568 
00586 extern int32_t tte_set_var(const uint8_t ctrl_id,
00587                            const tte_var_id_t var_id,
00588                            const uint32_t var_size,
00589                            const void * const value);
00590 /* @} functions_ctrl_flow ***********************************************/
00591 
00592 
00593 
00594 
00618 extern int32_t tte_get_var(const uint8_t ctrl_id,
00619                            const tte_var_id_t var_id,
00620                            const uint32_t var_size,
00621                            void * const value);
00622 
00623 
00633 __attribute__((__unused__))
00634 static TTE_INLINE uint32_t tte_get_api_version(void)
00635 {
00636     uint32_t ver;
00637     tte_get_var(0, TTE_VAR_API_VERSION, sizeof(ver), &ver);
00638     return ver;
00639 }
00640 
00641 
00649 __attribute__((__unused__))
00650 static TTE_INLINE int32_t tte_get_controller_cnt(void)
00651 {
00652     uint8_t cnt;
00653     int32_t ret;
00654     ret = tte_get_var(0, TTE_VAR_CTRL_COUNT, sizeof(cnt), &cnt);
00655     return (ret >= 0) ? cnt : ret;
00656 }
00657 
00658 
00671 __attribute__((__unused__))
00672 static TTE_INLINE int32_t tte_get_channel_cnt(const uint8_t ctrl_id)
00673 {
00674     uint8_t cnt;
00675     int32_t ret;
00676     ret = tte_get_var(ctrl_id, TTE_VAR_CHANNEL_COUNT, sizeof(cnt), &cnt);
00677     return (ret >= 0) ? cnt : ret;
00678 }
00679 
00680 
00695 __attribute__((__unused__))
00696 static TTE_INLINE int32_t tte_get_time_resolution(const uint8_t ctrl_id,
00697                                        tte_time_t * const resolution)
00698 {
00699     return tte_get_var(ctrl_id, TTE_VAR_TIME_RESOLUTION,
00700             sizeof(*resolution), resolution);
00701 }
00702 
00703 
00719 __attribute__((__unused__))
00720 static TTE_INLINE int32_t tte_get_link_status (const uint8_t ctrl_id,
00721                                     const uint8_t channel,
00722                                     uint8_t * const link_up)
00723 {
00724     int32_t ret;
00725     ret = tte_get_var(ctrl_id, TTE_VAR_LINK_STATUS,
00726             sizeof(*link_up), link_up);
00727     if (ret == ETT_SUCCESS) {
00728         *link_up >>= channel;
00729     }
00730     return ret;
00731 }
00732 
00733 
00748 __attribute__((__unused__))
00749 static TTE_INLINE int32_t tte_get_ctrl_status(const uint8_t ctrl_id,
00750                                    tte_ctrl_status_t * const status)
00751 {
00752     return tte_get_var(ctrl_id, TTE_VAR_CTRL_STATUS,
00753             sizeof(*status), status);
00754 }
00755 
00756 
00920 extern int32_t tte_get_ct_input_buf(const uint8_t ctrl_id,
00921                                     const uint16_t ct_id,
00922                                     tte_buffer_t * const buf);
00923 
00924 
00937 extern int32_t tte_get_ct_output_buf(const uint8_t ctrl_id,
00938                                      const uint16_t ct_id,
00939                                      tte_buffer_t * const buf);
00940 
00941 
00953 extern int32_t tte_get_bg_input_buf(const uint8_t ctrl_id,
00954                                     const uint8_t channel,
00955                                     tte_buffer_t * const buf);
00956 
00957 
00974 extern int32_t tte_get_bg_output_buf(const uint8_t ctrl_id,
00975                                      const uint8_t channel,
00976                                      tte_buffer_t * const buf);
00977 
00978 
00998 extern int32_t tte_write_output_buf(tte_buffer_t * const buf,
00999                                     tte_frame_t * const frame);
01000 
01001 
01025 extern int32_t tte_read_input_buf(tte_buffer_t * const buf,
01026                                   tte_frame_t * const frame,
01027                                   tte_buf_status_t * const status);
01028 
01029 
01058 extern int32_t tte_open_input_buf(tte_buffer_t * const buf,
01059                                   tte_frame_t * const frame,
01060                                   tte_buf_status_t * const status);
01061 
01062 
01076 extern int32_t tte_close_input_buf(tte_buffer_t * const buf);
01077 
01078 
01098 extern int32_t tte_open_output_buf(tte_buffer_t * const buf,
01099                                    tte_frame_t * const frame);
01100 
01101 
01114 extern int32_t tte_close_output_buf(tte_buffer_t * const buf);
01115 
01116 
01136 extern int32_t tte_get_buf_var(const tte_buffer_t * const buf,
01137                                const tte_buf_var_id_t var_id,
01138                                const uint32_t var_size,
01139                                void * const value);
01140 
01141 
01161 extern int32_t tte_set_buf_var(tte_buffer_t * const buf,
01162                                const tte_buf_var_id_t var_id,
01163                                const uint32_t var_size,
01164                                const void * const value);
01165 
01170 extern int32_t tte_flush_buffers(const uint8_t ctrl_id);
01171 
01172 
01177 extern int32_t tte_flush_tt_buffers(const uint8_t ctrl_id);
01178 
01179 
01185 extern int32_t tte_flush_bg_buffers(const uint8_t ctrl_id, const uint8_t channel);
01186 
01187 
01189 __attribute__((__unused__))
01190 static TTE_INLINE int32_t tte_get_tt_input_buf(const uint8_t ctrl_id,
01191                                            const uint16_t ct_id,
01192                                            tte_buffer_t * const buf)
01193 {
01194     return tte_get_ct_input_buf(ctrl_id, ct_id, buf);
01195 }
01196 
01197 
01199 __attribute__((__unused__))
01200 static TTE_INLINE int32_t tte_get_tt_output_buf(const uint8_t ctrl_id,
01201                                             const uint16_t ct_id,
01202                                             tte_buffer_t * const buf)
01203 {
01204     return tte_get_ct_output_buf(ctrl_id, ct_id, buf);
01205 }
01206 
01207 
01208 /* @} functions_indirect_trans ******************************************/
01209 
01210 
01211 
01212 
01246 __attribute__((__unused__))
01247 static TTE_INLINE int32_t tte_write_ct_msg(const uint8_t ctrl_id,
01248                                        tte_frame_t * const frame)
01249 {
01250     tte_buffer_t buf;
01251     int32_t ret;
01252 
01253     ret = tte_get_ct_output_buf(ctrl_id, frame->ct_id, &buf);
01254     if (ret == ETT_SUCCESS)
01255         ret = tte_write_output_buf(&buf, frame);
01256     return ret;
01257 }
01258 
01259 
01281 __attribute__((__unused__))
01282 static TTE_INLINE int32_t tte_read_ct_msg(const uint8_t ctrl_id,
01283                                       tte_frame_t * const frame,
01284                                       tte_buf_status_t * const status)
01285 {
01286     tte_buffer_t buf;
01287     int32_t ret;
01288 
01289     ret = tte_get_ct_input_buf(ctrl_id, frame->ct_id, &buf);
01290     if (ret == ETT_SUCCESS)
01291         ret = tte_read_input_buf(&buf, frame, status);
01292     return ret;
01293 }
01294 
01295 
01312 __attribute__((__unused__))
01313 static TTE_INLINE int32_t tte_write_bg_msg(const uint8_t ctrl_id,
01314                                 tte_frame_t * const frame)
01315 {
01316     tte_buffer_t buf;
01317     int32_t ret;
01318 
01319     ret = tte_get_bg_output_buf(ctrl_id, frame->channel, &buf);
01320     if (ret == ETT_SUCCESS)
01321         ret = tte_write_output_buf(&buf, frame);
01322     return ret;
01323 }
01324 
01325 
01343 __attribute__((__unused__))
01344 static TTE_INLINE int32_t tte_read_bg_msg(const uint8_t ctrl_id,
01345                                       tte_frame_t * const frame,
01346                                       tte_buf_status_t * const status)
01347 {
01348     tte_buffer_t buf;
01349     int32_t ret;
01350 
01351     ret = tte_get_bg_input_buf(ctrl_id, frame->channel, &buf);
01352     if (ret == ETT_SUCCESS)
01353         ret = tte_read_input_buf(&buf, frame, status);
01354     return ret;
01355 }
01356 
01358 __attribute__((__unused__))
01359 static TTE_INLINE int32_t tte_write_tt_msg(const uint8_t ctrl_id,
01360                                        tte_frame_t * const frame)
01361 {
01362     return tte_write_ct_msg(ctrl_id, frame);
01363 }
01364 
01365 
01367 __attribute__((__unused__))
01368 static TTE_INLINE int32_t tte_read_tt_msg(const uint8_t ctrl_id,
01369                                       tte_frame_t * const frame,
01370                                       tte_buf_status_t * const status)
01371 {
01372     return tte_read_ct_msg(ctrl_id, frame, status);
01373 }
01374 
01375 /* @} functions_direct_trans ********************************************/
01376 /* @} basic_api_functions ***********************************************/
01377 
01378 
01379 #ifdef __cplusplus
01380 }                               /* closing brace for extern "C" */
01381 #endif
01382 
01383 #endif                          /* _TTE_API_H_ */
Generated on Tue Nov 29 14:09:18 2011 for TTEthernet Model for INET Framework by  doxygen 1.6.3