示例#1
0
void hal_diag_write_char(char c)
{
    static int  diag_index = 0;
    static unsigned char diag_buffer[128];

    CYG_ASSERT(diag_index < 128, "Diagnostic buffer overflow");
    
    diag_buffer[diag_index++] = (unsigned char) c;
    if (('\n' == c) || (128 == diag_index)) {
        if ((-1 != auxiliary_console_id) && synth_auxiliary_running) {
            synth_auxiliary_xchgmsg(auxiliary_console_id, 0, 0, 0, diag_buffer, diag_index, (int *) 0, (unsigned char*) 0, (int *)0, 0);
            diag_index = 0;
        } else {
            int     written;
            unsigned char* next    = diag_buffer;

            while (diag_index > 0) {
                written = cyg_hal_sys_write(1, next, diag_index);
                if (written > 0) {
                    diag_index -= written;
                    next       += written;
                } else if ((-CYG_HAL_SYS_EINTR != written) && (-CYG_HAL_SYS_EAGAIN != written)) {
                    CYG_FAIL("Unexpected error writing to stdout.");
                    diag_index = 0;
                    break;
                }
            }
            CYG_ASSERT(0 == diag_index, "All data should have been written out");
            diag_index = 0;
            cyg_hal_sys_fdatasync(1);
        }
    }
}
//send data to eth interface
int dev_linux_eth_write(desc_t desc, const char* buf,int size) {
   int rc;

   if(size>=ETH_0_OUTPUT_BUFFER_SZ)
      size = ETH_0_OUTPUT_BUFFER_SZ-1;

   eth_0_data->size_out = size;
   memcpy(eth_0_data->data_out, buf, eth_0_data->size_out);
   //
   _linux_eth_output_r = 0;
   _linux_eth_output_w = size;

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

   //disable IT
   //__clr_irq();
   //write to wake virtual_cpu
   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 all IT
   //__set_irq();
   return size;

}
//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;
}
示例#4
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;
}
示例#5
0
externC cyg_bool synth_disk_change( int unit, char *filename, int size,
                                    int cyls, int heads, int sectors)
{
    struct cyg_devtab_entry  *tab        = &synth_disk_io0;
    disk_channel             *chan       = (disk_channel *) tab->priv;
    synth_disk_info_t        *synth_info = (synth_disk_info_t *) chan->dev_priv;
    int err = 0;
    
    if (!chan->init) 
        return false;

    synth_info->filename = filename;
    synth_info->size = size;
    synth_info->cylinders_num = cyls;
    synth_info->heads_num = heads;
    synth_info->sectors_num = sectors;
    
#ifdef DEBUG
    diag_printf("synth disk %d change size=%d\n", 
                synth_info->num, synth_info->size);
#endif

    err = cyg_hal_sys_close( synth_info->filefd );

#ifdef DEBUG
    if( err != 0 )
    {
        diag_printf("synth disk change, failed to close old image: %d\n",err);
    }
#endif
    
    synth_info->filefd = cyg_hal_sys_open(synth_info->filename, 
            CYG_HAL_SYS_O_RDWR,
            CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);

    if (-ENOENT == synth_info->filefd)
    {
        synth_info->filefd = cyg_hal_sys_open(synth_info->filename, 
            CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT, 0644);
        
        if (synth_info->filefd >= 0)
        {
            unsigned char b = 0x00;
            int i;
        
            for (i = 0; i < synth_info->size; i++)
                cyg_hal_sys_write(synth_info->filefd, &b, 1);    
        }
    }

    if (synth_info->filefd < 0)
    {
        CYG_ASSERT(false, "Can't open/create disk image file");
        return false;
    }

    return true;
}
示例#6
0
int
flash_program_buf(volatile flash_t *addr, flash_t *data, int len,
                  unsigned long block_mask, int buffer_size)
{
  
    int offset = (int)addr;
    offset -= (int)cyg_dev_flash_synth_base;

    cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset, CYG_HAL_SYS_SEEK_SET);
    cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, data, len);
  
    return FLASH_ERR_OK;
}
示例#7
0
static cyg_bool 
synth_disk_init(struct cyg_devtab_entry *tab)
{
    disk_channel      *chan       = (disk_channel *) tab->priv;
    synth_disk_info_t *synth_info = (synth_disk_info_t *) chan->dev_priv;
    bool result = true;

    if (chan->init) 
        return true;

#ifdef DEBUG
    diag_printf("synth disk %d init size=%d\n", 
                synth_info->num, synth_info->size);
#endif
   
    synth_info->filefd = cyg_hal_sys_open(synth_info->filename, 
            CYG_HAL_SYS_O_RDWR,
            CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);

    if (-ENOENT == synth_info->filefd)
    {
        synth_info->filefd = cyg_hal_sys_open(synth_info->filename, 
            CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT, 0644);
        
        if (synth_info->filefd >= 0)
        {
            unsigned char b = 0x00;
            int i;
        
            for (i = 0; i < synth_info->size; i++)
                cyg_hal_sys_write(synth_info->filefd, &b, 1);    
        }
    }

    if (synth_info->filefd < 0)
    {
        CYG_ASSERT(false, "Can't open/create disk image file");
        return false;
    }
   
    if (result)
    {
 
        if (!(chan->callbacks->disk_init)(tab))
            return false;
    }
    return result;
}
/*-------------------------------------------
| 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;
}
示例#10
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;
}
示例#11
0
//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;
}
示例#12
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;
}
示例#13
0
static Cyg_ErrNo 
synth_disk_write(disk_channel *chan,
                 const 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 write 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_write(synth_info->filefd, buf, len*512);
//        cyg_hal_sys_fdatasync(synth_info->filefd);
        return ENOERR;
    }
    return -EIO; 
}
示例#14
0
int flash_erase_block(volatile flash_t *block, unsigned int block_size)
{
    int i;
    int offset = (int)block;
    offset -= (int)cyg_dev_flash_synth_base;

    cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
                      CYG_HAL_SYS_SEEK_SET);
  
    if (!empty_inited) {
        memset(empty, 0xff, sizeof(empty));
        empty_inited = true;
    }

    CYG_ASSERT(sizeof(empty) < block_size,
               "Eckk! Can't work with such small blocks");
    CYG_ASSERT((block_size % sizeof(empty)) == 0,
               "Eckk! Can't work with that odd size block");

    for (i=0; (i * sizeof(empty)) < block_size; i++) {
        cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, empty, sizeof(empty));
    }
    return FLASH_ERR_OK;
}