Commit 0bd10713 authored by yoogx's avatar yoogx

* Wrapper API for Star Dundee Mk3 SpaceWire devices

        For openaadl/ocarina#170
parent 8388dba9
include $(top_srcdir)/Makefile.common
AUTOMAKE_OPTIONS = no-dependencies
EXTRA_DIST = $(srcdir)/po_hi_driver_linux_serial.h \
$(srcdir)/po_hi_driver_leon_serial.h \
$(srcdir)/po_hi_driver_leon_eth.h \
$(srcdir)/po_hi_driver_serial_common.h \
$(srcdir)/po_hi_driver_exarm.h \
$(srcdir)/po_hi_driver_exarm_ni_6071e_analog.h \
$(srcdir)/po_hi_driver_exarm_ni_6071e_digital.h \
$(srcdir)/po_hi_driver_usbbrick_spacewire.h \
$(srcdir)/po_hi_driver_rasta_spacewire.h \
$(srcdir)/po_hi_driver_rasta_1553.h \
$(srcdir)/po_hi_driver_rasta_1553_brmlib.h \
$(srcdir)/po_hi_driver_xc4v_fpga.h \
$(srcdir)/po_hi_driver_rasta_serial.h \
$(srcdir)/po_hi_driver_rasta_common.h \
$(srcdir)/po_hi_driver_sockets.h \
$(srcdir)/po_hi_driver_keyboard.h \
$(srcdir)/po_hi_rtems_utils.h $(srcdir)/grspw_api.h \
$(srcdir)/grspw_pkt_lib.h \
$(srcdir)/po_hi_driver_drvmgr_common.h
EXTRA_DIST = $(srcdir)/po_hi_driver_linux_serial.h \
$(srcdir)/po_hi_driver_leon_serial.h \
$(srcdir)/po_hi_driver_leon_eth.h \
$(srcdir)/po_hi_driver_serial_common.h \
$(srcdir)/po_hi_driver_exarm.h \
$(srcdir)/po_hi_driver_exarm_ni_6071e_analog.h \
$(srcdir)/po_hi_driver_exarm_ni_6071e_digital.h \
$(srcdir)/po_hi_driver_usbbrick_spacewire.h \
$(srcdir)/po_hi_driver_rasta_spacewire.h \
$(srcdir)/po_hi_driver_rasta_1553.h \
$(srcdir)/po_hi_driver_rasta_1553_brmlib.h \
$(srcdir)/po_hi_driver_xc4v_fpga.h \
$(srcdir)/po_hi_driver_rasta_serial.h \
$(srcdir)/po_hi_driver_rasta_common.h \
$(srcdir)/po_hi_driver_sockets.h \
$(srcdir)/po_hi_driver_keyboard.h \
$(srcdir)/po_hi_rtems_utils.h $(srcdir)/grspw_api.h \
$(srcdir)/grspw_pkt_lib.h \
$(srcdir)/po_hi_driver_drvmgr_common. $(srcdir)/star_dundee_api.c
CLEANFILES = *~
......
/*
* This is a part of PolyORB-HI-C distribution, a minimal
* middleware written for generated code from AADL models.
* You should use it with the Ocarina toolsuite.
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2018 ESA & ISAE.
*/
#ifndef __STAR_DUNDEE_API_H__
#define __STAR_DUNDEE_API_H__
/* Wrapper for Star Dundee Mk3 API */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include "star-api.h"
#include "star-dundee_types.h"
/** Send message through selectedChannel */
size_t dundee_sending(void* message, int message_size, STAR_CHANNEL_ID selectedChannel);
/** Receive message through selectedChannel */
size_t dundee_receiving(void* message, STAR_CHANNEL_ID selectedChannel);
#endif /*__STAR_DUNDEE_API_H__ */
......@@ -4,31 +4,31 @@ AUTOMAKE_OPTIONS = no-dependencies
SUBDIRS=configuration
C_FILES = $(srcdir)/po_hi_driver_linux_serial.c \
$(srcdir)/po_hi_driver_leon_serial.c \
$(srcdir)/po_hi_driver_leon_eth.c \
$(srcdir)/po_hi_driver_sockets.c \
$(srcdir)/po_hi_driver_rtems_ne2000.c \
$(srcdir)/po_hi_driver_rasta_spacewire.c \
$(srcdir)/po_hi_driver_rasta_common.c \
$(srcdir)/po_hi_driver_exarm.c \
$(srcdir)/po_hi_driver_usbbrick_spacewire.c \
$(srcdir)/po_hi_driver_serial_common.c \
$(srcdir)/po_hi_driver_keyboard.c \
$(srcdir)/po_hi_driver_exarm_ni_6071e_analog.c \
$(srcdir)/po_hi_driver_exarm_ni_6071e_digital.c \
$(srcdir)/po_hi_driver_rasta_1553.c \
$(srcdir)/po_hi_driver_xc4v_fpga.c \
$(srcdir)/po_hi_driver_rasta_1553_brmlib.c \
$(srcdir)/po_hi_driver_rasta_serial.c \
$(srcdir)/grspw_api.c $(srcdir)/grspw_pkt_lib.c \
$(srcdir)/config.c $(srcdir)/config_leon3_drvmgr.c \
$(srcdir)/spwrouter_custom_config.c \
$(srcdir)/po_hi_driver_drvmgr_common.c \
$(srcdir)/po_hi_driver_rtems_drvmgr_spacewire.c \
$(srcdir)/po_hi_driver_rtems_drvmgr_serial.c \
$(srcdir)/po_hi_driver_rtems_drvmgr_ethernet.c \
$(srcdir)/config_leon4_n2x.c
C_FILES = $(srcdir)/po_hi_driver_linux_serial.c \
$(srcdir)/po_hi_driver_leon_serial.c \
$(srcdir)/po_hi_driver_leon_eth.c \
$(srcdir)/po_hi_driver_sockets.c \
$(srcdir)/po_hi_driver_rtems_ne2000.c \
$(srcdir)/po_hi_driver_rasta_spacewire.c \
$(srcdir)/po_hi_driver_rasta_common.c \
$(srcdir)/po_hi_driver_exarm.c \
$(srcdir)/po_hi_driver_usbbrick_spacewire.c \
$(srcdir)/po_hi_driver_serial_common.c \
$(srcdir)/po_hi_driver_keyboard.c \
$(srcdir)/po_hi_driver_exarm_ni_6071e_analog.c \
$(srcdir)/po_hi_driver_exarm_ni_6071e_digital.c \
$(srcdir)/po_hi_driver_rasta_1553.c \
$(srcdir)/po_hi_driver_xc4v_fpga.c \
$(srcdir)/po_hi_driver_rasta_1553_brmlib.c \
$(srcdir)/po_hi_driver_rasta_serial.c \
$(srcdir)/grspw_api.c $(srcdir)/grspw_pkt_lib.c \
$(srcdir)/config.c $(srcdir)/config_leon3_drvmgr.c \
$(srcdir)/spwrouter_custom_config.c \
$(srcdir)/po_hi_driver_drvmgr_common.c \
$(srcdir)/po_hi_driver_rtems_drvmgr_spacewire.c \
$(srcdir)/po_hi_driver_rtems_drvmgr_serial.c \
$(srcdir)/po_hi_driver_rtems_drvmgr_ethernet.c \
$(srcdir)/config_leon4_n2x.c $(srcdir)/star_dundee_api.c
csrc = ${shell $(CYGPATH_U) '$(OCARINA_RUNTIME)/polyorb-hi-c/src/drivers'}
csrc2 = ${shell $(CYGPATH_U) '$(OCARINA_RUNTIME)/polyorb-hi-c/src'}
......
/*
* This is a part of PolyORB-HI-C distribution, a minimal
* middleware written for generated code from AADL models.
* You should use it with the Ocarina toolsuite.
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2018 ESA & ISAE.
*/
#include<po_hi_debug.h>
#include "star_dundee_api.h"
/******************************************************************************/
size_t dundee_sending
(void* message,
int message_size,
STAR_CHANNEL_ID selectedChannel) {
size_t size = message_size;
if (size ==0){
__PO_HI_DEBUG_CRITICAL
("The length of the to-be-sent packet is 0, aborting.\n");
return 0;
}
/* Create a message_size packet to be transmitted, terminated with an EOP */
STAR_STREAM_ITEM *pTxStreamItem;
STAR_SPACEWIRE_ADDRESS *pAddress = NULL;
/* Note: for the moment, message_size is only the size of the data
(without header) */
pTxStreamItem = STAR_createPacket
(pAddress, message, message_size, STAR_EOP_TYPE_EOP);
if (!pTxStreamItem){
__PO_HI_DEBUG_CRITICAL
("Couldn't create the stream item to be transmitted.\n");
return 0;
}
/* Create a transfer operation to transmit the packet */
STAR_TRANSFER_OPERATION *pTxTransOp;
pTxTransOp = STAR_createTxOperation(&pTxStreamItem, 1);
if (!pTxTransOp){
__PO_HI_DEBUG_CRITICAL("Couldn't create the transmit operation.\n");
STAR_destroyStreamItem(pTxStreamItem);
return 0;
}
/* Start transmitting the packet */
(void)STAR_submitTransferOperation(selectedChannel, pTxTransOp);
/* Wait indefinitely on the transmit completing */
STAR_TRANSFER_STATUS status;
status = STAR_waitOnTransferOperationCompletion(pTxTransOp, -1);
if (status != STAR_TRANSFER_STATUS_COMPLETE){
__PO_HI_DEBUG_CRITICAL("Could not transmit packet, error of %d.", status);
return 0;
}
/* Dispose of the transmit operation */
(void)STAR_disposeTransferOperation(pTxTransOp);
/* Destroy the transmit packet */
STAR_destroyStreamItem(pTxStreamItem);
/* Return the size of the data */
return size;
}
/******************************************************************************/
size_t dundee_receiving(void* message, STAR_CHANNEL_ID selectedChannel){
size_t size = 0;
unsigned int receiveBufferLength;
unsigned char *pReceiveBuffer;
/* Create a transfer operation for receiving one packet */
STAR_TRANSFER_OPERATION *pRxTransOp;
pRxTransOp = STAR_createRxOperation(1, STAR_RECEIVE_PACKETS);
if (!pRxTransOp){
__PO_HI_DEBUG_CRITICAL("Couldn't create receive operation, exiting.\n");
return 0;
}
/* Start receiving a packet */
STAR_submitTransferOperation(selectedChannel, pRxTransOp);
/* Wait indefinitely on a packet being received */
STAR_TRANSFER_STATUS status;
status = STAR_waitOnTransferOperationCompletion(pRxTransOp, -1);
if (status != STAR_TRANSFER_STATUS_COMPLETE){
__PO_HI_DEBUG_CRITICAL("Could not receive packet, error of %d.\n", status);
STAR_disposeTransferOperation(pRxTransOp);
return 0;
}
/* Get the stream item received */
STAR_STREAM_ITEM *pRxStreamItem;
pRxStreamItem = STAR_getTransferItem(pRxTransOp, 0);
if (!pRxStreamItem){
__PO_HI_DEBUG_CRITICAL("Unable to get the stream item received. \n");
STAR_disposeTransferOperation(pRxTransOp);
return 0;
}
/* Get the bytes of the packet received */
pReceiveBuffer = STAR_getPacketData((STAR_SPACEWIRE_PACKET *)pRxStreamItem->item,&receiveBufferLength);
if (!pReceiveBuffer){
__PO_HI_DEBUG_CRITICAL("Unable to get the contents of the packet.\n");
STAR_disposeTransferOperation(pRxTransOp);
return 0;
}
/* Here the length is both header and data */
memcpy (message, pReceiveBuffer, receiveBufferLength);
/* Display the bytes in the packet */
__PO_HI_DEBUG_CRITICAL("Received packet contents:\n");
__PO_HI_DEBUG_CRITICAL(" \n");
size = receiveBufferLength;
if (size ==0){
__PO_HI_DEBUG_CRITICAL("The length of the received packet is 0. \n");
}
/* Destroy the buffer containing the received packet, once the
message is copied. */
STAR_destroyPacketData(pReceiveBuffer);
/* Dispose of the receive operation */;
STAR_disposeTransferOperation(pRxTransOp);
return size;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment