Esempio n. 1
0
File: diskio.c Progetto: gstroe/Arm
/**
 * \brief Initialize a disk.
 *
 * \param drv Physical drive number (0..).
 *
 * \return 0 or disk status in combination of DSTATUS bits
 *         (STA_NOINIT, STA_PROTECT).
 */
DSTATUS disk_initialize(BYTE drv)
{
	int i;
	Ctrl_status mem_status;

#if 0
	/* Default RTC configuration, 24-hour mode */
	rtc_set_hour_mode(RTC, 0);
#endif

#if 0
	configure_rtc_calendar();
#endif

#if LUN_USB
	/* USB disk with multiple LUNs */
	if (drv > LUN_ID_USB + Lun_usb_get_lun()) {
		return STA_NOINIT;
	}
#else
	if (drv > MAX_LUN) {
		/* At least one of the LUN should be defined */
		return STA_NOINIT;
	}
#endif
	/* Check LUN ready (USB disk report CTRL_BUSY then CTRL_GOOD) */
	for (i = 0; i < 2; i ++) {
		mem_status = mem_test_unit_ready(drv);
		if (CTRL_BUSY != mem_status) {
			break;
		}
	}
	if (mem_status != CTRL_GOOD) {
		return STA_NOINIT;
	}

	/* Check Write Protection Status */
	if (mem_wr_protect(drv)) {
		return STA_PROTECT;
	}

	/* The memory should already be initialized */
	return 0;
}
Esempio n. 2
0
int main(void)
{
//! [run_initialize_rtc]
//! [system_init]
	system_init();
//! [system_init]

//! [time]
	struct rtc_calendar_time time;
	rtc_calendar_get_time_defaults(&time);
	time.year   = 2012;
	time.month  = 12;
	time.day    = 31;
	time.hour   = 23;
	time.minute = 59;
	time.second = 59;
//! [time]

	/* Configure and enable RTC */
//! [run_conf]
	configure_rtc_calendar();
//! [run_conf]

	/* Configure and enable callback */
//! [run_callback]
	configure_rtc_callbacks();
//! [run_callback]

	/* Set current time. */
//! [set_time]
	rtc_calendar_set_time(&rtc_instance, &time);
//! [set_time]
//! [run_initialize_rtc]

//! [while]
//! [main_loop]
	while (true) {
//! [main_loop]
		/* Infinite loop */
	}
//! [while]
}
Esempio n. 3
0
int main(void)
{
//! [add_main]
	system_init();

	struct rtc_calendar_time time;
	time.year   = 2012;
	time.month  = 12;
	time.day    = 31;
	time.hour   = 23;
	time.minute = 59;
	time.second = 59;

	configure_rtc_calendar();

	/* Set current time. */
	rtc_calendar_set_time(&rtc_instance, &time);

	rtc_calendar_swap_time_mode(&rtc_instance);
//! [add_main]

//! [main_imp]
//! [main_loop]
	while (true) {
//! [main_loop]
//! [check_alarm_match]
		if (rtc_calendar_is_alarm_match(&rtc_instance, RTC_CALENDAR_ALARM_0)) {
//! [check_alarm_match]
//! [alarm_match_action]
			/* Do something on RTC alarm match here */
			port_pin_toggle_output_level(LED_0_PIN);
//! [alarm_match_action]

//! [clear_alarm_match]
			rtc_calendar_clear_alarm_match(&rtc_instance, RTC_CALENDAR_ALARM_0);
//! [clear_alarm_match]
		}
	}
//! [main_imp]
}