here is my main file
/* * nec decoder.c * * Created: 11-05-2020 20:13:54 * Author : jeet */ #define F_CPU 16000000UL #include <avr/io.h> #include <stdio.h> #include <stdbool.h> #include <avr/interrupt.h> #include "uart.h" #include "ir_nec.h" static int uart_putchar(char c, FILE *stream); static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,_FDEV_SETUP_WRITE); static int uart_putchar(char c, FILE *stream) { if (c == '\n') uart_putchar('\r', stream); loop_until_bit_is_set(UCSR0A, UDRE0); UDR0 = c; return 0; } int main(void) { UART_Initialize(); stdout = &mystdout; IR_Initialize(); sei(); while (1) { IR_ProcessData(); if (nec_new_data == true || nec_current_status == PACKET_RECVD_N_REPEAT_RECVNG) { nec_new_data = false; printf("nec_addrh=%u nec_addrl=%u nec_cmd=%u nec_cmdinv=%u\n",nec_current_packet.addr_h,nec_current_packet.addr_l,nec_current_packet.cmd,nec_current_packet.cmd_inv); } } }
here is uart.h
#ifndef UART_H #define UART_H #define BAUD 57600 #define UBBR_VALUE (uint16_t)(F_CPU/(16UL*BAUD) - 1) inline void UART_Initialize(void); #endif
here is my uart.c
#include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include <stdio.h> #include "uart.h" inline void UART_Initialize() { UBRR0H = (uint8_t) (UBBR_VALUE >> 8); UBRR0L = (uint8_t) UBBR_VALUE; UCSR0B = (1 << RXEN0) | (1 << TXEN0); UCSR0C = (1 << UPM01) | (1 << UCSZ01) | (1 << UCSZ00) | (1 << USBS0); //STOP BIT 2 DATA 8 BIT PARITY EVEN }
here is ir_nec.h
#ifndef IR_NEC_H #define IR_NEC_H #define IR_TSOP_DDR DDRB #define IR_TSOP_PIN 0 #define IR_START_TIME_H 30000 #define IR_START_TIME_L 25000 #define IR_LOW_TIME_H 2400 #define IR_LOW_TIME_L 1800 #define IR_HIGH_TIME_H 4800 #define IR_HIGH_TIME_L 4000 #define IR_REPEAT1_TIME_H 24000 #define IR_REPEAT1_TIME_L 20000 #define IR_REPEAT2_TIME_H 65000 #define IR_REPEAT2_TIME_L 62000 #define IR_ICR_BUFFER_SIZE 20 struct nec_packet{ uint8_t addr_l; uint8_t addr_h; uint8_t cmd; uint8_t cmd_inv; }; struct circular_q{ uint16_t buffer[IR_ICR_BUFFER_SIZE]; uint8_t read_index; uint8_t write_index; }; enum circular_q_status{ EMPTY = 0, OK, OVERFLOW }; enum nec_status{ PACKET_RECVD = 0, PACKET_RECVD_N_REPEAT_RECVNG, IDLE, TIMING_ERR, CHKSM_ERR }; extern volatile struct nec_packet nec_current_packet; extern volatile struct circular_q icr_buffer; extern volatile enum nec_status nec_current_status; extern volatile enum circular_q_status icr_buffer_status; extern volatile bool nec_new_data; inline void IR_Initialize(void); inline void IR_DeInitialize(void); void IR_ProcessData(void); inline void IR_WriteBuffer(uint16_t data); uint16_t IR_ReadBuffer(void); void IR_FlushBuffer(void); #endif
here is ir_nec.c
#include <avr/io.h> #include <string.h> #include <avr/interrupt.h> #include <util/atomic.h> #include <stdbool.h> #include <util/delay.h> #include <stdio.h> #include "ir_nec.h" volatile struct nec_packet nec_current_packet = { .addr_l = 0, .addr_h = 0, .cmd = 0, .cmd_inv = 0 }; volatile struct circular_q icr_buffer = { .buffer = {0}, .read_index = 0, .write_index = 0 }; volatile enum nec_status nec_current_status = IDLE; volatile enum circular_q_status icr_buffer_status = EMPTY; volatile bool nec_new_data = false; static volatile uint8_t nec_current_state = 0; static volatile uint8_t repeat_timer = 0; inline void IR_Initialize() { TCCR1B = (1 << ICNC1) | (1 << CS11); //PRESCALER SET TO 8, NEGATIVE EDGE DETECTION ENABLE AND NOISE CANCELLER ENABLED TIMSK1 = (1 << ICIE1) | (1 << TOIE1); //ENABLE INPUT CAPTURE AND TIMER OVERFLOW INTERUPT } inline void IR_DeInitialize() { TCCR1B = 0; TIMSK1 = 0; } ISR (TIMER1_CAPT_vect) { TCNT1 = 0; repeat_timer = 0; IR_WriteBuffer(ICR1); } ISR(TIMER1_OVF_vect) { if (nec_current_status == PACKET_RECVD_N_REPEAT_RECVNG) repeat_timer++; if (repeat_timer == 4) { nec_current_state = 0; nec_current_status = IDLE; } } void IR_FlushBuffer(void) { ATOMIC_BLOCK(ATOMIC_FORCEON) { memset((void *)icr_buffer.buffer,0,sizeof(icr_buffer)); icr_buffer.read_index = 0; icr_buffer.write_index = 0; icr_buffer_status = EMPTY; nec_current_state = 0; } } inline void IR_WriteBuffer(uint16_t data) { icr_buffer.buffer[icr_buffer.write_index] = data; if (icr_buffer.write_index == IR_ICR_BUFFER_SIZE - 1) icr_buffer.write_index = 0; else icr_buffer.write_index++; if (icr_buffer.write_index == icr_buffer.read_index) icr_buffer_status = OVERFLOW; else icr_buffer_status = OK; } uint16_t IR_ReadBuffer() { uint16_t icr_copy; ATOMIC_BLOCK(ATOMIC_FORCEON) { icr_copy = icr_buffer.buffer[icr_buffer.read_index]; if (icr_buffer.read_index == IR_ICR_BUFFER_SIZE - 1) icr_buffer.read_index = 0; else icr_buffer.read_index++; if (icr_buffer.read_index == icr_buffer.write_index) icr_buffer_status = EMPTY; else icr_buffer_status = OK; } return icr_copy; } void IR_ProcessData() { uint16_t icr_copy; if (icr_buffer_status == OK) { icr_copy = IR_ReadBuffer(); nec_current_state++; if (nec_current_state == 2) { if (!(icr_copy <= IR_START_TIME_H && icr_copy >= IR_START_TIME_L)) { nec_current_state = 0; nec_current_status = TIMING_ERR; } } else if (nec_current_state <= 34 && nec_current_state >= 3) { if (icr_copy <= IR_HIGH_TIME_H && icr_copy >= IR_HIGH_TIME_L) { if (nec_current_state <= 10) nec_current_packet.addr_l |= (1 << (nec_current_state - 3)); else if (nec_current_state <= 18) nec_current_packet.addr_h |= (1 << (nec_current_state - 11)); else if (nec_current_state <= 26) nec_current_packet.cmd |= (1 << (nec_current_state - 19)); else nec_current_packet.cmd_inv |= (1 << (nec_current_state - 27)); } else if (icr_copy <= IR_LOW_TIME_H && icr_copy >= IR_LOW_TIME_L) { if (nec_current_state <= 10) nec_current_packet.addr_l &= ~(1 << (nec_current_state - 3)); else if (nec_current_state <= 18) nec_current_packet.addr_h &= ~(1 << (nec_current_state - 11)); else if (nec_current_state <= 26) nec_current_packet.cmd &= ~(1 << (nec_current_state - 19)); else nec_current_packet.cmd_inv &= ~(1 << (nec_current_state - 27)); } else { nec_current_state = 0; nec_current_status = TIMING_ERR; } } else if (nec_current_state == 35) { if (nec_current_packet.cmd == (unsigned char)~(nec_current_packet.cmd_inv)) { nec_current_status = PACKET_RECVD; nec_new_data = true; } else { nec_current_state = 0; nec_current_status = CHKSM_ERR; } } else if (nec_current_state == 36) { if (!(icr_copy <= IR_REPEAT1_TIME_H && icr_copy >= IR_REPEAT1_TIME_L)) { if (icr_copy <= IR_START_TIME_H && icr_copy >= IR_START_TIME_L) { nec_current_state = 2; } else { nec_current_state = 0; nec_current_status = TIMING_ERR; } } } else if (nec_current_state == 37) { if (icr_copy <= IR_REPEAT2_TIME_H && icr_copy >= IR_REPEAT2_TIME_L) { nec_current_state = 35; nec_current_status = PACKET_RECVD_N_REPEAT_RECVNG; } else if (icr_copy <= IR_START_TIME_H && icr_copy >= IR_START_TIME_L) { nec_current_state = 2; } else { nec_current_state = 0; nec_current_status = TIMING_ERR; } } } else if (icr_buffer_status == OVERFLOW) { IR_FlushBuffer(); } }
the compiler gives me an error that function declared but never defined
I'm using as 7.0