示例#1
0
void hal_diag_read_char(char *c)
{
    int rc;
    do {
        rc = cyg_hal_sys_read(0, c, 1);
    } while ((-CYG_HAL_SYS_EINTR == rc) || (-CYG_HAL_SYS_EAGAIN == rc));
}
//initialize data and enable IT
int dev_linux_eth_open(desc_t desc, int o_flag) {
   cyg_vector_t eth_vector = CYGNUM_HAL_INT_ETH;
   int rc;
   //
   if(o_flag & O_WRONLY) {
      if(_linux_eth_desc_wr>=0)
         return -1;
      _linux_eth_desc_wr=desc;
   }
   if(o_flag & O_RDONLY) {
      if(_linux_eth_desc_rd>=0)
         return -1;
      _linux_eth_desc_rd = desc;
      _linux_eth_input_r = 0;
      _linux_eth_input_w = 0;
   }

   //
   if(_linux_eth_desc_wr>=0 && _linux_eth_desc_rd>=0) {
      //open eth port in virtual cpu
      eth_cmd.hdwr_id = ETH_0;
      eth_cmd.cmd = OPS_OPEN;
      //

      //disable IT
      //__clr_irq();
      while(cyg_hal_sys_write(1, (void *)&eth_cmd, sizeof(virtual_cmd_t)) != sizeof(virtual_cmd_t)) ;
      while(cyg_hal_sys_read(0, (void *)&eth_cmd, sizeof(virtual_cmd_t)) != sizeof(virtual_cmd_t)) ;
      //enable IT
      //__set_irq();
      cyg_interrupt_unmask(eth_vector);
   }
   return 0;
}
示例#3
0
int
flash_program_buf(volatile flash_t *addr, flash_t *data, int len,
                  unsigned long block_mask, int buffer_size)
{
    unsigned int offset = (unsigned int) addr;
    cyg_uint8 *buf = (cyg_uint8 *) data;

    // This helps speed up the programming
    static cyg_uint8 tmp[4096];

    offset -= (unsigned int) cyg_dev_flash_synth_base;

    while (len > 0) {
        int i;
        int write_size = MIN(len, sizeof(tmp));
        // Writing to NOR flash only sets bits from 1 to 0, not vice-versa
        cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
                          CYG_HAL_SYS_SEEK_SET);
        cyg_hal_sys_read(cyg_dev_flash_synth_flashfd, tmp, write_size);
        for (i = 0; i < write_size; i++)
            tmp[i] = tmp[i] & buf[i];
        cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
                          CYG_HAL_SYS_SEEK_SET);
        cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, tmp, write_size);
        // Process next chunk
        buf += write_size;
        offset += write_size;
        len -= write_size;        
    }
    
    return FLASH_ERR_OK;
}
/*-------------------------------------------
| Name:dev_linux_leds_open
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
int dev_linux_leds_open(desc_t desc, int o_flag) {
   if(o_flag & O_WRONLY) {
      if(_linux_leds_desc_wr>=0) //already open
         return -1;
   }
   //
   leds_cmd.hdwr_id = LEDS;
   leds_cmd.cmd = OPS_OPEN;
   //
   //disable IT
   __clr_irq();
   while(cyg_hal_sys_write(1, (void *)&leds_cmd, sizeof(virtual_cmd_t)) !=sizeof(virtual_cmd_t)) ;
   while(cyg_hal_sys_read(0, (void *)&leds_cmd, sizeof(virtual_cmd_t)) !=sizeof(virtual_cmd_t)) ;
   //enable IT
   __set_irq();

   return 0;
}
/*-------------------------------------------
| Name:dev_linux_leds_close
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
int dev_linux_leds_close(desc_t desc) {
   if(ofile_lst[desc].oflag & O_WRONLY) {
      if(!ofile_lst[desc].nb_writer) {
         _linux_leds_desc_wr = -1;
         leds_cmd.hdwr_id = LEDS;
         leds_cmd.cmd = OPS_CLOSE;
         //
         //disable IT
         __clr_irq();
         while(cyg_hal_sys_write(1, (void *)&leds_cmd,
                                 sizeof(virtual_cmd_t)) !=sizeof(virtual_cmd_t)) ;
         while(cyg_hal_sys_read(0, (void *)&leds_cmd, sizeof(virtual_cmd_t)) !=sizeof(virtual_cmd_t)) ;
         //enable IT
         __set_irq();
      }
   }

   return 0;
}
/*-------------------------------------------
| Name:dev_linux_leds_write
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
int dev_linux_leds_write(desc_t desc, const char* buf,int size) {
   if(size>SHM_LEDS_MAX)
      size = SHM_LEDS_MAX;

   //copy data directly on shared memory
   memcpy(leds_0_data->data_out, buf, size);

   //send order to write data on hardware serial port
   leds_cmd.hdwr_id = LEDS;
   leds_cmd.cmd = OPS_WRITE;

   //disable IT
   __clr_irq();
   //
   while(cyg_hal_sys_write(1, (void *)&leds_cmd, sizeof(virtual_cmd_t)) !=sizeof(virtual_cmd_t)) ;
   while(cyg_hal_sys_read(0, (void *)&leds_cmd, sizeof(virtual_cmd_t)) !=sizeof(virtual_cmd_t)) ;

   //Enable all IT
   __set_irq();
   return size;
}
示例#7
0
static Cyg_ErrNo 
synth_disk_read(disk_channel *chan, 
                void         *buf,
                cyg_uint32    len,
                cyg_uint32    block_num)
{
    synth_disk_info_t *synth_info = (synth_disk_info_t *)chan->dev_priv;

#ifdef DEBUG
    diag_printf("synth disk read block %d\n", block_num);
#endif
    
    if (synth_info->filefd >= 0)
    {
        cyg_hal_sys_lseek(synth_info->filefd, 
                          block_num * chan->info->block_size,
                          CYG_HAL_SYS_SEEK_SET);
        cyg_hal_sys_read(synth_info->filefd, buf, len*512);
        return ENOERR;
    }
    return -EIO; 
}
//close virtual_cpu socket if nothing else to do
int dev_linux_eth_close(desc_t desc) {
   if(ofile_lst[desc].oflag & O_RDONLY) {
      if(!ofile_lst[desc].nb_reader) {
         _linux_eth_desc_rd = -1;
      }
   }
   //
   if(ofile_lst[desc].oflag & O_WRONLY) {
      if(!ofile_lst[desc].nb_writer) {
         _linux_eth_desc_wr = -1;
      }
   }
   //close all
   if(_linux_eth_desc_wr<0 && _linux_eth_desc_rd<0) {
      eth_cmd.hdwr_id = ETH_0;
      eth_cmd.cmd = OPS_CLOSE;
      //
      while(cyg_hal_sys_write(1, (void *)&eth_cmd, sizeof(virtual_cmd_t)) != sizeof(virtual_cmd_t)) ;
      while(cyg_hal_sys_read(0, (void *)&eth_cmd, sizeof(virtual_cmd_t)) != sizeof(virtual_cmd_t)) ;
   }
   return 0;
}
示例#9
0
int send_order_r(unsigned char s, u_int32 reg, u_int32 * val)
{
   ecos_virtual_order order;
   ecos_virtual_order *ptr_order;

   int bufsz = sizeof(ecos_virtual_order);
   int cb, w, r;

   memset((void *)&order, 0, sizeof(ecos_virtual_order));
   //remplit ordre
   order.sens = s;
   order.reg = 0L;
   order.reg = reg;
   order.value = *val;
   ptr_order = &order;
   //on s'assure d'envoyer tous les caracteres
   cb = 0;
   w = 0;
   while(bufsz - cb) {
      w=cyg_hal_sys_write(1,(void *)(ptr_order+cb),bufsz-cb);
      cb += w;
      if(w <= 0) {
         cb = 0;
         w = 0;
      }
   }
   //on s'assure d'avoir reçu tous les caractères
   cb = 0;
   r = 0;
   while(bufsz - cb) {
      r=cyg_hal_sys_read(0,(void *)(ptr_order+cb),bufsz-cb);
      cb += r;
      if(r <= 0) {
         cb = 0;
         r = 0;
      }
   }
   *val = ptr_order->value;
}