grspw_api.h 4.16 KB
Newer Older
yoogx's avatar
yoogx committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#ifndef __GRSPW_API_H__
#define __GRSPW_API_H__

/* This unit provides a high-level set of help functions for the new
 * GRSPW packet driver. See RCC 1.3 Chapter 18 documentation for
 * details.
 *
 * Note: this implementation relies on elements from the grspw-test
 * sample program provided in RCC 1.3rc4 by Cobham Gaisler, and the
 * grspw_pkt_lib auxiliary library.
 */

#include <drvmgr/drvmgr_confdefs.h>
#include <bsp/grspw_pkt.h>
#include <bsp/grspw_router.h>

#include <stddef.h>

#include "grspw_pkt_lib.h"

#include <po_hi_messages.h>

Antonia Francis's avatar
Antonia Francis committed
23
#define DEVS_MAX 32 /* Maximum number of devices supported */
yoogx's avatar
yoogx committed
24

Antonia Francis's avatar
Antonia Francis committed
25
#define PKT_SIZE __PO_HI_MESSAGES_MAX_SIZE + 42 /* Size of the packets exchanged */
yoogx's avatar
yoogx committed
26

Antonia Francis's avatar
Antonia Francis committed
27 28 29 30
/**
 * \struct grspw_device.
 * \brief Structure representing a GRPSW device.
 */
yoogx's avatar
yoogx committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
struct grspw_device {
  /* GRSPW Device layout - must be the same as 'struct grspw_dev' */
  void *dh;
  /* Array of DMA Channels */
  void *dma[4];
  int index;
  /* Structure to describe the GRSPW hardware capabilities */
  struct grspw_hw_sup hwsup;
  /* Test structures */
  struct grspw_config cfg;
  int run;
  /* RX and TX lists of packet buffers */
  struct grspw_list rx_list, tx_list, tx_buf_list,rx_buf_list;
  int rx_list_cnt, tx_list_cnt, tx_buf_list_cnt, rx_buf_list_cnt;
};

/** Array listing all GRSPW devices */
static struct grspw_device devs[DEVS_MAX];

Antonia Francis's avatar
Antonia Francis committed
50 51 52 53 54 55 56 57 58 59
/**
 * \brief Auxiliary Initialization function to initialize the devices.
 * 
 * Application thread : \n
 * TDRX. SpaceWire DMA RX task. Handles reception of SpaceWire
 *        packets on all SpaceWire devices. \n
 * TDTX. SpaceWire DMA RX task. Handles transmission of SpaceWire
 *        packets on all SpaceWire devices. \n
 * Then Semaphores : dma_sync_rx and dma_sync tx. \n
 * Then the reception and transmission tasks are started. \n
yoogx's avatar
yoogx committed
60 61 62
 */
void grspw_api_init(void);

Antonia Francis's avatar
Antonia Francis committed
63 64 65 66 67 68 69
/**
 * \brief Function that close and clean a GRSPW-device.
 * 
 * All dma channels need to be closed before closing the device. \n
 * Error messages are returned whether the dma isn't closed correctly,
 * Or if it's the case for the device. \n
 * \param idx identifier of the device.
yoogx's avatar
yoogx committed
70 71 72
 */
void dev_cleanup(int idx);

Antonia Francis's avatar
Antonia Francis committed
73 74 75 76
/**
 * \struct route_entry;
 * \brief SpaceWire Routing table entry.
 */
yoogx's avatar
yoogx committed
77 78 79 80 81
struct route_entry {
  unsigned char dstadr[16];
  /* 0 terminates array */
};

Antonia Francis's avatar
Antonia Francis committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/**
 * \brief Function following a sending process.
 *
 * A packet is taken at the head of the tx_buf_list. \n
 * Its data content is extracted from the "message" parameter. \n
 * Its header is initialized according to the content of the p_route parameter. \n
 * Its length is initalized thanks to the message_size parameter. \n
 * The pkt is then added to the tx_list (to be sent). \n
 * The dma_sem semaphore is used so that the tasks don't overlap. \n
 * The dma_sync_tx is used so that the task isn't periodic but is triggered 
 * only when something is about to be sent. \n
 * The function is called in the main task and used with the sending command (x). \n
 * 
 * \param device the identifier of the device.
 * \param p_route a pointer toward the spacewire routing table.
 * \param message which will contain the message.
 * \param message_size the size of the message sent.
 * \return size the size of the message sent.
 */
yoogx's avatar
yoogx committed
101 102 103 104 105
size_t grspw_sending
  (int device,
   struct route_entry * p_route,
   void *message, int message_size);

Antonia Francis's avatar
Antonia Francis committed
106 107 108 109 110 111 112 113 114
/**
 * \brief Function following a receiving process.
 *
 * A packet is taken at the head of the tx_buf_list (of the specified device). \n
 * Its data content is extracted from the "message" parameter. \n
 * Its header is initialized according to the content of the p_route parameter. \n
 * Its length is initalized thanks to the message_size parameter. \n 
 * The pkt is then added to the tx_list (to be sent). \n
 * The dma_sem semaphore is used so that the tasks don't overlap. \n
yoogx's avatar
yoogx committed
115
 * The dma_sync_rx is used so that the task isn't periodic but is triggered
Antonia Francis's avatar
Antonia Francis committed
116 117 118 119 120 121 122
 * only when something is about to be received. \n
 * The function is called in the main Task, used qith the receiving command (r). \n
 * 
 * \param device the identifier of the device.
 * \param message which will contain the message.
 * \return size the size of the message received.
 */
yoogx's avatar
yoogx committed
123 124 125 126
size_t grspw_receiving(int device,void *message);


#endif /*__GRSPW_API_H__ */