Пример #1
0
static void init_usart(void) {
	/* Configure the usart */
	REG_STORE(AT91C_PMC_PCER, (1 << OPTION_GET(NUMBER,dev_id)));

	REG_STORE(AT91C_PIOA_PDR, BTM_BT_RX_PIN | BTM_BT_TX_PIN |
			BTM_BT_SCK_PIN | BTM_BT_RTS_PIN | BTM_BT_CTS_PIN);
	REG_STORE(AT91C_PIOA_ASR, BTM_BT_RX_PIN | BTM_BT_TX_PIN |
			BTM_BT_SCK_PIN | BTM_BT_RTS_PIN | BTM_BT_CTS_PIN);

	REG_STORE(&(us_dev_regs->US_PTCR), (AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS));

	REG_STORE(&(us_dev_regs->US_CR),  AT91C_US_RXDIS | AT91C_US_TXDIS);
	REG_STORE(&(us_dev_regs->US_CR),  AT91C_US_RSTSTA | AT91C_US_RSTRX | AT91C_US_RSTTX);
	REG_STORE(&(us_dev_regs->US_CR), AT91C_US_STTTO);

	REG_STORE(&(us_dev_regs->US_MR), AT91C_US_USMODE_HWHSH
			| AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE
			| AT91C_US_NBSTOP_1_BIT);
	REG_STORE(&(us_dev_regs->US_BRGR), SYS_CLOCK / (16 * BTM_BT_BAUD_RATE));

	REG_STORE(&(us_dev_regs->US_IDR), ~0);

	REG_STORE(&(us_dev_regs->US_RCR), 0);
	REG_STORE(&(us_dev_regs->US_TCR), 0);
	REG_STORE(&(us_dev_regs->US_RNPR), 0);
	REG_STORE(&(us_dev_regs->US_TNPR), 0);
	REG_LOAD(&(us_dev_regs->US_RHR));
	REG_LOAD(&(us_dev_regs->US_CSR));

	REG_STORE(&(us_dev_regs->US_CR), AT91C_US_RXEN | AT91C_US_TXEN);
	REG_STORE(&(us_dev_regs->US_PTCR), AT91C_PDC_RXTEN | AT91C_PDC_TXTEN);
	REG_STORE(&(us_dev_regs->US_IER), AT91C_US_ENDRX);
}
Пример #2
0
static int btm_bluetooth_init(void) {
	irq_attach(OPTION_GET(NUMBER,irq_num), btm_bt_us_handler, 0, NULL, "bt reader");
	// TODO error handling?

	init_usart();
	return 0;
}
Пример #3
0
static int run_script(void) {
    const char *command;
    const struct shell *shell;

    shell = shell_lookup(OPTION_STRING_GET(shell_name));
    if (NULL == shell) {
        shell = shell_any();
        if (NULL == shell) {
            return -ENOENT;
        }
    }

    setup_tty(OPTION_STRING_GET(tty_dev));

    printf("\nStarted shell [%s] on device [%s]\n",
           OPTION_STRING_GET(shell_name), OPTION_STRING_GET(tty_dev));

    printf("loading start script:\n");
    array_foreach(command, script_commands, ARRAY_SIZE(script_commands)) {
        int ret;

        printf("> %s \n", command);

        ret = shell_exec(shell, command);

        if (OPTION_GET(BOOLEAN,stop_on_error) && ret) {
            return ret;
        }
    }
Пример #4
0
//=============================================================================
//	eDevices::eDevices
//-----------------------------------------------------------------------------
eDevices::eDevices()
{
    OPTION_GET(op_devices) = this;
    storeable = false;
    memset(items, 0, sizeof(items));
    Set(true);
}
Пример #5
0
static Elm_Bg_Option
_bg_option_get(const char *option)
{
   assert(sizeof(_bg_options) / sizeof(_bg_options[0])
          == ELM_BG_OPTION_TILE + 2);
   OPTION_GET(_bg_options, option);
   return -1;
}
static byte TranslateKey(SDLKey _key, dword& _flags)
{
	bool ui_focused = Handler()->VideoDataUI();
	switch(_key)
	{
	case DINGOO_BUTTON_UP:		return 'u';
	case DINGOO_BUTTON_DOWN:	return 'd';
	case DINGOO_BUTTON_LEFT:	return 'l';
	case DINGOO_BUTTON_RIGHT:	return 'r';

	case DINGOO_BUTTON_A:		return 'f';
	case DINGOO_BUTTON_B:		return 'e';
	case DINGOO_BUTTON_X:		return '1';
	case DINGOO_BUTTON_Y:		return ' ';

	case DINGOO_BUTTON_SELECT:
		b_select = _flags&KF_DOWN;
		if(b_select && b_start)
			OPTION_GET(op_quit)->Set(true);
		return 'm';
	case DINGOO_BUTTON_START:
		b_start = _flags&KF_DOWN;
		if(b_select && b_start)
			OPTION_GET(op_quit)->Set(true);
		return 'k';

	case DINGOO_BUTTON_L:
		l_shift = _flags&KF_DOWN;
		if(!ui_focused)
			Handler()->OnAction(A_RESET);
		break;
	case DINGOO_BUTTON_R:
		r_shift = _flags&KF_DOWN;
		if(!ui_focused)
		{
			SAFE_CALL(OPTION_GET(op_sound_source))->Change();
		}
		break;

	default:
		break;
	}
	if(b_select && b_start)
		OPTION_GET(op_quit)->Set(true);
	return 0;
}
static Val   set_time_profiling_rw_vector   (Task* task,  Val arg)   {
    //       ============================
    //
    // Mythryl type:   Null_Or(Rw_Vector(Unt)) -> Void
    //
    // This dis/ables handling of SIGVTALRM signals by the process,
    // vs  set__time_profiling_is_running__to() below which
    // dis/ables sending of SIGVTALRM signals to the process,
    //
    // Set the profile array reference;
    // NULL means that there is no array.
    //
    // This function is bound as    set_time_profiling_rw_vector'   in:
    //
    //     src/lib/std/src/nj/runtime-profiling-control.pkg

									    ENTER_MYTHRYL_CALLABLE_C_FN("set_time_profiling_rw_vector");

#ifdef OPSYS_UNIX

    Bool  enabled =   (time_profiling_rw_vector__global != HEAP_VOID);
    int	    i;

    if (arg != OPTION_NULL) {

	time_profiling_rw_vector__global =   OPTION_GET( arg );

	if (!enabled) {
	    //
	    c_roots__global[c_roots_count__global++] = &time_profiling_rw_vector__global;		// Add   time_profiling_rw_vector__global   to the C roots.
            //
	    start_incrementing__time_profiling_rw_vector__once_per_SIGVTALRM ();		// Enable SIGVTALRM profiling signals   via   src/c/machine-dependent/posix-profiling-support.c
	}

    } else if (enabled) {

        // Remove   time_profiling_rw_vector__global   from the C roots:
        //
	for (i = 0;  i < c_roots_count__global;  i++) {
	    //
	    if (c_roots__global[i] == &time_profiling_rw_vector__global) {
		c_roots__global[i] = c_roots__global[ --c_roots_count__global ];
		break;
	    }
	}

        // Disable profiling signals:
        //
	stop_incrementing__time_profiling_rw_vector__once_per_SIGVTALRM ();			// Disable SIGVTALRM profiling signals   via   src/c/machine-dependent/posix-profiling-support.c
	time_profiling_rw_vector__global =  HEAP_VOID;
    }

    return HEAP_VOID;
#else
    return RAISE_ERROR__MAY_HEAPCLEAN(task, "time profiling not supported", NULL);
#endif

}
Пример #8
0
Val   _lib7_U_Dynload_dlopen   (Task* task, Val arg)   {	//  (String, Bool, Bool) -> one_word_unt::Unt
    //======================
    //
    // Open a dynamically loaded library.
    //

									    ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_U_Dynload_dlopen");

    Val ml_libname = GET_TUPLE_SLOT_AS_VAL (arg, 0);
    int lazy       = GET_TUPLE_SLOT_AS_VAL (arg, 1) == HEAP_TRUE;
    int global     = GET_TUPLE_SLOT_AS_VAL (arg, 2) == HEAP_TRUE;

    char *libname = NULL;
    void *handle;


    Mythryl_Heap_Value_Buffer  libname_buf;

    if (ml_libname != OPTION_NULL) {
	//
        libname = HEAP_STRING_AS_C_STRING (OPTION_GET (ml_libname));
	//
	// Copy libname out of Mythryl heap to
        // make it safe to reference between
	// RELEASE_MYTHRYL_HEAP and
	// RECOVER_MYTHRYL_HEAP:
	//
	libname =  (char*)  buffer_mythryl_heap_value( &libname_buf, (void*)libname, strlen(libname)+1 );		// '+1' for terminal NUL on string.
    }

    #ifdef OPSYS_WIN32

	handle = (void *) LoadLibrary (libname);

	if (handle == NULL && libname != NULL)	  dlerror_set ("Library `%s' not found", libname);

    #else
	int flag = (lazy ? RTLD_LAZY : RTLD_NOW);

	if (global) flag |= RTLD_GLOBAL;

	RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_U_Dynload_dlopen", NULL );
	    //
	    handle = dlopen (libname, flag);
	    //
	RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_U_Dynload_dlopen" );
    #endif

    if (libname)  unbuffer_mythryl_heap_value( &libname_buf );

    return  make_one_word_unt(task,  (Vunt) handle  );
}
Val   get_or_set_socket_nodelay_option   (Task* task,  Val arg)   {
    //================================
    //
    // Mythryl type:   (Int,  Null_Or(Bool)) -> Bool
    //
    // NOTE: this is a TCP level option, so we cannot use the utility function.
    //
    // This fn gets bound as   ctl_delay   in:
    //
    //     src/lib/std/src/socket/internet-socket.pkg

													ENTER_MYTHRYL_CALLABLE_C_FN("get_or_set_socket_nodelay_option");

    int	socket =  GET_TUPLE_SLOT_AS_INT( arg, 0 );
    Val	ctl    =  GET_TUPLE_SLOT_AS_VAL( arg, 1 );							// Last use of 'arg'.
    //
    Bool flag;
    int status;

    if (ctl == OPTION_NULL) {
        //
	socklen_t opt_size = sizeof(int);

	RELEASE_MYTHRYL_HEAP( task->pthread, "get_or_set_socket_nodelay_option", NULL );
	    //
	    status = getsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (sockoptval_t)&flag, &opt_size);
	    //
	RECOVER_MYTHRYL_HEAP( task->pthread, "get_or_set_socket_nodelay_option" );

	ASSERT((status < 0) || (opt_size == sizeof(int)));

    } else {

	flag = (Bool) TAGGED_INT_TO_C_INT(OPTION_GET(ctl));

	RELEASE_MYTHRYL_HEAP( task->pthread, "get_or_set_socket_nodelay_option", NULL );
	    //
	    status = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (sockoptval_t)&flag, sizeof(int));
	    //
	RECOVER_MYTHRYL_HEAP( task->pthread, "get_or_set_socket_nodelay_option" );
    }

    if (status < 0)     return RAISE_SYSERR__MAY_HEAPCLEAN(task, status, NULL);
    else		return (flag ? HEAP_TRUE : HEAP_FALSE);
}
Пример #10
0
Val   _lib7_netdb_get_service_by_name   (Task* task,  Val arg)   {
    //===============================
    //
    // Mythryl type:   (String, Null_Or(String)) ->   Null_Or(   (String, List(String), Int, String)   )
    //
    // This fn gets bound as   get_service_by_name'   in:
    //
    //     src/lib/std/src/socket/net-service-db.pkg

    Val	mlServ  =  GET_TUPLE_SLOT_AS_VAL( arg, 0 );
    Val	mlProto =  GET_TUPLE_SLOT_AS_VAL( arg, 1 );

    char* proto;

    if (mlProto == OPTION_NULL)   proto = NULL;
    else			  proto = HEAP_STRING_AS_C_STRING(OPTION_GET(mlProto));

    return _util_NetDB_mkservent (						// _util_NetDB_mkservent	def in   src/c/lib/socket/util-mkservent.c
               task,
               getservbyname( HEAP_STRING_AS_C_STRING( mlServ ), proto)
           );
}
Пример #11
0
// Get/set the rounding mode; the values are interpreted as follows:
//
//	0	To nearest
//	1	To zero
//	2	To +Inf
//	3	To -Inf
//
Val   _lib7_Math_get_or_set_rounding_mode   (Task* task,  Val arg)   {
    //===================================
    //
    // Mythryl type:   Null_Or(Int) -> Int
    //
    // This fn gets bound as   get_or_set_rounding_mode   in:
    //
    //     src/lib/std/src/ieee-float.pkg
    //

									 		ENTER_MYTHRYL_CALLABLE_C_FN(__func__);

    Val result;

    #ifdef NO_ROUNDING_MODE_CTL
	//
        result = RAISE_ERROR__MAY_HEAPCLEAN(task, "Rounding mode control not supported", NULL);
	//
    #else
	//
	if (arg == OPTION_NULL) {
	    //
	    fe_rnd_mode_t	 resultt = fegetround();
	    result = RMODE_CtoLib7(resultt);

	} else {

	    fe_rnd_mode_t	  mode    =  RMODE_LIB7toC( OPTION_GET( arg ));
	    fe_rnd_mode_t	  resultt =  fesetround( mode );				// fesetround	def in    src/c/machine-dependent/prim.intel32.asm
	    result = RMODE_CtoLib7( resultt );
	}
    #endif
									 		EXIT_MYTHRYL_CALLABLE_C_FN(__func__);

    return result;
}
Пример #12
0
static int dev_regs_init() {
	dev_regs = (volatile struct apbuart_regs *) OPTION_GET(NUMBER,apbuart_base);
	return 0;
}
Пример #13
0
#include <embox/unit.h>

extern void bt_handle(uint8_t *buff);

#define BTM_BT_RX_PIN  ((uint32_t) (1 << OPTION_GET(NUMBER,rx_pin)))
#define BTM_BT_TX_PIN  ((uint32_t) (1 << OPTION_GET(NUMBER,tx_pin)))
#define BTM_BT_SCK_PIN ((uint32_t) (1 << OPTION_GET(NUMBER,sck_pin)))
#define BTM_BT_RTS_PIN ((uint32_t) (1 << OPTION_GET(NUMBER,rts_pin)))
#define BTM_BT_CTS_PIN ((uint32_t) (1 << OPTION_GET(NUMBER,cts_pin)))

#define BTM_BT_RST_PIN   ((uint32_t) (1 << OPTION_GET(NUMBER,rst_pin)))
#define BTM_BT_LINK_PIN  ((uint32_t) (1 << OPTION_GET(NUMBER,link_pin)))


static volatile AT91PS_USART us_dev_regs = ((AT91PS_USART) OPTION_GET(NUMBER,serial_port_offset));

#define BTM_BT_BAUD_RATE 19200

EMBOX_UNIT_INIT(btm_bluetooth_init);

#define BUFF_SIZE 27

static uint8_t btm_bt_read_buff[BUFF_SIZE];
static int btm_bt_read_len;

static int nop_rx(int len, void *data) {
	return 0;
}
static int nop(void) {
	return 0;
Val   get_or_set_socket_linger_option   (Task* task,  Val arg)   {
    //===============================
    //
    // Mythryl type: (Socket_Fd, Null_Or(Null_Or(Int))) -> Null_Or(Int)
    //
    // Set/get the SO_LINGER option as follows:
    //   NULL		=> get current setting
    //   THE(NULL)	=> disable linger
    //   THE(THE t)	=> enable linger with timeout t.
    //
    // This function gets bound as   ctl_linger   in:
    //
    //     src/lib/std/src/socket/socket-guts.pkg
    //

													ENTER_MYTHRYL_CALLABLE_C_FN(__func__);

    int  socket = GET_TUPLE_SLOT_AS_INT( arg, 0 );
    Val	    ctl = GET_TUPLE_SLOT_AS_VAL( arg, 1 );							// Last use of 'arg'.

    struct linger   optVal;
    int		    status;

    if (ctl == OPTION_NULL) {
        //
	socklen_t  optSz =  sizeof( struct linger );

	RELEASE_MYTHRYL_HEAP( task->hostthread, __func__, NULL );
	    //
	    status =  getsockopt( socket, SOL_SOCKET, SO_LINGER, (sockoptval_t)&optVal, &optSz );
	    //
	RECOVER_MYTHRYL_HEAP( task->hostthread, __func__ );

	ASSERT( status < 0  ||  optSz == sizeof( struct linger ));
	//
    } else {
	//
	ctl = OPTION_GET(ctl);

	if (ctl == OPTION_NULL) {
	    optVal.l_onoff = 0;	    // Argument is THE(NULL); disable linger.
	} else {
	    optVal.l_onoff = 1;	    // argument is THE t; enable linger.
	    optVal.l_linger = TAGGED_INT_TO_C_INT(OPTION_GET(ctl));
	}

	RELEASE_MYTHRYL_HEAP( task->hostthread, __func__, NULL );
	    //
	    status = setsockopt (socket, SOL_SOCKET, SO_LINGER, (sockoptval_t)&optVal, sizeof(struct linger));
	    //
	RECOVER_MYTHRYL_HEAP( task->hostthread, __func__ );
    }

    if (status < 0)  		return RAISE_SYSERR__MAY_HEAPCLEAN(task, status, NULL);
    if (optVal.l_onoff == 0)    return OPTION_NULL;

    Val result =   OPTION_THE(  task,  TAGGED_INT_FROM_C_INT( optVal.l_linger )  );

									    EXIT_MYTHRYL_CALLABLE_C_FN(__func__);
    return result;
}
Пример #15
0
	size_t size; /** full size of the block including the block descriptor */
};

/* Helper macro. Size of a block_desc structure. */
#define BLOCK_DESC_SIZE  sizeof(struct block_desc)
/* Helper macro. The end of the using memory pool*/
#define LAST_ADDRESS     (memory + (uint32_t)sizeof(memory))

/* This is a pointer to a current free memory.
 * We start to search appropriate memory block for allocation
 * from this address */
static char *current_space;

/* This is our pool memory, that we allocated,
 * size defined from pool_size option. */
static char memory[OPTION_GET(NUMBER,pool_size)];

/*This function check address whether it from our pool or not */
static int correct_address(char *address) {
	return (((uint32_t) address >= (uint32_t) memory)
			&& ((uint32_t) address < (uint32_t) LAST_ADDRESS));
}

/* This function get  status of the memory block
 * 1 - block is free, can be allocated
 * 0 - block is busy, used now */
static int get_available(struct block_desc *md) {
	return (md->is_available);
}

/* This function marks the memory block as free (available) */
Пример #16
0
#include <fs/file_desc.h>
#include <fs/fs_driver.h>
#include <fs/vfs.h>
#include <fs/file_operation.h>
#include <fs/tmpfs.h>

#include <util/err.h>


/* tmpfs filesystem description pool */
POOL_DEF(tmpfs_fs_pool, struct tmpfs_fs_info, OPTION_GET(NUMBER,tmpfs_descriptor_quantity));

/* tmpfs file description pool */
POOL_DEF(tmpfs_file_pool, struct tmpfs_file_info, OPTION_GET(NUMBER,inode_quantity));

INDEX_DEF(tmpfs_file_idx,0,OPTION_GET(NUMBER,inode_quantity));

/* define sizes in 4096 blocks */
#define MAX_FILE_SIZE OPTION_GET(NUMBER,tmpfs_file_size)
#define FILESYSTEM_SIZE OPTION_GET(NUMBER,tmpfs_filesystem_size)

#define TMPFS_NAME "tmpfs"
#define TMPFS_DEV  "/dev/ram#"
#define TMPFS_DIR  "/tmp"

static char sector_buff[PAGE_SIZE()];/* TODO */
static char tmpfs_dev[] = TMPFS_DEV;

static int tmpfs_format(void *path);
static int tmpfs_mount(void *dev, void *dir);
Пример #17
0
 * @file
 * @brief
 *
 * @date 17.03.2012
 * @author Anton Kozlov
 */

#include <drivers/diag.h>
#include <string.h>

#include <framework/mod/options.h>

#define BUF_LEN OPTION_GET(NUMBER,buffer_len)

#if OPTION_GET(NUMBER, buffer_addr)
static char *const diag_buf = (char *const)OPTION_GET(NUMBER, buffer_addr);
#else
static char diag_buf[BUF_LEN];
#endif

static int diag_buf_head = 0;

static void diag_mem_putc(const struct diag *diag, char ch) {

	diag_buf[diag_buf_head++] = ch;

	if (diag_buf_head == BUF_LEN) {
		diag_buf_head = 0;
	}

	diag_buf[diag_buf_head] = '\0';
Пример #18
0
static const struct uart_ops stm32_uart_ops = {
		.uart_getc = stm32_uart_getc,
		.uart_putc = stm32_uart_putc,
		.uart_hasrx = stm32_uart_hasrx,
		.uart_setup = stm32_uart_setup,
};

static struct uart stm32_uart0 = {
		.uart_ops = &stm32_uart_ops,
		.irq_num = EVAL_COM_IRQn,
		.base_addr = (unsigned long) EVAL_COM,
};

static const struct uart_params uart_defparams = {
		.baud_rate = OPTION_GET(NUMBER,baud_rate),
		.parity = 0,
		.n_stop = 1,
		.n_bits = 8,
		.irq = true,
};

static const struct uart_params diag_defparams = {
		.baud_rate = OPTION_GET(NUMBER,baud_rate),
		.parity = 0,
		.n_stop = 1,
		.n_bits = 8,
		.irq = false,
};

const struct uart_diag DIAG_IMPL_NAME(__EMBUILD_MOD__) = {
Пример #19
0
	dev_regs = (volatile struct apbuart_regs *) OPTION_GET(NUMBER,apbuart_base);
	return 0;
}
#else
# error "Either DRIVER_AMBAPP or apbuart_base option must be defined"
#endif /* DRIVER_AMBAPP */

static const struct uart_ops uart_ops = {
		.uart_getc = apbuart_getc,
		.uart_putc = apbuart_putc,
		.uart_hasrx = apbuart_has_symbol,
		.uart_setup = apbuart_setup,
};

static struct uart uart0 = {
		.irq_num = OPTION_GET(NUMBER,irq_num),
		.base_addr = OPTION_GET(NUMBER,apbuart_base),
		.uart_ops = &uart_ops,
};

static const struct uart_params uart_defparams = {
		.baud_rate = OPTION_GET(NUMBER,baud_rate),
		.parity = 0,
		.n_stop = 1,
		.n_bits = 8,
		.irq = true,
};

static const struct uart_params uart_diag_params = {
		.baud_rate = OPTION_GET(NUMBER,baud_rate),
		.parity = 0,