Skip to content

Commit

Permalink
Added Atmel MCU tag firmware code
Browse files Browse the repository at this point in the history
  • Loading branch information
WildSpyAdmin committed Apr 30, 2020
1 parent 0a04ea4 commit a4313c4
Show file tree
Hide file tree
Showing 43 changed files with 5,902 additions and 0 deletions.
Empty file.
20 changes: 20 additions & 0 deletions Tag/Device_Firmware/V0.2.1/WIDTag.avrsln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# AvrStudio Solution File, Format Version 11.00
Project("{D1100916-62DA-4D80-A9B4-55A1E7CCEEB3}") = "WIDTag", "WIDTag\WIDTag.avrgccproj", "{77BCDBD5-EB6F-4198-9537-80123C2374B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AVR = Debug|AVR
Release|AVR = Release|AVR
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{77BCDBD5-EB6F-4198-9537-80123C2374B8}.Debug|AVR.ActiveCfg = Debug|AVR
{77BCDBD5-EB6F-4198-9537-80123C2374B8}.Debug|AVR.Build.0 = Debug|AVR
{77BCDBD5-EB6F-4198-9537-80123C2374B8}.Release|AVR.ActiveCfg = Release|AVR
{77BCDBD5-EB6F-4198-9537-80123C2374B8}.Release|AVR.Build.0 = Release|AVR
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added Tag/Device_Firmware/V0.2.1/WIDTag.avrsuo
Binary file not shown.
71 changes: 71 additions & 0 deletions Tag/Device_Firmware/V0.2.1/WIDTag/Includes/M_NRF24L01.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* M_NRF24L01.h
*
* Created on: 09/03/2010
* Author: Matty
*/

#ifndef M_NRF24L01_H_
#define M_NRF24L01_H_

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>


//Pins:
#define CSN1 2
#define CE1 1
#define NRF_MISO 4
#define NRF_MOSI 3
#define NRF_SCK 5


//nRF24L01 Registers:
#define NREG_CONFIG 0x00
#define NREG_EN_AA 0x01
#define NREG_EN_RXADDR 0x02
#define NREG_SETUP_AW 0x03
#define NREG_SETUP_RETR 0x04
#define NREG_RF_CH 0x05
#define NREG_RF_SETUP 0x06
#define NREG_STATUS 0x07
#define NREG_OBSERVE_TX 0x08
#define NREG_RPD 0x09
#define NREG_RX_ADDR_P0 0x0A //5 bytes
#define NREG_RX_ADDR_P1 0x0B //5 bytes
#define NREG_RX_ADDR_P2 0x0C
#define NREG_RX_ADDR_P3 0x0D
#define NREG_RX_ADDR_P4 0x0E
#define NREG_RX_ADDR_P5 0x0F
#define NREG_TX_ADDR 0x10 //5 bytes
#define NREG_RX_PW_P0 0x11
#define NREG_RX_PW_P1 0x12
#define NREG_RX_PW_P2 0x13
#define NREG_RX_PW_P3 0x14
#define NREG_RX_PW_P4 0x15
#define NREG_RX_PW_P5 0x16
#define NREG_FIFOSTATUS 0x17

//Macros:
#define NRF_POWERDOWN NRF24L01_SetMode(0,1)
#define NRF_RXMODE NRF24L01_SetMode(1,1)
#define NRF_TXMODE NRF24L01_SetMode(1,0)

//Function Prototypes
void NRF24L01_SPI_Setup( );
void NRF24L01_SPI_TX(uint8_t);
uint8_t NRF24L01_SPI_RX( );
void NRF24L01_W_Reg(uint8_t , uint8_t);
void NRF24L01_W_Reg_Long(uint8_t , uint8_t* , uint8_t);
uint8_t NRF24L01_R_Reg(uint8_t);
void NRF24L01_R_Reg_Long(uint8_t , uint8_t* , uint8_t);
uint8_t NRF24L01_TX_PAYLOAD(uint32_t*);
//uint8_t NRF24L01_R_RX_PAYLOAD(uint32_t*);
void NRF24L01_SetupnRF24L01(uint8_t, uint8_t*);
void NRF24L01_SetMode(uint8_t , uint8_t);
void NRF24L01_Flush_RX_FIFO( );
void NRF24L01_Flush_TX_FIFO( );


#endif /* M_NRF24L01_H_ */
44 changes: 44 additions & 0 deletions Tag/Device_Firmware/V0.2.1/WIDTag/Includes/M_PRTC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* M_PRTC.h
*
* Created on: 04/09/2010
* Author: MC
*/

#ifndef M_PRTC_H_
#define M_PRTC_H_

#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>

struct RTCTime {
uint8_t Second;
uint8_t Minute;
uint8_t Hour;

uint8_t Day;
uint8_t Month;
int Year;
};


//Function Prototypes:
void RTC_Setup();
uint16_t RTC_GetCNT();
uint8_t IntToBCD(uint8_t);
uint8_t BCDToInt(uint8_t);
void CopyTime (struct RTCTime*, struct RTCTime*);
void AddTimes(struct RTCTime*, struct RTCTime*);
void ClearTime(struct RTCTime*);
uint8_t CompareTimes (struct RTCTime* , struct RTCTime* );
//uint8_t FirstTimeGreater (struct RTCTime* , struct RTCTime* );
uint8_t ValidDateTime(struct RTCTime*);
uint8_t DaysInMonth(uint8_t , uint8_t );
int str2Time(char*, struct RTCTime*);
void sPrintTime(char*, struct RTCTime* , char*);
void ZipTime(struct RTCTime*, uint8_t*);
void UnzipTime(struct RTCTime*, uint8_t*);

#endif /* M_PRTC_H_ */
93 changes: 93 additions & 0 deletions Tag/Device_Firmware/V0.2.1/WIDTag/Includes/M_USART.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* M_USART.h
*
* Created on: 22/01/2010
* Author: Matthew Cochrane
*/

#ifndef M_USART_H_
#define M_USART_H_

//Includes
#include <avr/io.h>
#include <avr/pgmspace.h>

//Defines
//Register & Bit Defines - These need to be altered for your specific chip
#define UDRRRegH UBRR0H
#define UDRRRegL UBRR0L
#define UCSRAReg UCSR0A
#define UCSRBReg UCSR0B
#define UCSRCReg UCSR0C
#define UDRReg UDR0
#define U2XBit U2X0
#define RXENBit RXEN0
#define TXENBit TXEN0
#define UCSZ0Bit UCSZ00
#define UCSZ1Bit UCSZ01
#define UDREBit UDRE0
#define RXCBit RXC0
//Formatting and Escape Sequences
#define ECC_COL_BLACK "0"
#define ECC_COL_RED "1"
#define ECC_COL_GREEN "2"
#define ECC_COL_YELLOW "3"
#define ECC_COL_BLUE "4"
#define ECC_COL_MAGENTA "5"
#define ECC_COL_CYAN "6"
#define ECC_COL_WHITE "7"
#define ECC_COL_RESET "9"
#define ESC_FG "3"
#define ESC_BG "4"
#define ESC_FONT_NORMAL "0" //ALL attributes off
#define ESC_FONT_BOLD "1"
#define ESC_FONT_ITALIC "3" //Not widely supported. Sometimes treated as inverse.
#define ESC_FONT_UNDERLINE "4"
#define ESC_FONT_NOUNDERLINE "24"
#define ESC_FONT_2XUNDERLINE "21" //Not widely supported
#define ESC_INTENSITY_FAINT "2" //Not widely supported
#define ESC_INTENSITY_NORMAL "22" //Not bold and not faint
#define ESC_BLINK_SLOW "5" //less than 150 per minute
#define ESC_BLINK_RAPID "6" //more than 150 per minute
#define ESC_BLINK_OFF "25"
#define ESC_IMG_NEG "7" //Inverse - swap foreground and background colours
#define ESC_IMG_POS "27"
#define ESC_CONCEAL "8" //Not widely supported. Hides any further writing
#define ESC_REVEAL "28" //conceal off

//Macros
#define ESC_COL(type,col) type col
#define ESC_SGR1(var1) "\x1B[" var1 "m"
#define ESC_SGR2(var1, var2) "\x1B[" var1 ";" var2 "m"
#define ESC_SGR3(var1, var2, var3) "\x1B[" var1 ";" var2 ";" var3 "m"
#define ESC_SGR4(var1, var2, var3, var4) "\x1B[" var1 ";" var2 ";" var3 ";" var4 "m"
#define ESC_SGR5(var1, var2, var3, var4, var5) "\x1B[" var1 ";" var2 ";" var3 ";" var4 ";" var5 "m"
#define ESC_MOV_CUR_UP(n) "\x1B[" #n "A"
#define ESC_MOV_CUR_DOWN(n) "\x1B[" #n "B"
#define ESC_MOV_CUR_RIGHT(n) "\x1B[" #n "C"
#define ESC_MOV_CUR_LEFT(n) "\x1B[" #n "D"
#define ESC_MOV_CUR_ROW(n) "\x1B[" #n "A"
#define ESC_MOV_CUR_COL(n) "\x1B[" #n "A"
#define ESC_MOV_CUR(x,y) "\x1B[" #y ";" #x "H" //Row x, Col y
#define ESC_CLS "\x1B[2J"
#define ESC_CLR_LINE "\x1B[2K"
#define ESC_SCROLL_UP(n) "\x1B[" #n "S"
#define ESC_SCROLL_DOWN(n) "\x1B[" #n "T"
#define ESC_GET_CUR_POS "\x1B[6n"
#define ESC_CUR_SAVE "\x1B[s"
#define ESC_CUR_RESTORE "\x1B[u"

#define USART_printf_P(str, ...) do {sprintf_P(s, PSTR(str), __VA_ARGS__); USART_tx_String(s);} while (0)

//Function Prototypes
void USART_Setup(unsigned int, unsigned char);
void USART_tx_Byte(char);
void USART_tx_String(const char *);
void USART_tx_String_P(const char *);
char USART_rx_Byte(unsigned int);
int USART_rx_Byte_nb( void );
unsigned char USART_rx_String(char *, unsigned int);
void USART_UpdateTimers(void);


#endif /* M_USART_H_ */
90 changes: 90 additions & 0 deletions Tag/Device_Firmware/V0.2.1/WIDTag/Includes/WIDTag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* WIDTag.h
*
* Created on: 05/09/2010
* Author: Matthew Cochrane
*/

#ifndef WIDTAG_H_
#define WIDTAG_H_

//Includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include "M_PRTC.h"
#include "M_USART.h"
#include "M_NRF24L01.h"

//Define
#define CPU8MHZ 1
//#define CPU1MHZ 1
#ifdef CPU8MHZ
#define UBRRVAL 0x0067 //for 8MHz (Double Speed)
#define TIMEOUT 253 //aprox 8 seconds
#define NORWAITTIMPRE (1<<CS02)
#define NORWAITTIMOCA 0x4E
#define T0WAIT10MSOCA 0x4D
#endif
#ifdef CPU1MHZ
#define UBRRVAL 0x000C //for 1MHz (Double Speed)
#define TIMEOUT 32 //aprox 8 seconds
#define NORWAITTIMPRE (1<<CS01)|(1<<CS00)
#define NORWAITTIMOCA 0x26
#define T0WAIT10MSOCA 0x13
#endif

#define WAKEUP_SOURCE_NONE 0
#define WAKEUP_SOURCE_UART 1
#define WAKEUP_SOURCE_RTC 2

//Addresses V0.2 and after:
#define DEVIDADD 0x10 //a 4-byte integer (uint32_t)
#define DEVARMEDADD 0x17 //a 1-byte integer (uint8_t)
#define RFIDADD 0x30 //a 5-byte unsigned integer (uint8_t[5])
#define RFCHANADD 0x36 //a 1-byte unsigned integer (uint8_t)
#define DTIMEADD 0x52 //a 5-byte compressed structure (zipTime(struct RTCTime))
#define TXPERADD 0x58 //a 1-byte unsigned integer (uint8_t)

/*OLD addresses (pre V0.2):
#define DEVIDADD 0x00 //a 4-byte integer (uint32_t)
#define DEVARMEDADD 0x07 //a 1-byte integer (uint8_t)
#define RFIDADD 0x20 //a 5-byte unsigned integer (uint8_t[5])
#define RFCHANADD 0x25 //a 1-byte unsigned integer (uint8_t)
#define DTIMEADD 0x42 //a 5-byte compressed structure (zipTime(struct RTCTime))
#define TXPERADD 0x47 //a 1-byte unsigned integer (uint8_t)*/

#define ARM_OFF 0
#define ARM_ON 1
#define ARM_DEBUG 2
#define ARM_SHELF 3

//Macros
#define ByteNO(SrcPtr, byteNo) *(((uint8_t*)SrcPtr)+byteNo)

//Function Prototypes
void ShowMenu(void);
uint16_t GetBatVoltage(void);
void ADC_Setup(void);
uint16_t ADC_Read();
void ADC_Stop();
static inline void delay_ms(uint16_t);
//inline void WriteTimeEEPROM(struct RTCTime*, uint16_t);
//inline void ReadTimeEEPROM(struct RTCTime*, uint16_t);
void ReadEEPROM(uint8_t*, uint8_t, uint16_t);
void WriteEEPROM(uint8_t*, uint8_t, uint16_t);
void StartTim10ms(uint16_t);
void StopTim10ms(void);
void HardwareSetup(void);
void ReadAllVarsFromEEPROM(void);
void DevArmSetup();
void TXPayload(void);
void CPUSleep_1m5s(void);

#endif /* WIDTAG_H_ */
Loading

0 comments on commit a4313c4

Please sign in to comment.