Skip to content

Commit

Permalink
Added txm_lib reimplementation and build files + first example
Browse files Browse the repository at this point in the history
  • Loading branch information
Thalhammer committed Oct 31, 2018
1 parent 287c304 commit ba642a6
Show file tree
Hide file tree
Showing 33 changed files with 998 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
13 changes: 13 additions & 0 deletions api/include/stdlib/stddef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
typedef __SIZE_TYPE__ size_t;

#ifndef __cplusplus
#define NULL ((void *)0)
#else /* C++ */
#define NULL 0
#endif /* C++ */

#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)

#if defined(__cplusplus) && __cplusplus >= 201103L
typedef decltype(nullptr) nullptr_t;
#endif
113 changes: 113 additions & 0 deletions api/include/stdlib/stdint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#pragma once

#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ int8_t;
#endif
#ifdef __INT16_TYPE__
typedef __INT16_TYPE__ int16_t;
#endif
#ifdef __INT32_TYPE__
typedef __INT32_TYPE__ int32_t;
#endif
#ifdef __INT64_TYPE__
typedef __INT64_TYPE__ int64_t;
#endif
#ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ uint8_t;
#endif
#ifdef __UINT16_TYPE__
typedef __UINT16_TYPE__ uint16_t;
#endif
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ uint32_t;
#endif
#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ uint64_t;
#endif

typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;

typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;

#ifdef __INTPTR_TYPE__
typedef __INTPTR_TYPE__ intptr_t;
#endif
#ifdef __UINTPTR_TYPE__
typedef __UINTPTR_TYPE__ uintptr_t;
#endif

typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;
# define INT8_MAX __INT8_MAX__
# define INT8_MIN (-INT8_MAX - 1)
# define UINT8_MAX __UINT8_MAX__
# define INT16_MAX __INT16_MAX__
# define INT16_MIN (-INT16_MAX - 1)
# define UINT16_MAX __UINT16_MAX__
# define INT32_MAX __INT32_MAX__
# define INT32_MIN (-INT32_MAX - 1)
# define UINT32_MAX __UINT32_MAX__
# define INT64_MAX __INT64_MAX__
# define INT64_MIN (-INT64_MAX - 1)
# define UINT64_MAX __UINT64_MAX__

#define INT_LEAST8_MAX __INT_LEAST8_MAX__
#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
#define INT_LEAST16_MAX __INT_LEAST16_MAX__
#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#define INT_LEAST32_MAX __INT_LEAST32_MAX__
#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#define INT_LEAST64_MAX __INT_LEAST64_MAX__
#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__

#define INT_FAST8_MAX __INT_FAST8_MAX__
#define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
#define UINT_FAST8_MAX __UINT_FAST8_MAX__
#define INT_FAST16_MAX __INT_FAST16_MAX__
#define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
#define UINT_FAST16_MAX __UINT_FAST16_MAX__
#define INT_FAST32_MAX __INT_FAST32_MAX__
#define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
#define UINT_FAST32_MAX __UINT_FAST32_MAX__
#define INT_FAST64_MAX __INT_FAST64_MAX__
#define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
#define UINT_FAST64_MAX __UINT_FAST64_MAX__

# define INTPTR_MAX __INTPTR_MAX__
# define INTPTR_MIN (-INTPTR_MAX - 1)
# define UINTPTR_MAX __UINTPTR_MAX__
#define INTMAX_MAX __INTMAX_MAX__
#define INTMAX_MIN (-INTMAX_MAX - 1)
#define UINTMAX_MAX __UINTMAX_MAX__

#define PTRDIFF_MAX __PTRDIFF_MAX__
#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)

#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
#define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__

#define SIZE_MAX __SIZE_MAX__

#define WCHAR_MAX __WCHAR_MAX__
#define WCHAR_MIN __WCHAR_MIN__

#define WINT_MAX __WINT_MAX__
#define WINT_MIN __WINT_MIN__
Empty file added api/include/stdlib/stdlib.h
Empty file.
6 changes: 6 additions & 0 deletions api/include/stdlib/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include <stddef.h>

extern size_t strlen(const char* str);
extern void* memset(void* ptr, int value, size_t num);
extern void* memcpy(void* destination, const void* source, size_t num);
4 changes: 4 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.o.d
*.o
bin
usrconfig.mk
3 changes: 3 additions & 0 deletions examples/00-helloworld/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hello World example

Traditional "Hello World" Module that prints a simple message to UART and exits.
1 change: 1 addition & 0 deletions examples/00-helloworld/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../default.mk
34 changes: 34 additions & 0 deletions examples/00-helloworld/src/pal_module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdlib.h>

#include "qapi/qapi_types.h"
#include "qapi/qapi.h"
#include "qapi/qapi_status.h"
#include "qapi_timer.h"
#include "qapi_uart.h"

#include "tx_api.h"

char send_buf[256];

int dam_app_start(void)
{
const char* msg = "Hello from DAM :) \r\n";

qapi_UART_Handle_t uart_handle;

qapi_UART_Open_Config_t open_properties;
memset (&open_properties, 0, sizeof (open_properties));
open_properties.parity_Mode = QAPI_UART_NO_PARITY_E;
open_properties.num_Stop_Bits= QAPI_UART_1_0_STOP_BITS_E;
open_properties.baud_Rate = 115200;
open_properties.bits_Per_Char= QAPI_UART_8_BITS_PER_CHAR_E;
qapi_UART_Open(&uart_handle, QAPI_UART_PORT_003_E, &open_properties);

tx_thread_sleep(100);

memset(send_buf, 0, sizeof (send_buf));
memcpy(send_buf, (char*)msg, strlen(msg));
qapi_UART_Transmit(uart_handle, send_buf, strlen(msg), NULL);
tx_thread_sleep(100);
return TX_SUCCESS;
}
71 changes: 71 additions & 0 deletions examples/00-helloworld/src/txm_module_preamble.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
AREA Init, CODE, READONLY
CODE32
; /* Define public symbols. */

EXPORT __txm_module_preamble


; /* Define application-specific start/stop entry points for the module. */

IMPORT dam_app_start


; /* Define common external refrences. */

IMPORT _txm_module_thread_shell_entry
IMPORT _txm_module_callback_request_thread_entry
IMPORT |Image$$ER_RO$$Length|
#ifdef TX_DAM_QC_CUSTOMIZATIONS
IMPORT |Image$$ER_RW$$Length|
IMPORT |Image$$ER_ZI$$ZI$$Length|
#endif


__txm_module_preamble
DCD 0x4D4F4455 ; Module ID
DCD 0x5 ; Module Major Version
DCD 0x3 ; Module Minor Version
DCD 32 ; Module Preamble Size in 32-bit words
DCD 0x134350ac ; Module ID (application defined)
DCD 0x01000000 ; Module Properties where:
; Bits 31-24: Compiler ID
; 0 -> IAR
; 1 -> RVDS
; 2 -> GNU
; Bits 23-0: Reserved
DCD _txm_module_thread_shell_entry - . + . ; Module Shell Entry Point
DCD dam_app_start - . + . ; Module Start Thread Entry Point
DCD 0 ; Module Stop Thread Entry Point
DCD 140 ; Module Start/Stop Thread Priority
DCD 8192 ; Module Start/Stop Thread Stack Size
DCD _txm_module_callback_request_thread_entry - . + . ; Module Callback Thread Entry
DCD 25 ; Module Callback Thread Priority
DCD 2046 ; Module Callback Thread Stack Size
DCD |Image$$ER_RO$$Length| ; Module Code Size
#ifdef TX_DAM_QC_CUSTOMIZATIONS
DCD |Image$$ER_ZI$$ZI$$Length| ; Module data size - get it from ZI section
DCD __txm_module_preamble ; Reserved 0
DCD |Image$$ER_RW$$Length| ; Reserved 1
#else
DCD 0x16000 ; Module Data Size - default to 16K (need to make sure this is large enough for module's data needs!)
DCD 0 ; Reserved 0
DCD 0 ; Reserved 1
#endif
DCD 0 ; Reserved 2
DCD 0 ; Reserved 3
DCD 0 ; Reserved 4
DCD 0 ; Reserved 5
DCD 0 ; Reserved 6
DCD 0 ; Reserved 7
DCD 0 ; Reserved 8
DCD 0 ; Reserved 9
DCD 0 ; Reserved 10
DCD 0 ; Reserved 11
DCD 0 ; Reserved 12
DCD 0 ; Reserved 13
DCD 0 ; Reserved 14
DCD 0 ; Reserved 15

END


103 changes: 103 additions & 0 deletions examples/00-helloworld/src/txm_module_preamble.S.gcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
@ AREA Init, CODE, READONLY
.section Init, "ax", %progbits
.CODE32:
@ Define public symbols
.global __txm_module_preamble

@ Define application-specific start/stop entry points for the module
.extern dam_app_start

@ Define common external refrences
.extern _txm_module_thread_shell_entry
.extern _txm_module_callback_request_thread_entry
.extern Image$$ER_RO$$Length
#ifdef TX_DAM_QC_CUSTOMIZATIONS
.extern Image$$ER_RW$$Length
.extern Image$$ER_ZI$$ZI$$Length
#endif

__txm_module_preamble:
.p2align 2
.word 0x4D4F4455 @ Module ID
.p2align 2
.word 0x5 @ Module Major Version
.p2align 2
.word 0x3 @ Module Minor Version
.p2align 2
.word 32 @ Module Preamble Size in 32-bit words
.p2align 2
.word 0x134350ac @ Module ID (application defined)
.p2align 2
.word 0x02000000 @ Module Properties where:
.p2align 2
@ Bits 31-24: Compiler ID
@ 0 -> IAR
@ 1 -> RVDS
@ 2 -> GNU
@ 4 -> LLVM
@ Bits 23-1: Reserved
@ Bit 0: Privileged mode execution
@ 0 -> no MMU protection
@ 1 -> MMU protection Enabled
.word _txm_module_thread_shell_entry - __txm_module_preamble @ Module Shell Entry Point
.p2align 2
.word dam_app_start - __txm_module_preamble @ Module Start Thread Entry Point
.p2align 2
.word 0 @ Module Stop Thread Entry Point
.p2align 2
.word 140 @ Module Start/Stop Thread Priority
.p2align 2
.word 8192 @ Module Start/Stop Thread Stack Size
.p2align 2
.word _txm_module_callback_request_thread_entry - __txm_module_preamble @ Module Callback Thread Entry
.p2align 2
.word 25 @ Module Callback Thread Priority
.p2align 2
.word 2046 @ Module Callback Thread Stack Size
.p2align 2
.word (Image$$ER_RO$$Length) @ Module Code Size
#ifdef TX_DAM_QC_CUSTOMIZATIONS
.p2align 2
.word (Image$$ER_ZI$$ZI$$Length) @ Module data size - get it from ZI section
.p2align 2
.word __txm_module_preamble @ Reserved 0
.p2align 2
.word (Image$$ER_RW$$Length) @ Reserved 1
#else
.p2align 2
.word 0x32000 @ Module Data Size - default to 16K (need to make sure this is large enough for module's data needs!)
.p2align 2
.word 0 @ Reserved 0
.p2align 2
.word 0 @ Reserved 1
#endif
.p2align 2
.word 0 @ Reserved 2
.p2align 2
.word 0 @ Reserved 3
.p2align 2
.word 0 @ Reserved 4
.p2align 2
.word 0 @ Reserved 5
.p2align 2
.word 0 @ Reserved 6
.p2align 2
.word 0 @ Reserved 7
.p2align 2
.word 0 @ Reserved 8
.p2align 2
.word 0 @ Reserved 9
.p2align 2
.word 0 @ Reserved 10
.p2align 2
.word 0 @ Reserved 11
.p2align 2
.word 0 @ Reserved 12
.p2align 2
.word 0 @ Reserved 13
.p2align 2
.word 0 @ Reserved 14
.p2align 2
.word 0 @ Reserved 15

.end
Loading

0 comments on commit ba642a6

Please sign in to comment.