Running PASM from c

Hi I'm very new to this so the help i want may seem very stupid but I keep getting the following compiler error.
I have #include <propeller.h>
Tried all sorts just don't have the knowledge to work out what is wrong.
/*.................................................................
Start 1Hz PASM (Pulse1Hz.Spin) PUB Pulse_Every_Sec
//.................................................................*/
int startPulse1Hz(unsigned int * par){
extern unsigned int *binary_Pulse1Hz_dat_start;
return cognew(&binary_Pulse1Hz_dat_start,0);
}
int main() // Main function
{
Error returned is
C:\Users\Bobby\AppData\Local\Temp\cceNPXg3.o: In function `_startPulse1Hz':
(.text+0x1): undefined reference to `_binary_Pulse1Hz_dat_start'
collect2: ld returned 1 exit status
Done. Build Failed!
I've never used a forum before so hope what I've done is the correct way to go about it.
Thanks in advance.
Bob
I have #include <propeller.h>
Tried all sorts just don't have the knowledge to work out what is wrong.
/*.................................................................
Start 1Hz PASM (Pulse1Hz.Spin) PUB Pulse_Every_Sec
//.................................................................*/
int startPulse1Hz(unsigned int * par){
extern unsigned int *binary_Pulse1Hz_dat_start;
return cognew(&binary_Pulse1Hz_dat_start,0);
}
int main() // Main function
{
Error returned is
C:\Users\Bobby\AppData\Local\Temp\cceNPXg3.o: In function `_startPulse1Hz':
(.text+0x1): undefined reference to `_binary_Pulse1Hz_dat_start'
collect2: ld returned 1 exit status
Done. Build Failed!
I've never used a forum before so hope what I've done is the correct way to go about it.
Thanks in advance.
Bob
Comments
You can however include PASM code in your C code and call that.
void doAsm(void *par) { int rxbits; int wcnt; int rxdata; int Data; int rxmask; int baud; __asm__ volatile ( " waitpne 0, %[_mask] \n\t" " mov %[_rxbits], #9 \n\t" " mov %[_wcnt], %[_baud] \n\t" " shr %[_wcnt], #1 \n\t" " add %[_wcnt], cnt \n\t" "bit: add %[_wcnt], %[_baud] \n\t" " waitcnt %[_wcnt], %[_baud] \n\t" " test %[_mask], ina wc \n\t" " rcl %[_rxdata], #1 \n\t" " djnz %[_rxbits], #bit \n\t" " mov %[_data], %[_rxdata] \n\t" :[_rxbits] "+r" (rxbits), [_wcnt] "+r" (wcnt), [_rxdata] "+r" (rxdata), [_data] "+r" (Data) :[_mask] "r" (rxmask), [_baud] "r" (baud) ); }
Mike
Have found other references on this forum but no clear examples or explanations.
Hopefully there are others who may help me.
Thank you
Bob
If I remember correctly, the symbol name generated for the PASM code has two underscores prepended to the name, so you need to declare it with a single underscore (the second is automatically added by the C compiler as the standard naming convention).
int startPulse1Hz(unsigned int * par){ extern unsigned int *_binary_Pulse1Hz_dat_start; // underscore added return cognew(&_binary_Pulse1Hz_dat_start,0); }
If still not working, please post the complete source code you are actually using, otherwise it is very complicated to help you.
Best regards,
Marco.
Have tried that and exactly same error?
Here is my C and the PASM I'm trying to run.
Thanks Bob
#include <simpletools.h> #include <propeller.h> #include <stdbool.h> #include <stdio.h> #include <cog.h> /*................................................................. Start 1Hz PASM (Pulse1Hz.Spin) PUB PULSE //.................................................................*/ int startPulse1Hz(unsigned int * par){ extern unsigned int *binary_Pulse1Hz_dat_start; return cognew(&binary_Pulse1Hz_dat_start,0); } int main() // Main function { const int PosDetMask = 0b100000000000000000000000000000; // Positive edge detection mode const int NegDetMask = 0b110000000000000000000000000000; // Negative edge detection mode const int IpBitMaskPendulum = 0b000000000000100000000000000000; // Mask for INA Register Pin Location long Pendulum = 17; // Select Input pin /* Design note write code to generate "IpBitMaskPendulum" */ unsigned long hightime = 0; unsigned long Tick = 0; unsigned long Tock = 0; bool TickFlag = true; bool CountStabalised = true; bool DataReady = false; startPulse1Hz(0); set_direction(Pendulum,0); // enable pin for input waitcnt(CLKFREQ/10 + CNT); printf("Clock Frequency %d \n\n",CLKFREQ); CTRA = PosDetMask + Pendulum; // POSDET Set control mode and Pin FRQA = 1; CTRB = NegDetMask + Pendulum; // NEGDET " " " " " FRQB = 1; waitpeq(IpBitMaskPendulum, IpBitMaskPendulum); //sync to input waitpeq(0, IpBitMaskPendulum); PHSA = 0; // ready for POSDET phase waitpne( IpBitMaskPendulum, IpBitMaskPendulum); printf("Ready for positive detect %d\n"); while(1) { PHSB = 0; // pin is high, POSDET phsa advancing, phsb not waitpeq(0 , IpBitMaskPendulum); // pin goes low, phsa stops, phsb starts hightime = PHSA; // pin is low, NEGDET phsb advancing, phsa not PHSA = 0; waitpeq( IpBitMaskPendulum, IpBitMaskPendulum); // pin goes high, phsb stops, phsa starts if(TickFlag) { Tick = PHSB + hightime; // TickFlag = false; printf("Tick %d " , Tick); } else { Tock = PHSB + hightime; TickFlag = true; printf(":: Tock %d" , Tock); printf(" :: Beat Error %d \n" ,Tick - Tock); if (CountStabalised > 2) { DataReady = true; // New Data ready for reading } else { CountStabalised++; }// if Count stabilised }// if Tickflag } // while print("Done \n"); } Then PASM in spin file Pulse1Hz.spin '************************************************************* '** Used to output a test signal at 1 Hz on Pin P16 '************************************************************* PUB PULSE cognew(@PULSE_1Hz, 0) ' Start a Cog with our assembly routine, no stack ' is required since PASM requires we explicitly ' assign and use memory locations within the Cog/Hub DAT PULSE_1Hz org 0 or dira, Pin 'Set Pin to output mov Time1, cnt 'Calculate delay time add Time1, #9 'Set minimum delay here :loop waitcnt Time1, Delay1 'Wait xor outa, Pin 'Toggle Output waitcnt Time1, Delay2 'Wait xor outa, Pin 'Toggle Output jmp #:loop 'Loop endlessly Pin long |< 16 'Pin number Delay1 long 1_000_000 'Output Pulse High Time 1_000_000 Delay2 long 79_000_000 'Output Pulse Low Time 79_000_000 Time1 res 1 'System Counter Workspace fit 496 'Display PASM size on Compile '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Thanks for having a look for me. forgot am using SimpleIDE to compile and download
Bob
PS any hints or tip you have about my code would be gratefully received. Always looking to learn.
Well, the code you posted works without errors for me (and without the underscore thing, I was wrong with that, sorry).
I have just added the two sources to a new SimpleIDE project and compiled.
The spin file name is exactly as you typed in the post ? Because the symbol name is derived from the file name and it is case sensitive.
Best regards,
Marco.
Really scratching my head now.
Cant have any typos if it runs for you.
Had to have PASM as another Tab in SimpleIDE
Brill.