Commit a7865996 authored by Bruno Gomes's avatar Bruno Gomes

AIR Examples: Update Can example

refs #192377
parent e19ffa73
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ARINC_653_Module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ModuleName="iop_example">
<ARINC_653_Module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ModuleName="iop_can">
<!-- Partition 1 -->
<Partition PartitionIdentifier="1" PartitionName="partition1"
Criticality="LEVEL_A" EntryPoint="entry_func" SystemPartition="false">
<Sampling_Port Name="partition_receiver"
Direction="DESTINATION" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<Sampling_Port Name="partition_receiver2"
Direction="DESTINATION" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<Sampling_Port Name="partition_sender"
Direction="SOURCE" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<Sampling_Port Name="partition_sender2"
Direction="SOURCE" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<PartitionConfiguration Personality="RTEMS5" Cores="1">
<Libs>LIBAIR; IMASPEX; LIBPRINTF</Libs>
<Devices></Devices>
......@@ -18,14 +22,18 @@
</Permissions>
</PartitionConfiguration>
</Partition>
<!-- Partition 2 -->
<Partition PartitionIdentifier="2" PartitionName="iop"
Criticality="LEVEL_A" EntryPoint="empty" SystemPartition="true">
<Sampling_Port Name="iop_sender"
Direction="SOURCE" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<Sampling_Port Name="iop_sender2"
Direction="SOURCE" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<Sampling_Port Name="iop_receiver"
Direction="DESTINATION" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<Sampling_Port Name="iop_receiver2"
Direction="DESTINATION" MaxMessageSize="8" RefreshRateSeconds="1.0"/>
<PartitionConfiguration Personality="Bare" IOP="iop.xml" Cores="1">
<Libs>LIBIOP</Libs>
<Devices></Devices>
......@@ -34,9 +42,9 @@
<Permissions>
SUPERVISOR;
</Permissions>
</PartitionConfiguration>
</PartitionConfiguration>
</Partition>
<!-- Schedule 1 -->
<Module_Schedule ScheduleIdentifier="1" ScheduleName="schedule"
InitialModuleSchedule="true" MajorFrameSeconds="1.0">
......@@ -64,19 +72,38 @@
PortName="iop_receiver"/>
</Destination>
</Channel>
<Channel ChannelIdentifier="1" ChannelName="MessageIn2">
<Source>
<Standard_Partition PartitionIdentifier="1" PartitionName="partition1"
PortName="partition_sender2"/>
</Source>
<Destination>
<Standard_Partition PartitionIdentifier="2" PartitionName="iop"
PortName="iop_receiver2"/>
</Destination>
</Channel>
<Channel ChannelIdentifier="2" ChannelName="MessageOut">
<Source>
<Standard_Partition PartitionIdentifier="2" PartitionName="iop"
PortName="iop_sender"/>
</Source>
<Destination>
<Standard_Partition PartitionIdentifier="1" PartitionName="partition1"
PortName="partition_receiver"/>
</Destination>
<Source>
<Standard_Partition PartitionIdentifier="2" PartitionName="iop"
PortName="iop_sender"/>
</Source>
<Destination>
<Standard_Partition PartitionIdentifier="1" PartitionName="partition1"
PortName="partition_receiver"/>
</Destination>
</Channel>
<Channel ChannelIdentifier="3" ChannelName="MessageOut2">
<Source>
<Standard_Partition PartitionIdentifier="2" PartitionName="iop"
PortName="iop_sender2"/>
</Source>
<Destination>
<Standard_Partition PartitionIdentifier="1" PartitionName="partition1"
PortName="partition_receiver2"/>
</Destination>
</Channel>
</Connection_Table>
<!-- Module configuration -->
<AIR_Configuration TicksPerSecond="1000" RequiredCores="1"/>
</ARINC_653_Module>
......@@ -3,15 +3,18 @@
<RemotePorts>
<Port Name="iop_receiver" LogicalDeviceId="1"/>
<Port Name="iop_receiver2" LogicalDeviceId="2"/>
<Port Name="iop_sender" />
<Port Name="iop_sender2" />
</RemotePorts>
<LogicalDevices>
<Device Id="1" Name="DESTINATION_DEVICE_NAME"/>
<Device Id="2" Name="DESTINATION_DEVICE_NAME2"/>
</LogicalDevices>
<PhysicalDevices>
<Device Id="1" Device="CAN0" Baud="250" TXD="32" RXD="32" Code="0x00000000" Mask="0x00000000" Selection="0" Enable0="0" Enable1="1">
<Device Id="1" Device="CAN0" Baud="500" Code="0x00000000" Mask="0x00000000" Selection="0" Enable0="0" Enable1="0">
<PhysicalRoute Id="1" PortId="iop_sender">
<CanHeader Extended="true" Sshot="false" RTR="false" CanID="34"/>
</PhysicalRoute>
......@@ -19,16 +22,27 @@
<CanHeader Extended="false" Sshot="false" RTR="false" CanID="5"/>
</LogicalRoute>
</Device>
<Device Id="0" Device="CAN1" Baud="250" Code="0x00000000" Mask="0x00000000" Selection="1" Enable0="0" Enable1="0">
<PhysicalRoute Id="3" PortId="iop_sender2">
<CanHeader Extended="true" Sshot="false" RTR="false" CanID="35"/>
</PhysicalRoute>
<LogicalRoute Id="4" LogicalDeviceId="2">
<CanHeader Extended="false" Sshot="false" RTR="false" CanID="6"/>
</LogicalRoute>
</Device>
</PhysicalDevices>
<ModuleSchedules>
<Schedule ScheduleIdentifier="1">
<DevicesConfiguration>
<Device DeviceId="1" Device="CAN0" Reads="1"/>
<Device DeviceId="0" Device="CAN1" Reads="1"/>
</DevicesConfiguration>
<RoutesConfiguration>
<Route RouteId="1" Active="true"/>
<Route RouteId="2" Active="true"/>
<Route RouteId="3" Active="true"/>
<Route RouteId="4" Active="true"/>
</RoutesConfiguration>
</Schedule>
</ModuleSchedules>
......
......@@ -4,35 +4,26 @@
* Created on: Mar 15, 2018
* Author: gmvs
*
* WARNING: When running this example on GR740, the following have to be configured:
* - CAN pin multiplexing
*
*
*/
#include <rtems.h>
#include <rtems/rtems/tasks.h>
#include <rtems/rtems/sem.h>
#include <rtems/rtems/clock.h>
#include <string.h>
#include <a653.h>
#include <imaspex.h>
#include <pprintf.h>
SAMPLING_PORT_ID_TYPE SEND_PORT;
SAMPLING_PORT_ID_TYPE SEND_PORT, SEND_PORT2;
SAMPLING_PORT_ID_TYPE RECEIVE_PORT;
SAMPLING_PORT_ID_TYPE RECEIVE_PORT, RECEIVE_PORT2;
void grcan_send_msg(PARTITION_ID_TYPE self_id){
pprintf("This is Partition %d - Sender Task\n", self_id);
int i = 0;
char sample1[] = { 0x11, 0x22, 0x33, 0x44, 0x55};
// char sample2[] = "GMVS";
// char sample3[] = "TEST0";
char sample1[] = { 0xDE, 0xAD, 0xBE, 0xEF};
char sample2[] = { 0xBE, 0xEF, 0xDE, 0xAD};
int tps = 1000000 / air_syscall_get_us_per_tick();
int sleep = 1*tps;
......@@ -42,25 +33,19 @@ void grcan_send_msg(PARTITION_ID_TYPE self_id){
rtems_task_wake_after(sleep);
pprintf("Sender task starting\n");
RETURN_CODE_TYPE rc = NO_ERROR;
rtems_interval time;
while(1){
pprintf("Sending message ..%s.. through CAN\n", sample1);
pprintf("Sending %dbytes: 0xDEADBEEF\n", sizeof(sample1));
WRITE_SAMPLING_MESSAGE(SEND_PORT,
(MESSAGE_ADDR_TYPE) sample1,
3,
sizeof(sample1),
&rc);
// pprintf("Sending message ..%s.. through CAN\n", sample2);
// WRITE_SAMPLING_MESSAGE(SEND_PORT, (MESSAGE_ADDR_TYPE) sample2, 4, &rc);
//
// pprintf("Sending message ..%s.. through CAN\n", sample3);
// WRITE_SAMPLING_MESSAGE(SEND_PORT, (MESSAGE_ADDR_TYPE) sample3, 5, &rc);
// i++;
// if(i == 10){
// i = 0;
// }
// sample3[4] = 0x30 + i;
pprintf("Sending %dbytes: 0xBEEFDEAD\n", sizeof(sample2));
WRITE_SAMPLING_MESSAGE(SEND_PORT2,
(MESSAGE_ADDR_TYPE) sample2,
sizeof(sample2),
&rc);
rtems_task_wake_after(1* tps);
}
......@@ -69,33 +54,53 @@ void grcan_send_msg(PARTITION_ID_TYPE self_id){
void grcan_receive_msg(PARTITION_ID_TYPE self_id){
pprintf("This is Partition %d - Receiver Task\n", self_id);
char recv_msg[8];
int tsp = 1000000 / air_syscall_get_us_per_tick();
int sleep = 2*tsp;
int msg_len = 0;
char recv_msg[8] = {0,0,0,0,0,0,0,0};
int tps = 1000000 / air_syscall_get_us_per_tick();
int sleep = 2*tps;
long int msg_len = 0;
VALIDITY_TYPE validity;
pprintf("TSP %i\n", tsp);
pprintf("TPS %i\n", tps);
pprintf("Receiver task: Sleep for %ds so IOP gets ready...\n", sleep/1000);
pprintf("Receiver task: Sleep for %ds so IOP gets ready...\n", sleep/tps);
rtems_task_wake_after(sleep);
pprintf("Receiver task starting\n");
RETURN_CODE_TYPE rc = NO_ERROR;
rtems_interval time;
while(1){
pprintf("Attempting to read from CAN\n");
READ_SAMPLING_MESSAGE(RECEIVE_PORT,
(MESSAGE_ADDR_TYPE) recv_msg,
&msg_len,
&validity,
&rc);
if(msg_len > 0)
{
pprintf("Partition%d received a message with length %d:\n", self_id, msg_len);
for(int i = 0; i < msg_len; i++)
pprintf("%x",recv_msg[i]);
pprintf("\n");
/* Clear buffer for next message */
memset(recv_msg, 0, msg_len);
}
READ_SAMPLING_MESSAGE(RECEIVE_PORT2,
(MESSAGE_ADDR_TYPE) recv_msg,
&msg_len,
&validity,
&rc);
if(msg_len > 0)
pprintf("Partition%d received a message with length %d:\n %s \n", self_id, msg_len, recv_msg);
/* Clean buffer for next message */
memset(recv_msg, '\0', sizeof(char)*8);
{
pprintf("Partition%d received a message with length %d:\n", self_id, msg_len);
for(int i = 0; i < msg_len; i++)
pprintf("%x",recv_msg[i]);
pprintf("\n");
/* Clear buffer for next message */
memset(recv_msg, 0, msg_len);
}
rtems_task_wake_after(1*tsp);
rtems_task_wake_after(1*tps);
}
}
......@@ -123,6 +128,8 @@ int entry_func(){
/*Creating Source sampling Port*/
SAMPLING_PORT_NAME_TYPE RECEIVER_NAME = "partition_receiver";
SAMPLING_PORT_NAME_TYPE SENDER_NAME = "partition_sender";
SAMPLING_PORT_NAME_TYPE RECEIVER_NAME2 = "partition_receiver2";
SAMPLING_PORT_NAME_TYPE SENDER_NAME2 = "partition_sender2";
MESSAGE_SIZE_TYPE SIZE = 8;
SYSTEM_TIME_TYPE PERIOD= 1000000000ll;
......@@ -130,18 +137,25 @@ int entry_func(){
if (NO_ERROR != rc) {
pprintf("CREATE_SAMPLING_PORT %s, error: %d\n",SENDER_NAME, rc);
}
pprintf("CREATE_SAMPLING_PORT %s\n", SENDER_NAME);
CREATE_SAMPLING_PORT (SENDER_NAME2, SIZE, SOURCE, PERIOD, &SEND_PORT2, &rc);
if (NO_ERROR != rc) {
pprintf("CREATE_SAMPLING_PORT %s, error: %d\n",SENDER_NAME, rc);
}
CREATE_SAMPLING_PORT (RECEIVER_NAME, SIZE, DESTINATION, PERIOD, &RECEIVE_PORT, &rc);
if (NO_ERROR != rc) {
pprintf("CREATE_SAMPLING_PORT %s, error: %d\n", RECEIVER_NAME, rc);
}
pprintf("CREATE_SAMPLING_PORT %s\n", RECEIVER_NAME);
CREATE_SAMPLING_PORT (RECEIVER_NAME2, SIZE, DESTINATION, PERIOD, &RECEIVE_PORT2, &rc);
if (NO_ERROR != rc) {
pprintf("CREATE_SAMPLING_PORT %s, error: %d\n", RECEIVER_NAME, rc);
}
if (RTEMS_SUCCESSFUL == rtems_task_create (name_send, 15, 4096, mode, mode_mask, &id)) {
rtems_task_start (id, grcan_send_msg, self_id);
rtems_task_start (id, (rtems_task_entry) grcan_send_msg, self_id);
}
if(RTEMS_SUCCESSFUL == rtems_task_create (name_receive, 25, 4096, mode, mode_mask, &id)){
rtems_task_start(id, grcan_receive_msg, self_id);
rtems_task_start(id, (rtems_task_entry) grcan_receive_msg, self_id);
}
SET_PARTITION_MODE(NORMAL, &rc);
......
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