#include // kernel #include // diagnostics #include // diag_printf #include #define NTHREADS 1 #define STACKSIZE ( CYGNUM_HAL_STACK_SIZE_TYPICAL + 4096 ) // Base address for PIOA unsigned volatile int *pio_addr = 0xFFFF0000;//(unsigned int *) AT91_PIOB; unsigned volatile int *adc0_addr = 0xFFFB0000; // Stuff to handle the threads static cyg_handle_t thread[NTHREADS]; static cyg_thread thread_obj[NTHREADS]; static char stack[NTHREADS][STACKSIZE]; static cyg_handle_t rtc; static cyg_handle_t cnt_handle; static cyg_handle_t alarm_handle; static cyg_alarm alarm_obj; unsigned int wd_flag = 0; void wd_check_in() { wd_flag = 1; } void wd_handler(cyg_handle_t handle,cyg_addrword_t data) { unsigned int *flag = (unsigned int *) data; if ((*flag) == 1) { (*flag) = 0; } else { cyg_interrupt_disable(); diag_printf("Watchdog expired\n"); diag_printf("Watchdog printed the log\n"); diag_printf("Watchdog will now loop forever\n"); while(1); } } void init_wd_clock(void) { rtc = cyg_real_time_clock(); cyg_clock_to_counter(rtc,&cnt_handle); cyg_alarm_create(cnt_handle,wd_handler,(cyg_addrword_t) &wd_flag, &alarm_handle,&alarm_obj); // delay for 5 seconds cyg_alarm_initialize(alarm_handle,cyg_current_time()+500,500); } void loop(void) { int value; while(1) { cyg_thread_delay(100); //delay 1 second adc0_addr[0x00] = 0x02; //begin conversion diag_printf("Waiting...\n"); while(1) { diag_printf("V: %x\n",(adc0_addr[0x20]));// & 0x2)); if((adc0_addr[0x20] & 0x2) == 0x2) break; } value = adc0_addr[0x34]; diag_printf("Value: %d\n",value); } } //temperature sensor is on ADC Channel 1 void cyg_user_start(void) { int checker; //adc0_addr[0x04] = 0x00003f10; //no hardware triggering, no sleep mode, 8-bit operation, PS = 63 adc0_addr[0x10] = 0x00000007; //enable channel 1 adc0_addr[0x28] = 0xf; cyg_thread_create(4, loop, NULL, "Loop", (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); cyg_thread_resume(thread[0]); }