mirror of
https://github.com/supleed2/ELEC50003-P1-CW.git
synced 2024-12-22 21:45:49 +00:00
Add nonblock flag to UART FILE*
This commit is contained in:
parent
7ab9de2cc7
commit
108f4d1495
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "I2C_core.h"
|
#include "I2C_core.h"
|
||||||
#include "terasic_includes.h"
|
#include "terasic_includes.h"
|
||||||
|
@ -39,7 +37,8 @@
|
||||||
#define MIPI_REG_FrmErrCnt 0x0080
|
#define MIPI_REG_FrmErrCnt 0x0080
|
||||||
#define MIPI_REG_MDLErrCnt 0x0090
|
#define MIPI_REG_MDLErrCnt 0x0090
|
||||||
|
|
||||||
void mipi_clear_error(void){
|
void mipi_clear_error(void)
|
||||||
|
{
|
||||||
MipiBridgeRegWrite(MIPI_REG_CSIStatus, 0x01FF); // clear error
|
MipiBridgeRegWrite(MIPI_REG_CSIStatus, 0x01FF); // clear error
|
||||||
MipiBridgeRegWrite(MIPI_REG_MDLSynErr, 0x0000); // clear error
|
MipiBridgeRegWrite(MIPI_REG_MDLSynErr, 0x0000); // clear error
|
||||||
MipiBridgeRegWrite(MIPI_REG_FrmErrCnt, 0x0000); // clear error
|
MipiBridgeRegWrite(MIPI_REG_FrmErrCnt, 0x0000); // clear error
|
||||||
|
@ -55,7 +54,8 @@ void mipi_clear_error(void){
|
||||||
MipiBridgeRegWrite(0x0090, 0x00);
|
MipiBridgeRegWrite(0x0090, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mipi_show_error_info(void){
|
void mipi_show_error_info(void)
|
||||||
|
{
|
||||||
|
|
||||||
alt_u16 PHY_status, SCI_status, MDLSynErr, FrmErrCnt, MDLErrCnt;
|
alt_u16 PHY_status, SCI_status, MDLSynErr, FrmErrCnt, MDLErrCnt;
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@ void mipi_show_error_info(void){
|
||||||
printf("PHY_status=%xh, CSI_status=%xh, MDLSynErr=%xh, FrmErrCnt=%xh, MDLErrCnt=%xh\r\n", PHY_status, SCI_status, MDLSynErr, FrmErrCnt, MDLErrCnt);
|
printf("PHY_status=%xh, CSI_status=%xh, MDLSynErr=%xh, FrmErrCnt=%xh, MDLErrCnt=%xh\r\n", PHY_status, SCI_status, MDLSynErr, FrmErrCnt, MDLErrCnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mipi_show_error_info_more(void){
|
void mipi_show_error_info_more(void)
|
||||||
|
{
|
||||||
printf("FrmErrCnt = %d\n", MipiBridgeRegRead(0x0080));
|
printf("FrmErrCnt = %d\n", MipiBridgeRegRead(0x0080));
|
||||||
printf("CRCErrCnt = %d\n", MipiBridgeRegRead(0x0082));
|
printf("CRCErrCnt = %d\n", MipiBridgeRegRead(0x0082));
|
||||||
printf("CorErrCnt = %d\n", MipiBridgeRegRead(0x0084));
|
printf("CorErrCnt = %d\n", MipiBridgeRegRead(0x0084));
|
||||||
|
@ -82,46 +83,31 @@ void mipi_show_error_info_more(void){
|
||||||
printf("CSIPktLen = %d\n", MipiBridgeRegRead(0x006E));
|
printf("CSIPktLen = %d\n", MipiBridgeRegRead(0x006E));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MIPI_Init(void)
|
||||||
|
{
|
||||||
bool MIPI_Init(void){
|
|
||||||
bool bSuccess;
|
bool bSuccess;
|
||||||
|
|
||||||
|
|
||||||
bSuccess = oc_i2c_init_ex(I2C_OPENCORES_MIPI_BASE, 50 * 1000 * 1000, 400 * 1000); //I2C: 400K
|
bSuccess = oc_i2c_init_ex(I2C_OPENCORES_MIPI_BASE, 50 * 1000 * 1000, 400 * 1000); //I2C: 400K
|
||||||
if (!bSuccess)
|
if (!bSuccess)
|
||||||
|
{
|
||||||
printf("failed to init MIPI- Bridge i2c\r\n");
|
printf("failed to init MIPI- Bridge i2c\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
usleep(50 * 1000);
|
usleep(50 * 1000);
|
||||||
MipiBridgeInit();
|
MipiBridgeInit();
|
||||||
|
|
||||||
usleep(500 * 1000);
|
usleep(500 * 1000);
|
||||||
|
|
||||||
// bSuccess = oc_i2c_init_ex(I2C_OPENCORES_CAMERA_BASE, 50*1000*1000,400*1000); //I2C: 400K
|
|
||||||
// if (!bSuccess)
|
|
||||||
// printf("failed to init MIPI- Camera i2c\r\n");
|
|
||||||
|
|
||||||
MipiCameraInit();
|
MipiCameraInit();
|
||||||
MIPI_BIN_LEVEL(DEFAULT_LEVEL);
|
MIPI_BIN_LEVEL(DEFAULT_LEVEL);
|
||||||
// OV8865_FOCUS_Move_to(340);
|
|
||||||
|
|
||||||
// oc_i2c_uninit(I2C_OPENCORES_CAMERA_BASE); // Release I2C bus , due to two I2C master shared!
|
|
||||||
|
|
||||||
|
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|
||||||
|
|
||||||
// oc_i2c_uninit(I2C_OPENCORES_MIPI_BASE);
|
|
||||||
|
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
||||||
|
|
||||||
printf("DE10-LITE D8M VGA Demo\n");
|
printf("DE10-LITE D8M VGA Demo\n");
|
||||||
|
@ -137,14 +123,15 @@ int main()
|
||||||
printf("Image Processor ID: %x\n", IORD(0x42000, EEE_IMGPROC_ID));
|
printf("Image Processor ID: %x\n", IORD(0x42000, EEE_IMGPROC_ID));
|
||||||
//printf("Image Processor ID: %x\n",IORD(EEE_IMGPROC_0_BASE,EEE_IMGPROC_ID)); //Don't know why this doesn't work - definition is in system.h in BSP
|
//printf("Image Processor ID: %x\n",IORD(EEE_IMGPROC_0_BASE,EEE_IMGPROC_ID)); //Don't know why this doesn't work - definition is in system.h in BSP
|
||||||
|
|
||||||
|
|
||||||
usleep(2000);
|
usleep(2000);
|
||||||
|
|
||||||
|
|
||||||
// MIPI Init
|
// MIPI Init
|
||||||
if (!MIPI_Init()){
|
if (!MIPI_Init())
|
||||||
|
{
|
||||||
printf("MIPI_Init Init failed!\r\n");
|
printf("MIPI_Init Init failed!\r\n");
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf("MIPI_Init Init successfully!\r\n");
|
printf("MIPI_Init Init successfully!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,29 +145,6 @@ int main()
|
||||||
printf("\n");
|
printf("\n");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
#if 0 // focus sweep
|
|
||||||
printf("\nFocus sweep\n");
|
|
||||||
alt_u16 ii= 350;
|
|
||||||
alt_u8 dir = 0;
|
|
||||||
while(1){
|
|
||||||
if(ii< 50) dir = 1;
|
|
||||||
else if (ii> 1000) dir =0;
|
|
||||||
|
|
||||||
if(dir) ii += 20;
|
|
||||||
else ii -= 20;
|
|
||||||
|
|
||||||
printf("%d\n",ii);
|
|
||||||
OV8865_FOCUS_Move_to(ii);
|
|
||||||
usleep(50*1000);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
alt_u16 bin_level = DEFAULT_LEVEL;
|
alt_u16 bin_level = DEFAULT_LEVEL;
|
||||||
alt_u8 manual_focus_step = 10;
|
alt_u8 manual_focus_step = 10;
|
||||||
|
@ -194,66 +158,43 @@ int main()
|
||||||
Focus_Init();
|
Focus_Init();
|
||||||
|
|
||||||
FILE *ser = fopen("/dev/uart_0", "rb+");
|
FILE *ser = fopen("/dev/uart_0", "rb+");
|
||||||
if(ser){
|
fcntl(ser, F_SETFL, O_NONBLOCK);
|
||||||
|
if (ser)
|
||||||
|
{
|
||||||
printf("Opened UART\n");
|
printf("Opened UART\n");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf("Failed to open UART\n");
|
printf("Failed to open UART\n");
|
||||||
while (1);
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1){
|
while (1)
|
||||||
|
{
|
||||||
|
|
||||||
// touch KEY0 to trigger Auto focus
|
// touch KEY0 to trigger Auto focus
|
||||||
if((IORD(KEY_BASE,0)&0x03) == 0x02){
|
if ((IORD(KEY_BASE, 0) & 0x03) == 0x02)
|
||||||
|
{
|
||||||
|
|
||||||
current_focus = Focus_Window(320, 240);
|
current_focus = Focus_Window(320, 240);
|
||||||
}
|
}
|
||||||
// touch KEY1 to ZOOM
|
// touch KEY1 to ZOOM
|
||||||
if((IORD(KEY_BASE,0)&0x03) == 0x01){
|
if ((IORD(KEY_BASE, 0) & 0x03) == 0x01)
|
||||||
if(bin_level == 3 )bin_level = 1;
|
{
|
||||||
else bin_level ++;
|
if (bin_level == 3)
|
||||||
|
bin_level = 1;
|
||||||
|
else
|
||||||
|
bin_level++;
|
||||||
printf("set bin level to %d\n", bin_level);
|
printf("set bin level to %d\n", bin_level);
|
||||||
MIPI_BIN_LEVEL(bin_level);
|
MIPI_BIN_LEVEL(bin_level);
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if((IORD(KEY_BASE,0)&0x0F) == 0x0E){
|
|
||||||
|
|
||||||
current_focus = Focus_Window(320,240);
|
|
||||||
}
|
|
||||||
|
|
||||||
// touch KEY1 to trigger Manual focus - step
|
|
||||||
if((IORD(KEY_BASE,0)&0x0F) == 0x0D){
|
|
||||||
|
|
||||||
if(current_focus > manual_focus_step) current_focus -= manual_focus_step;
|
|
||||||
else current_focus = 0;
|
|
||||||
OV8865_FOCUS_Move_to(current_focus);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// touch KEY2 to trigger Manual focus + step
|
|
||||||
if((IORD(KEY_BASE,0)&0x0F) == 0x0B){
|
|
||||||
current_focus += manual_focus_step;
|
|
||||||
if(current_focus >1023) current_focus = 1023;
|
|
||||||
OV8865_FOCUS_Move_to(current_focus);
|
|
||||||
}
|
|
||||||
|
|
||||||
// touch KEY3 to ZOOM
|
|
||||||
if((IORD(KEY_BASE,0)&0x0F) == 0x07){
|
|
||||||
if(bin_level == 3 )bin_level = 1;
|
|
||||||
else bin_level ++;
|
|
||||||
printf("set bin level to %d\n",bin_level);
|
|
||||||
MIPI_BIN_LEVEL(bin_level);
|
|
||||||
usleep(500000);
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Read messages from the image processor and print them on the terminal
|
//Read messages from the image processor and print them on the terminal
|
||||||
while ((IORD(0x42000,EEE_IMGPROC_STATUS)>>8) & 0xff) { //Find out if there are words to read
|
while ((IORD(0x42000, EEE_IMGPROC_STATUS) >> 8) & 0xff)
|
||||||
|
{ //Find out if there are words to read
|
||||||
int word = IORD(0x42000, EEE_IMGPROC_MSG); //Get next word from message buffer
|
int word = IORD(0x42000, EEE_IMGPROC_MSG); //Get next word from message buffer
|
||||||
if (fwrite(&word, 4, 1, ser) != 1)
|
if (fwrite(&word, 4, 1, ser) != 1)
|
||||||
printf("Error writing to UART");
|
printf("Error writing to UART");
|
||||||
|
@ -268,44 +209,57 @@ int main()
|
||||||
|
|
||||||
//Process input commands
|
//Process input commands
|
||||||
int in = getchar();
|
int in = getchar();
|
||||||
switch (in) {
|
switch (in)
|
||||||
case 'e': {
|
{
|
||||||
|
case 'e':
|
||||||
|
{
|
||||||
exposureTime += EXPOSURE_STEP;
|
exposureTime += EXPOSURE_STEP;
|
||||||
OV8865SetExposure(exposureTime);
|
OV8865SetExposure(exposureTime);
|
||||||
printf("\nExposure = %x ", exposureTime);
|
printf("\nExposure = %x ", exposureTime);
|
||||||
break;}
|
break;
|
||||||
case 'd': {
|
}
|
||||||
|
case 'd':
|
||||||
|
{
|
||||||
exposureTime -= EXPOSURE_STEP;
|
exposureTime -= EXPOSURE_STEP;
|
||||||
OV8865SetExposure(exposureTime);
|
OV8865SetExposure(exposureTime);
|
||||||
printf("\nExposure = %x ", exposureTime);
|
printf("\nExposure = %x ", exposureTime);
|
||||||
break;}
|
break;
|
||||||
case 't': {
|
}
|
||||||
|
case 't':
|
||||||
|
{
|
||||||
gain += GAIN_STEP;
|
gain += GAIN_STEP;
|
||||||
OV8865SetGain(gain);
|
OV8865SetGain(gain);
|
||||||
printf("\nGain = %x ", gain);
|
printf("\nGain = %x ", gain);
|
||||||
break;}
|
break;
|
||||||
case 'g': {
|
}
|
||||||
|
case 'g':
|
||||||
|
{
|
||||||
gain -= GAIN_STEP;
|
gain -= GAIN_STEP;
|
||||||
OV8865SetGain(gain);
|
OV8865SetGain(gain);
|
||||||
printf("\nGain = %x ", gain);
|
printf("\nGain = %x ", gain);
|
||||||
break;}
|
break;
|
||||||
case 'r': {
|
}
|
||||||
current_focus += manual_focus_step;
|
case 'r':
|
||||||
if(current_focus >1023) current_focus = 1023;
|
{
|
||||||
OV8865_FOCUS_Move_to(current_focus);
|
current_focus += manual_focus_step;
|
||||||
printf("\nFocus = %x ",current_focus);
|
if (current_focus > 1023)
|
||||||
break;}
|
current_focus = 1023;
|
||||||
case 'f': {
|
OV8865_FOCUS_Move_to(current_focus);
|
||||||
if(current_focus > manual_focus_step) current_focus -= manual_focus_step;
|
printf("\nFocus = %x ", current_focus);
|
||||||
OV8865_FOCUS_Move_to(current_focus);
|
break;
|
||||||
printf("\nFocus = %x ",current_focus);
|
}
|
||||||
break;}
|
case 'f':
|
||||||
|
{
|
||||||
|
if (current_focus > manual_focus_step)
|
||||||
|
current_focus -= manual_focus_step;
|
||||||
|
OV8865_FOCUS_Move_to(current_focus);
|
||||||
|
printf("\nFocus = %x ", current_focus);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Main loop delay
|
//Main loop delay
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
|
||||||
};
|
};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue