void Producer(int bufSize, int itemCnt, int randSeed) { srand(randSeed); // Write code here to produce itemCnt integer values in the range [0-100] // Use the functions provided below to get/set the values of shared variables "in" and "out" // Use the provided function WriteAtBufIndex() to write into the bounded buffer // Use the provided function GetRand() to generate a random number in the specified range // **Extremely Important: Remember to set the value of any shared variable you change locally // Use the following print statement to report the production of an item: // printf("Producing Item %d with value %d at Index %d\n", i, val, in); // where i is the item number, val is the item value, in is its index in the bounded buffer int i; for(i=0;i < GetItemCnt(); i++){ while(((GetIn()+1) % GetBufSize())==GetOut()) ; int rando = GetRand(0,100); WriteAtBufIndex(GetIn(),rando); printf("Producing Item %d with value %d at Index %d\n", i+1, rando, GetIn()); SetIn((GetIn()+1) % GetBufSize()); } printf("Producer Completed\n"); }
CSWH264NetRenderFilter::CSWH264NetRenderFilter() :CSWNetRenderFilter(3, 0) ,m_fInited(FALSE) { GetIn(0)->AddObject(CLASSID(CSWImage)); GetIn(1)->AddObject(CLASSID(CSWImage)); GetIn(2)->AddObject(CLASSID(CSWImage)); }
int main() { const char *name = "OS_HW1"; // Name of shared memory object to be passed to shm_open int bufSize; // Bounded buffer size int itemCnt; // Number of items to be consumed int shm_fd; // Shared Memory File Descriptor // Write code here to create a shared memory block and map it to gShmPtr // Use the above name // **Extremely Important: map the shared memory block for both reading and writing // Use PROT_READ | PROT_WRITE shm_fd = shm_open(name, O_RDWR , 0666); gShmPtr = mmap(0,SHM_SIZE,PROT_READ | PROT_WRITE,MAP_SHARED,shm_fd,0); // Write code here to read the four integers from the header of the shared memory block // These are: bufSize, itemCnt, in, out // Just call the functions provided below like this: bufSize = GetBufSize(); itemCnt = GetItemCnt(); // Write code here to check that the consumer has read the right values: printf("Consumer reading: bufSize = %d\n",bufSize); printf("Consumer reading: itemCnt = %d\n",itemCnt); printf("Consumer reading: in = %d\n",GetIn()); printf("Consumer reading: out = %d\n",GetOut()); // Write code here to consume all the items produced by the producer // Use the functions provided below to get/set the values of shared variables in, out, bufSize // Use the provided function ReadAtBufIndex() to read from the bounded buffer // **Extremely Important: Remember to set the value of any shared variable you change locally // Use the following print statement to report the consumption of an item: // printf("Consuming Item %d with value %d at Index %d\n", i, val, out); // where i is the item number, val is the item value, out is its index in the bounded buffer int i; for(i=0;i < GetItemCnt(); i++){ while(GetIn() == GetOut()) ; printf("Consuming Item %d with value %d at Index %d\n", i+1, ReadAtBufIndex(GetOut()), GetOut()); //i+1 to show human readable count SetOut((GetOut()+1) % GetBufSize()); } // remove the shared memory segment if (shm_unlink(name) == -1) { printf("Error removing %s\n",name); exit(-1); } return 0; }
CSWGBH264TransformFilter::CSWGBH264TransformFilter() :CSWBaseFilter(2, 0) ,CSWMessage(MSG_GB28181_FILTER_BEGIN, MSG_GB28181_FILTER_END) ,m_fInited(FALSE) ,m_dwQueueSize(25) ,m_nH264FramRate(25) ,m_pTransformClient(NULL) ,m_fCurrentSpeed(1.0) ,m_fIsHistoryVideo(FALSE) ,m_fIsPause(FALSE) ,m_fBackward(FALSE) ,m_fNeedReadNextSecond(FALSE) { GetIn(0)->AddObject(CLASSID(CSWImage)); GetIn(1)->AddObject(CLASSID(CSWImage)); }
// 閉じる void Close(void){ if (State != FSTATE_Config){ // パイプを開いたはずなのにいつの間にかコンフィギュレーションが中断させられてた }else{ // こちらが正常 if (SPI::Open() == false) return portENTER_CRITICAL(); if (GetIn(PIN_FPGA_DONE) == IN_LOW){ // コンフィギュレーションが完了していない Reset(); xputs("Conf:unfinished\n"); }else{ // コンフィギュレーションが完了した State = FSTATE_Running; //SetDir(PIN_FPGA_AUX0, DIR_OUT); // M0ピンはもう駆動してよい //SetDir(PIN_FPGA_AUX1, DIR_OUT); // MOSIピンはもう駆動してよい xputs("Conf:finished\n"); } SPI::Close(); portEXIT_CRITICAL(); } }
// 書き込み bool Write(const void *data, unsigned int len, unsigned int &written){ // ポインタとサイズの確認 if (State != FSTATE_Config) return false; written = len; //xprintf("Conf:write(%d)\n", len); if (GetIn(PIN_FPGA_DONE) == IN_LOW){ // コンフィギュレーションはまだ終わってない // 送信 if (SPI::Open() == false) return false; SetOut(PIN_FPGA_CONF, OUT_HIGH); Barrier(); if (len & 1){ // 奇数 SPI::SetMode(SPI::MODE_8BIT); SPI::SetupTxDMA(data, len); }else{ // 偶数 SPI::SetMode(SPI::MODE_16BIT); SPI::SetupTxDMA(data, len / 2); } SPI::StartDMA(); SPI::WaitTxDMA(); SPI::StopDMA(); Barrier(); SetOut(PIN_FPGA_CONF, OUT_LOW); SPI::Close(); } return true; }
// メインスレッド extern "C" int main(void){ clDigitalIO<PIN_LED1> PinLED1; /* OSリソースの作成を伴うデバイスインスタンスの初期化を行う */ // カメラの初期化 Camera.Init(CAMERA_IRQ_PRIORITY); // UART0の初期化 Uart0.Init(HOSTIF_BAUDRATE, HOSTIF_IRQ_PRIORITY); // USBの初期化 USBSerial.Init(USB_IRQ_PRIORITY); //osThreadSetPriority(osThreadGetId(), osPriorityRealtime); /* スレッドを起動 */ osThreadDef(CameraThread, osPriorityHigh, 1, 0); osThreadCreate(osThread(CameraThread), nullptr); //udd_enable(); // テストメッセージ出力 Uart0.printf("usb test\n"); //USBSerial.printf("usb test\n"); // USBを有効化 USBSerial.Enable(true); while(true){ USBSerial.PollVBUS(GetIn(PIN_USB_VBUS)); PinLED1.SetOut(true); osDelay(50); PinLED1.SetOut(false); osDelay(50); /*int c; while((c = Uart0.getc()) != iSerial::EOF){ Uart0.putc(c); USBSerial.putc(c); }*/ /*while((c = USBSerial.getc()) != iSerial::EOF){ Uart0.putc(c); USBSerial.putc(c); }*/ } return 0; }
CSWAutoControlRenderFilter::CSWAutoControlRenderFilter() :CSWBaseFilter(2,0) ,CSWMessage(MSG_AUTO_CONTROL_START, MSG_AUTO_CONTROL_END) { GetIn(0)->AddObject(CLASSID(CSWCameraDataPDU)); GetIn(1)->AddObject(CLASSID(CSWImage)); m_fEnable = FALSE; m_fEnableAGC = FALSE; m_iMinPSD = 100; m_iMaxPSD = 20000; m_iLightType = 0; m_iCplStatus = 0; m_iPluseLevel = 0; swpa_memset(m_irgAGCLimit, 0, sizeof(m_irgAGCLimit)/sizeof(m_irgAGCLimit[0])); swpa_memset(m_irgExposureTime, 0, sizeof(m_irgExposureTime)/sizeof(m_irgExposureTime[0])); swpa_memset(m_irgGain, 0, sizeof(m_irgGain)/sizeof(m_irgGain[0])); m_fEnableAutoCapture = FALSE; m_iDayShutterMax = 3800; m_iDayGainMax = 120; m_iNightShutterMax = 1500; m_iNightGainMax = 60; m_iGainMin = 10; m_iShutterMin = 200; // 默认为白天 m_iIsDayCount = 120; m_iIsDuskCount = 120; m_fIsDay = FALSE; m_fIsDayEx = FALSE; m_iEnvType = 1; m_iCaptureShutter = 300; m_iCaptureGain = 60; m_iCaptureImageCount = 0; m_iTotalAvgY = 0; m_fNeedUpdateCaptureParam = FALSE; m_fIsInit = FALSE; m_fForceChange = FALSE; m_iEnableCpl = 0; m_iGammaMode = 2; m_nNightShutter = 50000; m_nNightThreshold = 0; m_nDuskThreshold = 0; m_nAvgPlateY = 0; m_nMinPlateY = 80; m_nMaxPlateY = 120; m_nWDRLevel = 0; m_fUseMaxAgcShutter = FALSE; m_iAGCDayNightShutterControl = 0; m_iAGCDayShutterHOri = 3800; m_iAGCNightShutterHOri = 1500; m_iAGCNightGainHOri = 60; m_iAGCGainHOri=120; m_iTempCaptureGain=60; m_iTempCaptureShutter=1500; m_dwAvgY=0; }