Commit 025b60c7 authored by Guilherme Sanches's avatar Guilherme Sanches

New folder introduced under the examples folder. Here it will be

developed the new example of the iop using canbus.
parent fd169139
#include <iop.h>
/**
* @brief IOP remote ports
*/
extern iop_port_t remote_ports[3];
/**
* @brief Logical devices
*/
extern iop_logical_device_t logical_device_0;
extern iop_logical_device_t logical_device_1;
/**
* @brief Physical devices
*/
extern iop_physical_device_t physical_device_0;
/**
* @brief Physical devices list
*/
static iop_physical_device_t *physical_device_list[1] = \
{
&physical_device_0,
};
/**
* @brief Logical devices list
*/
static iop_logical_device_t *logical_device_list[2] = \
{
&logical_device_0,
&logical_device_1,
};
static iop_wrapper_t requests_storage[1024];
/**
* @brief IOP buffers
*/
static iop_buffer_t iop_buffers[1024];
static uint8_t iop_buffers_storage[1024 * IOP_BUFFER_SIZE];
/**
* @brief IOP application configurations
*/
iop_configuration_t usr_configuration = {
.wrappers = requests_storage,
.iop_buffers = iop_buffers,
.iop_buffers_storage = iop_buffers_storage,
.wrappers_count = 1024,
.physical_devices = {
.length = 1,
.elements = physical_device_list
},
.logical_devices = {
.length = 2,
.elements = logical_device_list
},
.remote_ports = {
.length = 3,
.elements = remote_ports
}
};
#include <iop.h>
/**
* @brief Physical devices
*/
extern iop_physical_device_t physical_device_0;
/**
* @brief Routes Headers
*/
static iop_header_t route_header[1] = \
{
{
.eth_header = {
.dst_ip = { 192,168,0,3 },
.dst_mac = { 0x00,0x50,0xbf,0x50,0x07,0x0d},
.dst_port = HTONS(13000),
.src_port = HTONS(13000)
}
}
};
/**
* @brief Routes Scheduling
*/
static uint32_t route_schedule_0[1] = \
{ 1 };
/**
* @brief Routes Configuration
*/
static iop_logical_route_t logical_routes[1] = \
{
{
.schedule = route_schedule_0,
.header = &route_header[0],
.device = &physical_device_0
}
};
/**
* @brief Logical Device configuration
*/
iop_logical_device_t logical_device_0 = \
{
.routes = {
.length = 1,
.elements = logical_routes
},
};
#include <iop.h>
/**
* @brief Physical devices
*/
extern iop_physical_device_t physical_device_0;
/**
* @brief Routes Headers
*/
static iop_header_t route_header[0] = \
{
};
/**
* @brief Routes Scheduling
*/
/**
* @brief Routes Configuration
*/
static iop_logical_route_t logical_routes[0] = \
{
};
/**
* @brief Logical Device configuration
*/
iop_logical_device_t logical_device_1 = \
{
.routes = {
.length = 0,
.elements = logical_routes
},
};
/*
* ============================================================================
* This file was generated by the GMV's Configurator Tool and is part of an I/O
* partition configuration.
* File Purpose: IO Partition user configuration. Contains the configuration
* options for Ethernet's GRETH devices.
* ============================================================================
*/
#include <iop.h>
#include <iop_greth.h>
#include <eth_support.h>
/**
* @brief IOP remote ports
*/
extern iop_port_t remote_ports[3];
/**
* @brief IOP buffers
*/
static iop_buffer_t iop_buffers[64];
static uint8_t iop_buffers_storage[64 * IOP_BUFFER_SIZE];
/**
* @brief TX descriptor to IOP buffer mapping
*/
static iop_buffer_t *tx_iop_buffer[32];
/**
* @brief RX descriptor to IOP buffer mapping
*/
static iop_buffer_t *rx_iop_buffer[32];
/**
* @brief RX and TX descriptor table
* @warning this should be 2048, but we need 3072 to ensure the 0x400 alignment
*/
static uint8_t descriptor_table[3072];
/** @brief GRETH control structure*/
static greth_softc_t greth_driver = \
{
.iop_buffers = iop_buffers,
.iop_buffers_storage = iop_buffers_storage,
/** @note descriptor table address are split and aligned at the runtime */
.txdesc = descriptor_table,
.rxdesc = descriptor_table,
.tx_iop_buffer = tx_iop_buffer,
.rx_iop_buffer = rx_iop_buffer
};
/** @brief GRETH driver configuration */
static iop_eth_device_t device_configuration = \
{
/* device configuration */
.dev = {
.driver = (void *)&greth_driver,
.init = greth_initialize,
.open = greth_open,
.read = greth_read,
.write = greth_write,
.close = greth_close,
},
/* ethernet configuration */
.ip = { 192, 168, 0, 17 },
.mac = { 0x00, 0x50, 0xC2, 0x75, 0xa0, 0x60 },
.rx_count = 32,
.tx_count = 32
};
/**
* @brief Device Scheduling
*/
static uint32_t reads_per_period[] = \
{ 5 };
/**
* @brief Routes Headers
*/
static iop_header_t route_header[2] = \
{
{
.eth_header = {
.dst_ip = { 192,168,0,3 },
.dst_mac = { 0x00,0x50,0xbf,0x50,0x07,0x0d},
.dst_port = HTONS(14000),
.src_port = HTONS(14000)
}
},
{
.eth_header = {
.dst_ip = { 192,168,0,3 },
.dst_mac = { 0x00,0x50,0xbf,0x50,0x07,0x0d},
.dst_port = HTONS(14000),
.src_port = HTONS(14000)
}
}
};
/**
* @brief Routes Scheduling
*/
static uint32_t route_schedule_0[1] = \
{ 1 };
static uint32_t route_schedule_1[1] = \
{ 1 };
/**
* @brief Routes Configuration
*/
static iop_physical_route_t physical_routes[2] =\
{
{
.schedule = route_schedule_0,
.header = &route_header[0],
.port = &remote_ports[2]
},
{
.schedule = route_schedule_1,
.header = &route_header[1],
.port = &remote_ports[1]
}
};
/**
* @brief Pysical Device configuration
*/
iop_physical_device_t physical_device_0 =\
{
.driver = (iop_device_driver_t *)&device_configuration,
.routes = {
.length = 2,
.elements = physical_routes
},
.reads_per_period = reads_per_period,
.reader_task = eth_reader,
.writer_task = eth_writer,
.header_prebuild = eth_prebuild_header,
.header_compare = eth_compare_header,
.header_copy = eth_copy_header,
};
/*
* ============================================================================
* This file was generated by the GMV's Configurator Tool and is part of an I/O
* partition configuration.
* File Purpose: IO Partition user configuration. Contains the routing
* configuration options of the IO Partition.
* ============================================================================
*/
#include <iop.h>
/**
* @brief Logical devices
*/
extern iop_logical_device_t logical_device_0;
extern iop_logical_device_t logical_device_1;
/**
* @brief Queuing ports configurations
*/
static xky_queuing_port_configuration_t queuing_ports[] = {
{
.max_message_size = 1024,
.max_nb_message = 32,
.port_direction = XKY_SOURCE_PORT,
.port_discipline = 0
},
{
.max_message_size = 1024,
.max_nb_message = 32,
.port_direction = XKY_SOURCE_PORT,
.port_discipline = 0
},
};
/**
* @brief Sampling ports configurations
*/
static xky_sampling_port_configuration_t sampling_ports[] = {
{
.max_message_size = 1024,
.refresh_period = 1000,
.port_direction = XKY_DESTINATION_PORT,
},
};
/**
* @brief IOP remote ports
*/
iop_port_t remote_ports[3] = {
{
.type = XKY_SAMPLING_PORT,
.name = "dsampling",
.configuration = &sampling_ports[0],
.device = &logical_device_0
},
{
.type = XKY_QUEUING_PORT,
.name = "sevennumbers",
.configuration = &queuing_ports[0],
.device = NULL
},
{
.type = XKY_QUEUING_PORT,
.name = "soddnumbers",
.configuration = &queuing_ports[1],
.device = NULL
},
};
/* ============================================================================
* Copyright (C) GMVIS Skysoft S.A., 2008-2013
* ============================================================================
* This file is part of the AIR - ARINC 653 Interface in RTEMS - Operating
* system.
* The license and distribution terms for this file may be found in the file
* LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
* ==========================================================================*/
#include <rtems.h>
#include <rtems/rtems/tasks.h>
#include <rtems/rtems/sem.h>
#include <rtems/rtems/clock.h>
#include <a653.h>
#include <imaspex.h>
#include <pprintf.h>
QUEUING_PORT_ID_TYPE qpid;
/*---------------------------------------------------------
* function: test *
* prints a simple string *
------------------------------------------------------------*/
void test(PARTITION_ID_TYPE self_id) {
char msg[1024]="empty\0";
RETURN_CODE_TYPE rc;
MESSAGE_SIZE_TYPE len;
while(1) {
RECEIVE_QUEUING_MESSAGE(qpid, INFINITE_TIME_VALUE, msg, &len, &rc );
if (rc == NO_ERROR) {
pprintf ("Partition %d: %s\n", self_id, msg);
}
}
}
int entry_func() {
RETURN_CODE_TYPE rc;
rtems_name name = 2000;
rtems_mode mode = RTEMS_PREEMPT ;
rtems_mode mode_mask = RTEMS_PREEMPT_MASK;
rtems_id id;
PARTITION_ID_TYPE self_id;
CREATE_QUEUING_PORT("dqueuing", 1024, 32, DESTINATION, FIFO, &qpid, &rc );
if(NO_ERROR != rc){
pprintf("CREATE_QUEUING_PORT error %d\n", rc);
}
GET_PARTITION_ID(&self_id, &rc);
if(NO_ERROR != rc){
pprintf("GET_PARTITION_ID error %d\n", rc);
}
pprintf("Initializing partition %d...\n", self_id);
if (RTEMS_SUCCESSFUL == rtems_task_create (name, 15, 4096, mode, mode_mask, &id)) {
rtems_task_start (id, (rtems_task_entry)test, self_id);
}
SET_PARTITION_MODE(NORMAL, &rc);
if (NO_ERROR != rc){
pprintf("SET_PARTITION_MODE error %d\n", rc);
}
return RTEMS_SUCCESSFUL;
}
/* ============================================================================
* Copyright (C) GMVIS Skysoft S.A., 2008-2013
* ============================================================================
* This file is part of the AIR - ARINC 653 Interface in RTEMS - Operating
* system.
* The license and distribution terms for this file may be found in the file
* LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
* ==========================================================================*/
#include <rtems.h>
#include <rtems/rtems/tasks.h>
#include <rtems/rtems/sem.h>
#include <rtems/rtems/clock.h>
#include <a653.h>
#include <imaspex.h>
#include <pprintf.h>
/*
* gmvs
* Garbage due to lazyness
*
* */
void append_to_message(uint8_t *msg_ptr_, char * to_append, int offset){
int i;
//strlen
for( i = 0; to_append[i] != '\0'; i++);
int length = i;
for(i = 0; i < length; i++){
msg_ptr_[offset+i] = to_append[i];
}
msg_ptr_[offset + length] = '\0';
}
void append_time_to_message(uint8_t *msg_ptr_, rtems_interval time, int offset){
int i, length = 8;
char time_tag[] = "00000000";
for(i = length-1; time > 0 && i > 0; i--){
int digit = time%10;
time_tag[i] = digit + '0';
time /= 10;
}
for(i = 0; i < length; i++){
msg_ptr_[offset+i] = time_tag[i];
}
msg_ptr_[offset + length] = '\0';
}
/*
* end of garbage
* */
SAMPLING_PORT_ID_TYPE SEND_PORT;
/*---------------------------------------------------------
* function: test *
* outputs a simple string via a sampling port *
------------------------------------------------------------*/
void error_message(RETURN_CODE_TYPE rc){
switch(rc){
case INVALID_CONFIG:
pprintf("WRITE_SAMPLING_MESSAGE error Invalid Config\n");
break;
case INVALID_PARAM:
pprintf("WRITE_SAMPLING_MESSAGE error Invalid Param\n");
break;
case INVALID_MODE:
pprintf("WRITE_SAMPLING_MESSAGE error Invalid Mode\n");
break;
}
}
void test(PARTITION_ID_TYPE self_id) {
int i = 0, offset = 0;;
char sample[3] = "S0 ";
/* get the number of ticks per second */
int tps = 1000000 / xky_syscall_get_us_per_tick();
pprintf("TPS %i\n", tps);
RETURN_CODE_TYPE rc = NO_ERROR;
rtems_interval time;
while(1) {
rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &time);
// append_to_message(message, sample, offset);
// append_time_to_message(message, time, 3 + offset);
// append_to_message(message, " ", offset + 3 + 8);
pprintf ("Partition %d at time %d sending: %s\n", self_id, time, sample);
WRITE_SAMPLING_MESSAGE (SEND_PORT, (MESSAGE_ADDR_TYPE )sample, 1024, &rc );
if (NO_ERROR != rc) {
//pprintf("WRITE_SAMPLING_MESSAGE error %d\n", rc);
error_message(rc);
}
offset += 12;
/*identify the string with an integer index*/
i++;
if (i == 10) {
i=0;
}
sample[1] = 0x30 + i;
rtems_task_wake_after(0.7 * tps);
}
}
int entry_func() {
RETURN_CODE_TYPE rc;
rtems_name name = 10000;
rtems_mode mode = RTEMS_PREEMPT ;
rtems_mode mode_mask = RTEMS_PREEMPT_MASK;
rtems_id id;
PARTITION_ID_TYPE self_id;
/*Getting my own partition id*/
GET_PARTITION_ID(&self_id, &rc);
if(NO_ERROR != rc) {
pprintf("GET_PARTITION_ID error %d\n", rc);
}
pprintf("Initializing partition %d...\n", self_id);
/*Creating Source sampling Port*/
SAMPLING_PORT_NAME_TYPE NAME = "ssampling";
MESSAGE_SIZE_TYPE SIZE = 1024;
SYSTEM_TIME_TYPE PERIOD= 1000000000ll;
CREATE_SAMPLING_PORT (NAME, SIZE, SOURCE, PERIOD, &SEND_PORT, &rc);
if (NO_ERROR != rc) {
pprintf("CREATE_SAMPLING_PORT error %d\n", rc);
}
if (RTEMS_SUCCESSFUL == rtems_task_create (name, 15, 4096, mode, mode_mask, &id)) {
rtems_task_start (id, test, self_id);
}
SET_PARTITION_MODE(NORMAL, &rc);
if (NO_ERROR != rc) {
pprintf("SET_PARTITION_MODE error %d\n", rc);
}
return RTEMS_SUCCESSFUL;
}
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