Defines | Functions | Variables

hal/nrf24lu1p/hal_usb.c File Reference

Implementaion of the USB HAL. More...

#include "nrf24lu1p.h"
#include <stdint.h>
#include "nordic_common.h"
#include "hal_usb_desc.h"
#include "usb.h"
#include "hal_delay.h"
#include "usb_map.h"

Go to the source code of this file.

Defines

#define ALLOCATE_USB_MAP
#define CALCULATE_CS_IN_PTR(ep)   (uint8_t xdata*)(&in1cs + 2 * ((ep & 0x7f) - 1 ))
#define CALCULATE_CS_OUT_PTR(ep)   (uint8_t xdata*)(&out1cs + 2 * ( (ep & 0x7f) - 1 ))
#define CALCULATE_BC_OUT_PTR(ep)   (uint8_t xdata *)(&out0bc + (ep * 2 ))
#define CALCULATE_BC_IN_PTR(ep)   (uint8_t xdata *)(&in0bc + ((ep & 0x7f ) * 2))
#define CALCULATE_BUF_IN_PTR(ep)   (uint8_t xdata *)(in0buf - (( ep & 0x7f) * 128))
#define CALCULATE_BUF_OUT_PTR(ep)   (uint8_t xdata *)(out0buf - (ep * 128 ))
#define ICH4

Functions

void hal_usb_init (_Bool usb_disconnect, hal_usb_cb_device_req_t device_req, hal_usb_cb_reset_t reset, hal_usb_cb_resume_t resume, hal_usb_cb_suspend_t suspend)
void hal_usb_endpoint_stall (uint8_t ep_num, _Bool stall)
uint8_t hal_usb_get_address ()
void hal_usb_endpoint_config (uint8_t ep_num, uint8_t ep_size, hal_usb_cb_endpoint_t endpoint_isr)
void hal_usb_wakeup ()
void hal_usb_reset ()
hal_usb_state_t hal_usb_get_state ()
void hal_usb_send_data (uint8_t ep_num, uint8_t *array, uint8_t count)
void hal_usb_bus_disconnect ()
void hal_usb_bus_connect ()
void hal_usb_sleep ()
 USB_WU_ISR ()
 USB_ISR ()

Variables

hal_usb_t volatile g_hal_usb

Detailed Description

Implementaion of the USB HAL.

Definition in file hal_usb.c.


Define Documentation

#define ALLOCATE_USB_MAP

Definition at line 32 of file hal_usb.c.

#define CALCULATE_CS_IN_PTR (   ep )    (uint8_t xdata*)(&in1cs + 2 * ((ep & 0x7f) - 1 ))

Definition at line 38 of file hal_usb.c.

#define CALCULATE_CS_OUT_PTR (   ep )    (uint8_t xdata*)(&out1cs + 2 * ( (ep & 0x7f) - 1 ))

Definition at line 39 of file hal_usb.c.

#define CALCULATE_BC_OUT_PTR (   ep )    (uint8_t xdata *)(&out0bc + (ep * 2 ))

Definition at line 42 of file hal_usb.c.

#define CALCULATE_BC_IN_PTR (   ep )    (uint8_t xdata *)(&in0bc + ((ep & 0x7f ) * 2))

Definition at line 43 of file hal_usb.c.

#define CALCULATE_BUF_IN_PTR (   ep )    (uint8_t xdata *)(in0buf - (( ep & 0x7f) * 128))

Definition at line 46 of file hal_usb.c.

#define CALCULATE_BUF_OUT_PTR (   ep )    (uint8_t xdata *)(out0buf - (ep * 128 ))

Definition at line 47 of file hal_usb.c.

#define ICH4

Function Documentation

USB_WU_ISR (  )

Definition at line 626 of file hal_usb.c.

                       : 0x005b
{
#define ICH4
  #ifdef ICH4
  uint8_t t;
  #endif

  // Check if the wakeup source is the pin to the USB controller
  // If it is by the pin to the USB controller we want to start
  // a remote wakeup
  if( ( usbcs & 0x80 ) == 0x80 )
  {
    // Reset the wakesrc indicator
    usbcs = 0x80;

    // If we are allowed to perform a remote wakeup do that
    if( ( g_hal_usb.bm_state & USB_BM_STATE_ALLOW_REMOTE_WAKEUP ) == USB_BM_STATE_ALLOW_REMOTE_WAKEUP )
    {
  #ifdef ICH4
      // Force the J state on the USB lines
      usbcs |= 0x02;

      // Typical 5.4us delay
      _nop_();
      _nop_();

      t = usbcs;

      // Stop J state on the USB lines
      t &= ~0x02;

      // Signal remote resume
      t |= 0x01;

      // We have to set this register in one operation to avoid
      // idle state is restored between the forced J and resume state
      usbcs = t;
#else
      usbcs |= 0x01;  // Turn on the resume signal on the USB bus
#endif
      delay_ms(7); //.1.7.7 Resume: The remote wakeup device must hold the resume signaling for at 
                    // least 1 ms but for no more than 15ms

      usbcs &= ~0x01; // Turn off the resume signal on the USB bus
    }
  }
  else 
  {
    // We are awoken by the bus
    g_hal_usb.bm_state |= USB_BM_STATE_HOST_WU;
  }

  if((g_hal_usb.bm_state & USB_BM_STATE_CONFIGURED ) == USB_BM_STATE_CONFIGURED)
  {
    g_hal_usb.state = CONFIGURED;
  }
  else
  {
    g_hal_usb.state = DEFAULT;
  }

  // Call resume callback
  g_hal_usb.resume();
}
USB_ISR (  )

Definition at line 716 of file hal_usb.c.

{
  uint8_t ep;
  uint8_t ret;
  uint8_t xdata *cs_ptr;
  uint8_t xdata *buf_ptr;
  uint8_t xdata *bc_ptr;

  switch(ivec)
  {
    case INT_SUDAV:
      usbirq = 0x01;
      isr_sudav();
      break;
    case INT_SOF:
      usbirq = 0x02;
      break;
    case INT_SUTOK:
      usbirq = 0x04;
      i_packetizer.data_ptr = NULL;
      i_packetizer.data_size = 0;
      i_packetizer.pkt_size = 0;
      stall_data_size0 = 0;
      break;
    case INT_SUSPEND:
      usbirq = 0x08;
      isr_suspend();
      break;
    case INT_USBRESET:
      usbirq = 0x10;
      isr_usbreset();
      break;
    case INT_EP0IN:
      in_irq = 0x01;
      packetizer_isr_ep0_in();
      break;
    case INT_EP0OUT:
      out_irq = 0x01;
      i_packetizer.data_size = 0;
      usb_process_dev_req_cb_response();
      break;
      case INT_EP1IN:
      case INT_EP2IN:
      case INT_EP3IN:
      case INT_EP4IN:
      case INT_EP5IN:
        // Calculate IN endpoint number
        ep = (ivec - INT_EP0IN ) >> 3;// INT_EP2IN - INT_EP1IN == 8 ;   
        // Clear interrupt 
        in_irq = ( 1 << ep );

        cs_ptr = CALCULATE_CS_IN_PTR(ep);
        buf_ptr = CALCULATE_BUF_IN_PTR(ep);
        bc_ptr = CALCULATE_BC_IN_PTR(ep);
    
        // Call registered callback
        ret = i_endpoint_in_isr[ep - 1](buf_ptr, bc_ptr);
        usb_process_ep_response(ret, cs_ptr, bc_ptr);
        break;
      case INT_EP1OUT:
      case INT_EP2OUT:
      case INT_EP3OUT:
      case INT_EP4OUT:
      case INT_EP5OUT:
        // Calculate OUT endpoint number
        ep = (ivec - INT_EP0OUT) >> 3;          // INT_EP2OUT - INT_EP1OUT == 8

        // Clear interrupt
        out_irq = ( 1 << ep );
        
        cs_ptr = CALCULATE_CS_OUT_PTR(ep);
        buf_ptr = CALCULATE_BUF_OUT_PTR(ep);
        bc_ptr = CALCULATE_BC_OUT_PTR(ep);

        // Call registered callback
        ret = (i_endpoint_out_isr[ep - 1])(buf_ptr, bc_ptr);
        usb_process_ep_response(ret, cs_ptr, bc_ptr);
        break;
    default:
      break;
  };
}