?? letext_324.c
字號(hào):
/* +-------------------------------------------------------------------+ */
/* | Project : 1910.001 441GA01-T (External Reader RFID 125KHz) | */
/* | Module : LetExt_324.c | */
/* | Author : Lucio Faustinelli | */
/* | Company : AVE S.p.A. | */
/* | Released: June, 27 2008 | */
/* | Revision: YZ060.01 (FW - Revised) | */
/* | Revision: YZ062.00 (EEPROM - First Official Release) | */
/* | Revised : September, 04 2008 | */
/* | Revisor : AVE S.p.A. (Lucio FAUSTINELLI) | */
/* | Notes : -------------- | */
/* +-------------------------------------------------------------------+ */
/* | Purpose : This module contains all the functions needed to manage | */
/* | the external card reader (included ISR routines) | */
/* +-------------------------------------------------------------------+ */
/* | Resources: TIMER0: Generates system tick (baser timers) | */
/* | TIMER2: Manages timeouts for the room bus (RS-485) | */
/* | USART0: Allows data communication to/from other devices| */
/* +-------------------------------------------------------------------+ */
/* | Functions: ISR( USART0_RX_vect ) | */
/* | ISR( TIMER0_COMPA_vect ) | */
/* | ISR( TIMER2_COMPA_vect ) | */
/* | ISR( TIMER2_COMPB_vect ) | */
/* +-------------------------------------------------------------------+ */
/* | void cardIsNotOK( void ) | */
/* | void cardIsOK( uint8_t setType ) | */
/* | uint8_t tryAccessByZone( void ) | */
/* | uint8_t readInput( void ) | */
/* | int main( void ) | */
/* | void rstNoMaster( uint8_t sendReset ) | */
/* | void cardIsMaster( void ) | */
/* | void next_led_st( uint8_t, uint8_t, uint8_t ) | */
/* | void nextMasterState( uint8_t typ ) | */
/* | uint8_t ManageMaster( void ) | */
/* | void luci_OFF( void ) | */
/* | void luci_ON( uint8_t timed ) | */
/* | void onSerratura( void ) | */
/* | void buzzer_on( void ) | */
/* | void _LED_( uint8_t led_on, uint8_t led_off ) | */
/* | void delay_us( uint16_t __count ) | */
/* | void delay_ms( uint8_t t ) | */
/* | void search4commands( void ) | */
/* | void put485( uint8_t * s ) | */
/* | void tx_485frame( void ) | */
/* | uint8_t* put_CM( uint8_t *p ) | */
/* | void compute_CRC( uint8_t *s ) | */
/* | uint8_t analyse_cmd485( uint8_t *s ) | */
/* | void send_PC_resp( uint8_t *s ) | */
/* | void analyze_res485( uint8_t *s ) | */
/* | void tx_485resp( uint8_t *s ) | */
/* | uint8_t check_485addr( uint8_t * s ) | */
/* | uint8_t check_CRC( uint8_t *s, uint8_t len ) | */
/* | uint8_t get485( uint8_t * s ) | */
/* | void initTIMER0( void ) | */
/* | void initTIMER2( void ) | */
/* | void startT2( uint8_t AorB ) | */
/* | void initUART0( uint16_t baud ) | */
/* | void putc0( uint8_t c ) | */
/* | uint8_t getc0( void ) | */
/* +-------------------------------------------------------------------+ */
/* +-------------------------------------------------------------------+ */
/* | F W R E V I S I O N S | */
/* +-------------------------------------------------------------------+ */
// R e v i s i o n 0 0
// =====================
// Prima release ufficiale
/* +-------------------------------------------------------------------+ */
/* | I N C L U D E S | */
/* +-------------------------------------------------------------------+ */
// G L O B A L
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/crc16.h>
#include <avr/boot.h>
#include <avr/sleep.h>
// L O C A L S
#include "LetExtDef.h"
#include "CardMifare.h"
/* +-------------------------------------------------------------------+ */
/* | D E F I N E S | */
/* +-------------------------------------------------------------------+ */
// C P U C l o c k
#ifndef F_CPU
#define F_CPU 11059200L
#endif
// C o m p u t e O C R v a l u e
#define NCHAR_10 39L // uguale a 11 *3.5
#define T2_PRESCALER 32L
#define BUZ_FREQ 9000L
#define _STOPTIMER2 ( TCCR2B &= ~( _BV( CS22 ) | _BV( CS21 ) | _BV( CS20 ) ) )
// C o m p u t e T I M E ( T I M E R 0 )
#define TIMER0_FREQUENCY 50 // 10ms
#define TIMER0_PRESCALER 1024UL // 1, 8, 64, 256, 1024
#define TIMER0_OCR_VALUE ( ( F_CPU / ( 2 * TIMER0_PRESCALER * TIMER0_FREQUENCY ) ) - 1 )
#define T_SECONDO 100 /**< Tempo per determinare 1 secondo a 10ms/step */
#define T_DUEC 20 /**< Tempo per determinare 200ms a 10ms/step */
#define T_Off_LBG 195 /**< Tempo led BG off quando in idle */
#define T_On_L_BG 5 /**< Tempo led BG on qunado in idle */
// U A R T D E F I N E S
#define BAUDRATE0 57600L /**< baud rate to 485 */
#define ONE_TIMESTOP ( BAUDRATE0 / NCHAR_10 )
#define MAXB485 64 /**< maximum input/output buffer of 485 bus */
#define MASKBUF 0x3f /**< mask for pointer increment */
/* +-------------------------------------------------------------------+ */
/* | S T R U C T U R E S | */
/* +-------------------------------------------------------------------+ */
// Structure for system LED management (except backlight LED)
typedef struct {
uint8_t LM_on; /**< defined led on */
uint8_t LM_off; /**< defined led off */
uint8_t LM_tim; /**< define time to next state */
led_num LM_nex; /**< define next state */
} LED_MACHINE;
/* +-------------------------------------------------------------------+ */
/* | E X T V A R I A B L E S | */
/* +-------------------------------------------------------------------+ */
// R O M I t e m s
extern prog_uint8_t FWrev; // Software revision
extern prog_uint8_t FWvers; // Hardware revision
// R A M I t e m s
extern volatile uint8_t LI_STATUS;
extern volatile uint8_t card_type;
/* +-------------------------------------------------------------------+ */
/* | M O D U L E V A R I A B L E S | */
/* +-------------------------------------------------------------------+ */
// R O M I t e m s
const char ID[] PROGMEM = "RFID 125kHz Reader AVE S.p.A (C) 2007"; /* copyright */
// R A M I t e m s
uint8_t configChanged = 0;
uint8_t msgRetry = 0;
uint8_t statusIn;
volatile uint8_t lm_st; /* location when store led status machine */
volatile uint8_t lm_ti = 0; /* counter to execute led status, when 0 use lm_ol */
volatile uint8_t lm_ol = 0; /* new status when lm_ti == 0 */
volatile uint8_t card_is = RF_IDLE; /* riporta lo stato della card */
volatile uint8_t mast_is = MS_ONE;
volatile uint8_t mode_is = MO_CAMERA; /* define the mode, STANZA, AREA COMUNE, ACCESSO A SCALARE */
volatile uint16_t clima_on = 0x00;
volatile uint16_t luci_on = 0x00; /* tempo di disattivazione luce cortesia, secondi */
volatile uint8_t NoMaster = 0x00; /* in master mode la carta si e' allontanata =1 */
volatile uint8_t masterT;
volatile uint8_t masT_tmp;
volatile uint8_t B_RingOn = 0; /* one when ringing is on */
volatile uint8_t B_TimeOK = 0; /* one when time is sincronized by centrale */
volatile uint8_t B_CentOK = 0; /* one when centrale is present */
volatile uint8_t B_LetinOK = 0; /* one when lettore interno is present */
volatile uint8_t B_TermoOK = 0; /* one when termostato rilevato sul bus */
volatile uint8_t buz_cnt = 0; /* how many buzzer on? 1=normal, 3=error */
volatile uint8_t devicesOnARMBus = 0;
volatile uint8_t localOpenLck = 0;
// C A R D D A T A V A R S
uint8_t cardMode, cardGenerated;
volatile uint32_t RF_code[6] = { 0L, 0L, 0L, 0L, 0L, 0L };
volatile uint16_t card_imp = 0; /* CI = codice impianto letto dalla carta */
volatile uint16_t card_room = 0; /* CC = codice camera letto dalla carta */
volatile uint8_t card_cc_cam = 0; /* CC_CAM = parte di card_room (0x007F) */
volatile uint8_t card_cc_zona = 0; /* CC_ZONA = parte di card_room (0x0F00)>>8 */
volatile uint8_t card_cc_sub = 0; /* CC_SUB = parte di card_room (0x7000)>>12 */
volatile uint16_t card_incclie = 0; /* CL = codice incrementale cliente letto dalla carta */
volatile uint8_t card_subci = 0; /* SUB_CI = codice sub impianto */
volatile uint8_t card_type = 0; /* TY = codice type letto dalla carta */
volatile uint8_t card_HF = 0; /* HF = codice ora fine carta letto dalla carta */
volatile uint8_t card_GF = 0; /* GF = codice giorno fine carta letto dalla carta */
volatile uint8_t card_MF = 0; /* MF = codice mese fine carta letto dalla carta */
volatile uint8_t card_AF = 0; /* AF = codice anno fine carta letto dalla carta */
volatile uint8_t card_GAB = 0; /* GAB = giorni abilitati (bit) */
volatile uint8_t card_GI = 0; /* GI = codice giorno inizio */
volatile uint8_t card_MI = 0; /* MI = codice mese inizio */
volatile uint8_t card_AI = 0; /* AI = codice anno inizio */
volatile uint8_t card_FLAG = 0; /* FLAG = Usato dalla Master x gestione Tempi */
volatile uint8_t card_GEN = 0; /* GEN = modalita` genere M o F */
volatile uint8_t card_MAC = 0; /* MAC = modalita` accesso a fascie orarie */
volatile uint8_t card_HH_I = 0; /* HH_I = modalita` ora inizio fascia oraria */
volatile uint8_t card_MM_I = 0; /* MM_I = modalita` minuti inizio fascia oraria */
volatile uint8_t card_HH_F = 0; /* HH_F = modalita` ora fine fascia oraria */
volatile uint8_t card_MM_F = 0; /* MM_F = modalita` minuti fine fascia oraria */
// E E P R O M D A T A V A R S
volatile uint16_t lo_imp = 0; /* codice impianto memorizzato in eeprom */
volatile uint8_t lo_subci = 0; /* codice sub impianto memorizzato in eeprom */
volatile uint16_t lo_room = 0; /* codice camera memorizzato in eeprom */
volatile uint8_t lo_cc_cam = 0; /* codice camera recuperato da eeprom */
volatile uint8_t lo_cc_zona = 0; /* codice camera zona recuperato da eeprom */
volatile uint8_t lo_cc_sub = 0; /* codice camera sub recuperato da eeprom */
volatile uint16_t lo_inccl = 0; /* codice incrementale memorizzato in eeprom */
volatile uint8_t pin_change = 0; /* counter for pin change (SC_OUT) */
// buffer rx from 485 - USART0
volatile char pcRxBuf[MAXB485]; /* received buffer from 485 bus - used in interupt */
volatile uint8_t pc0Wr = 0; /* write pointer to pcRxBuf */
volatile uint8_t pc0Rd = 0; /* read pointer to pcRxBuf */
volatile uint8_t T2OVFV; /* flagw to define 485 intercaracter timeout */
// buffer tx to 485 - USART0
char pcTxBuf[MAXB485 / 2]; /* buffer to memorize the TX frame */
// system timer location
volatile uint32_t time = 0L; /* time location - 1s tic */
volatile uint8_t tled = 0; /* timer of binking led BG, 10ms unit, 2,54 sec max */
volatile uint8_t tout = 0; /* used in the card process to compute timeout */
volatile uint8_t tdel = 0; /* used in delay subrouties to compute time 1=10ms */
volatile uint8_t tmain; /* used in main to compute 1 second timeout */
volatile uint8_t t200; /* used in main to compute 1 second timeout */
volatile uint8_t tbuz = 0; /* used to compute buzzer timeout */
volatile uint16_t tminuto = 0; /* used in main to compute time */
volatile uint8_t LI_STATUS; /* define the module status (master or slave) */
uint8_t doIncrement;
uint16_t t_doorbell;
uint8_t t_doorbell_F;
uint8_t validCardLI = 0;
uint8_t fOpened = 0, oCard = 0;
volatile uint8_t tmrRXinProgress = 0;
volatile uint8_t tmrLetInt, tmrTermo;
volatile uint8_t setNewVars = 0;
// Init of the internal EEPROM with the default data values
uint16_t EECodiceHotel EEMEM = 0x0000; /* codice hotel di default .. non ancora inizializzato */
uint16_t EECodiceCamera EEMEM = 0x0000; /* camera di default .. non ancora inizializzata */
uint16_t EECodiceClient EEMEM = 0x0000; /* codice incrementale cliente */
uint8_t EECodiceSubci EEMEM = 0x00; /* codice subci di default .. non ancora inizializzato */
uint8_t EECodiceLivell EEMEM = 0x00; /* livelli di accesso */
uint8_t EEEletOffOn EEMEM = EVEletOffOn; /* tempo timeout spegnimento elettroserratura (254 sec max) */
uint8_t EERFCardTOut EEMEM = EVRFCardTOut; /* tempo timeout gestione carta master (254 sec max) */
uint8_t EEDlyRunTime EEMEM = EVDlyRunTime; /* tempo timeout dalla partenza del modulo 10ms*tick(254 tick max) */
uint8_t EELuciOffOut EEMEM = EVLuciOffOut; /* tempo timeout spegnimento luci uscita stanza (254 sec max) */
uint8_t EE_MM_AC EEMEM = 0x00; /* indice accesso aree comuni */
uint8_t EE_MM_ACS EEMEM = 0x00; /* indice accesso aree a scalare */
uint8_t EEMODE_IS EEMEM = MO_CAMERA; /* Modo operativo */
uint8_t EEST_CA_LO EEMEM = 0x00; /* memorizza stato camera. se 1 gia visto una volta a zero */
// D o o r b e l l I t e m s
uint8_t EEToutDoorB EEMEM = 10;
uint8_t EEAlwaysDoorB EEMEM = 0x01;
uint8_t EEMyAddress EEMEM = 0x00;
// F I R M W A R E V E R S I O N
prog_uint8_t FWvers = 0x80;
// F I R M W A R E R E V I S I O N
prog_uint8_t FWrev = 0x00;
volatile uint32_t uniquecode;
/* +-------------------------------------------------------------------+ */
/* | S T A T U S H A N D L E R S | */
/* +-------------------------------------------------------------------+ */
volatile LED_MACHINE lm_stat[] = {
{ LED_BG|LED_BR|LED_R|LED_Y, 0, 100, LD01 }, /**< 00 = poweron, all led on, next normal */
{ 0, LED_BG|LED_BR|LED_R|LED_Y, 190, LD02 }, /**< 01 = off normal state */
{ LED_BG, LED_BR|LED_R|LED_Y, 10, LD01 }, /**< 02 = on normal state */
{ 0, LED_BG|LED_BR|LED_R|LED_Y, 190, LD04 }, /**< 03 = off virgin state */
{ LED_BR, LED_BG|LED_R|LED_Y, 10, LD03 }, /**< 04 = on virgin state */
{ LED_BG, LED_BR|LED_R|LED_Y, 100, LD02 }, /**< 05 = led green on */
{ LED_BR, LED_BG|LED_R|LED_Y, 100, LD02 }, /**< 06 = led red on */
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -