-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (66 loc) · 2.33 KB
/
main.cpp
File metadata and controls
82 lines (66 loc) · 2.33 KB
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
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
// https://os.mbed.com/docs/mbed-os/v6.15/apis/eventqueue.html
/*
Quelques idées de choses à évoquer éventuellement :
- Création d'un simple projet "blink" sur mbed IDE pour la DISCO-F429ZI et les 2 LEDs.
- Configuration d'un nouveau projet utilisant une installation de mbed-os existante (pour réduire la taille des projets)
- Utilisation de InterruptIn pour l'usage du bouton avec fonction sur rise et fall.
- Découverte du fonctionnement des queue d'exécution pour un lancement régulier de tâche
- Découverte du fonctionnement de plusieurs threads avec priorités différentes
- Utlisation d'une librairie externe, par exemple pour servo moteur (installation, import, utilisation). https://os.mbed.com/users/simon/code/Servo/
- Envoie du code sur un github pour les versions et la collaboration.
*/
#include "mbed.h"
#include "Servo/Servo.h"
// Initialise the digital pin LED1 as an output
DigitalOut L0(LED1);
DigitalOut L1(LED2);
InterruptIn button(BUTTON1);
Servo myservo(PC_7);
Thread thread_leds(osPriorityNormal1);
EventQueue queue_leds(32 * EVENTS_EVENT_SIZE);;
Thread thread_button(osPriorityNormal2);
EventQueue queue_button(32 * EVENTS_EVENT_SIZE);;
Thread thread_servo(osPriorityNormal3);
EventQueue queue_servo(32 * EVENTS_EVENT_SIZE);;
void button_rise(void)
{
queue_button.call(printf, "Button Rise in context %p\n", ThisThread::get_id());
}
void button_fall(void)
{
queue_button.call(printf, "Button Fall in context %p\n", ThisThread::get_id());
}
void led0()
{
L0 = ! L0;
}
void led1()
{
L1 = ! L1;
}
void servo(){
myservo.position(-60);
ThisThread::sleep_for(200ms);
myservo.position(60);
ThisThread::sleep_for(200ms);
// Use CPU to test priority and preemption
for (int i=0; i<10000; i++){
wait_us(200);
}
}
int main()
{
queue_leds.call_every(1s, led0);
queue_leds.call_every(2s, led1);
button.rise(button_rise);
button.fall(button_fall);
queue_servo.call_every(5s, servo);
printf("Starting event_queue...\n\r");
thread_leds.start(callback(&queue_leds, &EventQueue::dispatch_forever));
thread_button.start(callback(&queue_button, &EventQueue::dispatch_forever));
thread_servo.start(callback(&queue_servo, &EventQueue::dispatch_forever));
}