Skip to content
Newer
Older
100644 175 lines (114 sloc) 5.47 KB
6f171a3 @embeddednirvana Firt commit
authored Apr 19, 2011
1 /*#####################################################################################
2 Copyright 2011 Nishchay Mhatre
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 ##################################################################################### */
16
17 /*#####################################################################################
18 COEP Satellite Project: On Board Computer
19
20 Single Stack RTOS: Main Function
21
22 Author: Nishchay Mhatre
23
24 17th September 2010 (First write)
25
26 Notes:
27 1. All things marked *FR have been copied as is from FreeRTOS source code by Richard
28 Barry.
29
30
31 #####################################################################################*/
32
33 #include<stdlib.h> // C standard includes
34 #include<stdint.h>
35
36 #include"task.h" // RTOS includes
37 #include"SST_config.h" // Configuration
38 #include"portmacro.h" // Hardware specific macros : *FR
39 #include"AT91SAM7X256.h" // H/W includes
40
41 #include"bob_tasks.h" // Application includes
42
43 #include"trace.h"
44
45 /* Hardware setup macro */
46 #define prvSetupHardware() /*Rev 1: Change1*/ \
47 {\
48 portDISABLE_INTERRUPTS();\
49 AT91C_BASE_AIC->AIC_EOICR = 0;\
50 AT91C_BASE_RTTC->RTTC_RTMR = (0x1)|(AT91C_RTTC_RTTRST);\
51 pio_init();\
52 AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA);\
53 AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOB);\
54 }
55
56
57 /*#####################################################################################
58
59 Setup the timer 0 to generate the tick interrupts at the required frequency.
60
61 *#####################################################################################*/
62
63 extern void (SST_Tick_ISR)(void); // Required for setup of timer interrupt
64 extern void (SST_Comm_ISR)(void); // Required for setup of comm interrupt
65
66 static void prvSetupTimerInterrupt( void ) // *FR
67 {
68 AT91PS_PITC pxPIT = AT91C_BASE_PITC;
69
70 /* Setup the AIC for PIT interrupts. The interrupt routine chosen depends
71 on whether the preemptive or cooperative scheduler is being used. */
72
73 AT91F_AIC_ConfigureIt( AT91C_ID_SYS, AT91C_AIC_PRIOR_HIGHEST, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, ( void (*)(void) ) SST_Tick_ISR );
74
75 /* Configure the PIT period. */
76 pxPIT->PITC_PIMR = AT91C_PITC_PITEN | AT91C_PITC_PITIEN | portPIT_COUNTER_VALUE;
77
78 /* Enable the interrupt. Global interrupts are disables at this point so
79 this is safe. */
80 AT91C_BASE_AIC->AIC_IECR = 0x1 << AT91C_ID_SYS;
81 }
82
83 /*#####################################################################################
84
85 Setup the Comm ISR to be triggered at a PIO input change interrupt.
86
87 *#####################################################################################*/
88
89 static void prv_Setup_Comm_Interrupt(void)
90 {
91
92 AT91C_BASE_PIOA->PIO_IER = (1 << config_PIO_INTR_PIN); // Configure the PIOA for interrupt
93 AT91C_BASE_PIOA->PIO_IDR = (0 << config_PIO_INTR_PIN);
94
95 AT91F_AIC_ConfigureIt(AT91C_ID_PIOA, AT91C_AIC_PRIOR_HIGHEST-1,config_IRQ_TYPE,(void(*)(void))SST_Comm_ISR ); // Configure the AIC properly
96
97 AT91C_BASE_AIC->AIC_IECR = 1 << AT91C_ID_PIOA; // Enable it
98
99 return;
100 }
101
102
103
104 /*#####################################################################################
105
106 Start of the RTOS loop: Idle task
107
108 ##################################################################################### */
109
110 extern uint8_t SST_current_priority ;
111 uint32_t system_time;
112
113 void StartLoop()
114 {
115 SST_current_priority = 0; // Set current priority to idle
116
117 prvSetupTimerInterrupt(); // Setup all Interrupts here
118 prv_Setup_Comm_Interrupt();
119
120 portENABLE_INTERRUPTS();
121
122 system_time = 4;
123
124 while(1) // The only task , idle task, that runs in
125 { // infinite loop. Power management algorithm
126 //to be put here or in the idle hook
127 ;
128 #if configUSE_IDLE_HOOK == 1
129 idle_hook(); /* Optional specific task to do in idle mode*/
130 #endif
131 }
132
133 asm volatile ("SWI 0x1"); // SWI interrupt to trap a return from loop
134 }
135
136 /*#####################################################################################
137
138 Main function. Payload of boot code.
139
140 ##################################################################################### */
141
142 extern uint8_t SST_ready_set; // Global used for scheduling
143
144 uint32_t current;
145 log_record data_log[LOGSIZE]; // This is used for debug only
146
147 int main(void)
148 {
149 update_log(MAIN, START|NOT_ISR);
150
151 prvSetupHardware(); // Initial setup of real time clcok, AIC and memory manager
152
153 SST_ready_set =0;
154 SST_task_create(one,1, NULL); // Create tasks. Task functions
155 SST_task_create(two,2, NULL); // defined in app/bob_tasks.c
156 SST_task_create(three,3, NULL);
157
158 StartLoop(); // Call Idle task
159
160 asm volatile ("SWI 0x1"); // SWI interrupt to trap a return from loop
161
162 }
163
164 /*#####################################################################################
165 Changelog:
166
167 17th September 2010 (First write)
168 14th October 2010 (Rev 1: Nishchay Mhatre)
169
170 Rev1:
171 1. Redundant instructions from the pio configuration removed. PIO clock activation
172 using the PMC_PCER done after the PIO configuration function returns
173
174 ##################################################################################### */
Something went wrong with that request. Please try again.