Esempio n. 1
0
/*
** Function resolving requested file path in filesystem
**
** IN:
**       char *path - path to resolve.
**
**       char* root - root directory of requested file.
** OUT:
**      none
**
** Return Value: 
**      char* - full path in filesystem with correct slashes.
*/
char* httpsrv_get_full_path(char *path, char *root)
{
    char* buffer;
    char* tmp;

    /* Session buffer is too small */
    buffer = _mem_alloc_zero(strlen(path) + strlen(root) + 1);
    if (buffer == NULL)
    {
        return(NULL);
    }
    /* Create full path from root directory and path */
    _mem_copy(root, buffer, strlen(root)+1);
    strcat(buffer, path);

    tmp = buffer;
    /* Correct path slashes */
    while (*tmp)
    {
        if (*tmp == '/')
        {
            *tmp = '\\';
        }
        tmp++;
    }
    return(buffer);
}
Esempio n. 2
0
/*!
 * \brief This function sets up the FLOATING POINT context of a new task descriptor.
 * 
 * \param[in] td_ptr the address of the task descriptor
 */
bool _psp_build_float_context
   (
      /* [IN] the address of the task descriptor */
      TD_STRUCT_PTR    td_ptr
   )
{
    PSP_BLOCKED_FP_STRUCT_PTR fp_ptr;

    /* Allocate space for saving/restoring the DSP registers */
    fp_ptr = (PSP_BLOCKED_FP_STRUCT_PTR)_mem_alloc_zero((_mem_size)sizeof(PSP_BLOCKED_FP_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
    if (!fp_ptr) {
        /* Couldn't allocate memory for the DSP register context */
        _task_set_error_td_internal(td_ptr, MQX_OUT_OF_MEMORY);
        return FALSE;
    }
#endif

    _mem_set_type(fp_ptr, MEM_TYPE_FP_CONTEXT);
    /*
    ** Transfer the block to the task being created. This will ensure the
    ** float context will be freed if the task is destroyed.
    */
    _mem_transfer_internal((void *)fp_ptr, td_ptr);

    /* This field should never be overwitten */
    fp_ptr->TID = td_ptr->TASK_ID;

    td_ptr->FLOAT_CONTEXT_PTR = (void *)fp_ptr;

    return TRUE;
}
Esempio n. 3
0
void usb_host_mass_device_event
   (
      /* [IN] pointer to device instance */
      _usb_device_instance_handle      dev_handle,

      /* [IN] pointer to interface descriptor */
      _usb_interface_descriptor_handle intf_handle,

      /* [IN] code number for event causing callback */
      uint_32           event_code
   )
{
   DEVICE_STRUCT_PTR          device;
   usb_msg_t                  msg;

   switch (event_code) {
      case USB_CONFIG_EVENT:
         /* Drop through into attach, same processing */
      case USB_ATTACH_EVENT:
         /* Here, the device starts its lifetime */
         device = (DEVICE_STRUCT_PTR) _mem_alloc_zero(sizeof(DEVICE_STRUCT));
         if (device == NULL)
            break;

         if (USB_OK != _usb_hostdev_select_interface(dev_handle, intf_handle, &device->ccs))
            break;
         msg.ccs = &device->ccs;
         msg.body = USB_EVENT_ATTACH;
         if (LWMSGQ_FULL == _lwmsgq_send(usb_taskq, (uint_32 *) &msg, 0)) {
            printf("Could not inform USB task about device attached\n");
         }
         break;

      case USB_INTF_EVENT:
         if (USB_OK != usb_class_mass_get_app(dev_handle, intf_handle, (CLASS_CALL_STRUCT_PTR *) &device))
            break;
         msg.ccs = &device->ccs;
         msg.body = USB_EVENT_INTF;
         if (LWMSGQ_FULL == _lwmsgq_send(usb_taskq, (uint_32 *) &msg, 0)) {
            printf("Could not inform USB task about device interfaced\n");
         }
         break;

      case USB_DETACH_EVENT:
         if (USB_OK != usb_class_mass_get_app(dev_handle, intf_handle, (CLASS_CALL_STRUCT_PTR *) &device))
            break;
         msg.ccs = &device->ccs;
         msg.body = USB_EVENT_DETACH;
         if (LWMSGQ_FULL == _lwmsgq_send(usb_taskq, (uint_32 *) &msg, 0)) {
            printf("Could not inform USB task about device detached\n");
         }
         _mem_free(device);
         break;

      default:
         break;
   } 
} 
void watering_system_init(uint64_t start_delay, uint64_t time_between_watering, uint32_t watering_cycles, uint32_t pumping_time, uint64_t dry_time){
	pump_ptr p;
	
	p = (pump_ptr)_mem_alloc_zero(sizeof(pump));
	pump_init(p);
	ws_params.pump = p;
	
	watering_system_update(start_delay, time_between_watering, watering_cycles, pumping_time, dry_time);
}
Esempio n. 5
0
static void monitor_all_inputs(void)
{
    LWADC_STRUCT_PTR    lwadc_inputs;
    LWADC_VALUE_PTR     last;
    LWADC_VALUE         i,scaled, raw, delta, max_delta = 160;

    printf("Monitoring all inputs\n");

    lwadc_inputs = (LWADC_STRUCT_PTR) _mem_alloc_zero(ELEMENTS_OF(adc_inputs)*sizeof(LWADC_STRUCT));
    last         = (LWADC_VALUE_PTR)  _mem_alloc_zero(ELEMENTS_OF(adc_inputs)*sizeof(LWADC_VALUE));
    
    if ((lwadc_inputs == NULL) || (last==NULL)) {
        printf("Error, Insufficient memory to run full test\n.");
        _task_block();
    }
    
    for (i=0;i<ELEMENTS_OF(adc_inputs);i++) {
        /* Set last value to a value out of range of the ADC. */
        last[i] = MAX_UINT_32;
        if ( !_lwadc_init_input(&lwadc_inputs[i],adc_inputs[i].input) ) {
            /* Failed to initialize this input. We will end up failing the reads below as well. */
            printf("Failed to initialize ADC input %s\n",adc_inputs[i].name);
        }
    }
    
    printf("Monitoring ADC Inputs\n");
    while (1) {
        for (i=0;i<ELEMENTS_OF(adc_inputs);i++) {
            /* This waits until a new conversion is read on the channel */
            if (_lwadc_wait_next(&lwadc_inputs[i])) {
                if (_lwadc_read(&lwadc_inputs[i], &scaled) &&
                    _lwadc_read_raw(&lwadc_inputs[i], &raw)) {
                    
                    /* Obtained data, is the change significant enough to display? */
                    delta = (raw>last[i])?raw-last[i]:last[i]-raw;
                    if (delta > max_delta) {
                        printf("%-30s = %04x (%d mv)\n",adc_inputs[i].name, raw,scaled);
                        last[i]=raw;
                    }
                }
            }
        }
    }
}
Esempio n. 6
0
/*!
 * \brief This function sets up the kernel priority ready queues
 */
uint32_t _psp_init_readyqs
   (
      void
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR kernel_data;
   READY_Q_STRUCT_PTR     q_ptr;
   uint32_t                priority_levels;
   uint32_t                n;
   uint16_t                sr;

   _GET_KERNEL_DATA(kernel_data);
   kernel_data->READY_Q_LIST = (READY_Q_STRUCT_PTR) NULL;
   priority_levels = kernel_data->LOWEST_TASK_PRIORITY + 3; // IDLE TASK, INIT TASK

   q_ptr = (READY_Q_STRUCT_PTR)
      _mem_alloc_zero(sizeof(READY_Q_STRUCT) * priority_levels);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if ( q_ptr == NULL ) {
      return (MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif
   _mem_set_type(q_ptr, MEM_TYPE_READYQ);

   n = priority_levels;
   while (n--) {
      q_ptr->HEAD_READY_Q  = (TD_STRUCT_PTR)q_ptr;
      q_ptr->TAIL_READY_Q  = (TD_STRUCT_PTR)q_ptr;
      q_ptr->PRIORITY      = (uint16_t)n;
      q_ptr->NEXT_Q        = kernel_data->READY_Q_LIST;
      kernel_data->READY_Q_LIST = q_ptr++;
   } /* Endwhile */

   /* 
   ** Set the current ready q (where the ready queue searches start) to
   ** the head of the list of ready queues.
   */
   kernel_data->CURRENT_READY_Q = kernel_data->READY_Q_LIST;


   /* Initialize the ENABLE_SR fields in the ready queues */
   sr = (uint16_t)0x2000 | 
      (uint16_t)((kernel_data->INIT.MQX_HARDWARE_INTERRUPT_LEVEL_MAX - 1) << 8);
   n  = priority_levels;
   q_ptr =  kernel_data->READY_Q_LIST;
   while (n--) {
      q_ptr->ENABLE_SR = sr;
      if (  ((uint16_t) 0xF00 & sr) > 0  ) {
         sr = (uint16_t)sr - (uint16_t)0x100; 
      } /* Endif */
      q_ptr = q_ptr->NEXT_Q;
   } /* Endwhile */

   return MQX_OK;

} /* Endbody */
Esempio n. 7
0
/*!
 * \brief
 *
 * \param size
 *
 * \return void *
 */
void *MFS_mem_alloc_zero(_mem_size size)
{
    if (_MFS_pool_id)
    {
        return _mem_alloc_zero_from(_MFS_pool_id, size);
    }
    else
    {
        return _mem_alloc_zero(size);
    }
}
Esempio n. 8
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : allocate_buffer
* Returned Value   : 
* Comments         :
*    
*
*END*----------------------------------------------------------------------*/
uchar_ptr allocate_buffer(_mem_size buffer_size, char_ptr string) 
{
    uchar_ptr buffer_ptr;
    
    buffer_ptr = _mem_alloc_zero(buffer_size);
    
    if (buffer_ptr == NULL) {
        printf("\nFailed to get %s buffer", string);
    } 
    return buffer_ptr;          
}
Esempio n. 9
0
uint_32 _psp_init_readyqs
   (
      void
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR kernel_data;
   READY_Q_STRUCT_PTR     q_ptr;
   _mqx_uint              priority_levels;
   _mqx_uint              n;

   _GET_KERNEL_DATA(kernel_data);
   kernel_data->READY_Q_LIST = (READY_Q_STRUCT_PTR) NULL;
   priority_levels = kernel_data->LOWEST_TASK_PRIORITY + 2;

   q_ptr = (READY_Q_STRUCT_PTR)
      _mem_alloc_zero(sizeof(READY_Q_STRUCT) * priority_levels);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if ( q_ptr == NULL ) {
      return (MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif
   _mem_set_type(q_ptr, MEM_TYPE_READYQ);

   n = priority_levels;
   while (n--) {
      q_ptr->HEAD_READY_Q  = (TD_STRUCT_PTR)((pointer)q_ptr);
      q_ptr->TAIL_READY_Q  = (TD_STRUCT_PTR)((pointer)q_ptr);
      q_ptr->PRIORITY      = (uint_16)n;
      q_ptr->NEXT_Q        = kernel_data->READY_Q_LIST;
      kernel_data->READY_Q_LIST = q_ptr++;
   } /* Endwhile */

   /* 
   ** Set the current ready q (where the ready queue searches start) to
   ** the head of the list of ready queues.
   */
   kernel_data->CURRENT_READY_Q = kernel_data->READY_Q_LIST;

   /* Initialize the ENABLE_SR fields in the ready queues */
   q_ptr =  kernel_data->READY_Q_LIST;
   q_ptr->ENABLE_SR = 1;  /* Interrupts disabled for this level */

   return MQX_OK;

} /* Endbody */
Esempio n. 10
0
void main_task
    (
        uint32_t initial_data
    )
{
    MY_ISR_STRUCT_PTR  isr_ptr;

    uint32_t result;

    /* Create the lightweight semaphore */
    result = _lwsem_create(&lwsem, 0);
    if (result != MQX_OK) {
        printf("\nCreating sem failed: 0x%X", result);
        _task_block();
    }

    isr_ptr               =  _mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT));
    isr_ptr->TICK_COUNT   =  0;
    isr_ptr->OLD_ISR_DATA =  _int_get_isr_data(BSP_TIMER_INTERRUPT_VECTOR);
    isr_ptr->OLD_ISR      =  _int_get_isr(BSP_TIMER_INTERRUPT_VECTOR);

    /* Native MQX interrupt handling method, ISR is installed into the interrupt vector table in kernel */
    if(! _int_install_isr(BSP_TIMER_INTERRUPT_VECTOR, new_tick_isr, isr_ptr))
    {
        printf("Install interrupt handler to interrupt vector table of MQX kernel failed.\n");
        _task_block();
    }
#ifndef DEMO_ENABLE_KERNEL_ISR
    _time_delay_ticks(200);
    printf("\nTick count = %d\n", isr_ptr->TICK_COUNT);
    _task_block();
#else
    printf("\n====================== ISR Example =======================\n");
    printf("Press the SW1 to blink LED1, press it again to turn it off\n");
    while(1)
    {
      _lwsem_wait(&lwsem);
      num_tick = isr_ptr->TICK_COUNT;
    }
#endif /* DEMO_ENABLE_KERNEL_ISR */
}
Esempio n. 11
0
/*
** Process one line of http request header
**
** IN:
**      HTTPSRV_SESSION_STRUCT* session - session structure pointer.
**      HTTPSRV_STRUCT *server - pointer to server structure (needed for session parameters).
**      char* buffer - pointer to begining of line with request.
**
** OUT:
**      none
**
** Return Value:
**      none
*/
void httpsrv_process_req_hdr_line(HTTPSRV_STRUCT *server, HTTPSRV_SESSION_STRUCT* session, char* buffer)
{
    char* param_ptr = NULL;

    if (strncmp(buffer, "Connection: ", 12) == 0)
    {
        param_ptr = buffer+12;

        if ((session->keep_alive_enabled) &&
           ((strncmp(param_ptr, "Keep-Alive", 10) == 0) || 
            (strncmp(param_ptr, "keep-alive", 10) == 0)))
        {
            session->keep_alive = 1;
        }
        else
        {
            session->keep_alive = 0;
        }
    }
    else if (strncmp(buffer, "Content-Length: ", 16) == 0)
    {
        param_ptr = buffer+16;
        session->request.content_length = strtoul(param_ptr, NULL, 10);
    }
    else if (strncmp(buffer, "Content-Type: ", 14) == 0)
    {
        param_ptr = buffer+14;
        session->request.content_type = httpsrv_get_table_int((httpsrv_table_row*) content_type, param_ptr, strlen(param_ptr)-2);
        if (session->request.content_type == 0)
        {
            session->request.content_type = HTTPSRV_CONTENT_TYPE_OCTETSTREAM;
        }
    }
    else if (strncmp(buffer, "Authorization: ", 15) == 0)
    {
        param_ptr = buffer+15;
        if (strncmp(param_ptr, "Basic ", 6) == 0)
        {
            uint32_t decoded_length = 0;
            char* user = NULL;
            char* pass = NULL;
            param_ptr += 6;

            /* evaluate number of bytes required for worst case (no padding) */
            decoded_length = (strlen(param_ptr)/4) * 3 + 1;
            user = _mem_alloc_zero(sizeof(char)*decoded_length);
            if (user != NULL)
            {
                _mem_set_type(user, MEM_TYPE_HTTPSRV_AUTH);
                base64_decode(user, param_ptr, decoded_length);
                session->request.auth.user_id = user;
            }
            else
            {
                return;
            }

            pass = strchr(user, ':');
            if (pass)
            {
                *pass = '******';
                pass = pass + 1;
                session->request.auth.password = pass;
            }
        }
    }
}
Esempio n. 12
0
void main_task
   (
      uint_32 dummy
   )
{
   MQX_FILE_PTR         fd;
   uint_32                        i, j;
   _mqx_int                     param, result;
   I2C_STATISTICS_STRUCT        stats;
   uchar_ptr                    buffer;

   /* I2C transaction lock */
   _lwsem_create (&lock, 1);
   
   /* Allocate receive buffer */
   buffer = _mem_alloc_zero (BUFFER_SIZE);
   if (buffer == NULL) 
   {
      printf ("ERROR getting receive buffer!\n");
      _task_block ();
   }

   
   printf ("\n\n-------------- Polled I2C master example --------------\n\n");

   /* Open the I2C driver */         
   fd = fopen (I2C_DEVICE_POLLED, NULL);
   if (fd == NULL) 
   {
      printf ("ERROR opening the I2C driver!\n");
      _task_block ();
   }

   /* Test ioctl commands */
   param = 100000;
   printf ("Set current baud rate to %d ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_BAUD, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current baud rate ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_BAUD, &param))
   {
      printf ("%d\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Set master mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_MODE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x60;
   printf ("Set station address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_STATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get station address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Clear statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_CLEAR_STATISTICS, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   printf ("Get statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = I2C_EEPROM_BUS_ADDRESS;
   printf ("Set destination address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get destination address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_DESTINATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   /* Test EEPROM communication */
   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, (uchar_ptr)TEST_STRING, 0);
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, 0);

   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, (uchar_ptr)TEST_STRING, 1);
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, 1);
   printf ("Received: %c (0x%02x)\n", buffer[0], buffer[0]);
   if (buffer[0] != TEST_STRING[0])
   {
      printf ("ERROR\n");
      _task_block ();
   }

   _mem_zero (buffer, BUFFER_SIZE);
   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, sizeof(TEST_STRING));
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, sizeof(TEST_STRING));
   for (result = 0; result < BUFFER_SIZE; result++)
   {
      if (0 != buffer[result])
      {
         printf ("\nERROR during memory clearing\n");
         _task_block ();
      }
   }
   
   i2c_write_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, (uchar_ptr)TEST_STRING, sizeof(TEST_STRING));
   i2c_read_eeprom_polled (fd, I2C_EEPROM_MEMORY_ADDRESS1, buffer, sizeof(TEST_STRING));
   printf ("Received: ");
   for (result = 0; result < sizeof(TEST_STRING); result++)
   {
      printf ("%c", buffer[result]);
      if (buffer[result] != TEST_STRING[result])
      {
         printf ("\nERROR\n");
         _task_block ();
      }
   }
   printf ("\n");
   
   /* Test special cases: write 1 byte (address pointer), read 1 byte (dump memory) */
   _lwsem_wait (&lock);
   buffer[0] = 0;
   buffer[1] = 0;
   fwrite (buffer, 1, I2C_EEPROM_MEMORY_WIDTH, fd);
   if (I2C_OK != ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, NULL))
   {
      printf ("\nERROR during flush\n");
   }
   if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
   {
      printf ("\nERROR during stop\n");
   }
   
   printf ("\nMemory dump:\n");
   for (i = 0; i < 16; i++)
   {
      for (j = 0; j < 16; j++)
      {
         _time_delay (1);
         param = 1;
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_SET_RX_REQUEST, &param))
         {
            printf ("\nERROR during set rx request\n");
         }
         fread (&(buffer[j]), 1, 1, fd);
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
         {
            printf ("\nERROR during stop\n");
         }
      }
      printf ("0x%02x: ", i * 16);
      for (j = 0; j < 16; j++)
      {
         printf ("%02x ", buffer[j]);
      }
      for (j = 0; j < 16; j++)
      {
         if ((32 <= buffer[j]) && (buffer[j] <= 128))
         {
            printf ("%c", buffer[j]);
         }
         else
         {
            printf (".");
         }
      }
      printf ("\n");
   }
   _lwsem_post (&lock);
   
   printf ("\nGet statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   /* Close the driver */
   result = fclose (fd);
   if (result) 
   {
      printf ("ERROR during close, returned: %d\n", result);
   }

   
#if ENABLE_I2C_INTERRUPT

   printf ("\n\n-------------- Interrupt I2C master example --------------\n\n");
  
   /* Open the I2C driver */         
   fd = fopen (I2C_DEVICE_INTERRUPT, NULL);
   if (fd == NULL) 
   {
      printf ("Failed to open the I2C driver!\n");
      _task_block ();
   }

   /* Test ioctl commands */
   printf ("Get current baud rate ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_BAUD, &param))
   {
      printf ("%d\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Set master mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   printf ("Get current mode ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_MODE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x60;
   printf ("Set station address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_STATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get station address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   printf ("Clear statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_CLEAR_STATISTICS, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   printf ("Get statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   param = I2C_EEPROM_BUS_ADDRESS;
   printf ("Set destination address to 0x%02x ... ", param);
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }
   
   param = 0x00;
   printf ("Get destination address ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_DESTINATION_ADDRESS, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }
   
   /* Test EEPROM communication */
   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, (uchar_ptr)TEST_STRING, 0);
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, 0);

   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, (uchar_ptr)TEST_STRING, 1);
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, 1);
   printf ("Received: %c (0x%02x)\n", buffer[0], buffer[0]);
   if (buffer[0] != TEST_STRING[0])
   {
      printf ("ERROR\n");
      _task_block ();
   }
   
   _mem_zero (buffer, BUFFER_SIZE);
   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, sizeof(TEST_STRING));
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, sizeof(TEST_STRING));
   for (result = 0; result < BUFFER_SIZE; result++)
   {
      if (0 != buffer[result])
      {
         printf ("\nERROR during memory clearing\n");
         _task_block ();
      }
   }
      
   i2c_write_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, (uchar_ptr)TEST_STRING, sizeof(TEST_STRING));
   i2c_read_eeprom_interrupt (fd, I2C_EEPROM_MEMORY_ADDRESS2, buffer, sizeof(TEST_STRING));
   printf ("Received: ");
   for (result = 0; result < sizeof(TEST_STRING); result++)
   {
      printf ("%c", buffer[result]);
      if (buffer[result] != TEST_STRING[result])
      {
         printf ("\nERROR\n");
         _task_block ();
      }
   }
   printf ("\n");

   /* Test special cases: write 1 byte (address pointer), read 1 byte (dump memory) */
   _lwsem_wait (&lock);
   buffer[0] = 0;
   buffer[1] = 0;
   fwrite (buffer, 1, I2C_EEPROM_MEMORY_WIDTH, fd);
   if (I2C_OK != ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, NULL))
   {
      printf ("\nERROR during flush\n");
   }
   if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
   {
      printf ("\nERROR during stop\n");
   }
   
   printf ("\nMemory dump:\n");
   for (i = 0; i < 16; i++)
   {
      for (j = 0; j < 16; j++)
      {
         _time_delay (1);
         param = 1;
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_SET_RX_REQUEST, &param))
         {
            printf ("\nERROR during set rx request\n");
         }
         do 
         {
            result = fread (&(buffer[j]), 1, 1, fd);
         } while (0 == result);
         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))
         {
            printf ("\nERROR during stop\n");
         }
      }
      printf ("0x%02x: ", i * 16);
      for (j = 0; j < 16; j++)
      {
         printf ("%02x ", buffer[j]);
      }
      for (j = 0; j < 16; j++)
      {
         if ((32 <= buffer[j]) && (buffer[j] <= 128))
         {
            printf ("%c", buffer[j]);
         }
         else
         {
            printf (".");
         }
      }
      printf ("\n");
   }
   _lwsem_post (&lock);
   
   printf ("\nGet statistics ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATISTICS, (pointer)&stats))
   {
      printf ("OK\n  Interrupts:  %d\n", stats.INTERRUPTS);
      printf ("  Rx packets:  %d\n", stats.RX_PACKETS);
      printf ("  Tx packets:  %d\n", stats.TX_PACKETS);
      printf ("  Tx lost arb: %d\n", stats.TX_LOST_ARBITRATIONS);
      printf ("  Tx as slave: %d\n", stats.TX_ADDRESSED_AS_SLAVE);
      printf ("  Tx naks:     %d\n", stats.TX_NAKS);
   } else {
      printf ("ERROR\n");
   }

   printf ("Get current state ... ");
   if (I2C_OK == ioctl (fd, IO_IOCTL_I2C_GET_STATE, &param))
   {
      printf ("0x%02x\n", param);
   } else {
      printf ("ERROR\n");
   }

   /* Close the driver */
   result = fclose (fd);
   if (result) 
   {
      printf ("ERROR during close, returned: %d\n", result);
   }

#endif

   
   /* Free transation lock */
   _lwsem_destroy (&lock);

   /* Free buffer */
   _mem_free (buffer);
   printf("Example finished.\n");
   _task_block();
 
} /* Endbody */
Esempio n. 13
0
/*TASK*-------------------------------------------------------------------
*
* Task Name : main_task
* Comments  :
*
*END*----------------------------------------------------------------------*/
void main_task
   (
      uint_32 dummy
   )
{
    MQX_FILE_PTR           qspifd;
    int_32 ret = 0, i, byte_write, byte_read;
    uint_8_ptr data;
    uint_8 test_data[512];
    TIME_STRUCT start_time, end_time, diff_time;

    printf ("\n-------------- QSPI driver example --------------\n\n");
    printf ("This example application demonstrates usage of QSPI driver.\n");

    /* Open the QSPI driver */
    qspifd = fopen (TEST_CHANNEL, NULL);
    if (qspifd == NULL) {
        printf ("Error opening QSPI driver!\n");
        _time_delay (200L);
        _task_block ();
    }

    /* erase all */
    printf("\n\n************************************************************************\n");
    printf("Erase the first flash chip, for S25FL128S/256S, it might take 30s/60s....\n");
    printf("************************************************************************\n");
    _time_get(&start_time);

    memory_chip_erase(qspifd, FLASH_BASE_ADR);

    _time_get(&end_time);
    _time_diff(&start_time, &end_time, &diff_time);
    printf("\nErase whole flash %ld sec, %ld millisec\n", diff_time.SECONDS, diff_time.MILLISECONDS);
    printf("Finish erase all flash\n");

    printf("\n\n*****************************************\n");
    printf("*** Function Test <memory_read_data> ****\n");
    printf("*****************************************\n");
    printf("From Flash %08x: first 20 btyes\n", TEST_BUFFER1);
    byte_read = memory_read_data(qspifd, TEST_BUFFER1, 20, test_data);
    if (byte_read < 0) {
        printf("memory_read_data failed!\n");
        return;
    }

    for (i = 0; i < 20; i++) {
        printf("0x%02x ", test_data[i]);
    }

    printf("\n\n*****************************************\n");
    printf("*** Function Test <memory_read_byte> ****\n");
    printf("*****************************************\n");
    printf("From Flash %08x: first 20 bytes\n", TEST_BUFFER1);
    for (i = 0; i < 20; i++) {
        printf("0x%02x ", memory_read_byte(qspifd, TEST_BUFFER1 + i));
    }
    printf("\n");

    printf("\n\n*****************************************\n");
    printf("*** Function Test <memory_write_data> ***\n");
    printf("*****************************************\n");
    data = (uint_8_ptr)_mem_alloc_zero(TEST_BUF_SIZE1);
    if (data == NULL) {
        printf("fail to allocate write buffer\n");
        fclose(qspifd);
        return;
    }
    for (i = 0; i < TEST_BUF_SIZE1; i++) {
        data[i] = i % 256;
    }

    _time_get(&start_time);

    byte_write = memory_write_data (qspifd, TEST_BUFFER1, TEST_BUF_SIZE1, data);
    if (byte_write < 0) {
        printf("memory_write_data failed!\n");
        return;
    }

    _time_get(&end_time);
    _time_diff(&start_time, &end_time, &diff_time);
    printf("\ndata = %d, Time spends on Flash write is %ld sec, %ld millisec, rate = %ld kbps\n",
        byte_write, diff_time.SECONDS, diff_time.MILLISECONDS,
        (byte_write)/(diff_time.SECONDS * 1000 + diff_time.MILLISECONDS));

    printf("\n\n*****************************************\n");
    printf("***** Time Test <memory_read_data> ******\n");
    printf("*****************************************\n");
    for (i = 0; i < TEST_BUF_SIZE1; i++) {
        data[i] = 255;
    }

    _time_get(&start_time);

    byte_read = memory_read_data (qspifd, TEST_BUFFER1, TEST_BUF_SIZE1, data);
    if (byte_read < 0) {
        printf("memory_read_data failed!\n");
        return;
    }

    _time_get(&end_time);
    _time_diff(&start_time, &end_time, &diff_time);
    printf("\ndata = %d, Time spends on Flash read is %ld sec, %ld millisec, rate = %ld kbps\n\n",
        byte_write, diff_time.SECONDS, diff_time.MILLISECONDS,
        (byte_write)/(diff_time.SECONDS * 1000 + diff_time.MILLISECONDS));

    printf("memory_read_data read data from %08x: first 20 bytes \n", TEST_BUFFER1);
    for(i = 0; i < 20; i++) {
        printf ("0x%02x ", data[i]);
    }
    printf("\n");

    printf("\n\n*****************************************\n");
    printf("**** Compare Test <memory_read_byte> ****\n");
    printf("*****************************************\n");
    printf("memory_read_byte from %08x: first 20 bytes \n", TEST_BUFFER1);
    for (i = 0; i < 20; i++) {
        printf("0x%02x ", memory_read_byte(qspifd, TEST_BUFFER1 + i));
    }
    printf("\n");

    /* Close the SPI */
    _mem_free(data);
    ret = (uint_32)fclose (qspifd);
    if (ret) {
        printf ("Error closing QSPI, returned: 0x%08x\n", ret);
    }

    printf ("\n-------------- End of example --------------\n\n");

}
Esempio n. 14
0
uint_32 _psp_init_readyqs
   (
      void
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR kernel_data;
   READY_Q_STRUCT_PTR     q_ptr;
   uint_32                priority_levels;
   uint_32                n;

   _GET_KERNEL_DATA(kernel_data);
   kernel_data->READY_Q_LIST = (READY_Q_STRUCT_PTR) NULL;
   priority_levels = kernel_data->LOWEST_TASK_PRIORITY + 2;

   q_ptr = (READY_Q_STRUCT_PTR)_mem_alloc_zero(sizeof(READY_Q_STRUCT) * priority_levels);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if ( q_ptr == NULL ) {
      return (MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif
   _mem_set_type(q_ptr, MEM_TYPE_READYQ);

   n = priority_levels;
   while (n--) {
      q_ptr->HEAD_READY_Q  = (TD_STRUCT_PTR)q_ptr;
      q_ptr->TAIL_READY_Q  = (TD_STRUCT_PTR)q_ptr;
      q_ptr->PRIORITY      = (uint_16)n;

      if (n + kernel_data->INIT.MQX_HARDWARE_INTERRUPT_LEVEL_MAX < ((1 << CORTEX_PRIOR_IMPL) - 1))
        q_ptr->ENABLE_SR   = CORTEX_PRIOR(n + kernel_data->INIT.MQX_HARDWARE_INTERRUPT_LEVEL_MAX);
      else
        q_ptr->ENABLE_SR   = CORTEX_PRIOR((1 << CORTEX_PRIOR_IMPL) - 2);

      q_ptr->NEXT_Q        = kernel_data->READY_Q_LIST;
      kernel_data->READY_Q_LIST = q_ptr++;
   }


   /*
   ** Set the current ready q (where the ready queue searches start) to
   ** the head of the list of ready queues.
   */
   kernel_data->CURRENT_READY_Q = kernel_data->READY_Q_LIST;

#if 0
   /* Initialize the ENABLE_SR fields in the ready queues */
   sr = 0;
   n  = priority_levels;
   q_ptr =  kernel_data->READY_Q_LIST;
   while (n--) {
      q_ptr->ENABLE_SR = CORTEX_PRIOR(sr);
      if (sr < kernel_data->INIT.MQX_HARDWARE_INTERRUPT_LEVEL_MAX) {
         sr++;
      }
      q_ptr = q_ptr->NEXT_Q;
   }
#endif

   return MQX_OK;

} /* Endbody */
Esempio n. 15
0
/*FUNCTION*****************************************************************
* 
* Function Name    : _adc_open
* Returned Value   : _mqx_int - ADC_ERROR_* or ADC_OK
* Comments         : Opens and initializes ADC driver.
* 
*END*********************************************************************/
_mqx_int _adc_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 initialization parameters (ADC_INIT_STRUCT_PTR) */
      char_ptr   flags
   )
{ /* Body */
   ADC_DRIVER_BUNDLE_PTR       adc_driver_bundle = (ADC_DRIVER_BUNDLE_PTR) fd_ptr->DEV_PTR->DRIVER_INIT_PTR;
   char_ptr                    file_name_ptr = fd_ptr->DEV_PTR->IDENTIFIER; /* use driver name temporarily */
   _mqx_int                    status;

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

   if (*file_name_ptr == 0) {
      /* 
      ** ADC DEVICE DRIVER OPENED WITHOUT CHANNEL SPECIFIED
      */                                         
      ADC_INIT_STRUCT_PTR  adc_init = (ADC_INIT_STRUCT_PTR) flags;

      if (adc_init == NULL)
         return ADC_ERROR_PARAM; /* mandatory open parameter missing */

      if (NULL == adc_driver_bundle->adc) {
         adc_driver_bundle->adc = (ADC_PTR) _mem_alloc_zero(sizeof(ADC));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
         if (adc_driver_bundle->adc == NULL)
            return ADC_ERROR_ALLOC; /* memory allocation error */
#endif
         adc_driver_bundle->adt = (ADT_PTR) _mem_alloc_zero(sizeof(ADT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
         if (adc_driver_bundle->adt == NULL) {
            _mem_free(adc_driver_bundle->adt);
            return ADC_ERROR_ALLOC; /* memory allocation error */
         }
#endif
      } else
         return ADC_ERROR_OPENED; /* cannot open more than one instance of ADC driver */
      
      adc_driver_bundle->adc->g.resolution = adc_init->resolution;
      adc_driver_bundle->adt->g.run = 0;

      if (IO_OK != (status = _adc_hw_init(fd_ptr, adc_driver_bundle->adc))) { /* init cpu according to adc_general_config */
         _mem_free(adc_driver_bundle->adc);
         _mem_free(adc_driver_bundle->adt);
         adc_driver_bundle->adc = NULL;
         adc_driver_bundle->adt = NULL;
      }
      else if (IO_OK != (status = _adt_hw_init(fd_ptr, adc_driver_bundle->adt))) { /* init cpu according to adt_general_config */
         _mem_free(adc_driver_bundle->adc);
         _mem_free(adc_driver_bundle->adt);
         adc_driver_bundle->adc = NULL;
         adc_driver_bundle->adt = NULL;
      }
      
      //fd_ptr->DEV_DATA_PTR = NULL; /* not needed: we dont need to store any additional data */

      return status;
   }
   else {
      /*
      ** CHANNEL TO BE OPENED, FILENAME IS IN OPEN_NAME_PTR
      */
      ADC_INIT_CHANNEL_STRUCT_PTR ch_init = (ADC_INIT_CHANNEL_STRUCT_PTR) flags;
      ADC_CHANNEL_BUNDLE_PTR      adc_channel_bundle;
      ADC_CHANNEL_PTR             *adc_ch;
      ADT_CHANNEL_PTR             *adt_ch;
      _mqx_uint                   ch = 0, i;
    
      adc_ch = adc_driver_bundle->adc_ch;
      adt_ch = adc_driver_bundle->adt_ch;
      
      if (ch_init == NULL)
         return ADC_ERROR_PARAM; /* mandatory open parameter missing */

      if (NULL == adc_driver_bundle->adc)
         return ADC_ERROR_MISSING_DEVICE; /* general device was not opened */

      if (ch_init->number_samples < 1)
         return ADC_ERROR_BAD_PARAM; /* number of samples must be more than 0 */

//      open_name_ptr = file_name_ptr; // not needed, already done

#if ADC_STORE_FILENAMES
      for (ch = 0; ch < ADC_MAX_CHANNELS; ch++)
         if (!strcmp((const char *) adc_driver_bundle->adc_name[ch], open_name_ptr))
            return ADC_ERROR_OPENED; /* file with such name already opened */
#endif
      for (ch = 0; (ch < ADC_MAX_CHANNELS) && (adc_driver_bundle->adc_name[ch] != NULL); ch++)
      { /* searching for free channel in the bundle */
      }
      
      if (ch == ADC_MAX_CHANNELS)
         return ADC_ERROR_FULL; /* no free channel */

      /* variable 'ch' now contains valid channel number */
      adc_channel_bundle = (ADC_CHANNEL_BUNDLE_PTR) _mem_alloc_zero(sizeof(ADC_CHANNEL_BUNDLE));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
      if (adc_channel_bundle == NULL) {
         status = ADC_ERROR_ALLOC; /* memory allocation error */
         goto error_channel_0;
      }
#endif

      if (adc_ch[ch] == NULL) {
         adc_ch[ch] = (ADC_CHANNEL_PTR) _mem_alloc_zero(sizeof(ADC_CHANNEL));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
         if (adc_ch[ch] == NULL) {
            status = ADC_ERROR_ALLOC; /* memory allocation error */
            goto error_channel_1;
         }
#endif
         adt_ch[ch] = (ADT_CHANNEL_PTR) _mem_alloc_zero(sizeof(ADT_CHANNEL));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
         if (adt_ch[ch] == NULL) {
            status = ADC_ERROR_ALLOC; /* memory allocation error */
            goto error_channel_2;
         }
#endif
      } else
         return IO_ERROR; /* channel already in use */

      adc_channel_bundle->adc_ch = adc_ch[ch];
      adc_channel_bundle->adt_ch = adt_ch[ch];
      /* store file context for opened channel */
      fd_ptr->DEV_DATA_PTR = adc_channel_bundle; /* store information about channel */

      /* allocate channel buffer */
      adc_ch[ch]->g.buffer_start = _mem_alloc_zero((ch_init->buffer_size + 1) * sizeof(ADC_RESULT_STRUCT)); /* zero is needed for ADC_CHANNEL_ACCUMULATE */
      adc_ch[ch]->g.buffer_end = adc_ch[ch]->g.buffer_start + (ch_init->buffer_size + 1);

      if (adc_ch[ch]->g.buffer_start == NULL) {
         status = ADC_ERROR_ALLOC; /* memory allocation error */
         goto error_channel_3;
      }

      // initialize channel
      adc_ch[ch]->g.buffer_task = adc_ch[ch]->g.buffer_start;
      adc_ch[ch]->g.buffer_driver = adc_ch[ch]->g.buffer_start;

      adc_ch[ch]->g.number = ch;
      adc_ch[ch]->g.init_flags = ch_init->flags;
      adc_ch[ch]->g.source = ch_init->source;

      adt_ch[ch]->g.trigger = ch_init->trigger;
      adt_ch[ch]->g.offset = ch_init->time_offset;
      adt_ch[ch]->g.period = ch_init->time_period;
      
      adt_ch[ch]->g.number = ch;
      adt_ch[ch]->g.init_flags = ch_init->flags;
      adt_ch[ch]->g.samples_preset = ch_init->number_samples - 1;
      adt_ch[ch]->g.samples = adt_ch[ch]->g.samples_preset;

#if MQX_USE_LWEVENTS
      adt_ch[ch]->g.complete_event = ch_init->complete_event;
      if (ch_init->event_mask == 0)
         adt_ch[ch]->g.event_mask = 0x01;
      else
         adt_ch[ch]->g.event_mask = ch_init->event_mask;
#endif

      if (IO_OK != (status = _adc_hw_channel_init(fd_ptr, adc_ch[ch]))) /* this should initialize ADC converter hardware */
         goto error_channel_4;

      if (IO_OK != (status = _adt_hw_channel_init(fd_ptr, adt_ch[ch]))) /* this should initialize ADC timer hardware */
         goto error_channel_5;

#if ADC_STORE_FILENAMES
      /* allocate filename buffer */
      if (NULL == (adc_driver_bundle->adc_name[ch] = _mem_alloc_zero(strlen(open_name_ptr) + 1))) /* +1 for zero-ending char */
         goto error_channel_6;
      for (i = 0; open_name_ptr[i] != 0; i++)
         adc_driver_bundle->adc_name[ch][i] = open_name_ptr[i];
      adc_driver_bundle->adc_name[ch][i] = 0;
#else
      adc_driver_bundle->adc_name[ch] = (pointer) 0xFFFFFFFF; /* channel is used */
#endif
      
      /* if ADC_CHANNEL_START_NOW was defined, then start channel */
      if (!(ch_init->flags & ADC_CHANNEL_START_TRIGGERED))
         return _adc_ioctl(fd_ptr, ADC_IOCTL_RUN_CHANNEL, NULL);
      
      return IO_OK;     
      
error_channel_6:
      _adt_hw_channel_deinit(fd_ptr, adt_ch[ch]);
error_channel_5:
      _adc_hw_channel_deinit(fd_ptr, adc_ch[ch]);
error_channel_4:
      _mem_free(adc_ch[ch]->g.buffer_start);
error_channel_3:
      _mem_free(adt_ch[ch]);
      adt_ch[ch] = NULL;
error_channel_2:
      _mem_free(adc_ch[ch]);
      adc_ch[ch] = NULL;
error_channel_1:
      _mem_free(adc_channel_bundle);
error_channel_0:
      return status;
   }


} /* Endbody */
Esempio n. 16
0
int32_t Shell_smtp (int32_t argc, char *argv[])
{
    struct addrinfo            hints;
    struct addrinfo           *result, *rp;
    int32_t                    retval = 0;
    uint32_t                   sfd = 0;
    int32_t                    err_code = 0;
    bool                       print_help;
    bool                       shorthelp = FALSE;
    SMTP_PARAM_STRUCT          params;
    char                      *errstr = NULL;
    char                      *server = NULL;
    char                      *optstring = ":f:t:s:u:p:m:h";
    int32_t                    next_option;
    char                      *email_text = NULL;
    uint32_t                   email_size = 0;
    TIME_STRUCT                time;
    DATE_STRUCT                date;
    char                       date_str[DATE_LENGTH];
    SHELL_GETOPT_CONTEXT       gopt_context;

    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 */
    Shell_getopt_init(&gopt_context);
    do
    {
        next_option = Shell_getopt(argc, argv, optstring, &gopt_context);
        switch (next_option)
        {
            case 'f':
                params.envelope.from = gopt_context.optarg;
                break;
            case 't':
                params.envelope.to = gopt_context.optarg;
                break;
            case 'm':
                params.text = gopt_context.optarg;
                break;
            case 's':
                server = gopt_context.optarg;
                break;
            case 'u':
                params.login = gopt_context.optarg;
                break;
            case 'p':
                params.pass = gopt_context.optarg;
                break;
            case 'h':
                print_usage (stdout, FALSE);
                return(SHELL_EXIT_SUCCESS);
            case '?': /* 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(&time);
    _time_to_date(&time,&date);

    snprintf(date_str, DATE_LENGTH, "%s, %d %s %d %02d:%02d:%02d -0000",
        wday[date.WDAY],date.DAY, months[date.MONTH-1],date.YEAR, date.HOUR, date.MINUTE, date.SECOND);
    /* 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 *) _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 *) _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);
} 
Esempio n. 17
0
uint32_t clone_application(void)
{
    char * source_buffer = NULL, * target_buffer = NULL;
    MQX_FILE_PTR source_file = NULL, target_file = NULL;
    uint32_t read_size, write_size, result = 1;
    uint32_t position = 0;

/* allocate resources */
    source_buffer = (char *)_mem_alloc_zero(BUFFER_SIZE);
    if (NULL == source_buffer)
    {
        result = 0;
    }
    target_buffer = (char *)_mem_alloc_zero(BUFFER_SIZE);
    if (NULL == target_buffer)
    {
        result = 0;
    }
    source_file = fopen("flashx:code", NULL);
    if (NULL == source_file)
    {
        result = 0;
    }
    target_file = fopen("flashx:swap1", NULL);
    if (NULL == target_file)
    {
        result = 0;
    }

/* clean target file of no error occurred */
    if (result)
    {
        fseek(target_file, 0, IO_SEEK_SET);
        ioctl(target_file, FLASH_IOCTL_ERASE_FILE, NULL);
    }

/* clone source file and target file */
    while (result)
    {
        /* read source_buffer of source_file */
        fseek(source_file, position, IO_SEEK_SET);
        read_size = read(source_file, source_buffer, BUFFER_SIZE);

        /* end loop if whole file was readed */
        if (!read_size)
        {
            break;
        }

        /* write source_buffer to target_file */
        fseek(target_file, position, IO_SEEK_SET);
        write_size = write(target_file, source_buffer, read_size);
        if (write_size != read_size)
        {
            return 0;
        }

        /* read written data to target_buffer */
        fseek(target_file, position, IO_SEEK_SET);
        write_size = read(target_file, target_buffer, read_size);
        if (write_size != read_size)
        {
            return 0;
        }

        /* verify written data by buffer comparsion */
        if (strncmp(source_buffer, target_buffer, read_size))
        {
            return 0;
        }

        /* update file position */
        position += read_size;
    }

/* free resources */
    if (source_file != NULL)
    {
        fclose(source_file);
    }
    if (target_file != NULL)
    {
        fclose(target_file);
    }
    if (source_buffer != NULL)
    {
        _mem_free(source_buffer);
    }
    if (target_buffer != NULL)
    {
        _mem_free(target_buffer);
    }

/* return status */
    return result;
}
Esempio n. 18
0
int32_t  Shell_compare(int32_t argc, char *argv[] )
{ /* Body */
   bool      print_usage, shorthelp = FALSE;
   int32_t      size1, size2, return_code = SHELL_EXIT_SUCCESS;
   MQX_FILE_PTR in_fd_1=NULL, in_fd_2=NULL;
   char         *file1=NULL, *file2=NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int32_t               error = 0;      

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc != 3)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } 
      /* check if filesystem is mounted */ 
      else if (NULL == Shell_get_current_filesystem(argv))  
      {
         printf("Error, file system not mounted\n");
         return_code = SHELL_EXIT_ERROR;
      }
      else if (MFS_alloc_path(&file1) != MFS_NO_ERROR) {
         printf("Error, unable to allocate memory for paths\n" );
         return_code = SHELL_EXIT_ERROR;
      } else {
         error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
         if(!error)
         {
            in_fd_1 = fopen(file1, "r");
         }      

         error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[2],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
         if(!error)
         {
            in_fd_2 = fopen(file1, "r");
         }  

         MFS_free_path(file1);         

         if (in_fd_1 == NULL)  {
             printf("Error, unable to open file %s\n", argv[1] );
             return_code = SHELL_EXIT_ERROR;
         } else  if (in_fd_2 == NULL)  {
             printf("Error, unable to open file %s\n", argv[2] );
             return_code = SHELL_EXIT_ERROR;
         } else {
            file1 = _mem_alloc_zero(COMPARE_BLOCK_SIZE);
            file2 = _mem_alloc_zero(COMPARE_BLOCK_SIZE);
            if ((file1==NULL) || (file2==NULL)) {
               printf("Error, unable to allocate buffer space" );
               return_code = SHELL_EXIT_ERROR;
            } else {
               do {
                  size1 = read(in_fd_1, file1, COMPARE_BLOCK_SIZE);
                  size2 = read(in_fd_2, file2, COMPARE_BLOCK_SIZE);
                  if (size1!=size2) {
                     printf("Compare failed, files have different sizes\n" );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (size1 > 0) {
                     if (memcmp(file1,file2,COMPARE_BLOCK_SIZE)!=0) {
                        printf("Compare failed, files are different\n" );
                        return_code = SHELL_EXIT_ERROR;
                     }                     
                  }
               } while ((size1>0) && (return_code == SHELL_EXIT_SUCCESS));
               if (return_code == SHELL_EXIT_SUCCESS) {
                  printf("The files are identical\n" );
               }
            }
            if (file1) _mem_free(file1);
            if (file2) _mem_free(file2);
         }
         if (in_fd_1) fclose(in_fd_1); 
         if (in_fd_2) fclose(in_fd_2); 
      }
   }
      
      
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <file1> <file2> \n", argv[0]);
      } else  {
         printf("Usage: %s <file1> <file2>\n", argv[0]);
         printf("   <file1> = first file to compare\n");
         printf("   <file2> = second file to compare\n");
      }
   }
   return return_code;
} /* Endbody */
Esempio n. 19
0
int_32  Shell_search_file_r(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   int_32               len;
   MQX_FILE_PTR         fs_ptr;
   char_ptr             path_ptr, mode_ptr;
   pointer              dir_ptr;
   char_ptr             buffer = NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int_32               error = 0;
   char_ptr             file_name,source_name; 
   MFS_SEARCH_DATA search_data;
   pointer      search_ptr;
   DIR_STRUCT_PTR dir_file; // wk @130405 -->
   dir_file = _mem_alloc_zero( sizeof( DIR_STRUCT ));  // wk @130405 -->
   
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 2)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         path_ptr  ="*.*";
         mode_ptr = "m";

         source_name=argv[1];
         
         fs_ptr = Shell_get_current_filesystem(argv);
         /* check if filesystem is mounted */ 
         if (fs_ptr == NULL)  {
             printf("Error, file system not mounted\n");
             return_code = SHELL_EXIT_ERROR;
         } else  {
            buffer = _mem_alloc(BUFFER_SIZE);
            error = ioctl(fs_ptr, IO_IOCTL_CHANGE_CURRENT_DIR, shell_ptr->CURRENT_DIR);
            if (buffer && !error) {
            
               dir_ptr = _io_mfs_dir_open(fs_ptr, path_ptr, mode_ptr );
            
               if (dir_ptr == NULL)  {
                  printf("File not found.\n");
                  return_code = SHELL_EXIT_ERROR;
               } else {
                 
                 
//                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk(dir_ptr, buffer, BUFFER_SIZE )) > 0) {  // wk @130405-->old
                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk1(dir_ptr, buffer, BUFFER_SIZE,dir_file )) > 0) {
//                    printf ("%-12.12s  %6lu \n"
//                    ,dir_ptr_g->SEARCH_DATA.NAME, dir_ptr_g->SEARCH_DATA.FILE_SIZE);
//                    file_name=dir_ptr_g->SEARCH_DATA.NAME;   // wk @130405-->old                   
                    printf ("%-12.12s  %6lu \n"
                    ,dir_file->SEARCH_DATA.NAME, dir_file->SEARCH_DATA.FILE_SIZE);
//                    file_name=dir_ptr_g->SEARCH_DATA.NAME; // wk @130405-->old
                    file_name=dir_file->SEARCH_DATA.NAME;
                    if(argc==2)
                    {
                      while(*(source_name)!='\0')
                       if(*(file_name++)!= *(source_name++))
                        goto next;
                      
                       error=33;   // WK --> 文件找到
                       break;     
                    }
 next:                 source_name=argv[1];                     
                  } 
                  if(argc==2)
                  printf("error=%d if /t33表示文件找到\n",error);
                  _io_mfs_dir_close(dir_ptr);
               }
               
               _mem_free(buffer);
               _mem_free(dir_file);
            } else {
               if(buffer == NULL){
                 printf("Error, unable to allocate space.\n" );
               } else {
                 printf("Error, directory does not exist.\n" );
               }
               return_code = SHELL_EXIT_ERROR;
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<filename>]\n", argv[0]);
      } else  {
         printf("Usage: %s [<filespec> [<attr>]]\n", argv[0]);
         printf("   <filename>   = filename what want to fine\n");
      }
   }
   return return_code;
} /* Endbody */
Esempio n. 20
0
/*TASK*-----------------------------------------------------
*
* Task Name    : nill_task
* Comments     :
*    This task does nothing
*
*END*-----------------------------------------------------*/
void nill_task
   (
      uint_32 initial_data
   )
{
   MQX_FILE_PTR   nandflash_hdl;
   _mqx_int       i;
   _mqx_uint      ID, num_blocks, virt_page_size, block_size, tmp = 0;
   uchar_ptr      write_buffer, read_buffer;
   _mem_size      num_virt_pages_per_block, seek_location;
   uint_8_ptr     bbt;

   _int_install_unexpected_isr();

   puts("\n\n");
   puts("MQX NAND Flash Example Application\n");
   puts("==================================\n");

   /* Open the flash device */
   nandflash_hdl = nandflash_open(FLASH_NAME);

   /* Get NAND Flash organization data */
   puts("\nObtaining NAND Flash organization data ...");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_ID, &ID))
       printf("\nID:                      0x%x", ID);
   else
       printf("\nID not obtained");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_PHY_PAGE_SIZE, &tmp))
       printf("\nPhysical page size:      %d bytes", tmp);
   else
       printf("\nPhysical page size not obtained");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_SPARE_AREA_SIZE, &tmp))
       printf("\nSpare area size:         %d bytes", tmp);
   else
       printf("\nSpare area size not obtained");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_BLOCK_SIZE, &block_size))
       printf("\nBlock size:              %d bytes", block_size);
   else
       printf("\nBlock size not obtained");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_NUM_BLOCKS, &num_blocks))
       printf("\nNumber of blocks:        %d", num_blocks);
   else
       printf("\nNumber of blocks not obtained");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_WIDTH, &tmp))
       printf("\nWidth:                   %d", tmp);
   else
       printf("\nWidth not obtained");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_NUM_VIRT_PAGES, &tmp))
       printf("\nNumber of virtual pages: %d", tmp);
   else
       printf("\nNumber of virtual pages not obtained");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_VIRT_PAGE_SIZE, &virt_page_size))
       printf("\nVirtual page size:       %d bytes\n", virt_page_size);
   else
       printf("\nVirtual page size not obtained\n");

   /* Get Bad Block Table */
   bbt = _mem_alloc_zero(num_blocks);
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_GET_BAD_BLOCK_TABLE, bbt))
   {
       for (i=0; i<num_blocks; i++)
           if(bbt[i]==0)
           {
                printf("\nBlock #%d is bad", i);
                if(NANDFLASHERR_BLOCK_BAD != ioctl(nandflash_hdl, NANDFLASH_IOCTL_CHECK_BLOCK, (void*)i))
                    printf("\nCHECK BLOCK IOCTL command testing failed");
           }
   }
   else
   {
       printf("\nReading Bad block table not successful ");
   }

#if BSP_TWR_K60F120M
   /*
   ** Needed to decrease the size of buffer because of limited SRAM memory
   ** TWR-K60F120M - use nand device which block size is 128kB.
   ** There is not enough RAM memory for allocating one block.
   */
   block_size = block_size/8;
#endif

   /* Allocate read and write buffers */
   write_buffer = allocate_buffer(2*block_size, "write");
   read_buffer = allocate_buffer(2*block_size, "read");

   /* Calculate the number of virtual pages per one block */
   num_virt_pages_per_block = block_size / virt_page_size;

   /* Fill data to write buffer */
   for ( i = 0; i < 2*block_size; i++ )
        write_buffer[i] = rand();

   /* Any single bit can only be programmed one time before an erase is required
      and pages must be programmed consecutively from the least significant bit page
      of the block to the most significant bit pages of the block.
      Erase block #0 before writting to the first page of the block. */
   if(MQX_OK != ioctl(nandflash_hdl, NANDFLASH_IOCTL_ERASE_BLOCK, (void*)0))
       printf("\n\nErasing block #0 failed.");
   else
       printf("\n\nErasing block #0 passed.");

   /* Write to block #0 */
   printf("\nWriting data to %d virtual pages of block #0 ... ", num_virt_pages_per_block);
   seek_location = 0;
   fseek(nandflash_hdl, seek_location, IO_SEEK_SET);
   i = write(nandflash_hdl, &write_buffer[0], num_virt_pages_per_block);
   size_compare(nandflash_hdl, i, num_virt_pages_per_block);

   /* Read data back from block #0 and compare with the write buffer */
   printf("\n\nReading data back from %d virtual pages of block #0 ... ", num_virt_pages_per_block);
   fseek(nandflash_hdl, seek_location, IO_SEEK_SET);
   if(num_virt_pages_per_block == read(nandflash_hdl, read_buffer, num_virt_pages_per_block))
       printf("Done");
   else
       printf("Failed");
   printf("\nComparing data ... ");
   compare_test(write_buffer, read_buffer, block_size);


#if (FLASH_TEST_ERASE_CHIP)
   printf("\n\nErasing entire chip ... ");
   if(MQX_OK == ioctl(nandflash_hdl, NANDFLASH_IOCTL_ERASE_CHIP, NULL))
       printf("Done");
   else
       printf("Failed");
#endif

   /* The following section shows how bad block management is performed.
      Block #1 is marked as bad and checked afterwards. Then, the block
      marked as bad is forced to be erased causing the block #1 is marked
      as good again which is checked afterwards. */
   if(NANDFLASHERR_NO_ERROR != ioctl(nandflash_hdl, NANDFLASH_IOCTL_MARK_BLOCK_AS_BAD, (void*)1))
       printf("\nMarking block #1 as bad failed.");
   if(NANDFLASHERR_BLOCK_BAD != ioctl(nandflash_hdl, NANDFLASH_IOCTL_CHECK_BLOCK, (void*)1))
       printf("\nChecking block #1 failed.");
   if(NANDFLASHERR_NO_ERROR != ioctl(nandflash_hdl, NANDFLASH_IOCTL_ERASE_BLOCK_FORCE, (void*)1))
       printf("\nErasing block #1 failed.");
   else
       printf("\nErasing block #1 passed.");

   if(NANDFLASHERR_BLOCK_NOT_BAD != ioctl(nandflash_hdl, NANDFLASH_IOCTL_CHECK_BLOCK, (void*)1))
       printf("\nChecking block #1 failed.");

   /* Do several consequent writes, starting at the beginning of the block #1 and loading the whole blocks #1 and #2. */

   /* Fill new data to write buffer */
   for ( i = 0; i < 2*block_size; i++ )
        write_buffer[i] = rand();

   /* As there is no need to erase the block #1 again (NANDFLASH_IOCTL_ERASE_BLOCK_FORCE IOCTL command was already
      executed) erase just the block #2 */
   if(MQX_OK != ioctl(nandflash_hdl, NANDFLASH_IOCTL_ERASE_BLOCK, (void*)2))
       printf("\n\nErasing block #2 failed.");
   else
       printf("\n\nErasing block #2 passed.");

   /* Write into 3/4 of virtual pages of the block #1 */
   printf("\n\nWriting data to %d virtual pages of block #1 ... ", 3*num_virt_pages_per_block/4);
   seek_location = 1*num_virt_pages_per_block;
   fseek(nandflash_hdl, seek_location, IO_SEEK_SET);
   i = write(nandflash_hdl, &write_buffer[0], 3*num_virt_pages_per_block/4);
   size_compare(nandflash_hdl, i, 3*num_virt_pages_per_block/4);

   /* Write another X virtual pages, crossing between block #1 and block #2 */
   printf("\nWriting another %d virtual pages, crossing between block #1 and block #2 ... ", 3*num_virt_pages_per_block/4);
   seek_location += 3*num_virt_pages_per_block/4;
   fseek(nandflash_hdl, seek_location, IO_SEEK_SET);
   i = write(nandflash_hdl, &write_buffer[(3*num_virt_pages_per_block/4)*virt_page_size], 3*num_virt_pages_per_block/4);
   size_compare(nandflash_hdl, i, 3*num_virt_pages_per_block/4);

   /* Write the rest of the block #2 */
   printf("\nWriting data to the rest of block #2 ... ");
   seek_location += 3*num_virt_pages_per_block/4;
   fseek(nandflash_hdl, seek_location, IO_SEEK_SET);
   i = write(nandflash_hdl, &write_buffer[2*(3*num_virt_pages_per_block/4)*virt_page_size], (2*num_virt_pages_per_block)-(2*3*num_virt_pages_per_block/4));
   size_compare(nandflash_hdl, i, (2*num_virt_pages_per_block)-(2*3*num_virt_pages_per_block/4));

   /* Read data back from the whole block #1 and #2 and compare with the write buffer */
   printf("\n\nReading data back from the whole block #1 and #2 ... ");
   seek_location -= 2*(3*num_virt_pages_per_block/4);
   fseek(nandflash_hdl, seek_location, IO_SEEK_SET);
   if(2*num_virt_pages_per_block == read(nandflash_hdl, read_buffer, 2*num_virt_pages_per_block))
       printf("Done");
   else
       printf("Failed");
   printf("\nComparing data ... ");
   compare_test(write_buffer, read_buffer, 2*block_size);


   /* Close the device */
   nandflash_close(nandflash_hdl);
}
Esempio n. 21
0
_ppp_handle PPP_init
   (
        PPP_PARAM_STRUCT*     params
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4 
    PPP_CFG_PTR          ppp_ptr;
    uint32_t             error;
    IPCP_DATA_STRUCT     ipcp_data;
    int stage = 0;

    /* Allocate the state structure */
    ppp_ptr = _mem_alloc_zero(sizeof(PPP_CFG));
    
    if (!ppp_ptr)
    {
        return(NULL);
    }
    ppp_ptr->DEVICE_NAME = _mem_alloc_zero(strlen(params->device)+1);
    if (ppp_ptr->DEVICE_NAME == NULL)
    {
        _mem_free(ppp_ptr);
        return(NULL);
    }
    strcpy(ppp_ptr->DEVICE_NAME, params->device);
    /* Stage 0 - Open low level device */
    ppp_ptr->IOPCB_DEVICE = fopen(params->device, NULL);
    if (ppp_ptr->IOPCB_DEVICE == NULL)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 1 - Initialize HDLC and lwsem */
    ppp_ptr->DEVICE = _iopcb_ppphdlc_init(ppp_ptr->IOPCB_DEVICE);
    if (ppp_ptr->DEVICE == NULL)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }

    ppp_ptr->RECV_OPTIONS = &PPP_DEFAULT_OPTIONS;
    ppp_ptr->SEND_OPTIONS = &PPP_DEFAULT_OPTIONS;

    if (_lwsem_create(&ppp_ptr->MUTEX, 1))
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 2 - Initialize LCP */
    error = LCP_init(ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 3 - Initialize and open CCP */
    /*
    error = CCP_init(ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return error;
    }
    CCP_open(ppp_ptr);
    */
    stage++;

    /* Stage 4 - Create a pool of message buffers */
    ppp_ptr->MSG_POOL = RTCS_msgpool_create(sizeof(PPP_MESSAGE), PPP_MESSAGE_INITCOUNT, PPP_MESSAGE_GROWTH, PPP_MESSAGE_LIMIT);
    if (ppp_ptr->MSG_POOL == MSGPOOL_NULL_POOL_ID)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 5 - Create the Tx Task */
    error = RTCS_task_create("PPP tx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_tx_task, ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    } 
    stage++;

    /* Stage 6 - Create the Rx Task */
    ppp_ptr->STOP_RX = FALSE; 

    error = RTCS_task_create("PPP rx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_rx_task, ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 7 - Open HDLC layer */
    error = _iopcb_open(ppp_ptr->DEVICE, PPP_lowerup, PPP_lowerdown, ppp_ptr);
    if (error != PPPHDLC_OK)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    ppp_ptr->VALID = PPP_VALID;
    stage++;

    /* Stage 8 - Add PPP interface to RTCS */
    error = RTCS_if_add(ppp_ptr, RTCS_IF_PPP, &ppp_ptr->IF_HANDLE);
    if (error != RTCS_OK)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 9 - Bind IP address to PPP interface */
    _mem_zero(&ipcp_data, sizeof(ipcp_data));
    ipcp_data.IP_UP              = params->up;
    ipcp_data.IP_DOWN            = params->down;
    ipcp_data.IP_PARAM           = params->callback_param;

    if(params->listen_flag == 0)
    {
        ipcp_data.ACCEPT_LOCAL_ADDR  = TRUE;
        ipcp_data.ACCEPT_REMOTE_ADDR = TRUE;
    }
    else
    {
        ipcp_data.ACCEPT_LOCAL_ADDR  = FALSE;
        ipcp_data.ACCEPT_REMOTE_ADDR = FALSE;
    }
    ipcp_data.LOCAL_ADDR         = params->local_addr;
    ipcp_data.REMOTE_ADDR        = params->remote_addr;
    ipcp_data.DEFAULT_NETMASK    = TRUE;
    ipcp_data.DEFAULT_ROUTE      = TRUE;

    error = RTCS_if_bind_IPCP(ppp_ptr->IF_HANDLE, &ipcp_data);
    if (error != RTCS_OK)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    params->if_handle = ppp_ptr->IF_HANDLE;
    stage++;

    /* Stage 10 - Init complete, return handle */
    return(ppp_ptr);

#else

    return(NULL);    

#endif /* RTCSCFG_ENABLE_IP4 */

} /* Endbody */
Esempio n. 22
0
/*TASK*-----------------------------------------------------
* 
* Task Name    : YaDa
* Comments     :
*    
*
*END*-----------------------------------------------------*/
void YaDa
   (
      uint_32 initial_data
   )
{
 #ifdef _GUI_DBUG_
   printf("\n----------MAIN&GUI_Task----------\n");
   printf("\n----------             ----------\n");
   printf("\n----------             ----------\n");
   printf("\n----------      END    ----------\n");
#endif 
  UartLCD_init();  // uart initialization
  UartTouch_init();
  flg_int(); // wk --> 初始化一些标志 !  
  spi2_dma_int(); // dsp2k60 spi2 初始化
  
  YADA_70(PageStart); //必要的初始化后进入首页
  delay_ms(1000); // wk -->test  延时1s
  delay_ms(4000); // wk -->test  延时4s,等待U盘启动完成
//  YADA_E4();  // wk --> 屏幕校正
  YADA_70(MenuTop);  // 进入菜单首页
  
  RefreshFlg = 0; //页面无刷新 
    
    SHELL_CONTEXT_PTR    shell_ptr;
    shell_ptr = _mem_alloc_zero( sizeof( SHELL_CONTEXT ));
    _mem_set_type(shell_ptr, MEM_TYPE_SHELL_CONTEXT);
    uint_32 file_size;  uchar status;
   /* wk @130401 --> 在 flash中 新建 sysset 用于系统变量保存 */
    shell_ptr->ARGC = 2;
    shell_ptr->ARGV[0]="cd";
    shell_ptr->ARGV[1]="f:\\"; 
    Shell_cd(shell_ptr->ARGC, shell_ptr->ARGV);
    
//      shell_ptr->ARGC = 2;
//      shell_ptr->ARGV[0]="df_s";
    shell_ptr->ARGV[1]="SYSSET";   //wk --> 注意:查找的文件名暂时必须要是大写
    status=Shell_search_file_r1(shell_ptr->ARGC, shell_ptr->ARGV,&file_size);
    if(status==0)
    {
//        shell_ptr->ARGC = 2;
//        shell_ptr->ARGV[0]="mkdir";
      shell_ptr->ARGV[1]="SYSSET"; 
      Shell_mkdir(shell_ptr->ARGC, shell_ptr->ARGV);
    }
  _mem_free(shell_ptr);
    
  /* button1 into interrupt for shell or maingui task change */
   GPIO_PIN_STRUCT pins_int[] = {
            BSP_BUTTON1 | GPIO_PIN_IRQ_RISING ,
            GPIO_LIST_END
        };
    MQX_FILE_PTR port_file4;        
         /* 这是按键1 上升沿中断*/
   port_file4 = fopen("gpio:read", (char_ptr) &pins_int );
   ioctl(port_file4, GPIO_IOCTL_SET_IRQ_FUNCTION, (pointer)int_callback);        
  /* end */
  /* wk @130330 -->timer of lpt */
   /* wk @130504 --> 调试事件,先关闭 */
   _lpt_install (0,3 * 1000000 , LPT_FLAG_CLOCK_SOURCE_LPO, 11, timer_isr, TRUE);//3 * 1000000  --> 3秒   
  /* wk @130330 -->timer end */
   
//   delay_ms(4000); 
   _rtc_init ( RTC_INIT_FLAG_CLEAR); // wk @130510 --> 在应用程序中再初始化并打开
   _rtc_init ( RTC_INIT_FLAG_ENABLE); /* wk@130511-->程序有时可能因为此处影响触摸屏的应用 */
//   TimeSet();
  while(1)
  {   
      if(SysFlashData[5])                           //背光标志,1为开背光,0为关。
        {
            YADA_5F(0x3f);                            //背光全开
        }
        else
        {
            YADA_5F(0x08);                             //背光部分开
        }
      
      MainLoop(); //循环主程序
  }
}