<commit_before>/* Copyright (c) 2014 Quanta Research Cambridge, Inc
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "StdDmaIndication.h"
#include "MMURequest.h"
#include "Ov7670ControllerRequest.h"
#include "Ov7670ControllerIndication.h"
#include "pthread.h"

int slaveaddr[3];
int addr;

int rdClock[64];
int rdData[64];
int rdOutEn[64];
volatile int rdSample[64];
volatile int cursor = 0;
volatile int phase = 0;
sem_t bit_sem;

class Ov7670ControllerIndication : public Ov7670ControllerIndicationWrapper {
  int datacount;
  int gapcount;
public:
  Ov7670ControllerIndication(unsigned int id) : Ov7670ControllerIndicationWrapper(id), datacount(0), gapcount(0) {}
  ~Ov7670ControllerIndication() {}
  virtual void i2cResponse(uint8_t bus, uint8_t data) {
    fprintf(stderr, "i2c bus %d device %d addr %x response %02x\n", bus, slaveaddr[bus], addr, data);
    sem_post(&bit_sem);
  }
  virtual void vsync(uint32_t cycles, uint8_t href) {
    //fprintf(stderr, "vsync %8d href %d\n", cycles, href);
    if (datacount) {
      fprintf(stderr, "vsync datacount=%8d gapcount=%8d\n", datacount, gapcount);
      datacount = 0;
      gapcount = 0;
    }
  }
  virtual void data(uint8_t first, uint8_t gap, uint8_t data) {
    //if (gap) fprintf(stderr, "data %8x first %d gap %d\n", data, first, gap);
    datacount++;
    if (gap) gapcount++;
  }
  virtual void frameStarted(uint8_t first) {
    //if (first) fprintf(stderr, "frameStarted %d\n", first);
  }
  virtual void frameTransferred() {
    //fprintf(stderr, "frameTransferred\n");
  }
  virtual void data4(uint32_t data) {
  }
};

void enqueueStart()
{
  rdClock[cursor] = 0b110;
  rdData[cursor] = 0b100;
  rdOutEn[cursor] = 0b111;
  cursor++;
}
void enqueueStop()
{
  rdClock[cursor] = 0b001;
  rdData[cursor] = 0b011;
  rdOutEn[cursor] = 0b111;
  cursor++;
}
void enqueueIdle()
{
  rdClock[cursor] = 0b111;
  rdData[cursor] = 0b111;
  rdOutEn[cursor] = 0b111;
  cursor++;
}
void enqueueBitOut(int b)
{
    rdClock[cursor] = 0b010;
    rdData[cursor] = b ? 0b111 : 0b000;
    rdOutEn[cursor] = 0b111;
    cursor++;
}
void enqueueBitIn()
{
    rdClock[cursor] = 0b010;
    rdData[cursor] = 0;
    rdOutEn[cursor] = 0b000;
    cursor++;
}
void enqueueAck()
{
    rdClock[cursor] = 0b010;
    rdData[cursor] = 0;
    rdOutEn[cursor] = 0b000;
    cursor++;
}
void enqueueMAck()
{
    rdClock[cursor] = 0b010;
    rdData[cursor] = 0b111;
    rdOutEn[cursor] = 0b111;
    cursor++;
}

int bit(int v, int pos)
{
  return (v >> pos) & 1;
}

int main(int argc, const char **argv)
{
  Ov7670ControllerRequestProxy device(IfcNames_Ov7670ControllerRequestS2H);
  Ov7670ControllerIndication deviceResponse(IfcNames_Ov7670ControllerIndicationH2S);
  MMURequestProxy *mmuRequest = new MMURequestProxy(IfcNames_MMURequestS2H);
  DmaManager *dma = new DmaManager(mmuRequest);
  MemServerRequestProxy *memServerRequest = new MemServerRequestProxy(IfcNames_MemServerRequestS2H);
  MemServerIndication *memServerIndication = new MemServerIndication(memServerRequest, IfcNames_MemServerIndicationH2S);
  MMUIndication mmuIndication(dma, IfcNames_MMUIndicationH2S);

  int len = 640*480*4;
  int nfbAlloc = portalAlloc(4096, 0);
  unsigned int *nfbBuffer = (unsigned int *)portalMmap(nfbAlloc, 4096);
  unsigned int ref_nfbAlloc = dma->reference(nfbAlloc);
  int fbAlloc = portalAlloc(len, 0);
  unsigned int *fbBuffer = (unsigned int *)portalMmap(fbAlloc, len);
  unsigned int ref_fbAlloc = dma->reference(fbAlloc);

  sem_init(&bit_sem, 0, 0);

  device.setPowerDown(0);
  device.setReset(0);
  sleep(1);
  device.setReset(1);
  sleep(1);
  fprintf(stderr, "ref_fbAlloc=%d\n", ref_fbAlloc);<commit_msg>remove more bit-banging code<commit_after>/* Copyright (c) 2014 Quanta Research Cambridge, Inc
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "StdDmaIndication.h"
#include "MMURequest.h"
#include "Ov7670ControllerRequest.h"
#include "Ov7670ControllerIndication.h"
#include "pthread.h"

int slaveaddr[3];
int addr;

sem_t bit_sem;

class Ov7670ControllerIndication : public Ov7670ControllerIndicationWrapper {
  int datacount;
  int gapcount;
public:
  Ov7670ControllerIndication(unsigned int id) : Ov7670ControllerIndicationWrapper(id), datacount(0), gapcount(0) {}
  ~Ov7670ControllerIndication() {}
  virtual void i2cResponse(uint8_t bus, uint8_t data) {
    fprintf(stderr, "i2c bus %d device %d addr %x response %02x\n", bus, slaveaddr[bus], addr, data);
    sem_post(&bit_sem);
  }
  virtual void vsync(uint32_t cycles, uint8_t href) {
    //fprintf(stderr, "vsync %8d href %d\n", cycles, href);
    if (datacount) {
      fprintf(stderr, "vsync datacount=%8d gapcount=%8d\n", datacount, gapcount);
      datacount = 0;
      gapcount = 0;
    }
  }
  virtual void data(uint8_t first, uint8_t gap, uint8_t data) {
    //if (gap) fprintf(stderr, "data %8x first %d gap %d\n", data, first, gap);
    datacount++;
    if (gap) gapcount++;
  }
  virtual void frameStarted(uint8_t first) {
    //if (first) fprintf(stderr, "frameStarted %d\n", first);
  }
  virtual void frameTransferred() {
    //fprintf(stderr, "frameTransferred\n");
  }
  virtual void data4(uint32_t data) {
  }
};

int main(int argc, const char **argv)
{
  Ov7670ControllerRequestProxy device(IfcNames_Ov7670ControllerRequestS2H);
  Ov7670ControllerIndication deviceResponse(IfcNames_Ov7670ControllerIndicationH2S);
  MMURequestProxy *mmuRequest = new MMURequestProxy(IfcNames_MMURequestS2H);
  DmaManager *dma = new DmaManager(mmuRequest);
  MemServerRequestProxy *memServerRequest = new MemServerRequestProxy(IfcNames_MemServerRequestS2H);
  MemServerIndication *memServerIndication = new MemServerIndication(memServerRequest, IfcNames_MemServerIndicationH2S);
  MMUIndication mmuIndication(dma, IfcNames_MMUIndicationH2S);

  int len = 640*480*4;
  int nfbAlloc = portalAlloc(4096, 0);
  unsigned int *nfbBuffer = (unsigned int *)portalMmap(nfbAlloc, 4096);
  unsigned int ref_nfbAlloc = dma->reference(nfbAlloc);
  int fbAlloc = portalAlloc(len, 0);
  unsigned int *fbBuffer = (unsigned int *)portalMmap(fbAlloc, len);
  unsigned int ref_fbAlloc = dma->reference(fbAlloc);

  sem_init(&bit_sem, 0, 0);

  device.setPowerDown(0);
  device.setReset(0);
  sleep(1);
  device.setReset(1);
  sleep(1);
  fprintf(stderr, "ref_fbAlloc=%d\n", ref_fbAlloc);
{'fraction_non_alphanumeric': 0.1048280819456092, 'fraction_numerical': 0.03582125314484246, 'mean_word_length': 4.773167358229599, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6579502', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2766, 'n_words': 824}