Esempio n. 1
0
PCB_PTR PPP_pcballoc
   (
      uint_16 protocol,
            /* [IN] - PPP protocol */
      uint_32 size
            /* [IN] - max size of packet, excluding protocol */
   )
{ /* Body */
   PCB_FRAGMENT _PTR_ pcb_frag_ptr;
   PCB_PTR packet;

   packet = _mem_alloc_system(sizeof(PCB) + sizeof(PCB_FRAGMENT) + 2 + size);
   if (packet) {
      packet->FREE = (void (_CODE_PTR_)(PCB_PTR))_mem_free;
      /* Start SPR P122-0266-22 remove all warnings from RTCS code. */
      /*  packet->FRAG[0].LENGTH   = size + 2; */
      /*  packet->FRAG[0].FRAGMENT = (uchar_ptr)packet + sizeof(PCB) + sizeof(PCB_FRAGMENT); */
      /*  packet->FRAG[1].LENGTH   = 0; */
      /*  packet->FRAG[1].FRAGMENT = NULL; */
      /*  htons(packet->FRAG[0].FRAGMENT, protocol); */
      pcb_frag_ptr = packet->FRAG;
      pcb_frag_ptr->LENGTH   = size + 2;
      pcb_frag_ptr->FRAGMENT = (uchar_ptr)packet + sizeof(PCB) +
         sizeof(PCB_FRAGMENT);
      htons(pcb_frag_ptr->FRAGMENT, protocol);
      pcb_frag_ptr++;
      pcb_frag_ptr->LENGTH   = 0;
      pcb_frag_ptr->FRAGMENT = NULL;
      /* End SPR P122-0266-22 */
   } /* Endif */

   return packet;

} /* Endbody */
Esempio n. 2
0
/*
** ===================================================================
**     Method      :  WDog1_Init (component WatchDog_LDD)
**
**     Description :
**         Initializes the device. Allocates memory for the device data
**         structure, allocates interrupt vectors and sets interrupt
**         priority, sets pin routing, sets timing, etc. If the
**         property <"Enable in init. code"> is set to "yes" value then
**         the device is also enabled (see the description of the
**         <Enable> method). In this case the <Enable> method is not
**         necessary and needn't to be generated. This method can be
**         called only once. Before the second call of Init the <Deinit>
**         must be called first.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * UserDataPtr     - Pointer to the user or
**                           RTOS specific data. This pointer will be
**                           passed as an event or callback parameter.
**     Returns     :
**         ---             - Pointer to the dynamically allocated
**                           private structure or NULL if there was an
**                           error.
** ===================================================================
*/
LDD_TDeviceData* WDog1_Init(LDD_TUserData *UserDataPtr)
{
  /* Allocate device structure */
  WDog1_TDeviceData *DeviceDataPrv;

  /* {MQX RTOS Adapter} Driver memory allocation: RTOS function call is defined by MQX RTOS Adapter property */
  DeviceDataPrv = (WDog1_TDeviceData *)_mem_alloc_system((_mem_size)sizeof(WDog1_TDeviceData));
  #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (DeviceDataPrv == NULL) {
      return (NULL);
    }
  #endif
  DeviceDataPrv->UserDataPtr = UserDataPtr; /* Store the RTOS device structure */
  /* SIM_SCGC4: EWM=1 */
  SIM_SCGC4 |= (uint32_t)0x02UL;                       
  /* PORTE_PCR24: ISF=0,MUX=6 */
  PORTE_PCR24 = (uint32_t)((PORTE_PCR24 & (uint32_t)~0x01000100UL) | (uint32_t)0x0600UL);
  DeviceDataPrv->CtrlRegWritten = FALSE; /* Control register is not initialized yet. */
  DeviceDataPrv->CtrlRegValue = 0x01u; /* Content of control register */
  /* EWM_CMPL: COMPAREL=0x96 */
  EWM_CMPL = (uint8_t)0x96U;           /* Set window register */
  /* EWM_CMPH: COMPAREH=0xF8 */
  EWM_CMPH = (uint8_t)0xF8U;           /* Set period register */
  /* Registration of the device structure */
  PE_LDD_RegisterDeviceStructure(PE_LDD_COMPONENT_WDog1_ID,DeviceDataPrv);
  return ((LDD_TDeviceData *)DeviceDataPrv); /* Return pointer to the device data structure */
}
Esempio n. 3
0
PCB_PTR PPP_pcballoc
   (
      uint16_t protocol,
            /* [IN] - PPP protocol */
      uint32_t size
            /* [IN] - max size of packet, excluding protocol */
   )
{ /* Body */
   PCB_FRAGMENT      *pcb_frag_ptr;
   PCB_PTR packet;

   packet = _mem_alloc_system(sizeof(PCB) + sizeof(PCB_FRAGMENT) + 2 + size);
   if (packet)
   {
      packet->FREE = (void (_CODE_PTR_)(PCB_PTR))_mem_free;
      pcb_frag_ptr = packet->FRAG;
      pcb_frag_ptr->LENGTH   = size + 2;
      pcb_frag_ptr->FRAGMENT = (unsigned char *)packet + sizeof(PCB) + sizeof(PCB_FRAGMENT);
      mqx_htons(pcb_frag_ptr->FRAGMENT, protocol);
      pcb_frag_ptr++;
      pcb_frag_ptr->LENGTH   = 0;
      pcb_frag_ptr->FRAGMENT = NULL;
   } /* Endif */

   return packet;

} /* Endbody */
Esempio n. 4
0
void * OS_Mem_alloc_uncached(uint32_t size)
{
#if PSP_HAS_DATA_CACHE
    return _mem_alloc_system_uncached(size);
#else
    return _mem_alloc_system(size);
#endif
}
Esempio n. 5
0
void _PTR_ __rta_alloc
(
    size_t   size
)
{   /* Body */

    return _mem_alloc_system(size);

} /* Endbody */
Esempio n. 6
0
static _mqx_int _io_serial_mix_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;
   IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr;
   _mqx_uint                       result = MQX_OK;
   _mqx_uint                       ioctl_val;

   io_dev_ptr     = fd_ptr->DEV_PTR;
   int_io_dev_ptr = (void *)io_dev_ptr->DRIVER_INIT_PTR;
   
   if (int_io_dev_ptr->COUNT) {
      /* Device is already opened */
      int_io_dev_ptr->COUNT++;
      fd_ptr->FLAGS = int_io_dev_ptr->FLAGS;
      return(result);
   } /* Endif */

   int_io_dev_ptr->IN_WAITING_TASKS  = _taskq_create(MQX_TASK_QUEUE_FIFO);
   int_io_dev_ptr->OUT_WAITING_TASKS = _taskq_create(MQX_TASK_QUEUE_FIFO);

   int_io_dev_ptr->OUT_QUEUE = (void *)_mem_alloc_system(
      sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + int_io_dev_ptr->OQUEUE_SIZE);
   _mem_set_type(int_io_dev_ptr->OUT_QUEUE,MEM_TYPE_IO_SERIAL_OUT_QUEUE);      
   _CHARQ_INIT(int_io_dev_ptr->OUT_QUEUE, int_io_dev_ptr->OQUEUE_SIZE);



   int_io_dev_ptr->FLAGS = (_mqx_uint)flags;
   fd_ptr->FLAGS      = (_mqx_uint)flags;

   result = (*int_io_dev_ptr->DEV_INIT)(int_io_dev_ptr, open_name_ptr);
   
   if (result == MQX_OK) {
       result = (*int_io_dev_ptr->DEV_ENABLE_INTS)(int_io_dev_ptr->DEV_INFO_PTR);
   } /* Endif */
   
   if (result != MQX_OK) {
      _mem_free(int_io_dev_ptr->OUT_QUEUE);
      _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS);
      _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS);
   }
   int_io_dev_ptr->COUNT = 1;
   return(result);

} /* Endbody */
Esempio n. 7
0
pointer _taskq_create
   ( 
      /* [IN] the policy of this task queue (fifo or priority queueing) */
      _mqx_uint policy
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR kernel_data;
   TASK_QUEUE_STRUCT_PTR  task_queue_ptr;

   _GET_KERNEL_DATA(kernel_data);

   _KLOGE2(KLOG_taskq_create, policy);

#if MQX_CHECK_ERRORS
   if (! ((policy == MQX_TASK_QUEUE_FIFO) ||
          (policy == MQX_TASK_QUEUE_BY_PRIORITY)))
   {
      _task_set_error(MQX_INVALID_PARAMETER);
      _KLOGX2(KLOG_taskq_create, NULL);
      return (NULL);
   } /* Endif */
   if (kernel_data->IN_ISR) {
      _task_set_error(MQX_CANNOT_CALL_FUNCTION_FROM_ISR);
      _KLOGX2(KLOG_taskq_create, NULL);
      return(NULL);
   }/* Endif */
#endif

   task_queue_ptr = (TASK_QUEUE_STRUCT_PTR)_mem_alloc_system((_mem_size)
      sizeof(TASK_QUEUE_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (task_queue_ptr == NULL) {
      _KLOGX2(KLOG_taskq_create, NULL);
      return(NULL);
   } /* Endif */
#endif

   _mem_set_type(task_queue_ptr, MEM_TYPE_TASK_Q);

   task_queue_ptr->POLICY = policy;
   _QUEUE_INIT(&task_queue_ptr->TD_QUEUE, 0);
   task_queue_ptr->VALID  = TASK_QUEUE_VALID;
   _int_disable();
   if (kernel_data->KERNEL_TASK_QUEUES.NEXT == NULL) {
       /* Initialize the task queue */
      _QUEUE_INIT(&kernel_data->KERNEL_TASK_QUEUES,0);
   
   } /* Endif */
   _QUEUE_ENQUEUE(&kernel_data->KERNEL_TASK_QUEUES, task_queue_ptr);
   _int_enable();

   _KLOGX2(KLOG_taskq_create, task_queue_ptr);

   return(task_queue_ptr);
   
} /* Endbody */
Esempio n. 8
0
/*!
 * \brief
 *
 * \param size
 *
 * \return void *
 */
void *MFS_mem_alloc_system(_mem_size size)
{
    if (_MFS_pool_id)
    {
        return _mem_alloc_system_from(_MFS_pool_id, size);
    }
    else
    {
        return _mem_alloc_system(size);
    }
}
Esempio n. 9
0
char * strdup	( 
					const char *s
				)
{
  unsigned int len = strlen (s) + 1;
  
  char *result = (char*) _mem_alloc_system(len);
  if (result != NULL)
  {
	  _mem_copy((void*) s, result, len);
  }
  return result;
}
Esempio n. 10
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _allocate_sector_cache
* Returned Value   : True, False
* Comments         : Allocate the flash sector cache
* 
*END*----------------------------------------------------------------------*/
bool _allocate_sector_cache(MQX_FILE_PTR fd_ptr) 
{
    IO_FLASHX_FILE_STRUCT_PTR file_ptr = (IO_FLASHX_FILE_STRUCT_PTR) fd_ptr->DEV_DATA_PTR;

    /* test for sector cache enable */
    if (!(file_ptr->FLAGS & FLASHX_SECTOR_CACHE_ENABLED))
        return FALSE;
    
    if (file_ptr->CACHE_PTR == NULL) {
        file_ptr->CACHE_PTR  = _mem_alloc_system(file_ptr->MAX_SECT_SIZE);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
        /* test for memory allocation */
        if(file_ptr->CACHE_PTR == NULL)
            return FALSE;
#endif
        _mem_set_type(file_ptr->CACHE_PTR, MEM_TYPE_IO_FLASHX_SECTOR_CACHE);
    }
    return TRUE;
}
Esempio n. 11
0
uint_32 NAT_ALG_tftp
   (
      pointer ptr       /* [IN] pointer to NAT config struct */
   )
{ /* Body */
   NAT_CFG_STRUCT_PTR      nat_cfg_ptr = ptr;
   NAT_ALG_CFG_STRUCT_PTR  tftp_ptr;

   tftp_ptr = _mem_alloc_system(sizeof(NAT_ALG_CFG_STRUCT));
   
   if (tftp_ptr)  {
      tftp_ptr->NEXT = nat_cfg_ptr->ALG_INFO_PTR;
      nat_cfg_ptr->ALG_INFO_PTR = tftp_ptr;  
      tftp_ptr->ALG_TYPE = NAT_ALG_TFTP_TYPE;
      tftp_ptr->ALG_EXEC = NAT_ALG_tftp_apply;   
      return RTCS_OK;
   } /* Endif */
   
   return RTCSERR_OUT_OF_MEMORY;

} /* Endbody */
Esempio n. 12
0
/*!
 * \brief Override C/C++ runtime heap allocation function
 *
 * \param bytes
 *
 * \return pointer
 */
void *malloc(_mem_size bytes)
{
    return _mem_alloc_system(bytes);
}
Esempio n. 13
0
void _msgpool_add_internal
   (
      /* [IN] a pointer to the message pool */
      MSGPOOL_STRUCT_PTR  msgpool_ptr,

      /* [IN] the number of messages to attempt to add */
      uint_16 num_messages
   )
{ /* Body */
   INTERNAL_MESSAGE_STRUCT_PTR  first_imsg_ptr;
   INTERNAL_MESSAGE_STRUCT_PTR  imsg_ptr;
   MSGPOOL_BLOCK_STRUCT_PTR     msgpool_block_ptr;
   _mqx_int                      raw_message_size;
   _mqx_uint                     count;

   raw_message_size = sizeof(INTERNAL_MESSAGE_STRUCT) -
      sizeof(MESSAGE_HEADER_STRUCT) +  msgpool_ptr->MESSAGE_SIZE;
   _MEMORY_ALIGN_VAL_LARGER(raw_message_size);

   msgpool_block_ptr = (MSGPOOL_BLOCK_STRUCT_PTR)_mem_alloc_system((_mem_size)
      ((raw_message_size*num_messages) + sizeof(MSGPOOL_BLOCK_STRUCT) +
      PSP_MEMORY_ALIGNMENT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (msgpool_block_ptr == NULL) {
      return;
   } /* Endif */
#endif
  _mem_set_type(msgpool_block_ptr, MEM_TYPE_MESSAGE_POOL_BLOCKS);

   msgpool_block_ptr->NEXT_BLOCK_PTR   = NULL;
   msgpool_block_ptr->RAW_MESSAGE_SIZE = raw_message_size;
   msgpool_block_ptr->NUM_MESSAGES     = num_messages;

   first_imsg_ptr =(INTERNAL_MESSAGE_STRUCT_PTR)
      ((uchar _PTR_)msgpool_block_ptr +  sizeof(MSGPOOL_BLOCK_STRUCT));
   first_imsg_ptr = (INTERNAL_MESSAGE_STRUCT_PTR)
      _ALIGN_ADDR_TO_HIGHER_MEM(first_imsg_ptr);

   msgpool_block_ptr->FIRST_IMSG_PTR = first_imsg_ptr;

   imsg_ptr = first_imsg_ptr;
   count    = num_messages + 1;
   while (--count){
      imsg_ptr->NEXT           = NULL;   /* Free list pointer */
      imsg_ptr->VALID          = MSG_VALID;
      imsg_ptr->FREE           = TRUE;
      imsg_ptr->QUEUED         = FALSE;
      imsg_ptr->MSGPOOL_PTR    = msgpool_ptr;
      imsg_ptr->TD_PTR         = NULL;
      if (count > 1) {
         /* imsg is in the middle of the list */
         imsg_ptr->NEXT           = (INTERNAL_MESSAGE_STRUCT_PTR)
            ((uchar _PTR_)imsg_ptr + raw_message_size);
         imsg_ptr                 = imsg_ptr->NEXT;
      }/* Endif */
   } /* Endwhile */

   /* Now make the pool entries available */
   _int_disable();
   msgpool_block_ptr->NEXT_BLOCK_PTR = msgpool_ptr->MSGPOOL_BLOCK_PTR;
   msgpool_ptr->MSGPOOL_BLOCK_PTR    = msgpool_block_ptr;

   /* imsg_ptr here is the last message on the list */
   imsg_ptr->NEXT                    = msgpool_ptr->MSG_FREE_LIST_PTR;
   msgpool_ptr->MSG_FREE_LIST_PTR    = first_imsg_ptr;
   msgpool_ptr->SIZE += num_messages;
   msgpool_ptr->MAX  += num_messages;
   _int_enable();

} /* Endbody */
Esempio n. 14
0
pointer malloc(unsigned int bytes)
{
  return _mem_alloc_system(bytes);
}
Esempio n. 15
0
void * OS_Mem_alloc(uint32_t size)
{
    return _mem_alloc_system(size);
}
Esempio n. 16
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _io_flashx_open
* Returned Value   : _mqx_uint a task error code or MQX_OK
* Comments         : Opens and initializes flash driver.
*    Must be synchronized by app software with concurrent calls also with
*    close and uninstall function.
* 
*END*----------------------------------------------------------------------*/
_mqx_int _io_flashx_open
   (
      /* [IN] the file handle for the device being opened */
      MQX_FILE_PTR fd_ptr,
      
      /* [IN] the remaining portion of the name of the device */
      char_ptr   open_name_ptr,

      /* [IN] the flags to be used during operation: */
      char_ptr   flags
   )
{ /* Body */
    IO_FLASHX_STRUCT_PTR dev_ptr = (IO_FLASHX_STRUCT_PTR) fd_ptr->DEV_PTR->DRIVER_INIT_PTR;
    IO_FLASHX_FILE_STRUCT_PTR file_ptr;
    FLASHX_BLOCK_INFO_STRUCT_PTR b;
    char_ptr             file_name_ptr = fd_ptr->DEV_PTR->IDENTIFIER; /* use driver name temporarily */
    boolean              chip_initialized = TRUE;
    _mqx_uint            erase_array_size;
    _mqx_uint            skip_sectors;
    _mqx_uint            skip_size;
    _mem_size            sfa, efa; /* start file address, end file address */
    _mem_size            bsa, bea; /* block start address, block end address */
    _mem_size            size, sec_size; /* file size, maximum sector size */
    _mqx_int             f; /* file number */

    while (*file_name_ptr++ != 0)
        open_name_ptr++; /* move to the file name */
    file_name_ptr = open_name_ptr; /* throw out value of file_name_ptr and assign the correct file name */

    if (!dev_ptr->FILES) {
        /* First time of opening the device. */
        if (dev_ptr->INIT) {
            chip_initialized = (*dev_ptr->INIT)(dev_ptr);
        } /* Endif */
    } /* Endif */

#if MQX_CHECK_ERRORS
    if (!chip_initialized) {
        return IO_ERROR;
    } /* Endif */
#endif //MQX_CHECK_ERRORS

    /* Check if the file name is in the file list */
    if (dev_ptr->FILE_BLOCK) {
        for (f = 0; dev_ptr->FILE_BLOCK[f].FILENAME; f++) {
            if (strcmp(dev_ptr->FILE_BLOCK[f].FILENAME, file_name_ptr) == 0) {
                /* Found a block with correct filename, prepare file driver memory */
                break;
            }
        }
    }

    if (!dev_ptr->FILE_BLOCK || !dev_ptr->FILE_BLOCK[f].FILENAME) {
        /* File name not found in the list */
        if (*file_name_ptr == 0) {
            /* No filename, use the whole HW space (4GiB) */
            sfa = 0;
            efa = MAX_UINT_32;
            f = -1;
        }
        else {
            /* Specified file name not found in the list of files */
            return IO_ERROR;
        }
    }
    else {
        sfa = dev_ptr->FILE_BLOCK[f].START_ADDR;
        efa = dev_ptr->FILE_BLOCK[f].END_ADDR;
    }

    /* Go through all blocks in HW map and find the first one that matches start of file */
    for (b = dev_ptr->HW_BLOCK; b->NUM_SECTORS != 0; b++) {
        bsa = dev_ptr->BASE_ADDR + b->START_ADDR;
        bea = bsa + b->NUM_SECTORS * b->SECTOR_SIZE - 1;
        if (sfa <= bea)
             break; /* start address of the file preceed the block or is inside the block */
    }

    if ((b->NUM_SECTORS == 0) || (bsa > efa)) {
        return IO_ERROR; /* no intersection */
    }

    if (sfa < bsa) {
        sfa = bsa;
    }
#if MQX_CHECK_ERRORS
    else if ((sfa - bsa) % b->SECTOR_SIZE) {
        return IO_ERROR; /* start address of file is not sector aligned */
    }
#endif //MQX_CHECK_ERRORS

    skip_size = sfa - (dev_ptr->BASE_ADDR + b->START_ADDR);
    skip_sectors = skip_size / b->SECTOR_SIZE;

    /* Get the size of the file */
    size = 0;
    erase_array_size = 0;
    sec_size = 0;
    for ( ; b->NUM_SECTORS != 0; b++) {
        _mqx_uint block_size = b->NUM_SECTORS * b->SECTOR_SIZE;
        bsa = dev_ptr->BASE_ADDR + b->START_ADDR;
        bea = bsa + block_size - 1;

        /* Test if we have not overrun after the file area */
        if (bsa > efa) break;
        
        size += block_size;
        erase_array_size += b->NUM_SECTORS;
        /* Compute max. sector size for this file */
        if (sec_size < b->SECTOR_SIZE) {
            sec_size = b->SECTOR_SIZE;
        }

        /* Check if this is the last block in the file */
        if (bea >= efa) {
#if MQX_CHECK_ERRORS
            if ((efa + 1 - bsa) % b->SECTOR_SIZE) {
                return IO_ERROR; /* end address of file is not sector aligned */
            }
#endif //MQX_CHECK_ERRORS
            /* Remove the trailing space */
            size -= bea - efa;
            erase_array_size -= (bea - efa) / b->SECTOR_SIZE;
            break;
        }
    }
    /* Remove the heading space */
    size -= skip_size;
    erase_array_size -= skip_sectors;

    file_ptr = _mem_alloc_system(sizeof(IO_FLASHX_FILE_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (file_ptr == NULL) {
        return IO_ERROR;
    }
#endif //MQX_CHECK_MEMORY_ALLOCATION_ERRORS

    file_ptr->ERASE_ARRAY_MAX = erase_array_size; /* size in bytes, each bit represents one sector */
    file_ptr->ERASE_ARRAY = _mem_alloc_system(erase_array_size / 8); /* size in bytes, each bit represents one sector */

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (file_ptr->ERASE_ARRAY == NULL) {
        _mem_free(file_ptr);
        return IO_ERROR; /* end address of file is not sector aligned */
    }
#endif //MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    _mem_set_type(file_ptr->ERASE_ARRAY, MEM_TYPE_IO_FLASHX_SECTOR_MAP); 
    /* Assume that the opened file's area in flash was not erased */
    _mem_zero(file_ptr->ERASE_ARRAY, erase_array_size / 8);

    /* Store file block */
    if (f != -1)
        file_ptr->FILE_BLOCK = &dev_ptr->FILE_BLOCK[f];
    else
        file_ptr->FILE_BLOCK = NULL; /* the whole flash is used */

    /* Store the flags */
    file_ptr->FLAGS = 0;
    /* Set the cache for this file as not yet allocated */
    file_ptr->CACHE_PTR = 0;
    /* Invalidate cache, mark the data not dirty */
    file_ptr->DIRTY_DATA = 0;
    /* File size */
    fd_ptr->SIZE = size;
    /* Store max. sector size */
    file_ptr->MAX_SECT_SIZE = sec_size;
    /* Store file context structure */
    fd_ptr->DEV_DATA_PTR = (IO_FLASHX_STRUCT_PTR) file_ptr;

    return MQX_OK;

} /* Endbody */
Esempio n. 17
0
uint_32 MACNET_initialize
   (
      ENET_CONTEXT_STRUCT_PTR enet_ptr
   )
{ 
   MACNET_CONTEXT_STRUCT_PTR  macnet_context_ptr=NULL;
   ENET_MemMapPtr             macnet_ptr;
   VENET_BD_STRUCT_PTR        bd_ptr;
   uchar_ptr                  buf_ptr;
   MACNET_RX_PCB_PTR          pcb_ptr;
   uint_32                    i, rxsize, txsize, ssize, lsize, pcbsize,rx_pcb_size, large_packet_size, rcr;
   uint_32                    timeout, error = ENET_OK;
   boolean                    bOK;
#if ENETCFG_SUPPORT_PTP
   MACNET_PTP_PRIVATE_PTR     macnet_ptp_ptr = NULL;
#endif /* ENETCFG_SUPPORT_PTP */
   KERNEL_DATA_STRUCT_PTR     kernel_data;
   
   _GET_KERNEL_DATA(kernel_data);

   // Initialize the MACNET I/O Pins
   MACNET_io_init(enet_ptr->PARAM_PTR->ENET_IF->MAC_NUMBER);
   
   macnet_ptr = MACNET_get_base_address(enet_ptr->PARAM_PTR->ENET_IF->MAC_NUMBER);
   if (macnet_ptr == NULL) {
      return ENETERR_INVALID_DEVICE;
   }
   
   
   // currently limit number of TX BDs to 32, as a bitmask is used in the free function.
   if (enet_ptr->PARAM_PTR->NUM_TX_ENTRIES > 32) {
      return ENETERR_INVALID_INIT_PARAM;
   }
   
   /*
   ** This function can be called from any context, and it needs mutual
   ** exclusion with itself.
   */
   MACNET_int_disable();

   macnet_context_ptr = _mem_alloc_system_zero(sizeof(MACNET_CONTEXT_STRUCT));
   IF_ERROR_EXIT((NULL==macnet_context_ptr), ENETERR_ALLOC_MAC_CONTEXT);
   _mem_set_type((pointer)macnet_context_ptr, MEM_TYPE_IO_ENET_MAC_CONTEXT_STRUCT);
   
   enet_ptr->MAC_CONTEXT_PTR = (pointer) macnet_context_ptr;  

   macnet_context_ptr->MACNET_ADDRESS = macnet_ptr;
   macnet_context_ptr->PHY_PTR = MACNET_get_base_address(enet_ptr->PARAM_PTR->ENET_IF->PHY_NUMBER);

   /* Stop the chip */
   macnet_ptr->ECR = ENET_ECR_RESET_MASK;

   /* wait until the initialization cycle completes */
   timeout = 0;
   while ((macnet_ptr->ECR & ENET_ECR_RESET_MASK) && (timeout<MACNET_RESET_TIMEOUT)){
      _time_delay(1);
      timeout++;
   } 
   IF_ERROR_EXIT((macnet_ptr->ECR & ENET_ECR_RESET_MASK), ENETERR_INIT_FAILED);
   
   /* Disable all MACNET interrupts */
   macnet_ptr->EIMR = 0;

   /* clear any pending interrpts */
   macnet_ptr->EIR = ENET_EIR_ALL_PENDING;

   macnet_context_ptr->NumRxBDs = enet_ptr->PARAM_PTR->NUM_RX_ENTRIES;
   macnet_context_ptr->NumTxBDs = enet_ptr->PARAM_PTR->NUM_TX_ENTRIES;
     
   // Compute aligned buffer sizes 
   if (enet_ptr->PARAM_PTR->TX_BUFFER_SIZE) {
      macnet_context_ptr->AlignedTxBufferSize = MACNET_TX_ALIGN(enet_ptr->PARAM_PTR->TX_BUFFER_SIZE);
   } else {
      macnet_context_ptr->AlignedTxBufferSize = MACNET_TX_ALIGN(enet_ptr->MaxTxFrameSize);
   }

   if (enet_ptr->PARAM_PTR->RX_BUFFER_SIZE) {
      macnet_context_ptr->AlignedRxBufferSize = MACNET_RX_ALIGN(enet_ptr->PARAM_PTR->RX_BUFFER_SIZE);
   } else {
      macnet_context_ptr->AlignedRxBufferSize = MACNET_RX_ALIGN(enet_ptr->MaxRxFrameSize);
   }

   // Allocate the Transmit and Receive buffer descriptors
   // TODO remake to using alloc_align fn
#if BSPCFG_HAS_SRAM_POOL && BSPCFG_ENET_SRAM_BUF
   bd_ptr = (VENET_BD_STRUCT_PTR)_mem_alloc_system_zero_from(_BSP_sram_pool, (sizeof(ENET_BD_STRUCT)*(macnet_context_ptr->NumRxBDs+macnet_context_ptr->NumTxBDs))+MACNET_BD_ALIGNMENT);
#else
   bd_ptr = (VENET_BD_STRUCT_PTR) _mem_alloc_system_zero((sizeof(ENET_BD_STRUCT)*(macnet_context_ptr->NumRxBDs+macnet_context_ptr->NumTxBDs))+MACNET_BD_ALIGNMENT);
#endif

   IF_ERROR_EXIT((NULL == bd_ptr), ENETERR_ALLOC_BD);
   _mem_set_type((pointer)bd_ptr, MEM_TYPE_IO_BD_STRUCT);

   macnet_context_ptr->UNALIGNED_RING_PTR = (pointer) bd_ptr;
   macnet_context_ptr->MACNET_RX_RING_PTR = (VENET_BD_STRUCT_PTR) MACNET_BD_ALIGN((uint_32)bd_ptr);
   macnet_context_ptr->MACNET_TX_RING_PTR = &macnet_context_ptr->MACNET_RX_RING_PTR[macnet_context_ptr->NumRxBDs];

   /* Set wrap bit in last BD */
   macnet_context_ptr->MACNET_RX_RING_PTR[macnet_context_ptr->NumRxBDs - 1].CONTROL = HOST_TO_BE_SHORT_CONST(ENET_BD_ETHER_RX_WRAP);
   macnet_context_ptr->MACNET_TX_RING_PTR[macnet_context_ptr->NumTxBDs - 1].CONTROL = HOST_TO_BE_SHORT_CONST(ENET_BD_ETHER_TX_WRAP);

   macnet_context_ptr->AvailableTxBDs = macnet_context_ptr->NumTxBDs;

   // Allocate array to hold Transmit PCB pointers while they are queued for transmission
   macnet_context_ptr->TxPCBS_PTR = (PCB_PTR *) _mem_alloc_system_zero(sizeof(PCB_PTR)*macnet_context_ptr->NumTxBDs);
   IF_ERROR_EXIT((NULL==macnet_context_ptr->TxPCBS_PTR), ENETERR_ALLOC_PCB);
   _mem_set_type((pointer)macnet_context_ptr->TxPCBS_PTR, MEM_TYPE_IO_PCB_PTR);

   // Allocate the Receive PCBs
   rx_pcb_size = sizeof(MACNET_RX_PCB);
   pcbsize = enet_ptr->PARAM_PTR->NUM_RX_PCBS * rx_pcb_size;
   macnet_context_ptr->RX_PCB_BASE = (MACNET_RX_PCB_PTR) _mem_alloc_system_zero(pcbsize);
   IF_ERROR_EXIT((NULL==macnet_context_ptr->RX_PCB_BASE), ENETERR_ALLOC_PCB);
   _mem_set_type((pointer)macnet_context_ptr->RX_PCB_BASE, MEM_TYPE_IO_PCB_STRUCT);
       
   // Allocate the Transmit and Receive buffers
   txsize = (enet_ptr->PARAM_PTR->NUM_TX_BUFFERS * macnet_context_ptr->AlignedTxBufferSize) + MACNET_TX_BUFFER_ALIGNMENT;
   rxsize = (enet_ptr->PARAM_PTR->NUM_RX_BUFFERS  * macnet_context_ptr->AlignedRxBufferSize) +MACNET_RX_BUFFER_ALIGNMENT;
   ssize  = (enet_ptr->PARAM_PTR->NUM_SMALL_BUFFERS * MACNET_SMALL_PACKET_SIZE);
   large_packet_size = enet_ptr->PARAM_PTR->OPTIONS&ENET_OPTION_VLAN ? ENET_FRAMESIZE_VLAN : ENET_FRAMESIZE;
   lsize  = (enet_ptr->PARAM_PTR->NUM_LARGE_BUFFERS * large_packet_size);

#if BSPCFG_HAS_SRAM_POOL && BSPCFG_ENET_SRAM_BUF
   buf_ptr = _mem_alloc_system_from(_BSP_sram_pool, rxsize + txsize + ssize + lsize);
#else
   buf_ptr = _mem_alloc_system(rxsize + txsize + ssize + lsize);
#endif
   
   IF_ERROR_EXIT((NULL==buf_ptr), ENETERR_ALLOC_BUFFERS);
   _mem_set_type(buf_ptr, MEM_TYPE_IO_ENET_BUFFERS);

   macnet_context_ptr->UNALIGNED_BUFFERS = buf_ptr;

   // Align to TX buffer boundary
   buf_ptr = (uchar_ptr)MACNET_TX_ALIGN((uint_32)buf_ptr);
   
   // Queue packets on TX Buffer Q.
   macnet_context_ptr->TX_BUFFERS = NULL;
   for (i=0;i<enet_ptr->PARAM_PTR->NUM_TX_BUFFERS;i++) {
      ENET_Enqueue_Buffer((pointer *)&macnet_context_ptr->TX_BUFFERS, buf_ptr);
      buf_ptr += macnet_context_ptr->AlignedTxBufferSize;
   }
   
   // Align to RX buffer boundary
   buf_ptr = (uchar_ptr)MACNET_RX_ALIGN((uint_32)buf_ptr);
  
   // Queue packets on RX Buffer Q.
   macnet_context_ptr->RX_BUFFERS = NULL;
   for (i=0;i<enet_ptr->PARAM_PTR->NUM_RX_BUFFERS;i++) {
      ENET_Enqueue_Buffer((pointer *)&macnet_context_ptr->RX_BUFFERS, buf_ptr);
      buf_ptr += macnet_context_ptr->AlignedRxBufferSize;
   }

   // Queue small packets on small buffer Q.
   for (i=0;i<enet_ptr->PARAM_PTR->NUM_SMALL_BUFFERS;i++) {
      ENET_Enqueue_Buffer((pointer *)&macnet_context_ptr->SMALL_BUFFERS, buf_ptr);
      buf_ptr += MACNET_SMALL_PACKET_SIZE;
   }

   // Queue large packets on large buffer Q.
   for (i=0;i<enet_ptr->PARAM_PTR->NUM_LARGE_BUFFERS;i++) {
      ENET_Enqueue_Buffer((pointer *)&macnet_context_ptr->LARGE_BUFFERS, buf_ptr);
      buf_ptr += large_packet_size;
   }

   // Enqueue the RX PCBs onto the receive PCB queue 
   pcb_ptr = macnet_context_ptr->RX_PCB_BASE;
   for (i = 0; i < enet_ptr->PARAM_PTR->NUM_RX_PCBS; i++) {
      QADD(macnet_context_ptr->RxPCBHead, macnet_context_ptr->RxPCBTail, (PCB_PTR) pcb_ptr);
      pcb_ptr++;
   } 

   // Fill up the receive ring 
   MACNET_add_buffers_to_rx_ring(macnet_context_ptr);

   /* Program this station's Ethernet physical address */
   macnet_ptr->PALR = HOST_TO_BE_LONG(*(uint_32_ptr) &enet_ptr->ADDRESS[0]);
   macnet_ptr->PAUR = HOST_TO_BE_SHORT((*(uint_16_ptr)(&enet_ptr->ADDRESS[4]))) << 16;

   // Clear the individual hash table registers
   macnet_ptr->IAUR = 0;
   macnet_ptr->IALR = 0;

   // Clear the group hash table registers                                
   macnet_ptr->GAUR = 0;
   macnet_ptr->GALR = 0;  

   /* Program receive buffer size */
   macnet_ptr->MRBR = macnet_context_ptr->AlignedRxBufferSize;     

   // Configure start of Rx and Tx BD rings
   macnet_ptr->RDSR = (uint_32)(macnet_context_ptr->MACNET_RX_RING_PTR);
   macnet_ptr->TDSR = (uint_32)(macnet_context_ptr->MACNET_TX_RING_PTR);

   // Set Receive Frame size 
   // NOTE: Oddly, the Receive Control Register (RCR) afmacnetts the transmit side too.  The RCR is used to determine if the 
   //       transmitter is babbling, which means, if the RX buffer size < Tx Buffer size, we can get babling transmitter
   //       errors if we set RCR to the maximum Receive frame length.  We really have no choice but to set RCR to one
   //       of ENET_FRAMESIZE or ENET_FRAMESIZE_VLAN.
   //

   rcr = ENET_RCR_MII_MODE_MASK | (ENET_RCR_MAX_FL_MASK & (large_packet_size << ENET_RCR_MAX_FL_SHIFT));
   if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_RMII) {
      rcr |= ENET_RCR_RMII_MODE_MASK;
   } else if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_7WIRE) {
      rcr &= ~ENET_RCR_MII_MODE_MASK;
   }
   macnet_ptr->RCR =  rcr;
   

   if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_MAC_LOOPBACK) {
      macnet_ptr->RCR |= ENET_RCR_LOOP_MASK;
   }

   //  Set Full/Half duplex based on mode.
   if (enet_ptr->PARAM_PTR->MODE & ENET_HALF_DUPLEX) {
      macnet_ptr->TCR = 0; // half duplex
   } else {
      macnet_ptr->TCR = 4; // full duplex
   }
   
   // Enable MII_SPEED register 
   i = (MACNET_device[enet_ptr->PARAM_PTR->ENET_IF->MAC_NUMBER].BUS_CLOCK / enet_ptr->PARAM_PTR->ENET_IF->PHY_MII_SPEED + 1) & ~1;
   if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_NO_PREAMBLE) {
      i |= ENET_MSCR_DIS_PRE_MASK;
   }
   macnet_context_ptr->PHY_PTR->MSCR = i;

   // Zero counters
   macnet_ptr->MIBC |= ENET_MIBC_MIB_CLEAR_MASK;

   // Install the ISRs
   bOK = MACNET_install_isrs( enet_ptr, &MACNET_device[enet_ptr->PARAM_PTR->ENET_IF->MAC_NUMBER] );
   IF_ERROR_EXIT(!bOK, ENETERR_INSTALL_ISR);
          
   // Unmask transmit/receive interrupts 
   // NOTE: need to enable both RXF and RXB, but only TXB, as RXB does not get generated with RXF, 
   //       but TXB does get generated with TXF
   // However, on 52259, enabling RXB is resulting in an HBERR interrupt. RXB is not required, so leave it disabled.
   macnet_ptr->EIMR = ENET_EIR_TXB_MASK | ENET_EIR_RXF_MASK; 

   // Enable MACNET 
   macnet_ptr->ECR = (ENET_ECR_ETHEREN_MASK | ENET_ECR_EN1588_MASK);

   // Discover PHY address if PHY_DISCOVER option is set
   if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_PHY_DISCOVER) {
      bOK = (*enet_ptr->PARAM_PTR->ENET_IF->PHY_IF->DISCOVER)(enet_ptr);
      IF_ERROR_EXIT(!bOK, ENETERR_INIT_FAILED);
   } else {
      // Set Phy address from initialization parameter
      enet_ptr->PHY_ADDRESS = enet_ptr->PARAM_PTR->ENET_IF->PHY_ADDRESS;
   }
   
   // Enable STORE & FORWARD mode
   if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_STORE_AND_FORW) {
      macnet_ptr->TFWR |= ENET_TFWR_STRFWD_MASK;
      macnet_ptr->RSFL |= ENET_RSFL_RX_SECTION_FULL(0);
   }
   
   // Perform Phy initialization
   bOK = (*enet_ptr->PARAM_PTR->ENET_IF->PHY_IF->INIT)(enet_ptr);
   IF_ERROR_EXIT(!bOK, ENETERR_INIT_FAILED);


   // Signals the MACNET that empty buffers are available.
   // It is NECESSARY to do this AFTER enabling the MACNET.
   macnet_ptr->RDAR = ENET_RDAR_RDAR_MASK;

#if ENETCFG_SUPPORT_PTP
   macnet_ptp_ptr = _mem_alloc_system_zero(sizeof(MACNET_PTP_PRIVATE));
   IF_ERROR_EXIT((NULL==macnet_context_ptr), ENETERR_ALLOC_MAC_CONTEXT);


   macnet_ptp_ptr->MACNET_PTR = macnet_context_ptr->MACNET_ADDRESS;
   macnet_ptp_ptr->PTIMER_PRESENT = 1;

   bOK = _lwevent_create(&(macnet_ptp_ptr->LWEVENT_PTP), 0);
   IF_ERROR_EXIT(bOK, ENETERR_1588_LWEVENT);
   
   macnet_ptp_ptr->TXSTAMP = (MACNET_PTP_TIME){0,0};
   macnet_ptp_ptr->L2PCKS_PTR = NULL;
   
   macnet_context_ptr->PTP_PRIV = macnet_ptp_ptr;
   MACNET_ptp_init(enet_ptr);
   
   if (macnet_ptp_ptr->PTIMER_PRESENT) {
      /* Set Timer count */
      MACNET_ptp_start(macnet_ptp_ptr, (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_PTP_MASTER_CLK));
      if(enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_PTP_MASTER_CLK)
          MACNET_ptp_set_master_base_address(macnet_ptr);
      macnet_ptp_ptr->MACNET_PTR->ECR |= ENET_ECR_EN1588_MASK;

   }
   /* Enable timer-relative interrupts */
   macnet_ptp_ptr->MACNET_PTR->EIMR |= (ENET_EIR_TS_TIMER_MASK | ENET_EIR_TS_AVAIL_MASK);
#endif /* ENETCFG_SUPPORT_PTP */


   // control transfers to this point on any error, with error set to error code.
EXIT:
   if (ENET_OK!=error) {
      #if BSPCFG_ENET_RESTORE
         MACNET_uninstall_all_isrs(enet_ptr);
      #endif
      MACNET_free_context(macnet_context_ptr);
   }
   MACNET_int_enable();
   return error;
} 
Esempio n. 18
0
pointer malloc(_mem_size bytes) 
{
    return _mem_alloc_system(bytes);
}
Esempio n. 19
0
/*!
 * \brief Initializes and starts MQX on the processor.
 * 
 * The function does the following:
 * \li Initializes the default memory pool and memory components.
 * \li Initializes kernel data.
 * \li Performs BSP-specific initialization, which includes installing the 
 * periodic timer.
 * \li Performs PSP-specific initialization.
 * \li Creates the interrupt stack.
 * \li Creates the ready queues.
 * \li Starts MQX tasks.
 * \li Starts autostart application tasks.
 * 
 * \param[in] mqx_init Pointer to the MQX initialization structure for the 
 * processor.
 * 
 * \return Does not return (Success.)
 * \return If application called _mqx_exit(), error code that it passed to 
 * _mqx_exit() (Success.)
 * \return Errors from _int_install_isr() (MQX cannot install the interrupt 
 *  subsystem.)
 * \return Errors from _io_init() (MQX cannot install the I/O subsystem.)
 * \return Errors from _mem_alloc_system() (There is not enough memory to 
 * allocate either the interrupt stack or the interrupt table.)
 * \return Errors from _mem_alloc_zero() (There is not enough memory to allocate 
 * the ready queues.)
 * \return MQX_KERNEL_MEMORY_TOO_SMALL (Init_struct_ptr does not specify enough 
 * kernel memory.)
 * \return MQX_OUT_OF_MEMORY (There is not enough memory to allocate either the 
 * ready queues, the interrupt stack, or the interrupt table.)
 * \return MQX_TIMER_ISR_INSTALL_FAIL (MQX cannot install the periodic timer ISR.)
 * 
 * \warning Must be called exactly once per processor.
 * 
 * \see _mqx_exit
 * \see _int_install_isr
 * \see _mem_alloc() 
 * \see _mem_alloc_from()
 * \see _mem_alloc_system()
 * \see _mem_alloc_system_from()
 * \see _mem_alloc_system_zero()
 * \see _mem_alloc_system_zero_from()
 * \see _mem_alloc_zero()
 * \see _mem_alloc_zero_from()
 * \see _mem_alloc_align()
 * \see _mem_alloc_align_from()
 * \see _mem_alloc_at()
 * \see MQX_INITIALIZATION_STRUCT
 * \see TASK_TEMPLATE_STRUCT        
 */ 
_mqx_uint _mqx
(
    register MQX_INITIALIZATION_STRUCT_PTR mqx_init
)
{ /* Body */
    KERNEL_DATA_STRUCT_PTR kernel_data;
    TASK_TEMPLATE_STRUCT_PTR template_ptr;
    TD_STRUCT_PTR td_ptr;
    _mqx_uint result;
    pointer stack_ptr;
    pointer sys_td_stack_ptr;
    uchar_ptr sys_stack_base_ptr;

#if MQX_EXIT_ENABLED || MQX_CRIPPLED_EVALUATION
    /* Setup a longjmp buffer using setjmp, so that if an error occurs
     * in mqx initialization, we can perform a longjmp to this location.
     *
     * Also _mqx_exit will use this jumpbuffer to longjmp to here in order
     * to cleanly exit MQX.
     */
    if ( MQX_SETJMP( _mqx_exit_jump_buffer_internal ) ) {
        _GET_KERNEL_DATA(kernel_data);
        _int_set_vector_table(kernel_data->USERS_VBR);
        return kernel_data->USERS_ERROR;
    } /* Endif */
#endif

    /*
     * The kernel data structure starts at the start of kernel memory,
     * as specified in the initialization structure. Make sure address
     * specified is aligned
     */
    kernel_data = (KERNEL_DATA_STRUCT_PTR) _ALIGN_ADDR_TO_HIGHER_MEM(mqx_init->START_OF_KERNEL_MEMORY);

    /* Set the global pointer to the kernel data structure */
    _SET_KERNEL_DATA(kernel_data);

    /* The following assignments are done to force the linker to include
     * the symbols, which are required by TAD.
     * Note that we should use address of the variable so it is not optimized
     * as direct constant assignment when optimization level is high.
     * Note that counter will be immediately reset to zero on the subsequent
     * _mem_zero call. */
    *(volatile pointer*) kernel_data = (pointer) & _mqx_version_number;
    *(volatile pointer*) kernel_data = (pointer) & _mqx_vendor;

    /* Initialize the kernel data to zero. */
    _mem_zero((pointer) kernel_data, (_mem_size) sizeof(KERNEL_DATA_STRUCT));

#if MQX_CHECK_ERRORS && MQX_VERIFY_KERNEL_DATA
    /* Verify that kernel data can be read and written correcly without
     * errors.  This is necessary during BSP development to validate the
     * DRAM controller is initialized properly.
     */

#ifndef PSP_KERNEL_DATA_VERIFY_ENABLE
#define PSP_KERNEL_DATA_VERIFY_ENABLE   0
#endif /* PSP_KERNEL_DATA_VERIFY_ENABLE */
    if (PSP_KERNEL_DATA_VERIFY_ENABLE) {
        /* This memory check is dangerous, because can destroy boot stack
         * stack which is used !!! -> MQX will failed !
         * Set PSP_KERNEL_DATA_VERIFY_ENABLE to 1
         * only if your boot stack is out of MQX memory heap
         */

        result = _mem_verify((uchar_ptr)kernel_data + sizeof(KERNEL_DATA_STRUCT),
                        mqx_init->END_OF_KERNEL_MEMORY);
        if ( result != MQX_OK ) {
            _mqx_exit(result); /* RETURN TO USER */
        }
    }
#endif /* MQX_CHECK_ERRORS && MQX_VERIFY_KERNEL_DATA */
    /* Copy the MQX initialization structure into kernel data. */
    kernel_data->INIT = *mqx_init;
    kernel_data->INIT.START_OF_KERNEL_MEMORY = (pointer) kernel_data;
    kernel_data->INIT.END_OF_KERNEL_MEMORY = (pointer) _ALIGN_ADDR_TO_LOWER_MEM(kernel_data->INIT.END_OF_KERNEL_MEMORY);

    /* init kernel data structures */
    _mqx_init_kernel_data_internal();

    /* Initialize the memory resource manager for the kernel */
    result = _mem_init_internal();
#if MQX_CHECK_ERRORS
    if ( result != MQX_OK ) {
        _mqx_exit(result); /* RETURN TO USER */
    } /* Endif */
#endif

#if MQX_USE_INTERRUPTS

    /* Now obtain the interrupt stack */
    if (kernel_data->INIT.INTERRUPT_STACK_LOCATION) {
        stack_ptr = kernel_data->INIT.INTERRUPT_STACK_LOCATION;
        result = kernel_data->INIT.INTERRUPT_STACK_SIZE;
    }
    else {
        if ( kernel_data->INIT.INTERRUPT_STACK_SIZE < PSP_MINSTACKSIZE ) {
            kernel_data->INIT.INTERRUPT_STACK_SIZE = PSP_MINSTACKSIZE;
        } /* Endif */
#if PSP_STACK_ALIGNMENT
        result = kernel_data->INIT.INTERRUPT_STACK_SIZE + PSP_STACK_ALIGNMENT + 1;
#else
        result = kernel_data->INIT.INTERRUPT_STACK_SIZE;
#endif
        stack_ptr = _mem_alloc_system((_mem_size)result);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
        if (stack_ptr == NULL) {
            _mqx_exit(MQX_OUT_OF_MEMORY); /* RETURN TO USER */
        } /* Endif */
#endif
        _mem_set_type(stack_ptr, MEM_TYPE_INTERRUPT_STACK);
    } /* Endif */

#if MQX_MONITOR_STACK
    _task_fill_stack_internal((_mqx_uint_ptr)stack_ptr, result);
#endif

    kernel_data->INTERRUPT_STACK_PTR = _GET_STACK_BASE(stack_ptr, result);

#endif

    /*
     * Set the stack for the system TD, in case the idle task gets blocked
     * by an exception or if idle task is not used.
     */
    result = PSP_MINSTACKSIZE;
    sys_td_stack_ptr = _mem_alloc_system((_mem_size) result);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (sys_td_stack_ptr == NULL) {
        _mqx_exit(MQX_OUT_OF_MEMORY); /* RETURN TO USER */
    } /* Endif */
#endif
    _mem_set_type(sys_td_stack_ptr, MEM_TYPE_SYSTEM_STACK);

    sys_stack_base_ptr = (uchar_ptr) _GET_STACK_BASE(sys_td_stack_ptr, result);
    td_ptr = SYSTEM_TD_PTR(kernel_data);
    td_ptr->STACK_PTR = (pointer)(sys_stack_base_ptr - sizeof(PSP_STACK_START_STRUCT));
    td_ptr->STACK_BASE = sys_stack_base_ptr;
#if MQX_TD_HAS_STACK_LIMIT
    td_ptr->STACK_LIMIT = _GET_STACK_LIMIT(sys_td_stack_ptr, result);
#endif
    _mqx_system_stack = td_ptr->STACK_PTR;

    /* Build the MQX ready to run queues */
    result = _psp_init_readyqs();
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if ( result != MQX_OK ) {
        _mqx_exit(result); /* RETURN TO USER */
    } /* Endif */
#endif

#if MQX_USE_COMPONENTS

    /* Create a light wait semaphore for component creation */
    _lwsem_create((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM, 1);
#endif

    /* Create a light wait semaphore for task creation/destruction creation */
    _lwsem_create((LWSEM_STRUCT_PTR) & kernel_data->TASK_CREATE_LWSEM, 1);

    /* Call bsp to enable timers and other devices */
    result = _bsp_enable_card();
#if MQX_CHECK_ERRORS
    if ( result != MQX_OK ) {
        _mqx_exit(result); /* RETURN TO USER */
    } /* Endif */
#endif

#if MQX_HAS_TIME_SLICE
    /* Set the kernel default time slice value */
    PSP_ADD_TICKS_TO_TICK_STRUCT(&kernel_data->SCHED_TIME_SLICE,
                    MQX_DEFAULT_TIME_SLICE, &kernel_data->SCHED_TIME_SLICE);
#endif

    /* Create the idle task */
#if MQX_USE_IDLE_TASK
    td_ptr = _task_init_internal(
                    (TASK_TEMPLATE_STRUCT_PTR)&kernel_data->IDLE_TASK_TEMPLATE,
                    kernel_data->ACTIVE_PTR->TASK_ID, MQX_IDLE_TASK_PARAMETER, TRUE, NULL, 0);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (td_ptr == NULL) {
        _mqx_exit(MQX_OUT_OF_MEMORY);
    } /* Endif */
#endif
    _task_ready_internal(td_ptr);
#endif

    /* Check here for auto-create tasks, and create them here */
    template_ptr = kernel_data->INIT.TASK_TEMPLATE_LIST;
    while (template_ptr->TASK_TEMPLATE_INDEX) {
        if (template_ptr->TASK_ATTRIBUTES & MQX_AUTO_START_TASK) {
            td_ptr = _task_init_internal(template_ptr, kernel_data->ACTIVE_PTR->TASK_ID,
                            template_ptr->CREATION_PARAMETER, FALSE, NULL, 0);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
            if (td_ptr == NULL) {
                _mqx_exit(MQX_OUT_OF_MEMORY);
            } /* Endif */
#endif
            _task_ready_internal(td_ptr);
        } /* Endif */
        ++template_ptr;
    } /* Endwhile */

    _sched_start_internal(); /* WILL NEVER RETURN FROM HERE */

    return MQX_OK; /* To satisfy lint */

} /* Endbody */
Esempio n. 20
0
/** server task - httpd main task which create new task for each new request
 */
static void httpd_server_task(pointer init_ptr, pointer creator) {
    HTTPD_STRUCT *server = (HTTPD_STRUCT*)init_ptr;
    int s;
    unsigned short len;
    struct sockaddr_in sin;
    HTTPD_SES_TASK_PARAM *param;
    _mqx_uint res;
    uint_32 stack;
 
    HTTPD_DEBUG(1, "server task start\n");
      
    res = _lwsem_create(&sem_session_counter, server->params->max_ses);

    if (!server && res != MQX_OK)
        goto ERROR;
        
    RTCS_task_resume_creator(creator, RTCS_OK);
    
    HTTPD_DEBUG(1, "server task run...\n");

    while (server->run) {
        // limit maximal opened sessions
        _lwsem_wait(&sem_session_counter);
        
        // allocate session task parameter structure
        param = _mem_alloc_system(sizeof(HTTPD_SES_TASK_PARAM));
        
        if (param) {
            param->server = server;
            param->sock = accept(server->sock, &sin, &len);
            
            if (0 < param->sock) {
                // accept return corect socket number - no error
                
                // try create task for session
                res = RTCS_task_create("httpd session", server->params->ses_prio, server->params->ses_stack, httpd_session_dynamic_task, param);
                
                if (MQX_OK != res) {
                    // session task creation failed, clean and wait...
                    shutdown(param->sock, FLAG_ABORT_CONNECTION);   // abort opened connection
                    _mem_free(param);
                    _lwsem_post(&sem_session_counter);
                    _time_delay(1);
                }
            }
            else {
                // accept return error, clean and wait, then try again...
                _mem_free(param);
                _lwsem_post(&sem_session_counter);
                _time_delay(1);
            }
        }
        else {
            // allocation failed ?!?!? wait some time
            _time_delay(100);
        }
    }
    
    HTTPD_DEBUG(1, "server task stop\n");
    
ERROR:
    RTCS_task_resume_creator(creator, (uint_32)RTCS_ERROR);
}
Esempio n. 21
0
_mqx_uint _io_mem_install
    (
        /* [IN] A string that identifies the device for fopen */
        char            *identifier,

        /* [IN] the address of the fdv_ram */
        void               *base_address, 

        /* [IN] the total size of the device */
        _file_size          size

    )
{
    IO_MEM_STRUCT_PTR handle_ptr;

#if (MAX_FILE_SIZE > MAX_MEM_SIZE)
   #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (size > MAX_MEM_SIZE) {
        return(MQX_OUT_OF_MEMORY);
    }
   #endif
#endif

    handle_ptr = (IO_MEM_STRUCT_PTR)
    _mem_alloc_system_zero((_mem_size)sizeof(IO_MEM_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (handle_ptr == NULL) {
        return(MQX_OUT_OF_MEMORY);
    }
#endif
    _mem_set_type(handle_ptr,MEM_TYPE_IO_MEM_STRUCT);            

    if (base_address == NULL) {
        base_address = _mem_alloc_system((_mem_size)size);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
        if (base_address == NULL) {
            _mem_free(handle_ptr);
            return(MQX_OUT_OF_MEMORY);
        }
#endif
        _mem_set_type(base_address,MEM_TYPE_IO_MEM_DATA);              

        /* Indicate the the RAM drive was allocated from kernel memory */
        handle_ptr->TYPE = MEM_TYPE_DYNAMIC;
    } else {
        /* Indicate the the RAM drive was statically allocated (global mem) */
        handle_ptr->TYPE = MEM_TYPE_STATIC;
    }

    handle_ptr->BASE_ADDR   = base_address;
    handle_ptr->SIZE        = size;

    _lwsem_create(&handle_ptr->LWSEM, 1);

    return (_io_dev_install(
        identifier,
        _io_mem_open,
        _io_mem_close,
        _io_mem_read,
        _io_mem_write,
        _io_mem_ioctl,
        (void *)handle_ptr
    ));
}
Esempio n. 22
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;
}
Esempio n. 23
0
/*!
 * \brief Creates a new log.
 * 
 * Each entry in the log contains application-specified data, a timestamp (in 
 * absolute time), and a sequence number.
 * 
 * \param[in] log_number Log number to create (0 through 15).
 * \param[in] max_size   Maximum size of the data to be stored in _mqx_uints 
 * (includes LOG_ENTRY_STRUCT headers).
 * \param[in] flags      One of the following:
 * \li LOG_OVERWRITE (When the log is full, write new entries over oldest ones.)
 * \li 0 (When the log is full, do not write entries.)
 * 
 * \return MQX_OK
 * \return LOG_INVALID (Log_number exceeds 15)
 * \return MQX_INVALID_COMPONENT_BASE (Component is not valid.)
 * \return MQX_OUT_OF_MEMORY (MQX is out of memory.)
 * \return LOG_EXISTS (Log log_number has already been created.)
 * 
 * \warning Creates the log component if it was not created.
 * 
 * \see _log_create_component
 * \see _log_destroy
 * \see _log_read
 * \see _log_write
 * \see LOG_ENTRY_STRUCT 
 */ 
_mqx_uint _log_create
(
    _mqx_uint log_number,
    _mqx_uint max_size,
    uint_32   flags
)
{ /* Body */
    KERNEL_DATA_STRUCT_PTR   kernel_data;
    LOG_COMPONENT_STRUCT_PTR log_component_ptr;
    LOG_HEADER_STRUCT_PTR    log_header_ptr;
    _mqx_uint                result;

    _GET_KERNEL_DATA(kernel_data);

#if MQX_CHECK_ERRORS
    if (log_number >= LOG_MAXIMUM_NUMBER)
    {
        return(LOG_INVALID);
    } /* Endif */
#endif

    log_component_ptr = (LOG_COMPONENT_STRUCT_PTR)
    kernel_data->KERNEL_COMPONENTS[KERNEL_LOG];
    if (log_component_ptr == NULL)
    {
        result = _log_create_component();
        log_component_ptr = (LOG_COMPONENT_STRUCT_PTR)
        kernel_data->KERNEL_COMPONENTS[KERNEL_LOG];
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
        if (log_component_ptr == NULL)
        {
            return(result);
        } /* Endif */
#endif
    } /* Endif */

#if MQX_CHECK_VALIDITY
    if (log_component_ptr->VALID != LOG_VALID)
    {
        return(MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif

    log_header_ptr = (LOG_HEADER_STRUCT_PTR)
    _mem_alloc_system((_mem_size)(sizeof(LOG_HEADER_STRUCT) + max_size *
                                    sizeof(_mqx_uint)));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (log_header_ptr == NULL)
    {
        return(MQX_OUT_OF_MEMORY);
    } /* Endif */
#endif
    _mem_set_type(log_header_ptr, MEM_TYPE_LOG);

    log_header_ptr->FLAGS = flags;
    log_header_ptr->FLAGS |= LOG_ENABLED;
    log_header_ptr->NUMBER = 1;
    log_header_ptr->MAX = max_size;
    log_header_ptr->SIZE = 0;
    log_header_ptr->LOG_WRITE = &log_header_ptr->DATA[0];
    log_header_ptr->LOG_READ = log_header_ptr->LOG_WRITE;
    log_header_ptr->LAST_LOG = log_header_ptr->LOG_WRITE;
    log_header_ptr->LOG_START = log_header_ptr->LOG_WRITE;
    log_header_ptr->LOG_END = &log_header_ptr->DATA[max_size];
    log_header_ptr->LOG_NEXT = NULL;

    _int_disable();
#if MQX_CHECK_ERRORS
    if (log_component_ptr->LOGS[log_number] != NULL)
    {
        _int_enable();
        _mem_free(log_header_ptr);
        return(LOG_EXISTS);
    } /* Endif */
#endif
    log_component_ptr->LOGS[log_number] = log_header_ptr;
    _int_enable();

    return(MQX_OK);

} /* Endbody */
Esempio n. 24
0
/*
** ===================================================================
**     Method      :  DA1_Init (component DAC_LDD)
**
**     Description :
**         Initializes the device according to design-time
**         configuration properties. Allocates memory for the device
**         data structure. 
**         If the <Enable in init. code> is set to "yes" then the
**         device is also enabled (see the description of the Enable
**         method).
**         This method can be called only once. Before the second call
**         of Init the Deinit method must be called first. If DMA
**         service is enabled this method also initializes inherited
**         DMA Transfer component.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * UserDataPtr     - Pointer to the user or
**                           RTOS specific data. This pointer will be
**                           passed as an events or callback parameter.
**     Returns     :
**         ---             - Device data structure pointer.
** ===================================================================
*/
LDD_TDeviceData* DA1_Init(LDD_TUserData *UserDataPtr)
{
  DA1_TDeviceData *DeviceDataPtr;

  /* Allocate HAL device structure */
  /* {MQX RTOS Adapter} Driver memory allocation: RTOS function call is defined by MQX RTOS Adapter property */
  DeviceDataPtr = (DA1_TDeviceData *)_mem_alloc_system((_mem_size)sizeof(DA1_TDeviceData));
  #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (DeviceDataPtr == NULL) {
      return (NULL);
    }
  #endif
  DeviceDataPtr->DmaTransferDeviceDataPtr = NULL; /* DMA is not used */
  DeviceDataPtr->UserDataPtr = UserDataPtr; /* Store the RTOS device structure */
  /* Enable device clock gate */
  /* SIM_SCGC2: DAC0=1 */
  SIM_SCGC2 |= (uint32_t)0x1000UL;                       
  DAC_PDD_EnableDevice(DAC0_BASE_PTR,PDD_DISABLE); /* Disable device */
  /* Interrupt vector(s) allocation */
  /* {MQX RTOS Adapter} Save old and set new interrupt vector (function handler and ISR parameter) */
  /* Note: Exception handler for interrupt is not saved, because it is not modified */
  DeviceDataPtr->SavedISRSettings_BufferInterrupt.isrData = _int_get_isr_data(LDD_ivIndex_INT_DAC0);
  DeviceDataPtr->SavedISRSettings_BufferInterrupt.isrFunction = _int_install_isr(LDD_ivIndex_INT_DAC0, DA1_BufferInterrupt, DeviceDataPtr);
  /* Interrupt vector(s) priority setting */
  /* NVICIP81: PRI81=0x90 */
  NVICIP81 = (uint8_t)0x90U;                             
  /* NVICISER2: SETENA|=0x00020000 */
  NVICISER2 |= (uint32_t)0x00020000UL;                       
  /* DAC0_DAT0H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT0H = (uint8_t)0x00U;                             
  /* DAC0_DAT0L: DATA=0 */
  DAC0_DAT0L = (uint8_t)0x00U;                             
  /* DAC0_DAT1H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT1H = (uint8_t)0x00U;                             
  /* DAC0_DAT1L: DATA=0 */
  DAC0_DAT1L = (uint8_t)0x00U;                             
  /* DAC0_DAT2H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT2H = (uint8_t)0x00U;                             
  /* DAC0_DAT2L: DATA=0 */
  DAC0_DAT2L = (uint8_t)0x00U;                             
  /* DAC0_DAT3H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT3H = (uint8_t)0x00U;                             
  /* DAC0_DAT3L: DATA=0 */
  DAC0_DAT3L = (uint8_t)0x00U;                             
  /* DAC0_DAT4H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT4H = (uint8_t)0x00U;                             
  /* DAC0_DAT4L: DATA=0 */
  DAC0_DAT4L = (uint8_t)0x00U;                             
  /* DAC0_DAT5H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT5H = (uint8_t)0x00U;                             
  /* DAC0_DAT5L: DATA=0 */
  DAC0_DAT5L = (uint8_t)0x00U;                             
  /* DAC0_DAT6H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT6H = (uint8_t)0x00U;                             
  /* DAC0_DAT6L: DATA=0 */
  DAC0_DAT6L = (uint8_t)0x00U;                             
  /* DAC0_DAT7H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT7H = (uint8_t)0x00U;                             
  /* DAC0_DAT7L: DATA=0 */
  DAC0_DAT7L = (uint8_t)0x00U;                             
  /* DAC0_DAT8H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT8H = (uint8_t)0x00U;                             
  /* DAC0_DAT8L: DATA=0 */
  DAC0_DAT8L = (uint8_t)0x00U;                             
  /* DAC0_DAT9H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT9H = (uint8_t)0x00U;                             
  /* DAC0_DAT9L: DATA=0 */
  DAC0_DAT9L = (uint8_t)0x00U;                             
  /* DAC0_DAT10H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT10H = (uint8_t)0x00U;                             
  /* DAC0_DAT10L: DATA=0 */
  DAC0_DAT10L = (uint8_t)0x00U;                             
  /* DAC0_DAT11H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT11H = (uint8_t)0x00U;                             
  /* DAC0_DAT11L: DATA=0 */
  DAC0_DAT11L = (uint8_t)0x00U;                             
  /* DAC0_DAT12H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT12H = (uint8_t)0x00U;                             
  /* DAC0_DAT12L: DATA=0 */
  DAC0_DAT12L = (uint8_t)0x00U;                             
  /* DAC0_DAT13H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT13H = (uint8_t)0x00U;                             
  /* DAC0_DAT13L: DATA=0 */
  DAC0_DAT13L = (uint8_t)0x00U;                             
  /* DAC0_DAT14H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT14H = (uint8_t)0x00U;                             
  /* DAC0_DAT14L: DATA=0 */
  DAC0_DAT14L = (uint8_t)0x00U;                             
  /* DAC0_DAT15H: ??=0,??=0,??=0,??=0,DATA=0 */
  DAC0_DAT15H = (uint8_t)0x00U;                             
  /* DAC0_DAT15L: DATA=0 */
  DAC0_DAT15L = (uint8_t)0x00U;                             
  /* DAC0_C2: DACBFRP=0,DACBFUP=0x0F */
  DAC0_C2 = (uint8_t)0x0FU;                             
  /* DAC0_C1: DMAEN=0,??=0,??=0,DACBFWM=3,DACBFMD=0,DACBFEN=1 */
  DAC0_C1 = (uint8_t)0x19U;                             
  /* DAC0_C0: DACEN=0,DACRFS=1,DACTRGSEL=1,DACSWTRG=0,LPEN=0,DACBWIEN=1,DACBTIEN=1,DACBBIEN=0 */
  DAC0_C0 = (uint8_t)0x66U;                             
  /* DAC0_SR: ??=0,??=0,??=0,??=0,??=0,DACBFWMF=0,DACBFRPTF=0,DACBFRPBF=0 */
  DAC0_SR = (uint8_t)0x00U;                             
  DeviceDataPtr->EnMode = TRUE;        /* Set the flag "device enabled" in the actual speed CPU mode */
  DeviceDataPtr->EnUser = FALSE;       /* Set the flag "device disabled by user" */
  /* Registration of the device structure */
  PE_LDD_RegisterDeviceStructure(PE_LDD_COMPONENT_DA1_ID,DeviceDataPtr);
  return ((LDD_TDeviceData*)DeviceDataPtr); /* Return pointer to the data data structure */
}
Esempio n. 25
0
static RTCSPCB_PTR NAT_IPREASM_reasm_dgram
   (
      IP_DGRAM_PTR   dgram    /* [IN] the dgram descriptor */
   )
{ /* Body */
   RTCSPCB_PTR outpcb;
   PCB_PTR     bpcb;
   PCB_FRAGMENT _PTR_ pcb_frag_ptr;
   uchar_ptr   data;
   uint_32     iphlen  = (ntohc(dgram->IPH.VERSLEN) & 0xF) << 2;
   uint_32     ip_totlen = iphlen + dgram->TOTLEN;

   bpcb = _mem_alloc_system(sizeof(PCB) + sizeof(PCB_FRAGMENT) + ip_totlen);
   if (!bpcb) {
      return NULL;
   } /* Endif */

   data = (uchar_ptr)bpcb + sizeof(PCB) + sizeof(PCB_FRAGMENT);
   bpcb->FREE    = (void(_CODE_PTR_)(PCB_PTR))_mem_free;
   bpcb->PRIVATE = NULL;

   pcb_frag_ptr = bpcb->FRAG;
   pcb_frag_ptr->LENGTH   = ip_totlen;
   pcb_frag_ptr->FRAGMENT = data;
   pcb_frag_ptr++;
   pcb_frag_ptr->LENGTH   = 0;
   pcb_frag_ptr->FRAGMENT = NULL;
 
   /* Copy the IP header with options */
   htons(dgram->IPH.FRAGMENT, 0);
   _mem_copy(&dgram->IPH, data, iphlen);
   data += iphlen;

   /*
   ** At this point, we really should update the LENGTH
   ** and CHECKSUM fields in the new IP header, but we
   ** don't actually need to, because this datagram is
   ** going straight to IPLOCAL_service, which doesn't
   ** check these things.
   */

   /* Copy the stored data in the new packet */
   NAT_IPREASM_blk_read_all(dgram, data, dgram->TOTLEN);

   /* Put it in an RTCSPCB */
   outpcb = RTCSPCB_alloc_recv(bpcb);
   if (outpcb == NULL) {
      PCB_free(bpcb);
      return NULL;
   } /* Endif */
   RTCSLOG_PCB_ALLOC(bpcb);
   outpcb->IFSRC           = dgram->IFSRC;
   outpcb->TYPE            = dgram->TYPE;
   outpcb->LINK_OPTIONS.RX = dgram->LINKOPT;
   RTCSPCB_DATA_NETWORK(outpcb) = RTCSPCB_DATA(outpcb);
   RTCSPCB_SET_TRANS_PROTL(outpcb, dgram->PROTO);
   RTCSPCB_SET_TRANS_DELTA(outpcb, iphlen);

   /* Delete the local structure */
   NAT_IPREASM_del_dgram(dgram);

   return outpcb;

} /* Endbody */
Esempio n. 26
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             _PTR_ open_name_ptr,

      /* [IN] the flags to be used during operation:
      ** echo, translation, xon/xoff
      */
      char             _PTR_ 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;
   uint_32                       result = MQX_OK;

   /* Allocate a Pipe information structure */
   io_pipe_info_ptr = _mem_alloc_system_zero(
      (uint_32)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 = (pointer)_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 */
Esempio n. 27
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : c90_flash_init
* Returned Value   : TRUE if successful, FALSE otherwise
* Comments         :
*   Initialize flash specific information.
*
*END*----------------------------------------------------------------------*/
boolean c90_flash_init
(
    /* [IN] Flash info structure */
    IO_FLASHX_STRUCT_PTR flash_ptr
)
{
    C90_FLASH_INTERNAL_STRUCT_PTR dev_spec_ptr;
    VC90_REG_STRUCT_PTR reg_ptr;
    FLASHX_BLOCK_INFO_STRUCT_PTR block_info_ptr;

    pointer ram_code_ptr;
    int     ram_code_size;
    uint_32 aspace;

    reg_ptr = _bsp_get_c90_address(flash_ptr->BASE_ADDR);
    if (reg_ptr == NULL)
    {
        return FALSE;
    }

    /* allocate internal structure */
    dev_spec_ptr = _mem_alloc_system(sizeof (C90_FLASH_INTERNAL_STRUCT));
    if( dev_spec_ptr == NULL)
    {
        return FALSE;
    }
    flash_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr;

    dev_spec_ptr->reg_ptr = reg_ptr;

    /* allocate space to execute flashing from RAM, FIXME: this shall be in PSP */
    ram_code_size = (char_ptr)c90_flash_exec_end  - (char_ptr)c90_flash_exec;
    ram_code_ptr = _mem_alloc_system(ram_code_size);
    
    if (ram_code_ptr == NULL)
    {
        _mem_free(dev_spec_ptr);
        return FALSE; 
    }
    dev_spec_ptr->flash_exec = ram_code_ptr;

    /* copy code to RAM */
    _mem_copy ((char_ptr)c90_flash_exec, ram_code_ptr, ram_code_size);

    /* count how many sectors belong to each address space */
    dev_spec_ptr->aspace_sectors[C90_ASPACE_LAS] = 0;
    dev_spec_ptr->aspace_sectors[C90_ASPACE_MAS] = 0;
    dev_spec_ptr->aspace_sectors[C90_ASPACE_HAS] = 0;
    dev_spec_ptr->aspace_sectors[C90_ASPACE_SHADOW] = 0;

    block_info_ptr = flash_ptr->HW_BLOCK;
    
    while (block_info_ptr->NUM_SECTORS) {

        aspace = C90_ASPACE(block_info_ptr->SPECIAL_TAG);
        if (aspace >= 0 && aspace < C90_ASPACE_COUNT)
            dev_spec_ptr->aspace_sectors[aspace] += block_info_ptr->NUM_SECTORS;

        block_info_ptr++;
    }        

    return TRUE;    
}
Esempio n. 28
0
/*
** Function for sending email
** IN:
**      SMTP_PARAM_STRUCT_PTR params - Pointer to structure with all required params set up
**                                      (email envelope, email text etc).
**
** OUT:
**      char *err_string - Pointer to string in which error string should be saved (can be NULL -
**                            error string is thrown away in that case).
**
** Return value:
**      _mqx_int - Error code or RTCS_SMTP_OK.
*/
_mqx_int SMTP_send_email (SMTP_PARAM_STRUCT_PTR params, char *err_string, uint32_t err_string_size)
{
    char *response = NULL;
    char *command = NULL;
    char *location = NULL;
    uint32_t code = 0;
    uint32_t socket = 0;

    /* Check params and envelope content for NULL */
    if ((params == NULL) || (params->envelope.from == NULL) || (params->envelope.to == NULL))
    {
        return(SMTP_ERR_BAD_PARAM);
    }

    /* Allocate buffers */
    response = (char *) _mem_alloc_system(sizeof(char)*SMTP_RESPONSE_BUFFER_SIZE);
    if (response == NULL)
    {
        return(MQX_OUT_OF_MEMORY);
    }
    command = (char *) _mem_alloc_system(sizeof(char)*SMTP_COMMAND_BUFFER_SIZE);
    if (command == NULL)
    {
        SMTP_cleanup(socket, response, NULL);
        return(MQX_OUT_OF_MEMORY);
    }
    
    /* Connect to server */
    socket = SMTP_connect(&params->server);
    if (socket == 0)
    {
        SMTP_cleanup(socket, response, command, NULL);
        return(SMTP_ERR_CONN_FAILED);
    }
    
    /* Read greeting message */
    recv(socket, response, SMTP_RESPONSE_BUFFER_SIZE, 0);
    
    /* Get response code */
    code = SMTP_get_response_code(response);
    if (code > 299)
    {
        SET_ERR_STR(err_string, response, err_string_size);
        SMTP_cleanup(socket, response, command, NULL);
        return(SMTP_WRONG_RESPONSE);
    }
    
    /* Get server extensions */
    sprintf(command, "EHLO FreescaleTower");
    code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
    
    /* If server does not support EHLO, try HELO */
    if (code > 399)
    {
        sprintf(command, "HELO FreescaleTower");
        code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
        if (code != 399)
        {
            SET_ERR_STR(err_string, response, err_string_size);
            SMTP_cleanup(socket, response, command, NULL);
            return(SMTP_WRONG_RESPONSE);
        }
    }
    /* Try to determine if authentication is supported, authenticate if needed */

    location = strstr(response, "AUTH");
    if ((location != NULL) && strstr(location, "LOGIN") && (params->login != NULL))
    {
        char *b64_data = NULL;
        uint32_t b64_length = 0;

        /* Send AUTH command */
        sprintf(command, "AUTH LOGIN");
        code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
        if ((code > 399) || (code == 0))
        {
            SET_ERR_STR(err_string, response, err_string_size);
            SMTP_cleanup(socket, response, command, NULL);
            return(SMTP_WRONG_RESPONSE);
        }

        /* Send base64 encoded username */
        b64_length = (strlen(params->login) / 3) * 4 + ((strlen(params->login) % 3) ? (1) : (0)) + 1;
        b64_data = (char *) _mem_alloc_system(sizeof(char)*b64_length);
        if (b64_data == NULL)
        {
            SMTP_cleanup(socket, response, command, NULL);
            return(MQX_OUT_OF_MEMORY);
        }
        sprintf(command, "%s", base64_encode(params->login, b64_data));
        _mem_free(b64_data);
        code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
        if ((code > 399) || (code == 0))
        {
            SET_ERR_STR(err_string, response, err_string_size);
            SMTP_cleanup(socket, response, command, NULL);
            return(SMTP_WRONG_RESPONSE);
        }

        /* Send base64 encoded password */
        b64_length = (strlen(params->login) / 3) * 4 + ((strlen(params->pass) % 3) ? (1) : (0)) + 1;
        b64_data = (char *) _mem_alloc_system(sizeof(char)*b64_length);
        if (b64_data == NULL)
        {
            SMTP_cleanup(socket, response, command, NULL);
            return(MQX_OUT_OF_MEMORY);
        }
        sprintf(command, "%s", base64_encode(params->pass, b64_data));
        _mem_free(b64_data);
        code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
        if ((code > 299) || (code == 0))
        {
            SET_ERR_STR(err_string, response, err_string_size);
            SMTP_cleanup(socket, response, command, NULL);
            return(SMTP_WRONG_RESPONSE);
        }
    }
    /* Send Email */
    sprintf(command, "MAIL FROM:<%s>", params->envelope.from);
    code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
    if ((code > 299) || (code == 0))
    {
        SET_ERR_STR(err_string, response, err_string_size);
        SMTP_cleanup(socket, response, command, NULL);
        return(SMTP_WRONG_RESPONSE);
    }
    sprintf(command, "RCPT TO:<%s>", params->envelope.to);
    code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
    
    /* Mail receiver not OK nor server will forward */
    if ((code > 299) || (code == 0))
    {
        SET_ERR_STR(err_string, response, err_string_size);
        SMTP_cleanup(socket, response, command, NULL);
        return(SMTP_WRONG_RESPONSE);
    }
    
    /* Send message data */
    sprintf(command, "DATA");
    code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
    if ((code > 399) || (code == 0))
    {
        SET_ERR_STR(err_string, response, err_string_size);
        SMTP_cleanup(socket, response, command, NULL);
        return(SMTP_WRONG_RESPONSE);
    }
    /* Send email text */
    code = SMTP_send_string(socket, params->text);
    
    /* Send terminating sequence for DATA command */
    code = SMTP_send_command(socket, "\r\n.", response, SMTP_RESPONSE_BUFFER_SIZE);
    if ((code > 299) || (code == 0))
    {
        SET_ERR_STR(err_string, response, err_string_size);
        SMTP_cleanup(socket, response, command, NULL);
        return(SMTP_WRONG_RESPONSE);
    }
   
    /* Write response to user buffer */
    SET_ERR_STR(err_string, response, err_string_size);
    
    /* Disconnect from server */
    sprintf(command, "QUIT");
    code = SMTP_send_command(socket, command, response, SMTP_RESPONSE_BUFFER_SIZE);
    
    /* Cleanup */
    SMTP_cleanup(socket, response, command, NULL);
    return(SMTP_OK);
}
Esempio n. 29
0
_mqx_int _io_serial_int_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             _PTR_ open_name_ptr,

      /* [IN] the flags to be used during operation:
      ** echo, translation, xon/xoff
      */
      char             _PTR_ flags
   )
{ /* Body */
   IO_DEVICE_STRUCT_PTR            io_dev_ptr;
   IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr;
   _mqx_uint                       result = MQX_OK;
   _mqx_uint                       ioctl_val;

   io_dev_ptr     = fd_ptr->DEV_PTR;
   int_io_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR;
   
   if (int_io_dev_ptr->COUNT) {
      /* Device is already opened */
      int_io_dev_ptr->COUNT++;
      fd_ptr->FLAGS = int_io_dev_ptr->FLAGS;
      return(result);
   } /* Endif */

   int_io_dev_ptr->IN_WAITING_TASKS  = _taskq_create(MQX_TASK_QUEUE_FIFO);
   int_io_dev_ptr->OUT_WAITING_TASKS = _taskq_create(MQX_TASK_QUEUE_FIFO);

   int_io_dev_ptr->IN_QUEUE = (pointer)_mem_alloc_system(
      sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + int_io_dev_ptr->QUEUE_SIZE);
   int_io_dev_ptr->OUT_QUEUE = (pointer)_mem_alloc_system(
      sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + int_io_dev_ptr->QUEUE_SIZE);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if ((int_io_dev_ptr->IN_QUEUE == NULL) || 
       (int_io_dev_ptr->OUT_QUEUE == NULL) ||
       (int_io_dev_ptr->IN_WAITING_TASKS == NULL) ||
       (int_io_dev_ptr->OUT_WAITING_TASKS == NULL))
   {
      if (int_io_dev_ptr->IN_QUEUE != NULL){
         _mem_free(int_io_dev_ptr->IN_QUEUE);
      } /* Endif */
      if (int_io_dev_ptr->OUT_QUEUE != NULL){
         _mem_free(int_io_dev_ptr->OUT_QUEUE);
      } /* Endif */
      if (int_io_dev_ptr->IN_WAITING_TASKS != NULL) {
         _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS);
      }/* Endif */
      if (int_io_dev_ptr->OUT_WAITING_TASKS != NULL) {
         _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS);
      }/* Endif */
      return(MQX_OUT_OF_MEMORY);
   }/* Endif */
#endif            
   _mem_set_type(int_io_dev_ptr->IN_QUEUE,MEM_TYPE_IO_SERIAL_IN_QUEUE);       
   _mem_set_type(int_io_dev_ptr->OUT_QUEUE,MEM_TYPE_IO_SERIAL_OUT_QUEUE);      

   _CHARQ_INIT(int_io_dev_ptr->IN_QUEUE, int_io_dev_ptr->QUEUE_SIZE);
   _CHARQ_INIT(int_io_dev_ptr->OUT_QUEUE, int_io_dev_ptr->QUEUE_SIZE);
   int_io_dev_ptr->INPUT_HIGH_WATER_MARK = int_io_dev_ptr->QUEUE_SIZE -
      int_io_dev_ptr->QUEUE_SIZE/8;
   int_io_dev_ptr->INPUT_LOW_WATER_MARK  = int_io_dev_ptr->QUEUE_SIZE/2;
   int_io_dev_ptr->FLAGS = (_mqx_uint)flags;
   fd_ptr->FLAGS      = (_mqx_uint)flags;

#if MQX_ENABLE_LOW_POWER          
   _lwsem_wait (&(int_io_dev_ptr->LPM_INFO.LOCK));
#endif
   result = (*int_io_dev_ptr->DEV_INIT)(int_io_dev_ptr, open_name_ptr);
#if MQX_ENABLE_LOW_POWER          
   _lwsem_post (&(int_io_dev_ptr->LPM_INFO.LOCK));
#endif
   
   if (result == MQX_OK) {
       
#if MQX_ENABLE_LOW_POWER          
      _lwsem_wait (&(int_io_dev_ptr->LPM_INFO.LOCK));
#endif
      result = (*int_io_dev_ptr->DEV_ENABLE_INTS)(int_io_dev_ptr->DEV_INFO_PTR);
#if MQX_ENABLE_LOW_POWER          
      _lwsem_post (&(int_io_dev_ptr->LPM_INFO.LOCK));
#endif
      
      if (int_io_dev_ptr->DEV_IOCTL != NULL) {
         if ((_mqx_uint)flags & IO_SERIAL_HW_FLOW_CONTROL) {
            ioctl_val = IO_SERIAL_RTS;
            (*int_io_dev_ptr->DEV_IOCTL)(int_io_dev_ptr->DEV_INFO_PTR, IO_IOCTL_SERIAL_SET_HW_SIGNAL, &ioctl_val);
         } /* Endif */
         ioctl_val = (_mqx_uint)flags;
         (*int_io_dev_ptr->DEV_IOCTL)(int_io_dev_ptr->DEV_INFO_PTR, IO_IOCTL_SERIAL_SET_FLAGS, &ioctl_val);
      }
      if (result == MQX_OK && ((_mqx_uint)flags & IO_SERIAL_NON_BLOCKING) 
         && (_mqx_uint)flags & (IO_SERIAL_TRANSLATION | IO_SERIAL_ECHO | IO_SERIAL_XON_XOFF)) {
         result = MQX_INVALID_PARAMETER;
      } /* Endif */
   } /* Endif */
   
   if (result != MQX_OK) {
      _mem_free(int_io_dev_ptr->IN_QUEUE);
      _mem_free(int_io_dev_ptr->OUT_QUEUE);
      _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS);
      _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS);
   }
   int_io_dev_ptr->COUNT = 1;
   return(result);

} /* Endbody */