summaryrefslogtreecommitdiff
path: root/Demo/PIC18_SDCC/main.c
blob: 0541bc8cc85df35939a5c470423f987db71992e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* #######################################################################################
* GAYE Abdoulaye Walsimou, <walsimou@walsimou.com>
* Copyright(C) 2009 GAYE Abdoulaye Walsimou, <walsimou@walsimou.com>. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License
* (Version 2 or later) published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
* #######################################################################################
*
* \file         main.c
* \brief	main function for SDCC PIC18 (pic16 arch in sddc world) port.
* \brief	It is based on existing PIC18 port.
* \author       GAYE Abdoulaye Walsimou, <walsimou@walsimou.com>
* \date         february 2009
* #######################################################################################
*/

#include "FreeRTOS.h"
#include "task.h"
#include <pic18fregs.h>
#include <malloc.h>

void panic(void);
void prvSetupHardware(void);
void prvtask1_func(void *pvparam);
void prvtask2_func(void *pvparam);
void prvtask3_func(void *pvparam);
void prvtask4_func(void *pvparam);

#define LED1_PORT PORTAbits.RA0
#define LED1_PORT_CONFIG TRISAbits.TRISA0

#define LED2_PORT PORTBbits.RB7
#define LED2_PORT_CONFIG TRISBbits.TRISB7

#define LED3_PORT PORTCbits.RC0
#define LED3_PORT_CONFIG TRISCbits.TRISC0

#define PANIC_PORT PORTDbits.RD0
#define PANIC_PORT_CONFIG TRISDbits.TRISD0


extern volatile __data unsigned char heap[configTOTAL_HEAP_SIZE];

#pragma stack 0x80 64
void main (void)
{
	prvSetupHardware();
	xTaskCreate(prvtask1_func,"T1",configMINIMAL_STACK_SIZE,NULL,1,NULL);
	xTaskCreate(prvtask2_func,"T2",configMINIMAL_STACK_SIZE,NULL,1,NULL);
	xTaskCreate(prvtask3_func,"T3",configMINIMAL_STACK_SIZE,NULL,4,NULL);
	vTaskStartScheduler();
}

void prvtask1_func(void* pvparam)
{
	(void*) pvparam;
	for(;;)
	{
	        portENTER_CRITICAL();
                LED1_PORT=LED1_PORT^1;
                portEXIT_CRITICAL();
	}
}

void prvtask2_func(void* pvparam)
{
	(void*) pvparam;
	for(;;)
	{
	        portENTER_CRITICAL();
                LED2_PORT=LED2_PORT^1;
                portEXIT_CRITICAL();
	}
}

void prvtask3_func(void* pvparam)
{
	(void*) pvparam;
	for(;;)
	{
	        portENTER_CRITICAL();
                LED3_PORT=LED3_PORT^1;
                portEXIT_CRITICAL();
                vTaskDelay(20);
	}
}
void panic (void)
{
        portDISABLE_INTERRUPTS();
	for(;;)
	{
		PANIC_PORT=PANIC_PORT^1;
	}
}
static void prvSetupHardware(void)
{
        /*Please do not remove the call of _initHeap unless you know what you're doing*/
        _initHeap(heap,configTOTAL_HEAP_SIZE);
	LED1_PORT=0;
	LED1_PORT_CONFIG=0;
	LED2_PORT=0;
	LED2_PORT_CONFIG=0;
	LED3_PORT=0;
	LED3_PORT_CONFIG=0;
	PANIC_PORT=0;
	PANIC_PORT_CONFIG=0;
}