view ppe/Sys.cc @ 3:8b4d6bf8c43d

add entry_head function
author yutaka@localhost.localdomain
date Wed, 07 Apr 2010 17:35:34 +0900
parents 1e1b0d280427
children ec2c1003f9b6
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include "Sys.h"

task_t*
entry_head(task_head_t *head)
{

  head->ea_out   = 0;
  head->size_in  = 0;
  head->size_out = 0;
  head->pin_in   = 0;
  head->pin_out  = 0;

  task_t *tail = (task_t*)allocate(sizeof(task_t));
  tail->head = head;
  tail->input = NULL;

  return tail;
  
}

task_t*
add_list(task_t *tail, task_t *task)
{

  tail->head->next_task = (unsigned long long) (unsigned long) task->head;
  tail->head->next_task_size = task->head->size_in + sizeof(task_head_t);

  task->head->next_task = 0;
  task->head->next_task_size = 0;

  return task;

}

void
set_pin(task_t *task, int pin_in, int pin_out)
{

  task->head->pin_in = pin_in;
  task->head->pin_out = pin_out;

}

int
size_fix(int size, int fix)
{

  //16の倍数にする
  size = ((size + fix -1) / fix)*fix;
  
  return size;

}

void*
allocate(int size)
{

  int alignment = 16;
  size = size_fix(size, alignment);

  void *buff;
  posix_memalign(&buff, alignment, size);
  return buff;

}

void
fix_type(task_t *task, void *buff)
{

  char *p;
  p = (char*)buff;
  p = p + sizeof(task_head_t);

  task->head = (task_head_t*)buff;
  task->input = p;

}

task_t*
task_allocate(int in_size, int out_size)
{

  if (in_size % 16) {
    printf("allocate in_size is not multiple of 16\n");
  }

  if (out_size % 16) {
    printf("allocate out_size is not multiple of 16\n");
  }

  int alignment = 16;
  task_t *task = (task_t*)allocate(sizeof(task_t));

  void *buff;
  void *out;

  int task_size = in_size + sizeof(task_head_t);

  if (task_size > MAX_DMA_SIZE) {
    printf("dma send size over %d\n",task_size); 
  }

  posix_memalign(&buff, alignment, task_size);
  fix_type(task, buff);

  posix_memalign(&out, alignment, out_size);
  task->head->ea_out = (unsigned long long) (unsigned long) out;

  task->head->size_in  = in_size;
  task->head->size_out = out_size;

  return task;

}