示例#1
0
文件: nfc.c 项目: Vinhuit/Freescale
uint32_t nfc_init
   (
      /* [IN] the NAND flash information */
      IO_NANDFLASH_STRUCT_PTR nandflash_ptr
   )
{ /* Body */

   uint32_t result = NANDFLASHERR_NO_ERROR;
   NFC_MemMapPtr nfc_ptr;
   uint32_t nand_id, block_size_kB, density, num_ecc_bytes;
   NANDFLASH_INFO_STRUCT_PTR nand_info_ptr;

   /* Initialize NFC I/O Pins */
   nfc_io_init();

   /* Get the pointer to nfc registers structure */
   nfc_ptr = _bsp_get_nfc_address();

   /* Create NANDFLASH_INFO_STRUCT based on NAND ID read from the NAND Flash,
      if not defined before manually */
   if((nandflash_ptr->NANDFLASH_INFO_PTR) == NULL)
   {
       nand_info_ptr = (NANDFLASH_INFO_STRUCT_PTR)_mem_alloc_system_zero(
                       (_mem_size)sizeof(NANDFLASH_INFO_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
       if(nand_info_ptr == NULL)
       {
          return((uint32_t)MQX_OUT_OF_MEMORY);
       } /* Endif */
#endif

       if (((*nandflash_ptr->IOCTL)(nandflash_ptr,NANDFLASH_IOCTL_GET_ID,&nand_id)) == NANDFLASHERR_NO_ERROR)
       {
           nand_info_ptr->PHY_PAGE_SIZE =
             (_mem_size)(((nand_id & NANDFLASH_ID_PAGE_SIZE_MASK) + 1)*1024);

           if((nand_id & NANDFLASH_ID_SPARE_BYTES_NUM_MASK)>>2 == 1)
           {
               nand_info_ptr->SPARE_AREA_SIZE = (_mem_size)64;
           }

           if(nand_id & NANDFLASH_ID_BLOCK_SIZE_MASK)
           {
               nand_info_ptr->BLOCK_SIZE =
                 (_mem_size)((nand_id & NANDFLASH_ID_BLOCK_SIZE_MASK)*8192);
           }
           else
           {
               nand_info_ptr->BLOCK_SIZE = 65536;
           }

           block_size_kB = (nand_info_ptr->BLOCK_SIZE)/1024;
           density = (nand_id & NANDFLASH_ID_DENSITY_MASK)>>16;
           switch(density)
           {
               case NANDFLASH_DENSITY_1Gb:
                   /* nand_info_ptr->NUM_BLOCKS = 1024/8*1024/block_size_kB; */
                   nand_info_ptr->NUM_BLOCKS = 131072/block_size_kB;
                   break;

               case NANDFLASH_DENSITY_2Gb:
                   nand_info_ptr->NUM_BLOCKS = 2*131072/block_size_kB;
                   break;

               case NANDFLASH_DENSITY_4Gb:
                   nand_info_ptr->NUM_BLOCKS = 4*131072/block_size_kB;
                   break;

               case NANDFLASH_DENSITY_8Gb:
                   nand_info_ptr->NUM_BLOCKS = 8*131072/block_size_kB;
                   break;

               case NANDFLASH_DENSITY_16Gb:
                   nand_info_ptr->NUM_BLOCKS = 16*131072/block_size_kB;
                   break;

               default:
                   break;
           }

           nand_info_ptr->WIDTH =
             (_mqx_uint)(8 + ((nand_id & NANDFLASH_ID_WIDTH_MASK)>>3));

           nandflash_ptr->NANDFLASH_INFO_PTR = nand_info_ptr;
           nandflash_ptr->NUM_VIRTUAL_PAGES  =
             ((nand_info_ptr->BLOCK_SIZE)/(nandflash_ptr->VIRTUAL_PAGE_SIZE))*(nand_info_ptr->NUM_BLOCKS);
           nandflash_ptr->PHY_PAGE_SIZE_TO_VIRTUAL_PAGE_SIZE_RATIO =
             (nand_info_ptr->PHY_PAGE_SIZE)/(nandflash_ptr->VIRTUAL_PAGE_SIZE);
       }
uint_32 _kusb_dcd_polled_init
   (
      /* [IN] Initialization information for the device being opened */
      KUSB_DCD_INIT_STRUCT_PTR      io_init_ptr,

      /* [OUT] Address to store device specific information */
      pointer _PTR_                 io_info_ptr_ptr,

      /* [IN] The rest of the name of the device opened */
      char_ptr                      open_name_ptr

   )
{ /* Body */
   USBDCD_MemMapPtr             usb_dcd_ptr;
   KUSB_DCD_INFO_STRUCT_PTR     io_info_ptr;
   SIM_MemMapPtr                sim = SIM_BASE_PTR;
   USB_MemMapPtr                usbotg = USB0_BASE_PTR;
   usb_dcd_ptr = _bsp_get_usb_dcd_base_address();
   if (NULL == usb_dcd_ptr)
   {
        return USB_DCD_ERROR_CHANNEL_INVALID;
   }

   io_info_ptr = (KUSB_DCD_INFO_STRUCT_PTR)_mem_alloc_system_zero ((uint_32)sizeof (KUSB_DCD_INFO_STRUCT));
   if (NULL == io_info_ptr)
   {
      return MQX_OUT_OF_MEMORY;
   }
   _mem_set_type (io_info_ptr, MEM_TYPE_IO_USB_DCD_INFO_STRUCT);

   *io_info_ptr_ptr 				= io_info_ptr;
   io_info_ptr->INIT          = *io_init_ptr;
   io_info_ptr->USB_DCD_PTR   = usb_dcd_ptr;
   io_info_ptr->METHOD        = USB_DCD_POLLED;
   io_info_ptr->STATE         = USB_DCD_DISABLE;

   /* USB DCD board specific initialization */

   /* USB Clock Gating for OTG */
#ifdef BSP_TWRMCF51JF
   sim->SCGC6 |= SIM_SCGC6_USBOTG_MASK;
#elif BSP_TWR_K70F120M || BSP_TWR_K60F120M
   sim->SCGC4 |= SIM_SCGC4_USBFS_MASK;
#else
   sim->SCGC4 |= SIM_SCGC4_USBOTG_MASK;
#endif
   /* USB Clock Gating for DCD */
   sim->SCGC6 |= SIM_SCGC6_USBDCD_MASK;

   /* USB pre-initialization */
   usbotg->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
   while (usbotg->USBTRC0 & USB_USBTRC0_USBRESET_MASK){};
   usbotg->ISTAT |= USB_ISTAT_USBRST_MASK;

   /* USB DCD initialization */

   /* CLOCK SPEED (in Khz)*/
   if (io_init_ptr->CLOCK_SPEED < 0x400) /*Khz*/
   {
   	if (io_init_ptr->CLOCK_SPEED < 0x04)
      	 return USB_DCD_CLOCK_SPEED_INVALID;
   	usb_dcd_ptr->CLOCK = ((uint_32)((uint_32)io_init_ptr->CLOCK_SPEED << USBDCD_CLOCK_CLOCK_SPEED_SHIFT)) & USBDCD_CLOCK_CLOCK_SPEED_MASK;
   }
   else
   {
   	if (((uint_32)(io_init_ptr->CLOCK_SPEED/1000)) > 0x3FF)
   		 return USB_DCD_CLOCK_SPEED_INVALID;
      usb_dcd_ptr->CLOCK = (((uint_32)(((uint_32)(io_init_ptr->CLOCK_SPEED/1000)) << USBDCD_CLOCK_CLOCK_SPEED_SHIFT)) & USBDCD_CLOCK_CLOCK_SPEED_MASK) | USBDCD_CLOCK_CLOCK_UNIT_MASK;
   }
   /* Timer0 initialization */
   usb_dcd_ptr->TIMER0 = (uint_32)((uint_32)(io_init_ptr->TSEQ_INIT)<<USBDCD_TIMER0_TSEQ_INIT_SHIFT) & USBDCD_TIMER0_TSEQ_INIT_MASK;

   /* Timer1 initialization */
   usb_dcd_ptr->TIMER1 = ((uint_32)((uint_32)(io_init_ptr->TDCD_DBNC)<<USBDCD_TIMER1_TDCD_DBNC_SHIFT) & USBDCD_TIMER1_TDCD_DBNC_MASK) |
   							 ((uint_32)((uint_32)(io_init_ptr->TVDPSRC_ON)<<USBDCD_TIMER1_TVDPSRC_ON_SHIFT) & USBDCD_TIMER1_TVDPSRC_ON_MASK);

   /* Timer2 initialization */
   usb_dcd_ptr->TIMER2 = ((uint_32)((uint_32)(io_init_ptr->TVDPSRC_CON)<<USBDCD_TIMER2_TVDPSRC_CON_SHIFT) & USBDCD_TIMER2_TVDPSRC_CON_MASK) |
   							 ((uint_32)((uint_32)(io_init_ptr->CHECK_DM)<<USBDCD_TIMER2_CHECK_DM_SHIFT) & USBDCD_TIMER2_CHECK_DM_MASK);

   /* Disable USB DCD module */
   usb_dcd_ptr->CONTROL = USBDCD_CONTROL_IACK_MASK | USBDCD_CONTROL_SR_MASK;

   return USB_DCD_OK;
} /* Endbody */
示例#3
0
文件: eninit.c 项目: gxliu/MQX_3.8.0
uint_32 ENET_initialize_ex
   (
         /* [IN] optional parameters */
      const ENET_PARAM_STRUCT *   param_ptr,
         /* [IN] the local Ethernet address */
      _enet_address           address,
         /* [OUT] the Ethernet state structure */
      _enet_handle _PTR_      handle
   )
{
   ENET_CONTEXT_STRUCT_PTR enet_ptr = NULL;//, other_enet_ptr;
   uint_32                 result;
   boolean                 vlan;
   
   if (param_ptr == NULL)
      return ENETERR_INVALID_DEVICE;

   if (param_ptr->NUM_RX_BUFFERS < param_ptr->NUM_RX_ENTRIES) 
      return ENETERR_INVALID_INIT_PARAM;
   
   enet_ptr = _mqx_get_io_component_handle(IO_ENET_COMPONENT);
   
   while (enet_ptr) {
      if (enet_ptr->PARAM_PTR->ENET_IF->MAC_NUMBER == param_ptr->ENET_IF->MAC_NUMBER)
         break;
      
      enet_ptr = enet_ptr->NEXT;
   }
   
   if (enet_ptr) {
      *handle = enet_ptr;
   
      return ENETERR_INITIALIZED_DEVICE;
   }
   else
      *handle = NULL;

   // Allocate the Enet context structure
   enet_ptr = _mem_alloc_system_zero(sizeof(ENET_CONTEXT_STRUCT));
   if (NULL==enet_ptr)
      return ENETERR_ALLOC_CFG;
      
   _mem_set_type((pointer)enet_ptr, MEM_TYPE_IO_ENET_CONTEXT_STRUCT);

   // Initialize the Enet context structure
   eaddrcpy(enet_ptr->ADDRESS, address);
   enet_ptr->PARAM_PTR = param_ptr;
   vlan = (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_VLAN) == ENET_OPTION_VLAN;
   enet_ptr->MaxTxFrameSize = ENET_max_framesize(enet_ptr->PARAM_PTR->TX_BUFFER_SIZE,0,vlan);
   enet_ptr->MaxRxFrameSize = ENET_max_framesize(enet_ptr->PARAM_PTR->RX_BUFFER_SIZE,enet_ptr->PARAM_PTR->NUM_LARGE_BUFFERS,vlan);
   
   _lwsem_create(&enet_ptr->CONTEXT_LOCK, 1);
    
   // Initialize the MAC
   result = (*param_ptr->ENET_IF->MAC_IF->INIT)(enet_ptr);
   
   if (ENET_OK == result) {
      // Link the driver into the kernel component list
      _mqx_link_io_component_handle(IO_ENET_COMPONENT,enet_ptr, (pointer *)&enet_ptr->NEXT);

      *handle = enet_ptr;
   } else {
      _mem_free(enet_ptr);
      *handle = NULL;
   }
   
   return result;
}   
示例#4
0
_mqx_int gpio_cpu_open
   (
      /* [IN] the file handle for the device */
      MQX_FILE_PTR fd_ptr,

      /* [IN] the file name */
      char_ptr   file_name,

      /* [IN] pointer to parameters */
      char_ptr   param_ptr
   )
{ /* Body */
    _mqx_int i;
    GPIO_DEV_DATA_PTR dev_data_ptr = (GPIO_DEV_DATA_PTR) fd_ptr->DEV_DATA_PTR;
 
    /* if file_name is used, then the user wants to open peripheral */
    if ((file_name != NULL) && (*file_name != 0)) {
        if (!strncmp(file_name, "gpio:write", 11))  /* user wants write access to GPIO */
            dev_data_ptr->type = DEV_OUTPUT;
        else if (!strncmp(file_name, "gpio:output", 12))  /* user wants write access to GPIO */
            dev_data_ptr->type = DEV_OUTPUT;
        else if (!strncmp(file_name, "gpio:read", 10)) /* user wants read access to GPIO */
            dev_data_ptr->type = DEV_INPUT;
        else if (!strncmp(file_name, "gpio:input", 11)) /* user wants read access to GPIO */
            dev_data_ptr->type = DEV_INPUT;
        else
        /* peripherals not used yet */
            return IO_ERROR;
    }
    else
        return IO_ERROR;
 
    /* check which irq pin to be opened and prepare interrupt service routine */
    for (i = 1; i < 8; i++) {
        if ((i & 0x01) == 0)
            continue;
        if ((dev_data_ptr->irqp_map.reg.portnq | dev_data_ptr->irqn_map.reg.portnq) & (1 << i)) {
            if (MQX_init_struct.MQX_HARDWARE_INTERRUPT_LEVEL_MAX < i)
                return IO_ERROR; /* hardware level must be higher than interrupt level */
            if (NULL == _int_install_isr(MCF5225_INT_EPORT0_EPF1 - 1 + i, gpio_eport_irq, NULL))
                return IO_ERROR; /* could not install interrupt routine */
            /* this is only to enable the interrupt source, level and sublevel values are hardwired */                
            _mcf5225_int_init(MCF5225_INT_EPORT0_EPF1 - 1 + i, i, BSP_EPORT_EPFX_INT_SUBLEVEL_MIDPOINT, TRUE);
        }
    }

    if ((param_ptr != NULL) && (dev_data_ptr->type == DEV_OUTPUT)) { /* set pins status before selecting GPIO function */
        /* note that this is similar to GPIO_IOCTL_WRITE function, but no checking is performed
           (was done in io_gpio_open function) */
        GPIO_PIN_STRUCT _PTR_  pin_table;
        uint_32        addr;
        uint_8         pin;
        GPIO_PIN_MAP_PTR    temp_pin0_map_ptr;
        GPIO_PIN_MAP_PTR    temp_pin1_map_ptr;

        if (NULL == (temp_pin0_map_ptr = (GPIO_PIN_MAP_PTR) _mem_alloc_system_zero(sizeof(GPIO_PIN_MAP))))
            return IO_ERROR;

        if (NULL == (temp_pin1_map_ptr = (GPIO_PIN_MAP_PTR) _mem_alloc_system_zero(sizeof(GPIO_PIN_MAP)))) {
            _mem_free(temp_pin0_map_ptr);
            return IO_ERROR;
        }

        /* prepare pin map */
        for (pin_table = (GPIO_PIN_STRUCT _PTR_) param_ptr; *pin_table != GPIO_LIST_END; pin_table++) {
            addr = (*pin_table & GPIO_PIN_ADDR) >> 3; /* prepare address of port */ 
            pin = 1 << (*pin_table & 0x07);  /* prepare bit mask */
            if (*pin_table & GPIO_PIN_STATUS)
                temp_pin1_map_ptr->memory8[addr] |= pin;
            else
                temp_pin0_map_ptr->memory8[addr] |= pin;
        }
        /* ok, now we can apply new map */
        /* note: applying the map after collecting pins is due to have pins applied in one instruction */
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->PORTTEP_SETTE)) + 0) = temp_pin1_map_ptr->memory32[0];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->CLRTE)) + 0) = ~temp_pin0_map_ptr->memory32[0];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->PORTTEP_SETTE)) + 1) = temp_pin1_map_ptr->memory32[1];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->CLRTE)) + 1) = ~temp_pin0_map_ptr->memory32[1];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->PORTTEP_SETTE)) + 2) = temp_pin1_map_ptr->memory32[2];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->CLRTE)) + 2) = ~temp_pin0_map_ptr->memory32[2];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->PORTTEP_SETTE)) + 3) = temp_pin1_map_ptr->memory32[3];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->CLRTE)) + 3) = ~temp_pin0_map_ptr->memory32[3];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->PORTTEP_SETTE)) + 4) = temp_pin1_map_ptr->memory32[4];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->CLRTE)) + 4) = ~temp_pin0_map_ptr->memory32[4];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->PORTTEP_SETTE)) + 5) = temp_pin1_map_ptr->memory32[5];
        * (((uint_32 _PTR_) (&mcf5225_gpio_ptr->CLRTE)) + 5) = ~temp_pin0_map_ptr->memory32[5];

        _mem_free(temp_pin1_map_ptr);
        _mem_free(temp_pin0_map_ptr);
    }
示例#5
0
_mqx_int _io_pipe_open
   (
      /* [IN] the file handle for the device being opened */
      FILE_DEVICE_STRUCT_PTR fd_ptr,
       
      /* [IN] the remaining portion of the name of the device */
      char              *open_name_ptr,

      /* [IN] the flags to be used during operation:
      ** echo, translation, xon/xoff
      */
      char              *flags
   )
{ /* Body */
   IO_DEVICE_STRUCT_PTR          io_dev_ptr = fd_ptr->DEV_PTR;
   IO_PIPE_INIT_STRUCT_PTR       io_pipe_init_ptr;
   IO_PIPE_INFO_STRUCT_PTR       io_pipe_info_ptr;
   MUTEX_ATTR_STRUCT             mutex_attr;
   uint32_t                       result = MQX_OK;

   /* Allocate a Pipe information structure */
   io_pipe_info_ptr = _mem_alloc_system_zero(
      (uint32_t)sizeof(IO_PIPE_INFO_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (io_pipe_info_ptr == NULL){
      return(MQX_OUT_OF_MEMORY);
   }/* Endif */
#endif 

   fd_ptr->DEV_DATA_PTR = io_pipe_info_ptr;
   io_pipe_init_ptr = (IO_PIPE_INIT_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR;
   
   io_pipe_info_ptr->QUEUE_SIZE = io_pipe_init_ptr->QUEUE_SIZE;

   /* Initialize mutexes */
   result = _mutatr_init(&mutex_attr); 
   
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   _mutatr_set_wait_protocol(&mutex_attr, MUTEX_PRIORITY_QUEUEING);
   _mutatr_set_sched_protocol(&mutex_attr, MUTEX_PRIO_INHERIT);

   result = _mutex_init(&io_pipe_info_ptr->READ_MUTEX, &mutex_attr);
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 
   
   result = _mutex_init(&io_pipe_info_ptr->WRITE_MUTEX, &mutex_attr);
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   result = _mutex_init(&io_pipe_info_ptr->ACCESS_MUTEX, &mutex_attr);
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   /* Initialize semaphores */

   result = _lwsem_create(&io_pipe_info_ptr->FULL_SEM, 0);
#if MQX_CHECK_ERRORS
   if (result != MQX_OK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   result = _lwsem_create(&io_pipe_info_ptr->EMPTY_SEM, 0);
#if MQX_CHECK_ERRORS
   if (result != MQX_OK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 
                          
   /* Allocate queue structure for pipe char queue */
   io_pipe_info_ptr->QUEUE = (void *)_mem_alloc_system(
      sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + io_pipe_info_ptr->QUEUE_SIZE);

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (io_pipe_info_ptr->QUEUE == NULL){
      _mem_free(io_pipe_info_ptr);
      return(MQX_OUT_OF_MEMORY);
   }/* Endif */
#endif            

   /* Initialize Pipe queue */
   _CHARQ_INIT(io_pipe_info_ptr->QUEUE, io_pipe_init_ptr->QUEUE_SIZE);
   
   return(result);

} /* Endbody */
示例#6
0
uint_32 _ki2c_polled_init
   (
      /* [IN] Initialization information for the device being opened */
      KI2C_INIT_STRUCT_PTR io_init_ptr,

      /* [OUT] Address to store device specific information */
      pointer _PTR_        io_info_ptr_ptr,
       
      /* [IN] The rest of the name of the device opened */
      char_ptr             open_name_ptr

   )
{ /* Body */
   I2C_MemMapPtr           i2c_ptr;
   VKI2C_INFO_STRUCT_PTR   io_info_ptr;

   i2c_ptr = _bsp_get_i2c_base_address (io_init_ptr->CHANNEL);
   if (NULL == i2c_ptr)
   {
        return I2C_ERROR_CHANNEL_INVALID;
   }
  
   io_info_ptr = (VKI2C_INFO_STRUCT_PTR)_mem_alloc_system_zero ((uint_32)sizeof (KI2C_INFO_STRUCT));
   if (NULL == io_info_ptr) 
   {
      return MQX_OUT_OF_MEMORY;
   }
   _mem_set_type ((pointer)io_info_ptr, MEM_TYPE_IO_I2C_INFO_STRUCT);

   /* I2C board specific initialization */
   _bsp_i2c_io_init (io_init_ptr->CHANNEL);

   *io_info_ptr_ptr                              = (pointer)io_info_ptr;
   io_info_ptr->INIT                             = *io_init_ptr;
   io_info_ptr->I2C_PTR                          = i2c_ptr;
   io_info_ptr->OLD_ISR                          = NULL;
   io_info_ptr->OLD_ISR_DATA                     = NULL;
   io_info_ptr->VECTOR                           = 0;
   io_info_ptr->MODE                             = io_init_ptr->MODE;
   io_info_ptr->STATE                            = I2C_STATE_READY;
   io_info_ptr->ADDRESSEE                        = 0;
   io_info_ptr->OPERATION                        = 0;
   io_info_ptr->RX_REQUEST                       = 0;
   io_info_ptr->RX_BUFFER                        = NULL;
   io_info_ptr->RX_IN                            = 0;
   io_info_ptr->RX_OUT                           = 0;
   io_info_ptr->TX_BUFFER                        = NULL;
   io_info_ptr->TX_IN                            = 0;
   io_info_ptr->TX_OUT                           = 0;
   io_info_ptr->STATISTICS.INTERRUPTS            = 0;
   io_info_ptr->STATISTICS.RX_PACKETS            = 0;
   io_info_ptr->STATISTICS.TX_PACKETS            = 0;
   io_info_ptr->STATISTICS.TX_LOST_ARBITRATIONS  = 0;
   io_info_ptr->STATISTICS.TX_ADDRESSED_AS_SLAVE = 0;
   io_info_ptr->STATISTICS.TX_NAKS               = 0;

   /* Disable and clear I2C before initializing it */
   i2c_ptr->C1 = 0x00;
  
   /* Clear out all I2C events */
   i2c_ptr->S = 0x00;

   /* Set the station address for SLAVE receive operations */      
   i2c_ptr->A1 = io_init_ptr->STATION_ADDRESS << 1;
   
   /* Set the frequency divider for the nearest found baud rate */
   i2c_ptr->F = _ki2c_set_baudrate( BSP_I2C_CLOCK, io_init_ptr->BAUD_RATE ); 
   
   /* Enable I2C */
   i2c_ptr->C1 |= I2C_C1_IICEN_MASK;

   return I2C_OK;
   
} /* Endbody */
示例#7
0
int_32 Shell_smtp (int_32 argc, char_ptr argv[])
{
    struct addrinfo           hints;
    struct addrinfo           *result, *rp;
    int_32                    retval = 0;
    uint_32                   sfd = 0;
    int_32                    err_code = 0;
    boolean                   print_help;
    boolean                   shorthelp = FALSE;
    SMTP_PARAM_STRUCT         params;
    char_ptr                  errstr = NULL;
    char_ptr                  server = NULL;
    char_ptr                  optstring = ":f:t:s:u:p:m:h";
    int_32                    next_option;
    char_ptr                  email_text = NULL;
    uint_32                   email_size = 0;
    MQX_TICK_STRUCT           ticks;
    MQX_XDATE_STRUCT          xdate;
    char                      date_str[DATE_LENGTH];
    
    params.login = NULL;
    params.pass = NULL;

    print_help = Shell_check_help_request(argc, argv, &shorthelp);
    
    if (print_help)
    {
        if (!shorthelp)
        {
            fprintf(stdout,"Usage:"); 
        }
        fprintf(stdout, "%s", argv[0]);
        print_usage(stdout, shorthelp);
        err_code = SHELL_EXIT_SUCCESS;
        return(err_code);
    }
    
    /* Parse command line options */
    do
    {
        next_option = Shell_getopt(argc, argv, optstring);
        switch (next_option)
        {
            case 'f':
                params.envelope.from = optarg;
                break;
            case 't':
                params.envelope.to = optarg;
                break;
            case 'm':
                params.text = optarg;
                break;
            case 's':
                server = optarg;
                break;
            case 'u':
                params.login = optarg;
                break;
            case 'p':
                params.pass = optarg;
                break;
            case 'h':
                print_usage (stdout, FALSE);
                return(SHELL_EXIT_SUCCESS);
            case '?': /* The user specified an invalid option. */
                print_usage(stderr, TRUE);
                return(SHELL_EXIT_ERROR);
            case ':': /* Option has a missing parameter. */
                printf("Option -%c requires a parameter.\n", next_option);
                return(SHELL_EXIT_ERROR);
            case -1: /* Done with options. */
                break;
            default:
                break;
        }
    }while(next_option != -1);
    
    
    _time_get_ticks(&ticks);
    _time_ticks_to_xdate(&ticks,&xdate);    

    snprintf(date_str, DATE_LENGTH, "%s, %d %s %d %02d:%02d:%02d -0000",
        wday[xdate.WDAY],xdate.MDAY, months[xdate.MONTH-1],xdate.YEAR, xdate.HOUR, xdate.MIN, xdate.SEC);
    /* Evaluate email size */
    email_size = strlen(params.envelope.from) + 
                 strlen(params.envelope.to) +
                 strlen(params.text) +
                 strlen(date_str) +
                 strlen("From: <>\r\n") +
                 strlen("To: <>\r\n") + 
                 strlen("Subject: Freescale Tower Email\r\n") +
                 strlen("Date: \r\n\r\n") +   
                 strlen("\r\n") + 1;
    /* Allocate space */
    email_text = (char_ptr) _mem_alloc_zero(email_size);
    if (email_text == NULL)
    {
        fprintf(stderr, "  Unable to allocate memory for email message.\n");
        err_code = SHELL_EXIT_ERROR;
        return(err_code);
    }
    /* Prepare email message */
    snprintf(email_text, email_size, "From: <%s>\r\n"
                                     "To: <%s>\r\n"
                                     "Subject: Freescale Tower Email\r\n"
                                     "Date: %s\r\n\r\n"
                                     "%s\r\n",
                                     params.envelope.from,
                                     params.envelope.to,
                                     date_str,
                                     params.text);
    params.text = email_text;
    
    _mem_zero(&hints, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM; /* TCP socket */
    hints.ai_flags = AI_PASSIVE;     /* For wildcard IP address */
    hints.ai_protocol = 0;           /* Any protocol */
    hints.ai_canonname = NULL;
    hints.ai_addr = NULL;
    hints.ai_next = NULL;

    retval = getaddrinfo(server, NULL, &hints, &result);
    if (retval != 0)
    {
        fprintf(stderr, "  getaddrinfo failed. Error: 0x%X\n", retval);
        err_code = SHELL_EXIT_ERROR;
        return(err_code);
    }
    /* Allocate buffer for error message */
    errstr = (char_ptr) _mem_alloc_system_zero(ERR_MSG_BUFF_SIZE);
    /* Try to send email using one of addresses. If it fails try another one. */
    for (rp = result; rp != NULL; rp = rp->ai_next)
    {
        _mem_copy(rp->ai_addr, &params.server, sizeof(params.server));
        /* Try to send email */
        retval = SMTP_send_email(&params, errstr, ERR_MSG_BUFF_SIZE);
        /* If connection failed try another address */
        if (retval != SMTP_ERR_CONN_FAILED)
        {
            break;
        }
    }
    /* No address succeeded */
    if (rp == NULL)
    {
        fprintf(stderr, "  Unable to connect to %s.\n", server);
        err_code = SHELL_EXIT_ERROR;
    }

    if (retval != SMTP_OK)
    {
        printf("  Email sending failed%s %s\n", (strlen(errstr) > 0) ? ":":".", errstr);
        err_code = SHELL_EXIT_ERROR;
    }
    else
    {
        printf("  Email send. Server response: %s", errstr);
    }
    /* Cleanup */
    freeaddrinfo(result);
    _mem_free(errstr);
    _mem_free(email_text);
    return(err_code);
} 
示例#8
0
/*
 * Allocate server structure, init sockets, etc.
 */
FTPSRV_STRUCT* ftpsrv_create_server(FTPSRV_PARAM_STRUCT* params)
{
    FTPSRV_STRUCT *server = NULL;
    uint32_t error;
    uint32_t error4 = FTPSRV_OK;
    uint32_t error6 = FTPSRV_OK;

    if ((server = _mem_alloc_system_zero(sizeof(FTPSRV_STRUCT))) == NULL)
    {
        return(NULL);
    }
    _mem_set_type(server, MEM_TYPE_FTPSRV_STRUCT);

    error = _lwsem_create(&server->tid_sem, 1);
    if (error != MQX_OK)
    {
        goto EXIT;
    }

    error = ftpsrv_set_params(server, params);
    if (error != FTPSRV_OK)
    {
        goto EXIT;
    }
    
    /* Allocate space for session pointers */
    server->session = RTCS_mem_alloc_zero(sizeof(FTPSRV_SESSION_STRUCT*) * server->params.max_ses);
    if (server->session == NULL)
    {
        goto EXIT;
    }

    /* Allocate space for session task IDs */
    server->ses_tid = RTCS_mem_alloc_zero(sizeof(_rtcs_taskid) * server->params.max_ses);
    if (server->ses_tid == NULL)
    {
        goto EXIT;
    }

    /* Init sockets. */
    if (params->af & AF_INET)
    {
        /* Setup IPv4 server socket */
        error4 = ftpsrv_init_socket(server, AF_INET);
    }
    if (params->af & AF_INET6)
    {
        /* Setup IPv6 server socket */
        error6 = ftpsrv_init_socket(server, AF_INET6);
    }

    if ((error4 != FTPSRV_OK) || (error6 != FTPSRV_OK))
    {
        ftpsrv_destroy_server(server);
        return(NULL);
    }
    server->run = 1;
    return(server);
    EXIT:
    ftpsrv_destroy_server(server);
    return(NULL);
}
示例#9
0
_mqx_uint _event_create_internal
   (
      /* [IN] the string name for the event */
      char _PTR_              name_ptr,

      /* [OUT] where the event pointer is */
      EVENT_STRUCT_PTR _PTR_  event_ptr_ptr
   )
{ /* Body */
            KERNEL_DATA_STRUCT_PTR     kernel_data;
   register EVENT_COMPONENT_STRUCT_PTR event_component_ptr;
   register EVENT_STRUCT_PTR           event_ptr;
            _mqx_uint                   result;
   
   _GET_KERNEL_DATA(kernel_data);                                         

   _KLOGE2(KLOG_event_create, name_ptr);

#if MQX_CHECK_ERRORS
   if (kernel_data->IN_ISR) {
      _KLOGX2(KLOG_event_create, MQX_CANNOT_CALL_FUNCTION_FROM_ISR);
      return(MQX_CANNOT_CALL_FUNCTION_FROM_ISR);
   } /* Endif */
#endif

   event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR)
      kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS];
   if (event_component_ptr == NULL) {
      result = _event_create_component(EVENT_DEFAULT_INITIAL_NUMBER,
         EVENT_DEFAULT_GROW_NUMBER, EVENT_DEFAULT_MAXIMUM_NUMBER);
      event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR)
         kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS];
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
      if (event_component_ptr == NULL){
         _KLOGX2(KLOG_event_create, result);
        return(result);
      } /* Endif */
#endif
   } /* Endif */

#if MQX_CHECK_VALIDITY
   if (event_component_ptr->VALID != EVENT_VALID){
      _KLOGX2(KLOG_event_create, MQX_INVALID_COMPONENT_BASE);
      return(MQX_INVALID_COMPONENT_BASE);
   } /* Endif */
#endif

   event_ptr = (EVENT_STRUCT_PTR)_mem_alloc_system_zero(
      (_mem_size)sizeof(EVENT_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (event_ptr == NULL) {
      _KLOGX2(KLOG_event_create, MQX_OUT_OF_MEMORY);
      return(MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif
   _mem_set_type(event_ptr, MEM_TYPE_EVENT);

   _QUEUE_INIT(&event_ptr->WAITING_TASKS, EVENT_MAX_WAITING_TASKS);

   strncpy(event_ptr->NAME, name_ptr, (_mqx_uint)NAME_MAX_NAME_SIZE-1);
   event_ptr->NAME[NAME_MAX_NAME_SIZE-1] = '\0';
   result = _name_add_internal(event_component_ptr->NAME_TABLE_HANDLE, 
      event_ptr->NAME, (_mqx_uint)event_ptr);
#if MQX_CHECK_ERRORS
   if (result != MQX_OK) {
      _mem_free(event_ptr);
      if (result == NAME_EXISTS) {
         _KLOGX2(KLOG_event_create, EVENT_EXISTS);
         return(EVENT_EXISTS);
      } else if (result == NAME_TABLE_FULL) {
         _KLOGX2(KLOG_event_create, EVENT_TABLE_FULL);
         return(EVENT_TABLE_FULL);
      } /* Endif */
      _KLOGX2(KLOG_event_create, result);
      return(result);
   } /* Endif */
#endif
   event_ptr->VALID = EVENT_VALID;

   *event_ptr_ptr = event_ptr;

   _KLOGX2(KLOG_event_create, result);
   return(result);

} /* Endbody */
示例#10
0
文件: asrc.c 项目: Vinhuit/Freescale
_mqx_uint _io_asrc_install
   (
      /* [IN] A string that identifies the device for fopen */
      char *               identifier,

      /* [IN] The I/O init function */
      _mqx_uint (_CODE_PTR_ init)(void *, void * *),

      /* The I/O open function */
      _mqx_uint (_CODE_PTR_ open)(void *, void *, char *),

      /* The I/O open function */
      _mqx_uint (_CODE_PTR_ close)(void *, void *),

      /* [IN] The I/O de-init function */
      _mqx_uint (_CODE_PTR_ deinit)(void *),

      /* [IN] The I/O ioctl function */
      _mqx_int  (_CODE_PTR_ ioctl)(void *, void *, _mqx_uint, _mqx_uint_ptr),

      /* [IN] The I/O init data pointer */
      void *               init_data_ptr,

      /* [IN] functions for pcm manager*/
      ASRC_PCMM_FUNCS_STRUCT_PTR   pcmm_funcs_ptr

   )

{ /* Body */
   IO_ASRC_DEVICE_STRUCT_PTR asrc_io_dev_ptr;
   MUTEX_ATTR_STRUCT mutex_attr;

   asrc_io_dev_ptr = (IO_ASRC_DEVICE_STRUCT_PTR)_mem_alloc_system_zero(
        (_mem_size)sizeof (IO_ASRC_DEVICE_STRUCT));
   if (asrc_io_dev_ptr == NULL)
   {
      return MQX_OUT_OF_MEMORY;
   }
   _mem_set_type (asrc_io_dev_ptr, MEM_TYPE_IO_ASRC_DEVICE_STRUCT);

   asrc_io_dev_ptr->DEV_INIT          = init;
   asrc_io_dev_ptr->DEV_OPEN          = open;
   asrc_io_dev_ptr->DEV_CLOSE         = close;
   asrc_io_dev_ptr->DEV_DEINIT        = deinit;
   asrc_io_dev_ptr->DEV_IOCTL         = ioctl;
   asrc_io_dev_ptr->DEV_INIT_DATA_PTR = init_data_ptr;
   asrc_io_dev_ptr->DEV_INFO_PTR      = NULL;
   asrc_io_dev_ptr->COUNT             = 0;

   asrc_io_dev_ptr->PCMM_DRV_FUNCS_PTR = pcmm_funcs_ptr;

   _mutatr_init(&mutex_attr);
   _mutatr_set_sched_protocol(&mutex_attr, MUTEX_PRIO_INHERIT);
   _mutex_init(&asrc_io_dev_ptr->DEV_MUTEX, &mutex_attr);

   if (NULL != pcmm_funcs_ptr) {
     /*register to pcm manager*/

     /*set pcm handle to a valid value*/
     asrc_io_dev_ptr->PCMM_DRV_HANDLE = PCMM_HANDLE_ASRC_VALID;

   }

   return (_io_dev_install_ext (identifier,
      _io_asrc_open,  _io_asrc_close,
      NULL,  NULL,
      _io_asrc_ioctl, _io_asrc_uninstall,
      (void *)asrc_io_dev_ptr));

} /* Endbody */
示例#11
0
/*FUNCTION****************************************************************
*
* Function Name    : _dspi_dma_init
* Returned Value   : MQX error code
* Comments         :
*    This function initializes the SPI driver
*
*END*********************************************************************/
static _mqx_int _dspi_dma_init
    (
        /* [IN] The initialization information for the device being opened */
        const void                     *init_data_ptr,

        /* [OUT] The address to store device specific information */
        void                           **io_info_ptr_ptr
    )
{
    DSPI_DMA_INIT_STRUCT_PTR           dspi_init_ptr = (DSPI_DMA_INIT_STRUCT_PTR)init_data_ptr;
    DSPI_DMA_INFO_STRUCT_PTR           dspi_info_ptr;
    VDSPI_REG_STRUCT_PTR               dspi_ptr;
    int                                result;

    #if PSP_HAS_DEVICE_PROTECTION
    if (!_bsp_dspi_enable_access(dspi_init_ptr->CHANNEL)) {
        return SPI_ERROR_CHANNEL_INVALID;
    }
    #endif

    /* Check channel */
    dspi_ptr = _bsp_get_dspi_base_address (dspi_init_ptr->CHANNEL);
    if (NULL == dspi_ptr)
    {
        return SPI_ERROR_CHANNEL_INVALID;
    }

    if (_bsp_dspi_io_init (dspi_init_ptr->CHANNEL) == -1)
    {
        return SPI_ERROR_CHANNEL_INVALID;
    }

    /* Initialize internal data */
    dspi_info_ptr = (DSPI_DMA_INFO_STRUCT_PTR)_mem_alloc_system_zero((uint32_t)sizeof(DSPI_DMA_INFO_STRUCT));
    if (dspi_info_ptr == NULL)
    {
        return MQX_OUT_OF_MEMORY;
    }
    _mem_set_type(dspi_info_ptr, MEM_TYPE_IO_SPI_INFO_STRUCT);

    *io_info_ptr_ptr = (void *)dspi_info_ptr;

    dspi_info_ptr->DSPI_PTR = dspi_ptr;
    dspi_info_ptr->CHANNEL = dspi_init_ptr->CHANNEL;
    dspi_info_ptr->CLOCK_SOURCE = dspi_init_ptr->CLOCK_SOURCE;

    _dspi_init_low(dspi_info_ptr->DSPI_PTR);

    /* Claim DMA channels and perform setup */
    if ((result = dma_channel_claim(&dspi_info_ptr->DMA_RX_CHANNEL, dspi_init_ptr->DMA_RX_CHANNEL)) != MQX_OK
        || (result = dma_channel_claim(&dspi_info_ptr->DMA_TX_CHANNEL, dspi_init_ptr->DMA_TX_CHANNEL)) != MQX_OK
        || (result = dma_channel_setup(dspi_info_ptr->DMA_RX_CHANNEL, 1, 0)) != MQX_OK
        || (result = dma_channel_setup(dspi_info_ptr->DMA_TX_CHANNEL, 1, 0)) != MQX_OK
        || (result = dma_request_source(dspi_info_ptr->DMA_RX_CHANNEL, dspi_init_ptr->DMA_RX_SOURCE)) != MQX_OK
        || (result = dma_request_source(dspi_info_ptr->DMA_TX_CHANNEL, dspi_init_ptr->DMA_TX_SOURCE)) != MQX_OK
       )
    {
        dma_channel_release(dspi_info_ptr->DMA_RX_CHANNEL);
        dma_channel_release(dspi_info_ptr->DMA_TX_CHANNEL);
        _mem_free(dspi_info_ptr);
        return result;
    }

    /* Allocate cache line aligned block of memory and split it in half to form RX and TX buffer */
    dspi_info_ptr->RX_BUF = _mem_alloc_system(4*PSP_CACHE_LINE_SIZE);
    if (dspi_info_ptr->RX_BUF == NULL)
    {
        dma_channel_release(dspi_info_ptr->DMA_RX_CHANNEL);
        dma_channel_release(dspi_info_ptr->DMA_TX_CHANNEL);
        _mem_free(dspi_info_ptr);
        return MQX_OUT_OF_MEMORY;
    }
    dspi_info_ptr->TX_BUF = dspi_info_ptr->RX_BUF + 2*PSP_CACHE_LINE_SIZE;

    _lwsem_create(&dspi_info_ptr->EVENT_IO_FINISHED, 0);

    dma_callback_reg(dspi_info_ptr->DMA_RX_CHANNEL, _dspi_dma_callback, dspi_info_ptr);

    /* Route data s to DMA */
    dspi_ptr->RSER = DSPI_RSER_RFDF_DIRS_MASK | DSPI_RSER_RFDF_RE_MASK | DSPI_RSER_TFFF_DIRS_MASK | DSPI_RSER_TFFF_RE_MASK;
    dma_request_enable(dspi_info_ptr->DMA_RX_CHANNEL);
    dma_request_enable(dspi_info_ptr->DMA_TX_CHANNEL);

    return SPI_OK;
}
示例#12
0
_mqx_uint _io_pcb_shm_install
    (
        /* [IN] the name of this device */
        char    *device_name_ptr,

        /* [IN] the initialization record for this device */
        void       *init_ptr
    )
{
    IO_PCB_SHM_INFO_STRUCT_PTR info_ptr;
    uint32_t                    tmp;

    info_ptr = _mem_alloc_system_zero(sizeof(IO_PCB_SHM_INFO_STRUCT));
    if (info_ptr == NULL) {
        return(MQX_OUT_OF_MEMORY);
    }

    info_ptr->INIT = *((IO_PCB_SHM_INIT_STRUCT_PTR)init_ptr);

    /* Initialize the info structure */
    /*
    ** Set the Tx and Rx RINGPTR address base
    **
    */
    info_ptr->TX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)(
        ((IO_PCB_SHM_INIT_STRUCT_PTR)init_ptr)->TX_BD_ADDR);

    info_ptr->TX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)
        SHM_DESCR_ALIGN((uint32_t)info_ptr->TX_RING_PTR);
    tmp = (uint32_t)(IO_PCB_SHM_BUFFER_STRUCT_PTR)(((IO_PCB_SHM_INIT_STRUCT_PTR)
        init_ptr)->TX_LIMIT_ADDR);
    tmp -= (uint32_t)(info_ptr->TX_RING_PTR);
    tmp /= sizeof(IO_PCB_SHM_BUFFER_STRUCT);

    info_ptr->TXENTRIES = tmp;
    info_ptr->TX_LENGTH = tmp;
    info_ptr->TXNEXT = 0;
    info_ptr->TXLAST = 0;

    info_ptr->RX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)(
        ((IO_PCB_SHM_INIT_STRUCT_PTR)init_ptr)->RX_BD_ADDR);

    info_ptr->RX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)
        SHM_DESCR_ALIGN((uint32_t)info_ptr->RX_RING_PTR);

    tmp = (uint32_t)(IO_PCB_SHM_BUFFER_STRUCT_PTR)(((IO_PCB_SHM_INIT_STRUCT_PTR)
        init_ptr)->RX_LIMIT_ADDR);
    tmp -= (uint32_t)(info_ptr->RX_RING_PTR);
    tmp /= sizeof(IO_PCB_SHM_BUFFER_STRUCT);
    info_ptr->RXENTRIES = tmp;
    info_ptr->RX_LENGTH = tmp;
    info_ptr->RXNEXT = 0;
    info_ptr->RXLAST = 0;

    return (_io_dev_install_ext(device_name_ptr,
        _io_pcb_shm_open,
        _io_pcb_shm_close,
        _io_pcb_shm_read,
        _io_pcb_shm_write,
        _io_pcb_shm_ioctl,
        _io_pcb_shm_uninstall,
        (void *)info_ptr));

}
示例#13
0
pointer usb_filesystem_install( 
    pointer     usb_handle,
    char_ptr    block_device_name,
    char_ptr    partition_manager_name,
    char_ptr    file_system_name )
{
    uint_32                    partition_number;
    uchar_ptr                  dev_info;
    int_32                     error_code;
    USB_FILESYSTEM_STRUCT_PTR  usb_fs_ptr;

    usb_fs_ptr = _mem_alloc_system_zero(sizeof(USB_FILESYSTEM_STRUCT));
    if (usb_fs_ptr==NULL)
    {
        return NULL;
    }

    /* Install USB device */
    error_code = _io_usb_mfs_install(block_device_name, 0, (pointer)usb_handle);
    if (error_code != MQX_OK)
    {
        printf("Error while installing USB device (0x%X)\n", error_code);
        return NULL;
    }
    usb_fs_ptr->DEV_NAME = block_device_name;

    /* Open the USB mass storage  device */
    _time_delay(500);
    // printf("open msd dev\n");
    usb_fs_ptr->DEV_FD_PTR = fopen(block_device_name, 0);

    if (usb_fs_ptr->DEV_FD_PTR == NULL)
    {
        printf("Unable to open USB device\n");
        /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,USB_DEV_OPEN_FAIL);
        return NULL;
    } 

    _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_SET_BLOCK_MODE, NULL);

    /* Get the vendor information and display it */
    printf("\n************************************************************************\n");
    _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_VENDOR_INFO, &dev_info);
    printf("Vendor Information:     %-1.8s Mass Storage Device\n",dev_info);
    _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_PRODUCT_ID, &dev_info);
    printf("Product Identification: %-1.16s\n",dev_info);
    _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_PRODUCT_REV, &dev_info);
    printf("Product Revision Level: %-1.4s\n",dev_info);
    printf("************************************************************************\n");

    /* Try to install the partition manager */
    // printf("_io_part_mgr_install\n");
    error_code = _io_part_mgr_install(usb_fs_ptr->DEV_FD_PTR, partition_manager_name, 0);
    if (error_code != MFS_NO_ERROR)
    {
        printf("Error while initializing partition manager: %s\n", MFS_Error_text((uint_32)error_code));
        /* usb_filesystem_uninstall */usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_INIT_FAIL);
        return NULL;
    } 
    usb_fs_ptr->PM_NAME = partition_manager_name;

    /* Open partition manager */
   // printf("fopen partition\n");
    usb_fs_ptr->PM_FD_PTR = fopen(partition_manager_name, NULL);
    if (usb_fs_ptr->PM_FD_PTR == NULL)
    {
        error_code = ferror(usb_fs_ptr->PM_FD_PTR);
        printf("Error while opening partition manager: %s\n", MFS_Error_text((uint_32)error_code));
        /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_OPEN_FAIL);
        return NULL;
    } 

    /* Select partition */
    partition_number = 1;
    // printf("select partition\n");
    error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_SEL_PART, &partition_number);

    if (error_code == MFS_NO_ERROR)
    {
        printf("Installing MFS over partition...\n");

        /* Validate partition */
        // printf("Validate partition\n");
        error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_VAL_PART, NULL);
        if (error_code != MFS_NO_ERROR)
        {
            printf("Error while validating partition: %s\n", MFS_Error_text((uint32_t)error_code));
            printf("Not installing MFS.\n");
            /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_VALIDATE_FAIL);
            return NULL;
        }

        /* Install MFS over partition */
        //printf("Install MFS over partition\n");
        error_code = _io_mfs_install(usb_fs_ptr->PM_FD_PTR, file_system_name, 0);
        if (error_code != MFS_NO_ERROR)
        {
            printf("Error initializing MFS over partition: %s\n", MFS_Error_text((uint_32)error_code));
        }
    }
    else {

        printf("Installing MFS over USB device...\n");

        /* Install MFS over USB device driver */
        //printf("Install MFS over USB device driver\n");
        error_code = _io_mfs_install(usb_fs_ptr->DEV_FD_PTR, file_system_name, 0);
        if (error_code != MFS_NO_ERROR)
        {
            printf("Error initializing MFS: %s\n", MFS_Error_text((uint_32)error_code));
        }
    }

    /* Open file system */
    if (error_code == MFS_NO_ERROR)
    {
        usb_fs_ptr->FS_NAME = file_system_name;
        //printf("Open file system\n");
        usb_fs_ptr->FS_FD_PTR = fopen(file_system_name, NULL);
        error_code = ferror(usb_fs_ptr->FS_FD_PTR);
        if (error_code == MFS_NOT_A_DOS_DISK)
        {
            printf("NOT A DOS DISK! You must format to continue.\n");
        }
        else if (error_code != MFS_NO_ERROR)
        {
            printf("Error opening filesystem: %s\n", MFS_Error_text((uint_32)error_code));
            /* usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,MFS_OPEN_FAIL);
            return NULL;
        }

        printf("USB device installed to %s\n", file_system_name);  
    }
    else {
        
        /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,MFS_INIT_FAIL);
        return NULL;
    }

    return (pointer)usb_fs_ptr;
}
示例#14
0
uint_32 _mcf53xx_uart_serial_polled_init
   (
      /* [IN] the initialization information for the device being opened */
      MCF53XX_UART_SERIAL_INIT_STRUCT_PTR io_init_ptr,

      /* [OUT] the address to store device specific information */
      pointer _PTR_                       io_info_ptr_ptr,

      /* [IN] the rest of the name of the device opened */
      char _PTR_                          open_name_ptr
   )
{ /* Body */
   volatile MCF53XX_UART_STRUCT _PTR_  uart_ptr;
   MCF53XX_UART_SERIAL_INFO_STRUCT _PTR_ uart_info_ptr;
   uint_32                             channel;
   uint_32                             baud;

   uart_info_ptr = _mem_alloc_system_zero((uint_32)
      sizeof(MCF53XX_UART_SERIAL_INFO_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if ( uart_info_ptr == NULL ) {
        return(MQX_OUT_OF_MEMORY);
   }/* Endif */
#endif
   _mem_set_type(uart_info_ptr,MEM_TYPE_IO_SERIAL_INFO_STRUCT);    

   *io_info_ptr_ptr = uart_info_ptr;

   /* Save initialization values */
   uart_info_ptr->INIT = *io_init_ptr;

   channel = uart_info_ptr->INIT.DEVICE;
   _bsp_serial_io_init (channel);
   uart_ptr = _bsp_get_serial_base_address (channel);
   uart_info_ptr->UART_PTR = (pointer)uart_ptr;

   uart_ptr->WRITE.UCR = MCF53XX_UART_UCR_RESET_RX;
   uart_ptr->WRITE.UCR = MCF53XX_UART_UCR_RESET_TX;
   uart_ptr->WRITE.UCR = MCF53XX_UART_UCR_RESET_ERROR;
   uart_ptr->WRITE.UCR = MCF53XX_UART_UCR_RESET_BREAK;
   uart_ptr->WRITE.UCR = MCF53XX_UART_UCR_RESET_POINTER;

   uart_ptr->WRITE.UMR = uart_info_ptr->INIT.UMR1_VALUE;
   uart_ptr->WRITE.UMR = uart_info_ptr->INIT.UMR2_VALUE;

   uart_ptr->WRITE.UCSR = MCF53XX_UART_UCSR_RX_TIMER |
                          MCF53XX_UART_UCSR_TX_TIMER;

   uart_ptr->WRITE.UIMR = 0; /* Disable all interrupts */

   /* Set up the baud rate */
   /* baud = fsck / (32 * baudrate) + 0.5 */ 
   baud = (uart_info_ptr->INIT.CLOCK_SPEED + (16 * uart_info_ptr->INIT.BAUD_RATE) ) / (32 * uart_info_ptr->INIT.BAUD_RATE);   
   uart_ptr->WRITE.UBG1 = (uchar)((baud >> 8) & 0xFF);
   uart_ptr->WRITE.UBG2 = (uchar)(baud & 0xFF);

   uart_ptr->WRITE.UCR = MCF53XX_UART_UCR_TX_ENABLE |
                         MCF53XX_UART_UCR_RX_ENABLE;

   return( MQX_OK );

} /* Endbody */
示例#15
0
pointer calloc(unsigned int n, unsigned int z)
{
   return _mem_alloc_system_zero(n*z);
} 
示例#16
0
文件: comp.c 项目: nevinxu/HM502B2
/*!
 * \brief Override C/C++ runtime heap allocation function in IAR's DLIB
 *
 * \param n
 * \param z
 *
 * \return pointer
 */
void *calloc(_mem_size n, _mem_size z)
{
    return _mem_alloc_system_zero(n*z);
}
示例#17
0
_mqx_uint _io_serial_int_install
(
    /* [IN] A string that identifies the device for fopen */
    char             *identifier,

    /* [IN] The I/O init function */
    _mqx_uint (_CODE_PTR_ init)(void *, char *),

    /* [IN] The enable interrupts function */
    _mqx_uint (_CODE_PTR_ enable_ints)(void *),

    /* [IN] The I/O de-init function */
    _mqx_uint (_CODE_PTR_ deinit)(void *, void *),

    /* [IN] The output function */
    void    (_CODE_PTR_  putc)(void *, char),

    /* [IN] The I/O ioctl function */
    _mqx_uint (_CODE_PTR_ ioctl)(void *, _mqx_uint, void *),

    /* [IN] The I/O init data pointer */
    void                *init_data_ptr,

    /* [IN] The I/O queue size to use */
    _mqx_uint             queue_size
)
{   /* Body */
    IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr;
    uint32_t                         result;

    int_io_dev_ptr = _mem_alloc_system_zero(
                         (_mem_size)sizeof(IO_SERIAL_INT_DEVICE_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (int_io_dev_ptr == NULL) {
        return(MQX_OUT_OF_MEMORY);
    } /* Endif */
#endif
    _mem_set_type(int_io_dev_ptr,MEM_TYPE_IO_SERIAL_INT_DEVICE_STRUCT);

    int_io_dev_ptr->DEV_INIT          = init;
    int_io_dev_ptr->DEV_ENABLE_INTS   = enable_ints;
    int_io_dev_ptr->DEV_DEINIT        = deinit;
    int_io_dev_ptr->DEV_PUTC          = putc;
    int_io_dev_ptr->DEV_IOCTL         = ioctl;
    int_io_dev_ptr->DEV_INIT_DATA_PTR = init_data_ptr;
    int_io_dev_ptr->QUEUE_SIZE        = queue_size;

    result = _io_dev_install(identifier,
                             _io_serial_int_open, _io_serial_int_close,
                             _io_serial_int_read, _io_serial_int_write,
                             _io_serial_int_ioctl,
                             (void *)int_io_dev_ptr);

#if MQX_ENABLE_LOW_POWER
    if (MQX_OK == result)
    {
        LPM_REGISTRATION_STRUCT registration;
        registration.CLOCK_CONFIGURATION_CALLBACK = _io_serial_int_clock_configuration_callback;
        registration.OPERATION_MODE_CALLBACK = _io_serial_int_operation_mode_callback;
        registration.DEPENDENCY_LEVEL = BSP_LPM_DEPENDENCY_LEVEL_SERIAL_INT;
        result = _lpm_register_driver (&registration, int_io_dev_ptr, &(int_io_dev_ptr->LPM_INFO.REGISTRATION_HANDLE));
        if (MQX_OK == result)
        {
            _lwsem_create (&(int_io_dev_ptr->LPM_INFO.LOCK), 1);
            int_io_dev_ptr->LPM_INFO.FLAGS = 0;
        }
    }
#endif

    return result;
} /* Endbody */
示例#18
0
文件: ev_comp.c 项目: gxliu/MQX_3.8.0
_mqx_uint _event_create_component
   (
      /* [IN] the initial number of event */
      _mqx_uint initial_number, 

      /* 
      ** [IN] the number of events to add when
      ** space is no longer available
      */
      _mqx_uint grow_number,

      /* [IN] the maximum number of events allowed */
      _mqx_uint maximum_number 
   )
{ /* Body */
            KERNEL_DATA_STRUCT_PTR     kernel_data;
   register EVENT_COMPONENT_STRUCT_PTR event_component_ptr;
            _mqx_uint                   result;
            
   _GET_KERNEL_DATA(kernel_data);            

   _KLOGE4(KLOG_event_create_component, initial_number, grow_number, maximum_number);

#if MQX_CHECK_ERRORS
   if (kernel_data->IN_ISR) {
      _KLOGX2(KLOG_event_create_component, MQX_CANNOT_CALL_FUNCTION_FROM_ISR);
      return(MQX_CANNOT_CALL_FUNCTION_FROM_ISR);
   } /* Endif */
#endif

   _lwsem_wait((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));

   event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR)
      kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS];
   if (event_component_ptr != NULL) {
      _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
      _KLOGX2(KLOG_event_create_component, MQX_OK);
      return(MQX_OK);
   } /* Endif */
   
   event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR)
      _mem_alloc_system_zero((_mem_size)sizeof(EVENT_COMPONENT_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (event_component_ptr == NULL) {
      _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
      _KLOGX2(KLOG_event_create_component, MQX_OUT_OF_MEMORY);
      return(MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif
   _mem_set_type(event_component_ptr, MEM_TYPE_EVENT_COMPONENT);

   result = _name_create_handle_internal(&event_component_ptr->NAME_TABLE_HANDLE,
      initial_number, grow_number, maximum_number, initial_number);
#if MQX_CHECK_ERRORS
   if (result != MQX_OK) {
      _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
      _mem_free(event_component_ptr);
      _KLOGX2(KLOG_event_create_component, result);
      return(result);
   } /* Endif */
#endif
   event_component_ptr->VALID             = EVENT_VALID;
   event_component_ptr->GROW_NUMBER       = grow_number;
   if (maximum_number == 0) {
      event_component_ptr->MAXIMUM_NUMBER = MAX_MQX_UINT;
   } else if (maximum_number < initial_number) {
      event_component_ptr->MAXIMUM_NUMBER = initial_number;
   } else {
      event_component_ptr->MAXIMUM_NUMBER = maximum_number;
   } /* Endif */

   kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS] = event_component_ptr;

#if MQX_TASK_DESTRUCTION
   kernel_data->COMPONENT_CLEANUP[KERNEL_EVENTS] = _event_cleanup;
#endif

   _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
   
   _KLOGX2(KLOG_event_create_component, MQX_OK);
   return(MQX_OK);

} /* Endbody */
示例#19
0
_mqx_int gpio_cpu_open
   (
      /* [IN] the file handle for the device */
      MQX_FILE_PTR fd_ptr,

      /* [IN] the file name */
      char_ptr   file_name,

      /* [IN] pointer to parameters */
      char_ptr   param_ptr
   )
{ /* Body */
    _mqx_int          i;
    GPIO_DEV_DATA_PTR dev_data_ptr = (GPIO_DEV_DATA_PTR) fd_ptr->DEV_DATA_PTR;
 
    /* if file_name is used, then the user wants to open peripheral */
    if ((file_name != NULL) && (*file_name != 0)) {
        if (!strncmp(file_name, "gpio:write", 11))  /* user wants write access to GPIO */
            dev_data_ptr->type = DEV_OUTPUT;
        else if (!strncmp(file_name, "gpio:output", 12))  /* user wants write access to GPIO */
            dev_data_ptr->type = DEV_OUTPUT;
        else if (!strncmp(file_name, "gpio:read", 10)) /* user wants read access to GPIO */
            dev_data_ptr->type = DEV_INPUT;
        else if (!strncmp(file_name, "gpio:input", 11)) /* user wants read access to GPIO */
            dev_data_ptr->type = DEV_INPUT;
        else
        /* peripherals not used yet */
            return IO_ERROR;
    }
    else
        return IO_ERROR;
 
    if ((param_ptr != NULL) && (dev_data_ptr->type == DEV_OUTPUT)) { /* set pins status before selecting GPIO function */
        /* note that this is similar to GPIO_IOCTL_WRITE function, but no checking is performed
           (was done in io_gpio_open function) */
        uint_32 _PTR_  pin_table;
        uint_32        addr;
        uint_8         pin;
        GPIO_PIN_MAP_PTR    temp_pin0_map_ptr;
        GPIO_PIN_MAP_PTR    temp_pin1_map_ptr;

        if (NULL == (temp_pin0_map_ptr = (GPIO_PIN_MAP_PTR) _mem_alloc_system_zero(sizeof(GPIO_PIN_MAP))))
            return IO_ERROR;

        if (NULL == (temp_pin1_map_ptr = (GPIO_PIN_MAP_PTR) _mem_alloc_system_zero(sizeof(GPIO_PIN_MAP)))) {
            _mem_free(temp_pin0_map_ptr);
            return IO_ERROR;
        }

        /* prepare pin map */
        for (pin_table = (uint_32 _PTR_) param_ptr; *pin_table != GPIO_LIST_END; pin_table++) {
            addr = (*pin_table & GPIO_PIN_ADDR) >> 3; /* prepare address of port */ 
            pin = 1 << (*pin_table & 0x07);  /* prepare bit mask */
            if (*pin_table & GPIO_PIN_STATUS)
                temp_pin1_map_ptr->memory8[addr] |= pin;
            else
                temp_pin0_map_ptr->memory8[addr] |= pin;
        }
        /* first, configure pin as output */
        gpio_cpu_configure(dev_data_ptr);

        /* ok, now we can apply new map */
        /* note: applying the map after collecting pins is due to have pins applied in one instruction */
        for (i = GPIO_PORT_A; i < GPIO_PORT_MAX; i++)
            mcf521cn_gpioX_ptr->PORT[i].PTxD = (mcf521cn_gpioX_ptr->PORT[i].PTxD | temp_pin1_map_ptr->reg.portt[i]) & ~temp_pin0_map_ptr->reg.portt[i];

        _mem_free(temp_pin1_map_ptr);
        _mem_free(temp_pin0_map_ptr);
    }
示例#20
0
/*FUNCTION****************************************************************
*
* Function Name    : _io_spi_install
* Returned Value   : MQX error code
* Comments         :
*    Installs SPI device.
*
*END**********************************************************************/
_mqx_int _io_spi_install
    (
        /* [IN] A string that identifies the device for fopen */
        char                       *identifier,

        /* [IN] Pointer to driver initialization data */
        SPI_INIT_STRUCT_CPTR           init_data_ptr
    )
{
    SPI_DRIVER_DATA_STRUCT_PTR driver_data;

    _mqx_int error_code = MQX_OK;

    if ((init_data_ptr->DEVIF->SETPARAM == NULL) || (init_data_ptr->DEVIF->TX_RX == NULL))
    {
        /* Missing mandatory low level driver function */
        return IO_ERROR_DEVICE_INVALID;
    }

    driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(SPI_DRIVER_DATA_STRUCT));
    if (driver_data == NULL)
    {
        return MQX_OUT_OF_MEMORY;
    }
    _mem_set_type(driver_data, MEM_TYPE_IO_SPI_POLLED_DEVICE_STRUCT);

    driver_data->CS_CALLBACK = init_data_ptr->CS_CALLBACK;
    driver_data->CS_USERDATA= init_data_ptr->CS_USERDATA;
    driver_data->PARAMS = init_data_ptr->PARAMS;
    driver_data->DEVIF = init_data_ptr->DEVIF;

    /* initialize low level driver */
    if (driver_data->DEVIF->INIT)
        error_code = driver_data->DEVIF->INIT(init_data_ptr->DEVIF_INIT, &(driver_data->DEVIF_DATA));

    if (error_code != MQX_OK)
    {
        _mem_free(driver_data);
        return error_code;
    }

    _lwsem_create(&driver_data->BUS_LOCK, 1);

    error_code = _io_dev_install_ext(identifier,
        _io_spi_open, _io_spi_close,
        _io_spi_read, _io_spi_write,
        _io_spi_ioctl,
        _io_spi_uninstall,
        (void *)driver_data);

    if (error_code)
    {
        /* deinitialize low level driver */
        if (driver_data->DEVIF->DEINIT)
            driver_data->DEVIF->DEINIT(driver_data->DEVIF_DATA);

        _lwsem_destroy(&driver_data->BUS_LOCK);
        _mem_free(driver_data);
        return error_code;
    }

    return MQX_OK;
}