Advertisement
GeeckoDev

msp430 uart+led

Dec 24th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. #include <msp430.h>
  2. #include "HAL.h"
  3. #include "BTPSKRNL.h"
  4.  
  5. static int n_blink = 0;
  6.  
  7. /* Cette tâche lit l'entrée UART et la renvoie vers la sortie */
  8. void SerialMirrorFunction(void *param) {
  9.     char buf[256];
  10.     int n_read;
  11.  
  12.     n_read = HAL_ConsoleRead(256, buf);
  13.     HAL_ConsoleWrite(n_read, buf);
  14.  
  15.     // Des caractères ont été lus
  16.     if (n_read > 0)
  17.         n_blink = 3; // La LED clignotera trois fois.
  18. }
  19.  
  20. /* Cette tâche fait clignoter les LEDs */
  21. void ActivityIndicatorFunction(void *param) {
  22.     if (n_blink > 0) {
  23.         HAL_LedToggle(0);
  24.         n_blink--;
  25.     }
  26. }
  27.  
  28. void MainFunction(void) {
  29.     BTPS_Initialization_t btps_init;
  30.  
  31.     // Le comptage des ticks se fait dans le HAL via une interruption
  32.     // On donne l'accès du compteur au kernel
  33.     btps_init.GetTickCountCallback = HAL_GetTickCount;
  34.  
  35.     // Initialisation du kernel
  36.     BTPS_Init(&btps_init);
  37.  
  38.     // Ajout des tâches appelées périodiquement toutes les x millisecondes
  39.     BTPS_AddFunctionToScheduler(SerialMirrorFunction, NULL, 2);
  40.     BTPS_AddFunctionToScheduler(ActivityIndicatorFunction, NULL, 333);
  41.  
  42.     // Lancement de l'ordonnanceur (ne retourne jamais)
  43.     BTPS_ExecuteScheduler();
  44. }
  45.  
  46. void main(void) {
  47.     // Désactive le watchdog timer
  48.     WDTCTL = WDTPW | WDTHOLD;
  49.  
  50.     // Configuration initiale du microcontrôleur
  51.     HAL_ConfigureHardware();
  52.     __enable_interrupt();
  53.  
  54.     // Tâche principale (ordonnanceur)
  55.     MainFunction();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement