Création d'une application pour le Badge


4.4   Creating an Application for the Badge

To create software that can be downloaded to the badge using the bootloader, there are a few guidelines that must be met. The LEDApp.zip and JM_Badge_Board.zip CodeWarrior projects have been provided as templates for development. It is highly recommended to start custom software designs with one of those projects.

 

4.4.1    Software Requirements

 

There are severai important things that must be done for a custom application to download and work correctly with the badge bootloader. This includes setting up the interrupts, ensuring the code is called from the correct place, and checking the code size.

 

4.4.1.1 Interrupts

 

All interrupts that will be used in the project must be declared in the main.c file. This file can be found in <Project Directory>/Sources/main.c

 

In that file, there is an array called “RAM_vector[ ]” that contains the re-directs to all the interrupt handler routines. For the interrupt that is to be used, replace “dummy_ISR” with the name of the interrupt function that should be used instead.

 

For example, in the LED_App project, the RTC interrupt (Vector 91) is using the “rtc_interrupt” function. This function will be called any time an RTC interrupt occurs. This is the only change that is required that is specific to the badge board in order to use interrupts.

 

4.4.1.2 Application Code

 

All user application code must be called from a specific place in main.c. This file can be found in <Project Directory>/Sources/main.c

 

In the main(void) function, there are two large comment blocks that signal the beginning and end of where the application code should begin and end executing. The code may call any functions from within this block, so there is no need to put all the code in the main.c file.

 

4.4.1.3 Code Size

 

As can be seen in the project.lcf linker file, the bootloader takes up the flash addresses from

0x00000000 to 0x00003800. This leaves addresses 0x00003800 to 0x00020000 for application

code. There is also Ox3EOO bytes of RAM space available Iocated from 0x00800200 to

0x00804000. See the linker file for more information.



4.4.2    Loading Application onto Badge Board

See Section 4.3.1 for how to use get an S19 file and load it on the board.

4.4.3 Initialization code

It is highly recommended to keep the sys init() function from the sample projects when developing custom projects. This sets up the GPIO pins correctly for the badge board, and ensures very 10w power consumption. Certain pins (particularly PTF2, which is connected to the magnetic buzzer), can have very dramatic affects on current draw.

 

Note that the initialization function turns off all system docks except KBI and IRQ. The other module docks are only turned on when needed. See the SCGC1, SCGC2, and SCGC3 register descriptions in Section 5.7.8 of the MCFS1JM128 Reference Manual for more information.

 

The dock is also set up to use Bypassed Low Power External (BLPE) mode, with a bus dock speed of 750 Hz. See Chapter 7 of the MCFS1JM128 Reference Manual for more information.

 

4.4.4 Useful Information

The JM_Badge_Board.zip project contains sample code for using the touch sensor, accelerometer, battery charger, speaker, and scrolling messages across the LED Matrix. This should help get custom designs up and running quickly.

 

For simple debugging, you can use the LED Matrix. PTAD controls which rows are activated.

• PTAD=0x00 means no LED5 will light up.

• PTAD=0x01 will activate the 1st row.

• PTAD=0x02 will activate the 2nd row

• PTAD=0x1F will activate all the rows.

 

PTED and PTDD control which column is lit. PTED controls the left 8 columns. PTDD controls the right 8 columns. First negate the value to display, and then hold the badge upside-down to correctly read the value.

• PTED=~(0x01) will light up the left most column (Column #1)

• PTED=~(0x03) will light up the two left most columns (columns #1 and #2)

• PTDD=~(0x80) will light up the right most column (Column #16)

• PTDD=~(0x01) will light up column #9

 

See the page for important information on issues with the bootloader and workarounds.

 

4.4 Création d'une application pour le Badge

    Pour créer un logiciel qui peut être téléchargé sur le Badge à l'aide du bootloader, il y a quelques conditions qui doivent être remplies. Les projets LEDApp.zip et JM_Badge_Board.zip CodeWarrior ont été fournis en tant que modèles pour le développement. Il est fortement recommandé de commencer la conception d’un logiciel personnalisé avec l'un de ces projets.

4.4.1 Nécessités logicielles
 
     Il y a plusieurs choses importantes qui doivent être faites pour qu’une application personnalisée se télécharge et fonctionne correctement avec le bootloader. Cela comprend la mise en place des interruptions, l’assurance que le  code est appelé à partir du bon endroit, et la vérification de la taille du code.

4.4.1.1 Interruptions

     Toutes les interruptions qui seront utilisés dans le cadre du projet doivent être déclarées dans le fichier main.c. Ce fichier peut être trouvé dans <Project Directory>/Sources/main.c.

     Dans ce fichier, il y a un tableau nommé “RAM_vector[ ] qui contient les re-directions vers toutes les routines d'interruption. Pour l'interruption destinée à être utilisée, remplacer "dummy_ISR" par le nom de la fonction d'interruption qui doit être utilisée à sa place.

     Par exemple, dans le projet LED_App , l’interruption RTC (Vector 91) utilise la fonction  "rtc_interrupt" . Cette fonction sera appelée à chaque fois qu'une interruption RTC se produit. C'est le seul changement qui est nécessaire, il est spécifique à la carte du Badge afin d'utiliser les interruptions.


4.4.1.2 Code de l'application

     Tout code d’application d’utilisateur doit être appelé à partir d'une place spécifique dans main.c. Ce fichier peut être trouvé dans <Project Directory>/Sources/main.c

     Dans la fonction main (void) fonction, il y a deux grands blocs de commentaire qui signalent le début et la  fin de l'endroit où le code de l'application et doit commencer et finir son exécution. Le code peut appeler n’importe quelle fonction au sein de ce bloc, il n'est donc pas nécessaire de mettre tout le code dans le fichier main.c.

4.4.1.3 Taille du Code

     Comme on peut le voir dans le fichier de liens project.lcf, le bootloader utilise les adresses de flash 0x00000000 à 0x00003800. Cela laisse les adresses 0x00003800 à 0x00020000 pour le code de  l'application. Il y a également Ox3EOO octets de RAM disponibles de 0x00800200 à 0x00804000. Voir le fichier de liens pour plus d'informations.

4.4.2 Chargement d'une application sur le Badge

Voir la section 4.3.1 pour savoir comment obtenir un fichier S19 et le charger sur la carte.

4.4.3 code d'initialisation

     Il est fortement recommandé de garder la fonction système init () des exemples de projets lors de l'élaboration de projets personnalisés. Cela met correctement en place les broches GPIO pour la carte du badge, et assure 10w de consommation d'énergie.
Certaines broches (particulièrement PTF2, qui est relié au buzzer magnétique), peuvent avoir des effets dramatiques sur la consommation électrique.

     Notez que la fonction d’initialisation désactive tous les docks système sauf KBI et IRQ. Les autres modules sont seulement activés en cas de besoin. Voir les descriptions des registres SCGC1, SCGC2, et SCGC3 dans la section 5.7.8  du Manuel de Référence du MCFS1JM128 pour plus d'informations.

     Le dock est également configuré pour utiliser le mode de faible puissance externe (BLPE), avec une vitesse de bus de 750 Hz. Voir le chapitre 7 du Manuel de Référence du MCFS1JM128 pour plus d'informations.

4.4.4 Informations utiles

     Le projet JM_Badge_Board.zip contient des exemples de code pour utiliser le détecteur de contact, l’accéléromètre, le chargeur de batterie, le haut-parleur, et le défilement des messages à travers la matrice de LED. Cela devrait aider à obtenir rapidement des applications personnalisées.

Pour le déboguage simple, vous pouvez utiliser la matrice de LED. PTAD contrôle les lignes qui sont activées.

• PTAD = 0x00 signifie qu’aucune LED5 ne s'allume.
• PTAD = 0x01 pour activer la première ligne.
• PTAD = 0x02 pour activer la deuxième ligne
• PTAD = 0x1F pour activer toutes les lignes.

PTED et PTDD contrôle quelle colonne est allumée. PTED contrôle les 8 colonnes de gauche. PTDD contrôle les 8 colonnes de droite. Tout d'abord supprimez la valeur à afficher, puis maintenez le badge à l'envers pour lire correctement la valeur.

• PTED = ~(0x01) allume la colonne la plus à gauche (colonne #1)
• PTED = ~(0x03) allume les deux colonnes plus les plus à gauche (Colonnes #1 et #2)
• PTDD = ~(0x80) allume la colonne la plus à droite, (colonne # 16)
• PTDD = ~(0x01) allume la colonne # 9

Voir la page des Badge Errata pour des informations importantes sur le bootloader et les environnements de travail.