I'm facing some trouble trying to create a library that calls "__delay_ms()" inside a function. Made extensive search but couldn't find the solution, nor some other explanations. I'm using XC8 v2.30 MPLAB 5.45.
I have a main function that includes the header "qc3.h":
#include <xc.h> // include standard header file
// set Config bits
#pragma config FOSC=INTOSC, PLLEN=OFF, WDTE=OFF, MCLRE=ON,
#pragma config CLKOUTEN=OFF, IESO=OFF, FCMEN=OFF,CP=OFF, CPD=OFF,BOREN=OFF
#pragma config WRT=OFF,STVREN=ON,BORV=LO,LVP=OFF
// Definitions
#define _XTAL_FREQ 500000 // this is used by the __delay_ms(xx) and __delay_us(xx) functions
#include "qc3.h"
#define LED PORTAbits.RA2
//**********************************************************************************
//***************** main routine ***********************************************
//**********************************************************************************
void main ( )
{
// set up oscillator control register
OSCCONbits.SPLLEN=0; // PLL is disabled
OSCCONbits.IRCF=0x07; //set OSCCON IRCF bits to select OSC frequency=500Khz
OSCCONbits.SCS=0x02; //set the SCS bits to select internal oscillator block
// OSCON should be 0x7Ah now.
// Set up I/O pins
ANSELAbits.ANSELA=0; // set all analog pins to digital I/O
ADCON0bits.ADON=0; // turn ADC off
DACCON0bits.DACEN=0; // turn DAC off
// PORT A Assignments (0 = OUTPUT, 1 = INPUT)
TRISAbits.TRISA0 = 0; // RA0 = nc
TRISAbits.TRISA1 = 0; // RA1 = nc
TRISAbits.TRISA2 = 0; // RA2 = nc
TRISAbits.TRISA3 = 0; // RA3 = nc (MCLR)
TRISAbits.TRISA4 = 0; // RA4 = nc
TRISAbits.TRISA5 = 0; // RA5 = nc
QC3_Initialize(); // incia protocolo para handshake
while(1)
{
__delay_ms(100);
LED = 1;
__delay_ms(100);
LED = 0;
}
}
qc3.h:
#ifndef QC3_H_ /* Include guard */
#define QC3_H_
/**
Section: Included Files
*/
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
//Quick Charge 3 Pin defines
#define DP_HIGH PORTAbits.RA0
#define DM_HIGH PORTAbits.RA1
#define DP_LOW PORTAbits.RA5
#define DM_LOW PORTAbits.RA4
void QC3_Initialize(void);
//void onewireWriteBit(int b);
//unsigned char onewireReadBit();
//unsigned char onewireInit();
//unsigned char onewireReadByte();
//void onewireWriteByte(char data);
//unsigned char onewireCRC(unsigned char* addr, unsigned char len);
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif
qc3.c:
#include "qc3.h"
void QC3_Initialize(void) {
__delay_ms(150);
DP_HIGH = 0;
}
Error:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
make -f nbproject/Makefile-default.mk dist/default/production/PIC.production.hex
make[2]: Entering directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
"D:\Program Files\Microchip\xc8\v2.30\bin\xc8-cc.exe" -mcpu=12F1840 -c -mdfp="D:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC12-16F1xxx_DFP/1.2.63/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -I"head_and_lib" -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/head_and_lib/qc3.p1 head_and_lib/qc3.c
"D:\Program Files\Microchip\xc8\v2.30\bin\xc8-cc.exe" -mcpu=12F1840 -c -mdfp="D:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC12-16F1xxx_DFP/1.2.63/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -I"head_and_lib" -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/source/ISOPOWER.p1 source/ISOPOWER.c
make[2]: *** [build/default/production/head_and_lib/qc3.p1] Error 1
make[2]: *** Waiting for unfinished jobs....
head_and_lib/qc3.c:6:3: error: use of undeclared identifier '_XTAL_FREQ'
__delay_ms(150);
^
D:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC12-16F1xxx_DFP/1.2.63/xc8\pic\include\pic.h:101:51: note: expanded from macro '__delay_ms'
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
^
1 error generated.
(908) exit status = 1
nbproject/Makefile-default.mk:123: recipe for target 'build/default/production/head_and_lib/qc3.p1' failed
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 913ms)
The compiler complains (use of undeclared identifier '_XTAL_FREQ') but the header in declared AFTER the #define _XTAL_FREQ 500000. Why?
If i remove the delay of the function:
void QC3_Initialize(void) {
__delay_ms(150);
DP_HIGH = 0;
it builds successfully
So. "when" the QC3.c is "called" if it's never declared (even in the ".h" header)?
Why I should declare the ".h" if is the ".c" that includes the ".h"? Shouldn't it be the other way around? Or at least the ".h"
to contain the ".c"?
Seems basic stuff but it's blowing my mind
Thank You
You define _XTAL_FREQ in your C source file containing main() but, since you're calling __delay_ms() in qc3.c (a separate translation unit), that's where that definition needs to exist.
The easiest fix is probably to define it in qc3.h.
you must give _XTAL_FREQ inside the .c file then you may get.
Related
I have this header and function defined in it called long ptr = PT_REGS_PARM2(ctx); so first running command like following assuming my system config will take care of it finding this header file in /usr/include/bpf/tracing.h.
but couldn't find the header file
root#this:/home/ubuntu/Desktop/ebpf/Linux-exFilter-main/pkg/probe/bpf# clang -O2 -Wall -g -target bpf -I /usr/include/ -c kprobe_send.c -o kprobe_send.o
I also tried with - I and changing <bpf/tracing.h> to "bpf/tracing.h" not worked either.
I started this inclusion of -I after I was compiling this program and it causing error on compile, I could not understand the error but this is following
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
#this:/home/ubuntu/Desktop/ebpf/Linux-exFilter-main/pkg/probe/bpf# clang -O2 -Wall -g-target bpf -c kprobe_send.c -o kprobe_send.o
clang: error: unknown argument: '-g-target'
clang: error: no such file or directory: 'bpf'
root#this:/home/ubuntu/Desktop/ebpf/Linux-exFilter-main/pkg/probe/bpf# clang -O2 -Wall -g -target bpf -c kprobe_send.c -o kprobe_send.o
kprobe_send.c:31:2: warning: implicit declaration of function 'srand' is invalid in C99 [-Wimplicit-function-declaration]
srand(time(NULL)); /* Seed the random number generator. */
^
kprobe_send.c:37:11: warning: implicit declaration of function 'rand' is invalid in C99 [-Wimplicit-function-declaration]
int c = randrange(MAX-i);
^
kprobe_send.c:11:22: note: expanded from macro 'randrange'
#define randrange(N) rand() / (RAND_MAX/(N) + 1)
^
kprobe_send.c:51:22: warning: implicit declaration of function 'PT_REGS_PARM2' is invalid in C99 [-Wimplicit-function-declaration]
char *ptr = PT_REGS_PARM2(ctx);
^
kprobe_send.c:51:15: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
char *ptr = PT_REGS_PARM2(ctx);
^ ~~~~~~~~~~~~~~~~~~
kprobe_send.c:61:22: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'void *' [-Wint-conversion]
bpf_map_update_elem(fd,&key,&data,BPF_ANY);
^~
Error at line 37: Unsupport signed division for DAG: 0x18aff58: i64 = sdiv 0x18af668, 0x18afe20, kprobe_send.c:37:11Please convert to unsigned div/mod.
fatal error: error in backend: Cannot select: 0x18aff58: i64 = sdiv 0x18af668, 0x18afe20, kprobe_send.c:37:11
0x18af668: i64 = sra 0x189bcd8, Constant:i64<32>, kprobe_send.c:37:11
0x189bcd8: i64 = shl 0x189c4f8, Constant:i64<32>, kprobe_send.c:37:11
0x189c4f8: i64,ch,glue = CopyFromReg 0x189c018, Register:i64 $r0, 0x189c018:1, kprobe_send.c:37:11
0x189c150: i64 = Register $r0
0x189c018: ch,glue = callseq_end 0x189bc08, TargetConstant:i64<0>, TargetConstant:i64<0>, 0x189bc08:1, kprobe_send.c:37:11
0x189bfb0: i64 = TargetConstant<0>
0x189bfb0: i64 = TargetConstant<0>
What the above error even means, I thought it was complaining I did not include any headers so I started including tracing.h to cater to PT_REGS_PARM2(ctx)
How can I get rid of this error?
On this line it says unsupported sign division:
Error at line 37: Unsupport signed division for DAG: 0x18aff58: i64 = sdiv 0x18af668, 0x18afe20, kprobe_send.c:37:11Please convert to unsigned div/mod.
Is this line 37 referring to assembly or my source file? In line 37 of source file I am doing
int c = randrange(MAX-i);
Why is the above simple line is not allowed in ebpf program? This is my line 37 and rest of the bpf program
#include <linux/ptrace.h>
#include <linux/version.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <string.h>
#include <sys/sendfile.h>
#include <time.h>
//#include <bpf/tracing.h>
#include <stdlib.h>
#define RAND_MAX 0x7fff
#define PERF_SAMPLE_RAW 1U << 0
#define randrange(N) rand() / (RAND_MAX/(N) + 1)
#define MAX 100000000 /* Values will be in the range (1 .. MAX) */
struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(int));
__uint(value_size, sizeof(int));
__uint(max_entries, 100);
} my_map SEC(".maps");
SEC("kprobe/__x64_sys_recvfrom")
int bpf_prog1(struct pt_regs *ctx,int fd, const char *buf, size_t count)
{
static int vektor[100000000];
int candidates[MAX];
int i;
long key;
srand(time(NULL)); /* Seed the random number generator. */
for (i=0; i<MAX; i++)
candidates[i] = i;
for (i = 0; i < MAX-1; i++) {
int c = randrange(MAX-i);
int t = candidates[i];
candidates[i] = candidates[i+c];
candidates[i+c] = t;
}
for (i=0; i<10; i++)
vektor[i] = candidates[i] + 1;
struct S {
int pid;
char cookie[90];
char *ptr;
} data={1,""};
char *ptr = PT_REGS_PARM2(ctx);
//data.pid =count;// bpf_get_current_pid_tgid();
//if(buf==NULL)
//memcpy(data.cookie,buf,20);
data.ptr=ptr;
// data.cookie[0]=buf[0];
//bpf_get_current_comm(&data.cookie, sizeof(data.cookie));
key=vektor[i];
bpf_map_update_elem(fd,&key,&data,BPF_ANY);
//bpf_perf_event_output(ctx, &my_map, 1, &data, sizeof(data));
return 0;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = 99;
is there any info source where it says what's allowed or what's not allowed because seems to me its just picking arbitrarily what's allowed and what's not looking into ebpf
My kernel: 5.14.1
My clang: 12
libbpf installed but I'd love to find a command that tells its version and or just where it's installed.
On some link I found it says maybe/or definitely (couldn't tell the difference) be a problem of symlink on Ubuntu exact source .. what this even means does it mean I installed libbpf or something and unbuntu messed up with my symlink that help find libbpf headers? How can I understand what this link says? https://github.com/iovisor/kubectl-trace/issues/76#issuecomment-513587108
this is my main.c program and there was a build failure due to "struct/union required". I'm using pic 13f877a microcontroller. I'll be really greatful if anyone can tell me the reason for this build failure. also there was another warning saying "36.1 function declared implicit int". what does that mean too?
#include<htc.h>
#define _XTAL_FREQ 4000000
__CONFIG(0X3F39);
void main(){
int a;
TRISB = 0b00010000; //RB4 as Input PIN (ECHO)
TRISC = 0b00000000; //C as Output PINs (LED)
T1CON = 0b00010000; //Initialize Timer Module
while(1){
TMR1H = 0; //Sets the Initial Value of Timer
TMR1L = 0; //Sets the Initial Value of Timer
PORTC = 0b00000000;
PORTB.F0 = 1; //TRIGGER HIGH
Delay_us(10); //10uS Delay
PORTB.F0 = 0; //TRIGGER LOW
while(!PORTB.F4){
T1CON.F0 = 1;
}
while(PORTB.F4){
T1CON.F0 = 0;
}
a = (TMR1L | (TMR1H<<8)); //Reads Timer Value
a = a/58; //Converts Time to Distance
a = a + 1; //Distance Calibration
if(a>=2 && a<=400){
//with in the range
PORTC = 0b11111111;
} else {
//out of range
PORTC = 0b00000000;
}
Delay_ms(400);
}
}
Build C:\Users\user\Desktop\SmartDustbin for device 16F877A
Using driver C:\Program Files (x86)\HI-TECH Software\PICC\9.81\bin\picc.exe
Make: The target "C:\Users\user\Desktop\main.p1" is out of date.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 C:\Users\user\Desktop\main.c -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [196] C:\Users\user\Desktop\main.c; 15.10 struct/union required
Warning [361] C:\Users\user\Desktop\main.c; 16.1 function declared implicit int
Error [196] C:\Users\user\Desktop\main.c; 17.10 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 19.16 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 20.10 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 22.15 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 23.10 struct/union required
Warning [361] C:\Users\user\Desktop\main.c; 36.1 function declared implicit int
********** Build failed! **********
You claim to be using MicroC, but the command line in your build output clearly shows you're actually using HI-Tech C 9.81, which is outdated and replaced with Microchip's XC8. HI-Tech C does not allow access to single bits in SFR's asif they were struct members, like MicroC does. You can only access registers as a full byte and need to perform bit manipulation yourself. For example, the line:
PORTB.F0 = 1;
Would need to become:
PORTB |= (1 << 0);
Which is the common way to set a single bit in C. It shifts a 1 bit to the required position and OR's it into the destination byte, not altering other bits. Google for bit manipulation in C if you don't yet understand this.
The function declared implicit int errors stem from the fact that the functions delay_us and delay_ms are not declared. HI-tech C uses the macro's __delay_ms and __delay_us. In addition, you will need to define _XTAL_FREQ with your PIC's operating frequency in Hz prior to using the delay macro's.
I have been trying to compile a code. I am very new to XC8 compiler. I have the following code.
main.c
void main()
{
bmp280_t bmp280;
...
bmp280.dev_addr = 0x77;
init_check = bmp280_init(&bmp280);
....
}
bmp280.h
...
typedef struct {
struct bmp280_calib_param_t calib_param;/**<calibration data*/
uint8_t chip_id;/**< chip id of the sensor*/
uint8_t dev_addr;/**< device address of the sensor*/
uint8_t oversamp_temperature;/**< temperature over sampling*/
uint8_t oversamp_pressure;/**< pressure over sampling*/
BMP280_WR_FUNC_PTR;/**< bus write function pointer*/
BMP280_RD_FUNC_PTR;/**< bus read function pointer*/
}bmp280_t;
BMP280_RETURN_FUNCTION_TYPE bmp280_init(bmp280_t *temp_bmp280);
...
bmp280.c
static bmp280_t *p_bmp280;
BMP280_RETURN_FUNCTION_TYPE bmp280_init(bmp280_t *temp_bmp280)
{
/* variable used to return communication result*/
BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
uint8_t v_data_u8 = BMP280_INIT_VALUE;
p_bmp280 = temp_bmp280;/* assign BMP280 ptr */
/* read chip id */
com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
BMP280_CHIP_ID_REG, &v_data_u8,
BMP280_GEN_READ_WRITE_DATA_LENGTH);/* read Chip Id */
p_bmp280->chip_id = v_data_u8;
/* readout bmp280 calibparam structure */
com_rslt += bmp280_get_calib_param();
return com_rslt;
}
...
After executing this code, I am getting an error as
":0: error: (499) undefined symbol:
_bmp280_init(dist/default/production\FTS_basic.X.production.obj)
(908) exit status = 1
nbproject/Makefile-default.mk:279: recipe for target 'dist/default/production/FTS_basic.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/Abhi/MPLABXProjects/FTS_basic.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Abhi/MPLABXProjects/FTS_basic.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [dist/default/production/FTS_basic.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 10s)
"
As I see, there are no typo. The naming is correct. I also hope structure is being passed correctly.
Is there anything new I need to take care in XC8 compiler?
This is for pic16f1618 microcontroller.
Makefile-impl.mk
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
# Project Name
PROJECTNAME=FTS_basic.X
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
# All Configurations
ALLCONFS=default
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
# dependency checking support
.depcheck-impl:
# #echo "# This code depends on make tool being used" >.dep.inc
# #if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
I'm really a newbie when it comes to Xenomai and I want to measure the times between two points.
I want first to send a pulse of 10µs.
After that, I wait till I have an interrupt.
I want to measure the time between the pulse and the interrupt.
I use the 'rtmd_clock_read()' function. So the type that it return is 'nanosecs_abs_t '. When I use this I can't lod the module anymore and get this when I do a 'make'.
WARNING: "__aeabi_uldivmod" [...] undefined!
If I want to run it, with 'insmod', it says this:
Unknow symbol in module
This is my Makefile
EXTRA_CFLAGS := -I /usr/xenomai/include/
ifneq (${KERNELRELEASE},)
obj-m += oef1.o
else
ARCH ?= arm
CROSS_COMPILE ?= /usr/local/cross/rpi/bin/arm-linux-
KERNEL_DIR = /usr/src/linux
MODULE_DIR := $(shell pwd)
CFLAGS := -Wall -g
.PHONY: all
all:: modules
.PHONY: modules
modules:
${MAKE} -C ${KERNEL_DIR} SUBDIRS=${MODULE_DIR} modules
XENOCONFIG=/usr/xenomai/bin/xeno-config
.PHONY: clean
clean::
rm -f *.o .*.o .*.o.* *.ko .*.ko *.mod.* .*.mod.* .*.cmd *~
rm -f Module.symvers Module.markers modules.order
rm -rf .tmp_versions
endif
run: oef1.ko
insmod oef1.ko
stop:
rmmod oef1
this is my .c file.
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/version.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>
#include <rtdm/rtdm_driver.h>
//define pins for the ultrasonic sensor
#define TRIGGER 4 //GPIO_0, pin 3 on the pi
#define ECHO 15 //GPIO_1, pin 5 on the pi
//Define the outputs for the leds
///blablabla
//define the time the trigger needs to be high
#define TRIGGER_PERIOD 10000//10us
#define SLEEP_TASK_TRIGGER 1000000000 //1s
//task for sending trigger pulse
static rtdm_task_t trigger_task;
//needed i n multiple operactions
static rtdm_mutex_t periode_mutex;
//timer to get the distance of the sensor
int end = 0;
nanosecs_abs_t time1=0;
nanosecs_abs_t time2=0;
int centimeter=0;
nanosecs_abs_t difTime=0;
//for GPIO interrupt
static rtdm_irq_t irq_rtdm;
static int numero_interruption;
static void triggertask(void * p)
{
printk("first time in trigger");
int value=0;
while(!end)
{
printk("trigger \n");
gpio_set_value(TRIGGER,1);
rtdm_task_sleep(TRIGGER_PERIOD);
gpio_set_value(TRIGGER,0);
rtdm_task_wait_period();
rtdm_mutex_lock(&periode_mutex);
time1 = rtdm_clock_read();
rtdm_mutex_unlock(&periode_mutex);
//printk("tijd1 %d\n",time1);
rtdm_task_sleep(SLEEP_TASK_TRIGGER);
}
}
static int handler_interruption(rtdm_irq_t * irq)
{
printk("irq\n");
//stop timer, get difference
rtdm_mutex_lock(&periode_mutex);
time2 = rtdm_clock_read();
//printk("tijd2 %d\n",time2);
difTime = time2-time1;
centimeter = (difTime/1000)/56;
rtdm_mutex_unlock(&periode_mutex);
printk("centimer: ");
printk("%d",centimeter);
return RTDM_IRQ_HANDLED;
}
static int __init init_sensor(void)
{
int err;
rtdm_printk("initsensor");
//error handling nog toevoegen
numero_interruption = gpio_to_irq(ECHO);
if((err = gpio_request(ECHO, THIS_MODULE->name))!=0)
{
return err;
}
if((err = gpio_direction_input(ECHO)) !=0)
{
gpio_free(ECHO);
return err;
}
irq_set_irq_type(numero_interruption, IRQF_TRIGGER_RISING);
if((err=rtdm_irq_request(& irq_rtdm, numero_interruption,handler_interruption,RTDM_IRQTYPE_EDGE,THIS_MODULE->name,NULL))!= 0)
{
gpio_free(ECHO);
gpio_free(TRIGGER);
return err;
}
rtdm_irq_enable(& irq_rtdm);
rtdm_mutex_init(&periode_mutex);
if((err = gpio_request(TRIGGER,THIS_MODULE->name))!=0)
{
return err;
}
if((err = gpio_direction_output(TRIGGER,1))!=0)
{
gpio_free(TRIGGER);
return err;
}
err = rtdm_task_init(&trigger_task,"send_trigger_task",triggertask,NULL,99,0);
if(err !=0)
{
gpio_free(TRIGGER);
}
return err;
}
static void __exit exit_sensor(void)
{
//stop
end = 1;
rtdm_task_join_nrt(&trigger_task,100);
rtdm_irq_disable(& irq_rtdm);
rtdm_irq_free(& irq_rtdm);
gpio_free(TRIGGER);
gpio_free(ECHO);
}
module_init(init_sensor);
module_exit(exit_sensor);
MODULE_LICENSE("GPL");
thank you guys!
Symbol __aeabi_uldivmod is required for modulo operation on 64-bit integers. Call for this function is automatically generated by gcc when it encounters operations of such sort. While user-space library (libgcc) implements this function, kernel doesn't implement it automatically for all architectures.
When divisor is predefined constant, division/module operation may be replaced with multiplication on magic number and shift. Here you may calculate magic number for your case.
I get following errors when trying compile using MPLAB X on Windows..
newmain.c:40:9: error: unknown configuration setting: 'JTAGEN'
newmain.c:61:2: error: 'LATA' undeclared (first use in this function)
newmain.c:62:2: error: 'TRISA' undeclared (first use in this function)
newmain.c:61:2: error: 'LATA' undeclared (first use in this function)
I tried this on 2 different machines (on Windows 8.1 and Vista), but they all gave me same error.
It seemed like that xc.h file is already included to project since I can open that file. And also I googled for this problem but there wasn't a solution for this.
Thank you very much if you can give me a possible way to solve this.
I also attached photo describing project properties for this project.
Following is full description of error :
- CLEAN SUCCESSFUL (total time: 52ms) make -f
nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]:
Entering directory 'Z:/Personal Data/MPLABXProjects/Lab01.X' make -f
nbproject/Makefile-default.mk
dist/default/production/Lab01.X.production.hex make[2]: Entering
directory 'Z:/Personal Data/MPLABXProjects/Lab01.X' "Z:\Program Files
(x86)\Microchip\xc32\v1.40\bin\xc32-gcc.exe" -g -x c -c
-mprocessor=32MX340F512H -MMD -MF build/default/production/newmain.o.d -o
build/default/production/newmain.o newmain.c newmain.c:40:9: error:
unknown configuration setting: 'JTAGEN' #pragma config JTAGEN = OFF
// JTAG Enable OFF (only use for '250)
nbproject/Makefile-default.mk:105: recipe for target
'build/default/production/newmain.o' failed ^ newmain.c: In function
'main': make[2]: Leaving directory 'Z:/Personal
Data/MPLABXProjects/Lab01.X' newmain.c:61:2: error: 'LATA' undeclared
(first use in this function) nbproject/Makefile-default.mk:78: recipe
for target '.build-conf' failed LATA = 0; // Set value of PORT A
output to 0. ^ make[1]: Leaving directory 'Z:/Personal
Data/MPLABXProjects/Lab01.X' nbproject/Makefile-impl.mk:39: recipe
for target '.build-impl' failed newmain.c:61:2: note: each undeclared
identifier is reported only once for each function it appears in
newmain.c:62:2: error: 'TRISA' undeclared (first use in this
function) TRISA = 0; // Set all pins on PORT A to output ^ make[2]:
*** [build/default/production/newmain.o] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 BUILD FAILED
(exit value 2, total time: 203ms)
And source is
#include <xc.h>
#pragma config FWDTEN = OFF, JTAGEN = OFF
void delay(void);
unsigned int ctr = 0;
unsigned int delayVal = 2048;
int main(void)
{
LATA = 0;
TRISA = 0xFF00;
while(1)
{
LATA = 0x0055;
delay();
LATA = 0x00AA;
delay();
ctr++;
}
}
void delay(void)
{
unsigned int i,j;
for (i = 0; i < delayVal; i++)
{
for (j = 0; j < 20; j++);
}
}
The errors you receive indicate that the compiler does not see any libraries to reference those registers to. It treats them as regular variables instead.
You should include the specific header file for the processor you are using and also check to see what registers are structured in there to make more sense of your problem.