at91sam7.c
Go to the documentation of this file.00001
00049 #include "cfg/cfg_ser.h"
00050 #include <cfg/macros.h>
00051
00052 #include <kern/proc.h>
00053
00054 #include <cpu/detect.h>
00055
00056 #include <drv/timer.h>
00057 #include <drv/sysirq_at91.h>
00058 #include <drv/ser.h>
00059
00060 #include <io/arm.h>
00061
00062 Timer leds_timer;
00063 Serial ser_fd;
00064
00065 enum
00066 {
00067 FORWARD,
00068 BACKWARD,
00069 };
00070
00071 int direction = FORWARD;
00072
00073 static void leds_init(void)
00074 {
00075 #if CPU_ARM_AT91SAM7X256
00076
00077 PIOB_PER = 0x780000;
00078
00079 PIOB_OER = 0x780000;
00080
00081
00082 PIOB_SODR = 0x780000;
00083
00084
00085 PIOB_CODR = 0x80000;
00086 #elif CPU_ARM_AT91SAM7S256
00087
00088 PIOA_PER = 0x0000001f;
00089
00090 PIOA_OER = 0x0000001f;
00091
00092
00093 PIOA_SODR = 0x0000000f;
00094
00095 PIOA_CODR = 0x00000001;
00096 #endif
00097 }
00098
00099 #if CPU_ARM_AT91SAM7X256
00100 #define GET_PIO_STATUS() (~PIOB_ODSR & 0x780000)
00101 #define LAST_LED 0x200000
00102 #define FIRST_LED 0x100000
00103 #define SET_PIO_BITS PIOB_SODR
00104 #define CLEAR_PIO_BITS PIOB_CODR
00105 #define AT91SAM7_MSG "BeRTOS is running on AT91SAM7X256..\n"
00106 #elif CPU_ARM_AT91SAM7S256
00107 #define GET_PIO_STATUS() (~PIOA_ODSR & 0x0000000f)
00108 #define LAST_LED 0x00000004
00109 #define FIRST_LED 0x00000002
00110 #define SET_PIO_BITS PIOA_SODR
00111 #define CLEAR_PIO_BITS PIOA_CODR
00112 #define AT91SAM7_MSG "BeRTOS is running on AT91SAM7S256..\n"
00113 #endif
00114
00115
00116
00117
00118 static void leds_toggle(void)
00119 {
00120 uint32_t led_status = GET_PIO_STATUS();
00121
00122
00123 if (direction == FORWARD)
00124 {
00125 if(led_status == LAST_LED)
00126 direction = BACKWARD;
00127
00128 SET_PIO_BITS = led_status;
00129 CLEAR_PIO_BITS = led_status << 1;
00130 }
00131
00132 else if (direction == BACKWARD)
00133 {
00134 if(led_status == FIRST_LED)
00135 direction = FORWARD;
00136
00137 SET_PIO_BITS = led_status;
00138 CLEAR_PIO_BITS = led_status >> 1;
00139 }
00140
00141
00142 timer_setDelay(&leds_timer, ms_to_ticks(100));
00143 timer_add(&leds_timer);
00144 }
00145
00146 int main(void)
00147 { char msg[]="BeRTOS, be fast be beatiful be realtime";
00148
00149
00150 kdbg_init();
00151 timer_init();
00152 proc_init();
00153 leds_init();
00154
00155 ASSERT(!IRQ_ENABLED());
00156
00157
00158 ser_init(&ser_fd, 0);
00159 ser_setbaudrate(&ser_fd, 115200);
00160 ser_setparity(&ser_fd, SER_PARITY_NONE);
00161
00162 IRQ_ENABLE;
00163 ASSERT(IRQ_ENABLED());
00164
00165
00166
00167
00168 timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0);
00169 timer_setDelay(&leds_timer, ms_to_ticks(100));
00170 timer_add(&leds_timer);
00171
00172
00173
00174
00175 if(!proc_testRun())
00176 kfile_printf(&ser_fd.fd, "ProcTest..ok!\n");
00177 else
00178 kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n");
00179
00180
00181 kputs(AT91SAM7_MSG);
00182
00183
00184 for(;;)
00185 {
00186 kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg);
00187 }
00188 return 0;
00189 }