📄 pdd_keypad.c
字号:
/** @file *//* ----------------------------------------------------------------------------Copyright (C) Siemens AG 1994-2001 * ALL RIGHTS RESERVED This software is protected by the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred. The information contained in this document is considered the CONFIDENTIAL and PROPRIETARY information of Siemens AG and may not be disclosed or discussed with anyone who is not employed by Siemens AG, unless the individual / company (i) has an express need to know such information, and (ii) disclosure of information is subject to the terms of a duly executed Confidentiality and Non-Disclosure Agreement between Siemens AG and the individual / company.Created using template RCSfile: templ_c.c,v, Revision: 1.7, genxfile V1.9.AUTHOR Holger Hollenberg.FILENAME pdd_keypad.c.TODO .VERSION 01.02.06.DATE 2004-05-03.SHORT_DESCR HW access functions for keypad peripheral on S-Gold/S-GOLDlite..SW_COMPONENT Low level device driver for keypad..SW_TYPE DEVICE_DRIVER.EXIT_CODES EXIT: 0xD120 : NU_HISR_ACTIVATION_FAILED_0 \ EXIT: 0xD121 : NU_HISR_ACTIVATION_FAILED_3 \ (S)EXIT: 0xD122 : LISR0_SCANCODE1_NOT_READ \ (S)EXIT: 0xD123 : LISR0_SCANCODE3_NOT_READ \ (S)EXIT: 0xD124 : LISR3_SCANCODE1_NOT_READ \ (S)EXIT: 0xD125 : LISR3_SCANCODE3_NOT_READ \.CHANGE_CONTROL Version Date Changed by Reason of change--------------------------------------------------------------------------------01.00.00 2003-05-02 H. Hollenberg (KLF) Initial Version01.01.00 2003-05-08 H. Hollenberg (KLF) change portconfiguration for S-Goldlite, END-Key moved to PCL_00 changed in PddKpd_ReadEndKey ().01.02.00 2003-05-12 H.Hollenberg (KLF) Move port configuration to portmanager directory.01.02.01 2003-06-05 H.Hollenberg (KLF) Increase keypad HISR stack size from 256 to 512 bytes.01.02.02 2003-06-24 H.Hollenberg (KLF) END-Key moved to PCL_01(for Viper-testboard) changed in PddKpd_ReadEndKey().01.02.03 2003-12-06 H.Hollenberg (KLF) Add in deact/shutdown function MOPI_DestroyHisr(pKeypHisr).01.02.04 2004-02-12 H.Hollenberg (KLF) Disable keypad intrrupts in keypad LISRs. They will be enabled in HISR. This is done to avoid that an other keypad interrup occured before the keypad HISR is called. Switch from SEXIT to EXIT in case of HISR activation failure. Reduce debounce time from 90ms to 50ms.01.02.05 2004-03-23 H.Hollenberg (KLF) Add switch to supervisor mode in PddKpd_EnableKeypadInt0_3() and PddKpd_DisableKeypadInt0_3(). Increase HISR stack size from 512 to 1024 bytes.01.02.06 2004-05-03 H.Hollenberg (KLF) Set debounce time to 20ms, Info from Bruno Seifert (DHW): this time is supported from the keys.G F B step up: Generation / Feature / Bugfix------------------------------------------------------------------------------*//* ----------------------------------------------------------------------------- INCLUDES------------------------------------------------------------------------------*/#include <global.h>#include "nucleus.h" // interface to nucleus#include "mopi.h"#include "mopi_taskdef.h" // nucleus task priorities#include "mopiext.h" // MOPI extension#include "register.h" // S-Gold register defines#include "portmanager.h" // register at portmanager#include "portmgr_config.h"// port configuration#include "int.h" // configure interrupt source#include "pdd_keyp.h" // interface to ADD keypad device driver/* ----------------------------------------------------------------------------- EXIT DEFINES------------------------------------------------------------------------------*/#define TASK_NR 0xD1#define MODUL_NR 0x02#include "exit.h"/* ----------------------------------------------------------------------------- DEFINES------------------------------------------------------------------------------*//** (S)EXIT defines */#define NU_HISR_ACTIVATION_FAILED_0 (0)#define NU_HISR_ACTIVATION_FAILED_3 (1)#define LISR0_SCANCODE1_NOT_READ (2)#define LISR0_SCANCODE3_NOT_READ (3)#define LISR3_SCANCODE1_NOT_READ (4)#define LISR3_SCANCODE3_NOT_READ (5)/** Clear value, set register content to a defined value. */#define CLEAR_REGISTER (0x00000000)/** Debounce time for keypad kernel. * The debounce time is configured in KPD_CONFIG register. * The following values can be used: * 0x0 : 10ms * 0x1 : 20ms * 0x2 : 30ms * 0x3 : 40ms * 0x4 : 50ms * 0x5 : 60ms * 0x6 : 70ms * 0x7 : 80ms * 0x8 : 90ms * 0x9 : 100ms * 0xA : 110ms * 0xB : 120ms * 0xC : 130ms * 0xD : 140ms * 0xE : 150ms * 0xF : 160ms */#define DEBOUNCE_TIME (0x01) ///< 20ms debounce time/** Long key press time. * The long key press time is configured in KPD_CONFIG register. * The following values can be used: * 0x0000 : 0ms * 0x0100 : 10ms * 0x0200 : 20ms * 0x0300 : 30ms * ... * ... * 0x6400 : 1000ms = 1s * All other values = 1s. * *///#define LONG_KEY_TIME (0x6300) // long key time = 980ms#define LONG_KEY_TIME (0x0100) // long key time = 10ms/** Bit defines for KPD_SRCx registers */#define KPD_SRC_X_SETR (0x8000) ///< Request flag set bit#define KPD_SRC_X_CLRR (0x4000) ///< Request flag clear bit#define KPD_SRC_X_SRR (0x2000) ///< Service request flag#define KPD_SRC_X_SRE (0x1000) ///< Service request enable control#define KPD_SRC_X_TOS (0x0400) ///< Type-of-service control/** Markros for keypad interrupts *//** clear keypad interrupts */#define CLEAR_KEYPAD_INT0 (KPD_SRC0 |= KPD_SRC_X_CLRR) ///< clear service request flag, bit CLRR=1#define CLEAR_KEYPAD_INT3 (KPD_SRC3 |= KPD_SRC_X_CLRR) ///< clear service request flag, bit CLRR=1/** enable keypad interrupts */#define ENABLE_KEYPAD_INT0 (KPD_SRC0 |= KPD_SRC_X_SRE) ///< service request enable, bit SRE=1#define ENABLE_KEYPAD_INT3 (KPD_SRC3 |= KPD_SRC_X_SRE) ///< service request enable, bit SRE=1/** disable keypad interrupts */#define DISABLE_KEPYAD_INT0 (KPD_SRC0 &= ~KPD_SRC_X_SRE) ///< service request disable, bit SRE=0#define DISABLE_KEPYAD_INT1 (KPD_SRC1 &= ~KPD_SRC_X_SRE) ///< service request disable, bit SRE=0#define DISABLE_KEPYAD_INT2 (KPD_SRC2 &= ~KPD_SRC_X_SRE) ///< service request disable, bit SRE=0#define DISABLE_KEPYAD_INT3 (KPD_SRC3 &= ~KPD_SRC_X_SRE) ///< service request disable, bit SRE=0/* ----------------------------------------------------------------------------- TYPES------------------------------------------------------------------------------*//* ----------------------------------------------------------------------------- FILE LOCAL CONSTANTS------------------------------------------------------------------------------*//** HISR configuration */const T_MOPI_RtosTaskConfig keypHisrConfig ={ TIDHisrKeypad, ///< task identifer#if MOBSIM >0 "H_Keypad", ///< task name#endif HPRIOHisrKeypad, ///< task priority 1024 ///< stack size in bytes}; /* ----------------------------------------------------------------------------- FILE LOCAL VARIABLES------------------------------------------------------------------------------*//** Port manager ID. * The keypad driver gets the ID when registering at the portmanager. */STATIC T_PortMgr_ID KeypadPortMgrID;/** Pointer to keypad HISR object. */NU_HISR *pKeypHisr;/** Store the interrupt number. * The keypad can generate different interrupts for special events. This variable * stores the interrupt and later it is given to the ADD-part of the driver. * This value is used in the HISR. */STATIC UINT8 mg_u8IntOccurred;/** Save scancode for standard keys (KEYNUM1-register). * The scancode is written during interrupt (LISR). */STATIC UINT32 mg_u32scancode1; // standard key/** Save scancode for special keys (KEYNUM3-register). * The scancode is written during interrupt (LISR). */STATIC UINT32 mg_u32scancode3; // special key/* ----------------------------------------------------------------------------- FILE LOCAL PROTOTYPES------------------------------------------------------------------------------*//** Configuration function for keypad. */STATIC void PddKpd_ConfigKeypadKernel (void);/** Read functions for scancodes. */UINT32 PddKpd_ReadKeynum1 (void);UINT32 PddKpd_ReadKeynum3 (void);/** Keypad port configuration. */STATIC void PddKpd_KeypadPortConfig(void);/** LISR functions */STATIC void PddKpd_LisrConfig(void);STATIC void PddKpd_Int0Lisr(T_Int_Source Kpd_Int0_Source);STATIC void PddKpd_Int3Lisr(T_Int_Source Kpd_Int3_Source);/* ----------------------------------------------------------------------------- IMPLEMENTATION SECTION EXPORTED FUNCTIONS------------------------------------------------------------------------------*//*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*------------------------------------------------------------------------*/void PddKpd_Init(void (*ptrHisrHandler) (void)){ NU_SUPERV_USER_VARIABLES; // set auto variable NU_SUPERVISOR_MODE(); // switch to supervisor mode//---- Keypad port configuration ----------------------------------------- PddKpd_KeypadPortConfig(); //---- configure keypad kernel ------------------------------------------- PddKpd_ConfigKeypadKernel();//---- LISR configuration ------------------------------------------------ PddKpd_LisrConfig();//---- create MOPI HISR --------------------------------------------------- pKeypHisr = MOPI_CreateHisr(&keypHisrConfig, ptrHisrHandler);//---- Key pressed, no. of pressed keys changed -------------------------- CLEAR_KEYPAD_INT0; ENABLE_KEYPAD_INT0;//---- Long key released ------------------------------------------------- CLEAR_KEYPAD_INT3; ENABLE_KEYPAD_INT3;//---- disable all unused keypad interrupts ------------------------------ DISABLE_KEPYAD_INT1; DISABLE_KEPYAD_INT2;//---- init variables ---------------------------------------------------- mg_u8IntOccurred = KEYPAD_INTERRUPT_INIT; mg_u32scancode1 = 0; // read mark, for test during interrupt mg_u32scancode3 = 0; // read mark, for test during interrupt //---- switch to user mode ----------------------------------------------- NU_USER_MODE(); // switch to user mode return;}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*------------------------------------------------------------------------*/void PddKpd_Deact(void){ NU_SUPERV_USER_VARIABLES; // set auto variable NU_SUPERVISOR_MODE(); // switch to supervisor mode//---- destroy keypad HISR ----------------------------------------------- MOPI_DestroyHisr(pKeypHisr); //---- disable all keypad interrupts ------------------------------------- DISABLE_KEPYAD_INT0; DISABLE_KEPYAD_INT1; DISABLE_KEPYAD_INT2; DISABLE_KEPYAD_INT3;//---- switch to user mode ----------------------------------------------- NU_USER_MODE(); // switch to user mode return;}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*----------------------------------------------------------------------- */UINT32 PddKpd_GetScancodeKeynum1 (void){ UINT32 u32scancode; u32scancode = mg_u32scancode1; // save scancode mg_u32scancode1 = 0; // read mark, for test during interrupt return(u32scancode);}/*-----------------------------------------------------------------------*//** You can find the interface description in pdd_keyp.h.*//*----------------------------------------------------------------------- */UINT32 PddKpd_GetScancodeKeynum3 (void){ UINT32 u32scancode; u32scancode = mg_u32scancode3; // save scancode mg_u32scancode3 = 0; // read mark, for test during interrupt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -