1 / 87

Traitement des interruptions

Traitement des interruptions. Cours. Objectif du chapitre. Présentation des notions nécessaires pour aborder le traitement des interruptions dans l’exemple traité dans le chapitre suivant Organisation générale des interruptions sous Windows CE Étude des composants principaux Handler ISR

sutton
Download Presentation

Traitement des interruptions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Traitement des interruptions Cours IT CE4.2 : cours

  2. Objectif du chapitre • Présentation des notions nécessaires pour aborder le traitement des interruptions dans l’exemple traité dans le chapitre suivant • Organisation générale des interruptions sous Windows CE • Étude des composants principaux • Handler • ISR • IST • Fonctions utiles IT CE4.2 : cours

  3. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Éléments mis en jeu pour le traitement des interruptions (1) IT CE4.2 : cours

  4. Éléments mis en jeu pour le traitement des interruptions (2) • Hardware • Contient le périphérique qui va générer l’interruption • OAL • ISR (Interrupt Service Routine) fournit une information sur la façon de traiter l’IT • Routines de base : OEMInterruptDisable, OEMInterruptEnable … • Gestion des I/O physiques IT CE4.2 : cours

  5. Éléments mis en jeu pour le traitement des interruptions (3) • KERNEL (noyau) • Exception Handler • Interrupt Support Handler • DRIVER • Fonctions classiques du driver • IST Interrupt Service Thread : thread haute priorité qui réalise les opérations liées à l’IT IT CE4.2 : cours

  6. Principe des interruptions • Composants logiciels spécifiques pour gérer les interruptions • ISR : Interrupt Service Routine • Code très court • Retourne un numéro logique d’IT • IST : Interrupt Service Thread • Traite l’interruption IT CE4.2 : cours

  7. Déroulement du traitement (1) • Une IT physique se produit • Le gestionnaire d’exception lance l’ISR associé à cette interruption • L’ISR retourne un code prédéfini au noyau pour lui indiquer le traitement à faire • Le noyau positionne un événement associé • L’IST en attente de cet événement est activé IT CE4.2 : cours

  8. Déroulement du traitement (2) • La fonction PeRPISR est l’ISR associé à chaque interruption physique lors de l’initialisation du système d’interruption (fonction HookInterrupt) • PeRPISR récupère le numéro physique d’interruption (fonction PICGetCurrentInterrupt) • Les niveaux 0 (timer) et 1 (horloge temps réel) sont traités immédiatement • Pour les autres niveaux valides, PeRPISR appelle la fonction NKCallIntChain IT CE4.2 : cours

  9. Déroulement du traitement (3) • NKCallIntChain utilise le numéro d’interruption pour trouver dans une table le point d’entrée d’une liste chaînée conduisant à un code de retour • Code de retour en fin de chaîne : • SYSINTR_CHAIN : quand l’interruption n’est concernée par aucun des ISR de la chaîne • SYSINTR_NOP : rien à faire • SYSINTR_UNDEFINED : non initialisé dans la table • Valeur prédéfinie valide (ex : SYSINTR_A_MOI) IT CE4.2 : cours

  10. Déroulement du traitement (4) • Fin de l’ISR après réception du code de retour • SYSINTR_NOP ou SYSINTR_UNDEFINED ou Code invalide → retour au noyau avec un code SYSINTR_NOP • Code valide → fermeture de la source d’interruption dans le PIC (ou les PICs) puis envoi du code au noyau • SYSINTR_CHAIN → interruption sur un niveau non partagé. Conversion de l’IT physique en IT logique (fonction OEMTranslateIrq) et envoi au noyau du numéro d’IT logique IT CE4.2 : cours

  11. Déroulement du traitement (5) • Retour au noyau Différentes actions en fonction du code retourné : • Ne rien faire • Faire le traitement standard de l’IT • Armer un événement particulier suivant le code de retour pour déclencher l’exécution d’un IST IT CE4.2 : cours

  12. IST • Thread en mode user de forte priorité • En attente d’un événement associé à l’IT logique • Réveillé lorsque le Kernel signale l’événement • Traite l’interruption • Acquitte l’interruption au niveau de la source IT CE4.2 : cours

  13. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Arrivée de la demande d’IT 1 IT CE4.2 : cours

  14. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Envoi de OEMInterruptDisable 2 IT CE4.2 : cours

  15. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Appel des ISR associés au niveau d’IT traitée 3 IT CE4.2 : cours

  16. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Retour du numéro d’IT logique 4 IT CE4.2 : cours

  17. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Positionnement de l’Event associé à l’IST 5 IT CE4.2 : cours

  18. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Réveil de l’IST 6 IT CE4.2 : cours

  19. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Opérations sur la périphérie 7 IT CE4.2 : cours

  20. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Envoi de InterruptDone 8 IT CE4.2 : cours

  21. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Envoi de OEMInterruptDone 9 IT CE4.2 : cours

  22. Driver Kernel Exception Handler Interrupt Support Handler IST ISR OAL Routines I/O Routines OAL OEM Hardware Rappel 6 5 8 7 4 2 3 9 1 IT CE4.2 : cours

  23. SYSINTR logique (1) • Une interruption logique SYSINTR est associée à une interruption physique • À un même niveau d’interruption physique peuvent être associés plusieurs numéros logiques (IT partagée) • On donne à la fonction KernelIoControl un numéro physique d’IT et elle renvoie un numéro logique • KernelIoControl peut aussi libérer une SYSINTR IT CE4.2 : cours

  24. SYSINTR logique (2) • KernelIoControl fonctionne suivant un code IOCTL donné en paramètre • IOCTL_HAL_REQUEST_SYSINTR pour associer une SYSINTR à une IT physique • IOCTL_HAL_RELEASE_SYSINTR pour libérer une SYSINTR • Beaucoup d’autres possibilités inutiles pour notre exemple IT CE4.2 : cours

  25. KernelIoControl (1) BOOL KernelIoControl( DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned); Paramètres : dwIoControlCode : IOCTL utilisé lpInBuf : adresse du buffer d’entrée IT CE4.2 : cours

  26. KernelIoControl (2) nInBufSize : longueur du buffer d’entrée lpOutBuf : adresse du buffer de sortie nOutBufSize : longueur du buffer de sortie lpBytesReturned : adresse où trouver le nombre de caractères réellement placés dans le buffer de sortie, NULL dans notre exemple Valeur retournée : True pour une réussite, False pour un échec IT CE4.2 : cours

  27. KernelIoControl exemple DWORD Buf_In[1]; DWORD Buf_Out[1]; DWORD SYSINTR_A_MOI; Buf_In[0]=3; // IT physique numéro 3 KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, Buf_In,4,Buf_Out,4,NULL); SYSINTR_A_MOI=Buf_Out[0]; // IT logique IT CE4.2 : cours

  28. Passage de paramètres driver ↔ ISR • Il peut être nécessaire de passer des paramètres entre le driver et l’ISR • Si le driver obtient un numéro d’IT logique de manière dynamique, il est nécessaire de donner ce numéro à l’ISR qui doit le renvoyer au système s’il est concerné par cette interruption. • La fonction KernelLibIoControl permet cela • KernelLibIoControl appelle la fonction IoControl qui traite les IOCTL de l’ISR IT CE4.2 : cours

  29. KernelLibIoControl (1) BOOL KernelLibIoControl( HANDLE hModule, DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned ); IT CE4.2 : cours

  30. KernelLibIoControl (2) Parameters:hModule[in] Handle returned from the LoadIntChainHandler function. dwIoControlCode [in] OEM or ISV specified IOCTL. lpInBuf [in] Long pointer to a buffer that contains the data required to perform the operation. This parameter can be NULL … nInBufSize [in] Size, in bytes, of the buffer pointed to by lpInBuffer. IT CE4.2 : cours

  31. KernelLibIoControl (3) lpOutBuf [out] Long pointer to a buffer that receives the operation's output data. This parameter can be NULL... nOutBufSize [in] Size, in bytes, of the buffer pointed to by lpOutBuffer. lpBytesReturned [out] Long pointer to a variable that receives the size, in bytes, of the data stored into the buffer pointed to by lpOutBuffer. The lpBytesReturned parameter cannot be NULL. IT CE4.2 : cours

  32. KernelLibIoControl (4) Return Values If the function succeeds, then TRUE is returned; otherwise, FALSE is returned. IT CE4.2 : cours

  33. IoControl (1) • Cette fonction de l’ISR permet de traiter les différents IOCTL de configuration de l’ISR (par exemple envoi du numéro logique SYSINTR ) • Appelée par KernelLibIoControl • Permet la communication d’informations entre ISR et le driver IT CE4.2 : cours

  34. IoControl (2) BOOL IOControl(DWORD dwInst,DWORD dwIoControlCode,LPVOID lpInBuf,DWORD nInBufSize,LPVOID lpOutBuf,DWORD nOutBufSize,LPDWORD lpBytesReturned ); IT CE4.2 : cours

  35. IoControl (3) Parameters dwInst [in] Value that identifies the instance of the ISR handler. dwIoControlCode [in] Specifies the control code for the operation. This value identifies the specific operation to be performed and the type of device on which to perform it. IT CE4.2 : cours

  36. IoControl (4) lpInBuf [in] Pointer to a buffer that contains the data required to perform the operation. This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not require input data. nInBufSize [in] Specifies the size, in bytes, of the buffer pointed to by lpInBuffer. lpOutBuf [out] Pointer to a buffer that receives the operation's output data. This parameter can be NULL if the dwIoControlCode… IT CE4.2 : cours

  37. IoControl (5) nOutBufSize [in] Specifies the size, in bytes, of the buffer pointed to by lpOutBuffer. lpBytesReturned [out] Pointer to a variable that receives the size, in bytes, of the data stored in the buffer pointed to by lpOutBuffer. If the output buffer is too small to return any data, then the call fails, the GetLastError function returns the ERROR_INSUFFICIENT_BUFFER error code, and the returned byte count is zero. IT CE4.2 : cours

  38. IoControl (6) If the output buffer can only hold some data, then the call fails, the operating system (OS) returns as much information as it can, GetLastError returns the ERROR_MORE_DATA error code, and lpBytesReturned indicates the amount of data returned. Your application should then call the DeviceIoControl function again with the same operation, specifying a new starting point. Return Values If the function succeeds, then TRUE is returned; otherwise, FALSE is returned. IT CE4.2 : cours

  39. Liaison DRIVER ↔ IST • Le driver va lancer l’IST par un CreateThread et lui passer une structure avec des paramètres • Handle de l’IST • Numéro d’IT logique • Evénement associé à l’IST (auto Reset) • Flag de fin d’utilisation • En cas de besoin il est possible de synchroniser une des fonctions du driver avec un Event local positionné par l ’IST qui signale que l’IST a traité l’interruption IT CE4.2 : cours

  40. Fonctions du driver • Driver Init • Driver Deinit • Driver Open • Driver Close • Driver IoControl • Etc. IT CE4.2 : cours

  41. Driver Init • Initialisation du périphérique • ISR • Chargement et chaînage de l’ISR • Passage de paramètres à l’ISR • IST • Création du thread IST • Création d’un Event associé  à l’IST • Inhibition (Disable) du niveau d’IT logique • Liaison IT logique → Event • Mise de l’IST en bonne priorité IT CE4.2 : cours

  42. Driver Deinit • Signaler l’arrêt du driver à l’IST (flag Abort) • Inhiber (Disable) le niveau d’IT • Fermeture de tous les handles ouverts IT CE4.2 : cours

  43. Driver Open • Fin de l’initialisation du périphérique • Armement des interruptions du périphérique IT CE4.2 : cours

  44. Driver Close • Inhibition (Disable) des interruptions du périphérique IT CE4.2 : cours

  45. Driver IoControl • Exécution des différentes commandes IOCTL IT CE4.2 : cours

  46. Exemple (1) • Pour les exemples nous supposons gérer une ligne série • Noms utilisés : • Driver : TTYIT_DRV.dll (avec l’IST : TTYIST) • Handle de l’IST : hThr • Event associé : ISTEvent • Handle ISR : hChain • ISR : TTYISR.dll (point d’entrée : ISRHandler) IT CE4.2 : cours

  47. Exemple (2) • Structure d’information à passer à l’IST : TTYIST_Data • IT physique : ItPhy=3 • IT logique : SYSINTR_A_MOI IT CE4.2 : cours

  48. Fonctions utilisées • LoadIntChainHandler • CreateThread • CreateEvent • InterruptDisable • InterruptInitialize • CeSetThreadPriority IT CE4.2 : cours

  49. Chaînage de l’ISR (1) HANDLE LoadIntChainHandler( LPCWSTR lpFilename, LPCWSTR lpszFunctionName, BYTE bIRQ ); Parameters lpFilename [out] Pointer to a null-terminated string that names the DLL executable module. lpszFunctionName [in] Name of the interrupt handler entry point. IT CE4.2 : cours

  50. Chaînage de l’ISR (2) bIRQ [in] IRQ value that is used to identify which interrupt the installed ISR will service. Return Values If the function succeeds, then a valid handle to the installed handler is returned; otherwise, NULL is returned. Exemple HANDLE hChain; hChain=LoadIntChainHandler(_T("TTYISR.dll"), _T("ISRHandler"),ItPhy); IT CE4.2 : cours

More Related