Beispiel #1
0
//系统主函数
void main (void)
{
//	uint i;
	LED1=1;
	LED0=0;
	OEC=1;
	Exti_init();
	Time_init();	  //两个定时器初始化
	//TR0=0;
	UART_init();
	UART_Send_Str("知趣电子欢迎你!");
	while(1)
	{ 	
	
		if(irreceok)
    	{  
		    irreceok=0;	
			//P0=0X00;
			IR_pros();
			if(irprosok)
			{
				irprosok=0;
				P0=ircode[2];
			}
		}
		//if(open_close_flang)
	//	{
		///	open_close_flang=0;
			//TR0=1;
		//display_pic();
	//	}
		//else {
		//TR0=0;
		//}
		 display_hand();
		 //display_pic();
		 //display_figure();
		/*if(uart_flang)
		{
			//uart_flang=0;
			P0=0x00;
		//	if(pic_ch_flag)
		//	{
		//		pic_ch_flag=0;
			 TR1=1;   

		//	}
			
		}
		*/
	}
}
Beispiel #2
0
static PyObject *
timing_time_to_Time(struct timespec t)
{
		PyObject *new_args = Py_BuildValue("ll",(long)t.tv_sec,t.tv_nsec);
#ifdef __DEBUG__REFCNT
	printf("timing_time_to_Time:main: ");
	printf("refcount to new_args is %lu\n", (unsigned long)Py_REFCNT(new_args));
#endif
	PyObject *new_kwargs = PyDict_New();	
#ifdef __DEBUG__REFCNT
	printf("timing_time_to_Time:main: ");
	printf("refcount to new_kwargs is %lu\n", (unsigned long)Py_REFCNT(new_kwargs));
#endif
	timing_TimeObject *new_Time = (timing_TimeObject *)Time_new(&timing_TimeType, NULL, NULL);
#ifdef __DEBUG__REFCNT
	printf("timing_time_to_Time:main: ");
	printf("refcount to new_Time is %lu\n", (unsigned long)Py_REFCNT(new_Time));
#endif
	if (Time_init(new_Time, new_args, new_kwargs) == 0)
	{
		Py_DECREF(new_args);
		Py_DECREF(new_kwargs);
#ifdef __DEBUG__REFCNT
		printf("timing_time_to_Time:init_success: ");
		printf("refcount to new_Time is %lu\n", (unsigned long)Py_REFCNT(new_Time));
		printf("timing_time_to_Time:init_success: ");
		printf("refcount to new_args is %lu\n", (unsigned long)Py_REFCNT(new_args));
		printf("timing_time_to_Time:init_success: ");
		printf("refcount to new_kwargs is %lu\n", (unsigned long)Py_REFCNT(new_kwargs));
#endif
		return (PyObject *)new_Time;
	}
	else
	{
		Py_DECREF(new_args);
		Py_DECREF(new_kwargs);
		Py_DECREF(new_Time);
#ifdef __DEBUG__REFCNT
		printf("timing_time_to_Time:init_failure: ");
		printf("refcount to new_Time is %lu\n", (unsigned long)Py_REFCNT(new_Time));
		printf("timing_time_to_Time:init_failure: ");
		printf("refcount to new_args is %lu\n", (unsigned long)Py_REFCNT(new_args));
		printf("timing_time_to_Time:init_failure: ");
		printf("refcount to new_kwargs is %lu\n", (unsigned long)Py_REFCNT(new_kwargs));
#endif
		return NULL;
	}
}
void SW_MDL_construct(void) {
/* =================================================== */
  /* note that an initializer that is called during
   * execution (better called clean() or something)
   * will need to free all allocated memory first
   * before clearing structure.
   *
   */
  SW_MODEL *m = &SW_Model;

  Time_init();
  m->newweek = m->newmonth = m->newyear = FALSE;

#ifndef STEPWAT
/* already set by user-provided seed in steppe */
    RandSeed(0);
#endif
}
Beispiel #4
0
int main(void) {
	SystemCoreClockUpdate();

	// Read IAP before any interrupts are enabled
	UPER_PART_NUMBER		= IAP_GetPartNumber();
	UPER_BOOT_CODE_VERSION	= IAP_GetBootCodeVersion();
	IAP_GetSerialNumber(GUID);

	// Init the rest of the system
	Time_init();

	while (CDC_Init(&stream, GUID) != LPC_OK); // Load SFPPacketStream

	LPC_SYSCON->SYSAHBCLKCTRL |= BIT6 | BIT16 | BIT19; // Enable clock for GPIO, IOConfig and Pin Interrupts

#ifndef DEBUG
	// Disabled for debugging (JTAG)
	lpc_config_gpioInit();
#endif

	// PIO0_4 and PIO0_5 forced to I2C
	LPC_IOCON->PIO0_4 |= 1;	// I2C SCL
	LPC_IOCON->PIO0_5 |= 1;	// I2C SDA

	/* SFP initialization, configuration and launch */
	SFPServer *server = SFPServer_new(&stream);

	SFPServer_setDataTimeout(server, 30000); // 300k is about a second (30k ~100ms)

	/* GPIO/Pin functions */
	SFPServer_addFunctionHandler(server, UPER_FNAME_SETPRIMARY,	 UPER_FID_SETPRIMARY,	lpc_config_setPrimary);
	SFPServer_addFunctionHandler(server, UPER_FNAME_SETSECONDARY, UPER_FID_SETSECONDARY,	lpc_config_setSecondary);

	SFPServer_addFunctionHandler(server, UPER_FNAME_PINMODE,      UPER_FID_PINMODE,		lpc_pinMode);
	SFPServer_addFunctionHandler(server, UPER_FNAME_DIGITALWRITE, UPER_FID_DIGITALWRITE,	lpc_digitalWrite);
	SFPServer_addFunctionHandler(server, UPER_FNAME_DIGITALREAD,  UPER_FID_DIGITALREAD,	lpc_digitalRead);

	SFPServer_addFunctionHandler(server, UPER_FNAME_ATTACHINTERRUPT, UPER_FID_ATTACHINTERRUPT, lpc_attachInterrupt);
	SFPServer_addFunctionHandler(server, UPER_FNAME_DETACHINTERRUPT, UPER_FID_DETACHINTERRUPT, lpc_detachInterrupt);

	SFPServer_addFunctionHandler(server, UPER_FNAME_PULSEIN, UPER_FID_PULSEIN, lpc_pulseIn);

	/* ADC functions */
	SFPServer_addFunctionHandler(server, UPER_FNAME_ANALOGREAD, UPER_FID_ANALOGREAD, lpc_analogRead);

	/* SPI functions */
	SFPServer_addFunctionHandler(server, UPER_FNAME_SPI0BEGIN, UPER_FID_SPI0BEGIN, lpc_spi0_begin);
	SFPServer_addFunctionHandler(server, UPER_FNAME_SPI0TRANS, UPER_FID_SPI0TRANS, lpc_spi0_trans);
	SFPServer_addFunctionHandler(server, UPER_FNAME_SPI0END,   UPER_FID_SPI0END, lpc_spi0_end);

	SFPServer_addFunctionHandler(server, UPER_FNAME_SPI1BEGIN, UPER_FID_SPI1BEGIN, lpc_spi1_begin);
	SFPServer_addFunctionHandler(server, UPER_FNAME_SPI1TRANS, UPER_FID_SPI1TRANS, lpc_spi1_trans);
	SFPServer_addFunctionHandler(server, UPER_FNAME_SPI1END,   UPER_FID_SPI1END, lpc_spi1_end);

	/* I2C functions */
	SFPServer_addFunctionHandler(server, UPER_FNAME_I2CBEGIN, UPER_FID_I2CBEGIN, lpc_i2c_begin);
	SFPServer_addFunctionHandler(server, UPER_FNAME_I2CTRANS, UPER_FID_I2CTRANS, lpc_i2c_trans);
	SFPServer_addFunctionHandler(server, UPER_FNAME_I2CEND,   UPER_FID_I2CEND, lpc_i2c_end);

	/* PWM functions */
	SFPServer_addFunctionHandler(server, UPER_FNAME_PWM0BEGIN, UPER_FID_PWM0BEGIN, lpc_pwm0_begin);
	SFPServer_addFunctionHandler(server, UPER_FNAME_PWM0SET,   UPER_FID_PWM0SET, lpc_pwm0_set);
	SFPServer_addFunctionHandler(server, UPER_FNAME_PWM0END,   UPER_FID_PWM0END, lpc_pwm0_end);

	SFPServer_addFunctionHandler(server, UPER_FNAME_PWM1BEGIN, UPER_FID_PWM1BEGIN, lpc_pwm1_begin);
	SFPServer_addFunctionHandler(server, UPER_FNAME_PWM1SET,   UPER_FID_PWM1SET, lpc_pwm1_set);
	SFPServer_addFunctionHandler(server, UPER_FNAME_PWM1END,   UPER_FID_PWM1END, lpc_pwm1_end);


	/* Other functions */
	SFPServer_addFunctionHandler(server, UPER_FNAME_RESTART,       UPER_FID_RESTART, lpc_system_restart);
	SFPServer_addFunctionHandler(server, UPER_FNAME_GETDEVICEINFO,  UPER_FID_GETDEVICEINFO, lpc_system_getDeviceInfo);


	SFPServer_loop(server);

	SFPServer_delete(server);

	while (1);
}
Beispiel #5
0
// Get current time
Time Time_now()
{
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
	Time time = {
		.ms    = systick_millis_count,
		.ticks = ARM_DWT_CYCCNT,
	};
#elif defined(_host_)
	Time time = {
		.ms    = systick_millis_count,
		.ticks = ns_since_systick_count,
	};
#else
	// No time facilities...
	Time time = Time_init();
#endif

	return time;
}

// Get zero'd Time
#if !defined(_host_)
inline
#endif
Time Time_init()
{
	Time time = {
		.ms    = 0,
		.ticks = 0,
	};
Beispiel #6
0
int main(int argc, char** argv)
{
	pspDebugScreenInit();
	pspDebugScreenEnableBackColor(0);
	
	SetupCallbacks();
	
	char* scriptFilename = "script.lua";
	
	lua_State *L;
	L = lua_open();
	luaL_openlibs(L);
	
	Aalib_init(L);
	Color_init(L);
	g2D_init(L);
	intraFont_init(L);
	Ctrl_init(L);
	Power_init(L);
	Time_init(L);
	Timer_init(L);
	Savedata_init(L);
	sceIo_init(L);
	Utility_init(L);
	USB_init(L);
	Xtream_init(L);
	
	
	SceCtrlData keys, oldkeys;
	int status = 0, i;
	
	while (1)
	{
	status = luaL_loadfile(L, scriptFilename);
		
	if (status == 0) 
		status = lua_pcall(L, 0, LUA_MULTRET, 0);
	

		if (status != 0) //If an error has occured
		{
		sceCtrlReadBufferPositive(&oldkeys, 1);
		
		pspDebugScreenInit();
		pspDebugScreenEnableBackColor(1);
		
			while (1)
			{			
				sceCtrlReadBufferPositive(&keys, 1);
			
				pspDebugScreenSetXY(0,0);
				printf("Lua Error:\n%s\n", lua_tostring(L, -1));
				printf("Press Start to reset.\n");
				
				if ((keys.Buttons &PSP_CTRL_START) && !(oldkeys.Buttons &PSP_CTRL_START))
					break;
				
				oldkeys = keys;
				
				for (i = 0; i < 10; i++)
					sceDisplayWaitVblankStart();
			}
			
		pspDebugScreenInit();
		pspDebugScreenEnableBackColor(0);
		
		lua_pop(L, 1);
		}
	}
		
	lua_close(L);

	intraFontShutdown();
	g2dTerm();
	cleanUSBDrivers();

	sceKernelExitGame();

	return 0;
}
Beispiel #7
0
// Setup GPIO pins for matrix scanning
void Matrix_setup()
{
	// Register Matrix CLI dictionary
	CLI_registerDictionary( matrixCLIDict, matrixCLIDictName );

#if defined(_sam_)
	// 31.5.8 Reading the I/O line levels requires the clock of the PIO Controller to be enabled
	PMC->PMC_PCER0 = (1 << ID_PIOA) | (1 << ID_PIOB);
#endif

	// Setup Strobe Pins
	for ( uint8_t pin = 0; pin < Matrix_colsNum; pin++ )
	{
		GPIO_Ctrl( Matrix_cols[ pin ], GPIO_Type_DriveSetup, Matrix_type );
	}

	// Setup Sense Pins
	for ( uint8_t pin = 0; pin < Matrix_rowsNum; pin++ )
	{
		GPIO_Ctrl( Matrix_rows[ pin ], GPIO_Type_ReadSetup, Matrix_type );
	}

	// Clear out Debounce Array
	for ( uint8_t item = 0; item < Matrix_maxKeys; item++ )
	{
		Matrix_scanArray[ item ].prevState        = KeyState_Off;
		Matrix_scanArray[ item ].curState         = KeyState_Off;
		Matrix_scanArray[ item ].activeCount      = 0;
		Matrix_scanArray[ item ].inactiveCount    = DebounceDivThreshold; // Start at 'off' steady state
		Matrix_scanArray[ item ].prevDecisionTime = 0;
	}

	// Reset strobe position
	matrixCurrentStrobe = 0;

	// Debug mode
	matrixDebugMode = 0;

	// Debug counter reset
	matrixDebugStateCounter = 0;

	// Debounce expiry time
	debounceExpiryTime = MinDebounceTime_define;

	// Strobe delay setting
	strobeDelayTime = StrobeDelay_define;

	// Setup tick duration (multiples of 1 second)
	activity_tick_duration = Time_init();
	activity_tick_duration.ms = 1000 * ActivityTimerMultiplier_define;

	// Setup Activity and Inactivity tick resources
	Time_tick_start( &activity_tickstore, activity_tick_duration, TickStore_MaxTicks );
	Time_tick_start( &inactivity_tickstore, activity_tick_duration, TickStore_MaxTicks );

	// Clear matrixStateActiveCount for activity check
	matrixStateActiveCount = 0;
	matrixStatePressCount = 0;
	matrixStateReleaseCount = 0;

	// Setup latency module
	matrixLatencyResource = Latency_add_resource("MatrixARMPeri", LatencyOption_Ticks);
}