Skip to content

Commit

Permalink
tower-aadl: temporary commit to store hand-written components.
Browse files Browse the repository at this point in the history
For the Camkes uart-test.
When it becomes a proper test, it'll move to a new repo.
  • Loading branch information
leepike committed Apr 16, 2015
1 parent d3ae4fe commit acd7e69
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tower-aadl/testUart/components/uart_driver/include/driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __STUB_H
#define __STUB_H

void pilot_recv(int32_t uart_num, int32_t c);
int32_t uart_write(int32_t uart_num, int32_t wsize);

#endif
60 changes: 60 additions & 0 deletions tower-aadl/testUart/components/uart_driver/include/smaccm_uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef __SMACCM_uart_types__H
#define __SMACCM_uart_types__H

#include <smaccm_sys_impl_types.h>

/**************************************************************************
Copyright (c) 2013, 2014, 2015 Rockwell Collins and the University of Minnesota.
Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
Permission is hereby granted, free of charge, to any person obtaining a copy of this data,
including any software or models in source or binary form, as well as any drawings, specifications,
and documentation (collectively "the Data"), to deal in the Data without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Data, and to permit persons to whom the Data is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Data.
THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE DATA.
**************************************************************************/


/**************************************************************************
File: C:\docs\git_smaccm\smaccm\models\Trusted_Build_Test\test_uart\components\uart\include\smaccm_uart.h
Created on: 2015/03/25 10:28:09
using Dulcimer AADL system build tool suite
***AUTOGENERATED CODE: DO NOT MODIFY***
This header section contains the AADL gluecode interfaces used by the client
for the thread implementations.
**************************************************************************/
void send_handler(Data_Types__uart_packet_impl * send);

void recv_handler(Data_Types__uart_packet_impl * recv_handler);


bool recv_data(Data_Types__uart_packet_impl * recv);
bool uart_read_send(Data_Types__uart_packet_impl * send); bool uart_read_recv_handler(Data_Types__uart_packet_impl * recv_handler);
//////////////////////////////////////////////////////////////////////////
//
// Note: thread is declared EXTERNAL; user should provide run() function.
//
//////////////////////////////////////////////////////////////////////////

/* endif for: #ifndef __SMACCM_uart_types__H */
#endif

/**************************************************************************
End of autogenerated file: C:\docs\git_smaccm\smaccm\models\Trusted_Build_Test\test_uart\components\uart\include\smaccm_uart.h
**************************************************************************/

193 changes: 193 additions & 0 deletions tower-aadl/testUart/components/uart_driver/src/driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* Copyright 2014, NICTA
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(NICTA_BSD)
*/

#include <stdio.h>

#include <platsupport/chardev.h>
#include <platsupport/serial.h>
#include <utils/util.h>
#include <driver.h>
#include <uart_driver.h>

//#define BAUD_RATE 115200
#define BAUD_RATE 57600

#ifdef CONFIG_PLAT_EXYNOS5410
#define DEV_ID PS_SERIAL1
#elif CONFIG_PLAT_IMX31
#define DEV_ID IMX31_UART1
#else
#error
#endif

struct uart_token {
size_t cur_bytes;
size_t req_bytes;
char* buf;
};

char client_buffer[4];

static ps_chardevice_t serial_device;

static void
interrupt_event(void* token)
{
ps_chardevice_t* device;
device = (ps_chardevice_t*)token;
ps_cdev_handle_irq(device, 0);
interrupt_reg_callback(&interrupt_event, token);
}

/* UART 1 dummy input clock */
static freq_t
dummy_get_freq(clk_t* clk) {
return 24000000;
}

static freq_t
dummy_set_freq(clk_t* clk, UNUSED freq_t hz){
return dummy_get_freq(clk);
}

#define DUMMY_CLK(cust_id) \
{ \
.id = cust_id, \
.name = "DUMMY " #cust_id, \
.priv = NULL, \
.req_freq = 0, \
.parent = NULL, \
.sibling = NULL, \
.child = NULL, \
.clk_sys = NULL, \
.init = NULL, \
.get_freq = &dummy_get_freq, \
.set_freq = &dummy_set_freq, \
.recal = NULL \
}

#if DEV_ID == 1
clk_t uart_dummy_clk = DUMMY_CLK(CLK_UART1);
#else
clk_t uart_dummy_clk = DUMMY_CLK(CLK_UART3);
#endif

void uart__init(void)
{
/* Iniitialise the UART */
printf("Initialising UART driver\n");
if(exynos_serial_init(DEV_ID, uart0base, NULL, &uart_dummy_clk,
&serial_device)){
printf("Failed to initialise UART\n");
while(1);
}
serial_configure(&serial_device, BAUD_RATE, 8, PARITY_NONE, 1);
/* Prime semaphores */
read_sem_wait();
write_sem_wait();
/* Register for IRQs */
interrupt_reg_callback(&interrupt_event, &serial_device);
}


static void
read_callback(ps_chardevice_t* device, enum chardev_status stat,
size_t bytes_transfered, void* token){
struct uart_token* t;
t = (struct uart_token*)token;
/* We might get a short read due to a timeout. */
t->cur_bytes += bytes_transfered;
t->buf += bytes_transfered;
if(t->cur_bytes < t->req_bytes){
int ret;
ret = ps_cdev_read(device, t->buf, t->req_bytes - t->cur_bytes,
&read_callback, token);
if(ret < 0){
printf("Error reading from UART\n");
read_sem_post();
}
}else{
read_sem_post();
}
}

static void
write_callback(ps_chardevice_t* device, enum chardev_status stat,
size_t bytes_transfered, void* token){
struct uart_token* t;
t = (struct uart_token*)token;
t->cur_bytes += bytes_transfered;
if(t->cur_bytes == t->req_bytes){
write_sem_post();
}
}


int uart_read(int uart_num, char *c, int rsize)
{
struct uart_token token;
if (uart_num != 0) {
printf("Only support UART0!\n");
return -1;
}

token.cur_bytes = 0;
token.req_bytes = rsize;
token.buf = c;
if(ps_cdev_read(&serial_device, token.buf, token.req_bytes, &read_callback, &token) < 0){
printf("Error reading from UART\n");
return -1;
}
read_sem_wait();

return token.cur_bytes;
}

int uart_write(int uart_num, int datum)
{
struct uart_token token;
if (uart_num != 0) {
printf("Only support UART0!\n");
return -1;
}

token.cur_bytes = 0;
token.buf = (char*)client_buffer;

//////////////////////////////////////////////
// changed: MWW
// token.req_bytes = wsize;
token.req_bytes = 4;
*((int *)token.buf) = datum;
//////////////////////////////////////////////



if(ps_cdev_write(&serial_device, token.buf, token.req_bytes, &write_callback, &token) < 0){
printf("Error writing to UART\n");
return -1;
}
write_sem_wait();

return token.req_bytes;
}

int run(void)
{
char c;
printf("Started UART driver.");
uart__init();
while (1) {
uart_read(0, &c, 1);
pilot_recv(ID, (int)c);
}

return 0;
}
29 changes: 29 additions & 0 deletions tower-aadl/testUart/components/uart_driver/src/smaccm_uart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#include <smaccm_uart.h>
#include <uart_driver.h>
#include <driver.h>
#include <string.h>


bool send_write_Data_Types__uart_packet_impl(const Data_Types__uart_packet_impl *arg) {
int32_t result = -1;

// Other options rather than fail: re-send up to a bounded # of times?
// int32_t retries = 0;
result = uart_write(arg->uart_num, arg->datum);
if (result == -1) {
printf("send failed!.\n");
return false;
}
return true;
}

void pilot_recv(int32_t uart_num, int32_t c) {
Data_Types__uart_packet_impl packet;
packet.uart_num = uart_num;
packet.datum = c;

// MWW: might want to do error checking here(!)
recv_write_Data_Types__uart_packet_impl(&packet);
}

25 changes: 25 additions & 0 deletions tower-aadl/testUart/components/uart_driver/uart_driver.camkes
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "../../interfaces/uart_monitor_11_interface.idl4";
import "../../interfaces/Data_Types__uart_packet_impl_writer.idl4";

component uart_driver {
control;

// provided interfaces for input event / event data ports
provides Data_Types__uart_packet_impl_writer send;
uses Data_Types__uart_packet_impl_writer recv;

provides Data_Types__uart_packet_impl_writer recv_handler;
has mutex smaccm_recv_handler_sem;

// information from native UART driver
consumes DataAvailable interrupt;
has semaphore read_sem;
has semaphore write_sem;
attribute int ID;

// The first buffer is for shared memory.
dataport Buf uart0base;
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import "../../interfaces/uart_monitor_11_interface.idl4";
import "../../interfaces/Data_Types__uart_packet_impl_writer.idl4";
import "../../interfaces/receiverhandler_9_interface.idl4";
import "../uart_driver/uart_driver.camkes";

component uartbase {
hardware;
dataport Buf mem;
emits DataAvailable irq;
}

component uart_monitor_11 {
uses Data_Types__uart_packet_impl_writer receiverhandler_9_inst;
provides Data_Types__uart_packet_impl_writer Input0;

composition {
component uartbase uartbase;
component uart_driver uart_driver;

/* hardware connection */
connection seL4HardwareMMIO uart_mem(from uart_driver.uart0base, to uartbase.mem);
connection seL4HardwareInterrupt uart_irq(from uartbase.irq, to uart_driver.interrupt);

/* Software connections */
connection ExportRPC conn1(from Input0, to uart_driver.send);
connection ExportRPC conn2(from uart_driver.recv, to receiverhandler_9_inst);

}

configuration {
uartbase.mem_attributes = "0x12C10000:0x1000"; //UART1
uartbase.irq_attributes = 84; //UART1 interrupt
uart_driver.ID = 3;
}
}

/**************************************************************************
End of autogenerated file: C:\docs\git_smaccm\smaccm\models\Trusted_Build_Test\test_uart\components\uart\uart.camkes.template
**************************************************************************/

14 changes: 14 additions & 0 deletions tower-aadl/testUart/othercamkestargets.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uart_driver_CFILES := \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/src/*.c)) \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/src/plat/${PLAT}/*.c)) \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/src/arch/${ARCH}/*.c))

uart_driver_HFILES := \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/include/*.h)) \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/include/*.h))

uart_driver_ASMFILES := \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/crt/arch-${ARCH}/crt0.S)) \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/src/*.S)) \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/src/arch/${ARCH}/*.S)) \
$(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/components/uart_driver/src/plat/${PLAT}/*.S))
5 changes: 5 additions & 0 deletions tower-aadl/testUart/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mkdir components
cp -r /Users/leepike/vm-shared/testUart-works/components/uart_driver components
make ramses
cp /Users/leepike/vm-shared/testUart-works/components/uart_monitor_11/uart_monitor_11.camkes ./components/uart_monitor_11
cp /Users/leepike/vm-shared/testUart-works/othercamkestargets.mk ./

0 comments on commit acd7e69

Please sign in to comment.