• Tag Archives software
  • msp430- coding interrupts for mspgcc

    I am just an idiot, but thats my opinion. For those with MSPGCC compilers, we have a more difficult time finding code examples, and many of the code examples given either don’ explain very well (cryptic Coding, un-commented code) or they are for the CCS or IAR, and they dont use the same syntax as the MSPGCC compiler. So here is how to create an interrupt handler for non-PUC/POR interrupts.

    I will not go into interrupt vector masking, that is beyond me at this moment, but im not saying that i wont cover it later on, once i understand why you would want to mask it…..
    So lets start at what headers and other setup items you need before, creating the interrupt handler.
    First the signal.h has to be included into your code. #include<signal.h>
    this will give you access to the special function of
    interrupt(VECTOR ) service_routine (void) {/*interrupt code*/ }

    this is the same as #pragma vector=WDT_VECTOR
    __interrupt void watchdog_timer(void){ }

    These are the Defined vectors for interrupts right from the header files.(mspgcc headers)

    #define PORT1_VECTOR 4 /* 0xFFE4 Port 1 */
    #define PORT2_VECTOR 6 /* 0xFFE6 Port 2 */
    #define USI_VECTOR 8 /* 0xFFE8 USI */
    #define ADC10_VECTOR 10 /* 0xFFEA ADC10 */
    #define TIMERA1_VECTOR 16 /* 0xFFF0 Timer A CC1-2, TA */
    #define TIMERA0_VECTOR 18 /* 0xFFF2 Timer A CC0 */
    #define WDT_VECTOR 20 /* 0xFFF4 Watchdog Timer */
    #define NMI_VECTOR 28 /* 0xFFFC Non-maskable */

    all the interrupts should be self expainatory, vector = the source of the interrupt.

    since now we have all the basics we can now right a small program that uses interrupt, we will just create a small WDT interval timer.
    /*WDT interval timer- code based on msp430 examples*/
    //compiler=mspgcc
    #include<msp430x22x2.h>
    #include<signal.h> //interrupt service routine
    #include <io.h> //usually included on msp430 header, but for sfr register access.
    void main(void) {
    WDTCTL = WDT_MDLY_32; //~30mS intervals
    P1DIR |=BIT1;
    IE1 |= WDTIE; //enable interrupt
    _BIS_SR(LPM0_bits + GIE); //not low power mode and enable interrupts
    }//end of main
    //interrupt service routine
    interrupt(WDT_VECTOR) watchdog_timer(void)
    {
    P1OUT ^= BIT1;
    }//end of interrupt

    this should give you a good start on your Interrupts but there is still one thing that you may need. Changing the power modes when a interrupt is being serviced, the power mode will revert back to the power mode that it was in when the interrupt was called.
    There are 2 functions that we can use to clear or set power modes while in an interrupt.
    First one is to set the mode on exit of the routine, this is done by changing the copy of the status register that is saved to the stack. _BIS_SR_IRQ( ... )
    you would use this the same way you would use the _BIS_SR(…)

    The second one will clear the bits you select _BIC_SR_IRQ(...) same usage as the other, except it will just clear the bits not modify them.
    ***the use of _BIx_SR_IRQ() should only be used in an interrupt service request, the compiler will give you a warning but will produce the correct code if you use it anywhere else.***
    ****remember to enable Interrupts by using BIS_SR(GIE) or eint()****

    Edit 6-23-2011

    MSPGCC Uniarch branch of mspgcc has been released, It supports newer chips like the msp430G2453 (the newer 20pin DIPs) This is an initiative to unify the current branches of mspgcc. Interrupts for this version is slightly different. Once I test it or get confirmation from another user I will post the correct format for uniarch branch……but what would be better would be unify the branches so we don’t have so much confusion with these version discrepancies and nuances of the trees.

    As of right now uniarch is still being worked on and there and is not fully recommended unless you need support for the newer 20pin Dips (G2x53 G2x52).  Please don’t let my opinion dissuade your choice of compiler, mspgcc works great for me but uniarch may work better for you.

     

    Thank you Tissit for your Comment

    “In current gcc, you can (should) include msp430.c instead of the specific header and use the -m switches (in a Makefile) to tell the compiler which chip you’re using. It will find the right headers automatically. “

    If I forget something let me know and I will update


  • IR eye

    This project is the first step in my motion tracking. This Eye was built and adapted from an LRM post here .

    DSCN0219DSCN0221please dont laugh at my soldering job, its what i can manage with that kind of board, I like the ones that mimic a breadboard setup. With very little trouble i finished soldering in about 2 hours but had to go back a desolder one transistor and replace it and resolder one wire. After that i tested each IR sensor by themselves to make sure they all worked, each one gave a little different reading off the same IR source but that can be fixed with a little calibration in the software. But for now my goal is to hook it up to 2 servos and control the x and y for the motion tracking, eventually i would like to put this into an enclosure that looks like an eye.
    This is to make sure all 4 eyes are working
    const int sensepin0 = 0;
    const int sensepin1 = 1;
    const int sensepin2 = 2;
    const int sensepin3 = 3;
    int sensorValue0 = 0;
    int sensorValue1 = 0;
    int sensorValue2 = 0;
    int sensorValue3 = 0;
    void setup() {
    Serial.begin(9600);
    }
    void loop() {
    sensorValue0 = analogRead(sensepin0);
    sensorValue1 = analogRead(sensepin1);
    sensorValue2 = analogRead(sensepin2);
    sensorValue3 = analogRead(sensepin3);
    Serial.print("sensor = ");
    Serial.print(sensorValue0);
    Serial.print(" ");
    Serial.print(sensorValue1);
    Serial.print(" ");
    Serial.print(sensorValue2);
    Serial.print(" ");
    Serial.println(sensorValue3);
    delay(10);
    }

    this will test all 4 sensors and print to the serial port.

    also this code is written for the arduino but can be adapted to other microprossecors.

    Here is a screenshot of the schematic as well

    ScreenshotNext i will mount it to the servo and start writing the logic for 1 of the axis, but my question is how to mount this to a servo with stuff wround the garage. I will answer this question soo.

    and this is why you should never place you MC on your keyboard…………..Screenshot-1that large stack to the left is about 30 print screen applications running. I placed my arduino on my print screen button for about 10 secs before I realized what was going on.

    Parts:

    • 4x 2n 2222 NPN transistors (generic NPN)
    • 4x 220 Ohm 1/4w resistors
    • 4x NPN photo transistors
    • a bunch of wire
    • Arduino


  • I hate slow DBs

    Have you ever called a place that needs to look up your account or other info? ever notice how it takes about a some time for them to get that info?

    I’m the guy on the other side of the line waiting to get that info so I can help fix what ever problem they had called in with, and the longer i work the more i notice that its taking longer and longer to for me to pull up any info about any account. So whats is the deal, why cant a multi billion dollar company fix a database?

    We live in the Age of Information, where almost everything is instant, where people expect info or help to be provided to them that instant. My guess is everyone at my place of employment probably don’t even notice the long waits between DB queries through our ticketing system. So how long is long? well i decided to test this, for a basic customer id I queried takes about 20 seconds, ok thats acceptable but thats only to bring up there info, not there ticket history. So i click on there history, guess what another 30 seconds on the clock, so it starting to get bad, after that you can click on individual tickets, create a new one or use tabs to look at more info. Each tab when clicked on takes 5-25 seconds to open. And these are the fast times, other times i sit 30 secs to about 1 min to get anything useful, and there have been times that I started a query when I left for break , came back and still had 5 mins to wait till it finally showed some results. My querries where presise and dont pull alot of data, but this is getting ridicolous. So how does a database get this slow? traffic? Nope cant be traffic, I work 3 rd shift and have about 15 people who use it , during the day over 100 people use it. What about maitnence? not likely, thats run once a week for about 2 hours or so.

    What else could it be? corrupted database? bad design for a large database? I  have never worked with a large database like that before so I don’t know the challenges of design or maintenance of such a large beast. But I have worked with smaller DBs that had similar slowdowns, but that was caused by too much data being pulled, like querying the entire DB or a few thousand rows. Or could the bandit be the vendor lock on the ticketing system in combo there DB, by the way the ticketing system looks very customized and even has features, custom built by other vendors, like the data being pulled from  an access database or integration into 2 other ticketing systems. My guess is Oracles Seibel, and DB work wonders out of the box and setup correctly even better when you use there system to input the data. I wonder who approved adding more plugins was a great idea?  This kind of bloat is inexcusable in a place where employees are timed. How do you fix something thats going to get screwed anyways, there policy just keep it chugging along, my solution would be to start gettting rid of or migrating 3yr+ old tickets and closed accounts to another DB, at least it would be a start, next would be to start removing the bloat from system, we do not need it to make our coffee and tell us were great. We need something light fast and simple, all we want to do is get the person what they want and move on. What will it take for these so called decision makers to realize that there all in one application dream doesn’t work in reality. Maybe this will become the next epic IT failure? not likely because its behind closed doors and if it failed i doubt that they would even tell the employees. So far i enjoy working for the smaller company, at least your voice is heard unlike here where your the bottom of the barrel.

    Sorry about the long rant but some things at large companies are inexcusable that can throw money at situations. I thought customer service was supposed to be the focus of what we do. When will the people who call the shots going to learn to think logical instead of  using a magic 8 ball and some business lingo to make decisions about technology.


  • Hacking the Code

    Last Post i was talking about how to clean up a hacked web server, hopeful your server is clean now and you can get back to what you do best. But what was the hacker trying to do? What does that long string mean? I will tell you how to decode the string the safe way, and understand how it was constructed.

    The Example that I am going to use is from a real hacked website, the code that I will display is only partial but the construct will be complete. Any identifiable URLs will be changed to prevent identification and your safety.
    Lets start by identifying the code, this is what i had found at the very beginning of the page.
    <? /**/eval(base64_decode(aWYoZnVuY3Rpb25<–>KTt9fX0=)); ?>

    lets start with /**/, it looks innocent but its a way to hide the code, what the code usually used for is large blocks of comments instead of using // on each line you would start it with /* and  end with */ but what i noticed is that in bluefish and notepad++ when these are highlighted the whole line appears to be a comment, my guess is that other code scanners will look like one long comment  on that line and skip it. But this is just my conclusion and testing, very clever way to use comments.

    almost forgot the first thing to notice is the use of short tags(<?) that they use, on my personal server I have short tags disabled, I had learned that it should be disabled for security purposes, I don’t know if this holds true today. but the reason they use it is it helps hide it as a comment adding php to   it (<?php),makes it show up as php code not a comment, now its starting to unravel………

    evalEvaluate a string as PHP code

    very simple right, they need something to run there code, eval does this trick, you can even add html to the string. just another peice of the pie.

    base64_decode – it decodes base64 code, now what is base64? It was originally for email to send binary data in emails, and other uses like binary data in urls and other variables but newest use is hiding php code in a long string, the string was 2692 characters long. So what did that string have in it.

    Continue reading  Post ID 511


  • Web Site Security- what to do when you get hacked?

    Recently a Client/friend asked me to help him with his site after he found out he was hacked, in a situation like that i would gladly volunteer my time to help assess and fix the issue and prevent it from happening again. All the Guides from the major CMSs or other frameworks all have help guides to helped you when you get hacked. WordPress and Zen cart both have very good guides, but this guide should be a general help guide to getting back on track, you may have better site specific info from the company that developed the framework. Also check the forums as well for other people that have been hacked and how they fixed it and what the cause was.

    Continue reading  Post ID 511


  • Optimizing your social networking updates

    Screenshot
    Most people, now have multiple social networking accounts. so what do you do if you want to update all of them? Most would just log in to there preferred site and just do a status update, I think that this takes to long and i could spend that time coding or writing another post, so i decided to consolidate everything to my blog.
    Now I have been using WP plug called ‘Post to Twitter’. Its very simple you put your login info into it and click test, and its all set to go, simple enough write?
    Next is hooking up myspace to twitter, very easy, click on the link on your home page ‘get synced’ and fill out the form and your connected, next you would test by making a post to your blog, then check your update on myspace, now it should have updated. I didn’t have any issues with it updating my status at all, I cant guarantee that it will work for you, but why not try.
    After that I hooked up my facebook. I tried 2 different apps, the official twitter app and the ‘Selective Twitter Status’. I liked the selective one better because i didn’t have to use my user name and password for twitter, I really don’t like to give social networking password to other social networking apps, Its just add another link that could fail.For the selective app, all you have to do is install the app, allow it to post, on your next post add #fb and it will post it to your status.
    This setup may be useful for Blogs and people who just want to post to one place. This is a one way update, I post to my blog then my WP plugin Posts to Twitter, next Facebook and Myspace get updated, and thats exactly what i wanted this to do.


  • Fun with user agents

    I wanted to share this fun and interesting tool that I use and to test certain aspects of some of my applications, User Agent Switcher Is a Firefox plug in that changes the user agent to the one selected. For those who don’t know, a user agent is the name that the browser gives to the website to make sure it is compatible, another use is for search engine crawlers to identifies them to the site that they visited and added your site.

    My original use for it was to bypass a governments website restriction to IE only so i searched for the best possible way to change my user agent, there are other ways to hack Firefox to have the same out come but takes a little bit of know how, so i found user agent switcher for this purpose, next i turn it on and change my user agent to IE 7, then go to the website with that restriction, and i get through with out a problem, this doesnt always work and may crash your browser so try that at your own risk.

    Now for the fun part, ever wanted to see what some sites show google but not you, So download the ltest list of user agents here, import it and change your user agent to google’s bot and explore to see what sites show google or yahoo, or change your user agent to some ancient browser, like MSIE 3.0; AOL 4.0;, see what sites depend on such things to work, you would be surprised to find that Facebook and MySpace depend on user agents and ask you to upgrade your browser, other sites just say that support for your browser is coming soon, or get back at those people that look at browser statistics from sites and you start seeing profanity driven browsers…

    Another Use i found was for work, there are a few web applications that we use and they dont play well with Firefox, so i load up User Switcher Agent and turn on IE 7 and load the apps up and they start working……..well almost one, worked fine, the other…..the one that I really wanted working Bombed and froze Firefox……..well you can’t win them all but at least I tried.

    So Try out User Agent Switcher and add it to your toolbox.


  • twitter script for linux

    Well let me give you an interesting script i found on Tech Republic………..

    Its how to Tweet from the command line using cURL, its very simple and to the point….just like a script should be
    tweet.sh
    #!/bin/sh
    tweet="${@}"
    user="username"
    pass="sekret"
    if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then
    echo "FATAL: The tweet is longer than 140 characters!"
    exit 1
    fi
    curl -k -u ${user}:${pass} -d status="${tweet}" https://twitter.com/statuses/update.xml >/dev/null 2>&1
    if [ "$?" == "0" ]; then
    echo "Successful tweet!"
    fi

    to us it just type this
    $ ~/bin/tweet "social server rules"
    the only other thing to worry about is you have to escape “?”, “!” -> “?”, “!”


  • Webmin, next best thing to sliced bread

    I personally hate trying to configure some Applications on linux machines, especially ones that have very cryptic config files,  or there so big it takes you half an hour to get to the bottom, but no more hassle with Webmin as your remote server management solution. I have been using webmin for about 4 months now and I am quite pleased with the program, It is very simple to use no hassle setup of the interface and you can customize and build new modules for new applications or deamons.

    ignore the IE i took the picture on my work PC
    ignore the IE i took the picture on my work PC

    Ignore those high CPU times i was compiling glibc on my server  at the time of this screen shot, but lets get back to what makes it a great tool for me.

    The original reason i installed webmin is to beable to configure squid on the fly because of the need to test it from an outside connection but the uses grew as i kept exploring all the options. So after i setup squid i started looking into the apache, dns, dhcpd, and ssh server. So the apache 2 configureation was so easy compared to manuelly setting up the conf file and the enabled and installed sites, and a better understanding on how to configure apache the right way instead of the haphazard way of looking at examples and hopefully getting the config correct, with out creating security holes. I really  couldnt tell you how I got by with out webmin. The ssh, dhcpd, mysql, send mail, samba, where just as easy to setup as apache and squid, i would recomend this to any one doing any kind of server admin or running a dev system that needs monitoring or constant changes and you dont have access to the physical terminal all the time.

    There are a few things i didnt like so far, for starters I would like to be able to have a custom side bar with the links that i need only, but i think that can be taken care of with a little bit of editing the source code or creating a them. Next issue i would like changed is a better comand line interface, The one under Others comand shell does what it says it does and executes the command but I wish it emulated a shell better but i guess thats what the ssh login is for. another thing i would change would be the system info page Yes its very minimilistic and gets the info that you need, but i would like a little more info that may be helpful, Like keeping the Uptime on that page , yes i know its there when your system has been up for more than an hour but less than a day, other wise it disapears, I would also like to add how many proccesses are running at that moment and maybe the IP addresses assigned to the network interfaces would be helpul as well. I really couldnt think of any thing after that, but these are jsut cosmetic changes for the most part and the issues wont stop me from using this great tool. I have to thank the fine People at  http://www.webmin.com/index.html for creating and maintaining this fine tool.


  • Work, The Internet, Your Browsing

    Have you ever had that feeling that someone is standing over your shoulder, while browsing at work?  Or someone sends you a link in your corp mail, you click and you get that wonderful message, “this site has been blocked by <your big brother software> for <some reason that its not related to work>”…… Every time i have gotten a message like that, my brain goes “uh oh” knowing that in some log that it recorded your user name time and the site you were trying to get to!! So you think that this is another mark on your flawless company record…but even worse is it keeps all the sites that you go to regardless if its blocked or not…….So are you getting paranoid now? Well don’t be unless you know what your doing is against company policy like looking at NSFW sites or other social networking sites. But it still bugs me that my Digital Privacy is still being infringed upon……I know that Company’s put in filters and proxy s for extra security to keep out the viruses malware and spam from the internet, But do you really need Draconian laws to help with security? isnt there a better way, maybe Teach your emplyees, good browsing habits, what phising  is  or social engineering, and whats acceptable for work browsing and sample sites…… It may be years before major company realize that there internet policy is failing due to people circumventing there security, which is a Big problem that no one seems to realize, so Let me tell you some interesting ideas to circumvent your employers draconian internet policy……………… There are a few different ways to get by there security, depending on what is in your way. Most company uses a Proxy to allow people to access to the internet which usually have some sort of login, some use a Web filter software added to the proxy to allow you access to a few sites that the company feels you need access to, others use just the filter and some use something called a transparent proxy or gateway that has some sort of filtering software, there may be others ways for security to impede on your web surfing. Now for the Good stuff, how to get around your works web security… Remember I do not Support breaking the law or circumventing critical network security or breaking your company internet usage policy…Basically I take no Responsibility for your actions. Read the Policy and understand it because knowing your rights as an employee is your responsibility not HRs……….This is for informational and educational purposes only!
    Continue reading  Post ID 511