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 KFileSerial 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     sysirq_init();
00078     timer_init();
00079 
00080     proc_init();
00081     ASSERT(!IRQ_ENABLED());
00082 
00083     /* Open the main communication port */
00084     ser_init(&ser_fd, 0);
00085     ser_setbaudrate(&ser_fd, 115200);
00086     ser_setparity(&ser_fd, SER_PARITY_NONE);
00087 
00088 
00089     IRQ_ENABLE;
00090     ASSERT(IRQ_ENABLED());
00091 
00092     /* Disable all pullups */
00093     PIOA_PUDR = 0xffffffff;
00094     /* Set PA0..3 connected to PIOA */
00095     PIOA_PER  = 0x0000001f;
00096     /* Set PA0..3 as output */
00097     PIOA_OER  = 0x0000001f;
00098     /* Disable multidrive on all pins */
00099     PIOA_MDDR = 0x0000001f;
00100 
00101     /* Set PA0..3 to 1 to turn off leds */
00102     PIOA_SODR  = 0x0000000f;
00103     /* turn first led on */
00104     PIOA_CODR  = 0x00000001;
00105 
00106     timer_set_event_softint(&leds_timer, (Hook)leds_toggle, 0);
00107     timer_setDelay(&leds_timer, ms_to_ticks(100));
00108     timer_add(&leds_timer);
00109 
00110     // Main loop
00111     for(;;)
00112     {
00113         proc_test();
00114         kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg);
00115     }
00116     return 0;
00117 }