int platform_init() { unsigned i; TIM_InitTypeDef tim; TIM_TypeDef* base; // System configuration platform_config_scu(); // PIO setup for( i = 0; i < 10; i ++ ) GPIO_DeInit( ( GPIO_TypeDef* )port_data[ i ] ); // UART setup (only STR9_UART is used in this example) platform_uart_setup( 0, 115200, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 ); // Initialize timers for( i = 0; i < 4; i ++ ) { base = ( TIM_TypeDef* )timer_data[ i ]; TIM_DeInit( base ); TIM_StructInit( &tim ); tim.TIM_Clock_Source = TIM_CLK_APB; tim.TIM_Prescaler = 255; TIM_Init( base, &tim ); TIM_CounterCmd( base, TIM_START ); } // Set the send/recv functions std_set_send_func( uart_send ); std_set_get_func( uart_recv ); return PLATFORM_OK; }
int platform_init() { unsigned i; TIM_InitTypeDef tim; TIM_TypeDef* base; // System configuration platform_config_scu(); // PIO setup for( i = 0; i < 10; i ++ ) GPIO_DeInit( ( GPIO_TypeDef* )port_data[ i ] ); // Initialize VIC VIC_DeInit(); // UART setup (only STR9_UART is used in this example) platform_uart_setup( CON_UART_ID, CON_UART_SPEED, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 ); // Initialize timers for( i = 0; i < 4; i ++ ) { base = ( TIM_TypeDef* )timer_data[ i ]; TIM_DeInit( base ); TIM_StructInit( &tim ); tim.TIM_Clock_Source = TIM_CLK_APB; tim.TIM_Prescaler = 255; TIM_Init( base, &tim ); TIM_CounterCmd( base, TIM_START ); } cmn_platform_init(); return PLATFORM_OK; }
// Open Connection / Client int transport_open_connection(lua_State *L, Handle *handle) { // Get args & Set up connection unsigned uart_id, tmr_id; check_num_args( L,3 ); // 1st arg is uart num, 2nd arg is tmr_id, 3nd is handle if ( !lua_isnumber( L, 1 ) ) return luaL_error( L, "1st arg must be uart num" ); if ( !lua_isnumber( L, 2 ) ) return luaL_error( L, "2nd arg must be timer num" ); uart_id = lua_tonumber( L, 1 ); MOD_CHECK_ID( uart, uart_id ); tmr_id = lua_tonumber( L, 1 ); MOD_CHECK_ID( timer, tmr_id ); adispatch_buff = -1; handle->tpt.fd = ( int )uart_id; handle->tpt.tmr_id = tmr_id; // Setup uart platform_uart_setup( (unsigned int) uart_id, 115200, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 ); return 1; }
// Open Listener / Server void transport_open_listener( lua_State *L, ServerHandle *handle ) { // Get args & Set up connection unsigned uart_id, tmr_id; check_num_args( L,3 ); // 1st arg is uart num, 2nd arg is tmr_id, 3nd is handle if ( !lua_isnumber( L, 1 ) ) luaL_error( L, "1st arg must be uart num" ); if ( !lua_isnumber( L, 2 ) ) luaL_error( L, "2nd arg must be timer num" ); // @@@ Error handling could likely be better here uart_id = lua_tonumber( L, 1 ); if( !platform_uart_exists( uart_id ) ) luaL_error( L, "invalid uart id" ); tmr_id = lua_tonumber( L, 2 ); if( !platform_timer_exists( tmr_id ) ) luaL_error( L, "invalid timer id" ); handle->ltpt.fd = ( int )uart_id; handle->ltpt.tmr_id = tmr_id; // Setup uart platform_uart_setup( (unsigned int) uart_id, 115200, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 ); }
void cmn_platform_init() { #ifdef BUILD_INT_HANDLERS platform_int_init(); #endif #ifdef BUILD_SERMUX unsigned i; unsigned bufsizes[] = SERMUX_BUFFER_SIZES; // Setup the serial multiplexer platform_uart_setup( SERMUX_PHYS_ID, SERMUX_PHYS_SPEED, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 ); platform_uart_set_flow_control( SERMUX_PHYS_ID, SERMUX_FLOW_TYPE ); cmn_uart_setup_sermux(); // Set buffers for all virtual UARTs for( i = 0; i < sizeof( bufsizes ) / sizeof( unsigned ); i ++ ) platform_uart_set_buffer( i + SERMUX_SERVICE_ID_FIRST, bufsizes[ i ] ); #endif // #ifdef BUILD_SERMUX #if defined( CON_UART_ID ) && CON_UART_ID < SERMUX_SERVICE_ID_FIRST // Setup console UART platform_uart_setup( CON_UART_ID, CON_UART_SPEED, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 ); platform_uart_set_flow_control( CON_UART_ID, CON_FLOW_TYPE ); platform_uart_set_buffer( CON_UART_ID, CON_BUF_SIZE ); #endif // #if defined( CON_UART_ID ) && CON_UART_ID < SERMUX_SERVICE_ID_FIRST #ifndef BUILD_WEB_SERVER // Set the send/recv functions std_set_send_func( uart_send ); std_set_get_func( uart_recv ); #endif #ifdef BUILD_XMODEM // Initialize XMODEM xmodem_init( xmodem_send, xmodem_recv ); #endif #ifdef BUILD_TERM // Initialize terminal term_init( TERM_LINES, TERM_COLS, term_out, term_in, term_translate ); #endif }
// Lua: actualbaud = setup( id, baud, databits, parity, stopbits ) static int uart_setup( lua_State* L ) { unsigned id, databits, parity, stopbits; u32 baud, res; id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( uart, id ); baud = luaL_checkinteger( L, 2 ); databits = luaL_checkinteger( L, 3 ); parity = luaL_checkinteger( L, 4 ); stopbits = luaL_checkinteger( L, 5 ); res = platform_uart_setup( id, baud, databits, parity, stopbits ); lua_pushinteger( L, res ); return 1; }
void boot_rpc( void ) { lua_State *L = lua_open(); luaL_openlibs(L); /* open libraries */ // Set up UART for 8N1 w/ adjustable baud rate platform_uart_setup( RPC_UART_ID, RPC_UART_SPEED, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 ); // Start RPC Server lua_getglobal( L, "rpc" ); lua_getfield( L, -1, "server" ); lua_pushnumber( L, RPC_UART_ID ); lua_pushnumber( L, RPC_TIMER_ID ); lua_pcall( L, 2, 0, 0 ); }
// Lua: actualbaud = setup( id, baud, databits, parity, stopbits ) static int uart_setup( lua_State* L ) { unsigned id, databits, parity, stopbits; u32 baud, res; id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( uart, id ); if( id >= SERMUX_SERVICE_ID_FIRST ) return luaL_error( L, "uart.setup can't be called on virtual UARTs" ); baud = luaL_checkinteger( L, 2 ); databits = luaL_checkinteger( L, 3 ); parity = luaL_checkinteger( L, 4 ); stopbits = luaL_checkinteger( L, 5 ); res = platform_uart_setup( id, baud, databits, parity, stopbits ); lua_pushinteger( L, res ); return 1; }
// Lua: actualbaud = setup( id, baud, databits, parity, stopbits, echo ) static int uart_setup( lua_State* L ) { unsigned id, databits, parity, stopbits, echo = 1; u32 baud, res; id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( uart, id ); baud = luaL_checkinteger( L, 2 ); databits = luaL_checkinteger( L, 3 ); parity = luaL_checkinteger( L, 4 ); stopbits = luaL_checkinteger( L, 5 ); if(lua_isnumber(L,6)){ echo = lua_tointeger(L,6); if(echo!=0) uart0_echo = true; else uart0_echo = false; } res = platform_uart_setup( id, baud, databits, parity, stopbits ); lua_pushinteger( L, res ); return 1; }