Пример #1
0
// Lua: cli()
// Lua: cli() - to disable all interrupts
// or cli( id1, resnum1, [resnum2], ..., [resnumn] ) - to disable a specific id/resnum(s)
static int cpu_cli( lua_State *L )
{
#ifdef BUILD_LUA_INT_HANDLERS
  unsigned i;
  elua_int_id id;
  elua_int_resnum resnum;

  if( lua_gettop( L ) > 0 )
  {
    id = ( elua_int_id )luaL_checkinteger( L, 1 );
    for( i = 2; i <= lua_gettop( L ); i ++ )
    {
      resnum = ( elua_int_resnum )luaL_checkinteger( L, i );
      platform_cpu_set_interrupt( id, resnum, PLATFORM_CPU_DISABLE );
    }
    elua_int_disable( id );
  }
  else
#else // #ifdef BUILD_LUA_INT_HANDLERS
  if( lua_gettop( L ) > 0 )
    return luaL_error( L, "Lua interrupt support not available." );
#endif // #ifdef BUILD_LUA_INT_HANDLERS
  platform_cpu_set_global_interrupts( PLATFORM_CPU_DISABLE );
  return 0;
}
Пример #2
0
int platform_uart_set_buffer( unsigned id, unsigned log2size )
{
  if( id == SERMUX_PHYS_ID ) // mere mortals aren't allowed to mess with VUART physical interface buffering
    return PLATFORM_ERR;
#ifdef BUF_ENABLE_UART
  if( log2size == 0 )
  {
    if( id >= SERMUX_SERVICE_ID_FIRST ) // Virtual UARTs need buffers no matter what
      return PLATFORM_ERR; 
    // Disable buffering
    buf_set( BUF_ID_UART, id, BUF_SIZE_NONE, BUF_DSIZE_U8 );
  }  
  else
  {
    // Enable buffering
    if( buf_set( BUF_ID_UART, id, log2size, BUF_DSIZE_U8 ) == PLATFORM_ERR )
      return PLATFORM_ERR;
    if( id >= SERMUX_SERVICE_ID_FIRST ) // No need for aditional setup on virtual UARTs
      return PLATFORM_OK;    
    // Enable UART RX interrupt 
    if( platform_cpu_set_interrupt( INT_UART_RX, id, PLATFORM_CPU_ENABLE ) != PLATFORM_INT_OK )
      return PLATFORM_ERR;
    // Setup our C handler
    if( picoc_int_get_c_handler( INT_UART_RX ) != cmn_uart_rx_inthandler )
      prev_uart_rx_handler = picoc_int_set_c_handler( INT_UART_RX, cmn_uart_rx_inthandler );
  }
  return PLATFORM_OK;
#else // BUF_ENABLE_UART
  return PLATFORM_ERR;
#endif // BUF_ENABLE_UART
}
Пример #3
0
int platform_uart_set_buffer( unsigned id, unsigned log2size )
{
  if( id == SERMUX_PHYS_ID ) // mere mortals aren't allowed to mess with VUART physical interface buffering
    return PLATFORM_ERR;
#ifdef BUF_ENABLE_UART
  if( log2size == 0 )
  {
    if( id >= SERMUX_SERVICE_ID_FIRST ) // Virtual UARTs need buffers no matter what
      return PLATFORM_ERR; 

    if( id != CDC_UART_ID )
    {
      // Disable the UART interrupt if it was set
      if( platform_cpu_get_interrupt( INT_UART_RX, id ) ==  PLATFORM_CPU_ENABLE )
        platform_cpu_set_interrupt( INT_UART_RX, id, PLATFORM_CPU_DISABLE );

      // If our C interrupt handler is installed, restore the previous one
      if( elua_int_get_c_handler( INT_UART_RX ) == cmn_uart_rx_inthandler )
        (void) elua_int_set_c_handler( INT_UART_RX, prev_uart_rx_handler );
    }

    // Disable buffering
    buf_set( BUF_ID_UART, id, BUF_SIZE_NONE, BUF_DSIZE_U8 );
  }  
  else
  {
    // Enable buffering
    if( buf_set( BUF_ID_UART, id, log2size, BUF_DSIZE_U8 ) == PLATFORM_ERR )
      return PLATFORM_ERR;
    if( id == CDC_UART_ID || id >= SERMUX_SERVICE_ID_FIRST ) // No need for aditional setup on virtual UARTs or the CDC UART
      return PLATFORM_OK;    
    // Setup our C handler
    if( elua_int_get_c_handler( INT_UART_RX ) != cmn_uart_rx_inthandler )
      prev_uart_rx_handler = elua_int_set_c_handler( INT_UART_RX, cmn_uart_rx_inthandler );

    // Enable UART RX interrupt 
    if( platform_cpu_set_interrupt( INT_UART_RX, id, PLATFORM_CPU_ENABLE ) < 0 )
      return PLATFORM_ERR;
  }
  return PLATFORM_OK;
#else // BUF_ENABLE_UART
  return PLATFORM_ERR;
#endif // BUF_ENABLE_UART
}
Пример #4
0
// Send one command to the keyboard
// Gets the command and the number of expected ACKs from ps2_send_buffer at
// the index received as argument
static void ps2h_send_cmd( int idx )
{
  unsigned i;
  int par;
  int cmd = ps2_send_buffer[ idx * 2 ];
  int nacks = ps2_send_buffer[ idx * 2 + 1 ];

  platform_cpu_set_interrupt( INT_GPIO_NEGEDGE, PS2_CLOCK_PIN_RESNUM, PLATFORM_CPU_DISABLE );
  ps2h_clock_low();
  platform_timer_delay( PS2_TIMER_ID, 1000 );
  ps2h_data_low();
  ps2h_clock_high();
  ps2h_wait_clock_hl();
  for( i = par = 0; i < 8; i ++, cmd >>= 1 ) 
  {
    if( cmd & 1 )
    {
      ps2h_data_high();
      par ++;
    }
    else
      ps2h_data_low();
    ps2h_wait_clock_hl();
  }
  // Send parity now
  if( par & 1 )
    ps2h_data_low();
  else
    ps2h_data_high();
  ps2h_wait_clock_hl();
  // Release data line (stop bit)
  ps2h_data_high();
  ps2h_wait_clock_hl();
  // Read and interpret ACK bit
  if( ps2h_data_get() == 1 ) // error, [TODO] what to do here?
  {
  }
  while( ps2h_clock_get() == 0 );
  // Clear pending interrupts and re-enable keyboard interrupt
  ps2_acks_to_receive = nacks;
  platform_cpu_get_interrupt_flag( INT_GPIO_NEGEDGE, PS2_CLOCK_PIN_RESNUM, PLATFORM_CPU_CLEAR_FLAG );
  platform_cpu_set_interrupt( INT_GPIO_NEGEDGE, PS2_CLOCK_PIN_RESNUM, PLATFORM_CPU_ENABLE );
}
Пример #5
0
// Setup the serial multiplexer
void cmn_uart_setup_sermux()
{
  // Enable UART RX interrupt 
  if( platform_cpu_set_interrupt( INT_UART_RX, SERMUX_PHYS_ID, PLATFORM_CPU_ENABLE ) == PLATFORM_INT_OK )
  {
    // Setup our C handler
    if( picoc_int_get_c_handler( INT_UART_RX ) != cmn_uart_rx_inthandler )
      prev_uart_rx_handler = picoc_int_set_c_handler( INT_UART_RX, cmn_uart_rx_inthandler );
  }
  else // We don't have a choice but to get stuck here, as we can't print an error anyway, since the console most likely lives on a virtual UART
    while( 1 );      
}
Пример #6
0
//Lua: setidxtrig( id, resnum, tmr_id, count )
static int enc_set_index_handler( lua_State *L )
{
  elua_int_id id;
  
  id = ( elua_int_id )luaL_checkinteger( L, 1 );
  if( id < ELUA_INT_FIRST_ID || id > INT_ELUA_LAST )
    return luaL_error( L, "invalid interrupt ID" );
  index_resnum = ( elua_int_resnum )luaL_checkinteger( L, 2 );
  index_tmr_id = luaL_checkinteger( L, 3 );
  MOD_CHECK_ID( timer, index_tmr_id );
  index_count = ( u16 )luaL_checkinteger( L, 4 );

  platform_cpu_set_interrupt( id, index_resnum, PLATFORM_CPU_ENABLE );
  prev_handler = elua_int_set_c_handler( id, index_handler );
}
Пример #7
0
void ps2_init()
{
  // Setup pins (inputs with external pullups)
  platform_pio_op( PS2_DATA_PORT, 1 << PS2_DATA_PIN, PLATFORM_IO_PIN_DIR_INPUT );
  platform_pio_op( PS2_CLOCK_PORT, 1 << PS2_CLOCK_PIN, PLATFORM_IO_PIN_DIR_INPUT );
  platform_pio_op( PS2_RESET_PORT, 1 << PS2_RESET_PIN, PLATFORM_IO_PIN_DIR_INPUT );
  platform_pio_op( PS2_DATA_PORT, 1 << PS2_DATA_PIN, PLATFORM_IO_PIN_CLEAR );
  platform_pio_op( PS2_CLOCK_PORT, 1 << PS2_CLOCK_PIN, PLATFORM_IO_PIN_CLEAR );
  platform_pio_op( PS2_RESET_PORT, 1 << PS2_RESET_PIN, PLATFORM_IO_PIN_CLEAR );
  // Enable interrupt on clock line 
  ps2_prev_handler = elua_int_set_c_handler( INT_GPIO_NEGEDGE, ps2_hl_clk_int_handler ); 
  platform_cpu_set_interrupt( INT_GPIO_NEGEDGE, PS2_CLOCK_PIN_RESNUM, PLATFORM_CPU_ENABLE );
  // Reset + typematic rate
  ps2_send( 3, PS2_CMD_RESET, 2, PS2_CMD_TYPE_RATE, 1, 0x00, 1 );
}
Пример #8
0
// Lua: sei() - to enable all interrupts
// or sei( id1, resnum1, [resnum2], ..., [resnumn] ) - to enable a specific id/resnum(s)
static int cpu_sei( lua_State *L )
{
  unsigned i;
  elua_int_id id;
  elua_int_resnum resnum;  

  if( lua_gettop( L ) > 0 )
  {
    id = ( elua_int_id )luaL_checkinteger( L, 1 );
    for( i = 2; i <= lua_gettop( L ); i ++ )
    {
      resnum = ( elua_int_resnum )luaL_checkinteger( L, i );
      platform_cpu_set_interrupt( id, resnum, PLATFORM_CPU_ENABLE );
    }
    elua_int_enable( id );
  }
  else
    platform_cpu_set_global_interrupts( PLATFORM_CPU_ENABLE );
  return 0;
}