at91sam7s.c

Go to the documentation of this file.
00001 
00040 #include <cfg/macros.h>
00041 #include <drv/timer.h>
00042 #include <drv/sysirq_at91.h>
00043 #include <kern/proc.h>
00044 #include <drv/ser.h>
00045 #include <cfg/macros.h>
00046 #include <io/arm.h>
00047 
00048 Timer leds_timer;
00049 Serial ser_fd;
00050 
00051 static void leds_toggle(void)
00052 {
00053     uint8_t a = (~PIOA_ODSR & 0x0f);
00054 
00055     if (a)
00056     {
00057         PIOA_SODR = a;
00058         PIOA_CODR = a << 1;
00059     }
00060     else
00061     {
00062         PIOA_SODR  =  0x0f;
00063         /* turn first led on */
00064         PIOA_CODR  = 0x00000001;
00065     }
00066 
00067     /* Wait for interval time */
00068     timer_setDelay(&leds_timer, ms_to_ticks(100));
00069     timer_add(&leds_timer);
00070 }
00071 
00072 
00073 int main(void)
00074 {
00075     char msg[]="BeRTOS, be fast be beatiful be realtime";
00076     kdbg_init();
00077     timer_init();
00078 
00079     proc_init();
00080     ASSERT(!IRQ_ENABLED());
00081 
00082     /* Open the main communication port */
00083     ser_init(&ser_fd, 0);
00084     ser_setbaudrate(&ser_fd, 115200);
00085     ser_setparity(&ser_fd, SER_PARITY_NONE);
00086 
00087 
00088     IRQ_ENABLE;
00089     ASSERT(IRQ_ENABLED());
00090 
00091     /* Disable all pullups */
00092     PIOA_PUDR = 0xffffffff;
00093     /* Set PA0..3 connected to PIOA */
00094     PIOA_PER  = 0x0000001f;
00095     /* Set PA0..3 as output */
00096     PIOA_OER  = 0x0000001f;
00097     /* Disable multidrive on all pins */
00098     PIOA_MDDR = 0x0000001f;
00099 
00100     /* Set PA0..3 to 1 to turn off leds */
00101     PIOA_SODR  = 0x0000000f;
00102     /* turn first led on */
00103     PIOA_CODR  = 0x00000001;
00104 
00105     timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0);
00106     timer_setDelay(&leds_timer, ms_to_ticks(100));
00107     timer_add(&leds_timer);
00108 
00109     ASSERT(proc_testRun() == 0);
00110     // Main loop
00111     for(;;)
00112     {
00113         kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg);
00114     }
00115     return 0;
00116 }