ATmega128 - UCSROA undeclared (first use in this function) - avr

I have a question about ATmega128 (UART)
This program sends Hello message through UART.
The following is my code.
#include <avr/io.h>
void putch(unsigned char data)
{
while((UCSROA & 0x20) == 0);
UDR0 = data;
UCSROA |= 0x20;
}
int main()
{
unsigned char text[] = "Hello! World!\r\n";
unsigned char i = 0;
DDRE = 0xFE;
UCSROA = 0x00;
UCSROB = 0x18;
UCSROC = 0x06;
UBRROH = 0x00;
UBRROL = 0x03;
while(text[i] != '\0')
putch(text[i++]);
return 0;
}
This is error messages.
Build succeeded with 0 Warnings...
avr-gcc -mmcu=atmega128 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=7372800UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Hello.o -MF dep/Hello.o.d -c ../Hello.c
../Hello.c: In function 'putch':
../Hello.c:5: error: 'UCSROA' undeclared (first use in this function)
../Hello.c:5: error: (Each undeclared identifier is reported only once
../Hello.c:5: error: for each function it appears in.)
../Hello.c: In function 'main':
../Hello.c:16: error: 'UCSROA' undeclared (first use in this function)
../Hello.c:17: error: 'UCSROB' undeclared (first use in this function)
../Hello.c:18: error: 'UCSROC' undeclared (first use in this function)
../Hello.c:19: error: 'UBRROH' undeclared (first use in this function)
../Hello.c:20: error: 'UBRROL' undeclared (first use in this function)
make: *** [Hello.o] Error 1 Build failed with 8 errors and 0 warnings...
I tested my code other computers.
But, It's not working.
I don't know how to fix this problem.
Give me some advice.
Thanks.

Its not
UCSROA
with the letter "O", it is
UCSR0A
with the number 0.

Related

Why does this template work in a single file but not across files?

Consider array.sats:
#include "share/atspre_staload.hats"
fun {a:t#ype} make: (int, a) -> void
array.dats:
#include "share/atspre_staload.hats"
staload "./array.sats"
implement {a} make(n: int, x: a) = ()
and example.dats:
staload Array = "./array.sats"
implement main0() = () where {
val arr = $Array.make<int>(10, 42)
}
These fail to compile with a bunch of template errors:
$ make clean all
rm -fv *_[sd]ats.[co] example
removed 'array_dats.c'
removed 'array_dats.o'
removed 'array_sats.c'
removed 'array_sats.o'
removed 'example_dats.c'
patscc -DATS_MEMALLOC_GCBDW -c array.sats
clang: warning: argument unused during compilation: '-L/usr/local/lib/ats2-postiats-0.3.9/ccomp/atslib/lib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/lib/ats2-postiats-0.3.9/ccomp/atslib/lib64' [-Wunused-command-line-argument]
patscc -DATS_MEMALLOC_GCBDW -c array.dats
clang: warning: argument unused during compilation: '-L/usr/local/lib/ats2-postiats-0.3.9/ccomp/atslib/lib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/lib/ats2-postiats-0.3.9/ccomp/atslib/lib64' [-Wunused-command-line-argument]
patscc -DATS_MEMALLOC_GCBDW -o example example.dats -lgc
example_dats.c:169:23: error: use of undeclared identifier 'PMVtmpltcstmat'
ATSINSmove_void(tmp1, PMVtmpltcstmat[0](make<S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))>)(ATSPMVi0nt(10), ATSPMVi0nt(42))) ;
^
example_dats.c:169:46: warning: implicit declaration of function 'S2Eapp' is invalid in C99 [-Wimplicit-function-declaration]
ATSINSmove_void(tmp1, PMVtmpltcstmat[0](make<S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))>)(ATSPMVi0nt(10), ATSPMVi0nt(42))) ;
^
example_dats.c:169:53: warning: implicit declaration of function 'S2Ecst' is invalid in C99 [-Wimplicit-function-declaration]
ATSINSmove_void(tmp1, PMVtmpltcstmat[0](make<S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))>)(ATSPMVi0nt(10), ATSPMVi0nt(42))) ;
^
example_dats.c:169:60: error: use of undeclared identifier 'g0int_t0ype'
ATSINSmove_void(tmp1, PMVtmpltcstmat[0](make<S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))>)(ATSPMVi0nt(10), ATSPMVi0nt(42))) ;
^
example_dats.c:169:41: error: use of undeclared identifier 'make'
ATSINSmove_void(tmp1, PMVtmpltcstmat[0](make<S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))>)(ATSPMVi0nt(10), ATSPMVi0nt(42))) ;
^
example_dats.c:169:99: error: expected expression
ATSINSmove_void(tmp1, PMVtmpltcstmat[0](make<S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))>)(ATSPMVi0nt(10), ATSPMVi0nt(42))) ;
^
2 warnings and 4 errors generated.
make: *** [example] Error 1
Meanwhile the same content in a single file compiles and runs without error:
#include "share/atspre_staload.hats"
extern fun {a:t#ype} make: (int, a) -> void
#include "share/atspre_staload.hats"
implement {a} make(n: int, x: a) = ()
implement main0() = () where {
val arr = make<int>(10, 42)
}
What's wrong with the separated code? Very similar code in the $UNSAFE files seems to work fine with templates and with a namespace.
You also need to staload array.dats:
staload Array = "./array.sats"
staload _(*Array*) = "./array.dats"
implement main0() = () where {
val arr = $Array.make<int>(10, 42)
}

go runtime fails to compile

I am just wondering why would go runtime fail to build. How do we pass flags (-fpermissive in this case) to the c compiler which golang compiler is using to build the runtime. I am using gcc-4.6.2 on ubuntu 12.04
../../../thirdparty/go1.4.2/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/src/runtime/cgo/gcc_linux_amd64.c: In function ‘void _cgo_sys_thread_start(ThreadStart*)’:
../../../thirdparty/go1.4.2/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/src/runtime/cgo/gcc_linux_amd64.c:45:41: error: invalid conversion from ‘void*’ to ‘__sigset_t*’ [-fpermissive]
A sample program written also fails to compile, it seems the nil defined in the go code is the problem, i wonder how others are working, when does the golang compiler compiles this runtime code ?
gcc t.c -lpthread -o t
t.c: In function ‘void* hello_world(void*)’:
t.c:12:41: error: invalid conversion from ‘void*’ to ‘__sigset_t*’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/sigthread.h:31:12: error: initializing argument 3 of ‘int pthread_sigmask(int, const __sigset_t*, __sigset_t*)’ [-fpermissive]
rk#rk-VirtualBox:~$ gcc -fpermissive t.c -lpthread -o t
t.c: In function ‘void* hello_world(void*)’:
t.c:12:41: warning: invalid conversion from ‘void*’ to ‘__sigset_t*’ [-fpermissive]
rk#rk-VirtualBox:~$ cat t.c
#include<pthread.h>
#include<stdio.h>
#include<signal.h>
#define nil ((void*)0)
static void*
hello_world(void *vptr)
{
sigset_t set;
sigemptyset(&set);
pthread_sigmask(SIG_BLOCK, &set, nil);
printf("hello world");
return NULL;
}
int main(int ac, char **av)
{
pthread_t t;
pthread_create(&t, NULL, hello_world, NULL);
pthread_join(t, NULL);
return 0;
}
/usr/include/x86_64-linux-gnu/bits/sigthread.h:31:12: error: initializing argument 3 of ‘int pthread_sigmask(int, const __sigset_t*, __sigset_t*)’ [-fpermissive]
make: *** [rulemanager] Error 2

Building with libjson on OSX Mavericks

I've tried the advice on threads here and here to no avail.
I have Xcode 5.0.2 installed and I am compiling everything on the command line. After make/make install to build libjson, I created a simple test file to link and build from it:
#include <iostream>
#include "libjson.h"
int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";
JSONNode n(JSON_NODE);
n.push_back(JSONNode("RootA", "Hello World"));
JSONNode c(JSON_ARRAY);
c.set_name("ArrayOfNumbers");
c.push_back(JSONNode("", 16));
c.push_back(JSONNode("", 42));
c.push_back(JSONNode("", 128));
n.push_back(c);
std::string jc = n.write_formatted();
std::cout << jc << std::endl;
return 0;
}
When I try to build this file:
g++ -DNDEBUG main.cpp -ljson
I get this:
main.cpp:17:5: error: unknown type name 'JSONNode'
JSONNode n(JSON_NODE);
^
main.cpp:18:17: error: use of undeclared identifier 'JSONNode'
n.push_back(JSONNode("RootA", "Hello World"));
^
main.cpp:19:5: error: unknown type name 'JSONNode'
JSONNode c(JSON_ARRAY);
^
main.cpp:21:17: error: use of undeclared identifier 'JSONNode'
c.push_back(JSONNode("", 16));
^
main.cpp:22:17: error: use of undeclared identifier 'JSONNode'
c.push_back(JSONNode("", 42));
^
main.cpp:23:17: error: use of undeclared identifier 'JSONNode'
c.push_back(JSONNode("", 128));
Found the answer from another SO question after I realized the make process had problems. Basically, the solution is to copy the source code into Xcode and build it as part of the project instead of trying to link it as a library.
I also tried to build libjson 7.6.1 on an ubuntu machine (12.04) and encountered the exact problem despite a perfect make.

unknown error when compile STLPort with arm-linux-gcc

I was trying to compile STLPort with cross-compiler toolchaine for uclinux.
According to INSTALL in root folder of STLPort library, if you want add new toolchaine, then you must find most nearest toolchaine and modified for your compiler.
I select gcc.mak and change gcc to arm-linux-gcc and c++ to arm-linux-c++. I got this error when compile :
.../../src/num_get_float.cpp:44:6: #error Unknown endianness.
../../src/num_get_float.cpp: In function `double stlpmtx_std::_Stl_atod(char*,
int, int)':
../../src/num_get_float.cpp:728: error: 'struct _ll::<anonymous>' has no member
named 'hi'
../../src/num_get_float.cpp:729: error: 'struct _ll::<anonymous>' has no member
named 'lo'
../../src/num_get_float.cpp:736: error: 'struct _ll::<anonymous>' has no member
named 'hi'
../../src/num_get_float.cpp:737: error: 'struct _ll::<anonymous>' has no member
named 'lo'
what is this error? how can I make a appropciate Makefile for STLPort on arm-linux-gcc?
EDIT : Error is fixed by first answer but I have another error :
When I try to compile the code, the makefile gets me this sentences :
* ATTENTION! *
This makefile tries to use system locale which might not work well with all glibc flavours.
If build fails, please resort to gcc.mak which will build C-locale only version for STLport
and in the end I got this errors for c_local.c:
In file included from c_locale.c:32:
arm-linux-gcc -I../stlport -W -Wno-sign-compare -Wno-unused -Wno-uninitialized -D_STLP_USE_GLIBC -D_STLP_REAL_LOCALE_IMPLEMENTED -O2 -fpic c_locale.c -c -o ../lib/obj/GCC/ReleaseD/c_locale.o
c_locale_glibc/c_locale_glibc.c: In function `_Find_locale':
c_locale_glibc/c_locale_glibc.c:118: warning: return makes pointer from integer without a cast
c_locale_glibc/c_locale_glibc.c: In function `_Locale_decimal_point':
c_locale_glibc/c_locale_glibc.c:242: error: `DECIMAL_POINT' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c:242: error: (Each undeclared identifier is reported only once
c_locale_glibc/c_locale_glibc.c:242: error: for each function it appears in.)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_thousands_sep':
c_locale_glibc/c_locale_glibc.c:246: error: `THOUSANDS_SEP' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_grouping':
c_locale_glibc/c_locale_glibc.c:250: error: `GROUPING' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_int_curr_symbol':
c_locale_glibc/c_locale_glibc.c:289: error: `INT_CURR_SYMBOL' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_currency_symbol':
c_locale_glibc/c_locale_glibc.c:292: error: `CURRENCY_SYMBOL' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_mon_decimal_point':
c_locale_glibc/c_locale_glibc.c:295: error: `MON_DECIMAL_POINT' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_mon_thousands_sep':
c_locale_glibc/c_locale_glibc.c:298: error: `MON_THOUSANDS_SEP' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_mon_grouping':
c_locale_glibc/c_locale_glibc.c:301: error: `MON_GROUPING' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_positive_sign':
c_locale_glibc/c_locale_glibc.c:304: error: `POSITIVE_SIGN' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_negative_sign':
c_locale_glibc/c_locale_glibc.c:307: error: `NEGATIVE_SIGN' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_int_frac_digits':
c_locale_glibc/c_locale_glibc.c:310: error: `INT_FRAC_DIGITS' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_frac_digits':
c_locale_glibc/c_locale_glibc.c:313: error: `FRAC_DIGITS' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_p_cs_precedes':
c_locale_glibc/c_locale_glibc.c:316: error: `P_CS_PRECEDES' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_p_sep_by_space':
c_locale_glibc/c_locale_glibc.c:319: error: `P_SEP_BY_SPACE' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_p_sign_posn':
c_locale_glibc/c_locale_glibc.c:322: error: `P_SIGN_POSN' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_n_cs_precedes':
c_locale_glibc/c_locale_glibc.c:325: error: `N_CS_PRECEDES' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_n_sep_by_space':
c_locale_glibc/c_locale_glibc.c:328: error: `N_SEP_BY_SPACE' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_n_sign_posn':
c_locale_glibc/c_locale_glibc.c:331: error: `N_SIGN_POSN' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `_Locale_ctype_create':
c_locale_glibc/c_locale_glibc.c:485: error: `_NL_CTYPE_TOLOWER_EL' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c:487: error: `_NL_CTYPE_TOUPPER_EL' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c: In function `cname_lookup':
c_locale_glibc/c_locale_glibc.c:526: error: `_NL_CTYPE_NAMES_EL' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c:531: error: `_NL_CTYPE_HASH_SIZE' undeclared (first use in this function)
c_locale_glibc/c_locale_glibc.c:532: error: `_NL_CTYPE_HASH_LAYERS' undeclared (first use in this function)
make: *** [../lib/obj/GCC/ReleaseD/c_locale.o] Error 1
I think this error is related to attention of makefile.
What can I fix the problem? what is resort for gcc.mak in attendtion?
Check the endianness of the ARM processor you want to run uclinux on. Then you can try running gcc -D_STLP_BIG_ENDIAN ... or gcc -D_STLP_LITTLE_ENDIAN ... in your Makefile to get past this error.

Pthreads compile not working

I have written some code but it doesn't seem to work when I compile it. I am trying to run this in Ubuntu:
#include <pthread.h>
#include <ctype.h>
#include <unistd.h>
char buffer[128];
void *write_thread(void *args)
{
int count = *((int*)args);
write(STDOUT_FILENO, buffer, count);
pthread_exit(0);
}
void *toupper_thread(void *args)
{
int i;
int count = *((int*)args);
for(i = 0; i < count; i++) {
buffer[i] = toupper(buffer[i]);
}
pthread_t writeId;
pthread_create(&writeId, NULL, write_thread, &count);
pthread_join(writeId, NULL);
pthread_exit(0);
}
void *read_thread(void *args)
{
int count = read(STDIN_FILENO, buffer, 128);
pthread_t toupperId;
pthread_create(&toupperId, NULL, toupper_thread, &count);
pthread_join(toupperId, NULL);
//buffer[count] = 0;
pthread_exit(0);
}
int main()
{
pthread_t threadId;
pthread_create(&threadId, NULL, read_thread, NULL);
pthread_join(threadId, NULL);
}
and I get these errors when I try to compile it with gcc -pthread prob41.c or with gcc prob41.c -lpthread:
prob41.c:1:21: error: pthread.h: No such file or directory
prob41.c: In function ‘toupper_thread’:
prob41.c:23: error: ‘pthread_t’ undeclared (first use in this function)
prob41.c:23: error: (Each undeclared identifier is reported only once
prob41.c:23: error: for each function it appears in.)
prob41.c:23: error: expected ‘;’ before ‘writeId’
prob41.c:24: error: ‘writeId’ undeclared (first use in this function)
prob41.c: In function ‘read_thread’:
prob41.c:33: error: ‘pthread_t’ undeclared (first use in this function)
prob41.c:33: error: expected ‘;’ before ‘toupperId’
prob41.c:34: error: ‘toupperId’ undeclared (first use in this function)
prob41.c: In function ‘main’:
prob41.c:45: error: ‘pthread_t’ undeclared (first use in this function)
prob41.c:45: error: expected ‘;’ before ‘threadId’
prob41.c:46: error: ‘threadId’ undeclared (first use in this function)
I don't know what I'm doing wrong.
It seems that you missed some dependencies.
Try this:
$ sudo apt-get install -y libc6-dev
Need to add -I flag in the compile command to enable the compiler to find pthread.h
You don't have a pthread.h library in the system. Try to install the
suitable library for it.
You need to be sure to use #include <sys/type.h>
Don't forget to add the -lpthread while compiling: gcc -lpthread {x}.c -o {y}

Resources