Commit ee6712da authored by limm's avatar limm

1,初始版本

Signed-off-by: limm's avatarli.mengmeng@ikonke.com <li.mengmeng@ikonke.com>
parents
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
<?xml version="1.0"?>
<configurator>
<domain name="General" spec="zcl-7.0-07-5123-07" certifiable="true">
<older spec="zcl6-errata-14-0129-15" />
<older spec="zcl-6.0-15-02017-001" />
<older spec="zcl-1.0-07-5123-03" />
</domain>
<domain name="Lighting &amp; Occupancy" spec="l&amp;o-1.0-15-0014-04" certifiable="false" />
<domain name="HA" spec="ha-1.2.1-05-3520-30" dependsOn="zcl-1.0-07-5123-03" certifiable="false">
<older spec="ha-1.2-05-3520-29" dependsOn="zcl-1.0-07-5123-03" certifiable="true"/>
<older spec="ha-1.1-05-3520-27" dependsOn="zcl-1.0-07-5123-03" certifiable="true"/>
</domain>
<cluster>
<name>OptTunnel</name>
<domain>General</domain>
<description>The private cluster of the Konke company is used for the extended use of the private protocol </description>
<code>0xFCC0</code>
<define>OPT_TUNNEL_CLUSTER</define>
<client tick="false" init="true">true</client>
<server tick="false" init="true">true</server>
<attribute side="server" code="0x0000" define="OPT_DATA" type="CHAR_STRING" length="254" writable="true" default="" optional="true" >OptData</attribute>
<attribute side="server" code="0x0001" define="TTS" type="CHAR_STRING" length="254" writable="true" default="" optional="true" >TTS</attribute>
<attribute side="server" code="0x0002" define="MTO_RR_RspRandom" type="INT16U" min="0x00" max="0xFFFF" writable="true" default="" optional="true" >MTO_RR_RspRandom</attribute>
<attribute side="server" code="0x0003" define="AssociatedAnnounce" type="CHAR_STRING" length="16" writable="true" default="" optional="true" >AssociatedAnnounce</attribute>
<attribute side="server" code="0x0010" define="CMEI" type="CHAR_STRING" length="32" writable="true" default="" optional="true" >CMEI</attribute>
<attribute side="server" code="0x0011" define="ISN" type="CHAR_STRING" length="32" writable="true" default="" optional="true" >ISN</attribute>
<attribute side="server" code="0x0012" define="InstallCode" type="CHAR_STRING" length="32" writable="false" default="" optional="true" >InstallCode</attribute>
<attribute side="server" code="0x0013" define="CHUNK_N1" type="CHAR_STRING" length="32" writable="true" default="" optional="true" >CHUNK_N1</attribute>
<attribute side="server" code="0x1000" define="ErrorCode" type="INT8U" min="0x00" max="0xFF" writable="false" default="0x00" optional="true" >ErrorCode</attribute>
<attribute side="server" code="0x1001" define="ChildLock" type="BOOLEAN" min="0x00" max="0x01" writable="true" default="0x00" optional="true" >ChildLock</attribute>
<attribute side="server" code="0x1002" define="DelayOff" type="INT8U" min="0x00" max="0xF0" writable="true" default="0x00" optional="true" >DelayOff</attribute>
<attribute side="server" code="0x1003" define="SwingMode" type="ENUM8" min="0x00" max="0xFF" writable="true" default="0x00" optional="true" >SwingMode</attribute>
<attribute side="server" code="0x1004" define="ScreenSaverTime" type="ENUM8" min="0x00" max="0xFF" writable="true" default="0x00" optional="true" >ScreenSaverTime</attribute>
<attribute side="server" code="0x1005" define="FilterCleanTime" type="INT16U" min="0x0000" max="0xFFFF" writable="true" default="0x0FA0" optional="true" >FilterCleanTime</attribute>
<attribute side="server" code="0x1006" define="SystemMode" type="ENUM8" min="0x00" max="0x09" writable="true" default="0x00" optional="true" >SystemMode</attribute>
<attribute side="server" code="0x1007" define="TargetTemperature" type="INT16S" min="0x0000" max="0xFFFF" writable="true" default="0x0000" optional="true" >TargetTemperature</attribute>
<attribute side="server" code="0x1008" define="CurrentTemperature" type="INT16S" min="0x0000" max="0xFFFF" writable="true" default="0x0000" optional="true" >CurrentTemperature</attribute>
<attribute side="server" code="0x1009" define="CalibrationTemperature" type="INT8S" min="0x00" max="0xFF" writable="true" default="0x00" optional="true" >CalibrationTemperature</attribute>
<attribute side="server" code="0x100a" define="FanMode" type="ENUM8" min="0x00" max="0x09" writable="true" default="0x00" optional="true" >FanMode</attribute>
<attribute side="server" code="0x100b" define="OnOff" type="BOOLEAN" min="0x00" max="0x01" writable="true" default="0x00" optional="true" >OnOff</attribute>
<attribute side="server" code="0x100c" define="NoDisturbMode" type="BOOLEAN" min="0x00" max="0x01" writable="true" default="0x00" optional="true" >NoDisturbMode</attribute>
</cluster>
</configurator>
#ifndef ______00IKONKE_COMMON_PROCESS_H_____
#define ______00IKONKE_COMMON_PROCESS_H_____
#include "app/framework/include/af.h"
#include "././00ikonke-app/general/ikk-debug.h"
#include "./general/ikk-module-def.h"
#define BUILD_UINT16(lowByte, highByte) \
((uint16_t)(((lowByte) & 0x00FF) + (((highByte) & 0x00FF) << 8)))
#define HIGH_UINT16(a) (((a) >> 8) & 0xFF)
#define LOW_UINT16(a) ((a) & 0xFF)
#define FCC0_ATTR_Error_Code 0X1000
#define FCC0_ATTR_Child_Lock 0X1001
#define FCC0_ATTR_Delay_Off 0X1002
#define FCC0_ATTR_Swing_Mode 0X1003
#define FCC0_ATTR_Screen_Saver_Time 0X1004
#define FCC0_ATTR_Filter_Clean_Time 0X1005
#define FCC0_ATTR_System_Mode 0X1006
#define FCC0_ATTR_Target_Temperature 0X1007
#define FCC0_ATTR_Current_Temperature 0X1008
#define FCC0_ATTR_Calibration_Temperature 0X1009
#define FCC0_ATTR_Fan_Mode 0X100A
#define FCC0_ATTR_ON_OFF 0X100B
#define FCC0_ATTR_No_Disturb_Mode 0X100C
#define Device_Type_Air_Condition 1
#define Device_Type_Floor_Heating 2
#define Device_Type_Fan 3
EmberStatus Write_Attr(bool Report,uint8_t ep,uint16_t cluster,uint16_t attr, uint8_t* dataPtr,EmberAfAttributeType datatype);
#define Write_OnOff_Attr(x,ep,data) Write_Attr(x,ep,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID,data,ZCL_BOOLEAN_ATTRIBUTE_TYPE)
#define Write_SystemMode_Attr(x,ep,data) Write_Attr(x,ep,ZCL_THERMOSTAT_CLUSTER_ID,ZCL_SYSTEM_MODE_ATTRIBUTE_ID,data,ZCL_ENUM8_ATTRIBUTE_TYPE)
#define Write_TargetTemp_Attr(x,ep,data) Write_Attr(x,ep,ZCL_THERMOSTAT_CLUSTER_ID,ZCL_OCCUPIED_HEATING_SETPOINT_ATTRIBUTE_ID,(uint8_t*)data,ZCL_INT16S_ATTRIBUTE_TYPE)
#define Write_CurrentTemp_Attr(x,ep,data) Write_Attr(x,ep,ZCL_THERMOSTAT_CLUSTER_ID,ZCL_LOCAL_TEMPERATURE_ATTRIBUTE_ID,(uint8_t*)data,ZCL_INT16S_ATTRIBUTE_TYPE)
#define Write_CalibrationTemp_Attr(x,ep,data) Write_Attr(x,ep,ZCL_THERMOSTAT_CLUSTER_ID,ZCL_LOCAL_TEMPERATURE_CALIBRATION_ATTRIBUTE_ID,data,ZCL_INT8S_ATTRIBUTE_TYPE)
#define Write_FanSpeed_Attr(x,ep,data) Write_Attr(x,ep,ZCL_FAN_CONTROL_CLUSTER_ID,ZCL_FAN_CONTROL_FAN_MODE_ATTRIBUTE_ID,data,ZCL_ENUM8_ATTRIBUTE_TYPE)
//#define Write_ERROR_CODE_Attr(x,ep,data) Write_Attr(x,ep,ZCL_OPT_TUNNEL_CLUSTER_ID,FCC0_ATTR_Error_Code,data,ZCL_INT8U_ATTRIBUTE_TYPE)
#define Write_Child_Lock_Attr(x,ep,data) Write_Attr(x,ep,ZCL_OPT_TUNNEL_CLUSTER_ID,FCC0_ATTR_Child_Lock,data,ZCL_BOOLEAN_ATTRIBUTE_TYPE)
#define Write_Delay_off_Attr(x,ep,data) Write_Attr(x,ep,ZCL_OPT_TUNNEL_CLUSTER_ID,FCC0_ATTR_Delay_Off,data,ZCL_INT8U_ATTRIBUTE_TYPE)
#define Write_Wind_Direct_Attr(x,ep,data) Write_Attr(x,ep,ZCL_OPT_TUNNEL_CLUSTER_ID,FCC0_ATTR_Swing_Mode,data,ZCL_ENUM8_ATTRIBUTE_TYPE)
#define Write_Screen_Save_Time_Attr(x,ep,data) Write_Attr(x,ep,ZCL_OPT_TUNNEL_CLUSTER_ID,FCC0_ATTR_Screen_Saver_Time,data,ZCL_ENUM8_ATTRIBUTE_TYPE)
#define Write_Filter_Clean_Time_Attr(x,ep,data) Write_Attr(x,ep,ZCL_OPT_TUNNEL_CLUSTER_ID,FCC0_ATTR_Filter_Clean_Time,data,ZCL_INT16U_ATTRIBUTE_TYPE)
#define Write_MaxTemp_Attr(x,ep,data) Write_Attr(x,ep,ZCL_THERMOSTAT_CLUSTER_ID,ZCL_MAX_HEAT_SETPOINT_LIMIT_ATTRIBUTE_ID,(uint8_t*)data,ZCL_INT16S_ATTRIBUTE_TYPE)
#define Write_MinTemp_Attr(x,ep,data) Write_Attr(x,ep,ZCL_THERMOSTAT_CLUSTER_ID,ZCL_MIN_HEAT_SETPOINT_LIMIT_ATTRIBUTE_ID,(uint8_t*)data,ZCL_INT16S_ATTRIBUTE_TYPE)
typedef struct
{
uint8_t Device_Type;
uint8_t Device_subType;
uint8_t Binding_Device_SrcEP;
uint8_t mcu_software_version;
uint8_t mcu_hardware_version;
}DEVICVE_INFO_ST;
extern DEVICVE_INFO_ST g_sDevice_Info;
uint8_t Read_Zigbee_Version(void);
kk_err_t PrivateClusterHandler(EmberAfClusterCommand* cmd);
/**********************common interface*******************************/
uint8_t Get_Device_Endpoint(void);
uint8_t Get_Binding_Device_EP(void);
void print_all_attr_vaule(uint8_t ep);
#endif /* 00IKONKE_APP_BL55072A_H_ */
#ifndef __IKONKE_MODULE_BATTERY_H_______________________________
#define __IKONKE_MODULE_BATTERY_H_______________________________
#include "app/framework/include/af.h"
#if defined(ADC_COUNT) && (ADC_COUNT > 0)
/* DESP: Battery adc sample init
* Auth: maozj.20200325.
* */
void kBatteryMonitorInit(void);
/* DESP: This function will sample the ADC according to flag whether need to write to attribute
* Auth: maozj.20200325.
* */
uint16_t kBatteryMonitorReadVotage(bool bIsWriteAttr);
#endif
#endif
#ifndef __IKONKE_MODULE_BUTTON_H_______________________________
#define __IKONKE_MODULE_BUTTON_H_______________________________
#include "app/framework/include/af.h"
#include "../general/ikk-module-def.h"
#include "../general/ikk-debug.h"
// Maximum number of buttons supported!
#define BTN_SUPPORT_MAXN 8
#define BTN_UNKNOW_ID 0 // Valid[1,254], 255 for Operate all at the same time!
#define BTN_ALLOPT_ID 255 // Valid[1,254], 255 for Operate all at the same time!
typedef enum { EBP_LOW = 0, EBP_HIGH, EBP_BOTH }BtnPolarityEnum;
typedef enum { EBA_IDLE = 0, EBA_CLICK, EBA_DCLICK, EBA_LONGPRESS, EBA_PRESSED, EBA_RELEASED}BtnActionEnum;
typedef void (*pBtnActionCallback)(unsigned char btnIndex, BtnActionEnum action );
typedef struct tag_button_configeration {
unsigned char u8ButtonId;
GPIO_Port_TypeDef port;
unsigned int pin;
BtnPolarityEnum eActionPolarity;
bool bSupportDClick;
bool bSupportPressedSend; //true:key always long pressed will send pressed message interval 1 second.used to sensor
unsigned int u32LongPressDuration; // MS
}BtnConfSt;
/* DESP: Assign an unused interrupt number.
* Auth: dingmz_frc.20191108.
* */
uint8_t kBtnAssignIRQNO(uint8_t btn_index, unsigned int pin );
/* DESP:Get usefull assign irq index for other interrupt gpio include button
* Auth: maozj.20200325.
* */
uint8_t kBtnGetAssignUsefullIndex(void);
/* DESP: single Button instance register interface.
* Auth: dingmz_frc.20191108. modify by maozj 20200326
* */
kk_err_t kBtnRegister(uint8_t id, GPIO_Port_TypeDef port, unsigned int pin, BtnPolarityEnum ePolarity, \
bool bSupportDClick, bool bSupportPressedSend, uint32_t u32LongPressDuration );
/* DESP: button module Initialize configuration interface.
* Note: Button initialization interface supports one-time registration of multiple buttons!
* Auth: dingmz_frc.20191107.
* */
kk_err_t kBtnModuleInit(BtnConfSt *btnlist, unsigned char btn_number, pBtnActionCallback pBtnActionCallback );
/* DESP: get button information by button id
* Auth: maozj.20191123.
* */
kk_err_t kBtnGetInfoByButtonId(uint8_t id, BtnConfSt *btnConf);
#endif
#ifndef __IKONKE_MODULE_LED_H_______________________________
#define __IKONKE_MODULE_LED_H_______________________________
#include "app/framework/include/af.h"
#include "../general/ikk-module-def.h"
#define LED_OBJS_SUPPORT_MAXN 8
// the number of physical gpios that can be mapped for a single LED control instance!
#define LED_GPIO_MAPPING_MAXN 4
#define LED_UNKNOW_ID 0 // Valid[1,254], 255 for Operate all at the same time!
#define LED_ALLOPT_ID 255 // Valid[1,254], 255 for Operate all at the same time!
#define BLINK_DEAD 0xffffffff
#define BLINK_NONE 0x0
// LED STATUS
typedef enum { LED_OFF = 0, LED_ON = 1, LED_TOGGLE, LED_IGNORE = 2 }LedOptEnum;
typedef enum { ELP_LOW = 0/* low to on */, ELP_HIGH/* high to on */ }LedPolarityEnum;
typedef struct {
GPIO_Port_TypeDef port;
unsigned int pin;
unsigned int pwmId; //0 :not use pwm
}LedGpioListSt;
// led configuration struct
typedef struct tag_led_config_st {
unsigned char u8LedId; // 0 ~ 254
unsigned char u8GpioMappNum;
LedGpioListSt gpios[LED_GPIO_MAPPING_MAXN];
LedPolarityEnum eActionPolarity;
//uint8_t pwmIds[LED_GPIO_MAPPING_MAXN]; //band pwm id
}LedConfSt;
typedef void (*pLedActionDoneCallback)(unsigned char id);
/* DESP: Indicator lamp behavior control interface.
Auth: dingmz_frc.20191108.
*/
void kLedOptTrigger(uint8_t id, uint32_t duration_on_ms, uint32_t duration_off_ms, uint32_t times, LedOptEnum start, LedOptEnum end );
/* DESP: Toggle LED
Auth: maozj.20200226.
*/
void kLedOptToggle(uint8_t id);
// Turn ON
#define LED_OPT_ON(id) do { \
kLedOptTrigger(id, 0, 0, 0, LED_ON, LED_IGNORE); \
}while(0)
// Turn OFF
#define LED_OPT_OFF(id) do { \
kLedOptTrigger(id, 0, 0, 0, LED_OFF, LED_IGNORE); \
}while(0)
// Turn TOGGLE add by maozj 20200226
#define LED_OPT_TOGGLE(id) do { \
kLedOptToggle(id); \
}while(0)
/* DESP: Check if the specified led indicator is bliking.
* Auth: dingmz_frc.20191108.
* */
bool kLedIsBlinking(uint8_t led_id );
/* DESP: single LED instance register interface.
* Auth: dingmz_frc.20191108.
* */
kk_err_t kLedRegister(uint8_t id, uint8_t gpio_num, LedGpioListSt gpio_list[], LedPolarityEnum ePolarity);
/* DESP: led control module Initialize configuration interface.
* Note: Led initialization interface supports one-time registration of multiple LEDs!
* Auth: dingmz_frc.20191108.
* */
kk_err_t kLedModuleInit(LedConfSt *ledlist, unsigned char led_number, pLedActionDoneCallback pCallback);
/* DESP: led control module Initialize modify by led id.
* Note: Led initialization interface
* Auth: maozj.20191226.
* */
kk_err_t kLedModuleInfoModifyGpioById(uint8_t id, LedConfSt ledconf);
#endif
#ifndef __IKONKE_MODULE_PWM_H_______________________________
#define __IKONKE_MODULE_PWM_H_______________________________
#include "app/framework/include/af.h"
#include "../general/ikk-module-def.h"
#include "em_timer.h"
#define PWM_OBJS_SUPPORT_MAXN 6
#define PWM_UNKNOW_ID 0 // Valid[1,254], 255 for Operate all at the same time!
#define PWM_ALLOPT_ID 255 // Valid[1,254], 255 for Operate all at the same time!
#define PWM_TIMER_MAX_DUTY_CYCLE_NUM 40000
#define PWM_TIMER_MID_DUTY_CYCLE_NUM 500
#define PWM_TIMER_MIN_DUTY_CYCLE_NUM 0
typedef enum {ELP_MIN = 0, ELP_MID,ELP_ANY, ELP_MAX, ELP_TO_BRIGHT/* min to max */, ELP_TO_DARKEN/* max to min */, ELP_OPT_DEFAULT=0xff }PwmGradientDirectionEnum;
typedef enum {KK_TIMER_CC0=0, KK_TIMER_CC1, KK_TIMER_CC2, KK_TIMER_CC3}PwmTimerChannelEnum;
typedef enum {KTIMER0=0, KTIMER1, KTIMER2, KTIMER3}TIMER_ENUM;
typedef struct {
GPIO_Port_TypeDef port;
unsigned int pin;
TIMER_ENUM pwmTimer;
// TIMER_TypeDef *pwmTimer;
PwmTimerChannelEnum pwmChannel;
uint32_t timerChannalLocation; //just for EFR32MG13 chip, need check datasheet,search "location"
}PwmGpioListSt;
// led configuration struct
typedef struct tag_pwm_config_st {
unsigned char u8PwmId; // 0 ~ 254
PwmGpioListSt gpioInfo;
//TIMER_TypeDef timer;
//uint8_t pwmChannel;
}PwmConfSt;
extern TIMER_TypeDef *ktimer[];
extern CMU_Clock_TypeDef kclock[];
//funtion callback when pwm duty cycle is changed to max or min
typedef void (*pPwmActionDoneCallback)(unsigned char id, PwmGradientDirectionEnum opt);
/* DESP: get the pwm index by led_id.
* Auth: maozj.20200211.
* */
uint8_t kPwmGetIndexByID(uint8_t pwm_id );
/* DESP: Check whether all pwm have stopped action detection.
* Auth: maozj.20200211.
* */
bool kPwmGradientChangeIsGoing(void);
/* DESP: Check if the specified pwm is changing.
* Auth: maozj.20200211.
* */
bool kPwmIsChanging(uint8_t pwm_id );
/* DESP: registration the system pwm driver processing function interface.
Auth: maozj.20200211.
*/
void kPwmDriverhandler(uint8_t pwm_index, PwmGradientDirectionEnum st, uint16_t value);
/* DESP: pwm frequence init interface.
* Auth: maozj.20200212.
* */
void kPwmFrequencySetInit(uint16_t frequency_hz, uint16_t init_duty_cycle, PwmGpioListSt gpioInfo);
/* DESP: pwm control module Initialize configuration interface.
* Note: pwm initialization interface supports one-time registration of multiple pwm channel!
* Auth: maozj.20200219.
* */
kk_err_t kPwmModuleInit(PwmConfSt pwmlist[], unsigned char pwm_number, pPwmActionDoneCallback pCallback);
/* DESP: Indicator pwm trigger behavior control interface.
Auth: maozj.20200211.
*/
void kPwmOptTrigger(uint8_t id, uint32_t start_value, uint32_t end_value, uint32_t duration_time );
/* DESP: clear pwm gradient counter interface by pwm id.
* Auth: maozj.20200212.
* */
bool kPwmClearGradientCounterById(uint8_t pwm_id);
#endif
#ifndef __IKONKE_MODULE_ZERO_ACCESS_H_______________________________
#define __IKONKE_MODULE_ZERO_ACCESS_H_______________________________
#include "app/framework/include/af.h"
#include "../general/ikk-module-def.h"
#define RELAY_OBJS_SUPPORT_MAXN 8
// the number of physical gpios that can be mapped for a single Zero-Access channel instance!
#define RELAY_GPIO_MAPPING_MAXN 4
#define RELAY_CHNN_UNKNOW_ID 0 // Valid[1,254], 255 for Operate all at the same time!
#define RELAY_CHNN_ALLOPT_ID 255 // Valid[1,254], 255 for Operate all at the same time!
typedef enum { EZAO_OFF = 0, EZAO_ON = 1 , EZAO_DEFAULT = 0xFF}RelayOptEnum;
// Zero-Access channel status
typedef enum { EZAP_LOW = 0/* low to on */, EZAP_HIGH/* high to on */ }RelayPolarityEnum;
typedef struct {
GPIO_Port_TypeDef port;
unsigned int pin;
}RelayGpioListSt;
// ZA channel configuration struct
typedef struct tag_relay_config_st {
unsigned char u8RelayChannelId; // 0 ~ 254
unsigned char u8GpioMappNum; //relay numbers
RelayGpioListSt gpios[RELAY_OBJS_SUPPORT_MAXN]; //relay gpio buffer
RelayPolarityEnum eActionPolarity;
}RelayChannelConfSt;
typedef struct {
unsigned char u8RelayChannelId; // 0 ~ 254
RelayOptEnum opt;
}RelayStatusSt;
//user led control callback when relay on off
typedef void (*pRelayOptLedCallback)(RelayStatusSt stRelayStatus);
/* DESP: Zero-Access channel operate interface.
Auth: dingmz_frc.20191115.
*/
void kRelayChannelOpt(uint8_t channel_id, RelayOptEnum opt );
/* DESP: Relay control module Initialize configuration interface.alse zero gpio is not necessary
* PARAM[port]: the GPIO port for Zero-Access detection.
* PARAM[pin]: the GPIO pin for Zero-Access detection.
* PARAM[zero_on_time]: relay delay on time when get zero interrupt
* PARAM[zero_off_time]: relay delay off time when get zero interrupt
* PARAM[ePolarity]: the Zero GPIO pin interrupt edge
* PARAM[list]: the config list of all relay dection
* PARAM[channel_num]: total group number of relay.
* PARAM[callback]: callback function after relay operate done
* Auth: maozj.20191115.
* */
kk_err_t kRelayModuleInit(GPIO_Port_TypeDef port, uint8_t pin, uint32_t zero_on_time, uint32_t zero_off_time \
, RelayPolarityEnum ePolarity, RelayChannelConfSt *list, uint8_t channel_num, pRelayOptLedCallback callback);
#endif
#include "stdint.h"
#include "stdbool.h"
//#include "stack/include/ember-types.h"
#include "em_gpio.h"
#include "../driver/ikk-led.h"
#include "ikk-timer.h"
#include "../general/ikk-debug.h"
#define ONSHOT_MIN_TIMER_US (10)
#if defined(TIMER2) && defined(TIMER3)
uint8_t kTimerIRQn[] = {TIMER0_IRQn, TIMER1_IRQn, TIMER2_IRQn, TIMER3_IRQn};
#else
uint8_t kTimerIRQn[] = {TIMER0_IRQn, TIMER1_IRQn, TIMER1_IRQn, TIMER1_IRQn};
#endif
typedef struct {
bool bIsGoing;
TIMER_ENUM timer;
uint32_t timerTimeUs;
bool bIsOneShot;
pTimerPollCallback pollCallback;
pTimerPollCallback stopCallback;
}KTimer_ST;
KTimer_ST g_stKtimerBuffer[4] = {{.bIsGoing=false}, {.bIsGoing=false}, {.bIsGoing=false}, {.bIsGoing=false}};
//可用于过零检测延时使用
void kTimerInit(TIMER_ENUM timer, bool bIsOneShot, uint32_t time_us)
{
/* Enable clock for TIMER0 module */
CMU_ClockEnable(kclock[timer], true);
//CMU_ClockEnable(cmuClock_HCLK, true); //开启高速外设时钟
CMU_ClockSelectSet(kclock[timer], cmuSelect_HFXO);
/* Select TIMER0 parameters */
TIMER_Init_TypeDef timerInit =
{
.enable= false,//by kid
.debugRun= true,
.prescale= timerPrescale8,
.clkSel = timerClkSelHFPerClk,
.fallAction = timerInputActionNone,
.riseAction = timerInputActionNone,
.mode = timerModeUp,
.dmaClrAct= false,
.quadModeX4 = false,
.oneShot = bIsOneShot, //单次或循环
.sync= false,
};
// Configure TIMER3 Compare/Capture for output compare
//TIMER_InitCC_TypeDef timerCCInit = TIMER_INITCC_DEFAULT;
//timerCCInit.mode = timerCCModeCompare;
//timerCCInit.cmoa = timerOutputActionNone; // none output on compare match //by kid
/* Configure TIMER */
TIMER_Init(ktimer[timer], &timerInit);
//TIMER_InitCC(TIMER3, 0, &timerCCInit
uint32_t g_u32TimerFreq = CMU_ClockFreqGet(kclock[timer]); /// (timerInit.prescale + 1);
#if defined(TIMER2) && defined(TIMER3)
uint32_t clkFreq = CMU_ClockFreqGet(cmuClock_HCLK);
#else
uint32_t clkFreq = CMU_ClockFreqGet(cmuClock_HFPER);
#endif
iKonkeAfSelfPrint("\r\n\r\n######TIMER%d freq = %d clkFreq = %d #######\r\n", timer, g_u32TimerFreq, clkFreq);
// Set compare value to the first compare value
// lastcount = time_ms;
// TIMER_CompareSet(TIMER3, 0, time_ms);
// Set Top value
// Note each overflow event constitutes 1/2 the signal period
g_u32TimerFreq = CMU_ClockFreqGet(kclock[timer])/(timerInit.prescale + 1);
uint32_t topValue = (uint32_t)(g_u32TimerFreq / 1000000.0 * (time_us));
// uint32_t topValue = timerFreq * time_us;
TIMER_TopSet (ktimer[timer], topValue);
// Enable TIMER3 interrupts
//TIMER_IntEnable(TIMER3, TIMER_IEN_CC0);
TIMER_IntEnable(ktimer[timer], TIMER_IF_OF);
NVIC_EnableIRQ(kTimerIRQn[timer]);
// Enable the TIMER
TIMER_Enable(ktimer[timer], true);
}
#if defined(TIMER2) && defined(TIMER3)
void TIMER2_IRQHandler(void)
{
uint32_t flags = TIMER_IntGet(TIMER2);
TIMER_IntClear(TIMER2, flags);
//test_timer3 ++ ;
//LED_OPT_TOGGLE(5);
if (g_stKtimerBuffer[KTIMER2].pollCallback){
g_stKtimerBuffer[KTIMER2].pollCallback();
}
if (g_stKtimerBuffer[KTIMER2].bIsOneShot) {
g_stKtimerBuffer[KTIMER2].bIsGoing = false;
}
}
void TIMER3_IRQHandler(void)
{
uint32_t flags = TIMER_IntGet(TIMER3);
TIMER_IntClear(TIMER3, flags);
//test_timer3 ++ ;
//LED_OPT_TOGGLE(5);
if (g_stKtimerBuffer[KTIMER3].pollCallback){
g_stKtimerBuffer[KTIMER3].pollCallback();
}
if (g_stKtimerBuffer[KTIMER3].bIsOneShot) {
g_stKtimerBuffer[KTIMER3].bIsGoing = false;
}
}
#endif
void TIMER1_IRQHandler(void)
{
uint32_t flags = TIMER_IntGet(TIMER1);
TIMER_IntClear(TIMER1, flags);
//test_timer3 ++ ;
//LED_OPT_TOGGLE(5);
if (g_stKtimerBuffer[KTIMER1].pollCallback){
g_stKtimerBuffer[KTIMER1].pollCallback();
}
if (g_stKtimerBuffer[KTIMER1].bIsOneShot) {
g_stKtimerBuffer[KTIMER1].bIsGoing = false;
}
}
//do not use timer0
void kTimerStart(TIMER_ENUM timer, bool bIsOneShot, uint32_t time_us, pTimerPollCallback start_callback, pTimerPollCallback stop_callback)
{
if (g_stKtimerBuffer[timer].bIsGoing != true || g_stKtimerBuffer[timer].bIsOneShot == true) {
g_stKtimerBuffer[timer].bIsGoing = true;
g_stKtimerBuffer[timer].bIsOneShot = bIsOneShot;
g_stKtimerBuffer[timer].pollCallback = start_callback;
g_stKtimerBuffer[timer].stopCallback = stop_callback;
kTimerInit(timer, bIsOneShot, time_us);
} else {
iKonkeAfSelfPrint("Err: Timer[%d] is already used\r\n", timer);
}
}
void kTimerStop(TIMER_ENUM timer)
{
if (g_stKtimerBuffer[timer].bIsGoing == true) {
NVIC_ClearPendingIRQ(kTimerIRQn[timer]);
NVIC_DisableIRQ(kTimerIRQn[timer]);
// Disable the TIMER
TIMER_Enable(ktimer[timer], false);
}
g_stKtimerBuffer[timer].bIsGoing = false;
if (g_stKtimerBuffer[timer].stopCallback){
g_stKtimerBuffer[timer].stopCallback();
}
}
bool kTimerIsGoing(TIMER_ENUM timer)
{
return g_stKtimerBuffer[timer].bIsGoing;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment