<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 <stdio.h>
//#include <sys/mman.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdarg.h>
//#include <unistd.h>
//#include <stdint.h>
//#include <fcntl.h>
//#include <pthread.h>
//#include <semaphore.h>
#include "i2chdmi.h"
#include "i2ccamera.h"

#include "ImageonSensorRequestProxy.h"
#include "ImageonSensorIndicationWrapper.h"
#include "ImageonSerdesRequestProxy.h"
#include "ImageonSerdesIndicationWrapper.h"
#include "HdmiInternalRequestProxy.h"
#include "HdmiInternalIndicationWrapper.h"
#include "GeneratedTypes.h"

static ImageonSensorRequestProxy *sensordevice;
static ImageonSerdesRequestProxy *serdesdevice;
static HdmiInternalRequestProxy *hdmidevice;
static int trace_spi = 0;

#define DECL(A) \
    static sem_t sem_ ## A; \
    static uint32_t cv_ ## A;

DECL(iserdes_control)
DECL(spi_response)

#define GETFN(A) \
    static uint32_t read_ ## A (void) \
    { \
        serdesdevice->get_ ## A(); \
        sem_wait(&sem_ ## A); \
        return cv_ ## A; \
    }

class ImageonSerdesIndication : public ImageonSerdesIndicationWrapper {
public:
    ImageonSerdesIndication(int id, PortalPoller *poller = 0) : ImageonSerdesIndicationWrapper(id, poller) {}
    virtual void iserdes_control_value ( uint32_t v ){
        cv_iserdes_control = v;
        sem_post(&sem_iserdes_control);
    }
};

class ImageonSensorIndication : public ImageonSensorIndicationWrapper {
public:
    ImageonSensorIndication(int id, PortalPoller *poller = 0) : ImageonSensorIndicationWrapper(id, poller) {}
    void spi_response(uint32_t v){
        //fprintf(stderr, "spi_response: %x\n", v);
        cv_spi_response = v;
        sem_post(&sem_spi_response);
    }
};

class HdmiInternalIndication: public HdmiInternalIndicationWrapper {
    HdmiInternalRequestProxy *hdmiRequest;
public:
    HdmiInternalIndication(int id, HdmiInternalRequestProxy *proxy, PortalPoller *poller = 0) : HdmiInternalIndicationWrapper(id, poller), hdmiRequest(proxy) {}
    virtual void vsync ( const uint64_t v ) {
        printf("vsync v=%llx\n", v);
        hdmiRequest->waitForVsync(v+1);
    }
};

static void init_local_semaphores(void)
{
    sem_init(&sem_iserdes_control, 0, 0);
    sem_init(&sem_spi_response, 0, 0);
}
GETFN(iserdes_control)

//#define VITA_ISERDES_CONTROL_REG     0x10
   #define VITA_ISERDES_RESET_BIT       0x01
   #define VITA_ISERDES_AUTO_ALIGN_BIT  0x02
   #define VITA_ISERDES_ALIGN_START_BIT 0x04
   #define VITA_ISERDES_FIFO_ENABLE_BIT 0x08
//#define VITA_DECODER_CONTROL_REG           0x20
   #define VITA_DECODER_RESET_BIT            0x01
   #define VITA_DECODER_ENABLE_BIT           0x02

#define VITA_SPI_SEQ1_QTY  8
/* Table 6. enable clock management register upload - part 1 */
static uint16_t vita_spi_seq1[VITA_SPI_SEQ1_QTY][3] = {
   // Enable Clock Management - Part 1
   //    V1/SN/SE 10-bit mode with PLL
   {  2, 0xFFFF,      0}, // Monochrome Sensor
// {  2, 0xFFFF, 0x0001}, // Color Sensor
   { 32, 0xFFFF, 0x2004}, // Configure clock management
   { 20, 0xFFFF,      0}, // Configure clock management
   { 17, 0xFFFF, 0x2113}, // Configure PLL<commit_msg>update the vsync indication handler<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 <stdio.h>
//#include <sys/mman.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdarg.h>
//#include <unistd.h>
//#include <stdint.h>
//#include <fcntl.h>
//#include <pthread.h>
//#include <semaphore.h>
#include "i2chdmi.h"
#include "i2ccamera.h"

#include "ImageonSensorRequestProxy.h"
#include "ImageonSensorIndicationWrapper.h"
#include "ImageonSerdesRequestProxy.h"
#include "ImageonSerdesIndicationWrapper.h"
#include "HdmiInternalRequestProxy.h"
#include "HdmiInternalIndicationWrapper.h"
#include "GeneratedTypes.h"

static ImageonSensorRequestProxy *sensordevice;
static ImageonSerdesRequestProxy *serdesdevice;
static HdmiInternalRequestProxy *hdmidevice;
static int trace_spi = 0;

#define DECL(A) \
    static sem_t sem_ ## A; \
    static uint32_t cv_ ## A;

DECL(iserdes_control)
DECL(spi_response)

#define GETFN(A) \
    static uint32_t read_ ## A (void) \
    { \
        serdesdevice->get_ ## A(); \
        sem_wait(&sem_ ## A); \
        return cv_ ## A; \
    }

class ImageonSerdesIndication : public ImageonSerdesIndicationWrapper {
public:
    ImageonSerdesIndication(int id, PortalPoller *poller = 0) : ImageonSerdesIndicationWrapper(id, poller) {}
    virtual void iserdes_control_value ( uint32_t v ){
        cv_iserdes_control = v;
        sem_post(&sem_iserdes_control);
    }
};

class ImageonSensorIndication : public ImageonSensorIndicationWrapper {
public:
    ImageonSensorIndication(int id, PortalPoller *poller = 0) : ImageonSensorIndicationWrapper(id, poller) {}
    void spi_response(uint32_t v){
        //fprintf(stderr, "spi_response: %x\n", v);
        cv_spi_response = v;
        sem_post(&sem_spi_response);
    }
};

class HdmiInternalIndication: public HdmiInternalIndicationWrapper {
    HdmiInternalRequestProxy *hdmiRequest;
public:
    HdmiInternalIndication(int id, HdmiInternalRequestProxy *proxy, PortalPoller *poller = 0) : HdmiInternalIndicationWrapper(id, poller), hdmiRequest(proxy) {}
    virtual void vsync ( uint64_t v, uint32_t w ) {
        fprintf(stderr, "[%s:%d] v=%d w=%d\n", __FUNCTION__, __LINE__, (uint32_t) v, w);
        hdmiRequest->waitForVsync(v+1);
    }

};

static void init_local_semaphores(void)
{
    sem_init(&sem_iserdes_control, 0, 0);
    sem_init(&sem_spi_response, 0, 0);
}
GETFN(iserdes_control)

//#define VITA_ISERDES_CONTROL_REG     0x10
   #define VITA_ISERDES_RESET_BIT       0x01
   #define VITA_ISERDES_AUTO_ALIGN_BIT  0x02
   #define VITA_ISERDES_ALIGN_START_BIT 0x04
   #define VITA_ISERDES_FIFO_ENABLE_BIT 0x08
//#define VITA_DECODER_CONTROL_REG           0x20
   #define VITA_DECODER_RESET_BIT            0x01
   #define VITA_DECODER_ENABLE_BIT           0x02

#define VITA_SPI_SEQ1_QTY  8
/* Table 6. enable clock management register upload - part 1 */
static uint16_t vita_spi_seq1[VITA_SPI_SEQ1_QTY][3] = {
   // Enable Clock Management - Part 1
   //    V1/SN/SE 10-bit mode with PLL
   {  2, 0xFFFF,      0}, // Monochrome Sensor
// {  2, 0xFFFF, 0x0001}, // Color Sensor
   { 32, 0xFFFF, 0x2004}, // Configure clock management
   { 20, 0xFFFF,      0}, // Configure clock management
   { 17, 0xFFFF, 0x2113}, // Configure PLL
{'fraction_non_alphanumeric': 0.09579303111525463, 'fraction_numerical': 0.021908868430252883, 'mean_word_length': 4.045267489711934, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, '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': '655373', 'n_tokens_mistral': 2988, 'n_tokens_neox': 2814, 'n_words': 814}